pv_project/site/sollicitation-actions.php
2025-07-17 10:15:19 +02:00

419 lines
17 KiB
PHP

<?php
include('include/entete.php');
include('config/config.inc.php');
include('config/lib.inc.php');
include('include/agenda.inc.php');
$maCleDeCryptage = getCleDeCryptage();
/************************************************
//SOLLICITATION : RESERVATION
************************************************/
if(isset($_POST['myAction']) && $_POST['myAction']=='agendaForm'){
if(empty($_POST['ncfa']) || empty($_POST['mydate']) || empty($_POST['mycreneau'])){
$_SESSION['msg']='Une erreur a été rencontrée à la réservation du créneau.';
header('location:sollicitation-agenda.php?ncfa=399');
exit();
}
foreach($_POST as $cle=>$val){
$$cle=$val;
//echo $cle.' => '.$val.'<br />';
}
$etaCoLy = crypter($maCleDeCryptage,$etaCoLy);
$nomCoLy = crypter($maCleDeCryptage,$nomCoLy);
$prenomCoLy = crypter($maCleDeCryptage,$prenomCoLy);
$fonctionCoLy = crypter($maCleDeCryptage,$fonctionCoLy);
$telCoLy = crypter($maCleDeCryptage,$telCoLy);
$emlCoLy = crypter($maCleDeCryptage,$emlCoLy);
$adresse1CoLy = crypter($maCleDeCryptage,$adresse1CoLy);
$adresse2CoLy = crypter($maCleDeCryptage,$adresse2CoLy);
$cpCoLy = crypter($maCleDeCryptage,$cpCoLy);
$villeCoLy = crypter($maCleDeCryptage,$villeCoLy);
$commentCoLy = crypter($maCleDeCryptage,$commentCoLy);
if($mycreneau == 'am'){
$creneau1 = 'am1';
$creneau2 = 'am2';
$nomCreneau = "Matin";
}
if($mycreneau == 'pm'){
$creneau1 = 'pm1';
$creneau2 = 'pm2';
$nomCreneau = "Après-midi";
}
//pour tester
/*$mydate = '2019-01-28';
$creneau1 = 'am1';
$creneau2 = 'am2';*/
$db = connect_base();
//Mémorise les infos du CFA par défaut dans le cas où aucun capitaine n'est trouvé
$query="
SELECT * from eta
WHERE id_eta=:num_eta
";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':num_eta', $ncfa, PDO::PARAM_INT );
$queryRequest->execute();
$dataCfa=$queryRequest->fetchAll();
$countCfa = $queryRequest->rowCount();
if($countCfa!=1){ //CFA introuvable
header('location:./');
exit();
}
$emlReferrent = decrypter($maCleDeCryptage,$dataCfa[0]['email_ref']);
$nomEta = decrypter($maCleDeCryptage,$dataCfa[0]['nom_eta']);
$idCapitaine = 0;
$lastAction = 'ref';
//Vérifie si le créneau est libre pour un des jours suivants
$query="
SELECT * FROM capitaines
INNER JOIN eta ON id_eta=num_eta
INNER JOIN agenda ON id_cap = numCap
WHERE id_eta=:id_eta
AND jour=:jour AND (creneau=:creneau1 || creneau=:creneau2)
AND numCoLy=0 AND statut='libre'
ORDER BY id_cap";
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':id_eta', $ncfa, PDO::PARAM_INT );
$queryRequest->bindParam( ':jour', $mydate, PDO::PARAM_STR );
$queryRequest->bindParam( ':creneau1', $creneau1, PDO::PARAM_STR );
$queryRequest->bindParam( ':creneau2', $creneau2, PDO::PARAM_STR );
$queryRequest->execute();
$count = $queryRequest->rowCount();
if($count>0){
$data=$queryRequest->fetchAll();
$emlCapitaine = decrypter($maCleDeCryptage,$data[0]['email_cap']);
$idCapitaine = $data[0]['id_cap'];
$lastAction = 'cap';
}
//echo $emlCapitaine;echo $emlReferrent;exit();
$dateCreate = date('Y-m-d');
$provenance = 'sollicitation';
if(!empty($ncfa)){
//Insertion de l'établissement
$query="
INSERT INTO sollicitations (etaCoLy, nomCoLy, prenomCoLy, fonctionCoLy, telCoLy, emlCoLy, adresse1CoLy, adresse2CoLy, cpCoLy, villeCoLy, nbClasses, nbEleves, commentCoLy, dateCreate, chxNumEta, provenance, chxJour, chxCreneau, idCapitaine, lastAction)
VALUES (:etaCoLy, :nomCoLy, :prenomCoLy, :fonctionCoLy, :telCoLy, :emlCoLy, :adresse1CoLy, :adresse2CoLy, :cpCoLy, :villeCoLy, :nbClasses, :nbEleves, :commentCoLy, :dateCreate, :chxNumEta, :provenance, :chxJour, :chxCreneau, :idCapitaine, :lastAction)";
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':etaCoLy', $etaCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':nomCoLy', $nomCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':prenomCoLy', $prenomCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':fonctionCoLy', $fonctionCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':telCoLy', $telCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':emlCoLy', $emlCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':adresse1CoLy', $adresse1CoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':adresse2CoLy', $adresse2CoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':cpCoLy', $cpCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':villeCoLy', $villeCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':nbClasses', $nbClasses, PDO::PARAM_INT );
$queryRequest->bindParam( ':nbEleves', $nbEleves, PDO::PARAM_INT );
$queryRequest->bindParam( ':commentCoLy', $commentCoLy, PDO::PARAM_STR );
$queryRequest->bindParam( ':dateCreate', $dateCreate, PDO::PARAM_STR );
$queryRequest->bindParam( ':chxNumEta', $ncfa, PDO::PARAM_INT );
$queryRequest->bindParam( ':provenance', $provenance, PDO::PARAM_INT );
$queryRequest->bindParam( ':chxJour', $mydate, PDO::PARAM_INT );
$queryRequest->bindParam( ':chxCreneau', $mycreneau, PDO::PARAM_INT );
$queryRequest->bindParam( ':idCapitaine', $idCapitaine, PDO::PARAM_INT );
$queryRequest->bindParam( ':lastAction', $lastAction, PDO::PARAM_INT );
$queryRequest->execute();
//Envoi d'un email au capitaine ou référrent
require 'config/class.phpmailer.php';
$mail = new PHPMailer;
// Configuration du SMTP
$mail->IsSMTP();
$mail->Host = 'smtp-in.oximailing.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'BNCx6kLkQZxXYRAZrYVw';
$mail->Password = 'xoSAgSV6MrP568KqC3FM';
$mail->SMTPSecure ='tls';
// Entête de l'email
$mail->From = 'inscriptions@deciday.fr';
$mail->FromName = utf8_decode("DECIDAY!");
if(!empty($emlCapitaine)) $to=$emlCapitaine; else $to=$emlReferrent;
$objet="Nouvelle sollicitation DECIDAY !";
$adresseCL = $_POST['adresse1CoLy'];
if(!empty($adresse1CoLy)) $adresseCL .= '<br />'.$_POST['adresse2CoLy'];
$adresseCL .= '<br />'.$_POST['cpCoLy'].' '.$_POST['villeCoLy'];
$affich='';
$affich.='<table cellpadding="3" style="font-family:ARIAL; width:600px;">';
$affich.='<tr>';
$affich.='<td colspan="2"><img src="" /></td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2"><img src="cid:bando" alt="" width="600" height="150" border="0" /></td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Bonjour,</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Dans le cadre de l\'évènement Déciday !, une sollicitation a été effectuée par un établissement pour la venue d\'un trinôme au sein de ses locaux.</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Récapitulatif de la sollicitation : </td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Jour : </b></td><td>'.MysqlToDateFr($mydate).'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Créneau : </b></td><td>'.$nomCreneau.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Etablissement demandeur : </b></td><td>'.$_POST['etaCoLy'].'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Adresse : </b></td><td>'.$adresseCL.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Nom : </b></td><td>'.$_POST['prenomCoLy'].' '.mb_strtoupper($_POST['nomCoLy']).'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Fonction : </b></td><td>'.$_POST['fonctionCoLy'].'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Téléphone : </b></td><td>'.$_POST['telCoLy'].'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>email : </b></td><td>'.$_POST['emlCoLy'].'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Commentaires : </b></td><td>'.nl2br($_POST['commentCoLy']).'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Nombre de classes : </b></td><td>'.$nbClasses.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Nombre d\'élèves : </b></td><td>'.$nbEleves.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right"><b>Etablissement demandé : </b></td><td>'.$nomEta.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2"><b>Vous pouvez traiter vos sollicitations en vous connectant sur votre espace.</b></td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2" align="center"><table style="width:200px;background-color: #674B64;border: 1px solid #371B34;padding: 4px 6px;"><tr><td align="center"><a href="http://deciday.fr/connexion-cfa.php" style="color: #FFF;text-decoration: none;text-transform: uppercase; font-family:ARIAL;"><strong>Me connecter <br />sur Deciday !</strong></a></td></tr></table></td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Cordialement.</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">L\'équipe DECIDAY.</td>';
$affich.='</tr>'."\n";
echo $affich.='</table>';
$mail->IsHTML(true);
$mail->AddEmbeddedImage('images/bandeau-contact.jpg', 'bando', 'bandeau-contact.jpg');
$mail->Subject = utf8_decode($objet);
$mail->Body = utf8_decode($affich);
$mail->AddAddress($to);
$mail->AltBody = "/-------//--------/";
$mail->send();
/* copie de controle*/
$mail2 = new PHPMailer;
// Configuration du SMTP
$mail2->IsSMTP();
$mail2->Host = 'smtp-in.oximailing.com';
$mail2->Port = 587;
$mail2->SMTPAuth = true;
$mail2->Username = 'BNCx6kLkQZxXYRAZrYVw';
$mail2->Password = 'xoSAgSV6MrP568KqC3FM';
$mail2->SMTPSecure ='tls';
// Entête de l'email
$mail2->From = 'inscriptions@deciday.fr';
$mail2->FromName = utf8_decode("DECIDAY!");
$affich2 = $affich.$to;
$mail2->IsHTML(true);
$mail2->AddEmbeddedImage('images/bandeau-contact.jpg', 'bando', 'bandeau-contact.jpg');
$mail2->Subject = utf8_decode($objet);
$mail2->Body = utf8_decode($affich2);
$mail2->AddAddress('s.descamps@fafih.com');
$mail2->AddBCC('tech@pointvirgule.net');
$mail2->AltBody = "/-------//--------/";
$mail2->send();
/* confirmation enseignant*/
$mail3 = new PHPMailer;
// Configuration du SMTP
$mail3->IsSMTP();
$mail3->Host = 'smtp-in.oximailing.com';
$mail3->Port = 587;
$mail3->SMTPAuth = true;
$mail3->Username = 'BNCx6kLkQZxXYRAZrYVw';
$mail3->Password = 'xoSAgSV6MrP568KqC3FM';
$mail3->SMTPSecure ='tls';
// Entête de l'email
$mail3->From = 'inscriptions@deciday.fr';
$mail3->FromName = utf8_decode("DECIDAY!");
$affich3='';
$objet2="Votre sollicitation DECIDAY !";
$affich3.='<table cellpadding="3" style="font-family:ARIAL; width:600px;">';
$affich3.='<tr>';
$affich3.='<td colspan="2"><img src="" /></td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2"><img src="cid:bando" alt="" width="600" height="150" border="0" /></td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">Bonjour,</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">Votre sollicitation a bien été transmise.</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">Récapitulatif de votre sollicitation : </td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td align="right"><b>Jour : </b></td><td>'.MysqlToDateFr($mydate).'</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td align="right"><b>Créneau : </b></td><td>'.$nomCreneau.'</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td align="right"><b>Etablissement demandé : </b></td><td>'.$nomEta.'</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2"><b>Nous vous remercions pour votre participation à Deciday! Un kit pédagogique est à votre disposition pour préparer votre classe à la venue du trinôme.</b></td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<tr>';
$affich3.='<td colspan="2"><b>Veuillez trouver ci-dessous les liens de téléchargement du kit pédagogique.</b></td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">';
$tFilesBao = listFilesBao('kitPedago');
foreach($tFilesBao as $k=>$v){
$affich3 .= '<a href="http://deciday.fr/boite-outils/'.$v['file'].'" target="_blank">'.$v['title'].'</a><br />';
}
$affich3.='</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">Cordialement.</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">&nbsp;</td>';
$affich3.='</tr>'."\n";
$affich3.='<tr>';
$affich3.='<td colspan="2">L\'équipe DECIDAY.</td>';
$affich3.='</tr>'."\n";
$affich3.='</table>';
$to = $_POST['emlCoLy'];
$mail3->IsHTML(true);
$mail3->AddEmbeddedImage('images/bandeau-contact.jpg', 'bando', 'bandeau-contact.jpg');
$mail3->Subject = utf8_decode($objet2);
$mail3->Body = utf8_decode($affich3);
$mail3->AddAddress($to);
$mail3->AltBody = "/-------//--------/";
$mail3->send();
$_SESSION['msg']='Votre sollicitation a bien été transmise.';
}else{
$_SESSION['msg']='Le créneau n\'a pas pu être réservé car il n\'est pas disponible.';
}
header('location:index.php');
exit();
}
header('location:index.php?err=1');
exit();
?>