src/Controller/CourseController.php line 214

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\CourseCreateForm;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use App\Entity\Article;
  12. use App\Entity\ArticleImages;
  13. use App\Entity\Cart;
  14. use App\Entity\CategoryImages;
  15. use App\Entity\CategoryCostplace;
  16. use App\Entity\CourseAdditionalTimes;
  17. use App\Entity\CourseAddPerson;
  18. use App\Entity\CourseCategories;
  19. use App\Entity\CoursePlace;
  20. use App\Entity\CourseTimes;
  21. use App\Entity\CourseImages;
  22. use App\Entity\Course;
  23. use App\Entity\CostPlace;
  24. use App\Entity\Discount;
  25. use App\Entity\ManualAppointment;
  26. use App\Entity\OrderItems;
  27. use App\Entity\Orders;
  28. use App\Entity\User;
  29. use App\Entity\UserCostplace;
  30. use App\Entity\Userlog;
  31. use App\Entity\TrainerPayment;
  32. use App\Entity\Resource;
  33. class CourseController extends AbstractController
  34. {
  35.     private $requestStack;
  36.     public function __construct(RequestStack $requestStack)
  37.     {
  38.         $this->requestStack $requestStack;
  39.         // Accessing the session in the constructor is *NOT* recommended, since
  40.         // it might not be accessible yet or lead to unwanted side-effects
  41.         // $this->session = $requestStack->getSession();
  42.     }
  43.     function getUsedSlots($id)
  44.     {
  45.         $alreadyUsed 0;
  46.         $alreadyUsed2 0;
  47.         $offline 0;
  48.         $online 0;
  49.         
  50.         
  51.         $repository $this->getDoctrine()->getRepository(orderItems::class);
  52.         $orderItems $repository->findBy(['oi_tid' => $id ]);
  53.         foreach($orderItems as $o)
  54.         {
  55.         
  56.             $repository $this->getDoctrine()->getRepository(Orders::class);
  57.             $order $repository->findOneBy(['id' => $o->getOiOid() ]);
  58.             if($order->getOStatus() == '2'){continue;}
  59.             $pay $order->getOPayment();
  60.             
  61.             if($pay == '5')
  62.             {
  63.                 $offline++;
  64.             }
  65.             else 
  66.             {
  67.                 $online++;
  68.             }
  69.             if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  70.             {
  71.                 if($pay == '5')
  72.                 {
  73.                     continue;
  74.                 }
  75.             }
  76.             else
  77.             {
  78.                 $uid $this->get('security.token_storage')->getToken()->getUser();
  79.                 $role $uid->getURole();
  80.                 if($pay == '5' && ($role == || $role == 2) )
  81.                 {
  82.                     continue;
  83.                 }
  84.             }
  85.             $alreadyUsed $alreadyUsed + ($o->getOiAmount());
  86.         }
  87.         $em $this->getDoctrine()->getManager();
  88.         $repo2Articles $em->getRepository(ManualAppointment::class);
  89.         $alreadyUsed2 $repo2Articles->createQueryBuilder('ma')
  90.         ->select('count(ma.ma_tid)')
  91.         ->where('ma.ma_tid = '$id)
  92.         ->getQuery()
  93.         ->getSingleScalarResult();
  94.         
  95.         
  96.         $online $online $alreadyUsed2;
  97.         
  98.         /*
  99.         $repository = $this->getDoctrine()->getRepository(courseTimes::class);
  100.         $times = $repository->findOneBy(['id' => $id ]);
  101.         $times->setCttOfflineCustomer($offline);
  102.         $times->setCttOnline($online);
  103.         $em->persist($times);
  104.         $em->flush();
  105.         */
  106.         return intval($alreadyUsed $alreadyUsed2);
  107.     }
  108.     public function checkHoliday($datum) {
  109.         if(function_exists("easter_date")) {
  110.             $teile explode("."$datum);
  111.             $tag intval($teile[0]);
  112.             $monat intval($teile[1]);
  113.             $jahr intval($teile[2]);    
  114.             $ostersonntag date("d.m.Y"easter_date($jahr));
  115.             $osterteile explode("."$ostersonntag);
  116.             $ostertag intval($osterteile[0]);
  117.             $ostermonat intval($osterteile[1]);
  118.             $karfreitag date("d.m.Y"mktime(000$ostermonat, ($ostertag 2), $jahr));
  119.             $karfreitagteile explode("."$karfreitag);
  120.             $karfreitagtag intval($karfreitagteile[0]);
  121.             $karfreitagmonat intval($karfreitagteile[1]);
  122.             $ostermontag date("d.m.Y"mktime(000$ostermonat, ($ostertag 1), $jahr));
  123.             $ostermontagteile explode("."$ostermontag);
  124.             $ostermontagtag intval($ostermontagteile[0]);
  125.             $ostermontagmonat intval($ostermontagteile[1]);
  126.             $christihfahrt date("d.m.Y"mktime(000$ostermonat, ($ostertag 39), $jahr));
  127.             $christihfahrtteile explode("."$christihfahrt);
  128.             $christihfahrttag intval($christihfahrtteile[0]);
  129.             $christihfahrtmonat intval($christihfahrtteile[1]);
  130.             $pfingsten date("d.m.Y"mktime(000$ostermonat, ($ostertag 50), $jahr));
  131.             $pfingstenteile explode("."$pfingsten);
  132.             $pfingstentag intval($pfingstenteile[0]);
  133.             $pfingstenmonat intval($pfingstenteile[1]);
  134.             $fronleichnam date("d.m.Y"mktime(000$ostermonat, ($ostertag 60), $jahr));
  135.             $fronleichnamteile explode("."$fronleichnam);
  136.             $fronleichnamtag intval($fronleichnamteile[0]);
  137.             $fronleichnammonat intval($fronleichnamteile[1]);
  138.             $feiertext "";
  139.             if($tag == && $monat == 1) {
  140.                 $feiertext "Neujahr";
  141.             }
  142.             if($tag == $karfreitagtag && $monat == $karfreitagmonat) {
  143.                 if($feiertext != ""$feiertext.= " und ";
  144.                 $feiertext.= "Karfreitag";
  145.             } 
  146.             if($tag == $ostertag && $monat == $ostermonat) {
  147.                 if($feiertext != ""$feiertext.= " und ";
  148.                 $feiertext.= "Ostersonntag";
  149.             }
  150.             if($tag == $ostermontagtag && $monat == $ostermontagmonat) {
  151.                 if($feiertext != ""$feiertext.= " und ";
  152.                 $feiertext.= "Ostermontag";
  153.             }
  154.             if($tag == && $monat == 5) {
  155.                 if($feiertext != ""$feiertext.= " und ";
  156.                 $feiertext.= "Tag der Arbeit";
  157.             }
  158.             if($tag == $christihfahrttag && $monat == $christihfahrtmonat) {
  159.                 if($feiertext != ""$feiertext.= " und ";
  160.                 $feiertext.= "Christi Himmelfahrt";
  161.             }
  162.             if($tag == $pfingstentag && $monat == $pfingstenmonat) {
  163.                 if($feiertext != ""$feiertext.= " und ";
  164.                 $feiertext.= "Pfingstmontag";
  165.             }
  166.             if($tag == && $monat == 10) {
  167.                 if($feiertext != ""$feiertext.= " und ";
  168.                 $feiertext.= "Tag der deutschen Einheit";
  169.             }
  170.             if($tag == 25 && $monat == 12) {
  171.                 if($feiertext != ""$feiertext.= " und ";
  172.                 $feiertext.= "Erster Weihnachtstag";
  173.             }
  174.             if($tag == 26 && $monat == 12) {
  175.                 if($feiertext != ""$feiertext.= " und ";
  176.                 $feiertext.= "Zweiter Weihnachtstag";
  177.             }
  178.             if($feiertext != "") {
  179.                 return $feiertext;
  180.             } else {
  181.                 return false;
  182.             }
  183.         } else {
  184.             return false;
  185.         }
  186.     }
  187.     /**
  188.      * @Route("/", name="homepage")
  189.      */
  190.     public function homepage()
  191.     {
  192.         require_once("./include/global.php");
  193.         
  194.         $em $this->getDoctrine()->getManager();   
  195.        
  196.         if(!$this->requestStack->getSession())
  197.         {
  198.             $session = new Session();
  199.             $session->start();
  200.         }
  201.         
  202.         $repository $this->getDoctrine()->getRepository(Cart::class);
  203.         $cart $repository->findAll();
  204.         foreach($cart as $ca)
  205.         {
  206.             $time $ca->getCaNow()->format('Y-m-d H:i:s');
  207.             $time date("Y-m-d H:i:s",strtotime($time));
  208.             if($time date("Y-m-d H:i:s",strtotime("-".$cartMaxTime." Minutes"))  )
  209.             {
  210.                 if($ca && $ca != null && is_null($ca) == false )
  211.                 {
  212.                     $em->remove($ca);
  213.                     $em->flush();
  214.                 }
  215.             }
  216.         }
  217.         $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  218.         $categories $repository->findAll();
  219.         $repository $this->getDoctrine()->getRepository(CategoryImages::class);
  220.         $categoryImages $repository->findAll();
  221.         $categoryImgArr = array();
  222.         foreach($categoryImages as $catIm)
  223.         {
  224.             $categoryImgArr[$catIm->getCaiCatid()] = $catIm->getCaiPath();
  225.         }
  226.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  227.         $session->clear();
  228.         $session->invalidate();
  229.         
  230.         require_once("./include/global.php");
  231.         
  232.         if($company == 'KVO')
  233.         {
  234.     //      return $this->render('course/index.html.twig', ['places' => $costplacePlace, 'categories' => $categories]);
  235.             $placeid 1;
  236.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  237.             $session->set('place'$placeid);
  238.             return $this->render('course/index.html.twig', ['places' => $costplacePlace'categories' => $categories'placeid' => '1''url' => $url"catimg" => $categoryImgArr'anzProd' => $globAmnProd]);
  239.     
  240.         }
  241.         else
  242.         {
  243.             return $this->render('course/place.html.twig', ['places' => $costplacePlace'categories' => $categories]);
  244.         }
  245.     }
  246.    
  247.     /**
  248.      * @Route("/place/{placeid}/", name="homepage2")
  249.      */
  250.     public function homepage2($placeid)
  251.     {
  252.         include("./include/global.php");
  253.         
  254.         $dir "./tmp/";
  255.         if(!is_dir($dir)){ mkdir($dir); }
  256.         foreach (glob($dir."*") as $file
  257.         {
  258.             if(time() - filemtime($file) > 300)
  259.             {
  260.                 unlink($file);
  261.             }
  262.         }
  263.         $em $this->getDoctrine()->getManager();   
  264.        
  265.         $query "UPDATE orders SET o_xml_export = 0 WHERE o_xml_file = '' AND o_xml_export = 1 AND o_xml_storno_file = '' AND o_payment = 2 AND o_price_netto != 0  ";
  266.         $em2 $this->getDoctrine()->getManager();   
  267.         $em2->getConnection()->executeQuery($query);
  268.         $query "UPDATE orders SET o_xml_storno_export = 0 WHERE o_xml_storno_file = '' AND o_xml_storno_export = 1  AND o_price_netto != 0 AND o_xml_file = '' AND o_payment = 2  ";
  269.         $em2 $this->getDoctrine()->getManager();   
  270.         $em2->getConnection()->executeQuery($query);
  271.         $repository $this->getDoctrine()->getRepository(Coursetimes::class);
  272.         $coursetimes $repository->findBy(['ctt_active' => 1]);
  273.         foreach($coursetimes as $ctt)
  274.         {
  275.             if($ctt->getCttCid() == '776'){continue;}
  276.             $d $ctt->getCttDay();
  277.             $d $d->format('Y-m-d'); 
  278.             
  279.             if($d date("Y-m-d"))
  280.             {
  281.                 $ctt->setCttActive(0);
  282.                 $em->persist($ctt);
  283.                 $em->flush();
  284.             }
  285.         }
  286.         
  287.         if(!$this->requestStack->getSession())
  288.         {
  289.             $session = new Session();
  290.             $session->start();
  291.         }
  292.         
  293.         $repository $this->getDoctrine()->getRepository(Cart::class);
  294.         $cart $repository->findAll();
  295.         foreach($cart as $ca)
  296.         {
  297.             $time $ca->getCaNow()->format('Y-m-d H:i:s');
  298.             $time date("Y-m-d H:i:s",strtotime($time));
  299.             if($time date("Y-m-d H:i:s",strtotime("-".$cartMaxTime." Minutes"))  )
  300.             {
  301.                 if($ca && $ca != null && is_null($ca) == false )
  302.                 {
  303.                     $em->remove($ca);
  304.                     $em->flush();
  305.                 }
  306.             }
  307.         }
  308.         
  309.         $repository $this->getDoctrine()->getRepository(Course::class);
  310.         $courses $repository->findBy(['c_active' => 1]);
  311.         foreach($courses as $c)
  312.         {
  313.             $courseActive 0;
  314.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  315.             $courseTimes $repository->findBy(['ctt_cid' => $c->getId(), 'ctt_active' => 1]);
  316.             foreach($courseTimes as $ctt)
  317.             {
  318.                 if($ctt->getCttMaxoffline() == $ctt->getCttOfflineCustomer() && $ctt->getCttOnline() == $ctt->getCttMaxonline())
  319.                 {
  320.                     $ctt->setCttActive(0);
  321.                     $em $this->getDoctrine()->getManager();
  322.                     $em->persist($ctt);
  323.                     $em->flush();
  324.                 }
  325.                 else 
  326.                 {
  327.                     $courseActive 1;
  328.                 }
  329.             }
  330.             if($courseActive == 0)
  331.             {
  332.                 $c->setCActive(0);
  333.                 $em $this->getDoctrine()->getManager();
  334.                 $em->persist($c);
  335.                 $em->flush();
  336.             }
  337.         }
  338.         $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  339.         $categories $repository->findAll();
  340.         
  341.         $repository $this->getDoctrine()->getRepository(CategoryImages::class);
  342.         $categoryImages $repository->findAll();
  343.         
  344.         $repository $this->getDoctrine()->getRepository(CategoryCostplace::class);
  345.         $categoryCostplaces $repository->findBy(['cc_cpid' => $placeid]);
  346.         $categoryImgArr = array();
  347.         foreach($categoryImages as $catIm)
  348.         {
  349.             $categoryImgArr[$catIm->getCaiCatid()] = $catIm->getCaiPath();
  350.         }
  351.         $allowedCat = array();
  352.         foreach($categoryCostplaces as $ccp)
  353.         {
  354.             $allowedCat[$ccp->getCcCatid()] = $ccp->getCcActive();
  355.         }
  356.         
  357.         if($company == 'KVO')
  358.         {
  359.             $placeid 1;
  360.         }
  361.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  362.         $session->set('place'$placeid);
  363.         
  364.         return $this->render('course/index.html.twig', ['places' => $costplacePlace'categories' => $categories'placeid' => $placeid'url' => $url"catimg" => $categoryImgArr'anzProd' => $globAmnProd'allowedCat' => $allowedCat]);
  365.     }
  366.     /**
  367.      * @Route("/setTimesStatus", name="setTimesStatus" , options={"expose"=true})
  368.      */
  369.     public function setTimesStatus()
  370.     {
  371.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  372.         {
  373.             $response $this->forward('App\Controller\CourseController::homepage', []);
  374.             return $response;
  375.         }
  376.         require_once("./include/global.php");
  377.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  378.         $times $repository->findOneBy(['id' => $_POST['id']]);
  379.         if($times->getCttActive() == 1)
  380.         {
  381.             $times->setCttActive(0);
  382.         }
  383.         else
  384.         {
  385.             $times->setCttActive(1);
  386.         }
  387.         $em $this->getDoctrine()->getManager();
  388.         $em->persist($times);
  389.         $em->flush();
  390.  
  391.        echo '';
  392.        die();
  393.     }
  394.     /**
  395.      * @Route("/backendCourseBlock/{id}", name="backendCourseBlock")
  396.      */
  397.     public function backendCourseBlock($id)
  398.     {
  399.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  400.         {
  401.             $response $this->forward('App\Controller\CourseController::homepage', []);
  402.             return $response;
  403.         }
  404.         require_once("./include/global.php");
  405.         $repository $this->getDoctrine()->getRepository(Course::class);
  406.         $course $repository->findOneBy(['id' => $id]);
  407.  
  408.         return $this->render('backend/course/course_block.html.twig', ['id' => $id'course' => $course 'today' => date("d.m.Y")]);
  409.     }
  410.    
  411.     /**
  412.      * @Route("/loadBlockTimes", name="loadBlockTimes" , options={"expose"=true})
  413.      */
  414.     public function loadBlockTimes()
  415.     {
  416.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  417.         {
  418.             $response $this->forward('App\Controller\CourseController::homepage', []);
  419.             return $response;
  420.         }
  421.         require_once("./include/global.php");
  422.         $date date("Y-m-d",strtotime($_POST['date']));
  423.         $id $_POST['id']; 
  424.         $d = new \DateTime(date('Y-m-d',strtotime($date)));
  425.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  426.         $times $repository->findBy(['ctt_cid' => $id'ctt_day' => $d], ['ctt_from' => 'ASC']);
  427.         $output '';
  428.         $i 0;
  429.         foreach($times as $time)
  430.         {
  431.             $nd1 $time->getCttFrom();
  432.             $nd1 $nd1->format('H:i'); 
  433.             $nd2 $time->getCttTo();
  434.             $nd2 $nd2->format('H:i'); 
  435.             if($time->getCttActive() == '0')
  436.             {
  437.                 $output .= '<input class="btn-check" type="button" name="articleTime" id="articleTime'.$i.'" value="'.$time->getid().'" autocomplete="off" onclick="setTimeStatus(\''.$time->getId().'\')" />';
  438.                 $output .= '<label class="btn btn-secondary" for="articleTime'.$i.'" style="'.$defaultColor.'">'.$nd1.' - '.$nd2.'</label> &nbsp;';
  439.             }
  440.             else
  441.             {
  442.                 $output .= '<input class="btn-check" type="button" name="articleTime" id="articleTime'.$i.'" value="'.$time->getid().'" autocomplete="off" onclick="setTimeStatus(\''.$time->getId().'\')" />';
  443.                 $output .= '<label class="btn btn-success" for="articleTime'.$i.'" style="'.$defaultColor.'">'.$nd1.' - '.$nd2.'</label> &nbsp;';
  444.             }
  445.             $i++;
  446.         }
  447.         if(trim($output) == ''){$output "Es wurden leider keine Eintr&auml;ge gefunden";}
  448.         echo $output;die();
  449.     }
  450.     /**
  451.      * @Route("/backendCourse/", name="backendCourse")
  452.      */
  453.     public function backendCourse()
  454.     {
  455.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  456.         {
  457.             $response $this->forward('App\Controller\CourseController::homepage', []);
  458.             return $response;
  459.         }
  460.         require_once("./include/global.php");
  461.         require_once("./include/function.php");
  462.         $uid $this->get('security.token_storage')->getToken()->getUser();
  463.         $role $uid->getURole();
  464.         $uid $uid->getId();
  465.         if($role == 4)
  466.         {
  467.             $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  468.             $categories $repository->findAll();
  469.             
  470.             $query "SELECT * FROM course WHERE c_active = 1";
  471.             $em2 $this->getDoctrine()->getManager();   
  472.             $course $em2->getConnection()->executeQuery($query);
  473.             $course2 $em2->getConnection()->executeQuery($query);
  474.             
  475.             $query "SELECT * FROM article WHERE a_active = 1";
  476.             $em2 $this->getDoctrine()->getManager();   
  477.             $articles $em2->getConnection()->executeQuery($query);
  478.         }
  479.         else
  480.         {
  481.             $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  482.             $categories $repository->findAll();
  483.             
  484.             $userArr = array();
  485.             $repository $this->getDoctrine()->getRepository(UserCostplace::class);
  486.             $userCostplace $repository->findBy(['ucp_uid' => $uid]);
  487.             foreach($userCostplace as $cp)
  488.             {
  489.                 array_push($userArr,$cp->getUcpPlace());
  490.             }
  491.             array_unique($userArr);
  492.             $repository $this->getDoctrine()->getRepository(Costplace::class);
  493.             $costplace $repository->findAll();
  494.             $filter "";
  495.             $filter2 "";
  496.             $param = array();
  497.             $i 0;
  498.             foreach($costplace as $cp)
  499.             {
  500.                 if(in_array($cp->getCpPlace(),$userArr ))
  501.                 {
  502.                     if($i == 0)
  503.                     {
  504.                         $filter .= "c_costplace = :costplace".$i;
  505.                         $filter2 .= "a_costplace = :costplace".$i;
  506.                         
  507.                     }
  508.                     else
  509.                     {
  510.                         $filter .= " OR c_costplace = :costplace".$i;
  511.                         $filter2 .= " OR a_costplace = :costplace".$i;
  512.                     }
  513.                     $param["costplace$i"] = $cp->getId();
  514.                     $i++;
  515.                 }
  516.             }
  517.             if($filter == ""){ $filter " 1 = 2 ";}
  518.             if($filter2 == ""){ $filter2 " 1 = 2 ";}
  519.             $query "SELECT * FROM course WHERE c_active = 1 AND ($filter)";
  520.             $em2 $this->getDoctrine()->getManager();   
  521.             $course $em2->getConnection()->executeQuery($query,$param);
  522.             $course2 $em2->getConnection()->executeQuery($query,$param);
  523.             if($filter2 != "")
  524.             {
  525.                 $query "SELECT * FROM article WHERE a_active = 1 AND ($filter2)";
  526.             }
  527.             $em2 $this->getDoctrine()->getManager();   
  528.             $articles $em2->getConnection()->executeQuery($query,$param);
  529.         }
  530.         
  531.         $minArr = array();
  532.         $maxArr = array();
  533.         foreach($course2 as $c)
  534.         {
  535.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  536.             $min $repository->findOneBy(['ctt_cid' => $c['id']],['ctt_day' => 'ASC']);
  537.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  538.             $max $repository->findOneBy(['ctt_cid' => $c['id']],['ctt_day' => 'DESC']);
  539.             if($min)
  540.             {    
  541.                 $minArr[$min->getCttCid()] = $min->getCttDay()->format("d.m.Y");
  542.             }
  543.             if($max)
  544.             {
  545.                 $maxArr[$max->getCttCid()] = $max->getCttDay()->format("d.m.Y");
  546.             }
  547.             
  548.         }
  549.         
  550.         if(!isset($globalPeriods))
  551.         {
  552.             $globalPeriods[1] = "1. Trimester";
  553.             $globalPeriods[2] = "2. Trimester";
  554.             $globalPeriods[3] = "3. Trimester";
  555.             $globalPeriods[4] = "4. Trimester";
  556.             $globalPeriods[5] = "Osterferien";
  557.             $globalPeriods[6] = "Sommerferien";
  558.             $globalPeriods[7] = "Herbstferien";
  559.             $globalPeriods[8] = "Sonstiges";
  560.         }
  561.         return $this->render('backend/course/course.html.twig',[ 'courses' => $course'categories' => $categories'articles' => $articles'min' => $minArr 'max' => $maxArr'periods' => $globalPeriods ]);
  562.     }
  563.     /**
  564.      * @Route("/deleteCourse", name="deleteCourse" , options={"expose"=true})
  565.      */
  566.     public function deleteCourse()
  567.     {
  568.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  569.         {
  570.             $response $this->forward('App\Controller\CourseController::homepage', []);
  571.             return $response;
  572.         }
  573.         
  574.         if($_POST['mode'] == '1')
  575.         {
  576.             $repository $this->getDoctrine()->getRepository(Course::class);
  577.             $course $repository->findOneBy(['id' => $_POST['id']]);
  578.             $course->setCActive(0);
  579.             $em $this->getDoctrine()->getManager();
  580.             $em->persist($course);
  581.             $em->flush();
  582.         }
  583.         else if($_POST['mode'] == '2')
  584.         {
  585.             $repository $this->getDoctrine()->getRepository(Article::class);
  586.             $article $repository->findOneBy(['id' => $_POST['id']]);
  587.             
  588.             $article->setAActive(0);
  589.             $em $this->getDoctrine()->getManager();
  590.             $em->persist($article);
  591.             $em->flush();
  592.         }
  593.             
  594.         
  595.         die();
  596.     }
  597.     /**
  598.      * @Route("/copyCourse/{id}/{mode}", name="copyCourse")
  599.      */
  600.     public function copyCourse($id$mode)
  601.     {
  602.         include("./include/global.php");
  603.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  604.         {
  605.             $response $this->forward('App\Controller\CourseController::homepage', []);
  606.             return $response;
  607.         }
  608.         /*      
  609.         $repository = $this->getDoctrine()->getRepository(User::class);
  610.         $trainer = $repository->findBy(["u_role" => "2", "u_locked" => '0']);
  611.         */
  612.         $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  613.         $categories $repository->findAll();
  614.         $repository $this->getDoctrine()->getRepository(Discount::class);
  615.         $discount $repository->findAll();
  616.         $repository $this->getDoctrine()->getRepository(User::class);
  617.         $trainer $repository->findBy(["u_role" => "2""u_locked" => '0'],['u_lastname' => 'ASC']);
  618.         
  619.         $repository $this->getDoctrine()->getRepository(Resource::class);
  620.         $rooms $repository->findAll();
  621.        
  622.         if($mode == '1')
  623.         {
  624.             //course
  625.             $repository $this->getDoctrine()->getRepository(Course::class);
  626.             $course $repository->findOneBy(['id' => $id]);
  627.             
  628.             $repository $this->getDoctrine()->getRepository(CostPlace::class);
  629.             $costplaces $repository->findAll();
  630.             return $this->render('backend/course/course_new.html.twig',[  'categories' => $categories'course' => $course,  'mode' => $mode'url' => $url'copy' => 1'costplaces' => $costplaces'discount' => $discount'trainer' => $trainer'company' => $company'rooms' => $rooms'periods' => $globalPeriods ]);
  631.         }
  632.         else
  633.         {
  634.             //article 
  635.             $repository $this->getDoctrine()->getRepository(Article::class);
  636.             $article $repository->findOneBy(['id' => $id]);
  637.             
  638.             return $this->render('backend/course/course_new.html.twig',[  'categories' => $categories'article' => $article,  'mode' => $mode'url' => $url'copy' => 1'discount' => $discount'trainer' => $trainer'company' => $company'rooms' => $rooms ]);
  639.         }
  640.         
  641.     }
  642.     /**
  643.      * @Route("/backendCourseNew/", name="backendCourseNew")
  644.      */
  645.     public function backendCourseNew()
  646.     {
  647.         include("./include/global.php");
  648.         include("./include/function.php");
  649.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  650.         {
  651.             $response $this->forward('App\Controller\CourseController::homepage', []);
  652.             return $response;
  653.         }
  654.         $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  655.         $categories $repository->findAll();
  656.         
  657.         $repository $this->getDoctrine()->getRepository(CostPlace::class);
  658.         $costplaces $repository->findAll();
  659.          
  660.         $repository $this->getDoctrine()->getRepository(User::class);
  661.         $trainer $repository->findBy(["u_role" => "2""u_locked" => '0'],['u_lastname' => 'ASC']);
  662.         
  663.         $number 0;
  664.         $maxnumber 0;
  665.         $query "SELECT c_number FROM course WHERE c_number LIKE :year ";
  666.         $em2 $this->getDoctrine()->getManager();   
  667.         $resultSet $em2->getConnection()->executeQuery($query,['year' => date("y").'%' ]);
  668.         
  669.         foreach($resultSet as $rs)
  670.         {
  671.             $tmp substr($rs['c_number'],-3);
  672.             if(intval($tmp) > $maxnumber){ $maxnumber $tmp; }
  673.         }
  674.         $month date("m");
  675.         $maxnumber $maxnumber+1;
  676.         if($maxnumber 10 )
  677.         {
  678.             $maxnumber "00".$maxnumber;
  679.         }
  680.         else if($maxnumber 100)
  681.         {
  682.             $maxnumber "0".$maxnumber;
  683.         }
  684.         if($month  <= 4){ $number date("y")."1".$maxnumber; }
  685.         else if($month >= 9){$number date("y")."3".$maxnumber ;}
  686.         else{ $number date("y")."2".$maxnumber; }
  687.         $repository $this->getDoctrine()->getRepository(Resource::class);
  688.         $rooms $repository->findAll();
  689.        
  690.         $repository $this->getDoctrine()->getRepository(Discount::class);
  691.         $discount $repository->findAll();
  692.         return $this->render('backend/course/course_new.html.twig',[  'categories' => $categories'url' => $url'costplaces' => $costplaces'trainer' => $trainer'coursenumber2' => $number'company' => $company'rooms' => $rooms'discount' => $discount'periods' => $globalPeriods  ]);
  693.     }
  694.     /**
  695.     * @Route("/backendEditCourse/{id}/{mode}", name="backendEditCourse")
  696.     */
  697.     public function backendEditCourse($id,$mode)
  698.     {
  699.         include("./include/global.php");
  700.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  701.         {
  702.             $response $this->forward('App\Controller\CourseController::homepage', []);
  703.             return $response;
  704.         }
  705.         if($mode == 1)
  706.         {
  707.             $repository $this->getDoctrine()->getRepository(Course::class);
  708.             $course $repository->findBy(['id' => $id]);
  709.             $repository $this->getDoctrine()->getRepository(CourseImages::class);
  710.             $images $repository->findBy(['ci_cid' => $id]);
  711.         }
  712.         else if($mode == 2)
  713.         {
  714.             $repository $this->getDoctrine()->getRepository(Article::class);
  715.             $article $repository->findBy(['id' => $id]);
  716.             $repository $this->getDoctrine()->getRepository(ArticleImages::class);
  717.             $images $repository->findBy(['ai_aid' => $id]);
  718.         }
  719.         $repository $this->getDoctrine()->getRepository(CostPlace::class);
  720.         $costplaces $repository->findAll();
  721.         $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  722.         $categories $repository->findAll();
  723.         $repository $this->getDoctrine()->getRepository(Resource::class);
  724.         $rooms $repository->findAll();
  725.         $repository $this->getDoctrine()->getRepository(Discount::class);
  726.         $discount $repository->findAll();
  727.         if($mode == 1)
  728.         {
  729.             $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  730.             $addTimes $repository->findBy(['cat_cid' => $id]);
  731.             $atArr = array();
  732.             $atArr['number'] = "0";
  733.             $atArr['from'] = "00:00";
  734.             $atArr['to'] = "00:00";
  735.             $atArr['days'] = "";
  736.             $atArr['leader'] = "0";
  737.             $atArr['booking'] = "0";
  738.             $atArr['offline'] = "0";
  739.             $atArr['online'] = "0";
  740.             foreach($addTimes as $at)
  741.             {
  742.                 if($at->getCatItem() == '0')
  743.                 {
  744.                     $atArr['number'] = $at->getCatNumber();
  745.                     $atArr['from'] = $at->getCatFrom()->format('H:i');
  746.                     $atArr['to'] = $at->getCatTo()->format('H:i');
  747.                     $atArr['days'] = $at->getCatDays();
  748.                     $atArr['leader'] = $at->getCatLeader();
  749.                     $atArr['booking'] = $at->getCatBookingOption();
  750.                     $atArr['offline'] = $at->getCatMaxOffline();
  751.                     $atArr['online'] = $at->getCatMaxOnline();
  752.                 }
  753.             }
  754.             $repository $this->getDoctrine()->getRepository(User::class);
  755.             $trainer $repository->findBy(["u_role" => "2""u_locked" => '0'],['u_lastname' => 'ASC']);
  756.             return $this->render('backend/course/course_edit.html.twig',[ 'categories' => $categories,'discount' => $discount,'at' => $atArr'rooms' => $rooms'course' => $course'image' =>  $images ,'id' => $id'mode' => $mode 'url' => $url'addtimer' => $addTimes'costplaces' => $costplaces'trainer' => $trainer'company' => $company'periods' => $globalPeriods ]);
  757.         }
  758.         else if($mode == 2)
  759.         {
  760.             return $this->render('backend/course/course_edit.html.twig',[ 'categories' => $categories,'discount' => $discount,'rooms' => $rooms'article' => $article'image' =>  $images ,'id' => $id'mode' => $mode 'url' => $url'costplaces' => $costplaces 'company' => $company'periods' => $globalPeriods]);
  761.         }
  762.     }
  763.      
  764.     /**
  765.     * @Route("/backendCourseNewSave/", name="backendCourseNewSave")
  766.     */
  767.     public function backendCourseNewSave(Request $request)
  768.     {
  769.         include("./include/global.php");
  770.         include("./include/function.php");
  771.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  772.         {
  773.             $response $this->forward('App\Controller\CourseController::homepage', []);
  774.             return $response;
  775.         }
  776.         // save Course
  777.         
  778.         if($request->get('productKind') == '1' || $request->get('productKind') == 1)
  779.         {
  780.             $start = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  781.             $end = new \DateTime(date('H:i:s'strtotime($request->get('endtime'))));
  782.             $visible_from = new \DateTime(date('Y-m-d H:i:00'strtotime($request->get('visible_from'). ' '$request->get('visible_time').':00')));
  783.             $price str_replace(".","#",$request->get('price'));
  784.             $price str_replace(",",".",$price);
  785.             $price str_replace("#",",",$price);
  786.             $price number_format($price,2,'.',',');
  787.            
  788.             $tax number_format((float)$request->get('tax'),2,'.',',');
  789.             $adminFee number_format((float)$request->get('admin_fee'),2,'.',',');
  790.             if($request->get('yoga') == null)
  791.             {
  792.                 $yoga 0;
  793.             }
  794.             else
  795.             {
  796.                 $yoga $request->get('yoga');
  797.             }
  798.             if($request->get('sibling_discount') == null)
  799.             {
  800.                 $siblingDiscount 0;
  801.             }
  802.             else
  803.             {
  804.                 $siblingDiscount $request->get('sibling_discount');
  805.             }
  806.             if($request->get('studio_discount') == null)
  807.             {
  808.                 $studioDiscount 0;
  809.             }
  810.             else
  811.             {
  812.                 $studioDiscount $request->get('studio_discount');
  813.             }
  814.             
  815.             if($request->get('visible') == null)
  816.             {
  817.                 $visible 0;
  818.             }
  819.             else
  820.             {
  821.                 $visible $request->get('visible');
  822.             }
  823.             if($request->get('discount') == null)
  824.             {
  825.                 $discount 0;
  826.             }
  827.             else
  828.             {
  829.                 $discount $request->get('discount');
  830.             }
  831.             if($discount == null){$discount 0;}
  832.             $course = new Course();
  833.             $course->setCName($request->get('coursename'));
  834.             $course->setCVisible($visible);
  835.             $course->setCNumber($request->get('coursenumber'));
  836.             if( is_null($request->get('coursesbnumber')) )
  837.             {
  838.                 $course->setCSbNumber(0);
  839.             }
  840.             else
  841.             {
  842.                 $course->setCSbNumber($request->get('coursesbnumber'));
  843.             }
  844.             $course->setCLeader($request->get('courseleader'));
  845.             $course->setCCategory($request->get('coursecategory'));
  846.             $course->setCMaxcustomer($request->get('maxcustomer'));
  847.             $course->setCOfflineCustomer($request->get('offlinecustomer'));
  848.             $course->setCStart($start);
  849.             $course->setCEnd($end);
  850.             if( is_null($request->get('duration')) )
  851.             {
  852.                 $course->setCDuration(0);
  853.             }
  854.             else
  855.             {
  856.                 $course->setCDuration($request->get('duration'));
  857.             }
  858.             $course->setCBreakBefore($request->get('break_before'));
  859.             $course->setCBreakAfter($request->get('break_after'));
  860.             $course->setCDescription($request->get('description'));
  861.             $course->setCPrice($price);
  862.             $course->setCAdminFee$adminFee );
  863.             $course->setCTax($tax);
  864.             $course->setCActive(1);
  865.             $course->setCDiscount($discount);
  866.             $course->setCSiblingDiscount($siblingDiscount);
  867.             $course->setCStudioDiscount($studioDiscount);
  868.             $course->setCPeriod($request->get('courseperiod'));
  869.             $course->setCVisibleFrom($visible_from);
  870.             
  871.             if($company == "KVO")
  872.             {
  873.                 $course->setCRoom($request->get('room'));
  874.             }
  875.             else
  876.             {
  877.                 $course->setCRoom(0);
  878.             }
  879.             $course->setCYoga($yoga);
  880.             $course->setCCostplace($request->get('costplace'));
  881.             $course->setCAppointmentSeries($request->get('series'));
  882.             $course->setCAppointmentSeriesDays($request->get('seriesDays'));
  883.         
  884.             $mon $request->get('monday');
  885.             if(is_null($mon)) {$mon 0;}
  886.             $tue $request->get('tuesday');
  887.             if(is_null($tue)) {$tue 0;}
  888.             $wed $request->get('wednesday');
  889.             if(is_null($wed)) {$wed 0;}
  890.             $thu $request->get('thursday');
  891.             if(is_null($thu)) {$thu 0;}
  892.             $fri $request->get('friday');
  893.             if(is_null($fri)) {$fri 0;}
  894.             $sat $request->get('saturday');
  895.             if(is_null($sat)) {$sat 0;}
  896.             $sun $request->get('sunday');
  897.             if(is_null($sun)) {$sun 0;}
  898.             $course->setCMonday($mon);
  899.             $course->setCTuesday($tue);
  900.             $course->setCWednesday($wed);
  901.             $course->setCThursday($thu);
  902.             $course->setCFriday($fri);
  903.             $course->setCSaturday($sat);
  904.             $course->setCSunday($sun);
  905.             
  906.             $course->setCPlace(1);
  907.             $d = new \DateTime(date('Y-m-d H:i:s',strtotime($request->get('activeUntill'))));
  908.             $course->setCActiveUntill($d);
  909.             $d2 = new \DateTime(date('Y-m-d H:i:s',strtotime($request->get('activeFrom'))));
  910.             $course->setCActiveFrom($d2);
  911.             $em $this->getDoctrine()->getManager();
  912.             $em->persist($course);
  913.             $em->flush();
  914.             $id $course->getId();
  915.             //save Images  
  916.             $pic $request->files->get('courseImage');
  917.             $pic_full $request->files->get('courseImageFull');
  918.             
  919.             $folder =  $this->getParameter('kernel.project_dir')."/public/courseImages/";
  920.             if(!file_exists($folder)){mkdir($folder);}
  921.             
  922.             $subfolder $folder.$id."/";
  923.             if(!file_exists($subfolder)){mkdir($subfolder);}
  924.             $uniqid uniqid();
  925.             $path $subfolder.$uniqid."_".$pic->getClientOriginalName();
  926.             if(file_exists($path)){unlink($path);}
  927.             $newFilename $uniqid.'_'.$pic->getClientOriginalName();
  928.             $pic->move($subfolder$newFilename);
  929.             $uniqid uniqid();
  930.             $path2 $subfolder.$uniqid."_".$pic_full->getClientOriginalName();
  931.             if(file_exists($path2)){unlink($path2);}
  932.             $newFilename2 $uniqid.'_'.$pic_full->getClientOriginalName();
  933.             $pic_full->move($subfolder$newFilename2);
  934.             $courseImages = new CourseImages();
  935.             $courseImages->setCiCid($id);
  936.             $courseImages->setCiPath(str_replace($publicImagePath,'.',$path));
  937.             $courseImages->setCiFullPath(str_replace($publicImagePath,'.',$path2));
  938.             $em->persist($courseImages);
  939.             $em->flush();
  940.             // save Course Times 
  941.             if($company == 'KVO')
  942.             {
  943.                 $begin = new \DateTime(date("Y-m-d",strtotime($request->get('activeFrom'))));
  944.                 $endDate = new \DateTime(date('Y-m-d',strtotime('+1 day',strtotime($request->get('activeUntill')))));
  945.                 
  946.                 $interval = \DateInterval::createFromDateString('1 day');
  947.                 $period = new \DatePeriod($begin$interval$endDate);
  948.                 
  949.                 //each day from start to activeUntill
  950.                 foreach ($period as $dt//days
  951.                 {
  952.                     $day1 $dt->format("Y-m-d \n"); 
  953.                     $day = new \DateTime(date("Y-m-d"strtotime($day1)));
  954.                     
  955.                     
  956.                     if($this->checkHoliday($dt->format("d.m.Y")) != false ){ continue; }
  957.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCSunday() == 0) {continue; }
  958.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCMonday() == 0) {continue; }
  959.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCTuesday() == 0) {continue; }
  960.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCWednesday() == 0) {continue; }
  961.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCThursday() == 0) {continue; }
  962.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCFriday() == 0) {continue; }
  963.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCSaturday() == 0) {continue; }
  964.                     
  965.                     //day Times
  966.                     $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  967.                 
  968.                 
  969.                     while($d1 $end)
  970.                     {
  971.                         
  972.                         $d1orig = new \DateTime(date('H:i:s',strtotime($d1->format('H:i:s')))); 
  973.                         
  974.                         $d1->add(new \DateInterval('PT' $request->get('duration') . 'M'));
  975.                         
  976.                         $courseTimes = new CourseTimes();
  977.                         $courseTimes->setCttDay($day);
  978.                         $courseTimes->setCttFrom($d1orig);
  979.                         $courseTimes->setCttTo($d1);
  980.                         $courseTimes->setCttCid($id);
  981.                         $courseTimes->setCttNote('');
  982.                         $courseTimes->setCttOfflineCustomer(0);
  983.                         $courseTimes->setCttNumber($request->get('coursenumber'));
  984.                         $courseTimes->setCttRoom($request->get('room'));
  985.                         
  986.                         $em->persist($courseTimes);
  987.                         
  988.                         $em->flush();
  989.                         
  990.                         $bb $request->get('break_before');
  991.                         $ba $request->get('break_after');
  992.                         
  993.                         if(intval($bb) < 0){$bb ;}
  994.                         if(intval($ba) < 0){$ba ;}
  995.                         
  996.                         $d1->add(new \DateInterval('PT' $bb 'M'));
  997.                         $d1->add(new \DateInterval('PT' $ba 'M'));
  998.                     }
  999.                 
  1000.                     if($request->get('timesArr') != "")
  1001.                     {
  1002.                         //additional Times
  1003.                         $timesArr explode(',',$request->get('timesArr'));
  1004.                         foreach($timesArr as $time)
  1005.                         {
  1006.                             /*
  1007.                             if($company != "KVO")
  1008.                             {
  1009.                                 if($request->get('starttime'.$time) == $request->get('starttime') && $request->get('endtime'.$time) == $request->get('endtime')){continue;}
  1010.                             }
  1011.                             */
  1012.                             
  1013.                             if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1014.                             {
  1015.                                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1016.                                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1017.                                 
  1018.                                 while($d1 $d2)
  1019.                                 {
  1020.                                     
  1021.                                     $d1orig = new \DateTime(date('H:i:s',strtotime($d1->format('H:i:s')))); 
  1022.                                     
  1023.                                     $d1->add(new \DateInterval('PT' $request->get('duration') . 'M'));
  1024.                                     
  1025.                                     $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1026.                                     $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1orig'ctt_to' => $d1'ctt_room' => $request->get('room'.$time) ]);
  1027.                                     if($timetest)
  1028.                                     {
  1029.                                         $d1->add(new \DateInterval('PT' $request->get('break_before') . 'M'));
  1030.                                         $d1->add(new \DateInterval('PT' $request->get('break_after') . 'M'));
  1031.                                         continue;
  1032.                                     }
  1033.                                     
  1034.                                     $courseTimes = new CourseTimes();
  1035.                                     $courseTimes->setCttDay($day);
  1036.                                     $courseTimes->setCttFrom($d1orig);
  1037.                                     $courseTimes->setCttTo($d1);
  1038.                                     $courseTimes->setCttCid($id);
  1039.                                     $courseTimes->setCttNote('');
  1040.                                     $courseTimes->setCttOfflineCustomer(0);
  1041.                                     $courseTimes->setCttOnline(0);
  1042.                                     $courseTimes->setCttNumber($request->get('coursenumber'.$time));
  1043.                                     $courseTimes->setCttRoom($request->get('room'.$time));
  1044.                                     $courseTimes->setCttMaxonline($request->get('maxcustomer'));
  1045.                                     $courseTimes->setCttMaxoffline($request->get('offlinecustomer'));
  1046.                                     
  1047.                                     $em->persist($courseTimes);
  1048.                                     
  1049.                                     $em->flush();
  1050.                                     
  1051.                                     $d1->add(new \DateInterval('PT' $request->get('break_before') . 'M'));
  1052.                                     $d1->add(new \DateInterval('PT' $request->get('break_after') . 'M'));
  1053.                                 }
  1054.                                 
  1055.                             }
  1056.                         }
  1057.                     }
  1058.                 }
  1059.             }
  1060.             else
  1061.             {
  1062.                 $days $request->get('courseDays');
  1063.                 $days explode(',',$days);
  1064.                 
  1065.                 foreach($days as $day)
  1066.                 {
  1067.                     $day = new \DateTime(date("Y-m-d"strtotime($day)));
  1068.                     if($request->get('starttime') != "" && $request->get('endtime') != "")
  1069.                     {
  1070.                         $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1071.                         $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1072.                         
  1073.                         $courseTimes = new CourseTimes();
  1074.                         $courseTimes->setCttDay($day);
  1075.                         $courseTimes->setCttFrom($d1);
  1076.                         $courseTimes->setCttTo($d2);
  1077.                         $courseTimes->setCttCid($id);
  1078.                         $courseTimes->setCttNote('');
  1079.                         $courseTimes->setCttOfflineCustomer(0);
  1080.                         $courseTimes->setCttOnline(0);
  1081.                         $courseTimes->setCttNumber($request->get('coursenumber'));
  1082.                         $courseTimes->setCttRoom($request->get('room'));
  1083.                         //$courseTimes->setCttMaxonline($request->get('maxcustomer'));
  1084.                         //$courseTimes->setCttMaxoffline($request->get('offlinecustomer'));
  1085.                         $courseTimes->setCttMaxonline($request->get('courseMaxOnline'));
  1086.                         $courseTimes->setCttMaxoffline($request->get('courseMaxOffline'));
  1087.                         
  1088.                         $em->persist($courseTimes);
  1089.                         $em->flush();
  1090.                     }
  1091.                 }
  1092.                 if($request->get('courseTimesArr') != "")
  1093.                 {
  1094.                     //additional Times
  1095.                     $timesArr explode(',',$request->get('courseTimesArr'));
  1096.                     foreach($timesArr as $time)
  1097.                     {
  1098.                         
  1099.                         //GET Days
  1100.                         $days $request->get('courseDays'.$time);
  1101.                         $days explode(',',$days);
  1102.                         
  1103.                         foreach($days as $day)
  1104.                         {
  1105.                             $day = new \DateTime(date("Y-m-d"strtotime($day)));
  1106.                             //if($request->get('starttime'.$time) == $request->get('starttime') && $request->get('endtime'.$time) == $request->get('endtime')){continue;}
  1107.                             
  1108.                             if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1109.                             {
  1110.                                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1111.                                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1112.                                 
  1113.                                 $courseTimes = new CourseTimes();
  1114.                                 $courseTimes->setCttDay($day);
  1115.                                 $courseTimes->setCttFrom($d1);
  1116.                                 $courseTimes->setCttTo($d2);
  1117.                                 $courseTimes->setCttCid($id);
  1118.                                 $courseTimes->setCttNote('');
  1119.                                 $courseTimes->setCttOfflineCustomer(0);
  1120.                                 $courseTimes->setCttOnline(0);
  1121.                                 $courseTimes->setCttNumber($request->get('coursenumber'.$time));
  1122.                                 $courseTimes->setCttRoom($request->get('room'.$time));
  1123.                                 //$courseTimes->setCttMaxonline($request->get('maxcustomer'));
  1124.                                 //$courseTimes->setCttMaxoffline($request->get('offlinecustomer'));
  1125.                                 $courseTimes->setCttMaxonline($request->get('courseMaxOnline'.$time));
  1126.                                 $courseTimes->setCttMaxoffline($request->get('courseMaxOffline'.$time));
  1127.                                 
  1128.                                 $em->persist($courseTimes);
  1129.                                 
  1130.                                 $em->flush();
  1131.                             }
  1132.                         }
  1133.                     }
  1134.                 }
  1135.             }
  1136.             if($company == "KVO")
  1137.             {
  1138.                 $timesArr explode(',',$request->get('timesArr'));
  1139.             }
  1140.             else
  1141.             {
  1142.                 $timesArr explode(',',$request->get('courseTimesArr'));
  1143.             }
  1144.           
  1145.             foreach($timesArr as $time)
  1146.             {
  1147.                 if($time == ""){ continue; }      
  1148.                 if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1149.                 {
  1150.                     //$d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1151.                     //$d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1152.                     $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1153.                     $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1154.                 
  1155.                     $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  1156.                     if($company == "KVO")
  1157.                     {
  1158.                         $timetest $repository->findOneBy(['cat_cid' => $id'cat_from' => $d1'cat_to' => $d2'cat_room' => $request->get('room'.$time) ]);
  1159.                         if($timetest)
  1160.                         {
  1161.                             continue;
  1162.                         }
  1163.                     }
  1164.                     /*else
  1165.                     {
  1166.                         $timetest = $repository->findOneBy(['cat_cid' => $id, 'cat_from' => $d1, 'cat_to' => $d2, 'cat_room' => 0 ]);
  1167.                     }*/
  1168.                     
  1169.                     $courseAddTimes = new CourseAdditionalTimes();
  1170.                     $courseAddTimes->setCatCid($id);
  1171.                     $courseAddTimes->setCatFrom($d1);
  1172.                     $courseAddTimes->setCatTo($d2);
  1173.                     $courseAddTimes->setCatItem($time);
  1174.                     if($company == 'KVO')
  1175.                     {
  1176.                         if(!is_null($request->get('room'.$time)))
  1177.                         {
  1178.                             $courseAddTimes->setCatRoom($request->get('room'.$time));
  1179.                         }
  1180.                         else
  1181.                         {
  1182.                            $courseAddTimes->setCatRoom(0);
  1183.                         }
  1184.                         $courseAddTimes->setCatLeader(0);
  1185.                         $courseAddTimes->setCatDays('');
  1186.                         $courseAddTimes->setCatNumber(0);
  1187.                     }
  1188.                     else
  1189.                     {
  1190.                         $courseAddTimes->setCatRoom(0);
  1191.                         $courseAddTimes->setCatLeader($request->get('courseleader'.$time));
  1192.                         $courseAddTimes->setCatDays($request->get('courseDays'.$time));
  1193.                         $courseAddTimes->setCatNumber($request->get('coursenumber'.$time));
  1194.                         $courseAddTimes->setCatBookingOption($request->get('booking_option'.$time));
  1195.                     }
  1196.                     $courseAddTimes->setCatMaxOnline($request->get('courseMaxOnline'.$time));
  1197.                     $courseAddTimes->setCatMaxOffline($request->get('courseMaxOffline'.$time));
  1198.                     $em->persist($courseAddTimes);
  1199.                     $em->flush();
  1200.                 }
  1201.             }
  1202.             if($company != "KVO")
  1203.             {
  1204.                 //$d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1205.                 //$d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1206.                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1207.                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1208.                 $courseAddTimes = new CourseAdditionalTimes();
  1209.                 $courseAddTimes->setCatCid($id);
  1210.                 $courseAddTimes->setCatFrom($d1);
  1211.                 $courseAddTimes->setCatTo($d2);
  1212.                 $courseAddTimes->setCatItem(0);
  1213.                 $courseAddTimes->setCatRoom(0);
  1214.                 $courseAddTimes->setCatLeader($request->get('courseleader'));
  1215.                 $courseAddTimes->setCatDays($request->get('courseDays'));
  1216.                 $courseAddTimes->setCatNumber($request->get('coursenumber'));
  1217.                 $courseAddTimes->setCatBookingOption($request->get('booking_option'));
  1218.                 $courseAddTimes->setCatMaxOnline($request->get('courseMaxOnline'));
  1219.                 $courseAddTimes->setCatMaxOffline($request->get('courseMaxOffline'));
  1220.                 
  1221.                 $em->persist($courseAddTimes);
  1222.                 $em->flush();
  1223.             }
  1224.         }
  1225.         else if($request->get('productKind') == '2' || $request->get('productKind') == 2)
  1226.         {
  1227.             $price str_replace(".","#",$request->get('price'));
  1228.             $price str_replace(",",".",$price);
  1229.             $price str_replace("#",",",$price);
  1230.             $price number_format($price,2,'.',',');
  1231.             $tax number_format((float)$request->get('tax2'),2,'.',',');
  1232.             $article = new Article();
  1233.             $article->setAName($request->get('articlename'));
  1234.             $article->setASbNumber($request->get('coursesbnumber2'));
  1235.             $article->setACategory($request->get('coursecategory2'));
  1236.             $article->setADescription($request->get('description2'));
  1237.             $article->setAPrice($price);
  1238.             $article->setATax($tax);
  1239.             $article->setAActive(1);
  1240.             $article->setAPlace(1);
  1241.             $article->setADiscount($request->get('discount2'));
  1242.             $article->setACostplace($request->get('costplace2'));
  1243.             $em $this->getDoctrine()->getManager();
  1244.             $em->persist($article);
  1245.             $em->flush();
  1246.             $id $article->getId();
  1247.             //image
  1248.             $pic $request->files->get('courseImage2');
  1249.             
  1250.             $folder =  $this->getParameter('kernel.project_dir')."/public/courseImages/";
  1251.             if(!file_exists($folder)){mkdir($folder);}
  1252.             
  1253.             $subfolder $folder.$id."/";
  1254.             if(!file_exists($subfolder)){mkdir($subfolder);}
  1255.             $uniqid uniqid();
  1256.             $path $subfolder.$uniqid."_".$pic->getClientOriginalName();
  1257.             if(file_exists($path)){unlink($path);}
  1258.             $newFilename $uniqid.'_'.$pic->getClientOriginalName();
  1259.             $pic->move($subfolder$newFilename);
  1260.             $articleImages = new ArticleImages();
  1261.             $articleImages->setAiAid($id);
  1262.             $articleImages->setAiPath(str_replace($publicImagePath,'.',$path));
  1263.             $em->persist($articleImages);
  1264.             $em->flush();
  1265.         }
  1266.         
  1267.         if($request->get('productKind') == '1' || $request->get('productKind') == 1)
  1268.         {
  1269.             $response $this->forward('App\Controller\CourseController::backendTrainerPayment', ['id' => $id]);
  1270.             return $response;
  1271.         }
  1272.         else
  1273.         {
  1274.             $response $this->forward('App\Controller\CourseController::backendCourse', []);
  1275.             return $response;
  1276.         }
  1277.         
  1278.     }
  1279.     /**
  1280.     * @Route("/backendCourseEditSave/", name="backendCourseEditSave")
  1281.     */
  1282.     public function backendCourseEditSave(Request $request)
  1283.     {
  1284.         include("./include/global.php");
  1285.         include("./include/function.php");
  1286.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  1287.         {
  1288.             
  1289.             $response $this->forward('App\Controller\CourseController::homepage', []);
  1290.             return $response;
  1291.         }
  1292.         if($request->get('mode') == '1' || $request->get('mode') == 1)
  1293.         {
  1294.             // save Course
  1295.             $start = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1296.             $end = new \DateTime(date('H:i:s'strtotime($request->get('endtime'))));
  1297.             $visible_from = new \DateTime(date('Y-m-d H:i:00'strtotime($request->get('visible_from'). ' '$request->get('visible_time').':00')));
  1298.             $price str_replace(".","#",$request->get('price'));
  1299.             $price str_replace(",",".",$price);
  1300.             $price str_replace("#",",",$price);
  1301.             $price number_format($price,2,'.',',');
  1302.             
  1303.             $tax number_format((float)$request->get('tax'),2,'.',',');
  1304.             $adminFee number_format((float)$request->get('admin_fee'),2,'.',',');
  1305.             $repository $this->getDoctrine()->getRepository(Course::class);
  1306.             $course $repository->findOneBy(['id' => $request->get('courseID')]);
  1307.             $id $request->get('courseID');
  1308.             if($request->get('yoga') == null)
  1309.             {
  1310.                 $yoga 0;
  1311.             }
  1312.             else
  1313.             {
  1314.                 $yoga $request->get('yoga');
  1315.             }
  1316.             
  1317.             if($request->get('sibling_discount') == null)
  1318.             {
  1319.                 $siblingDiscount 0;
  1320.             }
  1321.             else
  1322.             {
  1323.                 $siblingDiscount $request->get('sibling_discount');
  1324.             }
  1325.             if($request->get('studio_discount') == null)
  1326.             {
  1327.                 $studioDiscount 0;
  1328.             }
  1329.             else
  1330.             {
  1331.                 $studioDiscount $request->get('studio_discount');
  1332.             }
  1333.             if($request->get('visible') == null)
  1334.             {
  1335.                 $visible 0;
  1336.             }
  1337.             else
  1338.             {
  1339.                 $visible $request->get('visible');
  1340.             }
  1341.             if($request->get('discount') == null)
  1342.             {
  1343.                 $discount 0;
  1344.             }
  1345.             else
  1346.             {
  1347.                 $discount $request->get('discount');
  1348.             }
  1349.             $course->setCName($request->get('coursename'));
  1350.             $course->setCNumber($request->get('coursenumber'));
  1351.             if( is_null($request->get('coursesbnumber')) )
  1352.             {
  1353.                 $course->setCSbNumber(0);
  1354.             }
  1355.             else
  1356.             {
  1357.                 $course->setCSbNumber($request->get('coursesbnumber'));
  1358.             }
  1359.             $course->setCYoga($yoga);
  1360.             $course->setCLeader($request->get('courseleader'));
  1361.             $course->setCCategory($request->get('coursecategory'));
  1362.             $course->setCMaxcustomer($request->get('maxcustomer'));
  1363.             $course->setCOfflineCustomer($request->get('offlinecustomer'));
  1364.             $course->setCStart($start);
  1365.             $course->setCEnd($end);
  1366.             if( is_null($request->get('duration')) )
  1367.             {
  1368.                 $course->setCDuration(0);
  1369.             }
  1370.             else
  1371.             {
  1372.                 $course->setCDuration($request->get('duration'));
  1373.             }
  1374.             $course->setCDiscount($discount);
  1375.             $course->setCSiblingDiscount($siblingDiscount);
  1376.             $course->setCStudioDiscount($studioDiscount);
  1377.             $course->setCVisibleFrom($visible_from);
  1378.             $course->setCVisible($visible);
  1379.             $course->setCPeriod($request->get('courseperiod'));
  1380.             
  1381.             $bb $request->get('break_before');
  1382.             $ba $request->get('break_after');
  1383.             if(intval($bb) < 0){$bb 0;}
  1384.             if(intval($ba) < 0){$ba 0;}
  1385.             $course->setCBreakBefore($bb);
  1386.             $course->setCBreakAfter($ba);
  1387.             $course->setCDescription($request->get('description'));
  1388.             $course->setCPrice($price);
  1389.             $course->setCAdminFee$adminFee );
  1390.             $course->setCTax($tax);
  1391.             $course->setCActive(1);
  1392.             if($company == 'KVO')
  1393.             {
  1394.                 $course->setCRoom($request->get('room'));
  1395.             }
  1396.             else
  1397.             {
  1398.                 $course->setCRoom(0);
  1399.             }
  1400.             $course->setCCostplace($request->get('costplace'));
  1401.             $course->setCAppointmentSeries($request->get('series'));
  1402.             $course->setCAppointmentSeriesDays($request->get('seriesDays'));
  1403.             
  1404.             $mon $request->get('monday');
  1405.             if(is_null($mon)) {$mon 0;}
  1406.             $tue $request->get('tuesday');
  1407.             if(is_null($tue)) {$tue 0;}
  1408.             $wed $request->get('wednesday');
  1409.             if(is_null($wed)) {$wed 0;}
  1410.             $thu $request->get('thursday');
  1411.             if(is_null($thu)) {$thu 0;}
  1412.             $fri $request->get('friday');
  1413.             if(is_null($fri)) {$fri 0;}
  1414.             $sat $request->get('saturday');
  1415.             if(is_null($sat)) {$sat 0;}
  1416.             $sun $request->get('sunday');
  1417.             if(is_null($sun)) {$sun 0;}
  1418.             $course->setCMonday($mon);
  1419.             $course->setCTuesday($tue);
  1420.             $course->setCWednesday($wed);
  1421.             $course->setCThursday($thu);
  1422.             $course->setCFriday($fri);
  1423.             $course->setCSaturday($sat);
  1424.             $course->setCSunday($sun);
  1425.             
  1426.             $course->setCPlace(1);
  1427.             $d = new \DateTime(date('Y-m-d H:i:s',strtotime($request->get('activeUntill'))));
  1428.             $course->setCActiveUntill($d);
  1429.             
  1430.             $d2 = new \DateTime(date('Y-m-d H:i:s',strtotime($request->get('activeFrom'))));
  1431.             $course->setCActiveFrom($d2);
  1432.             $em $this->getDoctrine()->getManager();
  1433.             $em->persist($course);
  1434.             $em->flush();
  1435.             //save Images  
  1436.             $pic $request->files->get('courseImage');
  1437.             $pic2 $request->files->get('courseImageFull');
  1438.             if($pic != "")
  1439.             {
  1440.                 $repository $this->getDoctrine()->getRepository(CourseImages::class);
  1441.                 $pics $repository->findOneBy(['ci_cid' => $id]);
  1442.                 $full $pics->getCiFullPath();
  1443.                 $em $this->getDoctrine()->getManager();
  1444.                 $em->remove($pics);
  1445.                 $em->flush();
  1446.                 $folder =  $this->getParameter('kernel.project_dir')."/public/courseImages/";
  1447.                 if(!file_exists($folder)){mkdir($folder);}
  1448.                 
  1449.                 $subfolder $folder.$id."/";
  1450.                 if(!file_exists($subfolder)){ mkdir($subfolder); }
  1451.                 $uniqid uniqid();
  1452.                 $path $subfolder.$uniqid."_".$pic->getClientOriginalName();
  1453.                 if(file_exists($path)){unlink($path);}
  1454.                 $newFilename $uniqid.'_'.$pic->getClientOriginalName();
  1455.                 $pic->move($subfolder$newFilename);
  1456.                 $courseImages = new CourseImages();
  1457.                 $courseImages->setCiCid($id);
  1458.                 $courseImages->setCiPath(str_replace($publicImagePath,'.',$path));
  1459.                 $courseImages->setCiFullPath($full);
  1460.                 $em->persist($courseImages);
  1461.                 $em->flush();
  1462.             }
  1463.             if($pic2 != "")
  1464.             {
  1465.                 $repository $this->getDoctrine()->getRepository(CourseImages::class);
  1466.                 $pics $repository->findOneBy(['ci_cid' => $id]);
  1467.                 $path1 $pics->getCiPath();
  1468.                 $em $this->getDoctrine()->getManager();
  1469.                 $em->remove($pics);
  1470.                 $em->flush();
  1471.                 $folder =  $this->getParameter('kernel.project_dir')."/public/courseImages/";
  1472.                 if(!file_exists($folder)){mkdir($folder);}
  1473.                 
  1474.                 $subfolder $folder.$id."/";
  1475.                 if(!file_exists($subfolder)){ mkdir($subfolder); }
  1476.                 $uniqid uniqid();
  1477.                 $path2 $subfolder.$uniqid."_".$pic2->getClientOriginalName();
  1478.                 if(file_exists($path2)){unlink($path2);}
  1479.                 $newFilename2 $uniqid.'_'.$pic2->getClientOriginalName();
  1480.                 $pic2->move($subfolder$newFilename2);
  1481.                 $courseImages = new CourseImages();
  1482.                 $courseImages->setCiCid($id);
  1483.                 $courseImages->setCiPath($path1);
  1484.                 $courseImages->setCiFullPath(str_replace($publicImagePath,'.',$path2));
  1485.                 $em->persist($courseImages);
  1486.                 $em->flush();
  1487.             }
  1488.             // save Course Times 
  1489.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1490.             $times $repository->findBy(['ctt_cid' => $id'ctt_offline_customer' => 0'ctt_online' => 0]);
  1491.             
  1492.             $em $this->getDoctrine()->getManager();
  1493.             $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  1494.             $courseAddTimes $repository->findBy(['cat_cid' => $id]);
  1495.             foreach($courseAddTimes as $cat)
  1496.             {
  1497.                
  1498.                 $em->remove($cat);
  1499.                 $em->flush();
  1500.             }
  1501.             foreach($times as $time)
  1502.             {
  1503.                 $repository $this->getDoctrine()->getRepository(OrderItems::class);
  1504.                 $item $repository->findBy(['oi_tid' => $time->getId()]);
  1505.         
  1506.                 $repository $this->getDoctrine()->getRepository(ManualAppointment::class);
  1507.                 $ma $repository->findBy(['ma_tid' => $time->getId()]);
  1508.         
  1509.                 if(!$item && !$ma)
  1510.                 {   
  1511.                     $em $this->getDoctrine()->getManager();
  1512.                     $em->remove($time);
  1513.                     $em->flush();
  1514.                 }
  1515.             }
  1516.             if($company == 'KVO')
  1517.             {
  1518.                 $begin = new \DateTime(date("Y-m-d",strtotime($request->get('activeFrom'))));
  1519.                 $endDate = new \DateTime(date('Y-m-d',strtotime('+1 day',strtotime($request->get('activeUntill')))));
  1520.                 $interval = \DateInterval::createFromDateString('1 day');
  1521.                 $period = new \DatePeriod($begin$interval$endDate);
  1522.                 //each day from start to activeUntill
  1523.                 foreach ($period as $dt
  1524.                 {
  1525.                 
  1526.                     $day1 $dt->format("Y-m-d \n"); 
  1527.                     $day = new \DateTime(date("Y-m-d"strtotime($day1)));
  1528.                     
  1529.                     
  1530.                     if($this->checkHoliday($dt->format("d.m.Y")) != false ){ continue; }
  1531.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCSunday() == 0) {continue; }
  1532.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCMonday() == 0) {continue; }
  1533.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCTuesday() == 0) {continue; }
  1534.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCWednesday() == 0) {continue; }
  1535.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCThursday() == 0) {continue; }
  1536.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCFriday() == 0) {continue; }
  1537.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $course->getCSaturday() == 0) {continue; }
  1538.                     $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1539.                 
  1540.                     while($d1 $end)
  1541.                     {
  1542.                     
  1543.                         $d1orig = new \DateTime(date('H:i:s',strtotime($d1->format('H:i:s')))); 
  1544.                         
  1545.                         $d1->add(new \DateInterval('PT' $request->get('duration') . 'M'));
  1546.                         
  1547.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1548.                         $time2 $repository->findBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1orig'ctt_to' => $d1'ctt_room' => $request->get('room')]);
  1549.                         
  1550.                         if(!$time2)
  1551.                         {
  1552.                             $courseTimes = new CourseTimes();
  1553.                             $courseTimes->setCttDay($day);
  1554.                             $courseTimes->setCttFrom($d1orig);
  1555.                             $courseTimes->setCttTo($d1);
  1556.                             $courseTimes->setCttCid($id);
  1557.                             $courseTimes->setCttNote('');
  1558.                             $courseTimes->setCttRoom($request->get('room'));
  1559.                             $courseTimes->setCttOfflineCustomer(0);
  1560.                             $courseTimes->setCttOnline(0);
  1561.                             $courseTimes->setCttNumber($request->get('coursenumber'));
  1562.                             $courseTimes->setCttMaxonline($request->get('maxcustomer'));
  1563.                             $courseTimes->setCttMaxoffline($request->get('offlinecustomer'));
  1564.                             
  1565.                             $em $this->getDoctrine()->getManager();
  1566.                             $em->persist($courseTimes);
  1567.                             $em->flush();
  1568.                         }
  1569.                 
  1570.                         $bb $request->get('break_before');
  1571.                         $ba $request->get('break_after');
  1572.                         if(intval($bb) < 0){$bb 0;}
  1573.                         if(intval($ba) < 0){$ba 0;}
  1574.                         $d1->add(new \DateInterval('PT' $bb 'M'));
  1575.                         $d1->add(new \DateInterval('PT' $ba 'M'));
  1576.                         
  1577.                     }
  1578.                     if($request->get('timesArr') != "")
  1579.                     {
  1580.                         //additional Times
  1581.                         $timesArr explode(',',$request->get('timesArr'));
  1582.                         foreach($timesArr as $time)
  1583.                         {
  1584.                             /*
  1585.                             if($company != "KVO")
  1586.                             {
  1587.                                 if($request->get('starttime'.$time) == $request->get('starttime') && $request->get('endtime'.$time) == $request->get('endtime')){continue;}
  1588.                             }
  1589.                             */
  1590.                             if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1591.                             {
  1592.                                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1593.                                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1594.                                 
  1595.                                 //if($compare1 == $d1 && $compare2 == $d2){continue;}
  1596.                                 
  1597.                                 while($d1 $d2)
  1598.                                 {
  1599.                                     
  1600.                                     $d1orig = new \DateTime(date('H:i:s',strtotime($d1->format('H:i:s')))); 
  1601.                                     
  1602.                                     $d1->add(new \DateInterval('PT' $request->get('duration') . 'M'));
  1603.                                     
  1604.                                     $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1605.                                     $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1orig'ctt_to' => $d1'ctt_room' => $request->get('room'.$time) ]);
  1606.                                     if($timetest)
  1607.                                     {
  1608.                 
  1609.                                         $bb $request->get('break_before');
  1610.                                         $ba $request->get('break_after');
  1611.                                         if(intval($bb) < 0){$bb 0;}
  1612.                                         if(intval($ba) < 0){$ba 0;}
  1613.         
  1614.                                         $d1->add(new \DateInterval('PT' $bb 'M'));
  1615.                                         $d1->add(new \DateInterval('PT' $ba 'M'));
  1616.                                         continue;
  1617.                                     }
  1618.                                     $courseTimes = new CourseTimes();
  1619.                                     $courseTimes->setCttDay($day);
  1620.                                     $courseTimes->setCttFrom($d1orig);
  1621.                                     $courseTimes->setCttTo($d1);
  1622.                                     $courseTimes->setCttCid($id);
  1623.                                     $courseTimes->setCttNote('');
  1624.                                     $courseTimes->setCttOfflineCustomer(0);
  1625.                                     $courseTimes->setCttNumber($request->get('coursenumber'.$time));
  1626.                                     $courseTimes->setCttRoom($request->get('room'.$time));
  1627.                                     
  1628.                                     $em->persist($courseTimes);
  1629.                                     
  1630.                                     $em->flush();
  1631.                 
  1632.                                     $bb $request->get('break_before');
  1633.                                     $ba $request->get('break_after');
  1634.                                     if(intval($bb) < 0){$bb 0;}
  1635.                                     if(intval($ba) < 0){$ba 0;}
  1636.                                     $d1->add(new \DateInterval('PT' $bb 'M'));
  1637.                                     $d1->add(new \DateInterval('PT' $ba 'M'));
  1638.                                 }
  1639.                             
  1640.                             }
  1641.                         }
  1642.                     }
  1643.                 }
  1644.             }
  1645.             else
  1646.             {
  1647.                 $days $request->get('courseDays');
  1648.                 $days explode(',',$days);
  1649.                 
  1650.                 foreach($days as $day)
  1651.                 {
  1652.                     $day = new \DateTime(date("Y-m-d"strtotime($day)));
  1653.                     if($request->get('starttime') != "" && $request->get('endtime') != "")
  1654.                     {
  1655.                         $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1656.                         $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1657.                         
  1658.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1659.                         $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1'ctt_to' => $d2'ctt_room' => $request->get('room') ]);
  1660.                         if($timetest)
  1661.                         {
  1662.                             continue;
  1663.                         }
  1664.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1665.                         $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1'ctt_to' => $d1'ctt_number' => $request->get('coursenumber') ]);
  1666.                         if($timetest){ continue; }
  1667.                         $courseTimes = new CourseTimes();
  1668.                         $courseTimes->setCttDay($day);
  1669.                         $courseTimes->setCttFrom($d1);
  1670.                         $courseTimes->setCttTo($d2);
  1671.                         $courseTimes->setCttCid($id);
  1672.                         $courseTimes->setCttNote('');
  1673.                         $courseTimes->setCttOfflineCustomer(0);
  1674.                         $courseTimes->setCttOnline(0);
  1675.                         $courseTimes->setCttNumber($request->get('coursenumber'));
  1676.                         $courseTimes->setCttRoom($request->get('room'));
  1677.                         $courseTimes->setCttMaxonline($request->get('courseMaxOnline'));
  1678.                         $courseTimes->setCttMaxoffline($request->get('courseMaxOffline'));
  1679.                         
  1680.                         $em->persist($courseTimes);
  1681.                         $em->flush();
  1682.                     }
  1683.                 }
  1684.                 if($request->get('courseTimesArr') != "")
  1685.                 {
  1686.                     //additional Times
  1687.                     $timesArr explode(',',$request->get('courseTimesArr'));
  1688.                     foreach($timesArr as $time)
  1689.                     {
  1690.                         
  1691.                         //GET Days
  1692.                         $days $request->get('courseDays'.$time);
  1693.                         $days explode(',',$days);
  1694.                         
  1695.                         foreach($days as $day)
  1696.                         {
  1697.                             $day = new \DateTime(date("Y-m-d"strtotime($day)));
  1698.                             //if($request->get('starttime'.$time) == $request->get('starttime') && $request->get('endtime'.$time) == $request->get('endtime')){continue;}
  1699.                             
  1700.                             if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1701.                             {
  1702.                                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1703.                                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1704.                                 
  1705.                                 $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1706.                                 $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1'ctt_to' => $d2'ctt_room' => $request->get('room'.$time) ]);
  1707.                                 if($timetest)
  1708.                                 {
  1709.                                     continue;
  1710.                                 }
  1711.                                 $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1712.                                 $timetest $repository->findOneBy(['ctt_cid' => $id'ctt_day' => $day'ctt_from' => $d1'ctt_to' => $d1'ctt_number' => $request->get('coursenumber'.$time) ]);
  1713.                                 if($timetest){ continue; }
  1714.                                 $courseTimes = new CourseTimes();
  1715.                                 $courseTimes->setCttDay($day);
  1716.                                 $courseTimes->setCttFrom($d1);
  1717.                                 $courseTimes->setCttTo($d2);
  1718.                                 $courseTimes->setCttCid($id);
  1719.                                 $courseTimes->setCttNote('');
  1720.                                 $courseTimes->setCttOfflineCustomer(0);
  1721.                                 $courseTimes->setCttOnline(0);
  1722.                                 $courseTimes->setCttNumber($request->get('coursenumber'.$time));
  1723.                                 $courseTimes->setCttRoom($request->get('room'.$time));
  1724.                                 $courseTimes->setCttMaxonline($request->get('courseMaxOnline'.$time));
  1725.                                 $courseTimes->setCttMaxoffline($request->get('courseMaxOffline'.$time));
  1726.                                 
  1727.                                 $em->persist($courseTimes);
  1728.                                 
  1729.                                 $em->flush();
  1730.                             }
  1731.                         }
  1732.                     }
  1733.                 }
  1734.             }
  1735.             if($company == "KVO")
  1736.             {
  1737.                 $timesArr explode(',',$request->get('timesArr'));
  1738.             }
  1739.             else
  1740.             {
  1741.                 $timesArr explode(',',$request->get('courseTimesArr'));
  1742.             }
  1743.             foreach($timesArr as $time)
  1744.             {
  1745.                 if($time == ""){ continue; }
  1746.                 /*
  1747.                 if($company != "KVO")
  1748.                 {
  1749.                     if($request->get('starttime'.$time) == $request->get('starttime') && $request->get('endtime'.$time) == $request->get('endtime')){continue;}
  1750.                 }
  1751.                 */
  1752.                 if($request->get('starttime'.$time) != "" && $request->get('endtime'.$time) != "")
  1753.                 {
  1754.                     //$d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1755.                     //$d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1756.                     $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'.$time))));
  1757.                     $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'.$time))));
  1758.                 
  1759.                     $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  1760.                     if($company == "KVO")
  1761.                     {
  1762.                         $timetest $repository->findOneBy(['cat_cid' => $id'cat_from' => $d1'cat_to' => $d2'cat_room' => $request->get('room'.$time) ]);
  1763.                         if($timetest)
  1764.                         {
  1765.                             continue;
  1766.                         }
  1767.                     }
  1768.                     /*else
  1769.                     {
  1770.                         $timetest = $repository->findOneBy(['cat_cid' => $id, 'cat_from' => $d1, 'cat_to' => $d2, 'cat_room' => 0 ]);
  1771.                     }
  1772.                     */
  1773.                     
  1774.                     $courseAddTimes = new CourseAdditionalTimes();
  1775.                     $courseAddTimes->setCatCid($id);
  1776.                     $courseAddTimes->setCatFrom($d1);
  1777.                     $courseAddTimes->setCatTo($d2);
  1778.                     $courseAddTimes->setCatItem($time);
  1779.                     if($company == 'KVO')
  1780.                     {
  1781.                         if(!is_null($request->get('room'.$time)))
  1782.                         {
  1783.                             $courseAddTimes->setCatRoom($request->get('room'.$time));
  1784.                         }
  1785.                         else
  1786.                         {
  1787.                             $courseAddTimes->setCatRoom(0);
  1788.                         }    
  1789.                         $courseAddTimes->setCatLeader(0);
  1790.                         $courseAddTimes->setCatDays('');
  1791.                         $courseAddTimes->setCatNumber(0);
  1792.                         $courseAddTimes->setCatBookingOption(0);
  1793.                     }
  1794.                     else
  1795.                     {
  1796.                         $courseAddTimes->setCatRoom(0);
  1797.                         $courseAddTimes->setCatLeader($request->get('courseleader'.$time));
  1798.                         $courseAddTimes->setCatDays($request->get('courseDays'.$time));
  1799.                         $courseAddTimes->setCatNumber($request->get('coursenumber'.$time));
  1800.                         $courseAddTimes->setCatBookingOption($request->get('booking_option'.$time));
  1801.                         
  1802.                     }
  1803.                     $courseAddTimes->setCatMaxOnline($request->get('courseMaxOnline'.$time));
  1804.                     $courseAddTimes->setCatMaxOffline($request->get('courseMaxOffline'.$time));
  1805.                     $em->persist($courseAddTimes);
  1806.                     $em->flush();
  1807.                 }
  1808.             }
  1809.             if($company != "KVO")
  1810.             {
  1811.                 //$d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1812.                 //$d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1813.                 $d1 = new \DateTime(date("H:i:s",strtotime($request->get('starttime'))));
  1814.                 $d2 = new \DateTime(date("H:i:s",strtotime($request->get('endtime'))));
  1815.                 $courseAddTimes = new CourseAdditionalTimes();
  1816.                 $courseAddTimes->setCatCid($id);
  1817.                 $courseAddTimes->setCatFrom($d1);
  1818.                 $courseAddTimes->setCatTo($d2);
  1819.                 $courseAddTimes->setCatItem(0);
  1820.                 $courseAddTimes->setCatRoom(0);
  1821.                 $courseAddTimes->setCatLeader($request->get('courseleader'));
  1822.                 $courseAddTimes->setCatDays($request->get('courseDays'));
  1823.                 $courseAddTimes->setCatNumber($request->get('coursenumber'));
  1824.                 $courseAddTimes->setCatBookingOption($request->get('booking_option'));
  1825.                 $courseAddTimes->setCatMaxOnline($request->get('courseMaxOnline'));
  1826.                 $courseAddTimes->setCatMaxOffline($request->get('courseMaxOffline'));
  1827.                 
  1828.                 $em->persist($courseAddTimes);
  1829.                 $em->flush();
  1830.             }
  1831.         } 
  1832.         else if($request->get('mode') == '2' || $request->get('mode') == 2)
  1833.         {
  1834.             $price str_replace(".","#",$request->get('price2'));
  1835.             $price str_replace(",",".",$price);
  1836.             $price str_replace("#",",",$price);
  1837.             $price number_format($price,2,'.',',');
  1838.             $tax number_format((float)$request->get('tax2'),2,'.',',');
  1839.             $repository $this->getDoctrine()->getRepository(Article::class);
  1840.             $article $repository->findOneBy(['id' => $request->get('articleID')]);
  1841.             $id $request->get('articleID');
  1842.             $article->setAName($request->get('articlename'));
  1843.             $article->setASbNumber($request->get('coursesbnumber2'));
  1844.             $article->setACategory($request->get('coursecategory2'));
  1845.             $article->setADescription($request->get('description2'));
  1846.             $article->setAPrice($price);
  1847.             $article->setATax($tax);
  1848.             $article->setAActive(1);
  1849.             $article->setAPlace(1);
  1850.             $article->setACostplace($request->get('costplace2'));
  1851.             $article->setADiscount($request->get('discount2'));
  1852.             
  1853.             $em $this->getDoctrine()->getManager();
  1854.             $em->persist($article);
  1855.             $em->flush();
  1856.         
  1857.              //save Images  
  1858.              $pic $request->files->get('courseImage2');
  1859.              if($pic != "")
  1860.              {
  1861.                  $repository $this->getDoctrine()->getRepository(ArticleImages::class);
  1862.                  $pics $repository->findOneBy(['ai_aid' => $id]);
  1863.  
  1864.                  $em $this->getDoctrine()->getManager();
  1865.                  $em->remove($pics);
  1866.                  $em->flush();
  1867.  
  1868.                  $folder =  $this->getParameter('kernel.project_dir')."/public/courseImages/";
  1869.                  if(!file_exists($folder)){mkdir($folder);}
  1870.                  
  1871.                  $subfolder $folder.$id."/";
  1872.                  if(!file_exists($subfolder)){mkdir($subfolder);}
  1873.  
  1874.                  $uniqid uniqid();
  1875.  
  1876.                  $path $subfolder.$uniqid."_".$pic->getClientOriginalName();
  1877.                  if(file_exists($path)){unlink($path);}
  1878.  
  1879.                  $newFilename $uniqid.'_'.$pic->getClientOriginalName();
  1880.                  $pic->move($subfolder$newFilename);
  1881.  
  1882.                  $articleImages = new ArticleImages();
  1883.                  $articleImages->setAiAid($id);
  1884.                  $articleImages->setAiPath(str_replace($publicImagePath,'.',$path));
  1885.                  $em->persist($articleImages);
  1886.                  $em->flush();
  1887.              }
  1888.             
  1889.         }
  1890.         $response $this->forward('App\Controller\CourseController::backendCourse', []);
  1891.         return $response;
  1892.         
  1893.     }
  1894.     /**
  1895.     * @Route("/loadContent/{category}/{period}", name="loadContent")
  1896.     */
  1897.     public function loadContent($category,$period)
  1898.     {
  1899.         include("./include/global.php");
  1900.         include("./include/function.php");
  1901.         
  1902.         if($category == ""){$category '0';}
  1903.         $place '0';
  1904.         if($place == '0')
  1905.         {
  1906.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  1907.             $place $session->get('place');
  1908.         } 
  1909.         $d1 = new \DateTime(date("Y-m-d"));
  1910.         
  1911.         $em2 $this->getDoctrine()->getManager();   
  1912.                     
  1913.         
  1914.         if($company == 'KVO')
  1915.         {
  1916.             $query "UPDATE course SET c_active = 0  WHERE c_active_untill < :date ";
  1917.             $statement $em2->getConnection()->prepare($query);
  1918.             $statement->bindValue('date',date("Y-m-d"));
  1919.             $statement->execute();
  1920.             
  1921.         }
  1922.         else
  1923.         {
  1924.   /*
  1925.             $query = "SELECT * FROM course WHERE c_active = 1";
  1926.             
  1927.             $course = $em2->getConnection()->prepare($query);
  1928.             $course->bindValue('category',$category);
  1929.             $course->execute();
  1930.             $course2 = $course->fetchAll();
  1931. */
  1932.             if($period == 0)
  1933.             {
  1934.                 $repository $this->getDoctrine()->getRepository(Course::class);
  1935.                 $course $repository->findBy(['c_active' => '1','c_category' => $category]);
  1936.             }
  1937.             else
  1938.             {
  1939.                 $repository $this->getDoctrine()->getRepository(Course::class);
  1940.                 $course $repository->findBy(['c_active' => '1','c_category' => $category'c_period' => $period]);
  1941.             }
  1942.             //            foreach($course2 as $cours)
  1943.             foreach($course as $cours)
  1944.             {
  1945.                 $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  1946.                 $times $repository->findOneBy(['ctt_cid' => $cours->getId()],['ctt_day' => 'DESC']);
  1947.                 if($times)
  1948.                 {
  1949.                     $tmp $times->getCttDay();
  1950.                     $tmp $tmp->format('Y-m-d');
  1951.                     
  1952.                     if($tmp date("Y-m-d"))
  1953.                     {
  1954.                         $query "UPDATE course SET c_active = 0  WHERE id = :id ";
  1955.                         $statement $em2->getConnection()->prepare($query);
  1956.                         $statement->bindValue('id',$times->getCttCid());
  1957.                         $statement->execute();
  1958.                     }
  1959.                 }
  1960.             }
  1961.         }
  1962.         
  1963.         $em2 $this->getDoctrine()->getManager();   
  1964.         if($company != "KVO")
  1965.         {
  1966.             if($period == 0)
  1967.             {
  1968.                 //$query = "SELECT * FROM course WHERE c_category = :category AND c_active = 1  AND c_visible_from <= :visible ORDER BY c_period DESC, c_name ASC";
  1969.                 $query "SELECT * FROM course WHERE c_category = :category AND c_visible_from <= :visible ORDER BY c_period DESC, c_name ASC";
  1970.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s") ]);
  1971.             }
  1972.             else
  1973.             {
  1974.                 //$query = "SELECT * FROM course WHERE c_category = :category AND c_active = 1  AND c_visible_from <= :visible  ORDER BY c_period DESC, c_name ASC";
  1975.                 $query "SELECT * FROM course WHERE c_category = :category AND c_visible_from <= :visible  ORDER BY c_period DESC, c_name ASC";
  1976.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s") ]);
  1977.             }
  1978.         }
  1979.         else
  1980.         {
  1981.             $query "SELECT * FROM course WHERE c_category = :category AND c_active = 1 ORDER BY c_name ASC";
  1982.             $course $em2->getConnection()->executeQuery($query,['category' => $category ]);
  1983.         }
  1984.                                 
  1985.         
  1986.         $output '';
  1987.         $output .= '<div class="class">';
  1988.         $output .= '<div class="container">';
  1989.         
  1990.         $output .= '<div class="section-header text-center wow zoomIn" data-wow-delay="0.1s" style="visibility: visible; animation-delay: 0.1s; animation-name: zoomIn;">';
  1991.         $output .= '    <p>Unsere Kurse</p>';
  1992.         $output .= '</div>';
  1993.         
  1994.         $lastperiod 0;
  1995.         $output .= '<div class="row" id="periodFilter">';
  1996.         $output .= '<div class="col-12">';
  1997.         $output .= '    <ul id="class-filter">';
  1998.         if($period == 0)
  1999.         {
  2000.             $output .= '        <li data-filter="*" class="filter-active">Alle Perioden</li>';
  2001.         }
  2002.         else
  2003.         {
  2004.             $output .= '        <li data-filter="*" onclick="periodFilter(\''.$url.'\',0);" >Alle Perioden</li>';
  2005.         }
  2006.         foreach($course as $cours)
  2007.         {
  2008.             if($cours['c_period'] == 0){ continue; }
  2009.             $cont false;
  2010.             if($place != "0")
  2011.             {
  2012.                 
  2013.                 $repository $this->getDoctrine()->getRepository(CostPlace::class);
  2014.                 $costplace $repository->findBy(['cp_active' => 1'cp_place' => $place]);
  2015.                 foreach($costplace as $cp)
  2016.                 {
  2017.                     if($cours['c_costplace'] == $cp->getId() )
  2018.                     {
  2019.                        $cont true;
  2020.                     }
  2021.                 }
  2022.             }
  2023.             if(!$cont)
  2024.             {
  2025.                 continue;
  2026.             }
  2027.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2028.             $times $repository->findOneBy(['ctt_cid' => $cours['id']],['ctt_day' => 'DESC']);
  2029.             $contTime false;
  2030.             if($times)
  2031.             {
  2032.                 $tmp $times->getCttDay();
  2033.                 $tmp $tmp->format('Y-m-d');
  2034.                 
  2035.                 if($tmp date("Y-m-d"))
  2036.                 {
  2037.                     $contTime true;
  2038.                 }
  2039.             }
  2040.             if($contTime == true){ continue; }
  2041.             
  2042.             if($lastperiod == || $lastperiod != $cours['c_period'])
  2043.             {
  2044.                 // show period
  2045.                 if($period == $cours['c_period'])
  2046.                 {
  2047.                     $output .= '        <li data-filter="*" class="filter-active" >'.$globalPeriods[$cours['c_period']].'</li>';
  2048.                 }
  2049.                 else
  2050.                 {
  2051.                     $output .= '        <li data-filter="*" onclick="periodFilter(\''.$url.'\','.$cours['c_period'].');">'.$globalPeriods[$cours['c_period']].'</li>';
  2052.                 }
  2053.             }
  2054.             $lastperiod $cours['c_period'];
  2055.             
  2056.         }
  2057.         $output .= '</ul>';
  2058.         $output .= '</div>';
  2059.         $output .= '</div>';
  2060.         $anzProd $globAmnProd;
  2061.         $i 0;
  2062.         $firstUsed false;
  2063.         //foreach($course as $cours)
  2064.         $lastperiod 0;
  2065.         if($company != "KVO")
  2066.         {
  2067.             if($period == 0)
  2068.             {
  2069.                 $query "SELECT id FROM course WHERE c_category = :category AND  (c_active_untill = '1970-01-01' OR c_active_from = '1970-01-01')  AND c_visible_from <= :visible ORDER BY  c_period DESC, c_name ASC";
  2070.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s") ]);
  2071.             }
  2072.             else
  2073.             {
  2074.                 $query "SELECT id FROM course WHERE c_category = :category AND  (c_active_untill = '1970-01-01' OR c_active_from = '1970-01-01')  AND c_visible_from <= :visible AND c_period = :period ORDER BY  c_period DESC, c_name ASC";
  2075.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s"), 'period' => $period ]);
  2076.             }
  2077.             foreach($course as $cours)
  2078.             {
  2079.                 $query3 "SELECT MIN(ctt_day) AS mindat, MAX(ctt_day) AS maxdat FROM course_times WHERE ctt_cid = :cid ";
  2080.                 $result $em2->getConnection()->executeQuery($query3,['cid' => $cours['id'] ]);
  2081.                 while (($row $result->fetchAssociative()) !== false)
  2082.                 {
  2083.                     $query4 "UPDATE course SET c_active_from = :min , c_active_untill = :max  WHERE id = :id ";
  2084.                     $statement $em2->getConnection()->prepare($query4);
  2085.                     $statement->bindValue('min',$row['mindat']);
  2086.                     $statement->bindValue('max',$row['maxdat']);
  2087.                     $statement->bindValue('id',$cours['id']);
  2088.                     $statement->execute();
  2089.                 }
  2090.             }
  2091.         }
  2092.         $query "SELECT * FROM course WHERE c_category = :category AND c_visible_from <= :visible AND c_period = :period ORDER BY  c_period DESC, c_name ASC";
  2093.         $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s"), 'period' => $period ]);
  2094.     
  2095.         if($company != "KVO")
  2096.         {
  2097.             if($period == 0)
  2098.             {
  2099.                 $query "SELECT * FROM course WHERE c_category = :category AND  c_visible_from <= :visible ORDER BY c_active_from DESC, c_period DESC, c_name ASC";
  2100.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s") ]);
  2101.             }
  2102.             else
  2103.             {
  2104.                 $query "SELECT * FROM course WHERE c_category = :category AND c_visible_from <= :visible AND c_period = :period ORDER BY c_active_from DESC, c_period DESC, c_name ASC";
  2105.                 $course $em2->getConnection()->executeQuery($query,['category' => $category'visible' => date("Y-m-d H:i:s"), 'period' => $period ]);
  2106.             }
  2107.         }
  2108.         else
  2109.         {
  2110.             $query "SELECT * FROM course WHERE c_category = :category AND c_active = 1 ORDER BY c_name ASC";
  2111.             $course $em2->getConnection()->executeQuery($query,['category' => $category ]);
  2112.         }
  2113.         foreach($course as $cours)
  2114.         {
  2115.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2116.             $times $repository->findOneBy(['ctt_cid' => $cours['id']],['ctt_day' => 'DESC']);
  2117.             $contTime false;
  2118.             if($times)
  2119.             {
  2120.                 $tmp $times->getCttDay();
  2121.                 $tmp $tmp->format('Y-m-d');
  2122.                 
  2123.                 if($tmp date("Y-m-d"))
  2124.                 {
  2125.                     $contTime true;
  2126.                 }
  2127.             }
  2128.             if($contTime == true){ continue; }
  2129.             if($cours['c_period'] == 0){ continue; }
  2130.             $cont false;
  2131.             if($place != "0")
  2132.             {
  2133.                 
  2134.                 $repository $this->getDoctrine()->getRepository(CostPlace::class);
  2135.                 $costplace $repository->findBy(['cp_active' => 1'cp_place' => $place]);
  2136.                 foreach($costplace as $cp)
  2137.                 {
  2138.                     if($cours['c_costplace'] == $cp->getId() )
  2139.                     {
  2140.                        $cont true;
  2141.                     }
  2142.                 }
  2143.             }
  2144.             if(!$cont)
  2145.             {
  2146.                 continue;
  2147.             }
  2148.             
  2149.             //only employee
  2150.             if($cours['c_visible'] == '1')
  2151.             {
  2152.                 if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  2153.                 {
  2154.                     //Guest
  2155.                     continue;
  2156.                 }
  2157.                 else
  2158.                 {
  2159.                     $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2160.                     $role $uid2->getURole();
  2161.                     
  2162.                     if($role == || $role == 2)
  2163.                     {
  2164.                         //Customer
  2165.                         continue;
  2166.                     }
  2167.                 }
  2168.             }
  2169.                         
  2170.             //if first entries of the course are full then skip course. 
  2171.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2172.             $cit $repository->findBy(['ctt_cid' => $cours['id']],['ctt_day' => 'ASC']);
  2173.             $weekdays = array();
  2174.             $stopit false;
  2175.             $weekday_counter = array();
  2176.             $active 0;
  2177.             $active2 0;
  2178.             foreach($cit as $days )
  2179.             {
  2180.                 if($days->getCttDay()->format('Y-m-d') < date('Y-m-d')){ continue; }
  2181.                 $tmp $days->getCttDay();
  2182.                 $tmp $tmp->format('d-m-Y');
  2183.                 if(array_key_exists(date('N'strtotime($tmp)),$weekday_counter))
  2184.                 {
  2185.                     if($weekday_counter[date('N'strtotime($tmp))] == 2){ continue; }
  2186.                 }
  2187.                 //if($weekday_counter[date('N', strtotime($tmp))] == ""){ $weekday_counter[date('N', strtotime($tmp))] = 0; }
  2188.                 if(!array_key_exists(date('N'strtotime($tmp)),$weekday_counter)){  $weekday_counter[date('N'strtotime($tmp))] = 0; }
  2189.                 if( $days->getCttOnline() <  $days->getCttMaxonline())
  2190.                 {
  2191.                     $active 1
  2192.                 }
  2193.                 if($days->getCttOfflineCustomer() <  $days->getCttMaxoffline() && $days->getCttOnline() >=  $days->getCttMaxonline())
  2194.                 {
  2195.                     $active2 1;
  2196.                 }
  2197.                 if($days->getCttOfflineCustomer() >=  $days->getCttMaxoffline() && $days->getCttOnline() >=  $days->getCttMaxonline())
  2198.                 {
  2199.                     $weekdays[date('N'strtotime($tmp))] = 1;
  2200.                     $weekday_counter[date('N'strtotime($tmp))] = $weekday_counter[date('N'strtotime($tmp))] + 1;
  2201.                 }
  2202.                 else
  2203.                 {
  2204.                     $weekdays[date('N'strtotime($tmp))] = 0;
  2205.                     $weekday_counter[date('N'strtotime($tmp))] = $weekday_counter[date('N'strtotime($tmp))] + 1;
  2206.                     //break;                    
  2207.                 }
  2208.             }
  2209.             foreach($weekdays as $we)
  2210.             {
  2211.                 if($we == 1){ $stopit true; break; }
  2212.             }
  2213.             if($stopit == true)
  2214.             {
  2215.                 //continue;
  2216.             }
  2217.             
  2218.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2219.             $cit $repository->findBy(['ctt_cid' => $cours['id']],['ctt_day' => 'ASC']);
  2220.             foreach($cit as $days )
  2221.             {
  2222.                 if( $days->getCttOnline() <  $days->getCttMaxonline())
  2223.                 {
  2224.                     $active 1
  2225.                 }
  2226.                 if($days->getCttOfflineCustomer() <  $days->getCttMaxoffline() && $days->getCttOnline() >=  $days->getCttMaxonline())
  2227.                 {
  2228.                     $active2 1;
  2229.                 }
  2230.             }
  2231.             
  2232.             //display
  2233.             $repository $this->getDoctrine()->getRepository(CourseImages::class);
  2234.             $image $repository->findOneBy(['ci_cid' => $cours['id']]);
  2235.             
  2236.             if($lastperiod == || $lastperiod != $cours['c_period'])
  2237.             {
  2238.                 // show period
  2239.                 if($lastperiod != 0)
  2240.                 {
  2241.                     $output .= '</div>';
  2242.                 }
  2243.                 $output .= '<h3>'.$globalPeriods[$cours['c_period']].' '.date("Y",strtotime($cours['c_active_from'])).'</h3>';
  2244.                 $output .= '<div class="row class-container">';
  2245.                 $i 0;
  2246.             }
  2247.             $lastperiod $cours['c_period'];
  2248.             if($i == 0)
  2249.             {
  2250.                 $firstUsed true;
  2251.                 if($active == '1')
  2252.                 {
  2253.                     $output .= '<div id="first" class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer" onclick="openArticle('.$cours['id'].',\''.$url.'\',\'1\' )">';
  2254.                 }
  2255.                 else
  2256.                 {
  2257.                     $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2258.                     if(is_object($uid2))
  2259.                     {
  2260.                         $role $uid2->getURole();
  2261.                     }
  2262.                     else
  2263.                     {
  2264.                         $role 0;
  2265.                     }
  2266.                     
  2267.                     if($active2 '1' && $role >= )
  2268.                     {
  2269.                         $output .= '<div id="first" class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer" onclick="openArticle('.$cours['id'].',\''.$url.'\',\'1\' )">';
  2270.                     }
  2271.                     else
  2272.                     {
  2273.                         $output .= '<div id="first" class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer">';
  2274.                     }
  2275.                 }
  2276.             }
  2277.             else
  2278.             {
  2279.                 if($active == '1')
  2280.                 {
  2281.                     $output .= '<div class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer" onclick="openArticle('.$cours['id'].',\''.$url.'\',\'1\' )">';
  2282.                 }
  2283.                 else
  2284.                 {
  2285.                     $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2286.                     if(is_object($uid2))
  2287.                     {
  2288.                         $role $uid2->getURole();
  2289.                     }
  2290.                     else
  2291.                     {
  2292.                         $role 0;
  2293.                     }
  2294.                     if($active2 '1' && $role >= )
  2295.                     {
  2296.                         $output .= '<div class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer" onclick="openArticle('.$cours['id'].',\''.$url.'\',\'1\' )">';
  2297.                     }
  2298.                     else 
  2299.                     {
  2300.                         $output .= '<div class="col-lg-4 col-md-6 col-sm-12 class-item filter-1 wow fadeInUp" data-wow-delay="0.0s" style="cursor:pointer">';
  2301.                     }
  2302.                 }
  2303.             }
  2304.             $output .= '<div class="class-wrap">';
  2305.             $output .= '<div class="class-img">';
  2306.             if($active == '1')
  2307.             {
  2308.                 $output .= '<img src="'.$url.$image->getCiPath().'">';
  2309.             }
  2310.             else
  2311.             {
  2312.                 $output .= '<img src="'.$url.$image->getCiFullPath().'">';
  2313.             }
  2314.             $output .= '</div>';
  2315.           //  $output .= '<span style="'.$defaultColor.'" >'.$cours['c_name'].'</span><br>';
  2316.             $output .= '<div class="class-text">';
  2317.             //$output .= '<div class="class-teacher">';
  2318.             //$output .= '    <img src="" alt="Image">';
  2319.             //$output .= '    <h3>Johannes der Täufer</h3>';
  2320.             //$output .= '    <a href="">+</a>';
  2321.             //$output .= '</div>';
  2322.             $output .= '<h2>'.$cours['c_name'].'</h2>';
  2323.             $output .= '<div class="class-meta">';
  2324.             //$output .= '    <p><i class="far fa-calendar-alt"></i>Sun, Tue, Thu</p>';
  2325.             //$output .= '    <p><i class="far fa-clock"></i>9:00 - 10:00</p>';
  2326.         
  2327.             $output .= '</div>';
  2328.             $output .= '</div>';
  2329.             $output .= '</div>';
  2330.             $output .= '</div>';
  2331.             
  2332.             $i++;
  2333.         }
  2334.         $repository $this->getDoctrine()->getRepository(Article::class);
  2335.         /*
  2336.         if($place == '0' && $category != '0')
  2337.         {
  2338.             $article = $repository->findBy(['a_category' => $category, 'a_active' => 1]);
  2339.         }
  2340.         else
  2341.         {
  2342.             $article = $repository->findBy(['a_active' => 1]);
  2343.         }
  2344.         */
  2345.         $article $repository->findBy(['a_category' => $category'a_active' => 1]);
  2346.         
  2347.         foreach($article as $art)
  2348.         {
  2349.             $cont false;
  2350.             if($place != "0")
  2351.             {
  2352.                 
  2353.                 $repository $this->getDoctrine()->getRepository(CostPlace::class);
  2354.                 $costplace $repository->findBy(['cp_active' => 1'cp_place' => $place]);
  2355.                 foreach($costplace as $cp)
  2356.                 {
  2357.                     if($art->getACostplace() == $cp->getId() )
  2358.                     {
  2359.                        $cont true;
  2360.                     }
  2361.                 }
  2362.             }
  2363.             /*
  2364.             else
  2365.             {
  2366.                 $cont = true; 
  2367.             }
  2368.             */
  2369.             if(!$cont)
  2370.             {
  2371.                 continue;
  2372.             }
  2373.             $repository $this->getDoctrine()->getRepository(ArticleImages::class);
  2374.             $image $repository->findOneBy(['ai_aid' => $art->getid()]);
  2375.             if($i == && $firstUsed == false)
  2376.             {
  2377.                 $firstUsed true;
  2378.                 $output .= '<div id="first" class="col-sm" align="left" style="cursor:pointer" onclick="openArticle('.$art->getid().',\''.$url.'\', \'2\' )">';
  2379.             }
  2380.             else
  2381.             {
  2382.                 $output .= '<div class="col-sm" align="left" style="cursor:pointer" onclick="openArticle('.$art->getid().',\''.$url.'\', \'2\' )">';
  2383.             }
  2384.             $output .= '<div  style="max-width: 200px;background-color: '.$mainboxColor.'">';
  2385.             $output .= '<img class="imgWithHighlightBorder" width="200px" height="200px" src="'.$url.$image->getAiPath().'">';
  2386.             $output .= '<br />';
  2387.             $output .= '<span style="'.$defaultColor.'" >'.$art->getAName().'</span><br>';
  2388.             $output .= '<span style="'.$defaultColor.'" >'.number_format($art->getAPrice(),2,',','.').' &euro;</span>';
  2389.             $output .= '</div>';
  2390.             $output .= '</div>';
  2391.            
  2392.             
  2393.             $i++;
  2394.         }
  2395.         $output .= '</div>';
  2396.         if(!$course && !$article)
  2397.         {   
  2398.             if($category == '0' || $category == '')
  2399.             {
  2400.                 $output '<span style="'.$defaultColor.'">Bitte wählen Sie eine Kategorie aus</span>';
  2401.             }
  2402.             else
  2403.             {
  2404.                 $output '<span style="'.$defaultColor.'">Es wurden leider keine Kurse / Produkte gefunden</span>';
  2405.             }
  2406.         }
  2407.         else 
  2408.         {
  2409.             if($i == 0)
  2410.             {
  2411.                 $output '<span style="'.$defaultColor.'">Es wurden leider keine Kurse / Produkte gefunden</span>';
  2412.             } 
  2413.         }
  2414.         $output .= '</div>';
  2415.         $output .= '</div>';
  2416.         return new Response($output);
  2417.         die();
  2418.     }
  2419.     /**
  2420.     * @Route("/openArticle/{id}/{mode}", name="openArticle")
  2421.     */
  2422.     public function openArticle($id$mode)
  2423.     {
  2424.         require_once("./include/global.php");
  2425.         require_once("./include/function.php");
  2426.         
  2427.         $em $this->getDoctrine()->getManager();   
  2428.        
  2429.         
  2430.         $repository $this->getDoctrine()->getRepository(Cart::class);
  2431.         $cart $repository->findAll();
  2432.         foreach($cart as $ca)
  2433.         {
  2434.             $time $ca->getCaNow()->format('Y-m-d H:i:s');
  2435.             $time date("Y-m-d H:i:s",strtotime($time));
  2436.             if($time date("Y-m-d H:i:s",strtotime("-".$cartMaxTime." Minutes"))  )
  2437.             {
  2438.                 if($ca && $ca != null && is_null($ca) == false )
  2439.                 {
  2440.                     $em->remove($ca);
  2441.                     $em->flush();
  2442.                 }
  2443.             }
  2444.         }
  2445.         
  2446.         $discount "0";
  2447.         $siblingdiscount "0";
  2448.         $costplace "";
  2449.         $period "0";
  2450.         $price "0";
  2451.         if($mode == '1')
  2452.         {
  2453.             $repository $this->getDoctrine()->getRepository(Course::class);
  2454.             $course $repository->findOneBy(['id' => $id]);
  2455.             
  2456.             $costplace $course->getCCostplace();
  2457.             $period $course->getCPeriod();
  2458.             $discount $course->getCDiscount();
  2459.             $siblingdiscount $course->getCSiblingDiscount();
  2460.             $price $course->getCPrice();
  2461.             
  2462.             $repository $this->getDoctrine()->getRepository(CourseImages::class);
  2463.             $images $repository->findOneBy(['ci_cid' => $id]);
  2464.             
  2465.             $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  2466.             $cat $repository->findOneBy(['id' => $course->getCCategory()]);
  2467.             $maxBuy $cat->getCcMaxamount();
  2468.             
  2469.             $daysString "";
  2470.             $daysArr = array();
  2471.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2472.             $cit $repository->findBy(['ctt_cid' => $course->getId()]);
  2473.             
  2474.             $weekdays = array();
  2475.             foreach($cit as $days )
  2476.             {
  2477.                 $tmp $days->getCttDay();
  2478.                 $tmp $tmp->format('d-m-Y');
  2479.                 $weekdays[date('N'strtotime($tmp))] = 1;
  2480.                 array_push($daysArr,$tmp); 
  2481.             }
  2482.             $daysArr array_unique($daysArr);
  2483.             $daysString '';
  2484.             foreach($daysArr as $day)
  2485.             {
  2486.                 $daysString .= $day.',';
  2487.             }
  2488.             $daysString  substr($daysString,0,-1);
  2489.             ksort($weekdays);
  2490.         }
  2491.         else if($mode == '2')
  2492.         {
  2493.             
  2494.             $repository $this->getDoctrine()->getRepository(Article::class);
  2495.             $article $repository->findOneBy(['id' => $id]);
  2496.             $price $article->getAPrice();
  2497.             $discount $article ->getADiscount();
  2498.             
  2499.             $costplace $article->getACostplace();
  2500.             $repository $this->getDoctrine()->getRepository(ArticleImages::class);
  2501.             $images $repository->findOneBy(['ai_aid' => $id]);
  2502.             
  2503.             $repository $this->getDoctrine()->getRepository(CourseCategories::class);
  2504.             $cat $repository->findOneBy(['id' => $article->getACategory()]);
  2505.             $maxBuy $cat->getCcMaxamount();
  2506.         }
  2507.         if($discount != "0")
  2508.         {
  2509.            if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  2510.            {
  2511.                 //Guest, check only cart. if > 1 Item and not highest price then Discount 
  2512.                 
  2513.                 $session $this->requestStack->getSession(); //$session = $this->get('session');
  2514.             
  2515.                 if(!$session->get('cartitems')){$session->set('cartitems'0);}
  2516.                 
  2517.                 $cartitems $session->get('cartitems');
  2518.                 if($cartitems 0)
  2519.                 {
  2520.                     //check if other prices higher / lower
  2521.                     $x 0;
  2522.                     $end $session->get('cartitems');
  2523.                     for($i 1$i <= $end$i++ )
  2524.                     {
  2525.                         $mode2 $session->get('cartItemMode'.$i);
  2526.                         if($mode2 == '1')
  2527.                         {
  2528.                             //course
  2529.                             $repository $this->getDoctrine()->getRepository(Course::class);
  2530.                             $tmp $repository->findOneBy(['id' => $session->get('cartCourse'.$i)]);
  2531.                             $price2 $tmp->GetCPrice();
  2532.                         }
  2533.                         else
  2534.                         {
  2535.                             //article
  2536.                             $repository $this->getDoctrine()->getRepository(Article::class);
  2537.                             $tmp $repository->findOneBy(['id' => $session->get('cartArticle'.$i)]);
  2538.                             $price2 $tmp->GetAPrice();
  2539.                         }
  2540.                         
  2541.                         if($price <= $price2)
  2542.                         {
  2543.                             $x++;
  2544.                         }
  2545.                     
  2546.                        
  2547.                     }           
  2548.                     
  2549.                     // x == amount of orders with higher price
  2550.                     $repository $this->getDoctrine()->getRepository(Costplace::class);
  2551.                     $tmp $repository->findOneBy(['id' => $costplace]);
  2552.                     $place $tmp->getCpPlace();
  2553.                     $y 0;
  2554.                     $discountArr = array();
  2555.                     $repository $this->getDoctrine()->getRepository(Discount::class);
  2556.                     $discount $repository->findBy(['d_place' => $place],['d_amount' => 'ASC']);
  2557.                     foreach($discount as $d)
  2558.                     {
  2559.                         $discountArr[$y] = $d->getDAmount();
  2560.                         $y++;
  2561.                     }
  2562.                     
  2563.                     if($x == 2// middle discount
  2564.                     {
  2565.                         $discount $discountArr[1];
  2566.                     } 
  2567.                     else if($x >= 3// highest discount
  2568.                     {
  2569.                         $discount $discountArr[2];
  2570.                     }
  2571.                     else // lowest discount
  2572.                     {
  2573.                         $discount $discountArr[0];
  2574.                     }
  2575.                 }
  2576.                 else
  2577.                 {
  2578.                     $discount  0;
  2579.                 }
  2580.             }
  2581.             else
  2582.             {
  2583.                 // existing user
  2584.                 // check only cart & all order in the same period. if > 1 Item then Discount 
  2585.                 $session $this->requestStack->getSession(); //$session = $this->get('session');
  2586.                 if(!$session->get('cartitems')){$session->set('cartitems'0);}
  2587.                 $cartitems $session->get('cartitems');
  2588.                 
  2589.                 //check if other prices higher / lower
  2590.                 $x 0;
  2591.                 for($i 1$i <= $cartitems$i++ )
  2592.                 {
  2593.                     $mode2 $session->get('cartItemMode'.$i);
  2594.                     if($mode2 == '1')
  2595.                     {
  2596.                         //course
  2597.                         $repository $this->getDoctrine()->getRepository(Course::class);
  2598.                         $tmp $repository->findOneBy(['id' => $session->get('cartCourse'.$i)]);
  2599.                         $price2 $tmp->GetCPrice();
  2600.                     }
  2601.                     else
  2602.                     {
  2603.                         //article
  2604.                         $repository $this->getDoctrine()->getRepository(Article::class);
  2605.                         $tmp $repository->findOneBy(['id' => $session->get('cartArticle'.$i)]);
  2606.                         $price2 $tmp->GetAPrice();
  2607.                     }
  2608.                     
  2609.                     if($price <= $price2)
  2610.                     {
  2611.                         $x++;
  2612.                     }
  2613.                 
  2614.                 }           
  2615.                 
  2616.                 $curId "0";
  2617.                 $curItem "0";
  2618.                 
  2619.                 $usr $this->get('security.token_storage')->getToken()->getUser();
  2620.                 $repository $this->getDoctrine()->getRepository(Orders::class);
  2621.                 $orders $repository->findBy(['o_uid' =>  $usr->getId()]);
  2622.                 
  2623.                 foreach($orders as $order)
  2624.                 {
  2625.                     $repository $this->getDoctrine()->getRepository(OrderItems::class);
  2626.                     $orderItems $repository->findBy(['oi_oid' =>  $order->getId()]);
  2627.                     foreach($orderItems as $orderItem)
  2628.                     {
  2629.                         if($orderItem->getOiCid() == 0){continue;}
  2630.                         
  2631.                         if($curId == $order->getId() && $orderItem->getOiItem() == $curItem)
  2632.                         {
  2633.                             continue;
  2634.                         }
  2635.                         
  2636.                         
  2637.                         if($orderItem->getOiPeriod() != $period){ continue; }
  2638.                         
  2639.                         if($orderItem->getOiPrice() >= $price){ $x++; }
  2640.                         $curId $order->getId();
  2641.                         $curItem $orderItem->getOiItem();
  2642.                     }
  2643.                 }
  2644.                 // x == amount of orders with higher price
  2645.                 $repository $this->getDoctrine()->getRepository(Costplace::class);
  2646.                 $tmp $repository->findOneBy(['id' => $costplace]);
  2647.                 $place $tmp->getCpPlace();
  2648.                 $y 0;
  2649.                 $discountArr = array();
  2650.                 $repository $this->getDoctrine()->getRepository(Discount::class);
  2651.                 $discount $repository->findBy(['d_place' => $place],['d_amount' => 'ASC']);
  2652.                 foreach($discount as $d)
  2653.                 {
  2654.                     $discountArr[$y] = $d->getDAmount();
  2655.                     $y++;
  2656.                 }
  2657.                 
  2658.                 if($x == 2// middle discount
  2659.                 {
  2660.                     $discount $discountArr[1];
  2661.                 } 
  2662.                 else if($x == 3// highest discount
  2663.                 {
  2664.                     $discount $discountArr[2];
  2665.                 }
  2666.                 else if($x 3// lowest discount
  2667.                 {
  2668.                     $discount $discountArr[0];
  2669.                 }
  2670.                 else // lowest discount
  2671.                 {
  2672.                     $discount $discountArr[0];
  2673.                 }
  2674.            }
  2675.         }
  2676.         $discount 0;
  2677.             
  2678.         if($mode == '1')
  2679.         {
  2680.             $followDays false;
  2681.             $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  2682.             $tmp $repository->findBy(['cat_cid' => $course->getId()]);
  2683.             foreach($tmp as $t)
  2684.             {
  2685.                 if($t->getCatBookingOption() == '2')
  2686.                 {
  2687.                     $followDays true; break;
  2688.                 }
  2689.             }
  2690.             return $this->render('course/article_detail.html.twig',[ 'course' => $course'image' =>  $images ,'id' => $id'mode' => $mode'max' => $maxBuy'url' => $url'days' => $daysString'discount' => $discount'siblingDiscount' => $siblingdiscount'weekdays' => $weekdays'followDays' => $followDays]);
  2691.         }
  2692.         else if($mode == '2')
  2693.         {
  2694.             return $this->render('course/article_detail.html.twig',[ 'article' => $article'image' =>  $images ,'id' => $id'mode' => $mode'max' => $maxBuy'url' => $url'discount' => $discount'siblingDiscount' => $siblingdiscount]);
  2695.         }
  2696.         else
  2697.         {
  2698.             return $this->render('checkout/error.html.twig', [ ]);
  2699.         }
  2700.     }
  2701.      /**
  2702.      * @Route("/loadTimes/{id}/{date}/{manualEntry}/{minAmount}" , name="loadTimes", options={"expose"=true})
  2703.      */
  2704.     public function loadTimes($id$date$manualEntry$minAmount )
  2705.     {
  2706.         require_once("./include/function.php");
  2707.         require_once("./include/global.php");
  2708.         
  2709.         $d1 = new \DateTime(date("Y-m-d",strtotime(checkUserInput($date))));
  2710.        
  2711.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  2712.         $times $repository->findBy([
  2713.             'ctt_cid' => trim(checkUserInput($id)), 
  2714.             'ctt_day' => $d1
  2715.         ], ['ctt_from' => 'ASC']);
  2716.         
  2717.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  2718.         $output '';
  2719.         $i 0;
  2720.         $timesArr = array();
  2721.         foreach($times as $time)
  2722.         {
  2723.             $nd1 $time->getCttFrom();
  2724.             $nd1 $nd1->format('H:i'); 
  2725.             $nd2 $time->getCttTo();
  2726.             $nd2 $nd2->format('H:i'); 
  2727.             $nd3 $time->getCttDay();
  2728.             $nd3 $nd3->format('d.m.Y'); 
  2729.             if(!isset( $timesArr[$nd3][$nd1.' '.$nd2] )){$timesArr[$nd3][$nd1.' '.$nd2] = 0;}
  2730.             
  2731.             $tmp 0;
  2732.             //$tmp = $this->getUsedSlots(trim(checkUserInput($time->getId())));
  2733.             $tmp $time->getCttOnline() + $time->getCttOfflineCustomer();
  2734.             $maxCustomer 0;
  2735.             $maxCustomer $time->getCttMaxonline();
  2736.             if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  2737.             {
  2738.                 //Guest
  2739.             }
  2740.             else
  2741.             {
  2742.                 $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2743.                 $role $uid2->getURole();
  2744.                 if($role == || $role == 2)
  2745.                 {
  2746.                     //Customer
  2747.                 }
  2748.                 else 
  2749.                 {
  2750.                     //employee
  2751.                     $maxCustomer $maxCustomer $time->getCttMaxoffline();
  2752.                 }
  2753.             }
  2754.             $tmp $maxCustomer $tmp;
  2755.             
  2756.             $timesArr[$nd3][$nd1.' '.$nd2] = $timesArr[$nd3][$nd1.' '.$nd2] + $tmp;
  2757.             
  2758.         }
  2759.         $usedArr = array();
  2760.         foreach($times as $time)
  2761.         {
  2762.             $nd1 $time->getCttFrom();
  2763.             $nd1 $nd1->format('H:i'); 
  2764.             
  2765.             $nd2 $time->getCttTo();
  2766.             $nd2 $nd2->format('H:i'); 
  2767.             $nd3 $time->getCttDay();
  2768.             $nd3 $nd3->format('d.m.Y'); 
  2769.             
  2770.             if(!isset( $usedArr[$nd3][$nd1.' '.$nd2] )){$usedArr[$nd3][$nd1.' '.$nd2] = 0;}
  2771.             
  2772.             
  2773.             $found false;
  2774.             //already in Cart
  2775.             $items $session->get('cartitems');
  2776.             for($j 0$j <= $items$j++)
  2777.             {
  2778.                $tid $session->get('cartTime'.$j);
  2779.                if(!empty($tid) && $tid == $time->getId() ){$found true;} 
  2780.             }
  2781.             if($usedArr[$nd3][$nd1.' '.$nd2] == )
  2782.             {
  2783.                 $tmp $timesArr[$nd3][$nd1.' '.$nd2];
  2784.                 $tmp2 $timesArr[$nd3][$nd1.' '.$nd2];
  2785.                 switch($tmp)
  2786.                 {
  2787.                     case '0'$tmp "Leider keine Plätze mehr verfügbar";break;
  2788.                     case '1'$tmp $tmp" Platz offen";break;
  2789.                     default: $tmp $tmp." Plätze offen";break;
  2790.                 }
  2791.                 if($found ==  true)
  2792.                 {
  2793.                     $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  2794.                     $output .= '<label class="btn btn-secondary timeTooltip" title="'.$tmp.'" for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled>'.$nd1.' - '.$nd2.' </label> &nbsp;';
  2795.                     
  2796.                 }
  2797.                 else if($time->getCttActive() == '0' && $tmp2 0)
  2798.                 {
  2799.                     continue;
  2800.                 }
  2801.                 else if($time->getCttActive() == '0' || $found == true)
  2802.                 {
  2803.                     $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  2804.                     $output .= '<label class="btn btn-secondary timeTooltip" title="'.$tmp.'" for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled>'.$nd1.' - '.$nd2.' </label> &nbsp;';
  2805.                 }
  2806.                 else
  2807.                 {
  2808.                     if($minAmount == '0')
  2809.                     {
  2810.                         if($tmp2 == 0)
  2811.                         {
  2812.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" disabled />';
  2813.                             $output .= '<label class="btn btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled>'.$nd1.' - '.$nd2.'</label> &nbsp;';
  2814.                         }
  2815.                         else
  2816.                         {
  2817.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')"  />';
  2818.                             $output .= '<label class="btn btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;">'.$nd1.' - '.$nd2.'</label> &nbsp;';
  2819.                         }
  2820.                     }
  2821.                     else
  2822.                     {
  2823.                         if($tmp2 $minAmount )
  2824.                         {
  2825.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  2826.                             $output .= '<label class="btn btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled>'.$nd1.' - '.$nd2.'</label> &nbsp;';
  2827.                         }
  2828.                         else
  2829.                         {
  2830.                             if($tmp2 == 0)
  2831.                             {
  2832.                                 $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" disabled />';
  2833.                                 $output .= '<label class="btn btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled>'.$nd1.' - '.$nd2.'</label> &nbsp;';
  2834.                             }
  2835.                             else
  2836.                             {
  2837.                                 $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" />';
  2838.                                 $output .= '<label class="btn btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;">'.$nd1.' - '.$nd2.'</label> &nbsp;';
  2839.                             }
  2840.                         }
  2841.                     }
  2842.                 } 
  2843.                 $usedArr[$nd3][$nd1.' '.$nd2] = 1;
  2844.                 $i++;
  2845.             }
  2846.         }
  2847.         if($output == "")
  2848.         {
  2849.             if($manualEntry == 1)
  2850.             {
  2851.                 $output '<p>Es sind leider keine Termine mehr Verf&uuml;gbar. <br>Bitte w&auml;hlen Sie einen anderen Termin.</p>';
  2852.             }
  2853.             else
  2854.             {
  2855.                 $output '<p style="'.$defaultColor.'">Es sind leider keine Termine mehr Verf&uuml;gbar. <br>Bitte w&auml;hlen Sie einen anderen Termin.</p>';
  2856.             }
  2857.         }
  2858.         return new Response($output);
  2859.     }
  2860.     /**
  2861.     * @Route("/loadWeekdayTimes/{id}/{weekday}/{manualEntry}/{minAmount}" , name="loadWeekdayTimes", options={"expose"=true})
  2862.     */
  2863.     public function loadWeekdayTimes($id$weekday$manualEntry$minAmount )
  2864.     {
  2865.         require_once("./include/function.php");
  2866.         require_once("./include/global.php");
  2867.         
  2868.            if($weekday == 0){ $order 'DESC'; }
  2869.         else { $order 'ASC'; }
  2870.         
  2871.         $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND  ctt_day >= :day ORDER BY ctt_day ".$order;
  2872.         $em2 $this->getDoctrine()->getManager();   
  2873.         
  2874.         $nextday "";
  2875.         $tmp "";
  2876.         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $id'day' => date("Y-m-d")]);
  2877.         foreach($resultSet as $res
  2878.         {
  2879.             $tmp $res['ctt_day'];
  2880.             if($weekday != 0)
  2881.             {
  2882.                 if(date("N",strtotime($tmp)) == $weekday)
  2883.                 {
  2884.                     break;
  2885.                 }
  2886.             }
  2887.         }
  2888.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  2889.         $output '<br>';
  2890.         $i 0;
  2891.         $timesArr = array();
  2892.         /*
  2893.         $d1 = new \DateTime(date("Y-m-d",strtotime(checkUserInput($tmp))));
  2894.         $repository = $this->getDoctrine()->getRepository(CourseTimes::class);
  2895.         $times = $repository->findBy([
  2896.             'ctt_cid' => trim(checkUserInput($id)), 
  2897.             'ctt_day' => $d1
  2898.         ], ['ctt_from' => 'ASC']);
  2899.         */
  2900.         if($tmp == ""){ $tmp date('Y-m-d'); } 
  2901.         $tmpTime $tmp;
  2902.         $d2 date('d.m.Y'strtotime('+1 week'strtotime(checkUserInput($tmpTime))));
  2903.         $d3 date('d.m.Y'strtotime('+2 week'strtotime(checkUserInput($tmpTime))));
  2904.         //debugText( date("Y-m-d",strtotime(checkUserInput($tmpTime))));
  2905.         //debugText( date("Y-m-d",strtotime($d2)));
  2906.         //$query = "SELECT * FROM course_times WHERE ctt_cid = :cid AND  (ctt_day = :day OR ctt_day = :day2) GROUP BY ctt_number ORDER BY ctt_day ASC , ctt_from ASC";
  2907.         $query "SELECT * FROM ( SELECT * FROM course_times WHERE ctt_cid = :cid AND (ctt_day = :day OR ctt_day = :day2 OR ctt_day = :day3) ORDER BY ctt_day ASC, ctt_from ASC LIMIT 18446744073709551615 ) AS sub GROUP BY ctt_number; ";
  2908.         $em2 $this->getDoctrine()->getManager();   
  2909.         $times $em2->getConnection()->executeQuery($query,['cid' => $id'day' => date("Y-m-d",strtotime(checkUserInput($tmpTime))), 'day2' =>  date("Y-m-d",strtotime($d2)), 'day3' =>  date("Y-m-d",strtotime($d3)) ]);
  2910.         
  2911.         $i 0;
  2912.         foreach($times as $time)
  2913.         {
  2914.             $i++;
  2915.             //$nd1 = $time->getCttFrom();
  2916.             $nd1 $time['ctt_from'];
  2917.             //$nd1 = $nd1->format('H:i'); 
  2918.             $nd1 date('H:i',strtotime($nd1)); 
  2919.             
  2920.             //$nd2 = $time->getCttTo();
  2921.             $nd2 $time['ctt_to'];
  2922.             //$nd2 = $nd2->format('H:i'); 
  2923.             $nd2 date('H:i',strtotime($nd2)); 
  2924.             
  2925.             //$nd3 = $time->getCttDay();
  2926.             $nd3 $time['ctt_day'];
  2927.             //$nd3 = $nd3->format('d.m.Y'); 
  2928.             $nd3 date('d.m.Y',strtotime($nd3)); 
  2929.             if(!isset( $timesArr[$nd3][$nd1.' '.$nd2] )){$timesArr[$nd3][$nd1.' '.$nd2] = 0;}
  2930.             
  2931.             $tmp 0;
  2932.             
  2933.             $checkCart true;
  2934.             if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  2935.             {
  2936.                 $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2937.                 $role2 $uid2->getURole();
  2938.                 if($role2 == '3' || $role2 == '4' || $role2 == '5')
  2939.                 {
  2940.                     $checkCart false;
  2941.                 }
  2942.             }
  2943.             if($checkCart == true)
  2944.             {
  2945.                 $repository $this->getDoctrine()->getRepository(Cart::class);
  2946.                 //$cartItems = $repository->findBy(['ca_tid' => trim(checkUserInput($time->getId()))]);
  2947.                 $cartItems $repository->findBy(['ca_tid' => trim(checkUserInput($time['id']))]);
  2948.                 foreach($cartItems as $ci)
  2949.                 {
  2950.                     $tmp $tmp $ci->getCaAmount();
  2951.                 }
  2952.             }
  2953.             $maxCustomer 0;
  2954.             //$maxCustomer = $time->getCttMaxonline();
  2955.             $maxCustomer $time['ctt_maxonline'];
  2956.             if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  2957.             {
  2958.                 //Guest
  2959.                 //$tmp = $tmp + $time->getCttOnline();
  2960.                 $tmp $tmp $time['ctt_online'];
  2961.             }
  2962.             else
  2963.             {
  2964.                 
  2965.                 $uid2 $this->get('security.token_storage')->getToken()->getUser();
  2966.                 $role $uid2->getURole();
  2967.                 
  2968.                 //$tmp = $tmp + $time->getCttOnline();
  2969.                 $tmp $tmp $time['ctt_online'];
  2970.                 if($role == || $role == 2)
  2971.                 {
  2972.                     //Customer
  2973.                 }
  2974.                 else 
  2975.                 {
  2976.                     //$tmp = $tmp + $time->getCttOfflineCustomer();
  2977.                     $tmp $tmp $time['ctt_offline_customer'];
  2978.                     //employee
  2979.                     //$maxCustomer = $maxCustomer + $time->getCttMaxoffline();
  2980.                     $maxCustomer $maxCustomer $time['ctt_maxoffline'];
  2981.                 }
  2982.             }
  2983.             $tmp $maxCustomer $tmp;
  2984.             //if($time->getCttActive() == '0'){  continue; }
  2985.             if($time['ctt_active'] == '0'){  continue; }
  2986.             $timesArr[$nd3][$nd1.' '.$nd2] = $timesArr[$nd3][$nd1.' '.$nd2] + $tmp;
  2987.             
  2988.         }
  2989.         $d2 date('d.m.Y'strtotime('+1 week'strtotime(checkUserInput($tmpTime))));
  2990.         $d3 date('d.m.Y'strtotime('+2 week'strtotime(checkUserInput($tmpTime))));
  2991.         //$query = "SELECT * FROM course_times WHERE ctt_cid = :cid AND  (ctt_day = :day OR ctt_day = :day2) GROUP BY ctt_number ORDER BY ctt_day ASC ,ctt_from ASC ";
  2992.         $query "SELECT * FROM ( SELECT * FROM course_times WHERE ctt_cid = :cid AND (ctt_day = :day OR ctt_day = :day2 OR ctt_day = :day3) ORDER BY ctt_day ASC, ctt_from ASC LIMIT 18446744073709551615 ) AS sub GROUP BY ctt_number;  ";
  2993.         $em2 $this->getDoctrine()->getManager();   
  2994.         $times $em2->getConnection()->executeQuery($query,['cid' => $id'day' => date("Y-m-d",strtotime(checkUserInput($tmpTime))), 'day2' =>  date("Y-m-d",strtotime($d2)) , 'day3' =>  date("Y-m-d",strtotime($d3)) ]);
  2995.         
  2996.         $usedArr = array();
  2997.         foreach($times as $time)
  2998.         {
  2999.             //$nd1 = $time->getCttFrom();
  3000.             $nd1 $time['ctt_from'];
  3001.             //$nd1 = $nd1->format('H:i'); 
  3002.             $nd1 date("H:i",strtotime($nd1)); 
  3003.             
  3004.             //$nd2 = $time->getCttTo();
  3005.             $nd2 $time['ctt_to'];
  3006.             //$nd2 = $nd2->format('H:i'); 
  3007.             $nd2 date("H:i",strtotime($nd2)); 
  3008.             
  3009.             //$nd3 = $time->getCttDay();
  3010.             $nd3 $time['ctt_day'];
  3011.             //$nd3 = $nd3->format('d.m.Y'); 
  3012.             $nd3 date("d.m.Y",strtotime($nd3)); 
  3013.             
  3014.             if(!isset( $usedArr[$nd3][$nd1.' '.$nd2] )){$usedArr[$nd3][$nd1.' '.$nd2] = 0;}
  3015.             
  3016.             
  3017.             $found false;
  3018.             //already in Cart
  3019.             $items $session->get('cartitems');
  3020.             for($j 0$j <= $items$j++)
  3021.             {
  3022.                $tid $session->get('cartTime'.$j);
  3023.                //if(!empty($tid) && $tid == $time->getId() ){$found = true;} 
  3024.                if(!empty($tid) && $tid == $time['id'] ){$found true;} 
  3025.             }
  3026.             if($usedArr[$nd3][$nd1.' '.$nd2] == )
  3027.             {
  3028.                 $tmp $timesArr[$nd3][$nd1.' '.$nd2];
  3029.                 $tmp2 $timesArr[$nd3][$nd1.' '.$nd2];
  3030.                 if($tmp ){$tmp 0;}
  3031.                 if($tmp2 ){$tmp2 0;}
  3032.                 switch($tmp)
  3033.                 {
  3034.                     case '0'$tmp "Leider keine Plätze mehr verfügbar";break;
  3035.                     case '1'$tmp $tmp" Platz offen";break;
  3036.                     default: $tmp $tmp." Plätze offen";break;
  3037.                 }
  3038.                 if($found ==  true)
  3039.                 {
  3040.                     $output .= '<label class="labl timeTooltip" title="'.$tmp.'" for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled><a class="btn-disabled">'.$nd1.' - '.$nd2.'</a>';
  3041.                     //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  3042.                     $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" disabled />';
  3043.                     $output .= '</label>';
  3044.                 }
  3045.                 //else if($time->getCttActive() == '0' && $tmp2 > 0)
  3046.                 else if($time['ctt_active'] == '0' && $tmp2 0)
  3047.                 {
  3048.                     continue;
  3049.                 }
  3050.                 //else if($time->getCttActive() == '0' || $found == true)
  3051.                 else if($time['ctt_active'] == '0' || $found == true)
  3052.                 {
  3053.                     $output .= '<label class="labl timeTooltip" title="'.$tmp.'" for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled><a class="btn-disabled">'.$nd1.' - '.$nd2.' </a> &nbsp;';
  3054.                     //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  3055.                     $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" disabled />';
  3056.                     $output .= '</label>';
  3057.                 }
  3058.                 else
  3059.                 {
  3060.                     if($minAmount == '0')
  3061.                     {
  3062.                         if($tmp2 == '0')
  3063.                         {
  3064.                             $output .= '<label class="labl timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled><a class="btn-disabled">'.$nd1.' - '.$nd2.'</a> &nbsp;';
  3065.                             //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" disabled />';
  3066.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" onclick="getAmount('.$time['id'].','.$time['ctt_cid'].')" disabled />';
  3067.                             $output .= '</label>';
  3068.                         }
  3069.                         else
  3070.                         {
  3071.                             $output .= '<label class="labl timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;"><a class="btn">'.$nd1.' - '.$nd2.'</a> &nbsp;';
  3072.                             //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" />';
  3073.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" onclick="getAmount('.$time['id'].','.$time['ctt_cid'].')" />';
  3074.                             $output .= '</label>';
  3075.                         }
  3076.                     }
  3077.                     else
  3078.                     {
  3079.                         if($tmp2 $minAmount )
  3080.                         {
  3081.                             $output .= '<label class="labl btn-success timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;"><a class="btn-disabled">'.$nd1.' - '.$nd2.'</a> &nbsp;';
  3082.                             //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" disabled />';
  3083.                             $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" disabled />';
  3084.                             $output .= '</label>';
  3085.                         }
  3086.                         else
  3087.                         {
  3088.                             if($tmp2 == '0')
  3089.                             {
  3090.                                 $output .= '<label class="labl timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;" disabled><a class="btn-disabled">'.$nd1.' - '.$nd2.'</a> &nbsp;';
  3091.                                 //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" disabled />';
  3092.                                 $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" onclick="getAmount('.$time['id'].','.$time['ctt_cid'].')" disabled />';
  3093.                                 $output .= '</label>';
  3094.                             }
  3095.                             else
  3096.                             {
  3097.                                 $output .= '<label class="labl timeTooltip" title="'.$tmp.'"  for="articleTime'.$i.'" style="'.$defaultColor2.' margin: 0 0 1rem 0;"><a class="btn">'.$nd1.' - '.$nd2.'</a> &nbsp;';
  3098.                                 //$output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time->getId().'" autocomplete="off" onclick="getAmount('.$time->getId().','.$time->getCttCid().')" />';
  3099.                                 $output .= '<input class="btn-check" type="radio" name="articleTime" id="articleTime'.$i.'" value="'.$time['id'].'" autocomplete="off" onclick="getAmount('.$time['id'].','.$time['ctt_cid'].')" />';
  3100.                                 $output .= '</label>';
  3101.                             }
  3102.                         }
  3103.                     }
  3104.                 } 
  3105.                 $usedArr[$nd3][$nd1.' '.$nd2] = 1;
  3106.                 $i++;
  3107.             }
  3108.         }
  3109.         if($output == "")
  3110.         {
  3111.             if($manualEntry == 1)
  3112.             {
  3113.                 $output '<p>Es sind leider keine Termine mehr Verf&uuml;gbar. <br>Bitte w&auml;hlen Sie einen anderen Termin.</p>';
  3114.             }
  3115.             else
  3116.             {
  3117.                 $output '<p>Es sind leider keine Termine mehr Verf&uuml;gbar. <br>Bitte w&auml;hlen Sie einen anderen Termin.</p>';
  3118.             }
  3119.         }
  3120.         return new Response($output);
  3121.     }
  3122.     /**
  3123.     * @Route("/addToCart/{id}/{date}/{time}/{amount}/{addPerson}/{sibling}" , name="addToCart", options={"expose"=true})
  3124.     */
  3125.     public function addToCart($id$date$time$amount$addPerson $sibling)
  3126.     {
  3127.         require_once("./include/function.php");
  3128.         
  3129.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  3130.        
  3131.         if(!$session->get('cartitems')){$session->set('cartitems'0);}
  3132.         
  3133.         $cartitems $session->get('cartitems');
  3134.         $i $cartitems 1;
  3135.         
  3136.         if($date == "" || $date == "undefined")
  3137.         {
  3138.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3139.             $times $repository->findOneBy(['id' => trim(checkUserInput($time))  ]);
  3140.             if($times)
  3141.             {
  3142.                 $date $times->getCttDay()->format("d.m.Y");
  3143.             }
  3144.             else
  3145.             {
  3146.                 debugText("addtocart error ");
  3147.                 return $this->render('checkout/error.html.twig', [ ]);
  3148.             }
  3149.         }
  3150.         $session->set('cartitems'$i);
  3151.         $session->set('cartAddPerson'.$i$addPerson);
  3152.         $session->set('cartTime'.$i$time);
  3153.         $session->set('cartCourse'.$i$id);
  3154.         $session->set('cartDate'.$i$date);
  3155.         $session->set('cartItemMode'.$i'1');
  3156.         $session->set('cartAmount'.$i$amount);
  3157.         $session->set('cartSibling'.$i$sibling);
  3158.         
  3159.         $placeid $session->get('place');
  3160.         $user $this->get('security.token_storage')->getToken()->getUser();
  3161.        
  3162.         $log = new Userlog();
  3163.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.'){
  3164.             $log->setUlUid(0);
  3165.         }
  3166.         else{
  3167.             $log->setUlUid$user->getId());
  3168.         }
  3169.         $log->setUlSessionid($session->getId());
  3170.         $log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
  3171.         $log->setUlIp($_SERVER['REMOTE_ADDR']);
  3172.         
  3173.         $now = new \DateTime(date("Y-m-d H:i:s"));
  3174.         $log->setUlNow($now);
  3175.         if($placeid == NULL)
  3176.         {
  3177.             $log->setUlPlace(0);
  3178.         }
  3179.         else
  3180.         {
  3181.             $log->setUlPlace($placeid);
  3182.         }
  3183.         $log->setUlAction(5);
  3184.         $log->setUlReferer($_SERVER['HTTP_REFERER']);
  3185.         $log->setUlCurrentPage($_SERVER['REQUEST_URI']);
  3186.         $em $this->getDoctrine()->getManager();
  3187.         $em->persist($log);
  3188.         $em->flush();
  3189.         
  3190.         return new Response("");
  3191.     }
  3192.     
  3193.     /**
  3194.      * @Route("/addToCart2/{id}/{amount}" , name="addToCart2", options={"expose"=true})
  3195.      */
  3196.     public function addToCart2($id$amount )
  3197.     {
  3198.         require_once("./include/function.php");
  3199.         
  3200.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  3201.         
  3202.         if(!$session->get('cartitems')){$session->set('cartitems'0);}
  3203.         
  3204.         $cartitems $session->get('cartitems');
  3205.         
  3206.         $i $cartitems 1;
  3207.         
  3208.         $session->set('cartitems'$i);
  3209.         
  3210.         $session->set('cartAmount'.$i$amount);
  3211.         $session->set('cartArticle'.$i$id);
  3212.         $session->set('cartItemMode'.$i'2');
  3213.         
  3214.         $placeid $session->get('place');
  3215.         $user $this->get('security.token_storage')->getToken()->getUser();
  3216.         $log = new Userlog();
  3217.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.'){
  3218.             $log->setUlUid(0);
  3219.         }
  3220.         else{
  3221.             $log->setUlUid$user->getId());
  3222.         }
  3223.         $log->setUlSessionid($session->getId());
  3224.         $log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
  3225.         $log->setUlIp($_SERVER['REMOTE_ADDR']);
  3226.         
  3227.         $now = new \DateTime(date("Y-m-d H:i:s"));
  3228.         $log->setUlNow($now);
  3229.         if($placeid == NULL)
  3230.         {
  3231.             $log->setUlPlace(0);
  3232.         }
  3233.         else
  3234.         {
  3235.             $log->setUlPlace($placeid);
  3236.         }
  3237.         $log->setUlAction(5);
  3238.         $log->setUlReferer($_SERVER['HTTP_REFERER']);
  3239.         $log->setUlCurrentPage($_SERVER['REQUEST_URI']);
  3240.         $em $this->getDoctrine()->getManager();
  3241.         $em->persist($log);
  3242.         $em->flush();
  3243.         
  3244.         return new Response("");
  3245.     }
  3246.     /**
  3247.     * @Route("/cart/" , name="cart")
  3248.     */
  3249.     public function cart()
  3250.     {
  3251.         require_once("./include/function.php");
  3252.         require_once("./include/global.php");
  3253.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  3254.         $end $session->get('cartitems');
  3255.         
  3256.         $outputArr = array();
  3257.         $outputArr2 = array();
  3258.         $fullprice 0;
  3259.         $fullpriceTax 0;
  3260.         $taxArr = array();
  3261.         $adminFee 0;
  3262.         if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  3263.         {
  3264.             $uid $this->get('security.token_storage')->getToken()->getUser();
  3265.             $role $uid->getURole();
  3266.             $uid $uid->getId();
  3267.             
  3268.             $em $this->getDoctrine()->getManager();
  3269.             $repository $this->getDoctrine()->getRepository(Cart::class);
  3270.             $cart $repository->findBy(['ca_uid' => $uid ]);
  3271.         
  3272.             //first clear cart to prevent duplicates
  3273.             foreach($cart as $ca)
  3274.             {
  3275.                 if($ca && $ca != null && is_null($ca) == false )
  3276.                 {
  3277.                     $em->remove($ca);
  3278.                     $em->flush();
  3279.                 }
  3280.             }
  3281.             
  3282.         }
  3283.         else
  3284.         {
  3285.             $repository $this->getDoctrine()->getRepository(Cart::class);
  3286.             $cart $repository->findBy(['ca_session' => $session->getId() ]);
  3287.     
  3288.             $em $this->getDoctrine()->getManager();
  3289.             //first clear cart to prevent duplicates
  3290.             foreach($cart as $ca)
  3291.             {
  3292.                 if($ca && $ca != null && is_null($ca) == false )
  3293.                 {
  3294.                     $em->remove($ca);
  3295.                     $em->flush();
  3296.                 }
  3297.             }
  3298.         }
  3299.         $xPerson = array();
  3300.         $anzPersons 0;
  3301.         for($i 1$i <= $end$i++ )
  3302.         {
  3303.             $anzPersons $anzPersons $session->get('cartAmount'.$i);
  3304.         }
  3305.         
  3306.         $showStudioDiscount false;
  3307.         $showSiblingDiscount false;
  3308.         $siblingDiscountGranted false;
  3309.         $periodArr = array();
  3310.         //change session items order from expensive --> cheap
  3311.         $sTimesArr = array();
  3312.         $sAmountArr = array();
  3313.         $sCourseArr = array();
  3314.         $sPersonArr = array();
  3315.         $sDateArr = array();
  3316.         $sModeArr = array();
  3317.         $sSiblingArr = array();
  3318.         $sDatesArr = array();
  3319.         for($i 1$i <= $end$i++ )
  3320.         {
  3321.             $sTimesArr[$i] = $session->get('cartTime'.$i);
  3322.             $sAmountArr[$i] = $session->get('cartAmount'.$i);
  3323.             $sCourseArr[$i] = $session->get('cartCourse'.$i);
  3324.             $sPersonArr[$i] = $session->get('cartAddPerson'.$i);
  3325.             $sDateArr[$i] = $session->get('cartDate'.$i);
  3326.             $sModeArr[$i] = $session->get('cartItemMode'.$i);
  3327.             $sSiblingArr[$i] = $session->get('cartSibling'.$i);
  3328.             //first get how many dates (Einheiten) the course has
  3329.             $courseId $session->get('cartCourse'.$i);
  3330.             if($courseId == NULL){continue;}
  3331.             $date $session->get('cartDate'.$i);
  3332.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3333.             $courseTime $repository->findOneBy(['id' => trim(checkUserInput($session->get("cartTime".$i))) ]);
  3334.             if(!$courseTime){continue;}
  3335.             $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  3336.             $repository $this->getDoctrine()->getRepository(CourseImages::class);
  3337.             $courseImage $repository->findOneBy(['ci_cid' => trim(checkUserInput($courseId)) ]);
  3338.             $repository $this->getDoctrine()->getRepository(Course::class);
  3339.             $course $repository->findOneBy(['id' => trim(checkUserInput($courseId)) ]);
  3340.             $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  3341.             $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber()]);
  3342.             $bookingOption $courseAddTime->getCatBookingOption();
  3343.             $nd1 $courseTime->getCttFrom();
  3344.             $nd1 $nd1->format('H:i'); 
  3345.             $nd2 $courseTime->getCttTo();
  3346.             $nd2 $nd2->format('H:i'); 
  3347.             if($course->getCAppointmentSeries() == 1)
  3348.             {
  3349.                 $t1 $courseTime->getCttDay();
  3350.                 $t1 $t1->format('Y-m-d'); 
  3351.                 
  3352.                 $t2 $courseTime->getCttFrom();
  3353.                 $t2 $t2->format('H:i:s'); 
  3354.                 
  3355.                 $query "SELECT id, ctt_day, ctt_cid FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day AND ctt_number = :number  ORDER BY ctt_day ASC ";
  3356.                 $em2 $this->getDoctrine()->getManager();   
  3357.                 
  3358.                 $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1"number" => $courseTime->getCttNumber()]);
  3359.                 
  3360.                 $dates 0;
  3361.                 //write new entries
  3362.                 foreach($resultSet as $res
  3363.                 {
  3364.                     
  3365.                     if($bookingOption == 1)
  3366.                     {
  3367.                         //check if same weekdays
  3368.                         $tmp date("N",strtotime($res['ctt_day']));
  3369.                         if($tmp != $weekday ){ continue; }
  3370.                     }
  3371.                     
  3372.                     $checkCart true;
  3373.                     if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  3374.                     {
  3375.                         $uid2 $this->get('security.token_storage')->getToken()->getUser();
  3376.                         $role2 $uid2->getURole();
  3377.                         if($role2 == '3' || $role2 == '4' || $role2 == '5')
  3378.                         {
  3379.                             $checkCart false;
  3380.                         }
  3381.                     }
  3382.                     
  3383.                     //check if coursetime still available
  3384.                     $alreadyUsed 0;
  3385.                     $maxCustomer 0;
  3386.                     $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3387.                     $time $repository->findOneBy(['id' => $res['id']]);
  3388.                     $maxCustomer $time->getCttMaxonline();
  3389.                     if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  3390.                     {
  3391.                         //Guest
  3392.                     }
  3393.                     else
  3394.                     {
  3395.                         $uid2 $this->get('security.token_storage')->getToken()->getUser();
  3396.                         $role $uid2->getURole();
  3397.                         if($role == || $role == 2)
  3398.                         {
  3399.                             //Customer
  3400.                         }
  3401.                         else 
  3402.                         {
  3403.                             //employee
  3404.                             $maxCustomer $maxCustomer $time->getCttMaxoffline();
  3405.                         }
  3406.                     }
  3407.                     
  3408.                     $dates++;
  3409.                     if($dates >= && $bookingOption == 0){ break; }
  3410.                 }
  3411.             }
  3412.             else
  3413.             {
  3414.                 $dates 1;
  3415.             }
  3416.             $sDatesArr[$i] = $dates;
  3417.         }
  3418.         $sPriceArr = array();
  3419.         foreach($sCourseArr as $k => $v)
  3420.         {
  3421.            
  3422.             $repository $this->getDoctrine()->getRepository(Course::class);
  3423.             $course $repository->findOneBy(['id' => trim(checkUserInput($v)) ]);
  3424.             $dates $sDatesArr[$k]; 
  3425.             $sPriceArr[$k] = ($course->getCPrice() * $dates);
  3426.         }
  3427.         arsort($sPriceArr);
  3428.         $i 1;
  3429.         foreach($sPriceArr as $k => $v)
  3430.         {
  3431.         
  3432.             $session->set('cartItemDates'.$i$sDatesArr[$k]);
  3433.             $session->set('cartAddPerson'.$i$sPersonArr[$k]);
  3434.             $session->set('cartAmount'.$i$sAmountArr[$k]);
  3435.             $session->set('cartCourse'.$i$sCourseArr[$k]);
  3436.             $session->set('cartDate'.$i$sDateArr[$k]);
  3437.             $session->set('cartItemMode'.$i$sModeArr[$k]);
  3438.             $session->set('cartSibling'.$i$sSiblingArr[$k]);
  3439.             $session->set('cartTime'.$i$sTimesArr[$k]);
  3440.             $i++;
  3441.             /*
  3442.                 $sTimesArr = array();
  3443.                 $sAmountArr = array();
  3444.                 $sCourseArr = array();
  3445.                 $sPersonArr = array();
  3446.                 $sDateArr = array();
  3447.                 $sModeArr = array();
  3448.                 $sSiblingArr = array();
  3449.                 $sDatesArr = array();
  3450.             */
  3451.         }
  3452.         
  3453.         // start with all cart items
  3454.         for($i 1$i <= $end$i++ )
  3455.         {
  3456.             if($session->get('cartItemMode'.$i) == '1')
  3457.             {
  3458.                 $dates $session->get('cartItemDates'.$i);
  3459.                 $courseId $session->get('cartCourse'.$i);
  3460.                 if($courseId == NULL){continue;} 
  3461.                 $date $session->get('cartDate'.$i);
  3462.                 
  3463.                 $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3464.                 $courseTime $repository->findOneBy(['id' => trim(checkUserInput($session->get("cartTime".$i))) ]);
  3465.                 if(!$courseTime){continue;}
  3466.                 $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  3467.                 
  3468.                 $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  3469.                 $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber(), 'cat_cid' => $courseTime->getCttCid()]);
  3470.                 if(!$courseAddTime){continue;}
  3471.                 $bookingOption $courseAddTime->getCatBookingOption();
  3472.                 
  3473.                 $repository $this->getDoctrine()->getRepository(CourseImages::class);
  3474.                 $courseImage $repository->findOneBy(['ci_cid' => trim(checkUserInput($courseId)) ]);
  3475.                 
  3476.                 $repository $this->getDoctrine()->getRepository(Course::class);
  3477.                 $course $repository->findOneBy(['id' => trim(checkUserInput($courseId)) ]);
  3478.                 
  3479.                 $period $course->getCPeriod();
  3480.                 $amount 0;
  3481.                 $amount $session->get('cartAmount'.$i);
  3482.                 
  3483.                 $siblingDiscountGranted false;
  3484.                 for($j 1$j <= $amount$j++)
  3485.                 {
  3486.                     $first "";
  3487.                     $last "";
  3488.                     $person "";
  3489.                     //go through all Persons 
  3490.                     // amount  == persons
  3491.                     
  3492.                         $x 1;
  3493.                         $tmpperson $session->get('cartAddPerson'.$i); 
  3494.                         $tmpperson explode("***",$tmpperson);
  3495.                         foreach($tmpperson as $tmppers)
  3496.                         {
  3497.                             if($x == $j)
  3498.                             {
  3499.                                 $person2 explode(";;;",$tmppers);
  3500.                                 $z 0;
  3501.                                 foreach($person2 as $p)
  3502.                                 {
  3503.                                     if($z == 0){ $person $p' '; }
  3504.                                     if($z == 1){ $person .= $p; }
  3505.                                     if($z == 2){ continue; }
  3506.                                     $z++;
  3507.                                 }
  3508.                                 
  3509.                             }
  3510.                             $x++;
  3511.                         }
  3512.                     
  3513.                     if(!array_key_exists($person,$xPerson)){ $xPerson[$person] = 0; }
  3514.                     $outdays ""
  3515.                     $seriesCounter 0;
  3516.                     if($company == "KVO")
  3517.                     {
  3518.                         if($course->getCAppointmentSeries() == '1')
  3519.                         {
  3520.                             
  3521.                             $t1 $courseTime->getCttDay();
  3522.                             $t1 $t1->format('Y-m-d'); 
  3523.                             
  3524.                             $t2 $courseTime->getCttFrom();
  3525.                             $t2 $t2->format('H:i:s'); 
  3526.                                 
  3527.                             $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day  ORDER BY ctt_day ASC LIMIT " $course->getCAppointmentSeriesDays();
  3528.                             $em2 $this->getDoctrine()->getManager();   
  3529.                             
  3530.                             $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1]);
  3531.                             foreach($resultSet as $res
  3532.                             {
  3533.                                 //here remove from series if neccessary
  3534.                                 $outdays .=  date("d.m.Y",strtotime$res['ctt_day'])) . "<br />";
  3535.                                 $seriesCounter++;
  3536.                             }
  3537.                             
  3538.                         }
  3539.                         else
  3540.                         {
  3541.                             $seriesCounter 1;
  3542.                         }
  3543.                     }
  3544.                     else
  3545.                     {
  3546.                     
  3547.                         
  3548.                         $t1 $courseTime->getCttDay();
  3549.                         $t1 $t1->format('Y-m-d'); 
  3550.                         
  3551.                         $t2 $courseTime->getCttFrom();
  3552.                         $t2 $t2->format('H:i:s'); 
  3553.                         
  3554.                         $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day AND ctt_number = :number  ORDER BY ctt_day ASC ";
  3555.                         $em2 $this->getDoctrine()->getManager();   
  3556.                         
  3557.                         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1"number" => $courseTime->getCttNumber()]);
  3558.                         $dates 0;
  3559.                         foreach($resultSet as $res
  3560.                         {
  3561.                             
  3562.                             if($bookingOption == 1)
  3563.                             {
  3564.                                 //check if same weekdays
  3565.                                 $tmp date("N",strtotime($res['ctt_day']));
  3566.                                 if($tmp != $weekday ){ continue; }
  3567.                             }
  3568.                             //here remove from series if neccessary
  3569.                             $outdays .=  date("d.m.Y",strtotime$res['ctt_day'])) . "<br />";
  3570.                             $seriesCounter++;
  3571.                             $dates++;
  3572.                             if($dates >= && $bookingOption == 0){ break; }
  3573.                         }
  3574.                         
  3575.                     }   
  3576.                     
  3577.                     //discount
  3578.                     if($course->getCSiblingDiscount() == '1' && $session->get("cartSibling".$i) == '1'  )
  3579.                     {
  3580.                         $discount $siblingDiscountGlob;
  3581.         
  3582.                     }
  3583.                     else
  3584.                     {
  3585.                         //debugText("test");
  3586.                         $discount $course->getCDiscount();
  3587.                         $price = ($course->getCPrice() * $dates);
  3588.                         if($discount != 0)
  3589.                         {
  3590.                             //check if other prices higher / lower
  3591.                             $x 0;
  3592.                             $ord false
  3593.                             // if logged in check earlier orders first
  3594.                             if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  3595.                             {
  3596.                     
  3597.                                 $curId "0";
  3598.                                 $curItem "0";
  3599.                                 $usr $this->get('security.token_storage')->getToken()->getUser();
  3600.                                 //if($usr == '28'){$usr = 60;}
  3601.                                 //debugText($usr);
  3602.                                 $repository $this->getDoctrine()->getRepository(Orders::class);
  3603.                                 $orders $repository->findBy(['o_uid' =>  $usr->getId()]);
  3604.                                 
  3605.                                 foreach($orders as $order)
  3606.                                 {
  3607.                                     if($order->getONow()->format("Y-m-d") < date("Y-01-01")  ){ continue; }
  3608.                                     $repository $this->getDoctrine()->getRepository(OrderItems::class);
  3609.                                     $orderItems $repository->findBy(['oi_oid' =>  $order->getId()]);
  3610.                 
  3611.                                     foreach($orderItems as $orderItem)
  3612.                                     {
  3613.                                         if($orderItem->getOiCid() == 0){continue;}
  3614.                                         
  3615.                                         if($curId == $order->getId() && $orderItem->getOiItem() == $curItem)
  3616.                                         {
  3617.                                             continue;
  3618.                                         }
  3619.                                         $personFound false;
  3620.                                         $repository $this->getDoctrine()->getRepository(CourseAddPerson::class);
  3621.                                         $courseAddPerson $repository->findBy(['cap_oid' => $orderItem->getId()]);
  3622.                                         foreach($courseAddPerson as $cap)
  3623.                                         {
  3624.                                             if( ($cap->getCapFirstname() .' '.$cap->getCapLastname()) == $person)
  3625.                                             {
  3626.                                                 
  3627.                                                 $personFound true;
  3628.                                             }
  3629.                                         }
  3630.                                         if($personFound == false){continue;}
  3631.                                         if($orderItem->getOiCid() == '0'){ continue; }
  3632.                                         if($orderItem->getOiPeriod() != $period){ continue; }
  3633.                                         $repository $this->getDoctrine()->getRepository(Course::class);
  3634.                                         $c $repository->findOneBy(['id' =>  $orderItem->getOiCid()]);
  3635.                                         if(!$c){continue;}
  3636.                                         
  3637.                                         if($c->getCDiscount() == '0'){continue;}
  3638.                                         //$testtime = $c->getCActiveFrom()->format("Y");
  3639.                                         
  3640.                                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3641.                                         $c2 $repository->findBy(['ctt_cid' =>  $orderItem->getOiCid()], ['ctt_day' => 'asc']);
  3642.                                         foreach($c2 as $cc2)
  3643.                                         {
  3644.                                             $testtime $cc2->getCttDay()->format("Y");
  3645.                                             break;
  3646.                                         }
  3647.                                         //debugText($order->getOUid().': '.$testtime);
  3648.                                         if($testtime != date('Y')){continue;}
  3649.                                          
  3650.                                         if(!array_key_exists($c->getCPeriod(),$periodArr))
  3651.                                         {
  3652.                                             $periodArr[$c->getCPeriod()] = 0
  3653.                                         }
  3654.                                         $periodArr[$c->getCPeriod()] = $periodArr[$c->getCPeriod()] + 1;
  3655.                                             
  3656.                                         if($orderItem->getOiPrice() >= $price)
  3657.                                         { 
  3658.                                             
  3659.                                             $x++; 
  3660.                                         }
  3661.                                         $ord true;
  3662.                                        
  3663.                                         $curId $order->getId();
  3664.                                         $curItem $orderItem->getOiItem();
  3665.                                     }
  3666.                                 }
  3667.                             }
  3668.                             
  3669.                             // then check cart
  3670.                             $end2 $session->get('cartitems');
  3671.                             for($i2 1$i2 <= $end2$i2++ )
  3672.                             {
  3673.                                 
  3674.                                 $mode2 $session->get('cartItemMode'.$i);
  3675.                                 if($mode2 == '1'
  3676.                                 {
  3677.                                     //course
  3678.                                     $repository $this->getDoctrine()->getRepository(Course::class);
  3679.                                     $tmp $repository->findOneBy(['id' => $session->get('cartCourse'.$i)]);
  3680.                                     $price2 = ($tmp->GetCPrice() * $dates);
  3681.                                     if(!array_key_exists($tmp->getCPeriod(),$periodArr))
  3682.                                     {
  3683.                                         $periodArr[$tmp->getCPeriod()] = 0
  3684.                                     }
  3685.                                     $periodArr[$tmp->getCPeriod()] = $periodArr[$tmp->getCPeriod()] + 1;
  3686.                                     if($tmp->getCDiscount() == '0'){continue;}
  3687.                                 }
  3688.                                 else
  3689.                                 {
  3690.                                     continue;
  3691.                                 }
  3692.                                 
  3693.                                 if($price <= $price2)
  3694.                                 {
  3695.                                     if($ord != true)
  3696.                                     {
  3697.                                         if($x >= $i ){ continue;}
  3698.                                     }
  3699.                                     else
  3700.                                     {
  3701.                                         if($i2 $i ){ continue;}
  3702.                                     }                                
  3703.                                     $x++; break;
  3704.                                 }
  3705.                             }   
  3706.                             
  3707.                             $xPerson[$person] = $xPerson[$person] + $x;
  3708.                             
  3709.                             // x == amount of orders with higher price
  3710.                             $repository $this->getDoctrine()->getRepository(Costplace::class);
  3711.                             $tmp $repository->findOneBy(['id' => $course->getCCostplace()]);
  3712.                             $place $tmp->getCpPlace();
  3713.                             
  3714.                             $y 0;
  3715.                             $discountArr = array();
  3716.                             $repository $this->getDoctrine()->getRepository(Discount::class);
  3717.                             $discount $repository->findBy(['d_place' => $place],['d_amount' => 'ASC']);
  3718.                             foreach($discount as $d)
  3719.                             {
  3720.                                 $discountArr[$y] = $d->getDAmount();
  3721.                                 $y++;
  3722.                             }
  3723.                             
  3724.                             if($periodArr[$course->getCPeriod()] > 1)
  3725.                             {
  3726.                                 if($xPerson[$person] == 2// lowest discount
  3727.                                 {
  3728.                                     $discount $discountArr[0];
  3729.                                 } 
  3730.                                 else if($xPerson[$person] == 3// middle discount
  3731.                                 {
  3732.                                     $discount $discountArr[1];
  3733.                                 }
  3734.                                 else if($xPerson[$person] >= 4// highest discount
  3735.                                 {
  3736.                                     $discount $discountArr[2];
  3737.                                 }
  3738.                                 else // no discount
  3739.                                 {
  3740.                                     $discount 0;
  3741.                                 }
  3742.                             }
  3743.                             else
  3744.                             {
  3745.                                 
  3746.                                 $discount 0;
  3747.                             }
  3748.                         }
  3749.                     }
  3750.                     
  3751.                     // check sibling Discount here 
  3752.                     if($course->getCSiblingDiscount() == '1' && $anzPersons >= 2)
  3753.                     {
  3754.                         $showSiblingDiscount true;
  3755.                     }
  3756.                     if($course->getCSiblingDiscount() == '1' && $anzPersons >= && $session->get('siblingDiscount') == '1' && $siblingDiscountGranted == false)
  3757.                     {
  3758.                         $discount $siblingDiscountGlob;
  3759.                         $siblingDiscountGranted true;
  3760.                     }
  3761.                     // check studio discount
  3762.                     if($course->getCStudioDiscount() == '1')
  3763.                     {
  3764.                         $showStudioDiscount true;
  3765.                     }
  3766.                     if($course->getCStudioDiscount() == '1' && $session->get('studioDiscount') == '1')
  3767.                     {
  3768.                         $discount $studioDiscountGlob;
  3769.                     }
  3770.                     //$fullprice = $fullprice + ( (($course->getCPrice() * $amount) * $seriesCounter) * (1 - ($discount / 100))   ) + $course->getCAdminFee();
  3771.                     $fullprice $fullprice + ( (($course->getCPrice() *  $seriesCounter)+ $course->getCAdminFee())  * (- ($discount 100))   ) ;
  3772.                     if(empty($taxArr[$course->getCTax()])){ $taxArr[$course->getCTax()] = 0;}
  3773.                     //$taxArr[$course->getCTax()] = $taxArr[$course->getCTax()] + (   ((   (number_format($course->getCPrice() * $amount,2,'.',',') * (($course->getCTax()/100))  ) * $seriesCounter) * ( 1 - ($discount / 100)) )  + number_format( ($course->getCAdminFee() * (($course->getCTax()/100)) ),2,'.',',') ); 
  3774.                     $taxArr[$course->getCTax()] = $taxArr[$course->getCTax()] + (   ((number_format($course->getCPrice(),2,'.',',') * (($course->getCTax()/100))  * $seriesCounter  )  * ( - ($discount 100)) )  + number_format( ($course->getCAdminFee() * (($course->getCTax()/100)) ),2,'.',',') ); 
  3775.                     if($person != "")
  3776.                     {
  3777.                         
  3778.                         $outputArr2[$person][$i]['course'] = $course->getCName();
  3779.                         $outputArr2[$person][$i]['coursePrice'] = ( ((  $course->getCPrice() * $seriesCounter) + $course->getCAdminFee()) * ( - ($discount 100)) ) ;
  3780.                         $outputArr2[$person][$i]['courseTax'] = $course->getCTax();
  3781.                         $outputArr2[$person][$i]['itemMode'] = '1';
  3782.                         $outputArr2[$person][$i]['discount'] = $discount;
  3783.                        
  3784.                         $outputArr2[$person][$i]['i'] = $i;
  3785.                         
  3786.                     }
  3787.                         
  3788.                     $outputArr[$i]['course'] = $course->getCName();
  3789.                     $outputArr[$i]['coursePrice'] = number_format( (  (($course->getCPrice() * $seriesCounter) + $course->getCAdminFee()) * ( - ($discount 100)) ) ,2,',','.'). " â‚¬";
  3790.                     $outputArr[$i]['courseTax'] = number_format($course->getCTax(),2,',','.'). " %";
  3791.                     $outputArr[$i]['itemMode'] = "1";
  3792.                     $outputArr[$i]['courseAmount'] = $session->get('cartAmount'.$i);
  3793.                     $adminFee  $adminFee $course->getCAdminFee();
  3794.                     $nd1 $courseTime->getCttFrom();
  3795.                     $nd1 $nd1->format('H:i'); 
  3796.                     $nd2 $courseTime->getCttTo();
  3797.                     $nd2 $nd2->format('H:i'); 
  3798.                     $outputArr[$i]['time'] = $nd1 " - " $nd2;
  3799.                     if($person != "")
  3800.                     {
  3801.                         $outputArr2[$person][$i]['time'] = $nd1 " - " $nd2;
  3802.                     }
  3803.                     $outputArr[$i]['image'] = $courseImage->getCiPath();
  3804.                     if($outdays != "")
  3805.                     {
  3806.                         $outputArr[$i]['date'] = $outdays;
  3807.                         if($person != "")
  3808.                         {
  3809.                             $outputArr2[$person][$i]['date'] = $outdays;
  3810.                         }
  3811.                     }
  3812.                     else
  3813.                     {
  3814.                         $outputArr[$i]['date'] = $date;
  3815.                         if($person != "")
  3816.                         {
  3817.                             $outputArr2[$person][$i]['date'] = $date;
  3818.                         }
  3819.                     }
  3820.                     // end mode 1
  3821.                 }
  3822.             }
  3823.             else if($session->get('cartItemMode'.$i) == '2')
  3824.             {
  3825.                 $articleId $session->get('cartArticle'.$i);
  3826.                 $repository $this->getDoctrine()->getRepository(Article::class);
  3827.                 $article $repository->findOneBy(['id' => trim(checkUserInput($articleId)) ]);
  3828.                 $repository $this->getDoctrine()->getRepository(ArticleImages::class);
  3829.                 $articleImage $repository->findOneBy(['ai_aid' => trim(checkUserInput($articleId)) ]);
  3830.                 
  3831.                 $discount $article->getADiscount();
  3832.                 if($discount != 0)
  3833.                 {
  3834.                    $repository $this->getDoctrine()->getRepository(Discount::class);
  3835.                    $discount $repository->findOneBy(['id' => $discount ]);  
  3836.                    
  3837.                    $discount $discount->getDAmount();
  3838.                 }
  3839.                 $outputArr[$i]['article'] = $article->getAName();
  3840.                 $outputArr[$i]['articlePrice'] = number_format(($article->getAPrice() * ( - ($discount 100))),2,',','.'). " â‚¬";
  3841.                 $outputArr[$i]['articleTax'] = number_format($article->getATax(),2,',','.'). " %";
  3842.                 $outputArr[$i]['itemMode'] = "2";
  3843.                 $outputArr[$i]['articleAmount'] = $session->get('cartAmount'.$i);
  3844.                 
  3845.                 $outputArr[$i]['image'] = $articleImage->getAiPath();
  3846.                 if($company != 'KVO')
  3847.                 {
  3848.                     $first $this->get('security.token_storage')->getToken()->getUser()->getUFirstname();
  3849.                     $last $this->get('security.token_storage')->getToken()->getUser()->getULastname();
  3850.                     $person $first " " $last;
  3851.                     $outputArr2[$i][$person]['article'] = $article->getAName();
  3852.                     $outputArr2[$i][$person]['articlePrice'] = number_format(($article->getAPrice() * ( - ($discount 100))),2,',','.'). " â‚¬";
  3853.                     $outputArr2[$i][$person]['articleTax'] = number_format($article->getATax(),2,',','.'). " %";
  3854.                     $outputArr2[$i][$person]['itemMode'] = "2";
  3855.                     $outputArr2[$i][$person]['articleAmount'] = $session->get('cartAmount'.$i);
  3856.                 }
  3857.                 
  3858.                 $amount 0;
  3859.                 $amount $session->get('cartAmount'.$i);
  3860.                 $fullprice $fullprice + ( ($article->getAPrice() * $amount)  * ( - ($discount 100)) );
  3861.                 if(empty($taxArr[$article->getATax()])){ $taxArr[$article->getATax()] = 0;}
  3862.                 $taxArr[$article->getATax()] = $taxArr[$article->getATax()] + ( number_format( (($article->getAPrice() * $amount)  * ( - ($discount 100))),2,'.',',') * (($article->getATax()/100))  ); 
  3863.             }
  3864.             $outputArr[$i]['i'] = $i;
  3865.             
  3866.         }
  3867.         
  3868.         $fullpriceTax $fullprice;
  3869.         foreach($taxArr as $k => $v)
  3870.         {
  3871.             $fullpriceTax $fullpriceTax $v;
  3872.             $taxArr[$k] = number_format($v,2,',','.') . " â‚¬";
  3873.         }
  3874.         
  3875.         
  3876.         $anonBuy 0;
  3877.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  3878.         {
  3879.             $anonBuy 1;
  3880.         }
  3881.         
  3882.         
  3883.         /* add to cart database table // begin */ 
  3884.         if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  3885.         {
  3886.             $uid $this->get('security.token_storage')->getToken()->getUser();
  3887.             $role $uid->getURole();
  3888.             $uid $uid->getId();
  3889.             
  3890.         }
  3891.         else
  3892.         {
  3893.             $uid 0;
  3894.         }
  3895.                 
  3896.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  3897.         $end $session->get('cartitems');
  3898.         
  3899.         for($i 1$i <= $end$i++ )
  3900.         {
  3901.             if($session->get('cartItemMode'.$i) == '1')
  3902.             {
  3903.                 $courseId $session->get('cartCourse'.$i);
  3904.                 if($courseId == NULL){continue;}
  3905.                 $date $session->get('cartDate'.$i);
  3906.     
  3907.                 $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3908.                 $courseTime $repository->findOneBy(['id' => trim(checkUserInput($session->get("cartTime".$i))) ]);
  3909.                 
  3910.                 if(!$courseTime){continue;}
  3911.                 $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  3912.                 
  3913.                 $repository $this->getDoctrine()->getRepository(CourseImages::class);
  3914.                 $courseImage $repository->findOneBy(['ci_cid' => trim(checkUserInput($courseId)) ]);
  3915.                 
  3916.                 $repository $this->getDoctrine()->getRepository(Course::class);
  3917.                 $course $repository->findOneBy(['id' => trim(checkUserInput($courseId)) ]);
  3918.                 
  3919.                 $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  3920.                 $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber()]);
  3921.                 $bookingOption $courseAddTime->getCatBookingOption();
  3922.                 $amount 0;
  3923.                 $amount $session->get('cartAmount'.$i);
  3924.                 
  3925.     
  3926.                 $nd1 $courseTime->getCttFrom();
  3927.                 $nd1 $nd1->format('H:i'); 
  3928.     
  3929.                 $nd2 $courseTime->getCttTo();
  3930.                 $nd2 $nd2->format('H:i'); 
  3931.                 
  3932.                 if($course->getCAppointmentSeries() == 1)
  3933.                 {
  3934.                     $t1 $courseTime->getCttDay();
  3935.                     $t1 $t1->format('Y-m-d'); 
  3936.                     $t2 $courseTime->getCttFrom();
  3937.                     $t2 $t2->format('H:i:s'); 
  3938.                     
  3939.                     $query "SELECT id, ctt_day, ctt_cid FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day AND ctt_number = :number  ORDER BY ctt_day ASC ";
  3940.                     $em2 $this->getDoctrine()->getManager();   
  3941.                     
  3942.                     $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1"number" => $courseTime->getCttNumber()]);
  3943.                     
  3944.                     $dates 0;
  3945.                     //write new entries
  3946.                     foreach($resultSet as $res
  3947.                     {
  3948.                         
  3949.                         if($bookingOption == 1)
  3950.                         {
  3951.                             //check if same weekdays
  3952.                             $tmp date("N",strtotime($res['ctt_day']));
  3953.                             if($tmp != $weekday ){ continue; }
  3954.                         }
  3955.                         
  3956.                         $checkCart true;
  3957.                         if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  3958.                         {
  3959.                             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  3960.                             $role2 $uid2->getURole();
  3961.                             if($role2 == '3' || $role2 == '4' || $role2 == '5')
  3962.                             {
  3963.                                 $checkCart false;
  3964.                             }
  3965.                         }
  3966.                         if($checkCart == true)
  3967.                         {
  3968.                             $cart = new Cart();
  3969.                             $cart->setCaUid($uid);
  3970.                             $cart->setCaCid($course->getId());
  3971.                             $cart->setCaTid($res['id']);
  3972.                             $cart->setCaAmount($session->get('cartAmount'.$i));
  3973.                             $now = new \DateTime(date("Y-m-d H:i:s"));
  3974.                             $cart->setCaNow($now);
  3975.                             $cart->setCaSession($session->getId());
  3976.                             
  3977.                             $em $this->getDoctrine()->getManager();
  3978.                     
  3979.                             $em->persist($cart);
  3980.                             $em->flush();
  3981.                         }
  3982.                         //check if coursetime still available
  3983.                         $alreadyUsed 0;
  3984.                         $maxCustomer 0;
  3985.         
  3986.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  3987.                         $time $repository->findOneBy(['id' => $res['id']]);
  3988.                 
  3989.                         $maxCustomer $time->getCttMaxonline();
  3990.                         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  3991.                         {
  3992.                             //Guest
  3993.                         }
  3994.                         else
  3995.                         {
  3996.             
  3997.                             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  3998.                             $role $uid2->getURole();
  3999.             
  4000.                             if($role == || $role == 2)
  4001.                             {
  4002.                                 //Customer
  4003.                             }
  4004.                             else 
  4005.                             {
  4006.                                 //employee
  4007.                                 $maxCustomer $maxCustomer $time->getCttMaxoffline();
  4008.                             }
  4009.                         }
  4010.                         
  4011.                         $dates++;
  4012.                         if($dates >= && $bookingOption == 0){ break; }
  4013.                     }
  4014.                 }
  4015.                 else
  4016.                 {
  4017.                     $checkCart true;
  4018.                     if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  4019.                     {
  4020.                         $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4021.                         $role2 $uid2->getURole();
  4022.                         if($role2 == '3' || $role2 == '4' || $role2 == '5')
  4023.                         {
  4024.                             $checkCart false;
  4025.                         }
  4026.                     }
  4027.                     if($checkCart == true)
  4028.                     {
  4029.                         $cart = new Cart();
  4030.                         $cart->setCaUid($uid);
  4031.                         $cart->setCaCid($course->getId());
  4032.                         $cart->setCaTid($session->get("cartTime".$i));
  4033.                         $cart->setCaAmount($session->get('cartAmount'.$i));
  4034.                         $now = new \DateTime(date("Y-m-d H:i:s"));
  4035.                         $cart->setCaNow($now);
  4036.                         $cart->setCaSession($session->getId());
  4037.                         $em->persist($cart);
  4038.                         $em->flush();
  4039.                     }
  4040.                     //check if coursetime still available
  4041.                     $alreadyUsed 0;
  4042.                     $maxCustomer 0;
  4043.     
  4044.                     $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4045.                     $time $repository->findOneBy(['id' => $res['id']]);
  4046.                 
  4047.                     $maxCustomer $time->getCttMaxonline();
  4048.                     if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4049.                     {
  4050.                         //Guest
  4051.                     }
  4052.                     else
  4053.                     {
  4054.         
  4055.                         $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4056.                         $role $uid2->getURole();
  4057.         
  4058.                         if($role == || $role == 2)
  4059.                         {
  4060.                             //Customer
  4061.                         }
  4062.                         else 
  4063.                         {
  4064.                             //employee
  4065.                             $maxCustomer $maxCustomer $time->getCttMaxoffline();
  4066.                         }
  4067.                     }
  4068.                     
  4069.                 }
  4070.             }
  4071.         }
  4072.         
  4073.         /* add to cart database table // end */ 
  4074.         //check if course was already bought. send warning if so.
  4075.         $warning "";
  4076.         $warningCount 0;
  4077.         $z 0;
  4078.         if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  4079.         {
  4080.             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4081.             $role $uid2->getURole();
  4082.             $uid $uid2->getId();
  4083.             if($role == || $role == 2)
  4084.             {
  4085.                 $end $session->get('cartitems');
  4086.                 for($i 1$i <= $end$i++ )
  4087.                 {
  4088.                     if($session->get('cartItemMode'.$i) == '1')
  4089.                     {
  4090.                         
  4091.                         
  4092.                         $courseId $session->get('cartCourse'.$i);
  4093.                         if($courseId == NULL){continue;} 
  4094.                         $date $session->get('cartDate'.$i);
  4095.                         
  4096.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4097.                         $courseTime $repository->findOneBy(['id' => trim(checkUserInput($session->get("cartTime".$i))) ]);
  4098.                         $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  4099.                         
  4100.                         $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  4101.                         $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber(), 'cat_cid' => $courseTime->getCttCid()]);
  4102.                         $bookingOption $courseAddTime->getCatBookingOption();
  4103.                         
  4104.                         $repository $this->getDoctrine()->getRepository(CourseImages::class);
  4105.                         $courseImage $repository->findOneBy(['ci_cid' => trim(checkUserInput($courseId)) ]);
  4106.                         
  4107.                         $repository $this->getDoctrine()->getRepository(Course::class);
  4108.                         $course $repository->findOneBy(['id' => trim(checkUserInput($courseId)) ]);
  4109.                         
  4110.                         $amount 0;
  4111.                         $amount $session->get('cartAmount'.$i);
  4112.                         
  4113.                         $siblingDiscountGranted false;
  4114.                         for($j 1$j <= $amount$j++)
  4115.                         {
  4116.                             $first "";
  4117.                             $last "";
  4118.                             $person "";
  4119.                             //go through all Persons 
  4120.                             // amount  == persons
  4121.                             
  4122.                                 $x 1;
  4123.                                 $tmpperson $session->get('cartAddPerson'.$i); 
  4124.                                 $tmpperson explode("***",$tmpperson);
  4125.                                 foreach($tmpperson as $tmppers)
  4126.                                 {
  4127.                                     if($x == $j)
  4128.                                     {
  4129.                                         $person2 explode(";;;",$tmppers);
  4130.                                         $z 0;
  4131.                                         foreach($person2 as $p)
  4132.                                         {
  4133.                                             if($z == 0){ $person $p' '; }
  4134.                                             if($z == 1){ $person .= $p; }
  4135.                                             if($z == 2){ continue; }
  4136.         
  4137.                                             $z++;
  4138.                                         }
  4139.                                         
  4140.                                     }
  4141.                                     $x++;
  4142.                                 }
  4143.                             
  4144.                             $repository $this->getDoctrine()->getRepository(Orders::class);
  4145.                             $orders $repository->findBy(['o_uid' => trim($uid) ]);
  4146.                             foreach($orders as $order )
  4147.                             {
  4148.                                 $repository $this->getDoctrine()->getRepository(OrderItems::class);
  4149.                                 $orderItems $repository->findBy(['oi_oid' => trim($order->getId()) ]);
  4150.                                 foreach($orderItems as $orderItem )
  4151.                                 {
  4152.                                     //check if exact course and time was already bought
  4153.                                     if($orderItem->getOiTid() == $courseTime->getId() && $orderItem->getOiCid() == $course->getId())
  4154.                                     {
  4155.                                         //last check the names
  4156.                                         $repository $this->getDoctrine()->getRepository(CourseAddPerson::class);
  4157.                                         $addPersons $repository->findBy(['cap_oid' => trim($orderItem->getId()) ]);
  4158.                                         foreach($addPersons as $addPerson )
  4159.                                         {
  4160.                                             if(($addPerson->getCapFirstname()." "$addPerson->getCapLastname()) == $person)
  4161.                                             {
  4162.                                                 //warning
  4163.                                                 $warningCount++;
  4164.                                                 if($warningCount == 1)
  4165.                                                 {
  4166.                                                     $warning "Achtung! Sie haben bereits f&uuml;r folgende Personen diesen Kurs zur gleichen Zeit gebucht.";
  4167.                                                     $warning .= "<table>";
  4168.                                                     $warning .= "<tr>";
  4169.                                                     $warning .= "<th>Kurs</th>";
  4170.                                                     $warning .= "<th>Kurszeit</th>";
  4171.                                                     $warning .= "<th>Name</th>";
  4172.                                                     $warning .= "</tr>";
  4173.                                                     
  4174.                                                 }
  4175.                                                 $warning .= "<tr>";
  4176.                                                 $warning .= "<td>".$course->getCName()."</td>";
  4177.                                                 $warning .= "<td>".$courseTime->getCttFrom()->format('H:i') ." - "$courseTime->getCttTo()->format('H:i') ."</td>";
  4178.                                                 $warning .= "<td>".$person."</td>";
  4179.                                                 $warning .= "</tr>";
  4180.                                             }
  4181.                                         }
  4182.                                     }
  4183.                                 }
  4184.                             }
  4185.                         }
  4186.                     }
  4187.                 }
  4188.             }
  4189.         }
  4190.         if($warning != "" ){$warning .= "</table>";}
  4191.         $sib $session->get('siblingDiscount');
  4192.         $studio $session->get('studioDiscount');
  4193.         
  4194.         $fullprice number_format($fullprice2',','.')." â‚¬";
  4195.         $fullpriceTax number_format($fullpriceTax2',','.')." â‚¬";
  4196.         return $this->render('course/cart.html.twig',[ 'warning' => $warning,'data' => $outputArr,'sib' => $sib ,'showSibling' => $showSiblingDiscount,'studio' => $studio,'showStudio' => $showStudioDiscount,'data2' => $outputArr2,"fullprice" => $fullprice 'taxes' => $taxArr'fullpricetax' => $fullpriceTax'anonBuy' => $anonBuy'adminFee' => $adminFee] );
  4197.     }
  4198.     /**
  4199.      * @Route("/loadCartSiblingDiscount/{sib}" , name="loadCartSiblingDiscount")
  4200.     */
  4201.     public function loadCartSiblingDiscount($sib)
  4202.     {
  4203.         require_once("./include/function.php");
  4204.         require_once("./include/global.php");
  4205.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  4206.         $session->set('siblingDiscount',$sib);
  4207.         $response $this->redirect($url ."cart");
  4208.         return $response;
  4209.     }
  4210.     /**
  4211.      * @Route("/loadStudioDiscount/{sib}" , name="loadStudioDiscount")
  4212.     */
  4213.     public function loadStudioDiscount($sib)
  4214.     {
  4215.         require_once("./include/function.php");
  4216.         require_once("./include/global.php");
  4217.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  4218.         $session->set('studioDiscount',$sib);
  4219.         $response $this->redirect($url ."cart");
  4220.         return $response;
  4221.     }
  4222.     
  4223.     /**
  4224.      * @Route("/dropArticle/{id}" , name="dropArticle")
  4225.     */
  4226.     public function dropArticle($id)
  4227.     {
  4228.         require_once("./include/function.php");
  4229.         require_once("./include/global.php");
  4230.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  4231.         $outputArr = array();
  4232.         $end $session->get('cartitems');
  4233.         
  4234.         $tmp1Arr = array();
  4235.         $tmp2Arr = array();
  4236.         $tmp3Arr = array();
  4237.         $tmp4Arr = array();
  4238.         $tmp5Arr = array();
  4239.         $tmp6Arr = array();
  4240.         $tmp7Arr = array();
  4241.         $tmp8Arr = array();
  4242.         $j 0;
  4243.         for($i 1$i <= $end$i++ )
  4244.         {
  4245.             if($i == $id){continue;}
  4246.             $j++;
  4247.             $tmp1Arr[$j] =  $session->get('cartTime'.$i);
  4248.             $tmp2Arr[$j] =  $session->get('cartCourse'.$i);
  4249.             $tmp3Arr[$j] =  $session->get('cartDate'.$i);
  4250.             $tmp4Arr[$j] =  $session->get('cartAmount'.$i);
  4251.             $tmp5Arr[$j] =  $session->get('cartArticle'.$i);
  4252.             $tmp6Arr[$j] =  $session->get('cartItemMode'.$i);
  4253.             $tmp7Arr[$j] =  $session->get('cartAddPerson'.$i);
  4254.             $tmp8Arr[$j] =  $session->get('cartSibling'.$i);
  4255.         }
  4256.         $anz $session->get('cartitems');
  4257.         for($i 1$i <= $end$i++ )
  4258.         {
  4259.             $session->remove('cartTime'.$i);
  4260.             $session->remove('cartCourse'.$i);
  4261.             $session->remove('cartDate'.$i);
  4262.             $session->remove('cartAmount'.$i);
  4263.             $session->remove('cartArticle'.$i);
  4264.             $session->remove('cartItemMode'.$i);
  4265.             $session->remove('cartAddPerson'.$i);
  4266.             $session->remove('cartSibling'.$i);
  4267.         }
  4268.         $anz $anz 1;
  4269.         $session->set('cartitems'$anz);
  4270.         for($i 1$i <= $j$i++ )
  4271.         {
  4272.             $session->set('cartTime'.$i$tmp1Arr[$i]);
  4273.             $session->set('cartCourse'.$i$tmp2Arr[$i]);
  4274.             $session->set('cartDate'.$i$tmp3Arr[$i]);
  4275.             $session->set('cartAmount'.$i$tmp4Arr[$i]);
  4276.             $session->set('cartArticle'.$i$tmp5Arr[$i]);
  4277.             $session->set('cartItemMode'.$i$tmp6Arr[$i]);
  4278.             $session->set('cartAddPerson'.$i$tmp7Arr[$i]);
  4279.             $session->set('cartSibling'.$i$tmp8Arr[$i]);
  4280.         
  4281.         }
  4282.  
  4283.         $uname $this->get('security.token_storage')->getToken()->getUser();
  4284.         $uid 0;
  4285.         if(is_object($uname))
  4286.         {
  4287.            if($uname->getId() != )
  4288.             {
  4289.                 $repository $this->getDoctrine()->getRepository(User::class);
  4290.                 $user $repository->findOneBy(['id' => $uname->getId()]);
  4291.                 $uid $user->getId();
  4292.             
  4293.                 $em $this->getDoctrine()->getManager();
  4294.                 $repository $this->getDoctrine()->getRepository(Cart::class);
  4295.                 $cart $repository->findBy(['ca_uid' => $uid ]);
  4296.                 foreach($cart as $ca)
  4297.                 {
  4298.                     if($ca && $ca != null && is_null($ca) == false )
  4299.                     {
  4300.                         $em->remove($ca);
  4301.                         $em->flush();
  4302.                     }
  4303.                 }
  4304.             }
  4305.         }
  4306.         else
  4307.         {
  4308.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  4309.             
  4310.             $em $this->getDoctrine()->getManager();
  4311.             $repository $this->getDoctrine()->getRepository(Cart::class);
  4312.             $cart $repository->findBy(['ca_session' => $session->getId() ]);
  4313.             foreach($cart as $ca)
  4314.             {
  4315.                 if($ca && $ca != null && is_null($ca) == false )
  4316.                 {
  4317.                     $em->remove($ca);
  4318.                     $em->flush();
  4319.                 }
  4320.             }
  4321.         }
  4322.         
  4323.         $placeid $session->get('place');
  4324.         $log = new Userlog();
  4325.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.'){
  4326.             $log->setUlUid(0);
  4327.         }
  4328.         else{
  4329.             $log->setUlUid$user->getId());
  4330.         }
  4331.         $log->setUlSessionid($session->getId());
  4332.         $log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
  4333.         $log->setUlIp($_SERVER['REMOTE_ADDR']);
  4334.         
  4335.         $now = new \DateTime(date("Y-m-d H:i:s"));
  4336.         $log->setUlNow($now);
  4337.         if($placeid == NULL)
  4338.         {
  4339.             $log->setUlPlace(0);
  4340.         }
  4341.         else
  4342.         {
  4343.             $log->setUlPlace($placeid);
  4344.         }
  4345.         $log->setUlAction(6);
  4346.         $log->setUlReferer($_SERVER['HTTP_REFERER']);
  4347.         $log->setUlCurrentPage($_SERVER['REQUEST_URI']);
  4348.         $em $this->getDoctrine()->getManager();
  4349.         $em->persist($log);
  4350.         $em->flush();
  4351.         $response $this->redirect($url ."cart");
  4352.         return $response;
  4353.     }
  4354.     
  4355.     /**
  4356.      * @Route("/dropArticle2/{id}/{person}" , name="dropArticle2")
  4357.     */
  4358.     public function dropArticle2($id,$person)
  4359.     {
  4360.         require_once("./include/function.php");
  4361.         require_once("./include/global.php");
  4362.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  4363.         $outputArr = array();
  4364.         $end $session->get('cartitems');
  4365.         
  4366.         $tmp1Arr = array();
  4367.         $tmp2Arr = array();
  4368.         $tmp3Arr = array();
  4369.         $tmp4Arr = array();
  4370.         $tmp5Arr = array();
  4371.         $tmp6Arr = array();
  4372.         $tmp7Arr = array();
  4373.         $tmp8Arr = array();
  4374.         $j 0;
  4375.         if($person != "" && $session->get('cartItemMode'.$id) == '1' && $session->get('cartAmount'.$id) >= 2)
  4376.         {
  4377.             $amt $session->get('cartAmount'.$id);
  4378.             $session->set('cartAmount'.$id, ($amt ));
  4379.             $personItem =  $session->get('cartAddPerson'.$id);
  4380.             // *** = each person
  4381.             // ;;; = person data
  4382.             $personItemArr explode("***",$personItem);
  4383.             $newPersonItem "";
  4384.             foreach($personItemArr as $pia)
  4385.             {
  4386.                 $personDataArr explode(";;;",$pia);
  4387.                 $pdaTmp "";
  4388.                 $x 0;
  4389.                 foreach($personDataArr as $pda)
  4390.                 {
  4391.                     if($x == 2){ continue; }
  4392.                     $pdaTmp $pda;
  4393.                     $x++;
  4394.                 }
  4395.                 
  4396.                 if($pdaTmp == $person){ continue; }
  4397.                 else
  4398.                 {
  4399.                     $newPersonItem .= $pia.'***';
  4400.                 }
  4401.                 
  4402.             }
  4403.             $session->set('cartAddPerson'.$id,$newPersonItem);
  4404.         }
  4405.         else
  4406.         {
  4407.             
  4408.             for($i 1$i <= $end$i++ )
  4409.             {
  4410.                 if($i == $id){continue;}
  4411.                 $j++;
  4412.                 $tmp1Arr[$j] =  $session->get('cartTime'.$i);
  4413.                 $tmp2Arr[$j] =  $session->get('cartCourse'.$i);
  4414.                 $tmp3Arr[$j] =  $session->get('cartDate'.$i);
  4415.                 $tmp4Arr[$j] =  $session->get('cartAmount'.$i);
  4416.                 $tmp5Arr[$j] =  $session->get('cartArticle'.$i);
  4417.                 $tmp6Arr[$j] =  $session->get('cartItemMode'.$i);
  4418.                 $tmp7Arr[$j] =  $session->get('cartAddPerson'.$i);
  4419.                 $tmp8Arr[$j] =  $session->get('cartSibling'.$i);
  4420.             }
  4421.             
  4422.             $anz $session->get('cartitems');
  4423.             for($i 1$i <= $end$i++ )
  4424.             {
  4425.                 $session->remove('cartTime'.$i);
  4426.                 $session->remove('cartCourse'.$i);
  4427.                 $session->remove('cartDate'.$i);
  4428.                 $session->remove('cartAmount'.$i);
  4429.                 $session->remove('cartArticle'.$i);
  4430.                 $session->remove('cartItemMode'.$i);
  4431.                 $session->remove('cartAddPerson'.$i);
  4432.                 $session->remove('cartSibling'.$i);
  4433.             }
  4434.             
  4435.             
  4436.             
  4437.             $anz $anz 1;
  4438.             $session->set('cartitems'$anz);
  4439.             
  4440.             for($i 1$i <= $j$i++ )
  4441.             {
  4442.                 $session->set('cartTime'.$i$tmp1Arr[$i]);
  4443.                 $session->set('cartCourse'.$i$tmp2Arr[$i]);
  4444.                 $session->set('cartDate'.$i$tmp3Arr[$i]);
  4445.                 $session->set('cartAmount'.$i$tmp4Arr[$i]);
  4446.                 $session->set('cartArticle'.$i$tmp5Arr[$i]);
  4447.                 $session->set('cartItemMode'.$i$tmp6Arr[$i]);
  4448.                 $session->set('cartAddPerson'.$i$tmp7Arr[$i]);
  4449.                 $session->set('cartSibling'.$i$tmp8Arr[$i]);
  4450.                 
  4451.             }
  4452.         }
  4453.         
  4454.         
  4455.         $uname $this->get('security.token_storage')->getToken()->getUser();
  4456.         $uid 0;
  4457.         if(is_object($uname))
  4458.         {
  4459.            if($uname->getId() != )
  4460.             {
  4461.                 $repository $this->getDoctrine()->getRepository(User::class);
  4462.                 $user $repository->findOneBy(['id' => $uname->getId()]);
  4463.                 $uid $user->getId();
  4464.             
  4465.                 $em $this->getDoctrine()->getManager();
  4466.                 $repository $this->getDoctrine()->getRepository(Cart::class);
  4467.                 $cart $repository->findBy(['ca_uid' => $uid ]);
  4468.                 foreach($cart as $ca)
  4469.                 {
  4470.                     if($ca && $ca != null && is_null($ca) == false )
  4471.                     {
  4472.                         $em->remove($ca);
  4473.                         $em->flush();
  4474.                     }
  4475.                 }
  4476.             }
  4477.         }
  4478.         else
  4479.         {
  4480.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  4481.             
  4482.             $em $this->getDoctrine()->getManager();
  4483.             $repository $this->getDoctrine()->getRepository(Cart::class);
  4484.             $cart $repository->findBy(['ca_session' => $session->getId() ]);
  4485.             foreach($cart as $ca)
  4486.             {
  4487.                 if($ca && $ca != null && is_null($ca) == false )
  4488.                 {
  4489.                     $em->remove($ca);
  4490.                     $em->flush();
  4491.                 }
  4492.             }
  4493.         }
  4494.                 
  4495.         $placeid $session->get('place');
  4496.         $user $this->get('security.token_storage')->getToken()->getUser();
  4497.         $log = new Userlog();
  4498.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.'){
  4499.             $log->setUlUid(0);
  4500.         }
  4501.         else{
  4502.             $log->setUlUid$user->getId());
  4503.         }
  4504.         $log->setUlSessionid($session->getId());
  4505.         $log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
  4506.         $log->setUlIp($_SERVER['REMOTE_ADDR']);
  4507.         
  4508.         $now = new \DateTime(date("Y-m-d H:i:s"));
  4509.         $log->setUlNow($now);
  4510.         if($placeid == NULL)
  4511.         {
  4512.             $log->setUlPlace(0);
  4513.         }
  4514.         else
  4515.         {
  4516.             $log->setUlPlace($placeid);
  4517.         }
  4518.         $log->setUlAction(6);
  4519.         $log->setUlReferer($_SERVER['HTTP_REFERER']);
  4520.         $log->setUlCurrentPage($_SERVER['REQUEST_URI']);
  4521.         $em $this->getDoctrine()->getManager();
  4522.         $em->persist($log);
  4523.         $em->flush();
  4524.         
  4525.         $response $this->redirect($url ."cart");
  4526.         return $response;
  4527.     
  4528.     }
  4529.     /**
  4530.      * @Route("/checkDuplicateCourse" , name="checkDuplicateCourse", options={"expose"=true})
  4531.      */
  4532.     public function checkDuplicateCourse()
  4533.     {
  4534.         require_once("./include/function.php");
  4535.         
  4536.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4537.         {
  4538.             $response $this->forward('App\Controller\CourseController::homepage', []);
  4539.             return $response;
  4540.         }
  4541.         $name checkUserInput($_POST['name']);
  4542.         $starttime checkUserInput($_POST['starttime']);
  4543.         $endtime checkUserInput($_POST['endtime']);
  4544.         $activeFrom checkUserInput($_POST['activefrom']);
  4545.         $activeUntill checkUserInput($_POST['activeuntill']);
  4546.         $breakbefore checkUserInput($_POST['breakbefore']);
  4547.         $breakafter checkUserInput($_POST['breakafter']);
  4548.         $duration checkUserInput($_POST['duration']);
  4549.         
  4550.         $costplace checkUserInput($_POST['costplace']);
  4551.         $mon checkUserInput($_POST['mon']);
  4552.         $tue checkUserInput($_POST['tue']);
  4553.         $wed checkUserInput($_POST['wed']);
  4554.         $thu checkUserInput($_POST['thu']);
  4555.         $fri checkUserInput($_POST['fri']);
  4556.         $sat checkUserInput($_POST['sat']);
  4557.         $sun checkUserInput($_POST['sun']);
  4558.         $exists false;
  4559.         $repository $this->getDoctrine()->getRepository(Course::class);
  4560.         $course $repository->findBy(['c_name' => trim(checkUserInput($name)), 'c_active' => 1'c_costplace' => $costplace ]);
  4561.         if($course)
  4562.         {
  4563.             //name found
  4564.             //loop every course and check if same timeslot found, if yes forbid
  4565.             foreach($course as $c)
  4566.             {
  4567.                 $start = new \DateTime(date('H:i:s'strtotime($starttime)));
  4568.                 $end = new \DateTime(date('H:i:s'strtotime($endtime)));
  4569.                 $begin = new \DateTime(date("Y-m-d",strtotime($activeFrom)));
  4570.                 $endDate = new \DateTime(date('Y-m-d',strtotime($activeUntill)));
  4571.                 
  4572.                 $interval = \DateInterval::createFromDateString('1 day');
  4573.                 $period = new \DatePeriod($begin$interval$endDate);
  4574.                 
  4575.                 //each day from start to activeUntill
  4576.                 foreach ($period as $dt
  4577.                 {
  4578.                     $day1 $dt->format("Y-m-d \n"); 
  4579.                     $day = new \DateTime(date("Y-m-d"strtotime($day1)));
  4580.                     
  4581.                     
  4582.                     if($this->checkHoliday($dt->format("d.m.Y")) != false ){ continue; }
  4583.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $sun == 0) {continue; }
  4584.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $mon == 0) {continue; }
  4585.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $tue == 0) {continue; }
  4586.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $wed == 0) {continue; }
  4587.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $thu == 0) {continue; }
  4588.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $fri == 0) {continue; }
  4589.                     if(date('w'strtotime($dt->format("d.m.Y"))) == && $sat == 0) {continue; }
  4590.                     
  4591.                     
  4592.                     $d1 = new \DateTime(date("H:i:s",strtotime($starttime)));
  4593.                     
  4594.                     
  4595.                     while($d1 $end)
  4596.                     {
  4597.                         
  4598.                         $d1orig = new \DateTime(date('H:i:s',strtotime($d1->format('H:i:s')))); 
  4599.                         
  4600.                         $d1->add(new \DateInterval('PT' $duration 'M'));
  4601.                         
  4602.                         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4603.                         $courseTime $repository->findBy([
  4604.                             'ctt_cid' => trim($c->getId()), 
  4605.                             'ctt_day' => $day
  4606.                             'ctt_from' => $d1orig
  4607.                             'ctt_to' => $d1
  4608.                         ]);
  4609.                         if($courseTime)
  4610.                         {
  4611.                             $exists true;
  4612.                         }
  4613.                         
  4614.                         $d1->add(new \DateInterval('PT' $breakbefore 'M'));
  4615.                         $d1->add(new \DateInterval('PT' $breakafter 'M'));
  4616.                         
  4617.                         
  4618.                     }
  4619.                 }
  4620.             }
  4621.             if($exists == true)
  4622.             {
  4623.                 return new Response("nok");
  4624.             }
  4625.             else
  4626.             {
  4627.                 return new Response("ok");
  4628.             }
  4629.         }   
  4630.         else
  4631.         {
  4632.             // OK 
  4633.             return new Response("ok");
  4634.         }   
  4635.     }
  4636.     
  4637.     /**
  4638.      * @Route("/getCourseAmount" , name="getCourseAmount", options={"expose"=true})
  4639.      */
  4640.     public function getCourseAmount()
  4641.     {
  4642.         require_once("./include/function.php");
  4643.         
  4644.         
  4645.         $id $_POST['id'];
  4646.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4647.         $courseTime $repository->findOneBy(['id' => $id]);
  4648.         $repository $this->getDoctrine()->getRepository(Course::class);
  4649.         $course $repository->findOneBy(['id' => $courseTime->getCttCid()]);
  4650.         $maxCustomer 0;
  4651.         $usedSlots 0;
  4652.         $maxCustomer $courseTime->getCttMaxonline();
  4653.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4654.         {
  4655.             //Guest
  4656.         }
  4657.         else
  4658.         {
  4659.             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4660.             $role $uid2->getURole();
  4661.             if($role == || $role == 2)
  4662.             {
  4663.                 //Customer
  4664.             }
  4665.             else 
  4666.             {
  4667.                 //employee
  4668.                 $maxCustomer $maxCustomer $courseTime->getCttMaxoffline();
  4669.             }
  4670.         }
  4671.         //$usedSlots = $this->getUsedSlots($id);
  4672.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4673.         {
  4674.             $usedSlots $courseTime->getCttOnline() ;
  4675.         }
  4676.         else
  4677.         {
  4678.             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4679.             $role $uid2->getURole();
  4680.             if($role == || $role == 2)
  4681.             {
  4682.                 //Customer
  4683.                 $usedSlots $courseTime->getCttOnline();
  4684.             }
  4685.             else 
  4686.             {
  4687.                 //employee
  4688.                 $usedSlots $courseTime->getCttOnline() + $courseTime->getCttOfflineCustomer();
  4689.             }
  4690.         }
  4691.         $checkCart true;
  4692.         if($this->get('security.token_storage')->getToken()->getUser() != 'anon.')
  4693.         {
  4694.             $uid2 $this->get('security.token_storage')->getToken()->getUser();
  4695.             $role2 $uid2->getURole();
  4696.             if($role2 == '3' || $role2 == '4' || $role2 == '5')
  4697.             {
  4698.                 $checkCart false;
  4699.             }
  4700.         }
  4701.         if($checkCart == true)
  4702.         {
  4703.             $repository $this->getDoctrine()->getRepository(Cart::class);
  4704.             $ca $repository->findBy(['ca_cid' => $courseTime->getCttCid(), 'ca_tid' => $id]);
  4705.             foreach($ca as $c)
  4706.             {
  4707.                 $usedSlots $usedSlots $c->getCaAmount();
  4708.             }
  4709.         }
  4710.         $diff $maxCustomer $usedSlots;
  4711.         
  4712.         return new Response($diff);
  4713.     }
  4714.     
  4715.     /**
  4716.      * @Route("/getSeriesDays" , name="getSeriesDays", options={"expose"=true})
  4717.      */
  4718.     public function getSeriesDays()
  4719.     {
  4720.         require_once("./include/function.php");
  4721.         require_once("./include/global.php");
  4722.         
  4723.         
  4724.         $id $_POST['id'];
  4725.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4726.         $courseTime $repository->findOneBy(['id' => $id]);
  4727.         $repository $this->getDoctrine()->getRepository(Course::class);
  4728.         $course $repository->findOneBy(['id' => $courseTime->getCttCid()]);
  4729.         $t1 $courseTime->getCttDay();
  4730.         $t1 $t1->format('Y-m-d'); 
  4731.         $t2 $courseTime->getCttFrom();
  4732.         $t2 $t2->format('H:i:s'); 
  4733.         $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day  ORDER BY ctt_day ASC LIMIT " $course->getCAppointmentSeriesDays();
  4734.         $em2 $this->getDoctrine()->getManager();   
  4735.         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1]);
  4736.         
  4737.         $output "Termine:<br>";
  4738.         $i 0;
  4739.         
  4740.         foreach($resultSet as $res
  4741.         {
  4742.             $button "";
  4743.             $button .= '<svg xmlns="http://www.w3.org/2000/svg" width="'.$defaultIconWidth.'" height="'.$defaultIconHeight.'" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">';
  4744.             $button .= '<path fill-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z"/>';
  4745.             $button .= '<path fill-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z"/>';
  4746.             $button .= '</svg>';
  4747.             $i++;
  4748.             $output .= $i". "date("d.m.Y",strtotime($res['ctt_day'])) . " "date("H:i",strtotime($res['ctt_from'])). " - "date("H:i",strtotime($res['ctt_to'])). "<br>";
  4749.         }
  4750.         
  4751.         return new Response($output);
  4752.     }
  4753.     
  4754.     /**
  4755.      * @Route("/getSeriesWeekDays" , name="getSeriesWeekDays", options={"expose"=true})
  4756.      */
  4757.     public function getSeriesWeekDays()
  4758.     {
  4759.         require_once("./include/function.php");
  4760.         require_once("./include/global.php");
  4761.         
  4762.         $id $_POST['id'];
  4763.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4764.         $courseTime $repository->findOneBy(['id' => $id]);
  4765.         $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  4766.         $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  4767.         $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber(), 'cat_cid' => $courseTime->getCttCid()]);
  4768.         if(!$courseAddTime)
  4769.         {
  4770.             return $this->render('checkout/error.html.twig', [ ]);
  4771.         }
  4772.         $bookingOption $courseAddTime->getCatBookingOption();
  4773.         
  4774.         $repository $this->getDoctrine()->getRepository(Course::class);
  4775.         $course $repository->findOneBy(['id' => $courseTime->getCttCid()]);
  4776.         $t1 $courseTime->getCttDay();
  4777.         $t1 $t1->format('Y-m-d'); 
  4778.         $t2 $courseTime->getCttFrom();
  4779.         $t2 $t2->format('H:i:s'); 
  4780.         $query "SELECT * FROM course_times WHERE  ctt_active = 1 AND ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day AND ctt_number = :number  ORDER BY ctt_day ASC";
  4781.         $em2 $this->getDoctrine()->getManager();   
  4782.         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1"number" => $courseTime->getCttNumber()]);
  4783.         
  4784.         $output "Termine:<br>";
  4785.         $i 0;
  4786.         $dates 0;
  4787.         foreach($resultSet as $res
  4788.         {
  4789.             if($bookingOption == 1)
  4790.             {
  4791.                 //check if same weekdays
  4792.                 $tmp date("N",strtotime($res['ctt_day']));
  4793.                 if($tmp != $weekday ){ continue; }
  4794.             }
  4795.             
  4796.             $button "";
  4797.             $button .= '<svg xmlns="http://www.w3.org/2000/svg" width="'.$defaultIconWidth.'" height="'.$defaultIconHeight.'" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">';
  4798.             $button .= '<path fill-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z"/>';
  4799.             $button .= '<path fill-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z"/>';
  4800.             $button .= '</svg>';
  4801.             
  4802.             $i++;
  4803.             $output .= $i". "date("d.m.Y",strtotime($res['ctt_day'])) . " "date("H:i",strtotime($res['ctt_from'])). " - "date("H:i",strtotime($res['ctt_to'])). "<br>";
  4804.             $dates++;
  4805.             if($dates >= && $bookingOption == 0){ break; }
  4806.         }
  4807.         
  4808.         return new Response($output);
  4809.     }
  4810.     
  4811.     /**
  4812.      * @Route("/getSeriesDaysPrice" , name="getSeriesDaysPrice", options={"expose"=true})
  4813.      */
  4814.     public function getSeriesDaysPrice()
  4815.     {
  4816.         require_once("./include/function.php");
  4817.         require_once("./include/global.php");
  4818.         
  4819.         $id $_POST['id'];
  4820.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4821.         $courseTime $repository->findOneBy(['id' => $id]);
  4822.         $repository $this->getDoctrine()->getRepository(Course::class);
  4823.         $course $repository->findOneBy(['id' => $courseTime->getCttCid()]);
  4824.         $coursePrice $course->getCPrice();
  4825.         $adminFee $course->getCAdminFee();
  4826.         $t1 $courseTime->getCttDay();
  4827.         $t1 $t1->format('Y-m-d'); 
  4828.         $t2 $courseTime->getCttFrom();
  4829.         $t2 $t2->format('H:i:s'); 
  4830.         $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day  ORDER BY ctt_day ASC LIMIT " $course->getCAppointmentSeriesDays();
  4831.         $em2 $this->getDoctrine()->getManager();   
  4832.         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1]);
  4833.         if($_POST['sibling'] == '1')
  4834.         {
  4835.             $discount $siblingDiscountGlob;
  4836.         }
  4837.         else
  4838.         {
  4839.             $discount $_POST['discount'];
  4840.         }
  4841.         $output "Termine:<br>";
  4842.         $i 0;
  4843.         $outprice 0;
  4844.         foreach($resultSet as $res
  4845.         {
  4846.             $i++;
  4847.             $outprice $outprice $coursePrice;
  4848.         }
  4849.         $outprice $outprice $adminFee;
  4850.         $outprice $outprice * (- ($discount 100));
  4851.         $outprice number_format($outprice2',','.'). " â‚¬"
  4852.         
  4853.         return new Response($outprice);
  4854.     }
  4855.     
  4856.     /**
  4857.      * @Route("/getSeriesWeekDaysPrice" , name="getSeriesWeekDaysPrice", options={"expose"=true})
  4858.      */
  4859.     public function getSeriesWeekDaysPrice()
  4860.     {
  4861.         require_once("./include/function.php");
  4862.         require_once("./include/global.php");
  4863.         
  4864.         $id $_POST['id'];
  4865.         $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  4866.         $courseTime $repository->findOneBy(['id' => $id]);
  4867.         $weekday date("N",strtotime($courseTime->getCttDay()->format("Y-m-d")));
  4868.         $repository $this->getDoctrine()->getRepository(CourseAdditionalTimes::class);
  4869.         $courseAddTime $repository->findOneBy(['cat_number' => $courseTime->getCttNumber(), 'cat_cid' => $courseTime->getCttCid()]);
  4870.         $bookingOption $courseAddTime->getCatBookingOption();
  4871.         $repository $this->getDoctrine()->getRepository(Course::class);
  4872.         $course $repository->findOneBy(['id' => $courseTime->getCttCid()]);
  4873.         $coursePrice $course->getCPrice();
  4874.         $adminFee $course->getCAdminFee();
  4875.         $t1 $courseTime->getCttDay();
  4876.         $t1 $t1->format('Y-m-d'); 
  4877.         $t2 $courseTime->getCttFrom();
  4878.         $t2 $t2->format('H:i:s'); 
  4879.         $query "SELECT * FROM course_times WHERE ctt_cid = :cid AND ctt_active = 1  AND ctt_from = :from AND ctt_day >= :day AND ctt_number = :number  ORDER BY ctt_day ASC";
  4880.         $em2 $this->getDoctrine()->getManager();   
  4881.         $resultSet $em2->getConnection()->executeQuery($query,['cid' => $course->getId(), 'from' => $t2 "day" => $t1"number" => $courseTime->getCttNumber()]);
  4882.         if($_POST['sibling'] == '1')
  4883.         {
  4884.             $discount $siblingDiscountGlob;
  4885.         }
  4886.         else
  4887.         {
  4888.             $discount $_POST['discount'];
  4889.         }
  4890.         $output "Termine:<br>";
  4891.         $i 0;
  4892.         $outprice 0;
  4893.         $dates 0;
  4894.         foreach($resultSet as $res
  4895.         {
  4896.             
  4897.             if($bookingOption == 1)
  4898.             {
  4899.                 //check if same weekdays
  4900.                 $tmp date("N",strtotime($res['ctt_day']));
  4901.                 if($tmp != $weekday ){ continue; }
  4902.             }
  4903.             $i++;
  4904.             $outprice $outprice $coursePrice;
  4905.             
  4906.             $dates++;
  4907.             if($dates >= && $bookingOption == 0){ break; }
  4908.         }
  4909.         $outprice $outprice $adminFee;
  4910.         $outprice $outprice * (- ($discount 100));
  4911.         $outprice number_format($outprice2',','.'). " â‚¬"
  4912.         
  4913.         return new Response($outprice);
  4914.     }
  4915.     /**
  4916.      * @Route("/calcDaysBackend" , name="calcDaysBackend", options={"expose"=true})
  4917.      */
  4918.     public function calcDaysBackend()
  4919.     {
  4920.         require_once("./include/function.php");
  4921.         
  4922.         $mon $_POST['mon'];
  4923.         $tue $_POST['tue'];
  4924.         $wed $_POST['wed'];
  4925.         $thu $_POST['thu'];
  4926.         $fri $_POST['fri'];
  4927.         $sat $_POST['sat'];
  4928.         $sun $_POST['sun'];
  4929.         $from $_POST['from'] ;
  4930.         $to date("Y-m-d",strtotime('+1 day',strtotime($_POST['to'])));
  4931.         
  4932.         $begin = new \DateTime(date("Y-m-d",strtotime($from)));
  4933.         $endDate = new \DateTime(date('Y-m-d',strtotime($to)));
  4934.         
  4935.         $interval = \DateInterval::createFromDateString('1 day');
  4936.         $period = new \DatePeriod($begin$interval$endDate);
  4937.         $i 0;
  4938.         //each day from start to activeUntill
  4939.         foreach ($period as $dt
  4940.         {
  4941.             $day1 $dt->format("Y-m-d \n"); 
  4942.             $day = new \DateTime(date("Y-m-d"strtotime($day1)));
  4943.             
  4944.             if($this->checkHoliday($dt->format("d.m.Y")) != false ){ continue; }
  4945.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $sun == 0) {continue; }
  4946.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $mon == 0) {continue; }
  4947.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $tue == 0) {continue; }
  4948.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $wed == 0) {continue; }
  4949.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $thu == 0) {continue; }
  4950.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $fri == 0) {continue; }
  4951.             if(date('w'strtotime($dt->format("d.m.Y"))) == && $sat == 0) {continue; }
  4952.             $i++;    
  4953.         }            
  4954.         return new Response($i);
  4955.     }
  4956.    
  4957.     /**
  4958.      * @Route("/backendTrainerPayment/{id}", name="backendTrainerPayment")
  4959.      */
  4960.     public function backendTrainerPayment($id)
  4961.     {
  4962.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4963.         {
  4964.             $response $this->forward('App\Controller\CourseController::homepage', []);
  4965.             return $response;
  4966.         }
  4967.         require_once("./include/global.php");
  4968.         $repository $this->getDoctrine()->getRepository(User::class);
  4969.         $trainer $repository->findBy(['u_role' => 2]);
  4970.         $repository $this->getDoctrine()->getRepository(TrainerPayment::class);
  4971.         $trainerPayment $repository->findBy(['tp_cid' => $id]);
  4972.         
  4973.         $repository $this->getDoctrine()->getRepository(Course::class);
  4974.         $course $repository->findOneBy(['id' => $id]);
  4975.         return $this->render('backend/course/trainer_payment.html.twig', ['id' => $id,'course' => $course,  'trainer' => $trainer'payment' => $trainerPayment ]);
  4976.     }
  4977.         /**
  4978.     * @Route("/backendTrainerMoneySave/", name="backendTrainerMoneySave")
  4979.     */
  4980.     public function backendTrainerMoneySave(Request $request)
  4981.     {
  4982.         include("./include/global.php");
  4983.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  4984.         {
  4985.             $response $this->forward('App\Controller\CourseController::homepage', []);
  4986.             return $response;
  4987.         }
  4988.         $em $this->getDoctrine()->getManager();
  4989.         
  4990.         $id $request->get('id');
  4991.         $repository $this->getDoctrine()->getRepository(TrainerPayment::class);
  4992.         $trainerPayment $repository->findBy(['tp_cid' => $id]);
  4993.         foreach($trainerPayment as $tp)
  4994.         {
  4995.             $em->remove($tp);
  4996.             $em->flush();
  4997.         }
  4998.         $repository $this->getDoctrine()->getRepository(User::class);
  4999.         $trainer $repository->findBy(['u_role' => 2]);
  5000.         foreach($trainer as $train)
  5001.         {
  5002.             $name "money_"$train->getId();
  5003.             
  5004.             $pay $request->get($name);
  5005.             if(!$pay){$pay 0;}
  5006.             $tp = new TrainerPayment();
  5007.             
  5008.             $tp->setTpCid($id);
  5009.             $tp->setTpPayment($pay);
  5010.             $tp->setTpUid($train->getId());
  5011.             $em->persist($tp);
  5012.             $em->flush();            
  5013.         }
  5014.         $response $this->forward('App\Controller\CourseController::backendCourse', []);
  5015.         return $response;
  5016.     }
  5017.         /**
  5018.     * @Route("/loadResource", name="loadResource", options={"expose"=true})
  5019.     */
  5020.     public function loadResource(Request $request)
  5021.     {
  5022.         include("./include/global.php");
  5023.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  5024.         {
  5025.             $response $this->forward('App\Controller\CourseController::homepage', []);
  5026.             return $response;
  5027.         }
  5028.         $room $_POST['room'];
  5029.         $output "";
  5030.         $repository $this->getDoctrine()->getRepository(Resource::class);
  5031.         $resource $repository->findAll();
  5032.         foreach($resource as $res)
  5033.         {
  5034.             if($res->getId() == $room)
  5035.             {
  5036.                 $output .= '<option value="'.$res->getId().'" selected>'.$res->getRName().'</option>';    
  5037.             }
  5038.             else
  5039.             {
  5040.                 $output .= '<option value="'.$res->getId().'">'.$res->getRName().'</option>';    
  5041.             }
  5042.         }
  5043.         return new Response($output);
  5044.     }
  5045.     
  5046.     /**
  5047.     * @Route("/getTrainer", name="getTrainer", options={"expose"=true})
  5048.     */
  5049.     public function getTrainer(Request $request)
  5050.     {
  5051.         include("./include/global.php");
  5052.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  5053.         {
  5054.             $response $this->forward('App\Controller\CourseController::homepage', []);
  5055.             return $response;
  5056.         }
  5057.         $times $_POST['times'];
  5058.         $leader $_POST['leader'];
  5059.         $output "";
  5060.         $output .= '<select id="courseleader'.$times.'" name="courseleader'.$times.'" class="form-control">';
  5061.         if($leader == "" || $leader == "0")
  5062.         {
  5063.            $output .= '<option value="0" selected>-</option>';
  5064.         }
  5065.         else{
  5066.             $output .= '<option value="0">-</option>';
  5067.         }
  5068.         
  5069.         $repository $this->getDoctrine()->getRepository(User::class);
  5070.         $user $repository->findby(['u_role' => '2']);
  5071.         foreach($user as $u)
  5072.         {
  5073.             if($leader == $u->getId() )
  5074.             {
  5075.                 $output .= '<option value="'.$u->getId().'" selected>'.$u->getULastname().', '.$u->getUFirstname().'</option>';    
  5076.             }
  5077.             else{
  5078.                 $output .= '<option value="'.$u->getId().'">'.$u->getULastname().', '.$u->getUFirstname().'</option>';    
  5079.             }
  5080.         }
  5081.         $output .= '</select>';
  5082.         return new Response($output);
  5083.     }
  5084.     /**
  5085.     * @Route("/saveBackendCourseSearch/", name="saveBackendCourseSearch", options={"expose"=true})
  5086.     */
  5087.     public function saveBackendCourseSearch(AuthenticationUtils $authenticationUtils): Response
  5088.     {
  5089.         require_once("./include/function.php");
  5090.         require_once("./include/global.php");
  5091.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  5092.         {
  5093.             $response $this->redirect($url ."login");
  5094.             return $response;
  5095.         }
  5096.         else
  5097.         {
  5098.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  5099.             
  5100.             $session->set('backendCourseSearch',$_POST['search']);
  5101.             $session->set('backendCoursePeriod',$_POST['period']);
  5102.             $output "";
  5103.             return new Response($output);
  5104.         }
  5105.     }
  5106.     /**
  5107.     * @Route("/loadBackendCourseSearch/", name="loadBackendCourseSearch", options={"expose"=true})
  5108.     */
  5109.     public function loadBackendCourseSearch(AuthenticationUtils $authenticationUtils): Response
  5110.     {
  5111.         require_once("./include/function.php");
  5112.         require_once("./include/global.php");
  5113.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  5114.         {
  5115.             $response $this->redirect($url ."login");
  5116.             return $response;
  5117.         }
  5118.         else
  5119.         {
  5120.             $session $this->requestStack->getSession(); //$session = $this->get('session');
  5121.             
  5122.             $output "";
  5123.             $output .= $session->get('backendCourseSearch');
  5124.             $output .= '###'.$session->get('backendCoursePeriod');
  5125.             return new Response($output);
  5126.         }
  5127.     }
  5128.     /**
  5129.     * @Route("/checkCoursenumber/", name="checkCoursenumber", options={"expose"=true})
  5130.     */
  5131.     public function checkCoursenumber(AuthenticationUtils $authenticationUtils): Response
  5132.     {
  5133.         require_once("./include/function.php");
  5134.         require_once("./include/global.php");
  5135.         if($this->get('security.token_storage')->getToken()->getUser() == 'anon.')
  5136.         {
  5137.             $response $this->redirect($url ."login");
  5138.             return $response;
  5139.         }
  5140.         else
  5141.         {
  5142.             $courseid $_POST['courseid'];
  5143.             $number $_POST['number'];
  5144.             $repository $this->getDoctrine()->getRepository(CourseTimes::class);
  5145.             $ctt $repository->findOneBy(['ctt_number' => $number]);
  5146.             if($ctt)
  5147.             {
  5148.                 if($courseid == '0')
  5149.                 {
  5150.                     // same number as existing course
  5151.                     $output "nok";
  5152.                 }
  5153.                 else
  5154.                 {
  5155.                     if($courseid == $ctt->getCttCid())
  5156.                     {
  5157.                         $output "ok";
  5158.                     }
  5159.                     else
  5160.                     {
  5161.                         $output "nok";
  5162.                     }
  5163.                 }
  5164.             }
  5165.             else
  5166.             {   
  5167.                 $output "ok";
  5168.             }
  5169.             return new Response($output);
  5170.         }
  5171.     }
  5172. }