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

232 lines
8.6 KiB
PHP

<?php
include('include/entete.php');
include('include/entete_cap.php');
include('config/config.inc.php');
include('config/lib.inc.php');
if(isset($_POST['action']) && $_POST['action']=='go_en'){
foreach($_POST as $cle=>$val) $$cle=$val;
$maCleDeCryptage = getCleDeCryptage();
$nom_eleve2=crypter($maCleDeCryptage,$nom_eleve);
$prenom_eleve2=crypter($maCleDeCryptage,$prenom_eleve);
$eml_eleve2=crypter($maCleDeCryptage,$eml_eleve);
$tel_eleve2=crypter($maCleDeCryptage,$tel_eleve);
$nom_pro2=crypter($maCleDeCryptage,$nom_pro);
$prenom_pro2=crypter($maCleDeCryptage,$prenom_pro);
$eml_pro2=crypter($maCleDeCryptage,$eml_pro);
$tel_pro2=crypter($maCleDeCryptage,$tel_pro);
$query = 'update equipes set nom_eleve=:nom_eleve,prenom_eleve=:prenom_eleve,eml_eleve=:eml_eleve,tel_eleve=:tel_eleve,nom_pro=:nom_pro,prenom_pro=:prenom_pro,eml_pro=:eml_pro,tel_pro=:tel_pro where num_capitaine=:num_cap';
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':nom_eleve', $nom_eleve2, PDO::PARAM_STR );
$queryRequest->bindParam( ':prenom_eleve', $prenom_eleve2, PDO::PARAM_STR);
$queryRequest->bindParam( ':eml_eleve', $eml_eleve2, PDO::PARAM_STR );
$queryRequest->bindParam( ':tel_eleve', $tel_eleve2, PDO::PARAM_STR);
$queryRequest->bindParam( ':nom_pro', $nom_pro2, PDO::PARAM_STR );
$queryRequest->bindParam( ':prenom_pro', $prenom_pro2, PDO::PARAM_STR );
$queryRequest->bindParam( ':eml_pro', $eml_pro2, PDO::PARAM_STR );
$queryRequest->bindParam( ':tel_pro', $tel_pro2, PDO::PARAM_STR);
$queryRequest->bindParam( ':num_cap', $_SESSION['cap_num'], PDO::PARAM_INT );
$queryRequest->execute();
$id_cap=$db->lastInsertId();
$_SESSION['msg']='Vos saisies ont bien été enregistrées.';
header('location:index-cap.php');
exit();
}
//Modification du profil du capitaine par lui-même
if(isset($_POST['action']) && $_POST['action']=='go_moCap'){
foreach($_POST as $cle=>$val) $$cle=$val;
if(!isset($id_cap) || empty($id_cap) || $_SESSION['cap_num']!=$id_cap){
header('location:index_cap.php');
exit();
}
echo '<pre>';
print_r($_POST);
echo '</pre>';
//Teste si l'item capitaine à modifier existe
$actualEml = '';
$query="select * from capitaines where id_cap=:id_cap and num_eta=:num_eta";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':id_cap', $id_cap, PDO::PARAM_INT );
$queryRequest->bindParam( ':num_eta', $num_eta, PDO::PARAM_INT );
$queryRequest->execute();
if($queryRequest->rowCount()==0){
header('location:index-cap.php');
exit();
}else{
$dataActual=$queryRequest->fetchAll();
$maCleDeCryptage = getCleDeCryptage();
$actualEml = decrypter($maCleDeCryptage,$dataActual[0]['email_cap']);
}
$nom_cap2=crypter($maCleDeCryptage,$nom_cap);
$prenom_cap2=crypter($maCleDeCryptage,$prenom_cap);
$email_cap2=crypter($maCleDeCryptage,$email_cap);
//Teste si l'email correspond déjà à un compte capitaine
$query="select * from capitaines where email_cap=:email_cap and id_cap!=:id_cap";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':email_cap', $email_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':id_cap', $id_cap, PDO::PARAM_INT );
$queryRequest->execute();
$test=$queryRequest->rowCount();
if($test>0){
$_SESSION['msg']='Cet email est déjà enregistré';
header('location:modifier-cap.php');
exit();
}
//Teste si l'email correspond à un compte référent d'établissement
$query="select * from eta where email_ref=:email_cap";
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':email_cap', $email_cap2, PDO::PARAM_STR );
$queryRequest->execute();
$test=$queryRequest->rowCount();
if($test>0){
$_SESSION['msg']='Cet email est déjà enregistré';
header('location:modifier-cap.php');
exit();
}
//envoi des nouveaux paramètres de connexion si l'email du capitaine a été changé
if($actualEml!=$email_cap){
include('config/class.phpmailer.php');
$mdp=Password(8,0);
$to=$email_cap;
$from = 'inscriptions@deciday.fr';
$objet="Votre compte DECIDAY";
$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 !, le référent de votre établissement a créé votre compte d\'accès "Capitaine" pour <b>gérer votre trinôme</b>.</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Vous pouvez : </td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2"> - Renseigner les membres de votre trinôme</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2"> - Accéder à la boite à outils Deciday</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2"> - Organiser votre agenda Deciday</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">Voici vos paramètres de connexion :</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td colspan="2">&nbsp;</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right" width="297">Votre identifiant : </td><td>'.$email_cap.'</td>';
$affich.='</tr>'."\n";
$affich.='<tr>';
$affich.='<td align="right">Votre mot de passe : </td><td>'.$mdp.'</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://www.deciday.fr/connexion-cfa.php" style="color: #FFF;text-decoration: none;text-transform: uppercase; font-family:ARIAL;"><strong>Connectez-vous</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";
$affich.='</table>';
$mail = new PHPMailer();
$mail->From = $from;
$mail->FromName=utf8_decode("DECIDAY");
$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->AddBCC('deciday@fafih.com');
$mail->AltBody = "/-------//--------/";
$mail->send();
$query='update capitaines set nom_cap=:nom_cap, prenom_cap=:prenom_cap, email_cap=:email_cap, mdp_cap=:mdp_cap where id_cap=:id_cap';
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':nom_cap', $nom_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':prenom_cap', $prenom_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':email_cap', $email_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':mdp_cap', md5($mdp), PDO::PARAM_STR );
$queryRequest->bindParam( ':id_cap', $id_cap, PDO::PARAM_INT );
$queryRequest->execute();
//Le Capitaine transmet ses pouvoir à une autre personne. Déconnexion automatique.
header('location:deco.php');
exit();
}else{
$query='update capitaines set nom_cap=:nom_cap, prenom_cap=:prenom_cap, email_cap=:email_cap where id_cap=:id_cap';
$queryRequest = $db->prepare( $query );
$queryRequest->bindParam( ':nom_cap', $nom_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':prenom_cap', $prenom_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':email_cap', $email_cap2, PDO::PARAM_STR );
$queryRequest->bindParam( ':id_cap', $id_cap, PDO::PARAM_INT );
$queryRequest->execute();
}
$_SESSION['msg']='Votre profil de Capitaine a bien été modifié.';
header('location:index-cap.php');
exit();
}
?>