src/Controller/UserController.php line 765

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  7. class UserController extends AbstractController {
  8.     /**
  9.      * Zasób ustawia wartości filtra klientów na podstawie formularza
  10.      * @Route("admin/setUserFilters", name="post-userFilters", methods={"POST"})
  11.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  12.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  13.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  14.      */
  15.     public function postUpdateUserFilters(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): \Symfony\Component\HttpFoundation\RedirectResponse {
  16.         $filter $this->getUser()->getUserFilters();
  17.         if (!$filter)
  18.             $filter = new \App\Entity\UsersFilter ();
  19.         $filter->setCsa($zadanie->get("csa"));
  20.         $filter->setWlasciciel($zadanie->get("nazwa"));
  21.         $filter->setDomena($zadanie->get("domena"));
  22.         $filter->setPozycjaKontraktu($zadanie->get("pozycjaKontraktu"));
  23.         $filter->setNipPesel($zadanie->get("nipPesel"));
  24.         $filter->setNieZaplacone(!($zadanie->get("nieZaplacone""false") == "false"));
  25.         if ($zadanie->get("dataOd""") == "") {
  26.             $filter->setDataOd(null);
  27.         } else {
  28.             $filter->setDataOd(new \DateTime($zadanie->get("dataOd")));
  29.         }
  30.         if ($zadanie->get("dataDo""") == "") {
  31.             $filter->setDataDo(null);
  32.         } else {
  33.             $filter->setDataDo(new \DateTime($zadanie->get("dataDo")));
  34.         }
  35.         $filter->setNumerDokumentu($zadanie->get("numerDokumentu"));
  36.         $filter->setUser($this->getUser());
  37.         $EM->persist($filter);
  38.         $EM->flush();
  39.         return $this->redirectToRoute("users_list");
  40.     }
  41.     /**
  42.      * Zasób renderuje stronę z listą urzytkowników
  43.      * @Route("/admin/usersList", name="users_list")
  44.      * @param \App\Repository\UserRepository $UR
  45.      * @return Response
  46.      */
  47.     public function usersList(\App\Repository\UserRepository $UR): Response {
  48.         return $this->render('usersList.html.twig', [
  49.                     'users' => $UR->findByFilters($this->getUser()->getUserFilters()),
  50.                     'admin' => $this->getUser()
  51.         ]);
  52.     }
  53.     /**
  54.      * Zasób renderuje strone z formularze edycji encji User
  55.      * @Route ("/admin/userEdit/{userId}", name="get_user_edit", methods={"GET"})
  56.      * @param \App\Repository\UserRepository $UR
  57.      * @param \App\Repository\KrajRepository $KR
  58.      * @param int $userId
  59.      * @return Response
  60.      */
  61.     public function getUserEdit(\App\Repository\UserRepository $UR, \App\Repository\KrajRepository $KRint $userId): Response {
  62.         $user $UR->find($userId);
  63.         return $this->render("userEdit.html.twig", [
  64.                     "user" => $user,
  65.                     "kraje" => $KR->findBy([], ["nazwa" => "ASC"])
  66.         ]);
  67.     }
  68.     /**
  69.      * Zasób uaktualnia encję usera na podstawie formularza i przekierowywuje do zasobu /admin/userEdit/{userId} dla metody GET
  70.      * @Route ("/admin/userEdit/{userId}", name="post_user_edit", methods={"POST"})
  71.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI
  72.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  73.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  74.      * $param int $userId
  75.      * @return Response
  76.      */
  77.     public function postUserEdit(\Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI, \Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanieint $userId): Response {
  78.         $user $EM->getRepository(\App\Entity\User::class)->find($userId);
  79.         if ($user) {
  80.             $user->setEmail($zadanie->get("email"));
  81.             if ($zadanie->get("emailFakturowy") == "") {
  82.                 $user->setEmailFakturowy(null);
  83.             } else {
  84.                 $user->setEmailFakturowy($zadanie->get("emailFakturowy"));
  85.             }
  86.             if ($zadanie->get("nip") == "") {
  87.                 $user->setNIP(null);
  88.             } else {
  89.                 $user->setNIP($zadanie->get("nip"));
  90.             }
  91.             $user->setNazwa($zadanie->get("nazwa"));
  92.             if ($zadanie->get("pesel") == "") {
  93.                 $user->setPESEL(null);
  94.             } else {
  95.                 $user->setPESEL($zadanie->get("pesel"));
  96.             }
  97.             if ($zadanie->get("haslo") != "") {
  98.                 $user->setPassword($UPHI->hashPassword($user$zadanie->get("haslo")));
  99.             }
  100.             if ($zadanie->get("SMS") == "") {
  101.                 $user->setSMS(null);
  102.             } else {
  103.                 $user->setSMS($zadanie->get("SMS"));
  104.             }
  105.             $user->setPrivateWHOIS ($zadanie->get ("privateWHOIS") == "true");
  106.             if ($zadanie->get("uwagi") == "") {
  107.                 $user->setUwagi(null);
  108.             } else {
  109.                 $user->setUwagi($zadanie->get("uwagi"));
  110.             }
  111.             $CA = [];
  112.             foreach ($zadanie->get("kontakt_nazwa", []) as $NDX => $N) {
  113.                 $CA [] = ["nazwa" => $N"wartosc" => $zadanie->get("kontakt_wartosc", [])[$NDX]];
  114.             }
  115.             $user->setKontakty($CA);
  116.             $EM->persist($user);
  117.             $EM->flush();
  118.             return $this->render("userEdit.html.twig", [
  119.                         "user" => $user,
  120.                         "kraje" => $EM->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"])
  121.             ]);
  122.         } else {
  123.             $this->redirectToRoute("users_list");
  124.         }
  125.     }
  126.     /**
  127.      * Zasób renderuje stronę klienta
  128.      * @Route ("/admin/userView/{userId}", name="user-view")
  129.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  130.      * @param int $userId
  131.      * @return Response
  132.      */
  133.     public function showUser(\Doctrine\ORM\EntityManagerInterface $EMint $userId): Response {
  134.         $user $EM->getRepository(\App\Entity\User::class)->find($userId);
  135.         $dokumenty = [];
  136.         foreach ($user->getDokumenty() as $dokument)
  137.             $dokumenty [] = $dokument;
  138.         foreach ($user->getCSA() as $CSA) {
  139.             //$CSA = new \App\Entity\HRDUser();
  140.             foreach ($CSA->getHRDProformy() as $PROFORMA) {
  141.                 $dokumenty [] = $PROFORMA;
  142.             }
  143.         }
  144.         if (is_array($dokumenty)) {
  145.             usort($dokumenty, function ($a$b) {
  146.                 if (get_class($a) == "App\Entity\HRDProforma") {
  147.                     $dataA $a->getCrDate()->getTimestamp();
  148.                 } else {
  149.                     $dataA $a->getDatawystawienia()->getTimestamp();
  150.                 }
  151.                 if (get_class($b) == "App\Entity\HRDProforma") {
  152.                     $dataB $b->getCrDate()->getTimestamp();
  153.                 } else {
  154.                     $dataB $b->getDatawystawienia()->getTimestamp();
  155.                 }
  156.                 if ($dataA $dataB) {
  157.                     return 1;
  158.                 } elseif ($dataA $dataB) {
  159.                     return -1;
  160.                 } else {
  161.                     return 0;
  162.                 }
  163.             });
  164.         }
  165.         $domeny = [];
  166.         foreach ($user->getCSA() as $CSA) {
  167.             foreach ($CSA->getHRDDomains() as $domena) {
  168.                 $domeny [] = $domena;
  169.             }
  170.         }
  171.         usort($domeny, function ($a$b) {
  172.             if ($a->getExDate()->getTimestamp() < $b->getExDate()->getTimestamp()) {
  173.                 return -1;
  174.             } elseif ($a->getExDate()->getTimestamp() > $b->getExDate()->getTimestamp()) {
  175.                 return 1;
  176.             } else {
  177.                 return 0;
  178.             }
  179.         });
  180.         
  181.         return $this->render("userView.html.twig", [
  182.                     "user" => $user,
  183.                     "VAT" => floatval($EM->getRepository(\App\Entity\Conf::class)->peek("vat""23")),
  184.                     "DOMAIN_VAT" => floatval($EM->getRepository(\App\Entity\Conf::class)->peek("domains_vat""23")),
  185.                     "ALLOW_REGISTRATION" => intval($EM->getRepository(\App\Entity\Conf::class)->peek("allow_domains_registration""0")),
  186.                     "DOKUMENTY" => $dokumenty,
  187.                     "domeny" => $domeny
  188.         ]);
  189.     }
  190.     /**
  191.      * Zasób na podstawie formularza dodaje adres do klienta
  192.      * @Route("/admin/userEdit/addAddress/{userId}", name="add-address-2-user", methods={"POST"})
  193.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  194.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  195.      * @param int $userId
  196.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  197.      */
  198.     public function addAddress2User(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanieint $userId): \Symfony\Component\HttpFoundation\JsonResponse {
  199.         $user $EM->getRepository(\App\Entity\User::class)->find($userId);
  200.         if ($user) {
  201.             $ADR = new \App\Entity\Adres();
  202.             $ADR->setDom($zadanie->get("dom"));
  203.             $ADR->setKod($zadanie->get("kod"));
  204.             $ADR->setKraj($zadanie->get("kraj"));
  205.             $ADR->setLokal($zadanie->get("lokal"));
  206.             $ADR->setMiasto($zadanie->get("miasto"));
  207.             $ADR->setUlica($zadanie->get("ulica"));
  208.             $ADR->setNazwa($zadanie->get("nazwa"));
  209.             $ADR->setUser($user);
  210.             $EM->persist($ADR);
  211.             $EM->flush();
  212.             return new \Symfony\Component\HttpFoundation\JsonResponse([
  213.                 "STATUS" => true,
  214.                 "CARD" => $this->render("user/adres.html.twig", ["ADRES" => $ADR])->getContent()
  215.             ]);
  216.         } else {
  217.             return new \Symfony\Component\HttpFoundation\JsonResponse(["STATUS" => false"MESSAGE" => "Nie odnalazłem użytkownika o identyfikatorze " $userId]);
  218.         }
  219.     }
  220.     /**
  221.      * Zasób usuwa rekord encji Adres, ID encji przekazany w polu POST "adresId"
  222.      * @Route ("/admin/user/deleteAddress", name="post-delete-address", methods={"POST"})
  223.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  224.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  225.      * @return Response
  226.      */
  227.     public function postDeleteAddress(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): Response {
  228.         $A $EM->getRepository(\App\Entity\Adres::class)->find(intval($zadanie->get("adresId""0")));
  229.         if ($A) {
  230.             $EM->remove($A);
  231.             $EM->flush();
  232.         }
  233.         return new Response("OK");
  234.     }
  235.     /**
  236.      * Zasób usuwa rekord encji User, ID encji przekazany w polu POST "userId"
  237.      * @Route ("/admin/user/deleteUser", name="post-delete-user", methods={"POST"})
  238.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  239.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  240.      * @return Response
  241.      */
  242.     public function postDeleteUser(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): Response {
  243.         $U $EM->getRepository(\App\Entity\User::class)->find(intval($zadanie->get("userId""0")));
  244.         if ($U) {
  245.             $EM->remove($U);
  246.             $EM->flush();
  247.         }
  248.         return new Response("OK");
  249.     }
  250.     /**
  251.      * Zasób udostępnia formularz nowego klienta
  252.      * @Route ("/admin/user/new", name="get-new-user", methods={"GET"})
  253.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  254.      * @return Response
  255.      */
  256.     public function getNewUser(\Doctrine\ORM\EntityManagerInterface $EM): Response {
  257.         return $this->render("userNew.html.twig", [
  258.                     "kraje" => $EM->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"])
  259.         ]);
  260.     }
  261.     /**
  262.      * Zasób tworzy na podstawie formularza nowego USERa i przekierowywuje do zasobu edycji nowo stworzonej encji
  263.      * @Route ("/admin/user/new", name="post-new-user", methods={"POST"})
  264.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI
  265.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  266.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  267.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  268.      */
  269.     public function postNewUser(\Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI, \Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): \Symfony\Component\HttpFoundation\JsonResponse {
  270.         $user = new \App\Entity\User();
  271.         $user->setEmail($zadanie->get("email"));
  272.         $user->setEmailFakturowy($zadanie->get("emailFakturowy"));
  273.         $kontakty = [];
  274.         foreach ($zadanie->get("kontakt_nazwa", []) as $NDX => $kNazwa) {
  275.             $kontakty [] = ["nazwa" => $kNazwa"wartosc" => $zadanie->get("kontakt_wartosc")[$NDX]];
  276.         }
  277.         $user->setKontakty($kontakty);
  278.         $user->setNIP($zadanie->get("nip"));
  279.         $user->setNazwa($zadanie->get("nazwa"));
  280.         $user->setPESEL($zadanie->get("pesel"));
  281.         if (trim($zadanie->get("haslo""")) != "") {
  282.             $user->setPassword($UPHI->hashPassword($user$zadanie->get("haslo")));
  283.         }
  284.         $user->setRoles(["USER"]);
  285.         $user->setSMS($zadanie->get("SMS"));
  286.         $user->setPrivateWHOIS ($zadanie->get ("privateWHOIS") == "true");
  287.         $user->setSaldo(0);
  288.         $user->setUwagi($zadanie->get("uwagi"));
  289.         $alerts = [];
  290.         if (trim($zadanie->get("email")) == "") {
  291.             $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "Adres e-mail nie może być pusty."];
  292.         } elseif (!preg_match('/^[a-z\d]+[\w\d.-]*@(?:[a-z\d]+[a-z\d-]+\.){1,5}[a-z]{2,6}$/'$zadanie->get("email"""))) {
  293.             $alerts [] = ["message" => $zadanie->get("email""") . " nie jest prawidłowym adresem e-mail."];
  294.         }
  295.         if (trim($zadanie->get("haslo")) == "") {
  296.             $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "haslo nie może być puste."];
  297.         }
  298.         if (count($user->getKontakty()) == 0) {
  299.             $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "Podaj przynajmniej jeden kontakt."];
  300.         }
  301.         $testU $EM->getRepository(\App\Entity\User::class)->findOneBy(["email" => $user->getEmail()]);
  302.         if ($testU) {
  303.             $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "Podany adres email \"<strong>" $user->getEmail() . "</strong>\" jest już używany."];
  304.         }
  305.         if (trim($user->getNIP()) != "") {
  306.             $testU $EM->getRepository(\App\Entity\User::class)->findOneBy(["NIP" => trim($user->getNIP())]);
  307.             if ($testU) {
  308.                 $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "Podany numer NIP \"<strong>" $user->getNIP() . "</strong>\" jest już używany."];
  309.             }
  310.         }
  311.         if (trim($user->getPESEL()) != "") {
  312.             $testU $EM->getRepository(\App\Entity\User::class)->findOneBy(["PESEL" => trim($user->getPESEL())]);
  313.             if ($testU) {
  314.                 $alerts [] = ["class" => "danger""icon" => "bi-exclamation-triangle-fill""message" => "Podany numer PESEL \"<strong>" $user->getPESEL() . "</strong>\" jest już używany."];
  315.             }
  316.         }
  317.         if ($zadanie->get("emailFakturowy""") != "") {
  318.             if (!preg_match('/^[a-z\d]+[\w\d.-]*@(?:[a-z\d]+[a-z\d-]+\.){1,5}[a-z]{2,6}$/'$zadanie->get("emailFakturowy"""))) {
  319.                 $alerts [] = ["message" => $zadanie->get("emailFakturowy""") . " nie jest prawidłowym adresem e-mail."];
  320.             }
  321.         }
  322.         if (intval($zadanie->get("hrd""0")) == 1) {
  323.             if ((trim($zadanie->get("nip""")) == "") && (trim($zadanie->get("pesel""")) == "")) {
  324.                 $alerts [] = ["message" => "Prosze podać NIP lub PESEL"];
  325.             } else if ((trim($zadanie->get("nip""")) != "") && (trim($zadanie->get("pesel""")) != "")) {
  326.                 $alerts [] = ["message" => "Prosze podać NIP lub PESEL"];
  327.             }
  328.             $reprezentant = -1;
  329.             $telefon_kontaktowy = -1;
  330.             $telefon_komorkowy = -1;
  331.             $faks = -1;
  332.             $kontakt_nazwa $zadanie->get("kontakt_nazwa", []);
  333.             $kontak_wartosc $zadanie->get("kontakt_wartosc", []);
  334.             foreach ($kontakt_nazwa as $index => $nazwa_pola) {
  335.                 if ((strtoupper($nazwa_pola) == "OSOBA REPREZENTUJĄCA") || (strtoupper($nazwa_pola) == "OSOBA REPREZENTUJąCA")) {
  336.                     if (isset($kontak_wartosc [$index])) {
  337.                         if (trim($kontak_wartosc [$index]) != "") {
  338.                             $reprezentant $index;
  339.                         }
  340.                     }
  341.                 }
  342.                 if (strtoupper($nazwa_pola) == "TELEFON KONTAKTOWY") {
  343.                     if (isset($kontak_wartosc [$index])) {
  344.                         if (trim($kontak_wartosc [$index]) != "") {
  345.                             $telefon_kontaktowy $index;
  346.                         }
  347.                     }
  348.                 }
  349.                 if ((strtoupper($nazwa_pola) == "TELEFON KOMÓRKOWY") || (strtoupper($nazwa_pola) == "TELEFON KOMóRKOWY")) {
  350.                     if (isset($kontak_wartosc [$index])) {
  351.                         if (trim($kontak_wartosc [$index]) != "") {
  352.                             $telefon_komorkowy $index;
  353.                         }
  354.                     }
  355.                 }
  356.                 if (strtoupper($nazwa_pola) == "FAKS") {
  357.                     if (isset($kontak_wartosc [$index])) {
  358.                         if (trim($kontak_wartosc [$index]) != "") {
  359.                             $faks $index;
  360.                         }
  361.                     }
  362.                 }
  363.             }
  364.             if ($telefon_kontaktowy == -1) {
  365.                 $alerts [] = ["message" => "Proszę wypełnić/podać kontakt o nazwie: \"Telefon kontaktowy\"."];
  366.             }
  367.             if (trim($zadanie->get("nip""")) != "") {
  368.                 if ($reprezentant == -1) {
  369.                     $alerts [] = ["message" => "Proszę wypełnić/podać kontakt o nazwie: \"Osoba reprezentująca\"."];
  370.                 }
  371.             }
  372.             if ($telefon_kontaktowy != -1) {
  373.                 $buf $kontak_wartosc [$telefon_kontaktowy];
  374.                 $telefon_kontaktowy_v "";
  375.                 $kropka false;
  376.                 for ($n 0$n strlen($buf); $n++) {
  377.                     if ($buf [$n] == "+") {
  378.                         if ($n == 0)
  379.                             $telefon_kontaktowy_v .= "+";
  380.                     }
  381.                     if ($buf [$n] == ".") {
  382.                         if ((strlen($telefon_kontaktowy_v) > 2) && (strlen($telefon_kontaktowy_v) < 5) && !$kropka) {
  383.                             $kropka true;
  384.                             $telefon_kontaktowy_v .= ".";
  385.                         }
  386.                     }
  387.                     if (($buf [$n] >= "0") && ($buf [$n] <= "9"))
  388.                         $telefon_kontaktowy_v .= $buf [$n];
  389.                 }
  390.                 if ($telefon_kontaktowy_v [0] != "+")
  391.                     $telefon_kontaktowy_v "+" $telefon_kontaktowy_v;
  392.                 if (strpos($telefon_kontaktowy_v".") === false) {
  393.                     $alerts [] = ["message" => "Telefon kontaktowy powinien być podany w formacie: \"+CC.NNNNNNNNN\". Gdzie CC to międzynarodowy numer kiedynkowy (48 dla Polski)."];
  394.                 }
  395.             }
  396.             if ($telefon_komorkowy != -1) {
  397.                 $buf $kontak_wartosc [$telefon_komorkowy];
  398.                 $telefon_komorkowy_v "";
  399.                 $kropka false;
  400.                 for ($n 0$n strlen($buf); $n++) {
  401.                     if ($buf [$n] == "+") {
  402.                         if ($n == 0)
  403.                             $telefon_komorkowy_v .= "+";
  404.                     }
  405.                     if ($buf [$n] == ".") {
  406.                         if ((strlen($telefon_komorkowy_v) > 2) && (strlen($telefon_komorkowy_v) < 5) && !$kropka) {
  407.                             $kropka true;
  408.                             $telefon_komorkowy_v .= ".";
  409.                         }
  410.                     }
  411.                     if (($buf [$n] >= "0") && ($buf [$n] <= "9"))
  412.                         $telefon_komorkowy_v .= $buf [$n];
  413.                 }
  414.                 if ($telefon_komorkowy_v [0] != "+")
  415.                     $telefon_komorkowy_v "+" $telefon_komorkowy_v;
  416.                 if (strpos($telefon_komorkowy_v".") === false) {
  417.                     $alerts [] = ["message" => "Telefon komórkowy powinien być podany w formacie: \"+CC.NNNNNNNNN\". Gdzie CC to międzynarodowy numer kiedynkowy (48 dla Polski)."];
  418.                 }
  419.             }
  420.             if ($faks != -1) {
  421.                 $buf $kontak_wartosc [$faks];
  422.                 $faks_v "";
  423.                 $kropka false;
  424.                 for ($n 0$n strlen($buf); $n++) {
  425.                     if ($buf [$n] == "+") {
  426.                         if ($n == 0)
  427.                             $faks_v .= "+";
  428.                     }
  429.                     if ($buf [$n] == ".") {
  430.                         if ((strlen($faks_v) > 2) && (strlen($faks_v) > 5) && !$kropka) {
  431.                             $kropka true;
  432.                             $faks_v .= "+";
  433.                         }
  434.                     }
  435.                     if (($buf [$n] >= "0") && ($buf [$n] <= "9"))
  436.                         $faks_v .= $buf [$n];
  437.                 }
  438.                 if ($faks_v [0] != "+")
  439.                     $faks_v "+" $faks_v;
  440.                 if (strpos($faks_v".") === false) {
  441.                     $alerts [] = ["message" => "Faks powinien być podany w formacie: \"+CC.NNNNNNNNN\". Gdzie CC to międzynarodowy numer kiedynkowy (48 dla Polski)."];
  442.                 }
  443.             } else {
  444.                 $faks_v "";
  445.             }
  446.         }
  447.         if (count($alerts) > 0) {
  448.             return new \Symfony\Component\HttpFoundation\JsonResponse(["STATUS" => false"MESSAGES" => $alerts]);
  449.         } else {
  450.             if (intval($zadanie->get("hrd""0")) == 1) {
  451.                 $EM->persist($user);
  452.                 $ADR = new \App\Entity\Adres ();
  453.                 $ADR->setDom(trim($zadanie->get("adres_dom""")));
  454.                 $ADR->setKod(trim($zadanie->get("adres_kod""")));
  455.                 $ADR->setKraj(trim($zadanie->get("adres_kraj""PL")));
  456.                 $ADR->setLokal(trim($zadanie->get("adres_lokal""")));
  457.                 $ADR->setMiasto(trim($zadanie->get("adres_miasto""")));
  458.                 $ADR->setNazwa(trim($zadanie->get("adres_nazwa""")));
  459.                 $ADR->setUlica(trim($zadanie->get("adres_ulica""")));
  460.                 $user->addAdresy($ADR);
  461.                 $EM->flush();
  462.                 $ulica_v trim($zadanie->get("adres_ulica""")) . " " trim($zadanie->get("adres_dom"""));
  463.                 if (trim($zadanie->get("adres_lokal""")) != "") {
  464.                     $ulica_v .= " lok. " trim($zadanie->get("adres_lokal"""));
  465.                 }
  466.                 $res $user->createNewCSA($EM,
  467.                         $zadanie->get("nazwa"),
  468.                         (trim($zadanie->get("nip")) != "") ? "company" "person",
  469.                         (trim($zadanie->get("nip")) != "") ? $zadanie->get("nip") : $zadanie->get("pesel"),
  470.                         $zadanie->get("email"),
  471.                         $telefon_kontaktowy_v,
  472.                         trim($zadanie->get("adres_kraj""PL")),
  473.                         ($reprezentant == -1) ? "" $kontakt_wartosc [$reprezentant],
  474.                         ($telefon_komorkowy == -1) ? "" $telefon_komorkowy_v,
  475.                         $faks_v,
  476.                         $ulica_v,
  477.                         trim($zadanie->get("adres_kod""")),
  478.                         trim($zadanie->get("adres_miasto"""))
  479.                 );
  480.                 return new \Symfony\Component\HttpFoundation\JsonResponse(["STATUS" => ($res == "OK"), "USERID" => $user->getId(), "RES" => $res]);
  481.             } else {
  482.                 $EM->persist($user);
  483.                 $EM->flush();
  484.             }
  485.             return new \Symfony\Component\HttpFoundation\JsonResponse(["STATUS" => true"USERID" => $user->getId()]);
  486.         }
  487.     }
  488.     /**
  489.      * Zasób uaktualnia proformy Usera z HRD, ID encji USER przekazane w polu POST userId
  490.      * @Route ("/admin/user/updateProformas", name="post-update-user-proformas", methods={"POST"})
  491.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  492.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  493.      * @return Response
  494.      */
  495.     public function postUpdateUserProformas(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): Response {
  496.         $user $EM->getRepository(\App\Entity\User::class)->find(intval($zadanie->get("userId""0")));
  497.         if ($user) {
  498.             foreach ($user->getCSA() as $CSA) {
  499.                 $CSA->updateProformas($EM);
  500.             }
  501.         }
  502.         return new Response("OK");
  503.     }
  504.     /**
  505.      * Zasób uaktualnia domeny Usera z HRD, ID encji USER przekazane w polu POST userId
  506.      * @Route ("/admin/user/updateDomains", name="post-update-user-domains", methods={"POST"})
  507.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  508.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  509.      * @return Response
  510.      */
  511.     public function postUpdateUserDomains(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie): Response {
  512.         $user $EM->getRepository(\App\Entity\User::class)->find(intval($zadanie->get("userId""0")));
  513.         if ($user) {
  514.             foreach ($user->getCSA() as $CSA) {
  515.                 $CSA->updateDomains($EM);
  516.             }
  517.         }
  518.         return new Response("OK");
  519.     }
  520.     /**
  521.      * Zasób wyświetla stronę wyszukiwarki domen do rejestracji dla klienta
  522.      * @Route ("/admin/user/newDomain/{userId}-1", name="get-new-domain")
  523.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  524.      * @param int $userId
  525.      * @return Response
  526.      */
  527.     public function getNewDomain(\Doctrine\ORM\EntityManagerInterface $EMint $userId): Response {
  528.         return $this->render("newDomain.html.twig", [
  529.                     "user" => $EM->getRepository(\App\Entity\User::class)->find($userId),
  530.                     "ns1" => $EM->getRepository(\App\Entity\Conf::class)->peek("ns1"),
  531.                     "ns2" => $EM->getRepository(\App\Entity\Conf::class)->peek("ns2"),
  532.                     "kosztonline" => floatVal($EM->getRepository(\App\Entity\Conf::class)->peek("TPAYKoszt"0))
  533.         ]);
  534.     }
  535.     /**
  536.      * Zasób kończy zamawianie domen w trybie do zapłaty we własnym zakresie.
  537.      * Dane przekazane w postaci JSON za pomoca metody POST
  538.      * @Route("/admin/user/newDomain/finishOffLine/{userId}", name="post-new-domain-finish-off-line", methods={"POST"})
  539.      * @param \Swift_Mailer $mailer
  540.      * @param \App\Service\inWords $slownie
  541.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  542.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  543.      * @param int $userId
  544.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  545.      */
  546.     public function postNewDomainFinishOffLine(\Swift_Mailer $mailer, \App\Service\inWords $slownie, \Symfony\Component\HttpFoundation\Request $zadanie, \Doctrine\ORM\EntityManagerInterface $EMint $userId): \Symfony\Component\HttpFoundation\JsonResponse {
  547.         $user $EM->getRepository(\App\Entity\User::class)->find($userId);
  548.         if ($user) {
  549.             $POZYCJE $zadanie->get("ITEMS");
  550.             $NETTO 0;
  551.             $VAT 0;
  552.             $BRUTTO 0;
  553.             foreach ($POZYCJE as $POZYCJA) {
  554.                 $NETTO += floatval($POZYCJA ['netto']);
  555.                 $BRUTTO += floatval($POZYCJA ['brutto']);
  556.             }
  557.             $p = new \App\Entity\Dokument();
  558.             $p->setBrutto($BRUTTO);
  559.             $p->setDatawystawienia(new \DateTime(date("Y-m-d")));
  560.             $p->setDozaplaty($BRUTTO);
  561.             $p->setFormaplatnosci(\App\Entity\Dokument::fpPrzelew);
  562.             $p->setNetto($NETTO);
  563.             $p->setOdbiorca($user->getNazwa() . "\n" . ($user->getNIP() ? "NIP: " $user->getNIP() : "PESEL: " $user->getPESEL()));
  564.             if (intval($zadanie->get("ADRES")) != 0) {
  565.                 $ADR $EM->getRepository(\App\Entity\Adres::class)->find(intval($zadanie->get("ADRES")));
  566.                 if ($ADR) {
  567.                     $p->setOdbiorca($p->getOdbiorca() . "\n" $ADR->getUlica() . " " $ADR->getDom() . ($ADR->getLokal() ? " lokal " $ADR->getLokal() : "") . "\n" $ADR->getKod() . " " $ADR->getMiasto() . "\n" $ADR->getKraj());
  568.                 }
  569.             }
  570.             $p->setRodzaj(\App\Entity\Dokument::dtFP);
  571.             $p->setStatus(\App\Entity\Dokument::dsNieZaplacony);
  572.             $p->setTerminplatnosci(new \DateTime(date("Y-m-d"time() + 86400 intval($EM->getRepository(\App\Entity\Conf::class)->peek("register-domains-pay-day-limit""7")))));
  573.             $p->setUser($user);
  574.             $p->setVat($BRUTTO $NETTO);
  575.             $p->setWystawca($EM->getRepository(\App\Entity\Conf::class)->peek("seller-text""seller-text"));
  576.             $numer_proformy intval($EM->getRepository(\App\Entity\Conf::class)->peek("proforma-counter""1"));
  577.             $EM->getRepository(\App\Entity\Conf::class)->poke("proforma-counter"$numer_proformy 1);
  578.             $format_numeru $EM->getRepository(\App\Entity\Conf::class)->peek("proforma-format""{nr}");
  579.             $p->setNumer(str_replace(["{nr}""{d}""{m}""{R}"], [$numer_proformydate("d"), date("m"), date("Y")], $format_numeru));
  580.             $EM->persist($p);
  581.             $EM->flush();
  582.             foreach ($POZYCJE as $POZYCJA) {
  583.                 $pp = new \App\Entity\PozycjaDokumentu ();
  584.                 $pp->setCenabrutto(floatval($POZYCJA ['brutto']));
  585.                 $pp->setCenanetto(floatval($POZYCJA ['netto']));
  586.                 $pp->setCenavat(floatval($POZYCJA ['brutto']) - floatval($POZYCJA ['netto']));
  587.                 $pp->setCsa(intval($zadanie->get("CSA")));
  588.                 $pp->setDokument($p);
  589.                 $pp->setDomena($POZYCJA ['name']);
  590.                 $pp->setIlosc(1);
  591.                 $pp->setNazwa("Rejestracja domeny: " $POZYCJA ['name']);
  592.                 $pp->setNs1($POZYCJA ['ns1']);
  593.                 $pp->setNs2($POZYCJA ['ns2']);
  594.                 $pp->setNs3($POZYCJA ['ns3']);
  595.                 $pp->setRodzaj(\App\Entity\PozycjaDokumentu::prRejestracjaDomeny);
  596.                 $pp->setWartoscbrutto(floatval($POZYCJA ['brutto']));
  597.                 $pp->setWartoscnetto(floatval($POZYCJA ['netto']));
  598.                 $pp->setWartoscvat(floatval($POZYCJA ['brutto']) - floatval($POZYCJA ['netto']));
  599.                 $EM->persist($pp);
  600.                 $EM->flush();
  601.             }
  602.             $EM->refresh($p);
  603.             
  604.             //Wygenerowanie pliku
  605.             //Faktura proforma
  606.             // Configure Dompdf according to your needs
  607.             $pdfOptions = new \Dompdf\Options();
  608.             $pdfOptions->set('defaultFont''Tahoma');
  609.             $pdfOptions->set('enable_remote'true);
  610.             //$pdfOptions->set('tempDir', "/var/www/80/chopin.ndc.pl/doc/temp");
  611.             //$pdfOptions->set('logOutputFile', "/var/www/80/chopin.ndc.pl/doc/temp/log.txt");
  612.             // Instantiate Dompdf with our options
  613.             $dompdf = new \Dompdf\Dompdf($pdfOptions);
  614.             // Retrieve the HTML generated in our twig file
  615.             $html $this->renderView('dokument/faktura-proforma-pdf-template.html.twig', [
  616.                 "dokument" => $p,
  617.                 "orgcpy" => "ORYGINAŁ",
  618.                 "słownie" => $slownie->kwotaslownie($p->getBrutto())
  619.             ]);
  620.             // Load HTML to Dompdf                
  621.             $dompdf->loadHtml($html);
  622.             // (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
  623.             $dompdf->setPaper('A4''portrait');
  624.             // Render the HTML as PDF
  625.             $dompdf->render();
  626.             // Output the generated PDF to Browser (force download)
  627.             $binaryPDF $dompdf->output();
  628.             $zalacznik = new \Swift_Attachment();
  629.             $zalacznik->setFilename (str_replace ("/""_"$p->getNumer()) . ".pdf");
  630.             $zalacznik->setContentType ("application/pdf");
  631.             $zalacznik->setBody ($binaryPDF);
  632.             
  633.             //Wysłanie e-maila
  634.             $emailMessage = new \Swift_Message(str_replace ('{nr}'$p->getNumer (), $EM->getRepository(\App\Entity\Conf::class)->peek ("email-domain-registration-title""InforPol NET: Zamówienie {nr} na rejestrację domen.")));
  635.             
  636.             $emailMessage->setFrom ($EM->getRepository(\App\Entity\Conf::class)->peek ("email-sender-return-address""info@ndc.pl"), $EM->getRepository(\App\Entity\Conf::class)->peek ("email-sender-name""INFORPOL NET"))
  637.                 ->setTo ($p->getUser()->getEmailFakturowy(), $p->getUser()->getNazwa())
  638.                 ->setBody (
  639.                     $this->renderView("email/rejestracja_proforma.html.twig", ["dokument" => $p]),
  640.                     'text/html'
  641.                 )->attach ($zalacznik);
  642.             $mailer->send($emailMessage);
  643.             return new \Symfony\Component\HttpFoundation\JsonResponse(["SUCCESS" => true"ITEMS" => $zadanie->get("ITEMS"), "CSA" => $zadanie->get("CSA")]);
  644.         } else {
  645.             throw new \Exception("Nieznany USER o identyfikatorze ID = " $userId);
  646.         }
  647.     }
  648.     /**
  649.      * Zasób kończy zamawianie domen w trybie zapłaty ON-LINE
  650.      * @Route("/admin/user/newDomain/finishOnLine/{userId}", name="post-new-domain-finish-on-line", methods={"POST"})
  651.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  652.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  653.      * @param int $userId
  654.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  655.      */
  656.     public function postNewDomainFinishOnLine(\Symfony\Component\HttpFoundation\Request $zadanie, \Doctrine\ORM\EntityManagerInterface $EMint $userId): \Symfony\Component\HttpFoundation\JsonResponse {
  657.         //$tpay = new \tpayLibs\src\_class_tpay\TransactionApi ();
  658.         $user $EM->getRepository(\App\Entity\User::class)->find($userId);
  659.         if ($user) {
  660.             $POZYCJE $zadanie->get("ITEMS");
  661.             $NETTO 0;
  662.             $VAT 0;
  663.             $BRUTTO 0;
  664.             foreach ($POZYCJE as $POZYCJA) {
  665.                 $NETTO += floatval($POZYCJA ['netto']);
  666.                 $BRUTTO += floatval($POZYCJA ['brutto']);
  667.             }
  668.             $p = new \App\Entity\Dokument();
  669.             $p->setBrutto($BRUTTO);
  670.             $p->setDatawystawienia(new \DateTime(date("Y-m-d")));
  671.             $p->setDozaplaty($BRUTTO);
  672.             $p->setFormaplatnosci(\App\Entity\Dokument::fpPrzelew);
  673.             $p->setNetto($NETTO);
  674.             $p->setOdbiorca($user->getNazwa() . "\n" . ($user->getNIP() ? "NIP: " $user->getNIP() : "PESEL: " $user->getPESEL()));
  675.             if (intval($zadanie->get("ADRES")) != 0) {
  676.                 $ADR $EM->getRepository(\App\Entity\Adres::class)->find(intval($zadanie->get("ADRES")));
  677.                 if ($ADR) {
  678.                     $p->setOdbiorca($p->getOdbiorca() . "\n" $ADR->getUlica() . " " $ADR->getDom() . ($ADR->getLokal() ? " lokal " $ADR->getLokal() : "") . "\n" $ADR->getKod() . " " $ADR->getMiasto() . "\n" $ADR->getKraj());
  679.                 }
  680.             }
  681.             $p->setRodzaj(\App\Entity\Dokument::dtFP);
  682.             $p->setStatus(\App\Entity\Dokument::dsNieZaplacony);
  683.             $p->setTerminplatnosci(new \DateTime(date("Y-m-d"time() + 86400 intval($EM->getRepository(\App\Entity\Conf::class)->peek("register-domains-pay-day-limit""7")))));
  684.             $p->setUser($user);
  685.             $p->setVat($BRUTTO $NETTO);
  686.             $p->setWystawca($EM->getRepository(\App\Entity\Conf::class)->peek("seller-text""seller-text"));
  687.             $numer_proformy intval($EM->getRepository(\App\Entity\Conf::class)->peek("proforma-counter""1"));
  688.             $EM->getRepository(\App\Entity\Conf::class)->poke("proforma-counter"$numer_proformy 1);
  689.             $format_numeru $EM->getRepository(\App\Entity\Conf::class)->peek("proforma-format""{nr}");
  690.             $p->setNumer(str_replace(["{nr}""{d}""{m}""{R}"], [$numer_proformydate("d"), date("m"), date("Y")], $format_numeru));
  691.             $EM->persist($p);
  692.             $EM->flush();
  693.             foreach ($POZYCJE as $POZYCJA) {
  694.                 $pp = new \App\Entity\PozycjaDokumentu ();
  695.                 $pp->setCenabrutto(floatval($POZYCJA ['brutto']));
  696.                 $pp->setCenanetto(floatval($POZYCJA ['netto']));
  697.                 $pp->setCenavat(floatval($POZYCJA ['brutto']) - floatval($POZYCJA ['netto']));
  698.                 $pp->setCsa(intval($zadanie->get("CSA")));
  699.                 $pp->setDokument($p);
  700.                 $pp->setDomena($POZYCJA ['name']);
  701.                 $pp->setIlosc(1);
  702.                 $pp->setNazwa("Rejestracja domeny: " $POZYCJA ['name']);
  703.                 $pp->setNs1($POZYCJA ['ns1']);
  704.                 $pp->setNs2($POZYCJA ['ns2']);
  705.                 $pp->setNs3($POZYCJA ['ns3']);
  706.                 $pp->setRodzaj(\App\Entity\PozycjaDokumentu::prRejestracjaDomeny);
  707.                 $pp->setWartoscbrutto(floatval($POZYCJA ['brutto']));
  708.                 $pp->setWartoscnetto(floatval($POZYCJA ['netto']));
  709.                 $pp->setWartoscvat(floatval($POZYCJA ['brutto']) - floatval($POZYCJA ['netto']));
  710.                 $EM->persist($pp);
  711.                 $EM->flush();
  712.             }
  713.             $EM->refresh($p);
  714.             
  715.             return new \Symfony\Component\HttpFoundation\JsonResponse(["SUCCESS" => true"DOCUMENT_ID" => $p->getId () ]);
  716.             
  717.         } else {
  718.             throw new \Exception("Nieznany USER o identyfikatorze ID = " $userId);
  719.         }        
  720.     }
  721.     
  722.     /**
  723.      * Zasób renderuje stronę rejestracji nowego uzytkownika
  724.      * @Route("/rejestracja", name="rejestracja", methods={"GET"})
  725.      * @param \Doctrine\ORM\EntityManagerInterface $em
  726.      * @return Response
  727.      */
  728.     public function getRejestracja (\Doctrine\ORM\EntityManagerInterface $em): Response {
  729.         return $this->render("rejestracja.html.twig", [
  730.             "kraje" => $em->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"]),
  731.             "nazwa" => [ "value" => """error" => false"message" => "" ],
  732.             "email" => [ "value" => """error" => false"message" => "" ],
  733.             "login" => [ "value" => """error" => false"message" => "" ],
  734.             "haslo1" => [ "value" => """error" => false"message" => "" ],
  735.             "haslo2" => [ "value" => """error" => false"message" => "" ],
  736.             "rodzaj_konta" => [ "value" => "person""error" => false"message" => "" ],
  737.             "identyfikator" => [ "value" => """error" => false"message" => "" ],
  738.             "email_fakturowy" => [ "value" => """error" => false"message" => "" ],
  739.             "reprezentant" => [ "value" => """error" => false"message" => "" ],
  740.             "telefon_kontaktowy" => [ "value" => """error" => false"message" => "" ],
  741.             "telefon_komorkowy" => [ "value" => """error" => false"message" => "" ],
  742.             "fax" => [ "value" => """error" => false"message" => "" ],
  743.             "kraj" => [ "value" => $em->getRepository (\App\Entity\Kraj::class)->findOneBy ( ["skrot2" => "PL" ])->getId (), "error" => false"message" => "" ],
  744.             "kod" => [ "value" => """error" => false"message" => "" ],
  745.             "miasto" => [ "value" => """error" => false"message" => "" ],
  746.             "ulica" => [ "value" => """error" => false"message" => "" ],
  747.             "dom" => [ "value" => """error" => false"message" => "" ],
  748.             "lokal" => [ "value" => """error" => false"message" => "" ],
  749.             "privateWHOIS" => [ "value" => true"error" => false"message" => "" ]
  750.         ]);
  751.     }
  752.     
  753.     /**
  754.      * Zasób rejestruje nowego użytkownika
  755.      * @Route("/rejestracja", name="postRejestracja", methods={"POST"})
  756.      * @param \App\Service\PassValidator $passv
  757.      * @param \Swift_Mailer $mailer
  758.      * @param \Doctrine\ORM\EntityManagerInterface $em
  759.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  760.      * @param \App\Service\phoneValidator $pv
  761.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI
  762.      * @return Response
  763.      */
  764.     public function postRejestracja (\App\Service\PassValidator $passv, \Swift_Mailer $mailer, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Component\HttpFoundation\Request $zadanie, \App\Service\phoneValidator $pv, \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI, \Psr\Log\LoggerInterface $log): Response {
  765.         $opcje = [
  766.             "kraje" => $em->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"]),
  767.             "nazwa" => [ "value" => $zadanie->get ("nazwa"), "error" => false"message" => "" ],
  768.             "email" => [ "value" => $zadanie->get ("email"), "error" => false"message" => "" ],
  769.             "login" => [ "value" => $zadanie->get ("login"), "error" => false"message" => "" ],
  770.             "haslo1" => [ "value" => $zadanie->get ("haslo1"), "error" => false"message" => "" ],
  771.             "haslo2" => [ "value" => $zadanie->get ("haslo2"), "error" => false"message" => "" ],
  772.             "rodzaj_konta" => [ "value" => $zadanie->get ("rodzaj_konta"), "error" => false"message" => "" ],
  773.             "identyfikator" => [ "value" => $zadanie->get ("identyfikator"), "error" => false"message" => "" ],
  774.             "email_fakturowy" => [ "value" => $zadanie->get ("email_fakturowy"), "error" => false"message" => "" ],
  775.             "reprezentant" => [ "value" => $zadanie->get ("reprezentant"), "error" => false"message" => "" ],
  776.             "telefon_kontaktowy" => [ "value" => $zadanie->get ("telefon_kontaktowy"), "error" => false"message" => "" ],
  777.             "telefon_komorkowy" => [ "value" => $zadanie->get ("telefon_komorkowy"), "error" => false"message" => "" ],
  778.             "fax" => [ "value" => $zadanie->get ("fax"), "error" => false"message" => "" ],
  779.             "kraj" => [ "value" => intval ($zadanie->get ("kraj")), "error" => false"message" => "" ],
  780.             "kod" => [ "value" => $zadanie->get ("kod"), "error" => false"message" => "" ],
  781.             "miasto" => [ "value" => $zadanie->get ("miasto"), "error" => false"message" => "" ],
  782.             "ulica" => [ "value" => $zadanie->get ("ulica"), "error" => false"message" => "" ],
  783.             "dom" => [ "value" => $zadanie->get ("dom"), "error" => false"message" => "" ],
  784.             "lokal" => [ "value" => $zadanie->get ("lokal"), "error" => false"message" => "" ],
  785.             "privateWHOIS" => [ "value" => ($zadanie->get ("privateWHOIS""off") == "on"), "error" => false"message" => "" ]
  786.         ];
  787.         if (trim ($opcje ['nazwa']['value']) == "") {
  788.             $opcje ['nazwa']['error'] = true;
  789.             $opcje ['nazwa']['message'] = "To pole nie może być puste.";
  790.         }
  791.         if (trim ($opcje ['email']['value']) == "") {
  792.             $opcje ['email']['error'] = true;
  793.             $opcje ['email']['message'] = "To pole nie może być puste.";
  794.         } else {
  795.             if (filter_var ($opcje ['email']['value'], FILTER_VALIDATE_EMAIL) === false) {
  796.                 $opcje ['email']['error'] = true;
  797.                 $opcje ['email']['message'] = "Ten adres e-mail wyglada na nieprawidłowy.";                
  798.             }
  799.         }
  800.         if (!$opcje ['email']['error']) {
  801.             $u $em->getRepository(\App\Entity\User::class)->findOneBy ([ "email" => $opcje ['email']['value']]);
  802.             if ($u) {
  803.                 $opcje ['email']['error'] = true;
  804.                 $opcje ['email']['message'] = "Ten adres e-mail jest już wykorzystywany. Proszę podać inny, lub zalogować się na swoje konto.";
  805.             }
  806.         }
  807.         if (trim ($opcje ['login']['value']) == "") {
  808.             $opcje ['login']['error'] = true;
  809.             $opcje ['login']['message'] = "To pole nie może być puste.";
  810.         }
  811.         if (!$opcje ['login']['error']) {
  812.             $u $em->getRepository(\App\Entity\User::class)->findOneBy ([ "login" => $opcje ['login']['value']]);
  813.             if ($u) {
  814.                 $opcje ['email']['error'] = true;
  815.                 $opcje ['email']['message'] = "Ten login jest już wykorzystywany. Proszę podać inny, lub zalogować się na swoje konto.";
  816.             }
  817.         }
  818.         if (trim ($opcje ['haslo1']['value']) == "") {
  819.             $opcje ['haslo1']['error'] = true;
  820.             $opcje ['haslo1']['message'] = "To pole nie może być puste.";
  821.         }
  822.         if (trim ($opcje ['haslo2']['value']) == "") {
  823.             $opcje ['haslo2']['error'] = true;
  824.             $opcje ['haslo2']['message'] = "To pole nie może być puste.";
  825.         }
  826.         if ($opcje ['rodzaj_konta'] == "company") {
  827.             if (trim ($opcje ['reprezentant']['value']) == "") {
  828.                 $opcje ['reprezentant']['error'] = "To pole nie może być puste.";
  829.                 $opcje ['reprezentant']['error'] = true;
  830.             }
  831.         }
  832.         if ($opcje ['haslo1']['value'] != $opcje ['haslo2']['value']) {
  833.             $opcje ['haslo1']['error'] = true;
  834.             $opcje ['haslo2']['error'] = true;
  835.             $opcje ['haslo1']['message'] = "Hasła nie mogą być różne.";
  836.             $opcje ['haslo2']['message'] = "Hasła nie mogą być różne.";
  837.         }
  838.         if (!$opcje ['haslo1']['error']) {
  839.             $passtest $passv->isValid($em$opcje ['haslo1']['value']);
  840.             if ($passtest !== true) {
  841.                 $opcje ['haslo1']['error'] = true;
  842.                 $opcje ['haslo2']['error'] = true;
  843.                 $opcje ['haslo1']['message'] = $passtest;
  844.                 $opcje ['haslo2']['message'] = $passtest;                
  845.             }
  846.         }
  847.         if (trim ($opcje ['identyfikator']['value']) == "") {
  848.             $opcje ['identyfikator']['error'] = true;
  849.             $opcje ['identyfikator']['message'] = "To pole nie może być puste.";
  850.         }
  851.         if (trim ($opcje ['email_fakturowy']['value']) != "") {
  852.             if (filter_var ($opcje ['email_fakturowy']['value'], FILTER_VALIDATE_EMAIL) === false) {
  853.                 $opcje ['email_fakturowy']['error'] = true;
  854.                 $opcje ['email_fakturowy']['message'] = "Ten adres e-mail wyglada na nieprawidłowy.";                
  855.             }
  856.         }
  857.         if (trim ($opcje ['telefon_kontaktowy']['value']) == "") {
  858.             $opcje ['telefon_kontaktowy']['error'] = true;
  859.             $opcje ['telefon_kontaktowy']['message'] = "To pole nie może być puste.";
  860.         } else {
  861.             //Walidacja telefonu
  862.             if (!$pv->isValid($opcje ['telefon_kontaktowy']['value'])) {
  863.                 $opcje ['telefon_kontaktowy']['error'] = true;
  864.                 $opcje ['telefon_kontaktowy']['message'] = "Ten numer telefonu wyglada na nieprawidłowy.";
  865.             }
  866.         }
  867.         if (trim ($opcje ['telefon_komorkowy']['value']) != "") {
  868.             if (!$pv->isValid($opcje ['telefon_komorkowy']['value'])) {
  869.                 $opcje ['telefon_komorkowy']['error'] = true;
  870.                 $opcje ['telefon_komorkowy']['message'] = "Ten numer telefonu wyglada na nieprawidłowy.";
  871.             }            
  872.         }
  873.         if (trim ($opcje ['fax']['value']) != "") {
  874.             if (!$pv->isValid($opcje ['fax']['value'])) {
  875.                 $opcje ['fax']['error'] = true;
  876.                 $opcje ['fax']['message'] = "Ten numer faksu wygląda na nieprawidłowy.";
  877.             }            
  878.         }
  879.         if (trim ($opcje ['kod']['value']) == "") {
  880.             $opcje ['kod']['error'] = true;
  881.             $opcje ['kod']['message'] = "To pole nie może być puste.";
  882.         }
  883.         if (trim ($opcje ['miasto']['value']) == "") {
  884.             $opcje ['miasto']['error'] = true;
  885.             $opcje ['miasto']['message'] = "To pole nie może być puste.";
  886.         }
  887.         if (trim ($opcje ['dom']['value']) == "") {
  888.             $opcje ['dom']['error'] = true;
  889.             $opcje ['dom']['message'] = "To pole nie może być puste.";
  890.         }
  891.         foreach ($opcje as $opcja) {
  892.             if (is_array ($opcja)) {
  893.                 if (isset ($opcja ['error'])) {
  894.                     if ($opcja ['error']) {
  895.                         return $this->render("rejestracja.html.twig"$opcje);
  896.                     }
  897.                 }
  898.             }
  899.         }
  900.         //Rejestracja użytkownika
  901.         $u = new \App\Entity\User ();
  902.         $u->setEmail($opcje ['email']['value']);
  903.         $u->setLogin($opcje ['login']['value']);
  904.         if ($opcje ['email_fakturowy']['value'] != ""$u->setEmailFakturowy($opcje ['email_fakturowy']['value']);
  905.         if ($opcje ['rodzaj_konta']['value'] == "person") {
  906.             $u->setPESEL ($opcje ['identyfikator']['value']);
  907.         } else {
  908.             $u->setNIP ($opcje ['identyfikator']['value']);
  909.         }
  910.         $u->setNazwa($opcje ['nazwa']['value']);
  911.         $u->setPassword($opcje ['haslo1']['value']);//$PHI->hashPassword ($u, $opcje ['haslo1']['value']));
  912.         $u->setPrivateWHOIS($opcje ['privateWHOIS']['value']);
  913.         $u->setRoles(["ROLE_USER"]);
  914.         if ($opcje ['telefon_komorkowy']['value'] != ""$u->setSMS($opcje ['telefon_komorkowy']['value']);
  915.         $u->setSaldo(0);
  916.         $u->setUwagi("Rejestracja z WWW");
  917.         $kontakty = [];
  918.         if (trim ($opcje ['telefon_kontaktowy']['value']) != "") {
  919.             $kontakty [] = [ "nazwa" => "Telefon kontaktowy""wartosc" => $opcje ['telefon_kontaktowy']['value'] ];
  920.         }
  921.         if (trim ($opcje ['telefon_komorkowy']['value']) != "") {
  922.             $kontakty [] = [ "nazwa" => "Telefon komórkowy""wartosc" => $opcje ['telefon_komorkowy']['value'] ];
  923.         }
  924.         if (trim ($opcje ['fax']['value']) != "") {
  925.             $kontakty [] = [ "nazwa" => "Faks""wartosc" => $opcje ['fax']['value'] ];
  926.         }
  927.         if (count ($kontakty) > 0) {
  928.             $u->setKontakty($kontakty);
  929.         }
  930.         $u->setCrDate(new \DateTime ());
  931.         $u->setPotwierdzenieMail(false);
  932.         $em->persist($u);
  933.         $em->flush();
  934.         
  935.         $a = new \App\Entity\Adres();
  936.         $a->setDom($opcje ['dom']['value']);
  937.         $a->setKod($opcje ['kod']['value']);
  938.         $a->setKraj($em->getRepository (\App\Entity\Kraj::class)->find (intval ($opcje ['kraj']['value']))->getSkrot2 ());
  939.         if ($opcje ['lokal']['value'] != ""$a->setLokal($opcje ['lokal']['value']);
  940.         $a->setMiasto($opcje ['miasto']['value']);
  941.         $a->setNazwa("Adres");
  942.         if ($opcje ['ulica']['value'] != ""$a->setUlica($opcje ['ulica']['value']);        
  943.         $a->setUser($u);
  944.         $em->persist($a);
  945.         $em->flush ();
  946.         
  947.         if ($opcje ['rodzaj_konta']['value'] == "person") {
  948.             $HRDMAKE $u->createNewCSA(
  949.                 $em,
  950.                 $opcje ['nazwa']['value'],
  951.                 $opcje ['rodzaj_konta']['value'],
  952.                 $opcje ['identyfikator']['value'],
  953.                 $opcje ['email']['value'],
  954.                 $pv->convert2HRD($opcje ['telefon_kontaktowy']['value']),
  955.                 $a->getKraj(),
  956.                 "",
  957.                 ((trim ($opcje ['telefon_komorkowy']['value']) == "") ? "" $pv->convert2HRD($opcje ['telefon_komorkowy']['value'])),
  958.                 ((trim ($opcje ['fax']['value']) == "") ? "" $pv->convert2HRD($opcje ['fax']['value'])),
  959.                 trim ($opcje ['ulica']['value'] . " " $opcje ['dom']['value'] . " lok. " $opcje ['lokal']['value']),
  960.                 $opcje ['kod']['value'],
  961.                 $opcje ['miasto']['value']
  962.             );            
  963.         } else {
  964.             $HRDMAKE $u->createNewCSA(
  965.                 $em,
  966.                 $opcje ['nazwa']['value'],
  967.                 $opcje ['rodzaj_konta']['value'],
  968.                 $opcje ['identyfikator']['value'],
  969.                 $opcje ['email']['value'],
  970.                 $pv->convert2HRD($opcje ['telefon_kontaktowy']['value']),
  971.                 $a->getKraj(),
  972.                 $opcje ['reprezentant']['value'],
  973.                 ((trim ($opcje ['telefon_komorkowy']['value']) == "") ? "" $pv->convert2HRD($opcje ['telefon_komorkowy']['value'])),
  974.                 ((trim ($opcje ['fax']['value']) == "") ? "" $pv->convert2HRD($opcje ['fax']['value'])),
  975.                 trim ($opcje ['ulica']['value'] . " " $opcje ['dom']['value'] . " lok. " $opcje ['lokal']['value']),
  976.                 $opcje ['kod']['value'],
  977.                 $opcje ['miasto']['value']
  978.             );            
  979.         }
  980.         if (substr ($HRDMAKE03) == "OK:") {
  981.             //Przypisanie ewentualnego koszyka do konta
  982.             if ($zadanie->getSession()->isStarted()) {
  983.                 if ($zadanie->getSession()->has("koszyk")) {
  984.                     //Przepisywanie koszyka z sesji do usera
  985.                     if (!$u->getKoszyk()) {
  986.                         $koszyk = new \App\Entity\Koszyk ();
  987.                         $koszyk->setUser($u);
  988.                         $em->persist($koszyk);
  989.                         $em->flush();
  990.                         $em->refresh($u);
  991.                     }
  992.                     foreach ($zadanie->getSession()->get("koszyk")->getPozycja() as $pozycja) {
  993.                         if (!$u->getKoszyk()->isIn($pozycja->getNazwa())) {
  994.                             $poz = new \App\Entity\PozycjaDokumentu();
  995.                             $poz->setCenabrutto($pozycja->getCenabrutto());
  996.                             $poz->setCenanetto($pozycja->getCenanetto());
  997.                             $poz->setCenavat($pozycja->getCenavat());
  998.                             $poz->setDomena($pozycja->getDomena());
  999.                             $poz->setIlosc($pozycja->getIlosc());
  1000.                             $poz->setKoszyk($u->getKoszyk());
  1001.                             $poz->setNazwa($pozycja->getNazwa());
  1002.                             $poz->setNs1($pozycja->getNs1());
  1003.                             $poz->setNs2($pozycja->getNs2());
  1004.                             $poz->setNs3($pozycja->getNs3());
  1005.                             $poz->setRodzaj($pozycja->getRodzaj());
  1006.                             $poz->setWartoscbrutto($pozycja->getWartoscbrutto());
  1007.                             $poz->setWartoscnetto($pozycja->getWartoscnetto());
  1008.                             $poz->setWartoscvat($pozycja->getWartoscvat());
  1009.                             $poz->setZrealizowane(false);
  1010.                             $em->persist($poz);
  1011.                             $em->flush();
  1012.                         }
  1013.                     }
  1014.                     $zadanie->getSession()->remove("koszyk");                    
  1015.                 }
  1016.             }
  1017.             //Wysłanie maila aktywacyjnego
  1018.             $emailMessage = new \Swift_Message($em->getRepository(\App\Entity\Conf::class)->peek ("email-activation-account-title""InforPol NET: Aktywacja konta."));
  1019.             
  1020.             $emailMessage->setFrom ($em->getRepository(\App\Entity\Conf::class)->peek ("email-sender-return-address""info@ndc.pl"), $em->getRepository(\App\Entity\Conf::class)->peek ("email-sender-name""INFORPOL NET"))
  1021.                 ->setTo ($u->getEmail(), $u->getNazwa())
  1022.                 ->setBody (
  1023.                     $this->renderView("email/aktywacja_konta.html.twig", ["account" => $u"key" => md5 ($u->getId() . date ("Y-m-d H:i:s"$u->getCrDate()->getTimestamp()))]),
  1024.                     'text/html'
  1025.                 );
  1026.             $mailer->send($emailMessage);
  1027.             return $this->render("rejestracja-ok.html.twig", [ "account" => $u"czasAktywacji" => $em->getRepository(\App\Entity\Conf::class)->peek ("inactive-account-lifetime"7) ]);
  1028.         } else {
  1029.             $log->debug("CREATENEWCSA", [$HRDMAKE]);
  1030.             $em->refresh($u);
  1031.             $em->remove($u);
  1032.             $em->flush ();
  1033.             $opcje ['alerts'] = [ "message" => print_r ($HRDMAKEtrue) ];
  1034.             return $this->render("rejestracja.html.twig"$opcje);
  1035.         }
  1036.     }
  1037.     
  1038.     /**
  1039.      * Zasób aktywuje konto
  1040.      * @Route("/aktywacja/{key}", name="aktywacja-konta", methods={"GET"})
  1041.      * @param \Doctrine\ORM\EntityManagerInterface $em
  1042.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI
  1043.      * @param \Psr\Log\LoggerInterface $log
  1044.      * @param string $key
  1045.      * @return Response
  1046.      */
  1047.     public function activateAccount (\Doctrine\ORM\EntityManagerInterface $em, \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI, \Psr\Log\LoggerInterface $logstring $key): Response {
  1048.         $user $em->getRepository (\App\Entity\User::class)->findByActivationKey ($key);
  1049.         if ($user) {
  1050.             if ($user->isPotwierdzenieMail()) {
  1051.                 return $this->render("aktywacja-ponowna-ok.html.twig", [ "user" => $user ]);                
  1052.             } else {
  1053.                 //$log->info ("AKTYWACJA! EMAIL: \"" . $user->getEmail () . "\", PASS: \"" . $user->getPassword () . "\"");
  1054.                 $user->setPotwierdzenieMail(true);
  1055.                 $user->setPassword($PHI->hashPassword ($user$user->getPassword()));
  1056.                 $em->persist($user);
  1057.                 $em->flush ();
  1058.                 return $this->render("aktywacja-ok.html.twig", [ "user" => $user ]);
  1059.             }
  1060.         } else {
  1061.             return $this->render("aktywacja-fail.html.twig");
  1062.         }
  1063.     }
  1064.     
  1065.     /**
  1066.      * Zasób wyświetla formularz profilu urzytkownika
  1067.      * @Route ("/profil", name="my-profile", methods={"GET"})
  1068.      * @IsGranted("ROLE_USER")
  1069.      * @param \Doctrine\ORM\EntityManagerInterface $em
  1070.      * @return Response
  1071.      */
  1072.     public function getProfil (\Doctrine\ORM\EntityManagerInterface $em): Response {
  1073.         return $this->render ("profil.html.twig", [
  1074.             "kraje" => $em->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"])
  1075.         ]);
  1076.     }
  1077.     
  1078.     /**
  1079.      * Zasób wyświetla dokonuje zmian w profilu i wyświetla formularz profilu urzytkownika
  1080.      * @Route ("/profil", name="my-profile-post", methods={"POST"})
  1081.      * @IsGranted("ROLE_USER")
  1082.      * @param \App\Service\PassValidator $pv
  1083.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  1084.      * @param \Doctrine\ORM\EntityManagerInterface $em
  1085.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI
  1086.      * @return Response
  1087.      */
  1088.     public function postProfil (\App\Service\PassValidator $pv, \Symfony\Component\HttpFoundation\Request $zadanie, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI): Response {
  1089.         $errors = [];
  1090.         if (trim ($zadanie->get ("haslo1""")) != "") {
  1091.             if ($zadanie->get ("haslo1""") != $zadanie->get ("haslo2""")) {
  1092.                 $errors [] = [ "body" => "podane hasła są różne." ];
  1093.             } else {
  1094.                 $test $pv->isValid($em$zadanie->get ("haslo1"""));
  1095.                 if ($test !== true) {
  1096.                     $errors [] = [ "body" => $test ];
  1097.                 }
  1098.             }
  1099.         }
  1100.         if (trim ($zadanie->get("nazwa""")) == "") {
  1101.             $errors [] = [ "body" => "Pole \"<b>Imię i Nazwisko lub Nazwa</b>\" nie moze być puste." ];
  1102.         }
  1103.         if (trim ($zadanie->get ("email_fakturowy""")) != "") {
  1104.             if (!filter_var (trim ($zadanie->get ("email_fakturowy""")), FILTER_VALIDATE_EMAIL)) {
  1105.                 $errors [] = [ "body" => "Podany adres e-mail w polu \"<b>Adres e-mail na który będziemy wysyłać dokumenty księgowe</b>\" jest nieprawidlowy." ];
  1106.             }
  1107.         }
  1108.         if ((trim ($zadanie->get ("nip""")) == "") && (trim ($zadanie->get ("pesel""")) == "")) {
  1109.             $errors [] = [ "body" => "Proszę podać przynajmniej jeden numer identyfikacyjny. NIP lub PESEL." ];
  1110.         }
  1111.         if ($zadanie->get("kontakt-nazwa"NULL) != NULL) {
  1112.             $pusta_nazwa false;
  1113.             $pusta_wartosc false;
  1114.             foreach ($zadanie->get ("kontakt-nazwa"NULL) as $index => $nazwa) {
  1115.                 $pusta_nazwa |= (trim ($nazwa) == "");
  1116.                 $pusta_wartosc |= (trim ($zadanie->get("kontakt-wartosc"NULL)[$index]) == "");
  1117.             }
  1118.             if ($pusta_nazwa$errors [] = [ "body" => "W sekcji \"<b>Dodatkowe formy kontaktu</b>\" nie może występować pusta nazwa." ];
  1119.             if ($pusta_wartosc$errors [] = [ "body" => "W sekcji \"<b>Dodatkowe formy kontaktu</b>\" nie może występować pusta wartość." ];
  1120.         }
  1121.         if ($zadanie->get("adres_nazwa"NULL) == NULL) {
  1122.             $errors [] = [ "body" => "Proszę podać przynajmniej jeden adres pocztowy." ];
  1123.         } else {
  1124.             $puste = [ "nazwa" => false"kod" => false"miasto" => false"dom" => false ];
  1125.             foreach ($zadanie->get ("adres_nazwa"NULL) as $index => $nazwa) {
  1126.                 $puste ['nazwa'] |= (trim ($nazwa) == "");
  1127.                 $puste ['kod'] |= (trim ($zadanie->get("adres_kod")[$index]) == "");
  1128.                 $puste ['miasto'] |= (trim ($zadanie->get("adres_miasto")[$index]) == "");
  1129.                 $puste ['dom'] |= (trim ($zadanie->get("adres_dom")[$index]) == "");
  1130.             }
  1131.             if ($puste ['nazwa']) $errors [] = [ "body" => "W sekcji \"<b>Adresy pocztowe</b>\" pole \"<b>Nazwa</b>\" nie może być puste." ];
  1132.             if ($puste ['kod']) $errors [] = [ "body" => "W sekcji \"<b>Adresy pocztowe</b>\" pole \"<b>Kod pocztowy</b>\" nie może być puste." ];
  1133.             if ($puste ['miasto']) $errors [] = [ "body" => "W sekcji \"<b>Adresy pocztowe</b>\" pole \"<b>Miejscowość</b>\" nie może być puste." ];
  1134.             if ($puste ['dom']) $errors [] = [ "body" => "W sekcji \"<b>Adresy pocztowe</b>\" pole \"<b>Numer domu</b>\" nie może być puste." ];
  1135.         }
  1136.         if (count ($errors) > 0) {
  1137.             return $this->render ("profil.html.twig", [
  1138.                 "messages" => $errors,
  1139.                 "kraje" => $em->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"])
  1140.             ]);            
  1141.         } else {
  1142.             $em->persist ($this->getUser ());
  1143.             $this->getUser ()->setNazwa(trim ($zadanie->get ("nazwa""")));
  1144.             if (trim ($zadanie->get ("haslo1""")) != "") {
  1145.                 $this->getUser ()->setPassword($PHI->hashPassword ($this->getUser (), $zadanie->get("haslo1")));
  1146.             }
  1147.             if (trim ($zadanie->get ("nip""")) != "") {
  1148.                 $this->getUser ()->setNIP (trim ($zadanie->get ("nip")));
  1149.             } else {
  1150.                 $this->getUser ()->setNIP (NULL);
  1151.             }
  1152.             if (trim ($zadanie->get ("pesel""")) != "") {
  1153.                 $this->getUser ()->setPESEL (trim ($zadanie->get ("pesel")));
  1154.             } else {
  1155.                 $this->getUser ()->setPESEL (NULL);
  1156.             }
  1157.             if (trim ($zadanie->get ("sms""")) != "") {
  1158.                 $this->getUser ()->setSMS (trim ($zadanie->get ("sms")));
  1159.             } else {
  1160.                 $this->getUser ()->setSMS (NULL);
  1161.             }
  1162.             if (trim ($zadanie->get ("email_fakturowy""")) != "") {
  1163.                 $this->getUser ()->setEmailFakturowy (trim ($zadanie->get ("email_fakturowy")));
  1164.             } else {
  1165.                 $this->getUser ()->setEmailFakturowy (NULL);
  1166.             }
  1167.             if ($zadanie->get ("kontakt-nazwa"NULL) != NULL) {
  1168.                 $kontakty = [];
  1169.                 foreach ($zadanie->get ("kontakt-nazwa"NULL) as $index => $nazwa) {
  1170.                     $kontakty [] = [ "nazwa" => $nazwa"wartosc" => $zadanie->get ("kontakt-wartosc"NULL)[$index]];
  1171.                 }
  1172.                 $this->getUser ()->setKontakty($kontakty);
  1173.             } else {
  1174.                 $this->getUser ()->setKontakty (NULL);
  1175.             }
  1176.             $em->flush ();
  1177.             //Usuwamy adresy
  1178.             foreach ($this->getUser ()->getAdresy () as $adres) {
  1179.                 $jest false;
  1180.                 foreach ($zadanie->get ("adres_id"NULL) as $index => $adr_id) {
  1181.                     if ($adres->getId () == intval ($adr_id)) {
  1182.                         $jest true;
  1183.                         break;
  1184.                     }
  1185.                 }
  1186.                 if (!$jest) {
  1187.                     $em->remove($adres);
  1188.                     $em->flush ();
  1189.                 }
  1190.             }
  1191.             $em->refresh ($this->getUser ());
  1192.             foreach ($zadanie->get ("adres_id"NULL) as $index => $adr_id) {
  1193.                 if (intval ($adr_id) != 0) {
  1194.                     //Edytujemy Adres
  1195.                     $adr_obj $em->getRepository (\App\Entity\Adres::class)->find (intval ($adr_id));
  1196.                     $em->persist ($adr_obj);
  1197.                     $adr_obj->setNazwa($zadanie->get ("adres_nazwa"NULL)[$index]);
  1198.                     $adr_obj->setKraj($zadanie->get ("adres_kraj"NULL)[$index]);
  1199.                     $adr_obj->setKod($zadanie->get ("adres_kod"NULL)[$index]);
  1200.                     $adr_obj->setMiasto($zadanie->get ("adres_miasto"NULL)[$index]);
  1201.                     if (trim ($zadanie->get ("adres_ulica"NULL)[$index]) != "") {
  1202.                         $adr_obj->setUlica(trim ($zadanie->get ("adres_ulica"NULL)[$index]));
  1203.                     } else {
  1204.                         $adr_obj->setUlica(NULL);
  1205.                     }
  1206.                     $adr_obj->setDom($zadanie->get ("adres_dom"NULL)[$index]);
  1207.                     if (trim ($zadanie->get ("adres_lokal"NULL)[$index]) != "") {
  1208.                         $adr_obj->setLokal(trim ($zadanie->get ("adres_lokal"NULL)[$index]));
  1209.                     } else {
  1210.                         $adr_obj->setLokal(NULL);
  1211.                     }
  1212.                     $em->flush ();
  1213.                 } else {
  1214.                     //Dodajemy Adres
  1215.                     $adr_obj = new \App\Entity\Adres ();
  1216.                     $em->persist ($adr_obj);
  1217.                     $adr_obj->setNazwa($zadanie->get ("adres_nazwa"NULL)[$index]);
  1218.                     $adr_obj->setKraj($zadanie->get ("adres_kraj"NULL)[$index]);
  1219.                     $adr_obj->setKod($zadanie->get ("adres_kod"NULL)[$index]);
  1220.                     $adr_obj->setMiasto($zadanie->get ("adres_miasto"NULL)[$index]);
  1221.                     if (trim ($zadanie->get ("adres_ulica"NULL)[$index]) != "") {
  1222.                         $adr_obj->setUlica(trim ($zadanie->get ("adres_ulica"NULL)[$index]));
  1223.                     } else {
  1224.                         $adr_obj->setUlica(NULL);
  1225.                     }
  1226.                     $adr_obj->setDom($zadanie->get ("adres_dom"NULL)[$index]);
  1227.                     if (trim ($zadanie->get ("adres_lokal"NULL)[$index]) != "") {
  1228.                         $adr_obj->setLokal(trim ($zadanie->get ("adres_lokal"NULL)[$index]));
  1229.                     } else {
  1230.                         $adr_obj->setLokal(NULL);
  1231.                     }
  1232.                     $adr_obj->setUser($this->getUser ());
  1233.                     $em->flush ();
  1234.                 }
  1235.             }
  1236.             $em->refresh ($this->getUser ());
  1237.             return $this->render ("profil.html.twig", [
  1238.                 "alerts" => [[ "icon" => "bi-check""class" => "success""message" => "Twoje dane zostały zaktualizowane." ]],
  1239.                 "kraje" => $em->getRepository(\App\Entity\Kraj::class)->findBy([], ["nazwa" => "ASC"])
  1240.             ]);
  1241.         }
  1242.     }
  1243.     
  1244. }