src/JuridicusBundle/Controller/PrueferController.php line 162

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  7. use Symfony\Component\Process\Process;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  14. use JF\JuridicusBundle\Entity\Kunde;
  15. use JF\JuridicusBundle\Entity\KundePruefung;
  16. use JF\JuridicusBundle\Entity\PrueferEmail;
  17. use JF\JuridicusBundle\Entity\Pruefer;
  18. use JF\JuridicusBundle\Entity\PrueferUser;
  19. use JF\JuridicusBundle\Entity\Dienststellung;
  20. use JF\JuridicusBundle\Entity\Titel;
  21. use JF\JuridicusBundle\Entity\User;
  22. use JF\JuridicusBundle\Entity\Pruefung;
  23. use JF\JuridicusBundle\Entity\PdfProtokollmappePruefer;
  24. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefer;
  25. use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer;
  26. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefung;
  27. use JF\JuridicusBundle\Entity\Download;
  28. use JF\JuridicusBundle\Entity\Pruefungsamt;
  29. use JF\JuridicusBundle\Entity\Bundesland;
  30. use JF\JuridicusBundle\Form\PrueferType;
  31. use JF\JuridicusBundle\Form\PrueferUserType;
  32. use JF\JuridicusBundle\Form\PruefungsamtPreSelectType;
  33. use Symfony\Component\Form\Extension\Core\Type\DateType;
  34. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  35. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  36. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  37. use Swift_Mailer;
  38. use Swift_Message;
  39. use Doctrine\ORM\EntityManagerInterface;
  40. use JF\JuridicusBundle\Services\Sms;
  41. use JF\JuridicusBundle\Entity\MailTemplate;
  42. /**
  43. * Pruefer controller.
  44. */
  45. class PrueferController extends AbstractController
  46. {
  47. /**
  48. * Lists all Pruefungsamt entities.
  49. *
  50. * @Route("/pruefungsprotokolle-{examNr}-staatsexamen", name="pruefer")
  51. */
  52. public function indexAction($examNr = 1)
  53. {
  54. $em = $this->getDoctrine()->getManager();
  55. if ($examNr == 1) {
  56. $examType = Pruefung::TYP_EXAMEN_1;
  57. } else {
  58. $examType = Pruefung::TYP_EXAMEN_2;
  59. }
  60. $pip_repo = $em->getRepository(ProtokollInfothekPruefer::class);
  61. $statistik = $pip_repo->filterParagraphsByExamen($examType);
  62. $bundeslaender = $em->getRepository(Bundesland::class)->findAll();
  63. $entities = $em->getRepository(Pruefung::class)->findNewest(8, $examType);
  64. $entities_indexed1 = array();
  65. $entities_indexed2 = array();
  66. $index = 0;
  67. foreach ($entities as $entity) {
  68. $datum = $entity->getDatum()->format('d.m.Y');
  69. if ($index%2 == 0) {
  70. $entities_indexed1[$datum][] = $entity;
  71. } else {
  72. $entities_indexed2[$datum][] = $entity;
  73. }
  74. $index++;
  75. }
  76. $filter_form = $this->createParagraphFilterForm($examNr);
  77. return $this->render('@JFJuridicusBundle/Pruefer/pruefungsamt_index.html.twig', array(
  78. 'statistik' => $statistik,
  79. 'filter_form' => $filter_form->createView(),
  80. 'entities_indexed1' => $entities_indexed1,
  81. 'entities_indexed2' => $entities_indexed2,
  82. 'examType' => $examType,
  83. 'entities' => $bundeslaender,
  84. ));
  85. }
  86. /**
  87. *
  88. * @param array $data
  89. * @return \Symfony\Component\Form\Form
  90. */
  91. private function createParagraphFilterForm($examNr)
  92. {
  93. $data = array('examen'=>$examNr);
  94. return $this->createFormBuilder($data)
  95. ->add('bundesland', EntityType::class, array(
  96. 'label' => false,
  97. 'class' => 'JF\JuridicusBundle\Entity\Bundesland',
  98. 'placeholder' => 'Bundesland wählen...',
  99. 'required' => false,
  100. ))
  101. ->add('fach', ChoiceType::class, array(
  102. 'label' => false,
  103. 'placeholder' => 'Fach auswählen...',
  104. 'choices' => array(
  105. 'Strafrecht' => 'Strafrecht',
  106. 'Öffentliches Recht' => 'Öffentliches Recht',
  107. 'Zivilrecht' => 'Zivilrecht',
  108. 'Arbeitsrecht' => 'Arbeitsrecht',
  109. 'Verwaltungsrecht' => 'Verwaltungsrecht',
  110. ),
  111. 'required' => false,
  112. ))
  113. ->add('startdatum', DateType::class, array(
  114. 'label' => false,
  115. 'placeholder' => 'Zeitraum von',
  116. 'widget' => 'single_text',
  117. //'format' => 'dd.MM.yyyy',
  118. 'required' => false,
  119. 'attr' => ['class' => 'js-datepicker', 'placeholder' => 'Zeitraum von ...',],
  120. ))
  121. ->add('endedatum', DateType::class, array(
  122. 'label' => false,
  123. 'placeholder' => 'bis ...',
  124. 'widget' => 'single_text',
  125. //'format' => 'dd.MM.yyyy',
  126. 'placeholder' => '',
  127. 'required' => false,
  128. 'attr' => ['class' => 'js-datepicker', 'placeholder' => 'bis',],
  129. ))
  130. ->add('examen', HiddenType::class, array(
  131. 'label' => false,
  132. 'required' => false,
  133. ))
  134. ->getForm();
  135. }
  136. /**
  137. * Finds and displays Pruefer entities for a given Prüfungsamt
  138. *
  139. * @Route("/pruefungsprotokolle-{examen}-staatsexamen/{bslug}",
  140. * name="pruefer_index_pruefungsamt",
  141. * requirements={"examen"="[12]"}
  142. * )
  143. */
  144. public function showPruefungsamtAction($bslug, $examen)
  145. {
  146. $em = $this->getDoctrine()->getManager();
  147. $pruefungsamt = $em->getRepository(Pruefungsamt::class)->findByExamenAndBSlug($examen, $bslug);
  148. if (!$pruefungsamt) {
  149. throw $this->createNotFoundException('Prüfungsamt wurde nicht gefunden.');
  150. }
  151. $pruefer_liste = $em->getRepository(Pruefer::class)
  152. ->findByPruefungsamt($pruefungsamt->getId(), $pruefungsamt->hasVollbestand());
  153. $statistik = $em->getRepository(ProtokollInfothekPruefer::class)->filterParagraphsByPruefungsamt($pruefungsamt);
  154. return $this->render('@JFJuridicusBundle/Pruefer/index.html.twig', array(
  155. 'pruefungsamt' => $pruefungsamt,
  156. 'pruefer_liste' => $pruefer_liste,
  157. 'typ_options' => Pruefung::getTypOptions(),
  158. 'statistik' => $statistik,
  159. ));
  160. }
  161. /**
  162. * Finds and displays a Pruefer entity.
  163. *
  164. * @Route("/pruefungsprotokolle-{examen}-staatsexamen/{bslug}/{pslug}_pruefer_protokolle_pruefung_jura",
  165. * name="pruefer_show",
  166. * requirements={"examen"="[12]"}
  167. * )
  168. */
  169. public function showAction($examen, $bslug, $pslug)
  170. {
  171. $em = $this->getDoctrine()->getManager();
  172. $bundesland = $em->getRepository(Bundesland::class)->findOneBySlug($bslug);
  173. if (!$bundesland) {
  174. throw $this->createNotFoundException('Bundesland wurde nicht gefunden.');
  175. }
  176. $pruefungsamt = $em->getRepository(Pruefungsamt::class)->findByExamenAndBSlug($examen, $bslug);
  177. if (!$pruefungsamt) {
  178. throw $this->createNotFoundException('Prüfungsamt wurde nicht gefunden.');
  179. }
  180. // Bei Vollbestand werden Prüfer ohne Protokolle umgeleitet - eventuell ändern?
  181. $pruefer = $em->getRepository(Pruefer::class)
  182. ->findByPruefungsamtAndSlug($pruefungsamt->getId(), $pslug, $pruefungsamt->hasVollbestand());
  183. if (!$pruefer) {
  184. return $this->redirect($this->generateUrl('pruefer_index_pruefungsamt', array(
  185. 'examen' => $examen, 'bslug' => $bslug,
  186. )));
  187. }
  188. $kunde = new Kunde();
  189. $kunde->setBundesland($bundesland);
  190. $kunde->setExamen($examen);
  191. $form = $this->createForm(PruefungsamtPreSelectType::class, $kunde);
  192. return $this->render('@JFJuridicusBundle/Pruefer/show.html.twig', array(
  193. 'bundesland' => $bundesland,
  194. 'examen' => $examen,
  195. 'pruefungsamt' => $pruefungsamt,
  196. 'pruefer' => $pruefer,
  197. 'form' => $form->createView(),
  198. 'typ_options' => Pruefung::getTypOptions(),
  199. ));
  200. }
  201. /**
  202. * Finds and displays a Pruefer and shows download text
  203. *
  204. * @Route("/pruefer/download/success", name="pruefer_download_success")
  205. * @Method({"POST"})
  206. */
  207. public function downloadSuccessAction(Request $request)
  208. {
  209. $this->denyAccessUnlessGranted('ROLE_KUNDE');
  210. $em = $this->getDoctrine()->getManager();
  211. $user = $this->getUser();
  212. $kunde = $user->getKunde();
  213. /* @var $kunde \JF\JuridicusBundle\Entity\Kunde */
  214. $pruefer_id = $request->request->getInt('pruefer_id');
  215. $pruefung_id = $request->request->getInt('pruefung_id');
  216. $examen = $request->request->getInt('examen');
  217. if (!$pruefer_id or !$examen or !$pruefung_id) {
  218. throw new AccessDeniedException();
  219. }
  220. $pruefer = $em->getRepository(Pruefer::class)->find($pruefer_id);
  221. if (!$pruefer) {
  222. throw $this->createNotFoundException('Prüfer nicht gefunden');
  223. }
  224. if ($pruefer->getAliasFor()) {
  225. $pruefer = $pruefer->getAliasFor();
  226. }
  227. // Berechtigung checken
  228. $buchung = $em->getRepository(KundePruefung::class)->getDownloadPermission($kunde->getId(), $pruefer->getId());
  229. /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  230. if (!$buchung) {
  231. // Donwload nicht erlaubt
  232. throw new AccessDeniedException();
  233. } else if ($buchung->needsFacebookPost()) {
  234. // umleiten
  235. return $this->redirect($this->generateUrl('facebook_write_post', array(
  236. 'id' => $buchung->getId(),
  237. 'pruefer_id' => $pruefer_id,
  238. 'pruefung_id' => $pruefung_id,
  239. 'examen' => $examen
  240. )));
  241. } else if ($buchung->needsKlausurprotokoll()) {
  242. // umleiten
  243. return $this->redirect($this->generateUrl('protokoll_klausur_edit', array('id' => $buchung->getId())));
  244. } else {
  245. // Download erlaubt
  246. $pdf = $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), $examen);
  247. if (!$pdf) {
  248. throw $this->createNotFoundException('Protokolldatei nicht gefunden');
  249. }
  250. }
  251. return $this->render("@JFJuridicusBundle/Pruefer/download_success.html.twig", array(
  252. 'pruefer' => $pruefer,
  253. 'examen' => $examen,
  254. 'pdf_id' => $pdf->getId()
  255. ));
  256. }
  257. /**
  258. * shows download error text
  259. *
  260. * @Route("/pruefer/download/error", name="pruefer_download_error")
  261. */
  262. public function downloadErrorAction(Request $request)
  263. {
  264. $this->denyAccessUnlessGranted('ROLE_KUNDE');
  265. return $this->render('@JFJuridicusBundle/Pruefer/download_error.html.twig', array());
  266. }
  267. /**
  268. * @Route("/pruefer/download/success/protokollmappe-{id}.pdf", name="pruefer_download")
  269. */
  270. public function downloadAction(PdfProtokollmappePruefer $pdf)
  271. {
  272. $this->denyAccessUnlessGranted('ROLE_KUNDE');
  273. $em = $this->getDoctrine()->getManager();
  274. $user = $this->getUser();
  275. $kunde = $user->getKunde();
  276. /* @var $kunde \JF\JuridicusBundle\Entity\Kunde */
  277. $pruefer = $pdf->getPruefer();
  278. // Berechtigung checken
  279. $buchung = $em->getRepository(KundePruefung::class)->getDownloadPermission($kunde->getId(), $pruefer->getId());
  280. /* @var $buchung \JF\JuridicusBundle\Entity\KundePruefung */
  281. if (!$buchung || $buchung->needsKlausurprotokoll()) {
  282. throw new AccessDeniedException();
  283. }
  284. // Dateiname für private Kopie
  285. $dir = $pdf->getDir();
  286. $stamped_path = tempnam($dir, 'protokoll_stamped_');
  287. //print_r($kunde->getPdfStempel()->getPath());
  288. //exit();
  289. // Protokoll stempeln
  290. $process = new Process([
  291. 'pdftk',
  292. $pdf->getPath(),
  293. 'stamp',
  294. $kunde->getPdfStempel()->getPath(),
  295. 'output',
  296. $stamped_path,
  297. 'owner_pw',
  298. 'stucha5Ac3ep', // später: $bag->get('tcpdf_owner_pw')
  299. 'allow',
  300. 'printing',
  301. ]);
  302. $process->run();
  303. if (!$process->isSuccessful()) {
  304. var_dump($process->getErrorOutput());
  305. exit();
  306. return $this->redirect($this->generateUrl('pruefer_download_error'));
  307. }
  308. $download = $em->getRepository(Download::class)->findOneBy(array(
  309. 'kunde' => $kunde->getId(), 'pruefer' => $pruefer->getId(), 'examen' => $pdf->getExamen()
  310. ));
  311. /* @var $download \JF\JuridicusBundle\Entity\Download */
  312. if (!$download) {
  313. $download = new Download();
  314. $download->setKunde($kunde)->setPruefer($pruefer)->setExamen($pdf->getExamen());
  315. }
  316. $download->setBuchung($buchung);
  317. $download->setAnzahlProtokolle($pdf->getAnzahlProtokolle());
  318. $em->persist($download);
  319. $em->flush();
  320. $filename = sprintf('%s-%d-examen.pdf', $pruefer->getSlug(), $pdf->getExamen());
  321. $response = new Response();
  322. $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
  323. $response->headers->set('Content-Disposition', $disposition);
  324. $response->headers->set('Content-Type', $pdf->getMimeType());
  325. $response->setContent(@file_get_contents($stamped_path));
  326. unlink($stamped_path);
  327. return $response;
  328. }
  329. /**
  330. * Displays a form to create a new Pruefer entity.
  331. *
  332. * @Route("/create/pruefer/ajax/new", name="pruefer_ajax_new")
  333. */
  334. public function newAjaxAction()
  335. {
  336. $this->denyAccessUnlessGranted('ROLE_KUNDE');
  337. $em = $this->getDoctrine()->getManager();
  338. $dienststellung_typeaheads = $em->getRepository(Dienststellung::class)->getTypeaheads();
  339. $titel_typeaheads = $em->getRepository(Titel::class)->getTypeaheads();
  340. $entity = new Pruefer();
  341. $form = $this->createForm(PrueferType::class, $entity);
  342. return $this->render("@JFJuridicusBundle/Pruefer/new.html.twig", array(
  343. 'entity' => $entity,
  344. 'form' => $form->createView(),
  345. 'dienststellungNames' => array_keys($dienststellung_typeaheads),
  346. 'titelNames' => array_keys($titel_typeaheads),
  347. ));
  348. }
  349. /**
  350. * Creates a new Pruefer entity per ajax
  351. *
  352. * @Route("/create/pruefer/ajax/create", name="pruefer_ajax_create")
  353. * @Method({"POST"})
  354. */
  355. public function createAjaxAction(Request $request)
  356. {
  357. $this->denyAccessUnlessGranted('ROLE_KUNDE');
  358. $em = $this->getDoctrine()->getManager();
  359. $user = $this->getUser();
  360. $kunde = $user->getKunde();
  361. $pruefungsamt = $em->getRepository(Pruefungsamt::class)->findOneByUser($user->getId());
  362. $entity = new Pruefer();
  363. $entity->setQuelle('man');
  364. $entity->setCreator($user);
  365. $pruefungsamt_candidates = $kunde->getBundesland()->getPruefungsaemter();
  366. foreach ($pruefungsamt_candidates as $candidate) {
  367. $entity->addPruefungsaemter($candidate);
  368. }
  369. $form = $this->createForm(PrueferType::class, $entity);
  370. $form->handleRequest($request); //changedFrom bind
  371. if ($form->isValid()) {
  372. // Prüfungsämter abgleichen
  373. $existing_pruefer = $em->getRepository(Pruefer::class)->findExisting($entity, $pruefungsamt);
  374. if (empty($existing_pruefer)) {
  375. $entity->setAliasFor(
  376. $em->getRepository(Pruefer::class)->findAlias($entity, null, $pruefungsamt)
  377. );
  378. if (!$entity->getSlug()) {
  379. $entity->setSlug($this->slugify($entity->getVorname().' '.$entity->getNachname()));
  380. }
  381. $em->persist($entity);
  382. $em->flush();
  383. } else {
  384. foreach ($pruefungsamt_candidates as $candidate) {
  385. $candidate->removePruefer($entity);
  386. }
  387. foreach ($existing_pruefer as $p) {
  388. /* @var $p \JF\JuridicusBundle\Entity\Pruefer */
  389. foreach ($pruefungsamt_candidates as $candidate) {
  390. if (!$p->getPruefungsaemter()->contains($candidate)) {
  391. $p->addPruefungsaemter($candidate);
  392. }
  393. }
  394. $em->persist($p);
  395. }
  396. $em->flush();
  397. $entity = $existing_pruefer[0];
  398. }
  399. return new JsonResponse(array(
  400. 'success' => true,
  401. 'objectId' => $entity->getId(),
  402. 'objectName' => $entity->getFullTextWithOrt()
  403. ));
  404. }
  405. $dienststellung_typeaheads = $em->getRepository(Dienststellung::class)->getTypeaheads();
  406. $titel_typeaheads = $em->getRepository(Titel::class)->getTypeaheads();
  407. $html = $this->get('templating')->render("@JFJuridicusBundle/Pruefer/new.html.twig", array(
  408. 'entity' => $entity,
  409. 'form' => $form->createView(),
  410. 'dienststellungNames' => array_keys($dienststellung_typeaheads),
  411. 'titelNames' => array_keys($titel_typeaheads),
  412. ));
  413. return new JsonResponse(array(
  414. 'success' => false,
  415. 'html' => $html
  416. ));
  417. }
  418. /**
  419. *
  420. * @param string $text
  421. * @param string $style 'lower'|'upper'
  422. * @return string
  423. */
  424. public static function slugify($text, $style = NULL)
  425. {
  426. // replace non letter or digits by -
  427. $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  428. // trim
  429. $text = trim($text, '-');
  430. // transliterate
  431. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  432. if ($style == 'lower') {
  433. // lowercase
  434. $text = strtolower($text);
  435. } elseif ($style == 'upper') {
  436. // uppercase
  437. $text = strtoupper($text);
  438. }
  439. // remove unwanted characters
  440. $text = preg_replace('~[^-\w]+~', '', $text);
  441. if (empty($text)) {
  442. return 'n-a';
  443. }
  444. return $text;
  445. }
  446. /**
  447. * Lists all Pruefungsamt entities.
  448. * @Method({"GET"})
  449. * @Route("/pruefer/protokolle", name="pruefer_protokolle")
  450. */
  451. public function prueferBereichAction()
  452. {
  453. $this->denyAccessUnlessGranted('ROLE_PRUEFER');
  454. $em = $this->getDoctrine()->getManager();
  455. $user = $this->getUser();
  456. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByUser($user);
  457. if (!$prueferUser) {
  458. return $this->render('@JFJuridicusBundle/PrueferBereich/not_yet_verified.html.twig', array(
  459. ));
  460. }
  461. $pruefer = $prueferUser->getPruefer();
  462. if (!$pruefer) {
  463. return $this->render('@JFJuridicusBundle/PrueferBereich/not_yet_verified.html.twig', array(
  464. ));
  465. }
  466. $lastDate = new \DateTime("01-01-2011");
  467. //$output->writeln("Prüfer: ".$pruefer->getId()." Pruefungen: ".count($pruefer->getPrueferPruefungen()));
  468. foreach($pruefer->getPrueferPruefungen() as $prueferPruefung) {
  469. if ($lastDate < $prueferPruefung->getPruefung()->getDatum()) {
  470. //prüfe ob dazu auch ein Protokoll gibt
  471. $infothekPruefung = $em->getRepository(ProtokollInfothekPruefung::class)->findBy(['pruefung'=>$prueferPruefung->getPruefung()]);
  472. if($infothekPruefung) {
  473. $lastDate = $prueferPruefung->getPruefung()->getDatum();
  474. }
  475. }
  476. }
  477. foreach($pruefer->getAliases() as $allias) {
  478. //$output->writeln("Alias: ".$allias->getId()." Pruefungen: ".count($allias->getPrueferPruefungen()));
  479. foreach($allias->getPrueferPruefungen() as $prueferPruefung) {
  480. if ($lastDate < $prueferPruefung->getPruefung()->getDatum()) {
  481. $infothekPruefung = $em->getRepository(ProtokollInfothekPruefung::class)->findBy(['pruefung'=>$prueferPruefung->getPruefung()]);
  482. if($infothekPruefung) {
  483. $lastDate = $prueferPruefung->getPruefung()->getDatum();
  484. }
  485. }
  486. }
  487. }
  488. //Letztes Protokoll
  489. //$lastProtocol = $em->getRepository('JFJuridicusBundle:Pruefer')->findLastProtocol($pruefer);
  490. $pdf1Exam = $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), 1);
  491. $pdf2Exam = $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), 2);
  492. return $this->render('@JFJuridicusBundle/PrueferBereich/index.html.twig', array(
  493. "lastProtocol" => $lastDate,
  494. "pruererUser" => $prueferUser,
  495. "pruefer" => $pruefer,
  496. "pdf1Exam" => $pdf1Exam,
  497. "pdf2Exam" => $pdf2Exam
  498. ));
  499. }
  500. /**
  501. * @Method({"GET"})
  502. * @Route("/pruefer/protokolle/download/{exam}", name="pruefer_protokolle_download")
  503. */
  504. public function prueferBereichDownloadAction($exam) {
  505. $this->denyAccessUnlessGranted('ROLE_PRUEFER');
  506. $em = $this->getDoctrine()->getManager();
  507. $user = $this->getUser();
  508. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByUser($user);
  509. $pruefer = $prueferUser->getPruefer();
  510. if (!$pruefer) {
  511. throw $this->createNotFoundException('Pruefer noch nicht verifiziert');
  512. }
  513. // Download erlaubt
  514. $pdf = $em->getRepository(PdfProtokollmappePruefer::class)->findOneByPrueferAndExamen($pruefer->getId(), $exam);
  515. return $pdf->createResponse();
  516. }
  517. /**
  518. * @Method({"GET"})
  519. * @Route("/pruefer/registration", name="pruefer_registration")
  520. */
  521. public function prueferRegistrationAction()
  522. {
  523. $form = $this->createForm(PrueferUserType::class, new PrueferUser());
  524. return $this->render('@JFJuridicusBundle/PrueferBereich/registration.html.twig', array(
  525. "form" => $form->createView()
  526. ));
  527. }
  528. /**
  529. * @Method({"POST"})
  530. * @Route("/pruefer/registration/save", name="pruefer_registration_save")
  531. */
  532. public function prueferRegistrationSaveAction(Request $request)
  533. {
  534. $form = $this->createForm(PrueferUserType::class, new PrueferUser()); //changedFrom
  535. $form->handleRequest($request); //changedFrom bind
  536. if ($form->isSubmitted() && $form->isValid()) {
  537. $em = $this->getDoctrine()->getManager();
  538. $prueferUser = $form->getData();
  539. //dump($prueferUser);
  540. //früher fos_user - nicht sicher ob es jetzt user ist Hier [TODO] - wie war unterschied fos_user und prueferUser?
  541. $user = $em->getRepository(User::class)->findOneBy(['email'=>$prueferUser->getEmail()]);
  542. $prueferUserOld = $em->getRepository(PrueferUser::class)->findOneByEmail($prueferUser->getEmail());
  543. if ($prueferUserOld) {
  544. return $this->render('@JFJuridicusBundle/PrueferBereich/email_in_use.html.twig', array(
  545. ));
  546. //throw $this->createNotFoundException('Die von Ihnen genutzte E-Mail-Adresse ist bei juridicus bereits registriert. Bitte nutzen Sie die „Passwort vergessen“- Funktion. Sollte Ihnen wider Erwarten kein neues Passwort zugestellt werden, nehmen Sie bitte über info@juridicus.de Kontakt mit uns auf.');
  547. }
  548. // alten User ggfs. umbiegen
  549. if ($user) {
  550. $kunde_old = $user->getKunde();
  551. if ($kunde_old) {
  552. $kunde_old->setUser(null);
  553. $em->persist($kunde_old);
  554. $em->flush();
  555. } else {
  556. $user->addRole("ROLE_PRUEFER");
  557. }
  558. } else {
  559. // entsprechenden User neu erstellen
  560. $user = new User();
  561. $user->addRole("ROLE_PRUEFER");
  562. $user->setUsername($prueferUser->getEmail());
  563. $user->setEmail($prueferUser->getEmail());
  564. $user->setPlainPassword(substr(uniqid(md5(rand())), 8, 8));
  565. }
  566. $token = uniqid(md5(rand()));
  567. $user->setConfirmationToken($token);
  568. $user->setEnabled(false);
  569. $em->persist($user);
  570. $prueferUser->setUser($user);
  571. $em->persist($prueferUser);
  572. $em->flush();
  573. // finde neuestes Template
  574. $template = $em->getRepository(MailTemplate::class)->findCurrentByTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG);
  575. $link = $this->generateUrl('pruefer_registration_activate', array('token' => $token), UrlGeneratorInterface::ABSOLUTE_URL); //chagngedFrom true
  576. $replacements = array(
  577. 'vorname' => $prueferUser->getVorname(),
  578. 'nachname' => $prueferUser->getNachname(),
  579. 'titel' => $prueferUser->getTitel(),
  580. 'email' => $prueferUser->getEmail(),
  581. // 'handynummer' => $prueferUser->getHandynummer(),
  582. 'link' => $link
  583. );
  584. $this->logger->info(sprintf('Link: %s ', $link));
  585. $mailerBcc = $this->getParameter('mailer_bcc');
  586. $mailUser = $this->getParameter('mailer_user');
  587. $message = (new Swift_Message($template->getBetreff()))
  588. ->setFrom(array($mailUser => 'Juridicus'))
  589. ->setReplyTo('info@juridicus.de')
  590. ->setTo($prueferUser->getEmail())
  591. ->setBcc('info@juridicus.de')
  592. ->setBody($template->replace($replacements), 'text/html')
  593. ;
  594. if (isset($mailerBcc)) {
  595. $message->setBcc(array($mailerBcc));
  596. }
  597. if ($this->mailer->send($message)) {
  598. // Versand speichern
  599. $email = new PrueferEmail();
  600. $email
  601. ->setTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG)
  602. ->setPrueferUser($prueferUser)
  603. ;
  604. $em->persist($email);
  605. $em->flush();
  606. $this->get('session')->set('registration_email_success', $prueferUser->getEmail());
  607. return $this->redirect($this->generateUrl('pruefer_registration_email_success'));
  608. } else {
  609. $this->get('session')->set('registration_email_error', $prueferUser->getEmail());
  610. return $this->redirect($this->generateUrl('pruefer_registration_email_error'));
  611. }
  612. }
  613. return $this->render('@JFJuridicusBundle/PrueferBereich/registration.html.twig', array(
  614. "form" => $form->createView()
  615. ));
  616. }
  617. /**
  618. * Tell the user to check his email provider
  619. *
  620. * @Route("/pruefer/email/success", name="pruefer_registration_email_success")
  621. */
  622. public function prueferEmailSuccessAction()
  623. {
  624. $user_manager = $this->container->get('fos_user.user_manager');
  625. $session = $this->container->get('session');
  626. $email = $session->get('registration_email_success');
  627. $session->remove('registration_email_success');
  628. if (empty($email)) {
  629. // the user does not come from the sendEmail action
  630. return $this->redirect($this->generateUrl('homepage'));
  631. }
  632. return $this->render('@JFJuridicusBundle/PrueferBereich/email_success.html.twig', array(
  633. 'email' => $email
  634. ));
  635. }
  636. /**
  637. * Tell the prueferUser that email sending failed
  638. *
  639. * @Route("/pruefer/email/error", name="pruefer_registration_email_error")
  640. */
  641. public function prueferEmailErrorAction()
  642. {
  643. $user_manager = $this->container->get('fos_user.user_manager');
  644. $session = $this->container->get('session');
  645. $email = $session->get('registration_email_error');
  646. $session->remove('registration_email_error');
  647. if (empty($email)) {
  648. // the user does not come from the sendEmail action
  649. return $this->redirect($this->generateUrl('homepage'));
  650. }
  651. return $this->render('@JFJuridicusBundle/PrueferBereich/email_error.html.twig', array(
  652. 'email' => $email
  653. ));
  654. }
  655. /**
  656. * Tell the user to check his sms
  657. *
  658. * @Route("/pruefer/sms/success", name="pruefer_registration_sms_success")
  659. */
  660. public function prueferSmsSuccessAction()
  661. {
  662. $user_manager = $this->get('fos_user.user_manager');
  663. $session = $this->get('session');
  664. $email = $session->get('registration_email_success');
  665. $session->remove('registration_email_success');
  666. $em = $this->getDoctrine()->getManager();
  667. if (empty($email)) {
  668. // the user does not come from the sendEmail action
  669. return $this->redirect($this->generateUrl('homepage'));
  670. }
  671. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  672. return $this->render('@JFJuridicusBundle/PrueferBereich/sms_success.html.twig', array(
  673. 'prueferUser' => $prueferUser
  674. ));
  675. }
  676. /**
  677. * Tell the user that email is checked
  678. *
  679. * @Route("/pruefer/email/check/success", name="pruefer_registration_email_check_success")
  680. */
  681. public function prueferEmailCheckSuccessAction()
  682. {
  683. $session = $this->container->get('session');
  684. $email = $session->get('registration_email_success');
  685. $session->remove('registration_email_success');
  686. $em = $this->getDoctrine()->getManager();
  687. if (empty($email)) {
  688. // the user does not come from the sendSms action
  689. return $this->redirect($this->generateUrl('homepage'));
  690. }
  691. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  692. return $this->render('@JFJuridicusBundle/PrueferBereich/email_checked.html.twig', array(
  693. 'email' => $email
  694. ));
  695. }
  696. /**
  697. * Tell the user that sms sending failed
  698. *
  699. * @Route("/pruefer/sms/error", name="pruefer_registration_sms_error")
  700. */
  701. public function prueferSmsErrorAction()
  702. {
  703. $user_manager = $this->container->get('fos_user.user_manager');
  704. $session = $this->container->get('session');
  705. $email = $session->get('registration_sms_error');
  706. $code = $session->get('registration_sms_code');
  707. $message = $session->get('registration_sms_message');
  708. $session->remove('registration_sms_error');
  709. $session->remove('registration_sms_code');
  710. $session->remove('registration_sms_message');
  711. $em = $this->getDoctrine()->getManager();
  712. if (empty($email) || empty($code) || empty($message)) {
  713. // the user does not come from the sendSms action
  714. return $this->redirect($this->generateUrl('homepage'));
  715. }
  716. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByEmail($email);
  717. return $this->render('@JFJuridicusBundle/PrueferBereich/sms_error.html.twig', array(
  718. 'prueferUser' => $prueferUser,
  719. 'code' => $code,
  720. 'message' => $message,
  721. ));
  722. }
  723. /**
  724. * Receive the confirmation token and send SMS with password
  725. *
  726. * @Route("pruefer/activate/{token}", name="pruefer_registration_activate")
  727. */
  728. public function prueferActivateAction($token)
  729. {
  730. $em = $this->getDoctrine()->getManager();
  731. $user_manager = $this->container->get('fos_user.user_manager');
  732. /* @var $user_manager \FOS\UserBundle\Model\UserManager */
  733. $sms_service = $this->container->get('jf_juridicus.sms');
  734. /* @var $sms_service \JF\JuridicusBundle\Services\Sms */
  735. $user = $user_manager->findUserByConfirmationToken($token);
  736. if (null === $user) {
  737. throw $this->createNotFoundException('Der Aktivierungscode ist ungültig oder wurde schon verwendet.');
  738. }
  739. $prueferUser = $em->getRepository(PrueferUser::class)->findOneByUser($user);
  740. if (null === $prueferUser) {
  741. throw $this->createNotFoundException('Der Benutzer zu diesem Aktivierungscode ist nicht mehr vorhanden.');
  742. }
  743. /* Hier wurde die E-Mail mit dem Passwort versendet, jetzt wird diese E-Mail erst nach verifizierung versendet */
  744. $password_plain = substr(uniqid(md5(rand())), 8, 8);
  745. $user->setConfirmationToken(null);
  746. $user->setPlainPassword($password_plain);
  747. $user->setEnabled(true);
  748. $em->persist($user);
  749. $this->get('logger')->info(sprintf('User: %s PW: %s', $user->getEmail(), $password_plain));
  750. // Senden des Passwords per SMS
  751. $template = $em->getRepository(MailTemplate::class)->findCurrentByTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG_PASSWORT);
  752. $replacements = array(
  753. 'titel' => $prueferUser->getTitel(),
  754. 'vorname' => $prueferUser->getVorname(),
  755. 'nachname' => $prueferUser->getNachname(),
  756. 'email' => $prueferUser->getEmail(),
  757. 'link' => 'https://juridicus.de/pruefer/login',
  758. 'password' => $password_plain
  759. );
  760. // NEW send E-Mail with PW
  761. $mailer_user = $this->container->getParameter('mailer_user');
  762. $mailer_bcc = $this->container->getParameter('mailer_bcc');
  763. $mailer = $this->get('mailer');
  764. $message = \Swift_Message::newInstance()
  765. ->setSubject($template->getBetreff())
  766. ->setFrom(array($mailer_user => 'Juridicus'))
  767. ->setReplyTo('info@juridicus.de')
  768. ->setTo($prueferUser->getEmail())
  769. ->setBcc('info@juridicus.de')
  770. ->setBody($template->replace($replacements), 'text/html')
  771. ;
  772. if ($mailer->send($message)) {
  773. // Versand speichern
  774. $email = new PrueferEmail();
  775. $email
  776. ->setTyp(PrueferEmail::PRUEFER_BEREICH_REGISTRIERUNG_PASSWORT)
  777. ->setPrueferUser($prueferUser)
  778. ;
  779. $em->persist($email);
  780. $em->flush();
  781. $this->get('session')->set('registration_email_success', $prueferUser->getEmail());
  782. return $this->redirect($this->generateUrl('pruefer_registration_sms_success'));
  783. } else {
  784. $this->get('session')->set('registration_email_error', $prueferUser->getEmail());
  785. return $this->redirect($this->generateUrl('pruefer_registration_sms_error'));
  786. }
  787. /*$this->get('session')->set('registration_email_success', $prueferUser->getEmail());
  788. return $this->redirect($this->generateUrl('pruefer_registration_email_check_success'));
  789. */
  790. }
  791. }