2024-08-05 13:35:19 +00:00

290 lines
15 KiB
PHP
Executable File

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require("../../include/variables.php");
require("../../include/init.php");
require 'vendor/autoload.php';
if (isset($_SESSION['userID']) == false || empty($_SESSION['userID'])) {
header("Location: /login?p=adhesion");
die('Veuillez vous connecter dans <a href="/login">/login</a>');
}
require("../../include/main-functions.php");
require("../../include/inputs.php");
require("../../include/panels.php");
$pdo = sqlConnect($sqlDatabaseHost, $sqlDatabaseName, $sqlDatabaseUser, $sqlDatabasePass);
$userID = $_SESSION['userID'];
$stepOneSQLReq = "SELECT ID FROM adhesion_requests WHERE userid = :userid";
$stepOneReq = $pdo->prepare($stepOneSQLReq);
$stepOneReq->bindParam(":userid", $userID);
$stepOneReq->execute();
$stepTwoSQLReq = "SELECT ID FROM adhesions_non_payees WHERE userid = :userid";
$stepTwoReq = $pdo->prepare($stepTwoSQLReq);
$stepTwoReq->bindParam(":userid", $userID);
$stepTwoReq->execute();
$stepThreeSQLReq = "SELECT ID FROM adherents WHERE userid = :userid";
$stepThreeReq = $pdo->prepare($stepThreeSQLReq);
$stepThreeReq->bindParam(":userid", $userID);
$stepThreeReq->execute();
$stepOne = $stepOneReq->fetchAll(PDO::FETCH_ASSOC);
$stepTwo = $stepTwoReq->fetchAll(PDO::FETCH_ASSOC);
$stepThree = $stepThreeReq->fetchAll(PDO::FETCH_ASSOC);
if ($stepOne) {
$step = 1;
} else if ($stepTwo) {
$step = 2;
} else if ($stepThree) {
$step = 3;
} else {
$step = 0;
}
if (isset($_POST['lastname']) && isset($_POST['firstname']) && isset($_POST['email']) && isset($_POST['club']) && isset($_POST['born']) && $step == 0) {
if ($_POST['valide'] != "accepte") {
$status = "Vous devez vous engager à restpecter les statuts et le règlement intérieur";
} else {
if (empty($_POST['lastname']) || empty($_POST['firstname']) || empty($_POST['email']) || empty($_POST['born'])) {
$status = "Veuillez remplir tous les champs";
} else {
if (preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $_POST['email']) == false) {
$status = "Veuillez entrer un email valide";
} else {
$email = isset($_POST['email']) ? strtolower($_POST['email']) : NULL;
$lastname = htmlspecialchars($_POST['lastname']);
$firstname = htmlspecialchars($_POST['firstname']);
$club = empty($_POST['club']) ? "Sans club" : htmlspecialchars($_POST['club']);
$born = htmlspecialchars($_POST['born']);
$promo = empty($_POST['promo']) ? "Sans promo" : htmlspecialchars($_POST['promo']);
$sqlRequest = "SELECT ID FROM adhesion_requests WHERE userid = :userid";
$request = $pdo->prepare($sqlRequest);
$request->bindParam(":userid", $userID);
$request->execute();
$result = $request->fetchAll(PDO::FETCH_ASSOC);
if($result) {
$requestAlreadySent = true;
} else {
$requestAlreadySent = false;
$request = $pdo->prepare("INSERT INTO adhesion_requests (firstname, lastname, born, promo, club, email, userid) VALUES (:firstname, :lastname, :born, :promo, :club, :email, :userid)");
$request->bindParam(':firstname', $firstname);
$request->bindParam(':lastname', $lastname);
$request->bindParam(':born', $born);
$request->bindParam(':promo', $promo);
$request->bindParam(':club', $club);
$request->bindParam(':email', $email);
$request->bindParam(':userid', $userID);
if ($request->execute()) {
$status = "Demande d'adhésion envoyée, vous recevrez la réponse du CA par mail.";
$mail = new PHPMailer(true);
try {
// Paramètres du serveur
$mail->isSMTP(); // Utiliser SMTP
$mail->Host = 'outlook.office365.com'; // Serveur SMTP Exchange
$mail->SMTPAuth = true; // Activer l'authentification SMTP
$mail->Username = 'smtp@e59.fr'; // Nom d'utilisateur SMTP
$mail->Password = 'WTFdoto5678TFWT'; // Mot de passe SMTP
$mail->SMTPSecure = 'tls'; // Activer le cryptage TLS
$mail->Port = 587; // Port TCP pour TLS
$mail->CharSet = "UTF-8";
// Destinataires
$mail->setFrom('service-adhesions@e59.fr', 'Adhesions');
$mail->addAddress('asso.uvsq@e59.fr', 'E59-UVSQ'); // Ajouter un destinataire
// Contenu de l'e-mail
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Nouvelle demande d\'adhesion';
$mail->Body = '<h2>Nouvelle demande d\'adhesion</h2><p>Nom Prenom : ' . $firstname . ' ' . $lastname . '</p><p>Email : ' . $email . '</p><p>Date de naissance : ' . $born . '</p><p>Promo : ' . $promo . '</p><p>Rendez-vous sur <a href="https://e59.fr/admin/adhesions.php">https://e59.fr/admin/adhesions.php</a> pour valider la demande lors du CA</p>';
$mail->AltBody = 'Nouvelle demande d\'adhésion : Nom Prenom : ' . $firstname . ' ' . $lastname . ' | Email : ' . $email . ' | Date de naissance : ' . $born . ' | Promo : ' . $promo;
$mail->send();
} catch (Exception $e) {
$status = "Erreur interne : {$mail->ErrorInfo}";
}
} else {
$status = "Erreur SQL";
}
}
}
}
}
}
$checkColor = "#99D366";
$pendingColor = "#878787";
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<?php fillHead($rootPageURL, "Adhésion - " . $pageName, $darkTheme, $lightTheme);?>
<style>
.select-input {
margin: 0.5em auto 1.5em auto;
width: 80%;
font-size: 0.8em;
}
.date-input {
margin: 0.5em auto;
font-size: 0.8em;
width: 80%;
}
#avancement-adhesion {
margin: 0.5em;
}
#avancement-adhesion circle {
margin: 1em;
fill: none;
stroke-width: 6px;
stroke-miterlimit: 10;
}
#avancement-adhesion line {
margin: 1em;
fill: none;
stroke-width: 6px;
stroke-miterlimit: 10;
stroke-linecap: round;
}
#avancement-adhesion polyline {
stroke-linejoin: round;
stroke-linecap: round;
fill: none;
stroke-width: 6px;
}
#avancement-adhesion text {
font-family: "Inter", Arial;
font-size: 30px;
}
.step-1 {
<?php if ($step >= 1) {echo ('stroke: ' . $checkColor);} else {echo ('stroke: ' . $pendingColor);}?>
}
.step-2 {
<?php if ($step >= 2) {echo ('stroke: ' . $checkColor);} else {echo ('stroke: ' . $pendingColor);}?>
}
.step-3 {
<?php if ($step >= 3) {echo ('stroke: ' . $checkColor);} else {echo ('stroke: ' . $pendingColor);}?>
}
.step-check-1 {
<?php if ($step >= 1) {echo ('stroke: ' . $checkColor);} else {echo ('display: none;');}?>
}
.step-check-2 {
<?php if ($step >= 2) {echo ('stroke: ' . $checkColor);} else {echo ('display: none;');}?>
}
.step-check-3 {
<?php if ($step >= 3) {echo ('stroke: ' . $checkColor);} else {echo ('display: none;');}?>
}
.step-text-1 {
<?php if ($step >= 1) {echo ('fill: ' . $checkColor);} else {echo ('fill: ' . $pendingColor);}?>
}
.step-text-2 {
<?php if ($step >= 2) {echo ('fill: ' . $checkColor);} else {echo ('fill: ' . $pendingColor);}?>
}
.step-text-3 {
<?php if ($step >= 3) {echo ('fill: ' . $checkColor);} else {echo ('fill: ' . $pendingColor);}?>
}
.adv-box {
border: 1px solid var(--text);
border-radius: 10px;
width: 7em;
font-size: 0.8em;
text-align: center;
padding: 0.5em;
}
.member-info {
text-align: left;
font-size: 0.8em;
}
</style>
</head>
<body class="body">
<header>
<div class="panel-content">
<?php fillHeader($rootPageURL, $headerTitle, $headerSubtitle, $social);?>
</div>
</header>
<nav>
<div class="panel-content">
<?php fillNav($rootPageURL);?>
</div>
</nav>
<main>
<div class="content">
<form action="#" method="post">
<div class="form">
<div class="form-title">Adhésion</div>
<div class="status"><?=$status?></div>
<?php
if ($step == 0) {
$sqlRequest = "SELECT username, email FROM users WHERE ID = :userID";
$request = $pdo->prepare($sqlRequest);
$request->bindParam(":userID", $_SESSION['userID']);
$request->execute();
$user = $request->fetchAll(PDO::FETCH_ASSOC);
$sqlRequest = "SELECT ID, name FROM clubs";
$request = $pdo->prepare($sqlRequest);
$request->execute();
$clubs = $request->fetchAll(PDO::FETCH_ASSOC);
$clubOptions = array();
foreach($clubs as $club) {
$clubOptions[$club["ID"]] = $club["name"];
}
textInput("text", "", "lastname", "Nom", isset($_POST['lastname']) ? $_POST['lastname'] : "");
textInput("text", "", "firstname", "Prénom", isset($_POST['firstname']) ? $_POST['firstname'] : "");
textInput("email", "", "email", "Email", isset($_POST['email']) ? $_POST['email'] : $user[0]['email']);
textInput("text", "", "promo", "Formation - Année", isset($_POST['promo']) ? $_POST['promo'] : "");
selectInput("club", "Club", $clubOptions, isset($_POST['club']) ? $_POST['club'] : $clubOptions[0]);
dateInput("born", "Né le", "1930-01-01", isset($_POST['born']) ? $_POST['born'] : "2005-01-01");
echo ('<div style="margin: 2em 0;""><input type="checkbox" name="valide" value="accepte">');
echo ('<label for="valide" style="font-size: 0.6em; margin-left: 0.5em;">Je m\'engage à respecter les <a href="https://e59.fr/about/docs/pdf/Statuts-E59-UVSQ.pdf" target="_blank">statuts</a> et le <a href="https://e59.fr/about/docs/pdf/Reglement-Interieur-E59-UVSQ.pdf" target="_blank">règlement intérieur</a></label></div>');
echo ('<a href="/" class="hidden-button" style="margin-right: 2em;">Annuler</a><button type="submit">Envoyer</button>');
} else {
echo ('<svg id="avancement-adhesion" data-name="Avancement Adhésion" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 621.85 174.92"><defs></defs><circle class="step-1" cx="65.07" cy="136.34" r="34.92"/><circle class="step-2" cx="308.65" cy="136.34" r="34.92"/><circle class="step-3" cx="552.24" cy="136.34" r="34.92"/><line class="line step-2" x1="248.28" y1="136.34" x2="125.44" y2="136.34"/><line class="step-3" x1="491.87" y1="136.34" x2="369.03" y2="136.34"/><polyline class="step-check-1" points="50.66 139.2 61.81 149.72 79.48 128.34"/><polyline class="step-check-2" points="294.24 139.2 305.4 149.72 323.07 128.34"/><polyline class="step-check-3" points="537.83 139.2 548.99 149.72 566.65 128.34"/><text class="step-text-1" transform="translate(-2.64 22.37)"><tspan x="0" y="0">Demande</tspan><tspan x="8.39" y="36">envoyée</tspan></text><text class="step-text-2" transform="translate(241.34 22.37)"><tspan x="0" y="0">Demande</tspan><tspan class="cls-10" x="17.39" y="36">validée</tspan></text><text class="step-text-3" transform="translate(480.33 22.5)"><tspan x="0" y="0">Cotisation</tspan><tspan x="29.08" y="36">payée</tspan></text></svg>');
if ($step == 3) {
$sqlRequest = "SELECT adherents.ID, adherents.firstname, adherents.lastname, adherents.email, clubs.name, adherents.memberid FROM adherents JOIN clubs ON adherents.club = clubs.ID WHERE adherents.userid = :userID";
$request = $pdo->prepare($sqlRequest);
$request->bindParam(":userID", $_SESSION['userID']);
$request->execute();
$result = $request->fetchAll(PDO::FETCH_ASSOC);
echo ('<div class="member-info">');
echo ('<div>' . $result[0]['firstname'] . ' ' . $result[0]['lastname'] . '</div>');
echo ('<div>' . $result[0]['memberid'] . '</div>');
echo ('<div>' . $result[0]['email'] . '</div>');
echo ('<div>' . $result[0]['name'] . '</div>');
echo ('</div>');
}
}
?>
</div>
</form>
</div>
</main>
<footer>
<div class="panel-content">
<?php fillFooter($footerText);?>
</div>
</footer>
</body>
</html>