-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmy_account.php
108 lines (94 loc) · 4.03 KB
/
my_account.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
session_start();
if($_SESSION["admin"] or !isset($_SESSION["email"])){
header("location:http://127.0.0.1:8080/index.php");
die();
}
require "php_includes/db_handler.php";
$db = new db_handler;
$account = $db->get_account_info($_SESSION["email"]);
$orders = $db->get_orders($_SESSION["email"]);
?>
<!doctype html>
<html>
<head>
<title>My Account</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/main.css">
<link rel="stylesheet" href="static/css/my_account.css">
</head>
<body>
<?php require "php_includes/nav_bar.php"; ?>
<div id="top"></div>
<main>
<section id="account-section">
<?php
echo('
<h1>Welcome '.$account["first_name"].' '.$account["last_name"].'.</h1>
<p>'.$_SESSION["email"].'</p>
');
?>
</section>
<section id="orders-section">
<?php
if(!$orders){
echo('
<h1>You don\'t have any orders placed.</h1>
');
}
foreach($orders as $order){
$product = $db->get_product_info($order["product_id"]);
echo('
<div class="order" id="card-'.$order["order_id"].'">
<div class="order-image">
<img src="static/images/products/'.$order["product_id"].'/'.$order["product_id"].'.jpg" alt="">
</div>
<div class="order-details">
<h3>'.$product["product_name"].'</h3>
<p> '.$order["address"].'
<br>
Placed on <b>'.$order["placed_date"].'</b>
<br>
<b>'.$order["price"].' ₹</b>
</p>
<button id="'.$order["order_id"].'" onclick="cancle_order(this)">Cancle</button>
</div>
</div>
');
}
?>
</section>
<div class="fab-btn" id="back-to-top">
<div class="fab-btn-content">
<a href="#top">^</a>
</div>
</div>
</main>
<div class="toast hidden" id="success-toast"><p>Successful</p></div>
<div class="toast hidden" id="fail-toast"><p>Failed</p></div>
</body>
<script>
var sucess_toast = document.querySelector("#success-toast");
var fail_toast = document.querySelector("#fail-toast");
function cancle_order(oid){
document.querySelector("#card-"+oid.id).classList.add("hidden");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText){
toast = sucess_toast;
}
else{
toast = fail_toast;
}
toast.classList.remove("hidden");
setTimeout(function(){ toast.classList.add("hidden"); }, 3000);
}
};
xhttp.open("GET", "php_includes/cancle_order.php?order_id="+oid.id, true);
xhttp.send();
}
</script>
</html>