Skip to content
Snippets Groups Projects
Commit 46773d27 authored by totoW's avatar totoW
Browse files

Purchased_item done, buy again done, forgot password done, FINISHED FOR...

Purchased_item done, buy again done, forgot password done, FINISHED FOR ANTHONY *drop the mic and run, very, very far*
parent d0571cb0
No related branches found
No related tags found
No related merge requests found
<?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();
?>
<?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();
}
?>
<?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
......@@ -24,12 +24,13 @@
</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>
<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">
......@@ -39,5 +40,32 @@
</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
......@@ -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>
......
......@@ -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({
......
......@@ -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
......@@ -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>
......
<?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>
......@@ -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>
......
Thank you
<a href="index.php">Return to Main Page</a>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment