src/Trinity/FormsBundle/Controller/FormsController.php line 726

Open in your IDE?
  1. <?php
  2. namespace App\Trinity\FormsBundle\Controller;
  3. use App\CmsBundle\Classes\Hummessenger as MailerTool;
  4. use App\CmsBundle\Controller\StorageController;
  5. use App\CmsBundle\Entity\Media;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. class FormsController extends StorageController
  18. {
  19.     /**
  20.      * @Route("/admin/forms/answers/filter/{formid}/{page}", name="admin_mod_forms_answers_filter", requirements={"formid": "\d+", "page": "\d+"})
  21.      * @Template()
  22.      */
  23.     public function filterAction(Request $request$formid$page 1)
  24.     {
  25.         parent::init($request);
  26.         $filter $request->get('filter');
  27.         if(!empty($filter['q'])){
  28.             $filter['q'] = explode(' '$filter['q']);
  29.         }
  30.         $offset 0;
  31.         $limit  = (int)(!empty($_GET['pp']) ? $_GET['pp'] : 20);
  32.         $count $this->getDoctrine()->getRepository('TrinityFormsBundle:Answer')->filter($formidtrue$offset$limit$filter);
  33.         $pages ceil($count $limit);
  34.         if($pages == 0$pages 1;
  35.         if($page $pages){ $page $pages; }
  36.         if($pages 1){ $pages 1; }
  37.         $offset = (($page $limit) - $limit);
  38.         $results = [];
  39.         $dql_results $this->getDoctrine()->getRepository('TrinityFormsBundle:Answer')->filter($formidfalse$offset$limit$filter);
  40.         foreach($dql_results as $Entry){
  41.             $a = [
  42.                 'name' => [],
  43.                 'email' => '',
  44.                 'phone' => '',
  45.                 'nieuwsbrief' => '',
  46.             ];
  47.             if(!is_array($Entry->getAnswer())){
  48.                 $ans json_decode($Entry->getAnswer(), true);
  49.                 foreach($ans as $k => $v){
  50.                     $k strtolower($k);
  51.                     // echo '<pre>' . print_r($k, 1) . '</pre>';
  52.                     if(preg_match('/naam/'$k)){
  53.                         $a['name'][] = $v;
  54.                     }
  55.                     if(preg_match('/mail/'$k)){
  56.                         $a['email'] = $v;
  57.                     }
  58.                     if(preg_match('/nieuwsbrief/'$k)){
  59.                         $a['nieuwsbrief'] = '<i class="material-icons">check_circle</i>';
  60.                     }
  61.                     if(preg_match('/foon/'$k)){
  62.                         $a['phone'] = $v;
  63.                     }
  64.                 }
  65.                 $a['name'] = implode(' '$a['name']);
  66.                 // $answers[$i]->setAnswer($a);
  67.             }
  68.             $results[] = [
  69.                 'id'      => $Entry->getId(),
  70.                 'ip'      => (!empty($Entry->getIp()) ? $Entry->getIp() : '----'),
  71.                 'date' => (!empty($Entry->getSession()) ? $Entry->getSession()->getDateEnd()->format('d-m-Y H:i:s') : ''),
  72.                 'name' => $a['name'],
  73.                 'email' => $a['email'],
  74.                 'phone' => $a['phone'],
  75.                 'nieuwsbrief' => $a['nieuwsbrief'],
  76.             ];
  77.         }
  78.         return new JsonResponse([
  79.             'count'   => (int)$count,
  80.             'page'    => $page,
  81.             'pages'   => $pages,
  82.             'offset'  => $offset,
  83.             'limit'   => $limit,
  84.             'results' => $results,
  85.         ]);
  86.     }
  87.     /**
  88.      * @Route("/admin/forms", name="admin_mod_forms")
  89.      * @Template()
  90.      */
  91.     public function indexActionRequest $request$id null)
  92.     {
  93.         parent::init($request);
  94.         $this->breadcrumbs->addRouteItem($this->trans("Formulieren"'cms'), "admin_mod_forms");
  95.         $forms $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->findBy([
  96.             'language' => $this->language,
  97.             'settings' => $this->Settings
  98.         ]);
  99.         $forms_used = [];
  100.         $blocks $this->getDoctrine()->getRepository('CmsBundle:PageBlock')->findByData('TrinityFormsBundle');
  101.         foreach($blocks as $Block){
  102.             $p $Block->getWrapper()->getPage();
  103.             if($p->getLanguage() == $this->language){
  104.                 $data $Block->getBundleData(true);
  105.                 if (isset($data['id'])) {
  106.                     $forms_used[] = $data['id'];
  107.                 }
  108.             }
  109.         }
  110.         return $this->attributes(array(
  111.             'forms_used' => $forms_used,
  112.             'forms' => $forms
  113.         ));
  114.     }
  115.     /**
  116.      * @Route("/admin/forms/answers/delete/{id}", name="admin_mod_forms_answers_delete")
  117.      */
  118.     public function deleteAmswerActionRequest $request$id null)
  119.     {
  120.         parent::init($request);
  121.         $Answer $this->getDoctrine()->getRepository('TrinityFormsBundle:Answer')->find($id);
  122.         $form_id $Answer->getForm()->getId();
  123.         $em $this->getDoctrine()->getManager();
  124.         $em->remove($Answer);
  125.         $em->flush();
  126.         return $this->redirectToRoute('admin_mod_forms_answers', ['id' => $form_id]);
  127.     }
  128.     /**
  129.      * @Route("/admin/forms/answers/{id}/export", name="admin_mod_forms_answers_export")
  130.      * @Template()
  131.      */
  132.     public function exportRequest $request$id null)
  133.     {
  134.         parent::init($request);
  135.         
  136.         header('Content-Type: text/csv; charset=utf-8');
  137.         header('Content-Disposition: attachment; filename=form_answers.csv');
  138.         $output fopen('php://output''w');
  139.         $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->find($id);
  140.         fputcsv($output, ['Veld',  'Invoer']);
  141.         fputcsv($output, ['']);
  142.         $answers $Form->getAnswers();
  143.         foreach($answers as $i => $answer){
  144.             if(!is_array($answer->getAnswer())){
  145.                 $ans json_decode($answer->getAnswer(), true);
  146.                 $keys = [];
  147.                 $values = [];
  148.                 foreach($ans as $k => $v){
  149.                     if(is_array($v)){
  150.                         $v implode(', '$v);
  151.                     }
  152.                     fputcsv($output, [$k,  $v]);
  153.                 }
  154.                 fputcsv($output, ['']);
  155.                 /* if(empty($csv[0])){
  156.                     $csv[0] = $keys;
  157.                 } */
  158.             }
  159.         }
  160.         exit;
  161.     }
  162.     /**
  163.      * @Route("/admin/forms/answers/{id}/{answerid}", name="admin_mod_forms_answers")
  164.      * @Template()
  165.      */
  166.     public function answersActionRequest $request$id null$answerid null)
  167.     {
  168.         parent::init($request);
  169.         $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->find($id);
  170.         $this->breadcrumbs->addRouteItem($this->trans("Formulieren"'cms'), "admin_mod_forms");
  171.         $this->breadcrumbs->addRouteItem($Form->getLabel(), "admin_mod_forms");
  172.         $this->breadcrumbs->addRouteItem($this->trans("Reacties"'cms'), "admin_mod_forms_answers", array('id' => $id'answerid' => null));
  173.         $Answer null;
  174.         if(!is_null($answerid)){
  175.             $Answer $this->getDoctrine()->getRepository('TrinityFormsBundle:Answer')->find($answerid);
  176.             $this->breadcrumbs->addRouteItem($this->trans("Reactie"'cms'), "admin_mod_forms_answers", array('id' => $id'answerid' => $answerid));
  177.             $Answer->setAnswer(json_decode($Answer->getAnswer(), true));
  178.             if($request->isXmlHttpRequest()) {
  179.                 return $this->render('@TrinityForms/form/answers_ajax.html.twig', ['Answer' => $Answer]);
  180.             }
  181.         }
  182.         $answers $Form->getAnswers();
  183.         foreach($answers as $i => $answer){
  184.             $a = [
  185.                 'name' => [],
  186.                 'email' => '',
  187.                 'phone' => '',
  188.             ];
  189.             if(!is_array($answer->getAnswer())){
  190.                 $ans json_decode($answer->getAnswer(), true);
  191.                 foreach($ans as $k => $v){
  192.                     $k strtolower($k);
  193.                     // echo '<pre>' . print_r($k, 1) . '</pre>';
  194.                     if(preg_match('/naam/'$k)){
  195.                         $a['name'][] = $v;
  196.                     }
  197.                     if(preg_match('/mail/'$k)){
  198.                         $a['email'] = $v;
  199.                     }
  200.                     if(preg_match('/foon/'$k)){
  201.                         $a['phone'] = $v;
  202.                     }
  203.                 }
  204.                 $a['name'] = implode(' '$a['name']);
  205.                 $answers[$i]->setAnswer($a);
  206.             }
  207.         }
  208.         $hasNewsletter false;
  209.         if(in_array('NewsletterBundle'$this->installed)){
  210.             $hasNewsletter true;
  211.         }
  212.         return $this->attributes(array(
  213.             'Form' => $Form,
  214.             'Answer' => $Answer,
  215.             'hasNewsletter' => $hasNewsletter,
  216.             'answers' => $answers
  217.         ));
  218.     }
  219.     /**
  220.      * @Route("/admin/forms/edit/addelement/{id}/{type}", name="admin_mod_forms_addrow")
  221.      */
  222.     public function addelementAction(Request $request$id null$type null){
  223.         parent::init($request);
  224.         $tpl '';
  225.         $tplDir $this->containerInterface->get('kernel')->locateResource('@TrinityFormsBundle/Resources/views/elements/');
  226.         // Check for newsletter presence
  227.         $emaillists null;
  228.         if(in_array('NewsletterBundle'$this->installed)){
  229.             $emaillists $this->getDoctrine()->getRepository('TrinityFormsBundle:Emaillist')->findAll();
  230.         }
  231.         if(file_exists($tplDir $type '.html.twig')){
  232.             $Question = new \App\Trinity\FormsBundle\Entity\Question();
  233.             $Question->setType($type);
  234.             /*if($Question->getTitle() == 'Titel'){
  235.                 $Question->setTitle($this->trans('Title', 'cms'));
  236.             }*/
  237.             /*if($Question->getSubTitle() == 'Toelichting'){
  238.                 $Question->setSubTitle($this->trans('Explanation', 'cms'));
  239.             }*/
  240.             // Default values
  241.             if($type == 'newsletter'){
  242.                 $Question->setTitle($this->trans('Ik wil me aanmelden voor de nieuwsbrief''cms'));
  243.             }
  244.             $random time();
  245.             // Get Form
  246.             $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->findOneById($id);
  247.             return $this->render('@TrinityForms/elements/' $type '.html.twig', array('edit' => true'emaillists' => $emaillists'Form' => $Form'Question' => $Question'random' => $random));
  248.         }
  249.         return $this->render('@TrinityForms/elements/invalid.html.twig', array('edit' => true'emaillists' => $emaillists));
  250.     }
  251.     /**
  252.      * @Route("/admin/forms/edit/{id}", name="admin_mod_forms_edit")
  253.      * @Template()
  254.      */
  255.     public function editActionRequest $request$id null)
  256.     {
  257.         parent::init($request);
  258.         $hasNewsletter false;
  259.         if(in_array('NewsletterBundle'$this->installed)){
  260.             $hasNewsletter true;
  261.         }
  262.         $this->breadcrumbs->addRouteItem($this->trans("Formulieren"'cms'), "admin_mod_forms");
  263.         $new false;
  264.         if( (int)$id ){
  265.             // Edit
  266.             $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->find($id);
  267.             if($this->language != $Form->getLanguage() || $this->Settings != $Form->getSettings()){
  268.                 return $this->redirect($this->generateUrl('admin_mod_forms'));
  269.             }
  270.             $this->breadcrumbs->addRouteItem($this->trans("Wijzigen:"'cms'). " " $Form->getLabel(), "admin_mod_forms_edit");
  271.         }else{
  272.             $new true;
  273.             // Add
  274.             $Form = new \App\Trinity\FormsBundle\Entity\Form();
  275.             $Form->setLanguage($this->language);
  276.             $Form->setSettings($this->Settings);
  277.             $this->breadcrumbs->addRouteItem($this->trans("Toevoegen"'cms'), "admin_mod_forms_edit");
  278.         }
  279.         $saved false;
  280.         if($this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
  281.             $editform $this->createFormBuilder($Form)
  282.                 ->add('label'TextType::class, array('label' => $this->trans('Formulier titel', [], 'cms')))
  283.                 ->add('hide_clear_button'CheckBoxType::class, ['label' => $this->trans('Verberg de leegmaken knop''cms'), 'required' => false'row_attr' => ['class' => 'page-chk']])
  284.                 ->add('mail_reply_to'CheckboxType::class, array('label' => $this->trans('E-mail als reply-to adres''cms'), 'row_attr' => ['class' => 'page-chk']))
  285.                 ->add('floating_labels'CheckboxType::class, array('label' => 'Floating labels''required' => false))
  286.                 ->add('active_campaign'CheckboxType::class, array('label' => 'ActiveCampaign''required' => false'row_attr' => ['class' => 'page-chk']))
  287.                 ->add('active_campaign_url'TextType::class, array('label' => 'ActiveCampaign Url''required' => false))
  288.                 ->add('active_campaign_key'TextType::class, array('label' => 'ActiveCampaign Key''required' => false))
  289.                 ->add('active_campaign_listid'TextType::class, array('label' => 'ActiveCampaign List ID''required' => false))
  290.                 ->add('active_lef_api'CheckboxType::class, array('label' => 'LEF api''required' => false))
  291.                 ->setMethod('post')
  292.                 ->getForm();
  293.             if($Form->getSettings()->isHummessengerApiEnabled()){
  294.             $editform->add('mailer_listid'TextType::class, array('label' => 'Hummessenger List ID''required' => false));
  295.             }
  296.         } else {
  297.             $editform $this->createFormBuilder($Form)
  298.                 ->add('label'TextType::class, array('label' => $this->trans('Formulier titel', [], 'cms')))
  299.                 ->add('hide_clear_button'CheckBoxType::class, ['label' => $this->trans('Verberg de leegmaken knop''cms'), 'required' => false'row_attr' => ['class' => 'page-chk']])
  300.                 ->add('mail_reply_to'CheckboxType::class, array('label' => $this->trans('E-mail als reply-to adres''cms'), 'row_attr' => ['class' => 'page-chk']))
  301.                 ->setMethod('post')
  302.                 ->getForm();
  303.         }
  304.         $em $this->getDoctrine()->getManager();
  305.         $editform->handleRequest($request);
  306.         if ($editform->isSubmitted() && $editform->isValid()) {
  307.             if(!isset($_POST['id'])){
  308.                 // No fields found, clean up
  309.                 $rm_questions $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findByForm($Form);
  310.                 foreach($rm_questions as $RmQuestion){
  311.                     $em->remove($RmQuestion);
  312.                 }
  313.             }
  314.             if(!empty($_POST['id'])){
  315.                 $ids = [];
  316.                 $q $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findByForm($Form);
  317.                 foreach($q as $Q){ $ids[] = $Q->getId(); }
  318.                 foreach(array_diff($ids$_POST['id']) as $id){
  319.                     $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->find($id);
  320.                     $em->remove($Question);
  321.                 }
  322.                 $positions = [];
  323.                 if(!empty($_POST['pos'])){
  324.                     $positions array_values($_POST['pos']);
  325.                 }
  326.                 $width = [];
  327.                 if(!empty($_POST['width'])){
  328.                     $width array_values($_POST['width']);
  329.                 }
  330.                 foreach($_POST['id'] as $i => $id){
  331.                     $pos = (isset($positions[$i]) ? (int)$positions[$i] : 0);
  332.                     $w = (isset($width[$i]) ? (int)$width[$i] : 12);
  333.                     $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->find($id);
  334.                     if(empty($Question)){
  335.                         // New
  336.                         $Question = new \App\Trinity\FormsBundle\Entity\Question();
  337.                         $Question->setForm($Form);
  338.                         $Question->setType($_POST['type'][$i]);
  339.                         $Form->addQuestion($Question);
  340.                     }
  341.                     $Question->setPosition($pos); // Set position
  342.                     $Question->setWidth($w); // Set position
  343.                     if(isset($_POST['values'][$id])){
  344.                         if(is_array($_POST['values'][$id])){
  345.                             foreach($_POST['values'][$id] as $k => $v){
  346.                                 $_POST['values'][$id][$k] = str_replace(',''&comma;'$v);
  347.                             }
  348.                         }
  349.                         $Question->setValues($_POST['values'][$id]);
  350.                     }
  351.                     if(isset($_POST['disabled'][$id])){
  352.                         $Question->setDisabled($_POST['disabled'][$id]);
  353.                     }else{
  354.                         $Question->setDisabled([]);
  355.                     }
  356.                     if(isset($_POST['config'][$id])){
  357.                         $Question->setConfig($_POST['config'][$id]);
  358.                     }else{
  359.                         $Question->setConfig([]);
  360.                     }
  361.                     if(isset($_POST['default'][$id])){
  362.                         $Question->setDefault($_POST['default'][$id]);
  363.                     }else{
  364.                         $Question->setDefault([]);
  365.                     }
  366.                     if(isset($_POST['email'][$id])){
  367.                         $Question->setEmail($_POST['email'][$id]);
  368.                     }else{
  369.                         $Question->setEmail([]);
  370.                     }
  371.                     if(isset($_POST['heading'][$i])){
  372.                         $Question->setTitle(strip_tags($_POST['heading'][$i]));
  373.                     }else{
  374.                         $Question->setTitle("");
  375.                     }
  376.                     
  377.                     
  378.                     if(!empty($_POST['title'][$i])){
  379.                         $Question->setTitle(strip_tags($_POST['title'][$i]));
  380.                     }else{
  381.                         $Question->setTitle("");
  382.                     }
  383.                     if(!empty($_POST['required'])){
  384.                         $Question->setRequired(in_array($id$_POST['required']));
  385.                     }else{
  386.                         $Question->setRequired(false);
  387.                     }
  388.                     if(!empty($_POST['hidden'])){
  389.                         $Question->setHidden(in_array($id$_POST['hidden']));
  390.                     }else{
  391.                         $Question->setHidden(false);
  392.                     }
  393.                     if(!empty($_POST['hidden_label'][$id])){
  394.                         $Question->setHiddenLabel(in_array($id$_POST['hidden_label']));
  395.                     }else{
  396.                         $Question->setHiddenLabel(false);
  397.                     }
  398.                     if(!empty($_POST['placeholder'][$i])){
  399.                         $Question->setPlaceholder($_POST['placeholder'][$i]);
  400.                     } else if (empty($_POST['placeholder'][$i]) && !empty($Question->getPlaceHolder())) {
  401.                         $Question->setPlaceholder(null);
  402.                     }
  403.                     // Set new sort order
  404.                     $Question->setSort($i);
  405.                     $em->persist($Question);
  406.                 }
  407.             }
  408.             $Form->setMails($_POST['mail']);
  409.             if(!empty($_POST['delete'])){
  410.                 foreach(explode(','$_POST['delete']) as $id){
  411.                     if(!empty($id)){
  412.                         $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->find($id);
  413.                         $em->remove($Question);
  414.                     }
  415.                 }
  416.             }
  417.             // Store in database
  418.             $em->persist($Form);
  419.             $em->flush();
  420.             // Clone question to more sites
  421.             if(!empty($_POST['clone'])){
  422.                 foreach($_POST['clone'] as $id){
  423.                     $LinkedSettings $this->getDoctrine()->getRepository('CmsBundle:Settings')->find($id);
  424.                     $NewForm = clone $Form;
  425.                     $NewForm->setSettings($LinkedSettings);
  426.                     $NewForm->setLanguage($LinkedSettings->getLanguage());
  427.                     $em->persist($NewForm);
  428.                     // Clone questions
  429.                     foreach($Form->getQuestions() as $Question){
  430.                         $newQuestion = clone $Question;
  431.                         $newQuestion->setForm($NewForm);
  432.                         $em->persist($newQuestion);
  433.                     }
  434.                 }
  435.                 $em->flush();
  436.             }
  437.             // Store metadata/metatags
  438.             if(!empty($_POST['metadata'])){
  439.                 foreach($_POST['metadata'] as $metatagid => $value){
  440.                     $Metatag $this->getDoctrine()->getRepository('CmsBundle:Metatag')->findOneById($metatagid);
  441.                     $FormMetatag $this->getDoctrine()->getRepository('TrinityFormsBundle:Metatag')->findOneBy(['metatag' => $Metatag'form' => $Form]);
  442.                     if(empty($FormMetatag)){
  443.                         $FormMetatag = new \App\Trinity\FormsBundle\Entity\Metatag();
  444.                         $FormMetatag->setMetatag($Metatag);
  445.                         $FormMetatag->setForm($Form);
  446.                     }
  447.                     $FormMetatag->setValue($value);
  448.                     $em->persist($FormMetatag);
  449.                 }
  450.             $em->flush();
  451.             }
  452.             $this->resetPageCacheThatContainedBundle('TrinityFormsBundle'$this->Settings);
  453.             if(empty($_POST['inline_save'])){
  454.                 return $this->redirect($this->generateUrl('admin_mod_forms'));
  455.             }else{
  456.                 return $this->redirect($this->generateUrl('admin_mod_forms_edit', ['id' => $Form->getId()]));
  457.             }
  458.         }
  459.         $templates scandir('../templates/emails');
  460.         foreach($templates as $k => $v){
  461.             if(substr($v01) == '.'){
  462.                 unset($templates[$k]);
  463.             }
  464.         }
  465.         $questions $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findBy(array('form'=> $Form), array('sort' => 'ASC'));
  466.         // Check for newsletter presence
  467.         $emaillists null;
  468.         if(in_array('NewsletterBundle'$this->installed)){
  469.             $emaillists $this->getDoctrine()->getRepository('TrinityFormsBundle:Emaillist')->findAll();
  470.         }
  471.         $formMetatags = [];
  472.         $ignoreTags    = ['description''keywords'];
  473.         $metatags      $this->getDoctrine()->getRepository('CmsBundle:Metatag')->findBy(['system' => false]);
  474.         foreach($metatags as $index => $Metatag){
  475.             if(!in_array($Metatag->getKey(), $ignoreTags)){
  476.                 $FormMetatag $this->getDoctrine()->getRepository('TrinityFormsBundle:Metatag')->findOneBy(['metatag' => $Metatag'form' => $Form]);
  477.                 if(empty($FormMetatag)){
  478.                     $FormMetatag = new \App\Trinity\FormsBundle\Entity\Metatag();
  479.                     $FormMetatag->setMetatag($Metatag);
  480.                 }
  481.                 $formMetatags[] = $FormMetatag;
  482.             }
  483.         }
  484.         return $this->attributes(array(
  485.             'form'          => $editform->createView(),
  486.             'Form'          => $Form,
  487.             'mails'         => $Form->getMails(),
  488.             'questions'     => $questions,
  489.             'templates'     => $templates,
  490.             'hasNewsletter' => $hasNewsletter,
  491.             'id'            => $id,
  492.             'new'           => $new,
  493.             'Settings'      => $this->Settings,
  494.             'edit'          => true,
  495.             'saved'         => (bool)$saved,
  496.             'emaillists'    => $emaillists,
  497.             'metatags'      => $formMetatags,
  498.         ));
  499.     }
  500.     /**
  501.      * @Route("/admin/forms/config/{id}", name="admin_mod_forms_config")
  502.      * @Template()
  503.      */
  504.     public function configActionRequest $request$id)
  505.     {
  506.         parent::init($request);
  507.         $this->breadcrumbs->addRouteItem($this->trans("Formulieren"'cms'), "admin_mod_forms");
  508.         $this->breadcrumbs->addRouteItem($this->trans("Configureren"'cms'), "admin_mod_forms_config", ['id' => $id]);
  509.         $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->find($id);
  510.         $saved false;
  511.         $editform $this->createFormBuilder($Form)
  512.             ->add('label'TextType::class, array('label' => $this->trans('Formulier titel''cms')))
  513.             ->add('auto_response'CheckboxType::class, array('label' => $this->trans('Automatisch antwoord''cms')))
  514.             ->add('auto_response_subject'TextType::class, array('label' => $this->trans('Onderwerp''cms')))
  515.             ->add('auto_response_text'TextareaType::class, array('label' => $this->trans('E-mail inhoud''cms')))
  516.             ->setMethod('post')
  517.             ->getForm();
  518.         $em $this->getDoctrine()->getManager();
  519.         $editform->handleRequest($request);
  520.         if ($editform->isSubmitted() && $editform->isValid()) {
  521.             // Store in database
  522.             $em->persist($Form);
  523.             $em->flush();
  524.             return $this->redirect($this->generateUrl('admin_mod_forms'));
  525.         }
  526.         return $this->attributes(array(
  527.             'form'      => $editform->createView(),
  528.             'Form'      => $Form,
  529.         ));
  530.     }
  531.     /**
  532.      * @Route("/admin/forms/delete/{id}", name="admin_mod_forms_delete")
  533.      * @Template()
  534.      */
  535.     public function deleteAction(Request $request$id null)
  536.     {
  537.         parent::init($request);
  538.         $em $this->getDoctrine()->getManager();
  539.         $Form $em->getRepository('TrinityFormsBundle:Form')->find($id);
  540.         if(!is_null($Form)){
  541.             $em $this->getDoctrine()->getManager();
  542.             $sessions $em->getRepository('TrinityFormsBundle:Session')->findByForm($Form);
  543.             foreach($sessions as $a){
  544.                 $a->setForm(null);
  545.                 $a->setAnswer(null);
  546.                 $em->flush();
  547.             }
  548.             foreach($sessions as $a){
  549.                 $em->remove($a);
  550.                 $em->flush();
  551.             }
  552.             foreach($Form->getAnswers() as $a){
  553.                 $em->remove($a);
  554.                 $em->flush();
  555.             }
  556.             $em->remove($Form);
  557.             $em->flush();
  558.             $this->resetPageCacheThatContainedBundle('TrinityFormsBundle'$this->Settings);
  559.         }
  560.         return $this->redirect($this->generateUrl('admin_mod_forms'));
  561.     }
  562.     /**
  563.      * @Route("/forms/ajax/{id}", name="mod_forms_ajax")
  564.      * @Template()
  565.      */
  566.     public function ajaxShowAction(Request $request,$id null){
  567.         parent::init($request);
  568.         
  569.         $config['id'] = $id;
  570.         return $this->showAction($config,array('isAjax' => true),$request);
  571.     }
  572.     /**
  573.      * Show bundle content to front
  574.      *
  575.      * @param  array  $config Array with configuration options
  576.      * @param  array  $params Additional parameters
  577.      *
  578.      * @return string         HTML
  579.      */
  580.     public function showAction($config$params$request)
  581.     {
  582.         parent::init($request);
  583.         $Form $this->getDoctrine()->getRepository('TrinityFormsBundle:Form')->findOneById($config['id']);
  584.         if($Form){
  585.             $hash $this->get('session')->get('formhash');
  586.             if(is_null($hash) || substr($hash0strlen($Form->getId()) + 1) != $Form->getId() . '_'){
  587.                 $hash $Form->getId() . '_' md5(rand(1000,9999) . '' time());
  588.             }
  589.             
  590.             if(in_array('WebshopBundle',$this->installed)){
  591.                 if($this->Settings->getIsCatalog() && !empty($params[0])){
  592.                     $product $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->find($params[0]);
  593.                 }
  594.             }
  595.             $this->get('session')->set('formhash'$hash);
  596.             $saved false;
  597.             $error false;
  598.             $inline_error false;
  599.             $files = array();
  600.             $canvas = [];
  601.             // Add attachement
  602.             $uploadDir str_replace('/src/Trinity/FormsBundle/Controller' '/public/uploads/'__DIR__);
  603.             if(!is_writable($uploadDir)){
  604.                 die($this->trans('Upload dir for forms is not writable!''cms'));
  605.             }
  606.             $ctx $this->container->get('router')->getContext();
  607.             $webUrl $ctx->getScheme() . '://' $ctx->getHost();
  608.             if(isset($_FILES['form']['tmp_name'][$config['id']]) && is_array($_FILES['form']['tmp_name'][$config['id']])){
  609.                 foreach($_FILES['form']['tmp_name'][$config['id']] as $index => $tmpfile){
  610.                     if(!empty($tmpfile)){
  611.                         $filename $_FILES['form']['name'][$config['id']][$index];
  612.                         $size $_FILES['form']['size'][$config['id']][$index];
  613.                         if ($size 10485760) { // 10 MB
  614.                             $error $this->trans('Het bestand dat u probeert te uploaden is te groot:''cms') . ' <strong>' $filename '</strong> (' round($size/1024/10242) . ' MB)';
  615.                         }else{
  616.                             // Validation
  617.                             $finfo = new \finfo(FILEINFO_MIME_TYPE);
  618.                             if (false === $ext array_search(
  619.                                 $finfo->file($tmpfile),
  620.                                 [
  621.                                     'doc'     => 'application/doc',
  622.                                     'xls'     => 'application/excel',
  623.                                     'pdf'     => 'application/pdf',
  624.                                     'ppt'     => 'application/powerpoint',
  625.                                     'rtf'     => 'application/rtf',
  626.                                     'keynote' => 'application/vnd.apple.keynote',
  627.                                     'numbers' => 'application/vnd.apple.numbers',
  628.                                     'pages'   => 'application/vnd.apple.pages',
  629.                                     'xlsx'    => 'application/vnd.ms-excel',
  630.                                     'pptx'    => 'application/vnd.ms-powerpoint',
  631.                                     'rar'     => 'application/x-rar-compressed',
  632.                                     'zip'     => 'application/zip',
  633.                                     'ogg'     => 'audio/ogg',
  634.                                     'wav'     => 'audio/wav',
  635.                                     'midi'    => 'audio/x-midi',
  636.                                     'csv'     => 'text/csv',
  637.                                     'avi'     => 'video/avi',
  638.                                     'mp4'     => 'video/mp4',
  639.                                     'mpg'     => 'video/mpeg',
  640.                                     'mpeg'    => 'video/mpeg',
  641.                                     'mov'     => 'video/quicktime',
  642.                                     'bmp'     => 'image/bmp',
  643.                                     'gif'     => 'image/gif',
  644.                                     'jpeg'    => 'image/jpeg',
  645.                                     'jpg'     => 'image/jpeg',
  646.                                     'png'     => 'image/png',
  647.                                     'svg'     => 'image/svg+xml',
  648.                                 ],
  649.                                 true
  650.                             )) {
  651.                                 $error $this->trans('U heeft geen geldig bestandstype geupload:''cms') . ' <strong>' $filename '</strong><br/><br/>' $this->trans('De volgende bestanden zijn toegestaan:''cms') . '<br/>.doc, .xls, .pdf, .ppt, .rtf, .keynote, .numbers, .pages, .xlsx, .pptx, .rar, .zip, .ogg, .wav, .midi, .csv, .avi, .mp4, .mpg, .mpeg, .mov, .bmp, .gif, .jpeg, .jpg, .png, .svg.';
  652.                             }
  653.                         }
  654.                         if(!$error){
  655.                             $tmpUploadDir $uploadDir '';
  656.                             $tmpUploadDir $tmpUploadDir 'forms/';
  657.                             if(!file_exists($tmpUploadDir)) mkdir($tmpUploadDir);
  658.                             $tmpUploadDir $tmpUploadDir $config['id'] . '/';
  659.                             if(!file_exists($tmpUploadDir)) mkdir($tmpUploadDir);
  660.                             $tmpUploadDir $tmpUploadDir date('YmdH') . '/';
  661.                             if(!file_exists($tmpUploadDir)) mkdir($tmpUploadDir);
  662.                             $dest $tmpUploadDir $filename;
  663.                             if(move_uploaded_file($tmpfile$dest)){
  664.                                 $files[$filename] = $webUrl '/uploads/forms/' $config['id'] . '/' date('YmdH') . '/' $filename;
  665.                             }
  666.                         }
  667.                     }
  668.                 }
  669.             }
  670.             // Store in database
  671.             if(!empty($_POST['form']) && !$error && !empty($_POST['form-bundle-submit']) && $_POST['form-bundle-submit'] == $Form->getId()){
  672.                 // $Session = $this->getDoctrine()->getRepository('TrinityFormsBundle:Session')->findOneByHash($hash);
  673.                 $validCaptcha $this->Settings->validateGoogleRecaptcha($request->request->get('g-recaptcha-response'));
  674.             
  675.                 if(($validCaptcha) && empty($_POST['form-check'])){
  676.                     if(empty($Session)){
  677.                         // Generate new session in case the current sesion got lost.
  678.                         $hash $Form->getId() . '_' md5(rand(1000,9999) . '' time());
  679.                         $this->get('session')->set('formhash'$hash);
  680.                         // if(is_null($Session)){
  681.                         $Session = new \App\Trinity\FormsBundle\Entity\Session();
  682.                         $Session->setForm($Form);
  683.                         $Session->setHash($hash);
  684.                         $Session->setIpaddress($_SERVER['REMOTE_ADDR']);
  685.                         $Session->setDateStart(new \Datetime("now"));
  686.                     }
  687.                     $receiverFromAnswer null;
  688.                 $Answer $this->getDoctrine()->getRepository('TrinityFormsBundle:Answer')->findOneBySession($Session);
  689.                 if(!empty($Answer)){
  690.                     $saved false;
  691.                     $error $this->trans('Uw heeft het formulier al verzonden.''cms');
  692.                 }else{
  693.                     $Answer = new \App\Trinity\FormsBundle\Entity\Answer();
  694.                     $Answer->setForm($Form);
  695.                     $results = array();
  696.                     $email null;
  697.                     $firstname '';
  698.                     $lastname '';
  699.                     $emaillist null;
  700.                     foreach($_POST['form'][$Form->getId()] as $questionid => $answer){
  701.                         $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findOneById($questionid);
  702.                         if($Question->getType() == 'email'){
  703.                             $email $answer;
  704.                         }
  705.                         if($Question->getType() == 'newsletter'){
  706.                             $this->addmemberActivecampaign($Answer->getForm(), [], $email);
  707.                         }
  708.                         if($Question->getType() == 'mailer'){
  709.                             if($email !== null) {
  710.                                 $mailerTool = new MailerTool(
  711.                                         $this->Settings->getHummessengerApiUrl(),
  712.                                         $this->Settings->getHummessengerApiKey(),
  713.                                         $Answer->getForm()->getMailerListid()
  714.                                 );
  715.                                 $mailerTool->setEmail($email);
  716.                                 if ($firstname != '') {
  717.                                     $mailerTool->setName($firstname);
  718.                                 }
  719.                                 if ($lastname != '') {
  720.                                     $mailerTool->setSurname($lastname);
  721.                                 }
  722.                                 $mailerTool->EditToList();
  723.                             }
  724.                         }
  725.                         if($Question->getType() == 'canvas'){
  726.                                 $random bin2hex(openssl_random_pseudo_bytes(5));
  727.                                 $filename 'canvas-' $random '.png';
  728.                                 $encoded_image explode(","$answer)[1];
  729.                                 $decoded_image base64_decode($encoded_image);
  730.                                 $uploadDir str_replace('/src/Trinity/FormsBundle/Controller' '/public/uploads/'__DIR__);
  731.                                 $uploadDir $uploadDir 'canvas/';
  732.                                 if(!file_exists($uploadDir)) {
  733.                                     mkdir($uploadDir);
  734.                                 }
  735.                                 $uploadDir $uploadDir date('Ymd') . '/';
  736.                                 if(!file_exists($uploadDir)) {
  737.                                     mkdir($uploadDir);
  738.                                 }
  739.                                 $dest $uploadDir $filename;
  740.                                 $webDest preg_replace('/^.*?\/public/'''$dest);
  741.                                 if(file_put_contents($dest$decoded_image) === false)
  742.                                 {
  743.                                     // return code was false
  744.                                 }else {
  745.                                     $canvas[$Question->getTitle()] = $webUrl $webDest;
  746.                                 }
  747.                             }
  748.                             if(preg_match('/voornaam/'strtolower($Question->getTitle()))){
  749.                                 $firstname $answer;
  750.                             }
  751.                             if(preg_match('/achternaam/'strtolower($Question->getTitle()))){
  752.                                 $lastname $answer;
  753.                             }
  754.                             if($Question->getType() == 'select'){
  755.                                 foreach($Question->getValues() as $i => $v){
  756.                                     if($v == $answer){
  757.                                         if(!empty($Question->getEmail()[$i])){
  758.                                             // Can send mail?
  759.                                             $receiverFromAnswer $v;
  760.                                         }
  761.                                     }
  762.                                 }
  763.                             }
  764.                             $results[$Question->getTitle()] = $answer;
  765.                         }
  766.                         $imagesUrls = [];
  767.                         $hosturl $this->generateUrl('homepage', [], \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL);
  768.                         if(isset($_POST['imageslist'])) {
  769.                             $imageQuestionId 0;
  770.                             foreach($_POST['imageslist'] as $questionid => $answer) {
  771.                                 $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findOneById($questionid);
  772.                                 $imageQuestionId $Question->getId();
  773.                                 if ($Question->getType() == 'dropzone') {
  774.                                     $images explode(','$answer);
  775.                                     foreach($images as $imageId) {
  776.                                         /** @var Media $Media */
  777.                                         $Media $this->getDoctrine()->getRepository('CmsBundle:Media')->find($imageId);
  778.                                         if ($Media) {
  779.                                             $extentions explode('.'$Media->getWebPath());
  780.                                             switch (end($extentions)){
  781.                                                 case 'doc':
  782.                                                 case 'docx':
  783.                                                     $path 'bundles/cms/images/filetypes/' $Media->getFileImage();
  784.                                                     break;
  785.                                                 case 'xlsx':
  786.                                                     $path 'bundles/cms/images/filetypes/excel.png';
  787.                                                     break;
  788.                                                 case 'pptx':
  789.                                                     $path 'bundles/cms/images/filetypes/powerpoint.png';
  790.                                                     break;
  791.                                                 default:
  792.                                                     if($Media->getFileImage() !== 'png.png' || $Media->getFileImage() !== 'jpg.png'){
  793.                                                         $path 'bundles/cms/images/filetypes/' $Media->getFileImage();
  794.                                                     } else {
  795.                                                         $path $Media->getWebPath();
  796.                                                     }
  797.                                             }
  798.                                             $imagesUrls[] = '<a class="d-flex justify-content-center" target="_blank" href="' $hosturl $Media->getWebPath() . '"><img src="' $hosturl $path '" width="70" height="70"/><br/> klik hier om ' $Media->getLabel() . ' te downloaden </a>';
  799.                                         }
  800.                                     }
  801.                                 }
  802.                             }
  803.                             $results[$imageQuestionId] = $imagesUrls;
  804.                         }
  805.                         $Answer->setIp($_SERVER['REMOTE_ADDR']);
  806.                         $Answer->setAnswer(json_encode($resultsJSON_FORCE_OBJECT));
  807.                         $Answer->setSession($Session);
  808.                         $Session->setDateEnd(new \Datetime("now"));
  809.                         $Session->setAnswer($Answer);
  810.                         $Session->setDone(1);
  811.                         $Session->setDuration($Session->getDateEnd()->getTimestamp() - $Session->getDateStart()->getTimestamp());
  812.                         if($this->Settings->getLefApiActive() && $Form->getLefApiActive()){
  813.                             if($this->Settings->getLefFormsRequest()){
  814.                                 $origin $_SERVER['HTTP_REFERER'];
  815.                                 $hostUrl "https://".$this->Settings->getHost();
  816.                                 $lef = new \App\CmsBundle\Classes\Lef();
  817.                                 $apiRequest $lef->setSettings($this->Settings)
  818.                                     ->setId()
  819.                                     ->setType()
  820.                                     ->setKindOf()
  821.                                     ->setInitType()
  822.                                     ->setDescription($Form->getLabel())
  823.                                     ->setOrigin($hostUrl)
  824.                                     ->setEntityManager($this->getDoctrine())
  825.                                     ->setByForm($_POST['form'][$Form->getId()])
  826.                                     ->addAddress();
  827.                                 if(!empty($origin)){
  828.                                     $apiRequest->addPair("Url",$origin);
  829.                                     $apiRequest->addGroup("Volledige URL");
  830.                                 }
  831.                                 $result $apiRequest->send();
  832.                                 if(!empty($result)){
  833.                                     $questions $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findBy(array('form'=> $Form), array('sort' => 'ASC'));
  834.                                     $error $result;
  835.                                     $saved false;
  836.                                     $maxFileSize 10;
  837.                                     return $this->renderView('@TrinityForms/default/form.html.twig', array(
  838.                                         'config'           => $config,
  839.                                         'Form'             => $Form,
  840.                                         'questions'        => $questions,
  841.                                         'saved'            => $saved,
  842.                                         'hide_send'        => !empty($config['hide_send']),
  843.                                         'error'            => $error,
  844.                                         'inline_error'     => $inline_error,
  845.                                         'settings'         => $this->Settings,
  846.                                         'maxMediaFileSize' => $this->Settings->getMaxMediaSizeInKB(),
  847.                                         'maxFileSize'      => $maxFileSize,
  848.                                     ));
  849.                                 }
  850.                             }
  851.                         }
  852.                         /*
  853.                             AUTO RESPONSE
  854.                         */
  855.                         /*if($Form->getAutoResponse() && $email){
  856.                             $Settings = $this->getDoctrine()->getRepository('CmsBundle:Settings')->findOneById(1);
  857.                             $body = $this->renderView(
  858.                                     ':emails:notify.html.twig',
  859.                                     array(
  860.                                         'label' => $Form->getAutoResponseSubject(),
  861.                                         'message' => $Form->getAutoResponseText()
  862.                                     )
  863.                                 );
  864.                             $message = \Swift_Message::newInstance()
  865.                             ->setSubject($Form->getAutoResponseSubject())
  866.                             ->setFrom(array($Settings->getSystemEmail() => $Settings->getSystemEmailFrom()))
  867.                             ->setTo($email)
  868.                             ->setBody($body, 'text/html')
  869.                             ->addPart($Form->getAutoResponseText(), 'text/plain');
  870.                             $this->get('mailer')->send($message);
  871.                         }*/
  872.                         /*
  873.                             SEND COPY
  874.                         */
  875.                         if(!empty($_POST['form'][$Form->getId()])){
  876.                             ob_start();
  877.                             $this->trans('Het onderstaande formulier is ingevuld via de website:''cms')
  878.                             ?>
  879.                             <table style="margin-top: 20px;width: 100%;">
  880.                                 <?php
  881.                                 foreach($_POST['form'][$Form->getId()] as $questionid => $value){
  882.                                     $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findOneById($questionid);
  883.                                     // we don't want the raw canvas data in the mails, canvas data will get added as a Bijlage
  884.                                     if($Question->getType() == "canvas")
  885.                                     {
  886.                                         continue;
  887.                                     }
  888.                                     $valueLabels $Question->getValues();
  889.                                     if ($Question->getType() == 'checkbox') {
  890.                                         if(is_array($value)){
  891.                                             $value '<ul><li>' implode('</li><li>'$value) . '</li></ul>';
  892.                                         }
  893.                                     }
  894.                                     // I don't know why this code is here, probably for checkbox. But so leave it here and fix checkbox above.
  895.                                     if(is_array($value)){
  896.                                         $values = [];
  897.                                         foreach($value as $k => $v){
  898.                                             $values[] = $valueLabels[$k];
  899.                                         }
  900.                                         $value '<ul><li>' implode('</li><li>'$values) . '</li></ul>';
  901.                                     }
  902.                                     if(preg_match('/\s?\|\s?/'$value)){
  903.                                         $value preg_replace('/^(.*?)\s?\|.*?$/''$1'$value);
  904.                                     }
  905.                                     $value str_replace('&comma;'','$value);
  906.                                     ?>
  907.                                     <tr>
  908.                                         <td style="padding: 10px 0;width: 40%;vertical-align: top;font-weight: bold;text-align: right;padding-right: 20px;"><?php echo $Question->getTitle(); ?></td>
  909.                                         <td style="padding: 10px 0;width: 60%;vertical-align: top;"><?php echo nl2br($value); ?></td>
  910.                                     </tr>
  911.                                     <?php
  912.                                 }
  913.                             if(!empty($files) || !empty($canvas) || !empty($imagesUrls)){
  914.                                 if ($Question->getType() == 'newsletter') {
  915.                                     if(is_array($value)){
  916.                                         $value '<ul><li>' implode('</li><li>'$value) . '</li></ul>';
  917.                                     }
  918.                                 }
  919.                                 ?>
  920.                                 <tr>
  921.                                     <td style="padding: 10px 0;width: 40%;vertical-align: top;font-weight: bold;text-align: right;padding-right: 20px;"><?php $this->trans('Bijlage(n)''cms')?></td>
  922.                                     <td style="padding: 10px 0;width: 60%;vertical-align: top;">
  923.                                         <?php
  924.                                         foreach($files as $filename => $path){
  925.                                             ?>
  926.                                             <a href="<?php echo $path?>"><?php echo $filename?></a><br />
  927.                                             <?php   
  928.                                         }
  929.                                             foreach($canvas as $title => $path){
  930.                                                 echo $title;
  931.                                                 ?>
  932.                                                 <br />
  933.                                                 <img src="<?php echo $path?>" style="width: 400px; height: 200px;"><br/>
  934.                                                 <?php
  935.                                             }
  936.                                             foreach($imagesUrls as $i) {
  937.                                                 ?>
  938.                                                 <?php echo $i?><br/><br/>
  939.                                                 <?php
  940.                                             }
  941.                                             ?>
  942.                                         </td>
  943.                                     </tr>
  944.                                     <?php
  945.                                 }
  946.                                 ?>
  947.                             </table>
  948.                             <?php
  949.                             $message ob_get_contents();
  950.                             ob_end_clean();
  951.                             /*if($this->container->getParameter('kernel.environment') == 'dev'){
  952.                                 dump($message);die();
  953.                             }*/
  954.                                 //$Settings = $this->getDoctrine()->getRepository('CmsBundle:Settings')->findOneById(1);
  955.                             $mails $Form->getMails();
  956.                             foreach($mails as $key => $mail){
  957.                                 if(!isset($mail['receiver'])){
  958.                                     // Try to find local mailaddress
  959.                                     $mail['receiver'] = $email;
  960.                                 }
  961.                                 // Remove spaces
  962.                                 $mail['receiver'] = str_replace(' '''$mail['receiver']);
  963.                                 $mail['receiver'] = explode(';'$mail['receiver']);
  964.                                 $vals $_POST['form'][$Form->getId()];
  965.                                 foreach($mail['receiver'] as $index => $receiver){
  966.                                     if(empty($receiver)){
  967.                                         unset($mail['receiver'][$index]);
  968.                                     }
  969.                                 }
  970.                                 $tags preg_match_all('/\[(\d+)\#.*?\]/'$mail['subject'], $m);
  971.                                 if($tags){
  972.                                     foreach($m[1] as $index => $field_id){
  973.                                         $value $vals[$field_id];
  974.                                         if(preg_match('/\s?\|\s?/'$value)){
  975.                                             $value preg_replace('/^(.*?)\s?\|.*?$/''$1'$value);
  976.                                         }
  977.                                         $mail['subject'] = str_replace($m[0][$index], $value$mail['subject']);
  978.                                     }
  979.                                 }
  980.                                 if (isset($mail['sendername'])) {
  981.                                     $tags preg_match_all('/\[(\d+)\#.*?\]/'$mail['sendername'], $m);
  982.                                     if($tags){
  983.                                         foreach($m[1] as $index => $field_id){
  984.                                             $value $vals[$field_id];
  985.                                             if(preg_match('/\s?\|\s?/'$value)){
  986.                                                 $value preg_replace('/^(.*?)\s?\|.*?$/''$1'$value);
  987.                                             }
  988.                                             $mail['sendername'] = str_replace($m[0][$index], $value$mail['sendername']);
  989.                                         }
  990.                                     }
  991.                                 }
  992.                                 if(!empty($mail['receiver'])){
  993.                                         if(is_array($mail['receiver'])){
  994.                                             foreach($mail['receiver'] as $i => $receiver){
  995.                                                 $tags preg_match_all('/\[(\d+)\#.*?\]/'$receiver$m);
  996.                                                 if($tags){
  997.                                                     foreach($m[1] as $index => $field_id){
  998.                                                         $receiver str_replace($m[0][$index], $vals[$field_id], $receiver);
  999.                                                         if(preg_match('/\s?\|\s?/'$receiver)){
  1000.                                                             $receiver preg_replace('/^.*?\s?\|\s?(.*?)$/''$1'$receiver);
  1001.                                                         }
  1002.                                                     }
  1003.                                                 }
  1004.                                                 $mail['receiver'][$i] = $receiver;
  1005.                                             }
  1006.                                         }
  1007.                                     $tags preg_match_all('/\[(\d+)\#.*?\]/'$mail['content'], $m);
  1008.                                     if($tags){
  1009.                                         foreach($m[1] as $index => $field_id){
  1010.                                                 $value $vals[$field_id];
  1011.                                                 if(preg_match('/\s?\|\s?/'$value)){
  1012.                                                     $value preg_replace('/^(.*?)\s?\|.*?$/''$1'$value);
  1013.                                                 }
  1014.                                                 $mail['content'] = str_replace($m[0][$index], $value$mail['content']);
  1015.                                         }
  1016.                                     }
  1017.                                     $mail['content'] = str_replace('[FORM_RESULTS]'$message$mail['content']);
  1018.                                     
  1019.                                     if(in_array('WebshopBundle',$this->installed)){
  1020.                                         if($this->Settings->getIsCatalog() && !empty($_POST["form"]["productid"])){
  1021.                                             $product $this->getDoctrine()->getRepository('TrinityWebshopBundle:Product')->find($_POST["form"]["productid"]);
  1022.                                             if(!empty($product)){
  1023.                                                 $productInfo $product->getLabel();
  1024.                                                 $mail['content'] = str_replace('[productinfo]'$productInfo,$mail['content']);
  1025.                                             }
  1026.                                         }
  1027.                                     }
  1028.                                     // $mail['receiver'] = 'jelle@beyonit.nl';
  1029.                                     $mailer = clone $this->mailer;
  1030.                                     $mailer->init();
  1031.                                     // Add optional reply-to
  1032.                                     if ($key == 'internal') {
  1033.                                         if (isset($mail['sendername']) && !empty($mail['sendername'])) {
  1034.                                             if($this->Settings->getTest()){
  1035.                                                 $mailer->setFrom(explode(';'$this->Settings->getAdminEmail())[0], $mail['sendername']);
  1036.                                             }else{
  1037.                                                 $mailer->setFrom($this->Settings->getSystemEmail(), $mail['sendername']);
  1038.                                             }
  1039.                                         }
  1040.                                         if ($Form->getMailReplyTo() && !empty($email) && !empty($mail['sendername'])) {
  1041.                                             $mailer->setReplyTo([$email => $mail['sendername']]);
  1042.                                         } elseif ($Form->getMailReplyTo() && !empty($email)) {
  1043.                                             $mailer->setReplyTo([$email]);
  1044.                                         }
  1045.                                     }
  1046.                                     $mailer->setSubject($mail['subject'])
  1047.                                             ->setTo($mail['receiver'])
  1048.                                             ->setTwigBody('/emails/' $mail['template'], [
  1049.                                                 // 'label' => $mail['label'],
  1050.                                                 'message' => $mail['content']
  1051.                                             ])
  1052.                                             ->setPlainBody($mail['content']);
  1053.                                         if(!empty($mail['from_email']) && !empty($mail['from_name'])){
  1054.                                             $mailer->setFrom($mail['from_email'], $mail['from_name']);
  1055.                                         }
  1056.                                     $send $mailer->execute_forced();
  1057.                                 }
  1058.                             }
  1059.                         }
  1060.                         /**
  1061.                          * LEF call
  1062.                          */
  1063.                         if (isset($config['extension_lef']))
  1064.                         {
  1065.                             $extensionObject = new \App\Trinity\ExtensionsBundle\Classes\Extensions($this->container$this->Settings'lef');
  1066.                             $formLabel $Form->getLabel();
  1067.                             $extensionObject->setDescriptionSuffix($formLabel);
  1068.                             // Aftersales formulieren
  1069.                             $aftersales = [];
  1070.                             if (preg_match('/renses-online.nl/'$request->server->get('HTTP_HOST')))
  1071.                             {
  1072.                                 $aftersales[] = 'werkplaats';
  1073.                                 $aftersales[] = 'ruitschade';
  1074.                                 $aftersales[] = 'autoschade';
  1075.                             }
  1076.                             if (preg_match('/kreijne.nl/'$request->server->get('HTTP_HOST')))
  1077.                             {
  1078.                                 $aftersales[] = 'Auto verzekering';
  1079.                                 $aftersales[] = 'werkplaatsafspraak';
  1080.                             }
  1081.                             foreach ($aftersales as $as)
  1082.                             {
  1083.                                 if (strpos(strtolower($formLabel), $as) !== FALSE)
  1084.                                 {
  1085.                                     $extensionObject->setLeadType('AfterSales');
  1086.                                 }
  1087.                             }
  1088.                             // FIXME HARDCODED, hoe willen we particulier / zakelijk keuze aanbidden?
  1089.                             $extensionObject->setRelationType($extensionObject->getRelationType()[0]);
  1090.                             $foundAccount false;
  1091.                             $extrainfo = [];
  1092.                             foreach($_POST['form'][$Form->getId()] as $questionid => $answer)
  1093.                             {
  1094.                                 $Question $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findOneById($questionid);
  1095.                                 switch($Question->getTitle())
  1096.                                 {
  1097.                                     case "Vestiging":
  1098.                                 case "Selecteer vestiging":
  1099.                                         $accounts $extensionObject->getAccounts();
  1100.                                         foreach($accounts as $account)
  1101.                                         {
  1102.                                         $expoded explode(' '$answer);
  1103.                                         foreach ($expoded as $item)
  1104.                                         {
  1105.                                             if (strpos($account['label'], $item) !== false)
  1106.                                             {
  1107.                                                 $foundAccount true;
  1108.                                                 $extensionObject->setAccount($account['id']);
  1109.                                                 $extrainfo['vestiging'] = $answer;
  1110.                                                 continue 2;
  1111.                                             }
  1112.                                         }
  1113.                                     }
  1114.                                     if (preg_match('/kreijne.nl/'$request->server->get('HTTP_HOST')))
  1115.                                     {
  1116.                                         $aftersalesquestions 'werkplaats';
  1117.                                         if (strpos(strtolower($answer), $aftersalesquestions) !== FALSE)
  1118.                                         {
  1119.                                             $extensionObject->setLeadType('AfterSales');
  1120.                                             }
  1121.                                         }
  1122.                                         break;
  1123.                                     case "Aanhef":
  1124.                                         $extensionObject->setNamePrefix($answer);
  1125.                                         break;
  1126.                                     case "Voornaam":
  1127.                                         $extensionObject->setFirstName($answer);
  1128.                                         break;
  1129.                                     case "Voorletters":
  1130.                                         $extensionObject->setNameInitials($answer);
  1131.                                         break;
  1132.                                     case "tussenvoegsel":
  1133.                                         $extensionObject->setMiddleName($answer);
  1134.                                         break;
  1135.                                     case "Naam":
  1136.                                     case "Uw naam":
  1137.                                     case "Achternaam":
  1138.                                     case "Voornaam + Achternaam":
  1139.                                         $extensionObject->setLastName($answer);
  1140.                                         break;
  1141.                                     case "Straat":
  1142.                                     case "Straatnaam + huisnummer":
  1143.                                         $extensionObject->setStreetName($answer);
  1144.                                         break;
  1145.                                     case "Huisnummer":
  1146.                                     case "huisnummer":
  1147.                                         $extensionObject->setHouseNumber($answer);
  1148.                                         break;
  1149.                                 case "Huisnummertoevoeging":
  1150.                                     case "huisnummertoevoeging":
  1151.                                         $extensionObject->setHouseNumberSuffix($answer);
  1152.                                         break;
  1153.                                     case "Postcode":
  1154.                                     case "postcode":
  1155.                                         $extensionObject->setPostcode($answer);
  1156.                                         break;
  1157.                                     case "Plaats":
  1158.                                     case "Stad":
  1159.                                         $extensionObject->setCity($answer);
  1160.                                         break;
  1161.                                     case "Land":
  1162.                                         $extensionObject->setCountry($answer);
  1163.                                         break;
  1164.                                     case "GeboorteDatum":
  1165.                                     case "Geboortedatum":
  1166.                                         $extensionObject->setBirthday($answer);
  1167.                                         break;
  1168.                                     case "Gender":
  1169.                                     case "Sex":
  1170.                                         $extensionObject->setGender($answer);
  1171.                                         break;
  1172.                                     case "Telefoonnummer":
  1173.                                         $extensionObject->addTelephoneNumber($answer);
  1174.                                         break;
  1175.                                     case "Bedrijfsnaam":
  1176.                                         $extensionObject->setCompanyName($answer);
  1177.                                         break;
  1178.                                     case "Bedrijfsnummer":
  1179.                                     case "CompanyNumber":
  1180.                                     case "KvKnummer":
  1181.                                         $extensionObject->setCompanyNumber($answer);
  1182.                                         break;
  1183.                                     case "E-mailadres":
  1184.                                     case "Uw e-mailadres":
  1185.                                     case "E-mail":
  1186.                                         $extensionObject->setEmailAddress($answer);
  1187.                                         break;
  1188.                                     default:
  1189.                                         // Add unknown forms to extrainfo.
  1190.                                         $title $Question->getTitle();
  1191.                                         $newtitle $title;
  1192.                                         // Make sure we don't overwrite another key, value pair
  1193.                                         for($i 0; ; $i++)
  1194.                                         {
  1195.                                             if (array_key_exists($newtitle$extrainfo))
  1196.                                             {
  1197.                                                 $newtitle $title ' ' . ($i 1);
  1198.                                         } else {
  1199.                                                 break;
  1200.                                         }
  1201.                                     }
  1202.                                         // Support checkbox questions
  1203.                                         if (is_array($answer))
  1204.                                         {
  1205.                                             $question_value_list $Question->getValues();
  1206.                                             $temp 'Opties: ';
  1207.                                             foreach($answer as $key => $a)
  1208.                                             {
  1209.                                                 if ($temp != 'Opties: ')
  1210.                                             {
  1211.                                                     $temp .= '; ';
  1212.                                             }
  1213.                                                 $temp .= '\'' $question_value_list[$key] . '\'';
  1214.                                             }
  1215.                                             $answer $temp ' geselecteerd';
  1216.                                         }
  1217.                                         $extrainfo[$newtitle] = $answer;
  1218.                                         break;
  1219.                                 }
  1220.                             } // end foreach()
  1221.                             if (!$foundAccount)
  1222.                             {
  1223.                                 $accounts $extensionObject->getAccounts();
  1224.                                 if(count($accounts) >= 1)
  1225.                                 {
  1226.                                     $extensionObject->setAccount($accounts[0]['id']);
  1227.                                 }
  1228.                             }
  1229.                             $extensionObject->setAdditionInfoGroup('Overige informatie'$extrainfo);
  1230.                             $extensionObject->sendContent();
  1231.                         } // end LEF
  1232.                         //Active Campaign
  1233.                         if ($Form->getActiveCampaign() && !empty($Form->getActiveCampaignKey()) && !empty($Form->getActiveCampaignListid())) {
  1234.                             $this->addmemberActivecampaign($Form$results$email);
  1235.                         }
  1236.                     $em $this->getDoctrine()->getManager();
  1237.                     $em->persist($Answer);
  1238.                     $em->persist($Session);
  1239.                     if($emaillist && $email && in_array('NewsletterBundle'$this->installed)){
  1240.                         $List $this->getDoctrine()->getRepository('TrinityNewsletterBundle:Emaillist')->find($emaillist);
  1241.                         $Recipient = new \App\Trinity\NewsletterBundle\Entity\Recipient();
  1242.                         $Recipient->setEmaillist($List);
  1243.                         $Recipient->setEmail($email);
  1244.                         $Recipient->setName(implode(' ', [$firstname$lastname]));
  1245.                         $em->persist($Recipient);
  1246.                     }
  1247.                     $em->flush();
  1248.                     $saved true;
  1249.                         if(isset($config['redirect']) && !empty($config['redirect'])){
  1250.                             header('Location: ' $config['redirect']);
  1251.                             exit;
  1252.                         }
  1253.                     }
  1254.                 }
  1255.                 else
  1256.                 {
  1257.                     $saved false;
  1258.                     $inline_error $this->trans('Ongeldige reCAPTCHA.''cms');
  1259.                 }
  1260.             }else{
  1261.                 $hash $Form->getId() . '_' md5(rand(1000,9999) . '' time());
  1262.                 $this->get('session')->set('formhash'$hash);
  1263.                 // if(is_null($Session)){
  1264.                 $Session = new \App\Trinity\FormsBundle\Entity\Session();
  1265.                 $Session->setForm($Form);
  1266.                 $Session->setHash($hash);
  1267.                 $Session->setIpaddress($_SERVER['REMOTE_ADDR']);
  1268.                 $Session->setDateStart(new \Datetime("now"));
  1269.                 $em $this->getDoctrine()->getManager();
  1270.                 $em->persist($Session);
  1271.                 $em->flush();
  1272.                 // }
  1273.             }
  1274.             $questions $this->getDoctrine()->getRepository('TrinityFormsBundle:Question')->findBy(array('form'=> $Form), array('sort' => 'ASC'));
  1275.             $maxFileSize 10;
  1276.             try{
  1277.                 //$maxFileSize = (int)ini_get('upload_max_filesize');
  1278.             }catch(\Exception $e){
  1279.                 // Nothing going on here
  1280.             }
  1281.             
  1282.             $parameters = array(
  1283.                     'config'           => $config,
  1284.                     'Form'             => $Form,
  1285.                     'questions'        => $questions,
  1286.                     'saved'            => $saved,
  1287.                     'hide_send'        => !empty($config['hide_send']),
  1288.                     'error'            => $error,
  1289.                     'inline_error'     => $inline_error,
  1290.                     'settings'         => $this->Settings,
  1291.                     'maxMediaFileSize' => $this->Settings->getMaxMediaSizeInKB(),
  1292.                     'maxFileSize'      => $maxFileSize,
  1293.                     'product'               => (!empty($product) ? $product null)
  1294.                 );
  1295.             
  1296.             if(!empty($params["isAjax"]) && $params["isAjax"]){
  1297.                 return $this->render('@TrinityForms/default/form.html.twig',$parameters);                
  1298.             }
  1299.             return $this->renderView('@TrinityForms/default/form.html.twig',$parameters);
  1300.         }
  1301.         return $this->renderView('@TrinityForms/default/not-found.html.twig');
  1302.     }
  1303.     public function addmemberActivecampaign($Form$results$email)
  1304.     {
  1305.         $ApiKey $Form->getActiveCampaignKey();
  1306.         $ListId $Form->getActiveCampaignListid();
  1307.         $ApiUrl $Form->getActiveCampaignUrl();
  1308.         if (isset($results['Naam'])) {
  1309.             $name $results['Naam'];
  1310.         } else {
  1311.             $name explode("@"$email)[0];
  1312.         }
  1313.         // $Mail = $_POST['email'];
  1314.         $curl curl_init();
  1315.         $data = array(
  1316.             'contact' => array(
  1317.                 'email' => $email,
  1318.                 // 'lastname' => $firstName,
  1319.                 'firstName' => $name,
  1320.                 // 'phone' => $_POST['phone']
  1321.             )
  1322.         );
  1323.         curl_setopt_array($curl, array(
  1324.             CURLOPT_URL => $ApiUrl "/api/3/contacts",
  1325.             CURLOPT_RETURNTRANSFER => true,
  1326.             CURLOPT_ENCODING => "",
  1327.             CURLOPT_SSL_VERIFYPEER => false,
  1328.             CURLOPT_MAXREDIRS => 10,
  1329.             CURLOPT_TIMEOUT => 30,
  1330.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1331.             CURLOPT_CUSTOMREQUEST => "POST",
  1332.             CURLOPT_POSTFIELDS => json_encode($data),
  1333.             CURLOPT_HTTPHEADER => array(
  1334.                 "Api-Token: $ApiKey",
  1335.                 "Content-Type: application/json",
  1336.                 "Postman-Token: 41fb5406-d0b7-40e3-b168-2645967314b0",
  1337.                 "cache-control: no-cache"
  1338.             )
  1339.         ));
  1340.         $response curl_exec($curl);
  1341.         $err curl_error($curl);
  1342.         curl_close($curl);
  1343.         $curl curl_init();
  1344.         curl_setopt_array($curl, array(
  1345.             CURLOPT_URL => $ApiUrl "/api/3/contacts?search=" $email,
  1346.             CURLOPT_RETURNTRANSFER => true,
  1347.             CURLOPT_ENCODING => "",
  1348.             CURLOPT_SSL_VERIFYPEER => false,
  1349.             CURLOPT_MAXREDIRS => 10,
  1350.             CURLOPT_TIMEOUT => 30,
  1351.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1352.             CURLOPT_CUSTOMREQUEST => "GET",
  1353.             CURLOPT_HTTPHEADER => array(
  1354.                 "Api-Token: $ApiKey",
  1355.                 "Content-Type: application/json",
  1356.                 "Postman-Token: 41fb5406-d0b7-40e3-b168-2645967314b0",
  1357.                 "cache-control: no-cache"
  1358.             )
  1359.         ));
  1360.         $response1 curl_exec($curl);
  1361.         $err curl_error($curl);
  1362.         $dataID json_decode($response1true);
  1363.         $ID $dataID['contacts'][0]["id"];
  1364.         curl_close($curl);
  1365.         $curl curl_init();
  1366.         $dataList = array(
  1367.             'contactList' => array(
  1368.                 'list' => $ListId,
  1369.                 'contact' => $ID,
  1370.                 'status' => 1,
  1371.             )
  1372.         );
  1373.         curl_setopt_array($curl, array(
  1374.             CURLOPT_URL => $ApiUrl "/api/3/contactLists",
  1375.             CURLOPT_RETURNTRANSFER => true,
  1376.             CURLOPT_ENCODING => "",
  1377.             CURLOPT_SSL_VERIFYPEER => false,
  1378.             CURLOPT_MAXREDIRS => 10,
  1379.             CURLOPT_TIMEOUT => 30,
  1380.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1381.             CURLOPT_CUSTOMREQUEST => "POST",
  1382.             CURLOPT_POSTFIELDS => json_encode($dataList),
  1383.             CURLOPT_HTTPHEADER => array(
  1384.                 "Api-Token: $ApiKey",
  1385.                 "Content-Type: application/json",
  1386.                 "Postman-Token: 41fb5406-d0b7-40e3-b168-2645967314b0",
  1387.                 "cache-control: no-cache"
  1388.             )
  1389.         ));
  1390.         $response curl_exec($curl);
  1391.         $err curl_error($curl);
  1392.         curl_close($curl);
  1393.     }
  1394.     /**
  1395.      * Return link data when required within the link form
  1396.      *
  1397.      * @param  object  Doctrine object
  1398.      *
  1399.      * @return array   Array with config options
  1400.      */
  1401.     public function getLinkData($em$language$container$settings){
  1402.         $questions = [];
  1403.         $forms $em->getRepository('TrinityFormsBundle:Form')->findBy([ 'language' => $language'settings' => $settings ]);
  1404.         foreach($forms as $Form){
  1405.             $q $em->getRepository('TrinityFormsBundle:Question')->findBy([ 'form' => $Form ], ['sort' => 'asc']);
  1406.             foreach($q as $Question){
  1407.                 $questions[$Form->getId()][$Question->getId()] = [
  1408.                     'id' => $Question->getId(),
  1409.                     'title' => $Question->getTitle(),
  1410.                     'type' => $Question->getType(),
  1411.                     'values' => $Question->getValues(),
  1412.                 ];
  1413.             }
  1414.         }
  1415.         return array(
  1416.             'forms' => $forms,
  1417.             'questions' => $questions,
  1418.         );
  1419.     }
  1420.     /**
  1421.      * Show dashboard blocks
  1422.      *
  1423.      * @return array List of blocks
  1424.      */
  1425.     public function dashboardBlocks(){
  1426.         $sessions $this->getDoctrine()->getRepository('TrinityFormsBundle:Session')->findBy(array(
  1427.             'done' => 1
  1428.         ), array(
  1429.             'dateStart' => 'desc'
  1430.         ), 10);
  1431.         $responses '';
  1432.         foreach($sessions as $Session){
  1433.             $responses .= '<tr>
  1434.                 <td style="text-align:left;">' $Session->getForm()->getLabel() . '</td>
  1435.                 <td style="text-align:center;"><a href="' $this->generateUrl('admin_mod_forms_answers', array('id' => $Session->getForm()->getId(), 'answerid' => $Session->getAnswer()->getId())) . '">' $this->time2str($Session->getDateStart()) . '</a></td>
  1436.             </tr>';
  1437.         }
  1438.         return array(
  1439.             array(
  1440.                 'title' => $this->trans('Laatst ingevulde formulieren''cms'),
  1441.                 'class' => '',
  1442.                 'content' => '<table><tr><th style="text-align:left;">'.$this->trans('Formulier''cms').'</th><th style="text-align:center;">'.$this->trans('Datum''cms').'</th></tr>' $responses '</table>'
  1443.             ),
  1444.         );
  1445.     }
  1446.     /**
  1447.      * Generate relative date
  1448.      *
  1449.      * @param  mixed $ts Timestamp or \DateTime object
  1450.      *
  1451.      * @return string    Relative date
  1452.      */
  1453.     private function time2str($ts) {
  1454.         if($ts instanceof \DateTime){
  1455.             $ts $ts->getTimestamp();
  1456.         }
  1457.         if(!ctype_digit($ts)) {
  1458.             $ts strtotime($ts);
  1459.         }
  1460.         $diff time() - $ts;
  1461.         if($diff == 0) {
  1462.             return 'Nu';
  1463.         } elseif($diff 0) {
  1464.             $day_diff floor($diff 86400);
  1465.             if($day_diff == 0) {
  1466.                 if($diff 60) { return $this->trans('Zojuist''cms'); }
  1467.                 if($diff 120) { return $this->trans('1 minuut geleden''cms'); }
  1468.                 if($diff 3600) { return floor($diff 60) . ' ' $this->trans('minuten geleden''cms'); }
  1469.                 if($diff 7200) { return $this->trans('1 uur geleden''cms'); }
  1470.                 if($diff 86400) { return floor($diff 3600) . ' ' $this->trans('uren geleden''cms'); }
  1471.             }
  1472.             if($day_diff == 1) { return $this->trans('Gisteren''cms'); }
  1473.             if($day_diff 7) { return $day_diff ' ' $this->trans('dagen geleden''cms'); }
  1474.             if($day_diff 31) { return ceil($day_diff 7) . ' '$this->trans('weken geleden''cms'); }
  1475.             if($day_diff 60) { return $this->trans('afgelopen maand''cms'); }
  1476.             return date('F Y'$ts);
  1477.         } else {
  1478.             $diff abs($diff);
  1479.             $day_diff floor($diff 86400);
  1480.             if($day_diff == 0) {
  1481.                 if($diff 120) { return $this->trans('Binnen een minuut''cms'); }
  1482.                 if($diff 3600) { return $this->trans('Binnen %time% minuten''cms', ['%time%' => floor($diff 60)]); }
  1483.                 if($diff 7200) { return $this->trans('Binnen een uur''cms'); }
  1484.                 if($diff 86400) { return $this->trans('Binnen %time% uren''cms', ['%time%' => floor($diff 3600)]); }
  1485.             }
  1486.             if($day_diff == 1) { return $this->trans('Morgen''cms'); }
  1487.             if($day_diff 4) { return date('l'$ts); }
  1488.             if($day_diff + (date('w'))) { return $this->trans('Volgende week''cms'); }
  1489.             if(ceil($day_diff 7) < 4) { return $this->trans('Binnen %time% weken''cms', ['%time%' => ceil($day_diff 7)]); }
  1490.             if(date('n'$ts) == date('n') + 1) { return $this->trans('Volgende week''cms'); }
  1491.             return date('F Y'$ts);
  1492.         }
  1493.     }
  1494.     /**
  1495.      * Handle uploaded files
  1496.      *
  1497.      * @Route("/trinity/forms/upload", name="trinity_mod_forms_upload")
  1498.      */
  1499.     public function uploadAction(Request $request){
  1500.         parent::init($request);
  1501.         /*if(count($_FILES) != 1 || !is_array($_FILES) || !isset($_FILES['images-' . $id]) || !is_array($_FILES['images-' . $id])) {
  1502.             $response = new JsonResponse(['error' => 'File parameter count is not 1, or the parameter is empty', 'json' => $_FILES]);
  1503.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST);
  1504.             return $response;
  1505.         }*/
  1506.         if(!empty($_FILES['file'])){
  1507.             $file $_FILES['file'];
  1508.             $uploadedfile = new UploadedFile$file['tmp_name'], $file['name'], $file['type'], (int)$file['error'] );
  1509.             $em $this->getDoctrine()->getManager();
  1510.             $mediadir $this->getDoctrine()->getRepository('CmsBundle:Mediadir')->findPathByName($em, (!empty($this->Settings->getHost()) ? $this->Settings->getHost() . '/' '') .  $this->trans('Forms', [], 'forms') . '/' date('Ymd'), $this->language);
  1511.             $mediafile = new \App\CmsBundle\Entity\Media();
  1512.             $mediafile->setParent($mediadir);
  1513.             $mediafile->setLabel($file['name']);
  1514.             $mediafile->setDateAdd();
  1515.             $mediafile->setFile($uploadedfile);
  1516.             $mediafile->preUpload();
  1517.             $mediafile->upload();
  1518.             $em->persist($mediafile);
  1519.             $em->flush($mediafile);
  1520.             return new JsonResponse([
  1521.                 'status' => true,
  1522.                 'mediaid' => $mediafile->getId(),
  1523.                 'webpath' => $mediafile->getWebpath(),
  1524.             ]);
  1525.         }
  1526.         return new JsonResponse([
  1527.             'status' => false,
  1528.             '_FILES' => (!empty($_FILES) ? $_FILES : []),
  1529.             '_POST' => (!empty($_POST) ? $_POST : []),
  1530.             'error' => 'No file given',
  1531.         ]);
  1532.     }
  1533.     public static function resourcesHandler($Settings, array $bundledatastring $projectDir) : ?string
  1534.     {
  1535.         $resources null;
  1536.         $layoutKey = !empty($Settings->getOverrideKey()) ? trim($Settings->getOverrideKey()) . '/' '';
  1537.         // check if file exists or build array in code and return that.
  1538.         $file __DIR__ "/../Resources/views/default/resources.json";
  1539.         $override $projectDir '/public/custom/' $layoutKey 'blog/resources.json';
  1540.         if (file_exists($override)) {
  1541.             $resources $override;
  1542.         } else if (file_exists($file)) {
  1543.             $resources $file;
  1544.         }
  1545.         return $resources;
  1546.     }
  1547. }