<?php
// src/Controller/SubController.php
namespace App\Controller;
use App\Entity\Prospect;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\FormTypeInterface;
use Swift_Mailer;
use Swift_SmtpTransport;
use Swift_Message;
class SubController extends AbstractController
{
/**
* @Route("/}", name="home")
*/
public function new(Request $request, Swift_Mailer $mailer)
{
$prospect = new Prospect();
//$date = date('d-M-y');
// ...
$form = $this->createFormBuilder($prospect)
->add('nom', TextType::class, array('label' => 'Nom / Prénom','required' => true))
->add('tel', TextType::class, array('label' => 'Tél.','required' => true))
->add('dpt', TextType::class, array('label' => 'Code Postal','required' => true))
/*->add('date', TextType::class, array('label' => 'Adresse','required' => false))
->add('code', TextType::class, array('label' => 'Ville','required' => false))*/
->add('email', TextType::class, array('label' => 'Email','required' => false))
->getForm();
/*$form = $this->createForm(ProspectType::class, $prospect [
'method' => 'GET',
]);*/
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$prospect = $form->getData();
$departement = $prospect->getDpt();
//Tri par dpt
$levasseur = array('29', '22', '56', '35', '44', '49', '53', '72', '61', '14', '50','85', '37', '79','86','36');
$menzoyan = array('07', '26', '38', '73', '74','69');
$fontenay = array('78', '91', '92', '28', '27', '76');
$nord = array('80', '62', '59');
$roulleau = array('77', '60', '02', '08', '51', '10', '89', '52');
$manca = array('55', '54', '57', '88', '68', '90', '70', '25');
$jacquet = array('18', '58', '21', '03', '71', '39', '01', '63', '42', '43', '15');
$debattista = array('30', '84', '13', '83', '04', '06', '05');
$languedoc = array('48', '12', '81', '34', '11', '09', '66', '31');
$fantarella = array('64', '65', '32', '40', '33', '47', '82', '46', '24', '19', '23', '17', '16', '87', '23');
$barbey = array('75');
$thiroux = array('95', '94', '93', '45', '41');
if (in_array($departement, $levasseur)) {
$commercial = array('clevasseur@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-guermeur.html.twig';
}
else if (in_array($departement, $fontenay)) {
$commercial = array('yfontenay@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-bes2.html.twig';
}
else if (in_array($departement, $barbey)) {
$commercial = array('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-barbey.html.twig';
}
else if (in_array($departement, $nord)) {
$commercial = array('cthiroux@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-sergeant.html.twig';
}
else if (in_array($departement, $roulleau)) {
$commercial = array('hroulleau@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-roulleau.html.twig';
}
else if (in_array($departement, $manca)) {
$commercial = array('jpmanca@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-manca.html.twig';
}
else if (in_array($departement, $jacquet)) {
$commercial = array('fjacquet@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-jacquet.html.twig';
}
else if (in_array($departement, $debattista)) {
$commercial = array('ddebattista@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-hinques.html.twig';
}
else if (in_array($departement, $languedoc)) {
$commercial = array('gmenzoyan@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-medina.html.twig';
}
else if (in_array($departement, $fantarella)) {
$commercial = array('dfantarella@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-hurlot.html.twig';
}
else if (in_array($departement, $menzoyan)) {
$commercial = array('gmenzoyan@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-men.html.twig';
}
else if (in_array($departement, $thiroux)) {
$commercial = array('cthiroux@everstyl.fr', 'romain.marchand@variationconfort.fr');
$zdc='soldes-thiroux.html.twig';
}
// Create a message
$message = (new Swift_Message('[Ventes Privees] Nouveau contact'))
->setFrom('contact@ventesprivees-everstyl.fr')
->setTo($commercial)
//->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
->setBody(
$this->renderView('email.html.twig', array(
'nom' => $prospect->getNom(),
'tel' => $prospect->getTel(),
'dpt' => $prospect->getDpt(),
'code' => '',
'date' => '',
'email' => $prospect->getEmail(),
)),
'text/html'
);
// Send the message
if($mailer->send($message)) {
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($prospect);
$entityManager->flush();
return $this->render($zdc, [
'form' => $form->createView(),
]);
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
}
else {
return $this->render($zdc, [
'form' => $form->createView(array('csrf_protection' => false)),
]);
}
}
// Create a message
/*$message = (new Swift_Message('[Catalogue] Nouveau contact'))
->setFrom('contact@ventesprivees-everstyl.fr')
->setTo('romain.marchand@variationconfort.fr')
//->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
->setBody(
$this->renderView('email.html.twig', array(
'nom' => $prospect->getNom(),
'tel' => $prospect->getTel(),
'dpt' => $prospect->getDpt(),
'code' => $prospect->getCode(),
'date' => $prospect->getDate(),
'email' => $prospect->getEmail(),
)),
'text/html'
);
// Send the message
if($mailer->send($message)) {
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($prospect);
$entityManager->flush();
//return $this->redirect('https://www.boutique-everstyl.com');
return $this->render('confirmation-itl.html.twig', [
'form' => $form->createView(),
]);
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
}
else {
return $this->render('home-itl.html.twig', [
'form' => $form->createView(),
]);
}
}*/
return $this->render('home_soldes.html.twig', [
'form' => $form->createView(),
]);
}
/**
*
* @Route("/form_ok", name="form_ok")
*/
public function ValidForm()
{
//return $this->redirect('https://www.boutique-everstyl.com');
return $this->render('confirmation-itl.html.twig', [
'form' => $form->createView(array('csrf_protection' => false)),
]);
}
/**
* Matches /produits exactly
*
* @Route("/produits", name="produits")
*/
public function Soldes(Request $request)
{
return $this->render('base.html.twig');
}
}