<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Cookie;
use mysqli;
use App\Entity\Baskets;
use App\Entity\Masterdata;
use App\Form\BasketsType;
use App\Form\CaptchaType;
use App\Controller\FunctionController;
use App\Service;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Gregwar\Captcha\CaptchaBuilder;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use PHPMailer\PHPMailer\PHPMailer;
use Symfony\Component\Mime\Crypto\DkimSigner;
use Symfony\Component\Mime\Crypto\DkimOptions;
class DioceseController extends AbstractController
{
private $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
// $this->session->clear(); // permet d effacer le contenu de la session
if($this->session) {
$this->session->set('attribut',8);
//dump($this->monPanier);
}
}
// const url ='http://localhost/Diocese/scripts/masterdata.xml';
// const xml = simplexml_load_file($url, 'SimpleXMLElement');
// public const XML_MASTERDATA = simplexml_load_file('http://localhost/Diocese/scripts/masterdata.xml', 'SimpleXMLElement');
/**
* @Route("/diocese", name="diocese")
*/
public function index(): Response
{
$url ='http://localhost/Diocese/scripts/masterdata.xml';
$xml = simplexml_load_file($url, 'SimpleXMLElement');
$captcha = new Captcha ('captcha', CaptchaType::class);
return $this->render('diocese/index.html.twig', [
'controller_name' => 'DioceseController',
'xml' => $xml,'captcha'=>$captcha
]);
}
/**
* @Route("/421_premiere_lecture_dans_l_ancien_testament/code={code}", name="421_premiere_lecture_dans_l_ancien_testament")
*/
public function page421($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$asterisk = "";
$desc = $xmls[3]->N421->description;
$leslectures = $Functions->searchByType(2100,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(2100,$xmls[1],$language,$code);
return $this->render('diocese/421_premiere_lecture_dans_l_ancien_testament.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/422_premiere_lecture_dans_le_nouveau_testament/code={code}", name="422_premiere_lecture_dans_le_nouveau_testament")
*/
public function page422($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$asterisk = "";
$desc = $xmls[3]->N422->description;
$leslectures = $Functions->searchByType(2300,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(2300,$xmls[1],$language,$code);
return $this->render('diocese/422_premiere_lecture_dans_le_nouveau_testament.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/423_deuxieme_lecture_dans_le_livre_des_psaumes/code={code}", name="423_deuxieme_lecture_dans_le_livre_des_psaumes")
*/
public function page423($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$asterisk = "";
$desc = $xmls[3]->N423->description;
$leslectures = $Functions->searchByType(2200,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(2200,$xmls[1],$language,$code);
return $this->render('diocese/423_deuxieme_lecture_dans_le_livre_des_psaumes.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/424_troisieme_lecture_dans_le_livre_des_evangiles/code={code}", name="424_troisieme_lecture_dans_le_livre_des_evangiles")
*/
public function page424($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$asterisk = "";
$desc = $xmls[3]->N424->description;
$leslectures = $Functions->searchByType(2500,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(2500,$xmls[1],$language,$code);
return $this->render('diocese/424_troisieme_lecture_dans_le_livre_des_evangiles.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/425_notre_choix_de_lectures", name="425_notre_choix_de_lectures")
*/
public function page425(Request $request) : Response
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// // Recherche du panier selon l'id session
$panierL = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des lectures existantes
$masterdata = $Functions->search_All_Readings($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata[$i]->id),$panierL)){
unset($masterdata[$i]);
}
}
// Récupérer la partie de la bible correspondante
$Types = $Functions->getPartie($masterdata);
// Récupérer le message de choix des livres
$message = $Functions->msgChoixL($masterdata,$xmls[3]);
// Vérifier les lectures traitant du mariage
$message2 ="";
$compteur = 0;
foreach ($masterdata as $leslectures) {
$compteur += $leslectures->asterisk;
}
if ($compteur >=1){
$message2 = $xmls[3]->NbrAsterisk->Unouplus;
}
else{
$message2 = $xmls[3]->NbrAsterisk->Aucun;
}
$captcha = new Baskets();
$form = $this->createForm(BasketsType::class, $captcha);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
return $this->redirecttoRoute('send_mail',['sessId' => $sessId,'mail' => $_POST['mail']]);
}
return $this->render('diocese/425_notre_choix_de_lectures.html.twig', [
'masterdata'=>$masterdata,'xml4'=>$xmls[3],'message'=>$message,'message2'=>$message2,'navbar'=>$navbar,'form'=>$form->createView(),'sessId'=>$sessId
// 'xml' => $xml,'xml2' => $xml2,'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture
]);
}
/**
* @Route("/430_le_choix_des_prieres", name="430_le_choix_des_prieres")
*/
public function page430()
{
$leslectures = array();
$leslectures2 = array();
$leslectures3 = array();
$leslectures4 = array();
$leslectures5 = array();
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Code par défaut pour chaque type de prière
foreach($xmls[1]->masterdata->Ecrits as $lesEcrits)
{
if($lesEcrits->type == 3100 && $lesEcrits->language == $language){
if (!count($leslectures) >= 1){
$leslectures[] = intval($lesEcrits->code);
}
}
if($lesEcrits->type == 3200 && $lesEcrits->language == $language){
if (!count($leslectures2) >= 1){
$leslectures2[] = intval($lesEcrits->code);
}
}
if($lesEcrits->type == 3310 && $lesEcrits->language == $language){
if (!count($leslectures3) >= 1){
$leslectures3[] = intval($lesEcrits->code);
}
}
if($lesEcrits->type == 3500 && $lesEcrits->language == $language){
if (!count($leslectures4) >= 1){
$leslectures4[] = intval($lesEcrits->code);
}
}
if($lesEcrits->type == 3700 && $lesEcrits->language == $language){
if (!count($leslectures5) >= 1){
$leslectures5[] = intval($lesEcrits->code);
}
}
}
return $this->render('diocese/430_le_choix_des_prieres.html.twig', [
'lecture'=>$leslectures,'lecture2'=>$leslectures2,'lecture3'=>$leslectures3,'lecture4'=>$leslectures4,'lecture5'=>$leslectures5,'navbar'=>$navbar
// 'xml' => $xml,'xml2' => $xml2,'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture
]);
}
/**
* @Route("/431_la_profession_de_foi/code={code}", name="431_la_profession_de_foi")
*/
public function page431($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$desc = $xmls[3]->N431->description;
$leslectures = $Functions->searchByType(3100,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(3100,$xmls[1],$language,$code);
return $this->render('diocese/431_la_profession_de_foi.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/432_le_dialogue_initial/code={code}", name="432_le_dialogue_initial")
*/
public function page432($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$desc = $xmls[3]->N432->description;
$leslectures = $Functions->searchByType(3200,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(3200,$xmls[1],$language,$code);
return $this->render('diocese/432_le_dialogue_initial.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/434_l_echange_des_consentements/code={code}", name="434_l_echange_des_consentements")
*/
public function page434($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$desc = $xmls[3]->N434->description;
$leslectures = $Functions->searchByType(3310,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(3310,$xmls[1],$language,$code);
return $this->render('diocese/434_l_echange_des_consentements.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/437_la_benediction_nuptiale_copyright/code={code}", name="437_la_benediction_nuptiale_copyright")
*/
public function page437($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$desc = $xmls[3]->N437->description;
$leslectures = $Functions->searchByType(3500,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(3500,$xmls[1],$language,$code);
return $this->render('diocese/437_la_benediction_nuptiale_copyright.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/440_la_priere_universelle/code={code}", name="440_la_priere_universelle")
*/
public function page440($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
$desc = $xmls[3]->N440->description;
$leslectures = $Functions->searchByType(3700,$xmls[1],$language,$code);
$laLecture = $Functions->searchOne(3700,$xmls[1],$language,$code);
return $this->render('diocese/440_la_priere_universelle.html.twig', [
'xml' => $xmls[0],'xml2' => $xmls[3],'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'lalecture'=>$laLecture,'navbar'=>$navbar
]);
}
/**
* @Route("/add_to_booklet/code={code}", name="add_to_booklet")
*/
public function add_to_booklet($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Ajouter la lecture/prière au panier
$TypeBasket = $Functions->create_Basket($sessId,$xmls[1],$xmls[0],$code);
if($TypeBasket<3000){
return $this->redirecttoRoute('425_notre_choix_de_lectures');
}
else{
return $this->redirecttoRoute('442_notre_choix_de_prières');
}
}
/**
* @Route("/delete_from_booklet/code={code}", name="delete_from_booklet")
*/
public function delete_from_booklet($code)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Supprimer la lecture/prière du panier
$Functions->delete_Basket($sessId,$xmls[1],$xmls[0],$code);
$TypeBasket = $Functions->delete_Basket($sessId,$xmls[1],$xmls[0],$code);
if($TypeBasket<3000){
return $this->redirecttoRoute('425_notre_choix_de_lectures');
}
else{
return $this->redirecttoRoute('442_notre_choix_de_prières');
}
}
/**
* @Route("/442_notre_choix_de_prieres", name="442_notre_choix_de_prières")
*/
public function page442(Request $request) : Response
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Recherche du panier selon l'id session
$panierP = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des prières existantes
$masterdata = $Functions->search_All_Prayers($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata[$i]->id),$panierP)){
unset($masterdata[$i]);
}
}
// Récupérer la partie de la bible correspondante
$Types = $Functions->getPartie($masterdata);
// Récupérer le message de choix des livres
$message = $Functions->msgChoixP($masterdata,$xmls[3]);
$captcha = new Baskets();
$form = $this->createForm(BasketsType::class, $captcha);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
return $this->redirecttoRoute('send_mail',['sessId' => $sessId,'mail' => $_POST['mail']]);
}
return $this->render('diocese/442_notre_choix_de_prieres.html.twig', [
'masterdata'=>$masterdata,'xml4'=>$xmls[3],'message'=>$message,'sessId'=>$sessId,'navbar'=>$navbar,'form'=>$form->createView(),'sessId'=>$sessId
// 'xml' => $xml,'xml2' => $xml2,'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture
]);
}
/**
* @Route("/print_booklet", name="print_booklet")
*/
public function printbooklet()
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Lectures
// Recherche du panier selon l'id session
$panierL = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des lectures existantes
$masterdata = $Functions->search_All_Readings($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata[$i]->id),$panierL)){
unset($masterdata[$i]);
}
}
// Recupérer les prières
// Recherche du panier selon l'id session
$panierP = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des prières existantes
$masterdata2 = $Functions->search_All_Prayers($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata2);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata2[$i]->id),$panierP)){
unset($masterdata2[$i]);
}
}
return $this->render('diocese/470_le_livret_de_mariage.html.twig', [
'masterdata'=>$masterdata,'xml3'=>$xmls[2],'masterdata2'=>$masterdata2,'sessId'=>$sessId,'navbar'=>$navbar
// 'xml' => $xml,'xml2' => $xml2,'desc' => $desc,'code'=>$code,'lectures'=>$leslectures,'asterisk'=>$asterisk,'lalecture'=>$laLecture
]);
}
/**
* @Route("/download_booklet/sessid={sessId}", name="download_booklet")
*/
public function dlbooklet($sessId)
{
$Functions = new FunctionController();
include(dirname(__FILE__) . '/headerControl.php');
$xmls = $Functions->getAllXML(); // 0 : Baskets 1 : Masterdata 2 : ArbreDecision 3 : ArbreDecisionCopy (Récent)
// Lectures
// Recherche du panier selon l'id session
$panierL = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des lectures existantes
$masterdata = $Functions->search_All_Readings($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata[$i]->id),$panierL)){
unset($masterdata[$i]);
}
}
// Recupérer les prières
// Recherche du panier selon l'id session
$panierP = $Functions->search_Basket($xmls[0],$sessId);
// Récupérer liste d'id des prières existantes
$masterdata2 = $Functions->search_All_Prayers($xmls[1],$language);
// Créer le panier de lectures
$totalmasterdata = count($masterdata2);
for ($i=0; $i <$totalmasterdata; $i++) {
if(!in_array(strval($masterdata2[$i]->id),$panierP)){
unset($masterdata2[$i]);
}
}
$booklet = $Functions->createBooklet($opening,$masterdata,$masterdata2);
header('Content-Description: File Transfer');
// header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($booklet));
// header('Content-Transfer-Encoding: binary');
// header('Expires: 0');
// header('Cache-Control: must-revalidate');
// header('Pragma: public');
header('Content-Length: ' . filesize($booklet));
// ob_clean();
readfile($booklet);
exit;
}
/**
* @Route("/send_mail/sessid={sessId}/mail={mail}", name="send_mail")
*/
public function sendMail($sessId,$mail,MailerInterface $mailer)
{
$ip = $_SERVER['REMOTE_ADDR'];
$sessId = $sessId;
$email = (new TemplatedEMail())
->from('pvm@netwedd.com')
->to($mail)
//->cc('cc@example.com')
//->bcc('bcc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Votre livret de mariage')
->htmlTemplate('diocese/email_template.html.twig')
->context([
'sessId' => $sessId,
'ip' => $ip,
]);
try {
$mailer->send($email);
} catch (TransportExceptionInterface $e) {
// some error prevented the email sending; display an
// error message or try to resend the message
}
return $this->render('diocese/confirmMail.html.twig', [
]);
}
/**
* @Route("/recover_session/sessid={sessId}", name="rec_session")
*/
public function recSession($sessId,Request $request)
{
$response = new Response();
$response->prepare($request);
$response->headers->setCookie(Cookie::create('recovery', $sessId));
$response->send();
return $this->redirecttoRoute('425_notre_choix_de_lectures');
}
}