/**
  * @Route("/zarejestruj-się-na-wymarzone-wakacje", name="register")
  */
 public function displayAction(Request $request)
 {
     $session = new Session();
     $conn = $this->get('database_connection');
     $msg = '';
     if ($request->getMethod() == 'POST') {
         $konto = new Konto();
         $login = $request->request->get('login');
         if ($this->getDoctrine()->getRepository('AppBundle:Konto')->findOneByLogin($login) != '') {
             $msg = 'Login już istnieje!';
         } else {
             if (strlen($login) < 3 || strlen($login) > 20) {
                 $msg = "Login musi posiadać od 3 do 20 znaków!";
             } else {
                 if (ctype_alnum($login) == false) {
                     $msg = "Login może składać się tylko z liter i cyfr (bez polskich znaków)";
                 }
             }
         }
         $konto->setLogin($login);
         $haslo = $request->request->get('password');
         if (strlen($haslo) < 6 || strlen($haslo) > 20) {
             $msg = "Hasło musi posiadać od 6 do 20 znaków!";
         }
         $haslo2 = $request->request->get('password2');
         if ($haslo != $haslo2) {
             $msg = 'Podane hasła nie zgadzają się!';
         }
         $haslo_hash = password_hash($haslo, PASSWORD_DEFAULT);
         $konto->setHaslo($haslo_hash);
         $email = $request->request->get('email');
         $emailB = filter_var($email, FILTER_SANITIZE_EMAIL);
         if (filter_var($emailB, FILTER_VALIDATE_EMAIL) == false || $emailB != $email) {
             $msg = "Podaj poprawny adres e-mail!";
         } else {
             if ($this->getDoctrine()->getRepository('AppBundle:Konto')->findOneByEmail($emailB) != '') {
                 $msg = 'Email już istnieje!';
             }
         }
         $konto->setEmail($emailB);
         $imie = $request->request->get('name');
         $konto->setImie($imie);
         $nazwisko = $request->request->get('surname');
         $konto->setNazwisko($nazwisko);
         $pesel = $request->request->get('pesel');
         $konto->setPesel($pesel);
         $checkbox = $request->request->get('regulamin');
         if (isset($checkbox) == false) {
             $msg = 'Musisz zaakceptować Regulamin!';
         }
         if ($msg == '') {
             $konto->setCzyAdmin('0');
             $em = $this->getDoctrine()->getManager();
             $em->persist($konto);
             $em->flush();
             $msg = 'Utworzono konto!';
         }
     }
     return $this->render('default/register.html.twig', array('session' => $session, 'message' => $msg, 'base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..')));
 }
 /**
  * @Route("/konto/editovanjeAkcija", name="edit_konto_akcija")
  */
 public function editFrameAction(Request $request)
 {
     $session = $request->getSession();
     $entityManager = $this->getDoctrine()->getManager();
     $all_nodes = $request->get('izabrani_cvorovi');
     $changes = $request->get('changes');
     $changes_array = json_decode($changes);
     $korisnik = $this->getDoctrine()->getRepository('AppBundle:Korisnik')->find($session->get('user_id'));
     $typicalDate = date('Y-m-d H:i:s');
     $doctrineDate = new \Datetime($typicalDate);
     foreach ($changes_array as $change) {
         $id = $change->cvorID;
         $firmaID = $change->firmaID;
         $first_query = $entityManager->createQuery('SELECT IDENTITY(k.kontocvor) FROM AppBundle:Konto k WHERE k.izbrisano = 0 AND k.kompanija = ?1');
         $first_query->setParameter(1, $firmaID);
         $qresult = $first_query->getResult();
         foreach ($qresult as $result) {
             if (!in_array($result[1], $all_nodes)) {
                 $query = $entityManager->createQuery('SELECT k FROM AppBundle:Konto k WHERE k.izbrisano = 0 AND k.kompanija = ?1 AND k.kontocvor = ?2');
                 $query->setParameter(2, $result[1]);
                 $query->setParameter(1, $firmaID);
                 $kontoID = $query->getResult();
                 foreach ($kontoID as $previousOption) {
                     $entityManager->remove($previousOption);
                     $entityManager->flush();
                 }
             }
         }
         $potrazuje = $change->potrazuje;
         $duguje = $change->duguje;
         try {
             $nquery = $entityManager->createQuery('SELECT k.id FROM AppBundle:Konto k WHERE k.izbrisano = 0 AND k.kompanija = ?1 AND k.kontocvor = ?2');
             $nquery->setParameter(1, $firmaID);
             $nquery->setParameter(2, $id);
             $kontoID = $nquery->getResult();
             $kontoID = $kontoID[0]["id"];
             $konto = $this->getDoctrine()->getRepository('AppBundle:Konto')->find($kontoID);
             $konto->setPotrazuje($potrazuje);
             $konto->setDuguje($duguje);
             $this->getDoctrine()->getEntityManager()->flush();
         } catch (\Doctrine\ORM\ORMException $e) {
             $novi_konto = new Konto();
             $kontocvor = $this->getDoctrine()->getRepository('AppBundle:Kontocvor')->find($id);
             $novi_konto->setKontocvor($kontocvor);
             $firma = $this->getDoctrine()->getRepository('AppBundle:Kompanija')->find($firmaID);
             $novi_konto->setKompanija($firma);
             $novi_konto->setDuguje($duguje);
             $novi_konto->setPotrazuje($potrazuje);
             $novi_konto->setSaldo($potrazuje - $duguje);
             $novi_konto->setKreiraokorisnik($korisnik);
             $novi_konto->setIzmjeniokorisnik($korisnik);
             $novi_konto->setDatumizmjene($doctrineDate);
             $novi_konto->setDatumkreiranja($doctrineDate);
             $entityManager->persist($novi_konto);
             $entityManager->flush();
         }
     }
     $session->set("dashboardPoruka", "Konto plan uspješno izmijenjen!");
     return $this->redirectToRoute('homepage');
 }