diff --git a/html/data_treatment/AJAX/buy_again.php b/html/data_treatment/AJAX/buy_again.php new file mode 100644 index 0000000000000000000000000000000000000000..b81eba2791ffec62cf339937b62576c5c6c9fd8f --- /dev/null +++ b/html/data_treatment/AJAX/buy_again.php @@ -0,0 +1,37 @@ +<?php +session_start(); +include("../connect_database.php"); + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['orderNumber'])) { + // Get the order details based on orderNumber + $orderNumber = $_POST['orderNumber']; + + $sql = "SELECT * FROM orders WHERE orderNumber = '$orderNumber'"; + $result = $conn->query($sql); + + if ($result->num_rows > 0) { + // Fetch order details + $row = $result->fetch_assoc(); + + // Decode and set the order items in $_SESSION["panier"] + unset($_SESSION["panier"]); + $_SESSION["panier"] = json_decode($row['items'], true); + + $_SESSION["promocode"] = $row['promocode']; + + $_SESSION["shipment"] = $row["shipment"]; + + // Return success + echo 'success'; + echo "Promocode: ".$row['promocode']." ".$_SESSION["promocode"]; + } else { + // Return error if order not found + echo 'Order not found.'; + } +} else { + // Return error for invalid request + echo 'Invalid request.'; +} + +$conn->close(); +?> diff --git a/html/data_treatment/AJAXendcheckout.php b/html/data_treatment/AJAXendcheckout.php new file mode 100644 index 0000000000000000000000000000000000000000..13cd2d9c49cf1e0c086bda97ca235b8eac8cfc47 --- /dev/null +++ b/html/data_treatment/AJAXendcheckout.php @@ -0,0 +1,77 @@ +<?php +session_start(); + +// Include PHPMailer +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\Exception; + +require 'vendor/autoload.php'; + +// Include your database connection code here +include("connect_database.php"); + +// Process the AJAX request +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $items = json_encode($_POST['items']); + $shipmentMethod = $_POST['shipmentMethod']; + $promocode = $_POST['promoCode']; + $totalprice = $_POST['totalPrice']; + $username = $_SESSION['username']; + + + // Insert order details into the "order" table + // Adjust the SQL query based on your table structure + $sql = "INSERT INTO `orders` (buyer, items, shipment, promocode) + VALUES ('$username', '$items', '$shipmentMethod', '$promocode')"; + $conn->query($sql); + + $sql = "SELECT orderNumber FROM `orders` WHERE buyer='$username' AND items='$items' AND shipment='$shipmentMethod' AND promocode='$promocode' order by orderNumber desc limit 1"; + + $result = $conn->query($sql); + + $final = $result->fetch_array(); + + $decoded_items = json_decode($items); + + $text = ""; + foreach($decoded_items as $item){ + $text .="- ".$item->quantity." ".$item->itemName." which costs "; + if($item->quantity >= 16){ + $text .= $item->price * $item->quantity * (1 - 0.16)." € (you have received a 16% discount !)<br>"; + } else if($item->quantity >= 8){ + $text .= $item->price * $item->quantity * (1 - 0.08)." € (you have received a 8% discount !)<br>"; + } else { + $text .= $item->price * $item->quantity * (1)." €<br>"; + } + } + + // Send confirmation email + try { + $mail = new PHPMailer(true); + + $mail->isSMTP(); + $mail->Host = '127.0.0.1'; + $mail->SMTPAuth = false; + $mail->Port = 25; + + $mail->setFrom('webshop@localhost.com'); + $mail->addAddress($username); + + $mail->Subject = 'Order Confirmation'; + $mail->isHTML(true); + $mail->Body = '<h1>Thank you for your order!</h1><br>Order number:'.$final[0].'<br>Items: <br>'.$text.'You have used the promocode "'.$promocode.'" that reduced the cost to '.$totalprice.' €.<br>You used the '.$shipmentMethod.' Shipment method.'; + + $mail->send(); + + // Reset the shopping cart in the session + $_SESSION['panier'] = array(); + + echo 'Order successful! Check your email for confirmation.'; + } catch (Exception $e) { + echo "Error sending email: {$mail->ErrorInfo}"; + } + + // Close the database connection + $conn->close(); +} +?> diff --git a/html/data_treatment/forgot_treatment.php b/html/data_treatment/forgot_treatment.php new file mode 100644 index 0000000000000000000000000000000000000000..9a0ff3db794234f3f5306d039195cf2e2910aa52 --- /dev/null +++ b/html/data_treatment/forgot_treatment.php @@ -0,0 +1,90 @@ +<?php + +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\Exception; + +require 'vendor/autoload.php'; +session_start(); +if ($_SERVER["REQUEST_METHOD"] == "POST") { + + include("connect_database.php"); + + function generateRandomPassword($length = 9) { + // Caractères possibles dans le mot de passe + $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + + $password = ''; + $charLength = strlen($characters) - 1; + + // Génère le mot de passe + for ($i = 0; $i < $length; $i++) { + $password .= $characters[mt_rand(0, $charLength)]; + } + + return $password; + } + + // Exemple d'utilisation avec un mot de passe de 12 caractères + $randomPassword = generateRandomPassword(12); + + // Check if username is entered and meets the criteria + if(isset($_POST["login"]) && strlen($_POST["login"]) >= 5 && strpos($_POST["login"], "@")) { + $username = $_POST["login"]; + + // Continue with other checks + } else { + echo "Invalid username format. Please enter a valid email address with at least five characters."; + // You might want to redirect or handle this differently based on your requirements + exit; + } + + // Requête SQL de recherche + $sql = "SELECT username FROM members WHERE username = '".$username."'"; + + // Exécute la requête + $result = $conn->query($sql); + + // Vérifie si des résultats ont été trouvés + if ($result->num_rows <= 0) { + // Affiche les résultats + echo "This email correspond to no account."; + exit; + } + + $password = generateRandomPassword(); + + // Validate the user credentials (you should use prepared statements to prevent SQL injection) + $sql = "UPDATE members SET `mdp` = '" . hash("sha512", $password) . "', `FirstConnection` = '1' WHERE `username` = '" . $username . "'"; + + $result = $conn->query($sql); + + if ($result) { + // create a new object + $mail = new PHPMailer(true); + +try { + $mail->isSMTP(); + $mail->Host = '127.0.0.1'; + $mail->SMTPAuth = false; + $mail->Port = 25; + + $mail->setFrom('webshop@localhost.com'); + $mail->addAddress($username); + + $mail->Subject = 'Forgot Password ?'; + + $mail->isHTML(true); + + $mail->Body = "We got you covered, here's the new temporary password: ".$password."<br>Log in again with this password."; + + $mail->send(); + echo 'A new temporary password has been sent to your Email.'; +} catch (Exception $e) { + echo "Erreur lors de l'envoi de l'email : {$mail->ErrorInfo}"; +} + exit; + } + + $conn->close(); +} +?> \ No newline at end of file diff --git a/html/forgot.html b/html/forgot.html deleted file mode 100644 index e85efa0ce472da04ec767f30ed553862c45dc32f..0000000000000000000000000000000000000000 --- a/html/forgot.html +++ /dev/null @@ -1,43 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - -<head> - <meta charset="UTF-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Forgot your password?</title> - <link rel="stylesheet" href="styles.css"> - <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> - <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> - <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> -</head> - -<body> - - <div class="wrapper fadeInDown"> - <div id="formContent"> - <!-- Tabs Titles --> - - <!-- Icon --> - <!-- <div class="fadeIn first"> - <img src="https://e1.pxfuel.com/desktop-wallpaper/130/54/desktop-wallpaper-png-pepsi-man-png-pepsiman.jpg" id="icon" alt="User Icon" /> - </div> --> - - <!-- Login Form --> - <form> - <p><h3><strong> Forgot your password? </strong></h3></p> - <p> Don't worry, we got you covered </p> - <input type="text" id="login" class="fadeIn second" name="login" placeholder="Email"> - <input type="submit" class="fadeIn fourth" value="Send code"> - </form> - - <!-- Remind Passowrd --> - <div id="formFooter"> - <a class="underlineHover" href="login.php">Go back to login</a> - </div> - - </div> - </div> -</body> - -</html> \ No newline at end of file diff --git a/html/forgot.php b/html/forgot.php new file mode 100644 index 0000000000000000000000000000000000000000..45a6ff431c02726d4da9b04b37a0e560e4c6f42d --- /dev/null +++ b/html/forgot.php @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Forgot your password?</title> + <link rel="stylesheet" href="styles.css"> + <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> + <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> + <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> +</head> + +<body> + + <div class="wrapper fadeInDown"> + <div id="formContent"> + <!-- Tabs Titles --> + + <!-- Icon --> + <!-- <div class="fadeIn first"> + <img src="https://e1.pxfuel.com/desktop-wallpaper/130/54/desktop-wallpaper-png-pepsi-man-png-pepsiman.jpg" id="icon" alt="User Icon" /> + </div> --> + + <!-- Login Form --> + + <p><h3><strong> Forgot your password? </strong></h3></p> + <p> Don't worry, we got you covered </p> + <input type="text" id="login" class="fadeIn second" name="login" placeholder="Email"> + <p id="searchResults" style="display:none;"></p> + <input type="submit" id="submit" class="fadeIn fourth" value="Send Password"> + + + <!-- Remind Passowrd --> + <div id="formFooter"> + <a class="underlineHover" href="login.php">Go back to login</a> + </div> + + </div> + </div> +</body> +<script> + $(document).ready(function(){ + $(document).ready(function(){ + var resolution=screen.width+"x"+screen.height+""; + $("#submit").on("click", function(){ + // Récupère la valeur de recherche + var login = $("#login").val(); + // Vérifie si la longueur de la chaîne de recherche est supérieure à 2 caractères + // Effectue une requête AJAX + $.ajax({ + type: "POST", + url: "data_treatment/forgot_treatment.php", + data: { login: login }, + success: function(response){ + // Affiche les résultats dans la div #searchResults + if(response=="A new temporary password has been sent to your Email."){ + setTimeout(function() { + window.location.href = "login.php"; + }, 1000); + } + $("#searchResults").html(response); + $("#searchResults").show(); + } + }); + }); + }); + }); +</script> +</html> \ No newline at end of file diff --git a/html/login.php b/html/login.php index de5ce4b7066368dc2a473aa9a08e580f5703b144..cf50d439702fb9a40048bafc9b05e030c6746c41 100644 --- a/html/login.php +++ b/html/login.php @@ -37,7 +37,7 @@ <!-- Remind Passowrd --> <div id="formFooter"> - <a class="underlineHover" href="forgot.html">Forgot Password?</a><br> + <a class="underlineHover" href="forgot.php">Forgot Password?</a><br> New to the WebShop? <a class="underlineHover" href="register.php">Join Now!</a> <br> <br> or <a class="underlineHover" href="../startbootstrap-agency-gh-pages/index.php">See offers without login in</a> </div> diff --git a/html/register.php b/html/register.php index 6a3c0c83cd22e36e5512dbd8a1509c9b677468ad..1b1e4384ec115f5b339c43bfcac556417c32a3aa 100644 --- a/html/register.php +++ b/html/register.php @@ -54,7 +54,6 @@ if(isset($_SESSION["username"])){ $("#submit").on("click", function(){ // Récupère la valeur de recherche var login = $("#login").val(); - var password = $("#password").val(); // Vérifie si la longueur de la chaîne de recherche est supérieure à 2 caractères // Effectue une requête AJAX $.ajax({ diff --git a/startbootstrap-agency-gh-pages/checkout.php b/startbootstrap-agency-gh-pages/checkout.php index 04b75677bc9b3a1e59fb3e20d0ba1b2bc93af2a2..b349d39df061b2c4c6f3a042dafc0f2d123da20f 100644 --- a/startbootstrap-agency-gh-pages/checkout.php +++ b/startbootstrap-agency-gh-pages/checkout.php @@ -117,9 +117,9 @@ echo $text; <form class="card p-2"> <div class="input-group"> - <input type="text" class="form-control" placeholder="Promo code" id="promocode"> - <button type="submit" class="btn btn-secondary">Redeem</button> - </div> + <input type="text" class="form-control" placeholder="Promo code" id="promocode" <?php if(isset($_SESSION["promocode"])){echo 'value="'.$_SESSION["promocode"].'"';}?>> + + </div> </form> </div> <div class="col-md-7 col-lg-8"> @@ -190,15 +190,15 @@ echo $text; <div class="my-3"> <div class="form-check"> - <input id="DHL Express" name="paymentMethod" type="radio" class="form-check-input" required> + <input id="DHL Express" name="shipmentMethod" type="radio" class="form-check-input" required <?php if(isset($_SESSION["shipment"]) && $_SESSION["shipment"] === "DHL Express") {echo "checked";}?>> <label class="form-check-label" for="DHL Express">DHL Express (+44 €)</label> </div> <div class="form-check"> - <input id="DHL" name="paymentMethod" type="radio" class="form-check-input" required> + <input id="DHL" name="shipmentMethod" type="radio" class="form-check-input" required <?php if(isset($_SESSION["shipment"]) && $_SESSION["shipment"] === "DHL") {echo "checked";}?>> <label class="form-check-label" for="DHL">DHL</label> </div> <div class="form-check"> - <input id="DPD" name="paymentMethod" type="radio" class="form-check-input" required> + <input id="DPD" name="shipmentMethod" type="radio" class="form-check-input" required <?php if(isset($_SESSION["shipment"]) && $_SESSION["shipment"] === "DPD") {echo "checked";}?>> <label class="form-check-label" for="DPD">DPD (-19 €)</label> </div> </div> @@ -206,7 +206,7 @@ echo $text; <hr class="my-4"> <div class="form-check"> - <input type="checkbox" class="form-check-input" id="same-address" required> + <input type="checkbox" class="form-check-input" id="DataProtection" required> <label class="form-check-label" for="same-address">By using this website you are agreeing to our Privacy Policy and our Data Protection Policy</label> </div> @@ -266,7 +266,7 @@ echo $text; <hr class="my-4"> - <button class="w-100 btn btn-primary btn-lg" type="submit">Continue to checkout</button> + <button class="w-100 btn btn-primary btn-lg" id="endcheckout">Continue to checkout</button> </form> </div> </div> @@ -288,7 +288,7 @@ echo $text; <script src="form-validation.js"></script> </body> </html> - +<?php echo json_encode($_SESSION["panier"]); ?> <!-- Add this script to the end of your HTML file, before the closing </body> tag --> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <script> @@ -296,7 +296,7 @@ echo $text; // Function to update total price based on shipment method function updateTotalPrice() { // Get the selected shipment method - var selectedMethod = $("input[name='paymentMethod']:checked").attr("id"); + var selectedMethod = $("input[name='shipmentMethod']:checked").attr("id"); // Récupérer le code promo saisi par l'utilisateur var promoCode = $("#promocode").val(); @@ -344,29 +344,50 @@ echo $text; }); // Attach change event to shipment method radio buttons - $("input[name='paymentMethod']").change(function() { + $("input[name='shipmentMethod']").change(function() { updateTotalPrice(); }); // Initial update when the page loads updateTotalPrice(); - }); -</script> + // Click event for checkout button + $("#endcheckout").on("click", function() { + event.preventDefault(); + if ($("#DataProtection").prop("checked")) { -you have ordered:<br> -<?php -$text=""; -foreach($_SESSION["panier"] as $item){ - $text .="- ".$item['quantity']." ".$item["itemName"]." which costs "; - if($item['quantity']>=16){ - $text .= $item["price"]*$item["quantity"]*(1-0.16)." € (you have received a 16% discount !)<br>"; - } else if($item['quantity']>=8){ - $text .= $item["price"]*$item["quantity"]*(1-0.08)." € (you have received a 8% discount !)<br>"; - } else { - $text .= $item["price"]*$item["quantity"]*(1)." €<br>"; - } -} -echo $text; -?> + // Gather data for the AJAX request + var items = <?php echo json_encode($_SESSION["panier"]); ?>; + var shipmentMethod = $("input[name='shipmentMethod']:checked").attr("id"); + var promoCode = $("#promocode").val(); + var totalPrice = <?php echo $totalprice; ?>; + + // Prepare data to be sent + var data = { + items: items, + shipmentMethod: shipmentMethod, + promoCode: promoCode, + totalPrice: totalPrice + }; + + // Make the AJAX request + $.ajax({ + url: '../html/data_treatment/AJAXendcheckout.php', // Replace with the actual path + type: 'POST', + data: data, + success: function(response) { + // Redirect to the thank you page upon successful response + window.location.href = 'thank_you_page.php'; + }, + error: function() { + // Handle error if needed + } + }); + } else { + // Display an alert if DataProtection checkbox is not checked + alert("Please check the Data Protection checkbox before proceeding."); + } + }); + }); +</script> \ No newline at end of file diff --git a/startbootstrap-agency-gh-pages/index.php b/startbootstrap-agency-gh-pages/index.php index 812e0c06bfaa30bd286ab6f0a6def13382042c87..004a3eb40757686df742f9ce6d9e6db503cecb18 100644 --- a/startbootstrap-agency-gh-pages/index.php +++ b/startbootstrap-agency-gh-pages/index.php @@ -42,7 +42,6 @@ switch ($j) { break; } include("../html/data_treatment/connect_database.php"); -var_dump($_SESSION["panier"]); ?> <html lang="en"> <head> @@ -97,7 +96,7 @@ data: { dataType: 'json', success: function (response) { alert(response.message); // Vous pouvez personnaliser cela en fonction de votre logique - $('#example').text(parseInt($('#numberbox').text(), 10)+itemQuantity); + $('#numberbox').text(parseInt($('#numberbox').text(), 10)+parseInt(itemQuantity),10); }, error: function (error) { console.error(error); @@ -122,8 +121,10 @@ error: function (error) { <div class="number-box" id="numberbox"> <?php $count = 0; - foreach($_SESSION["panier"] as $item){ - $count +=intval($item["quantity"]); + if(isset($_SESSION["panier"])){ + foreach($_SESSION["panier"] as $item){ + $count +=intval($item["quantity"]); + } } echo $count;?> </div> diff --git a/startbootstrap-agency-gh-pages/purchased_item.php b/startbootstrap-agency-gh-pages/purchased_item.php new file mode 100644 index 0000000000000000000000000000000000000000..1eeab50d4c61b03798a2fd60992f721b406aaf04 --- /dev/null +++ b/startbootstrap-agency-gh-pages/purchased_item.php @@ -0,0 +1,73 @@ +<?php +session_start(); +// Include your database connection code here +include("../html/data_treatment/connect_database.php"); + +// Fetch all orders for a specific buyer +$buyerEmail = $_SESSION["username"]; // Replace with the actual buyer's email + +$sql = "SELECT * FROM orders WHERE buyer = '$buyerEmail' ORDER BY orderNumber DESC"; +$result = $conn->query($sql); + +if ($result->num_rows > 0) { + // Display the summary for each order + while ($row = $result->fetch_assoc()) { + echo '<h2>Order Number: ' . $row['orderNumber'] . '</h2>'; + + // Decode the JSON-encoded items + $items = json_decode($row['items'], true); + + echo '<ul>'; + // Display each item in the order + foreach ($items as $itemName => $itemDetails) { + echo '<li>'; + echo 'Item: ' . $itemDetails['itemName'] . '<br>'; + echo 'Price: ' . $itemDetails['price'] . ' €<br>'; + echo 'Quantity: ' . $itemDetails['quantity'] . '<br>'; + echo 'Image: ' . $itemDetails['imagename'] . '<br>'; + echo '</li><br>'; + } + echo '</ul>'; + + echo '<p>Shipment Method: ' . $row['shipment'] . '</p>'; + echo '<p>Promocode Used: ' . $row['promocode'] . '</p>'; + + // Add "Buy Again" and "Buy Again Instantly" buttons + + echo '<input type="hidden" name="orderNumber" value="' . $row['orderNumber'] . '">'; + echo '<button class="buy-again-btn" data-order-number="' . $row['orderNumber'] . '">Buy Again</button>'; + + echo '<hr>'; + } +} else { + echo '<p>No orders found for this buyer.</p>'; +} + +// Close the database connection +$conn->close(); +?> +<!-- JQuery --> +<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> +<script> + $(document).ready(function() { + // Function to handle "Buy Again" button click + $(".buy-again-btn").click(function() { + // Get the orderNumber from the data attribute + var orderNumber = $(this).data("order-number"); + + // Make an AJAX request to buy_again.php + $.ajax({ + url: '../html/data_treatment/AJAX/buy_again.php', + type: 'POST', + data: { orderNumber: orderNumber }, + success: function(response) { + // Redirect to checkout.php upon success + window.location.href = 'checkout.php'; + }, + error: function() { + // Handle error if needed + } + }); + }); + }); +</script> diff --git a/startbootstrap-agency-gh-pages/shoppingPage.php b/startbootstrap-agency-gh-pages/shoppingPage.php index 1eda7872f2ae086606ce4307b8384604449cff7e..2c8001881d9ff7f6766951166a4c45363cf2e873 100644 --- a/startbootstrap-agency-gh-pages/shoppingPage.php +++ b/startbootstrap-agency-gh-pages/shoppingPage.php @@ -26,7 +26,6 @@ while ($row = $result->fetch_assoc()) { // Faites ce que vous avez besoin de faire avec ces informations // Par exemple, affichez-les ou les utilisez d'une autre manière } -var_dump($_SESSION["panier"]); ?> <!DOCTYPE html> diff --git a/startbootstrap-agency-gh-pages/thank_you_page.php b/startbootstrap-agency-gh-pages/thank_you_page.php new file mode 100644 index 0000000000000000000000000000000000000000..cbeb8c51c0b1085e33b65a4a74980d4ccdf97b1c --- /dev/null +++ b/startbootstrap-agency-gh-pages/thank_you_page.php @@ -0,0 +1,2 @@ +Thank you +<a href="index.php">Return to Main Page</a> \ No newline at end of file