File: /home/f/r/e/frenchy/refonte2023/wordpress/evenements/paiement.php
<?php
require_once("_mysql.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'admin/PHPMailer/src/Exception.php';
require 'admin/PHPMailer/src/PHPMailer.php';
require 'admin/PHPMailer/src/SMTP.php';
setlocale (LC_TIME, 'fr_FR.utf8','fra');
if (isset($_POST['email']) && $_POST['email'] != "")
{
die("Robot");
}
if (isset($_POST['id_evenement']))
{
$id_evenement = $_POST['id_evenement'];
$req = mysqli_query($link_bdd, "select * from evenements where id_evenement = ".$id_evenement." and date_debut_evenement <= '".date("Y-m-d")."' and date_fin_evenement >= '".date("Y-m-d")."'");
if (mysqli_num_rows($req) != 0)
{
$line = mysqli_fetch_array($req);
}
else
{
die ("Aucun evenement ne correspond");
}
}
else
{
die ("Aucun evenement ne correspond");
}
if (isset($_POST['envoiForm']))
{
$type_paiement = 'NON PAYE PAYPAL';
if ($_POST['type_paiement'] == 'CHEQUE')
{
$type_paiement = 'CHEQUE';
}
if ($_POST['type_paiement'] == 'AUCUN')
{
$type_paiement = 'AUCUN';
}
$montant = $line['prix_membre'];
$membre_contact = 'N/A';
$devenu_membre = "";
$montant_cotisation = 0;
if (isset($_POST['membre_contact']))
{
if ($_POST['membre_contact'] == 'O')
{
$montant = $line['prix_membre'];
$membre_contact = 'OUI';
}
else
{
if (isset($_POST['proposer_cotisation']) && $line['proposition_cotisation'] == 'oui')
{
$montant = $line['prix_membre'];
$membre_contact = 'OUI';
$reqCotisation = mysqli_query($link_bdd, "select * from inscriptions where lower(libelle_inscription) like ('%membre actif%')");
if (mysqli_num_rows($reqCotisation) > 0 && $reqCotisation)
{
$lineCotisation = mysqli_fetch_assoc($reqCotisation);
$montant_cotisation = $lineCotisation['montant_inscription'];
}
$devenu_membre = "oui";
}
else
{
$montant = $line['prix_non_membre'];
$membre_contact = 'NON';
$devenu_membre = "non";
}
}
}
$montant = $montant + $montant_cotisation;
mysqli_query($link_bdd, "INSERT INTO `contacts` ( `civilite_contact`, `prenom_contact`, `particule_contact`, `nom_contact`, `fonction_contact`, `entreprise_contact`, `telephone_contact`, `portable_contact`, `email_contact`, `adresse_entreprise_contact`, `code_postal_entreprise_contact`, `ville_entreprise_contact`, `membre_contact`, `id_evenement`, `montant_paiement`, `top_paiement`, `devenu_membre`) VALUES
( '".mysqli_real_escape_string($link_bdd, $_POST['civilite_contact'])."', '".mysqli_real_escape_string($link_bdd, $_POST['prenom_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['particule_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['nom_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['fonction_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['entreprise_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['telephone_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['portable_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['email_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['adresse_entreprise_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['code_postal_entreprise_contact'])."','".mysqli_real_escape_string($link_bdd, $_POST['ville_entreprise_contact'])."','".mysqli_real_escape_string($link_bdd, $membre_contact)."',".$id_evenement.",'".mysqli_real_escape_string($link_bdd, $montant)."','".$type_paiement."','".$devenu_membre."')");
$id_contact = mysqli_insert_id($link_bdd);
// Gestion email Cheque
if ($type_paiement =='CHEQUE' || $type_paiement =='AUCUN')
{
// On envoi un mail
$subject = "Confirmation inscription : ".html_entity_decode($line['libelle_evenement'])." du ". date_en2fr($line['date_evenement']);
$fd = fopen("mailconfirmation.htm", "r");
$message = fread($fd, filesize('mailconfirmation.htm'));
fclose($fd);
if ($montant !=0)
{
$ligne1= "<td width='50%'>".$line['libelle_evenement']."</td><td width='50%'>".number_format($montant-$montant_cotisation, 2, ',', ' ')."€</td>";
if ($montant_cotisation > 0)
{
$ligne2= "<td width='50%'>Adhésion à la French-American Foundation - France</td><td width='50%'>".number_format($montant_cotisation, 2, ',', ' ')."€</td>";
}
else
{
$ligne2= "<td width='50%'> </td><td width='50%'> </td>";
}
$ligne3= "<td width='50%'><b>Total réglé</b></td><td width='50%'><b>".number_format($montant, 2, ',', ' ')."€</b></td>";
$message = str_replace("%LIGNEPAIEMENT%", "Merci d'envoyer votre règlement par chèque libellé à l'ordre de la French-American Foundation - France, 18 bis boulevard Arago, 75013 Paris.", $message);
$message = str_replace("%MESSAGE1%", "Celle-ci sera confirmée dès réception de votre règlement.", $message);
}
else
{
$ligne1= "<td width='50%'>".$line['libelle_evenement']."</td><td width='50%'>Gratuit</td>";
$ligne2= "<td width='50%'> </td><td width='50%'> </td>";
$ligne3= "<td width='50%'><b>Total réglé</b></td><td width='50%'><b>Gratuit</b></td>";
$message = str_replace("%LIGNEPAIEMENT%", "", $message);
$message = str_replace("%MESSAGE1%", "", $message);
}
$message = str_replace("%DATEEVENEMENT%", date_en2fr($line['date_evenement']), $message);
$message = str_replace("%LIGNE1%", $ligne1, $message);
$message = str_replace("%LIGNE2%", $ligne2, $message);
$message = str_replace("%LIGNE3%", $ligne3, $message);
$message = str_replace("%LIBELLEEVENEMENT%", $line['libelle_evenement'], $message);
if ($_POST['particule_contact'] == "")
{
$message = str_replace("%ENTETENOM%", stripcslashes($_POST['civilite_contact'] . " " . $_POST['prenom_contact'] . " " . $_POST['nom_contact']), $message);
}
else
{
$message = str_replace("%ENTETENOM%", stripcslashes($_POST['civilite_contact'] . " " . $_POST['prenom_contact'] . " " . $_POST['particule_contact'] . " " . $_POST['nom_contact']), $message);
}
// Envoi de la copie du pdf
$reqContact = mysqli_query($link_bdd, "select * from contacts where id_contact=".$id_contact);
$lineContact = mysqli_fetch_array($reqContact);
$type_paiement = 'CHEQUE';
$designation = utf8_decode(html_entity_decode($line['libelle_evenement']))." du ". date_en2fr($line['date_evenement']);
require_once("admin/pdf/genepdf.php");
// PHP Mailer
$mail = new PHPmailer();
$mail->IsSMTP(); // send via SMTP
$mail->Mailer = "smtp"; // Mode d'acces
$mail->Host = "smtp.office365.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentification
$mail->Username = "sendmail@french-american.org"; // SMTP username
$mail->Password = "SE4848+1"; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Sender = "contact@french-american.org";
$mail->From="contact@french-american.org";
$mail->FromName="French-american.org";
$mail->AddReplyTo("contact@french-american.org");
if ($membre_contact == 'NON')
{
$message = str_replace("%MESSAGE2%", "<p>Nous avons bien noté que vous n'êtiez pas membre de la French-American Foundation - France et nous vous invitons à remplir le bulletin d'adhésion qui se trouve en pièce jointe de ce message.</p><br />", $message);
$mail->AddAttachment("France_Adhesion_indiv 2020.pdf");
}
else
{
$message = str_replace("%MESSAGE2%", "", $message);
}
if($montant > 0)
$mail->AddAttachment("admin/pdf/factures/".$nompdf);
$mail->Subject=utf8_decode($subject);
$mail->Body=utf8_decode($message);
$mail->ClearAddresses();
$mail->AddAddress($_POST['email_contact']);
if ($line['confirmation'] != 'non')
{
$mail->Send();
}
if ($montant !=0)
{
// PHP Mailer
$mail2 = new PHPmailer();
$mail2->IsSMTP(); // send via SMTP
$mail2->Mailer = "smtp"; // Mode d'acces
$mail2->Host = "smtp.office365.com"; // SMTP servers
$mail2->SMTPAuth = true; // turn on SMTP authentification
$mail2->Username = "sendmail@french-american.org"; // SMTP username
$mail2->Password = "SE4848+1"; // SMTP password
$mail2->SMTPSecure = 'tls';
$mail2->Port = 587;
$mail2->IsHTML(true);
$mail2->Sender = "contact@french-american.org";
$mail2->From="contact@french-american.org";
$mail2->FromName="French-american.org";
$mail2->AddReplyTo("contact@french-american.org");
if($montant > 0)
$mail2->AddAttachment("admin/pdf/factures/".$nompdf);
$mail2->Subject='Commande par Cheque Formulaire French American Foundation';
$mail2->Body=utf8_decode($message);
$mail2->ClearAddresses();
$mail2->AddAddress('rozenn.jouannigot@french-american.org');
$mail2->AddAddress('rim.hammami@french-american.org');
//$mail2->AddAddress('stephane.didier@live.fr');
$mail2->Send();
@unlink("admin/pdf/factures/".$nompdf);
}
header('location:http://www.french-american.org/evenements/merci.php?id_evenement='.$id_evenement);
}
}
if ($id_evenement == '')
{
die ("Aucun evenement ne correspond");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type"/>
<title>Evenement <?=$line['libelle_evenement']?> - Merci de votre inscription</title>
<style type="text/css">
/* General styles */
body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: #FFF; }
a:hover{
color:#0172b6;
}
a{
color:#0172b6;
}
a:visited{
color:#0172b6;
}
h2 { margin: 0px; padding: 10px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 200%; font-weight: normal; color: #FFF; background-color: #CCC; border-bottom: #BBB 2px solid; }
/* Form styles */
div.form-container {margin: auto; padding: 5px;}
p.legend { margin-bottom: 1em; }
p.legend em { color: #C00; font-style: normal; }
div.form-container form p { margin: 0; }
div.form-container form p.note { margin-left: 170px; font-size: 90%; color: #333; }
div.form-container form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; }
div.form-container form legend { font-weight: bold; color: #666; }
div.form-container form fieldset div { padding: 0.25em 0; }
div.form-container label,
div.form-container span.label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; }
div.form-container label em,
div.form-container span.label em { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; }
div.form-container input:focus,
div.form-container textarea:focus { background-color: #FFC; border-color: #FC6; }
div.form-container div.controlset label,
div.form-container div.controlset input { display: inline; float: none; }
div.form-container div.controlset div { margin-left: 170px; }
div.form-container div.buttonrow { margin: auto; text-align:center;}
#divAdhesion { margin: auto; text-align:center; border-width:2px; border-style:solid; border-color:#000000;}
#messageNonMembre { text-align:center; font-size: 12px; font-weight: bold;color:#FF0000;}
#checkboxMembre { font-size: 14px; font-weight: bold;}
</style>
</head>
<body>
<div id="header" style="border: 1px solid #8a959b; width: 752px; margin: auto;">
<table width="100%" cellspacing="0" cellpaddin="0">
<tr>
<td width="50%">
<img src="/evenements/images/logo_faf.jpg" alt="logo FAF" style="float: left; margin: 30px;" width="300">
</td>
<td width="50%">
<p style="font-size: 24px;font-weight:bold; color:#0172b6; text-align:right; margin: 30px;">Inscription</p>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#0172b6; width: 100%;">
<div style="text-align: center; color:#ffffff; font-size: 20px;"><b><?=html_entity_decode($line['libelle_evenement'])?></b></div>
<?php
if ($line['descriptif_evenement'] != '')
{
?>
<div style="text-align: center; color:#ffffff; font-size: 14px;"><b><?=nl2br($line['descriptif_evenement'])?></b></div>
<?php
}
?>
<div style="text-align: center; color:#ffffff; font-size: 18px;"><b><?=strftime("%A %d %B %Y", strtotime($line['date_evenement']))?></b></div>
</td>
</tr>
<tr>
<td colspan="2">
<?php
/* Debut de paiement Paypal */
echo '<font face=Verdana size=2><center><br><br>
Merci.<br /><br />Pour finaliser votre inscription, nous vous invitons à effectuer votre paiement en ligne d\'un montant de <b>'.($montant).' €</b> par carte bancaire via Paypal.<br>
<br><br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type=hidden name="amount" value="'.number_format($montant, 2, '.', '').'">
<input type=hidden name="cmd" value="_xclick">
<input name="return" type="hidden" value="http://www.french-american.org/evenements/merci.php?id_evenement='.$id_evenement.'">
<input name="cancel_return" type="hidden" value="http://www.french-american.org/evenements/annule.php?id_evenement='.$id_evenement.'">
<input name="notify_url" type="hidden" value="http://www.french-american.org/evenements/ipn_paypal.php?id_commande='.$id_contact.'">
<input type=hidden name="email" value="'.$_POST['email_contact'].'">
<input type=hidden name="currency_code" value="EUR">
<input type=hidden name="no_shipping" value="1">
<input type="hidden" name="charset" value="utf-8">
<input type="hidden" name="business_dev" value="'.'franck_1300481920_biz@netcourrier.com'.'">
<input type="hidden" name="business" value="'.'hugues.derevel@french-american.org'.'">
<input type=hidden name="item_name" value="Evenement '.$line['libelle_evenement'].'">
<input type=hidden name="no_note" value="1">
<input name="custom" type="hidden" value="'.$id_contact.'" />
<input type=submit name=submit value="Procéder au paiement sécurisé par CB >>">
</form>
<br><br>';
/* Fin de paiement Paypal */
?>
</td>
</tr>
</table>
</div>
</body></html>