src/Controller/SiteController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\ClassTheatre\asides;
  4. use App\ClassTheatre\TheatreController;
  5. use App\Service\TheatreMail\SendmailTheatre;
  6. use App\Validator\Recaptcha;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Psr\Log\LoggerInterface;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\FormType;
  12. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormFactoryInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. use TheatreCore\Entity\Contacts;
  22. use TheatreCore\Entity\Extranetusers;
  23. use TheatreCore\Form\Type\RecaptchaType;
  24. class SiteController extends TheatreController
  25. {
  26.     public function __construct(EntityManagerInterface $emTranslatorInterface $translatorTokenStorageInterface $tokenStorage)
  27.     {
  28.         // surbrillance du menu principal (thnet)
  29.         $GLOBALS['rub_courante'] = 'spectacles';
  30.         parent::__construct($translator$tokenStorage);
  31.         $this->em $em;
  32.         $this->asides = new asides();
  33.     }
  34.     /**
  35.      * @Route("/site/donnees-personnelles", name="site_donnees_personnelles")
  36.      */
  37.     public function donnees_personnelles()
  38.     {
  39.         // situation
  40.         $this->view->locate = array(=> 'Données personnelles');
  41.         // title page
  42.         $this->view->title_page 'Données personnelles sur theatre-contemporain.net';
  43.         return $this->view('site/donnees-personnelles.html.twig');
  44.     }
  45.     /**
  46.      * @Route("/site/cgv", name="site_cgv")
  47.      */
  48.     public function cgv()
  49.     {
  50.         // situation
  51.         $this->view->locate = array(=> 'Conditions Générales de Ventes');
  52.         // title page
  53.         $this->view->title_page 'CGV de theatre-contemporain.net';
  54.         return $this->view('site/cgv.html.twig');
  55.     }
  56.     /**
  57.      * @Route("/site/cgu", name="site_cgu")
  58.      */
  59.     public function cgu()
  60.     {
  61.         // situation
  62.         $this->view->locate = array(=> 'Conditions Générales d\'Utilisation');
  63.         // title page
  64.         $this->view->title_page 'CGU de theatre-contemporain.net';
  65.         return $this->view('site/cgu.html.twig');
  66.     }
  67.     /**
  68.      * @Route("/site/mentions-legales", name="site_mentions_legales")
  69.      */
  70.     public function mentions_legales()
  71.     {
  72.         // situation
  73.         $this->view->locate = array(=> 'Mentions légales');
  74.         // title page
  75.         $this->view->title_page 'Mentions légales de theatre-contemporain.net';
  76.         return $this->view('site/mentions-legales.html.twig');
  77.     }
  78.     /**
  79.      * @Route("/site/ressources", name="site_ressources")
  80.      */
  81.     public function ressources()
  82.     {
  83.         // situation
  84.         $this->view->locate = array(=> 'Statistiques du site');
  85.         // title page
  86.         $this->view->title_page 'Ressources du site';
  87.         return $this->view('site/ressources.html.twig');
  88.     }
  89.     /**
  90.      * @Route("/site/opendata", name="site_opendata")
  91.      */
  92.     public function opendata()
  93.     {
  94.         return $this->redirectToRoute('index', [], Response::HTTP_MOVED_PERMANENTLY);
  95.     }
  96.     /**
  97.      * @Route("/site/publicite", name="site_publicite")
  98.      */
  99.     public function publicite()
  100.     {
  101.         return $this->redirectToRoute('index', [], Response::HTTP_MOVED_PERMANENTLY);
  102.     }
  103.     /**
  104.      * @Route("/site/devenir-partenaire-ecole", name="site_devenir_partenaire_ecole")
  105.      */
  106.     public function devenir_partenaire_ecole()
  107.     {
  108.         return $this->redirectToRoute('index', [], Response::HTTP_MOVED_PERMANENTLY);
  109.     }
  110.     /**
  111.      * @Route("/site/devenir-partenaire", name="site_devenir_partenaire")
  112.      */
  113.     public function devenir_partenaire()
  114.     {
  115.         return $this->redirectToRoute('index', [], Response::HTTP_MOVED_PERMANENTLY);
  116.     }
  117.     /**
  118.      * @Route("/site/recherche", name="site_recherche")
  119.      */
  120.     public function recherche()
  121.     {
  122.         $websites = array(
  123.             'www.theatre-contemporain.net'  => array('label' => 'theatre-contemporain.net''module' => 'thnet'),
  124.             'www.theatre-video.net'   => array('label' => 'theatre-video.net''module' => 'thtv'),
  125.             'www.ressources-theatre.net'    => array('label' => 'ressources-theatre.net''module' => 'cris''only_for_modules' => array('cris')),
  126.             ''                              => array('label' => 'Web''module' => ''),
  127.         );
  128.         $code_google '<form method="get" action="/site/recherche" id="masterform">
  129.             <div><input type="text" name="q" size="31" maxlength="255" value="" />
  130.             <input type="submit" name="sa" value="Rechercher" class="boutform" /></div>
  131.             <ul>';
  132.         foreach($websites as $k => $v) {
  133.             if (!empty($v['only_for_modules']) && !in_array($this->context['module'], $v['only_for_modules'])) continue;
  134.             $code_google .= '<li><input type="radio" name="sitesearch" value="'.$k.'"';
  135.             if($this->context['module']==$v['module']) {
  136.                 $code_google .= 'checked="checked" ';
  137.             }
  138.             $code_google .= '/>'.$v['label'].'</li>';
  139.         }
  140.         $code_google .= '
  141.             </ul>
  142.             <div class="spacer" style="padding-top: 20px;"><input type="hidden" name="domains" value="www.theatre-contemporain.net;www.theatre-video.net"></input>
  143.             <input type="hidden" name="client" value="pub-1414152220322472"></input>
  144.             <input type="hidden" name="forid" value="1"></input>
  145.             <input type="hidden" name="ie" value="utf8"></input>
  146.             <input type="hidden" name="oe" value="utf8"></input>
  147.             <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11"></input>
  148.             <input type="hidden" name="hl" value="fr"></input>
  149.             <a href="http://www.google.com/"><img src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" /></a></div>
  150.         </form>';
  151.         $this->context['view']->code_google $code_google;
  152.         // situation
  153.         $this->view->locate = array(=> 'Rechercher sur le site');
  154.         // title page
  155.         $this->view->title_page 'Recherche sur theatre-contemporain.net';
  156.         return $this->view('site/recherche.html.twig');
  157.     }
  158.     /**
  159.      * @Route("/site/contacts", name="site_contacts")
  160.      */
  161.     public function action_contacts(
  162.         Request  $request,
  163.         SendmailTheatre $sendmailTheatre,
  164.         LoggerInterface $logger,
  165.         FormFactoryInterface $formFactory,
  166.         ParameterBagInterface $parameterBag
  167.     )
  168.     {
  169.         $form $formFactory->createNamedBuilder(''FormType::class, null, [
  170.             'validation_groups' => false,
  171.             'attr' => [
  172.                 'id' => 'masterform'
  173.             ]
  174.         ]);
  175.         $form->add('email'TextType::class, [
  176.             'label' => 'Votre adresse de courriel',
  177.             'attr' => [
  178.                 'size'=>'45'
  179.             ]
  180.         ]);
  181.         $form->add'nom'TextType::class, [
  182.             'label' => 'Votre nom',
  183.             'attr' => [
  184.                 'size'=>'30'
  185.             ]
  186.         ]);
  187.         $form->add('sujet'TextType::class, [
  188.             'label'  => 'Sujet de votre message',
  189.             'attr' => [
  190.                 'size'=>'40'
  191.             ]
  192.         ]);
  193.         $form->add('message'TextareaType::class, [
  194.             'label' => 'Votre message',
  195.             'attr' => [
  196.                 'cols'=>'90',
  197.                 'rows'=>'10'
  198.             ]
  199.         ]);
  200.         // captcha si pas loggué
  201.         if($_ENV['CAPTCHA_ACTIVE'] && !$this->getUser() instanceof Extranetusers) {
  202.             $form->add('recaptcha'RecaptchaType::class, [
  203.                 'mapped' => false,
  204.                 'empty_data' => '1',
  205.                 'constraints' => [
  206.                     new Recaptcha([
  207.                         'request' => $request
  208.                     ])
  209.                 ]
  210.             ]);
  211.         } else if($this->getUser() instanceof Extranetusers) {
  212.             // remplir l'adresse de courriel
  213.             $form->get('email')->setData($this->getUser()->getEmail());
  214.             $form->get('nom')->setData($this->getUser()->getLastname());
  215.         }
  216.         $form->add('envoyer'SubmitType::class, [
  217.             'label' => 'Envoyer votre message',
  218.             'attr' => [
  219.                 'class'=>'boutform'
  220.             ]
  221.         ]);
  222. //        $form->addRule('email', 'Votre adresse de courriel : veuillez préciser votre adresse de courriel', 'required');
  223. //        $form->addRule('email', 'Votre adresse de courriel : veuillez verifier votre adresse de courriel', 'email');
  224. //
  225. //        $form->addRule('contact', 'Votre contact : veuillez préciser la personne à contacter', 'numeric');
  226. //        $form->addRule('message', 'Votre message : veuillez préciser votre message', 'required');
  227. //        $form->addRule('sujet', 'Sujet : veuillez préciser le sujet de votre message', 'required');
  228. //        $form->addRule('sujet', 'Sujet : le sujet ne doit pas faire plus de 100 caractères', 'rangelength', array(2,100));
  229. //        $form->addRule('nom', 'Votre nom : veuillez préciser votre adresse nom', 'required');
  230. //        $form->addRule('nom', 'Votre nom : le nom ne doit pas faire plus de 100 caractères', 'rangelength',array(2,100));
  231.         // cacher le texte du haut
  232.         if(isset($_POST['envoyer'])) {
  233.             $this->view->ispost true;
  234.         }
  235.         $this->context['form'] = $form->getForm();
  236.         $this->context['form']->handleRequest($request);
  237.         if ($this->context['form']->isSubmitted() && $this->context['form']->isValid())
  238.         {
  239.             // destinataire
  240.             $sendmailTheatre->setDestinataire($parameterBag->get('mail.contact'));
  241.             // expediteur et return-path
  242.             $sendmailTheatre->setExpediteur($parameterBag->get('mail.contact'));
  243.             // répondre à
  244.             $replyTo =$this->context['form']->get('email')->getData();
  245.             $sendmailTheatre->setReplyTo($replyTo);
  246.             // sujet de l'e-mail
  247.             $subject $this->context['form']->get('sujet')->getData();
  248.             $sendmailTheatre->setSubject(utf8_decode($subject));
  249.             $nom $this->context['form']->get('nom')->getData();
  250.             if($this->getUser() instanceof Extranetusers) {
  251.                 $utilisateur ' [<a href="'.getenv('URL_BACKEND').'/extranetusers/edit/id/'.$this->getUser()->getIdextranetuser().'">'.$this->getUser()->getLogin().' / '.$this->getUser()->getIdextranetuser().'</a>]';
  252.             } else {
  253.                 $utilisateur null;
  254.             }
  255.             $params_tr = [
  256.                 'site' => 'theatre-contemporain.net',
  257.                 'nom' => $nom.$utilisateur,
  258.                 'email' => $this->context['form']->get('email')->getData(),
  259.                 'page_envoi' => $GLOBALS['url_module'].'/site/contacts',
  260.                 'message' => $this->context['form']->get('message')->getData(),
  261.                 'user_agent' => $_SERVER['REMOTE_ADDR'].' / '.$_SERVER['HTTP_USER_AGENT']
  262.             ];
  263.             // génération
  264.             $sendmailTheatre->prepare(
  265.                 'emails/message_site_contact.html.twig',
  266.                 $params_tr
  267.             );
  268.             try {
  269.                 $sendmailTheatre->send();
  270.                 $this->view->reponse['ok'] = $this->context['tr']->trans('reponse_generique_sendmessage');
  271.                 $this->view->hideform true;
  272.             } catch (\Exception $e) {
  273.                 $logger->error($e->getMessage());
  274.                 $logger->debug($e->getTraceAsString());
  275.                 $this->view->error['no'] = $this->context['tr']->trans('error_generique_sendmessage');
  276.             }
  277.         }
  278.         // situation
  279.         $this->context['view']->locate = array(=> 'Contacts');
  280.         // title page
  281.         $this->context['view']->title_page 'Contactez l\'équipe';
  282.         return $this->view('site/contacts.html.twig', [
  283.             'form' => $this->context['form']->createView()
  284.         ]);
  285.     }
  286. }