-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_success.php
324 lines (274 loc) · 10.9 KB
/
order_success.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
session_start();
include("connection.php");
error_reporting(0);
if(!isset($_SESSION['customer']))
{
header("location:index.php");
}
$cust= $_SESSION['customer'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Order Placed</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<style>
/* Center the loader */
#loader {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
@-webkit-keyframes animatebottom {
from { bottom:-100px; opacity:0 }
to { bottom:0px; opacity:1 }
}
@keyframes animatebottom {
from{ bottom:-100px; opacity:0 }
to{ bottom:0; opacity:1 }
}
#myDiv {
display: none;
text-align: center;
}
</style>
</head>
<body onload="myFunction()" style="margin:0;">
<?php
$q2= "SELECT * FROM customers WHERE email= '$cust'";
$data2= mysqli_query($conn, $q2);
while($res2= mysqli_fetch_assoc($data2)){
$address= $res2['street'].", ".$res2['city'].", ".$res2['pincode'];
}
?>
<div id="loader"></div>
<div id= "myDiv" class="container" style="display:none;">
<div class="row justify-content-center">
<div class="table-responsive">
<?php
$somerand= "COD".mt_rand(100000000,999999999);
$q2= "SELECT * FROM customers WHERE email='$cust'";
$data2= mysqli_query($conn, $q2);
$res2= mysqli_fetch_assoc($data2);
?>
<h2 class="text-center text-black mb-5" style="margin-top: 20px;"> Order Placed </h2>
<table class="table table-bordered" style="margin-top: 40px;">
<tr>
<th>Purchased from</th>
<td>Grocery Store</td>
</tr>
<tr>
<th>Payment ID</th>
<td><?php echo $somerand; ?></td>
</tr>
<tr>
<th>Buyer Name</th>
<td><?= $res2['username']; ?></td>
</tr>
<tr>
<th>Buyer Phone No.</th>
<td><?= $res2['phone']; ?></td>
</tr>
<tr>
<th>Buyer Email</th>
<td><?= $res2['email']; ?></td>
</tr>
<tr>
<th>Buyer Address</th>
<td><?= $address; ?></td>
</tr>
<tr>
<th>Payment Status</th>
<td>Pending</td>
</tr>
<tr>
<th>Order Date</th>
<td><?php
date_default_timezone_set('Asia/Kolkata');
$date = date('d/m/Y H:i:s', time());
echo $date;?></td>
</tr>
</table>
<?php
require './phpmailer/PHPMailerAutoload.php';
function send_email($vendor, $item, $qty, $pay_id, $sbuyer_name, $sbuyer_phone, $address){
$mail = new PHPMailer;
$htmlversion= "You have received and order <br> Product: <b>".$item."</b> <br> Qty: <b>".$qty."</b> <br> Order ID: <b>".$pay_id."</b> <br> Customer Name: <b>".$sbuyer_name."</b> <br> Customer Phone No: <b>".$sbuyer_phone."</b> <br> Customer Address <b>".$address."</b>";
$textversion= 'Order Received';
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'rfidlibrarypccoe@gmail.com'; // SMTP username
$mail->Password = '14785269'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('rfidlibrarypccoe@gmail.com', 'Grocery Store');
$mail->addAddress($vendor); // Name is optional
$mail->isHTML(true);
$mail->Subject = 'Order Received';
$mail->Body = $htmlversion;
$mail->AltBody = $textversion;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
/*echo 'Message has been sent';*/
}
}
function send_email_customer($cust, $item, $qty, $pay_id, $svendor_name, $svendor_phone, $svendor_address){
$mail = new PHPMailer;
$htmlversion= "You have ordered for <br> Product: <b>".$item."</b> <br> Qty: <b>".$qty."</b> <br> Order ID: <b>".$pay_id."</b> <br> Vendor Name: <b>".$svendor_name."</b> <br> Vendor Phone No: <b>".$svendor_phone."</b> <br> Vendor Address <b>".$svendor_address."</b>";
$textversion= 'Order Successful';
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'rfidlibrarypccoe@gmail.com'; // SMTP username
$mail->Password = '14785269'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('rfidlibrarypccoe@gmail.com', 'Grocery Store');
$mail->addAddress($cust); // Name is optional
$mail->isHTML(true);
$mail->Subject = 'Order Successful';
$mail->Body = $htmlversion;
$mail->AltBody = $textversion;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
/*echo 'Message has been sent';*/
}
}
function send_email_admin($item, $qty, $pay_id, $svendor_name, $svendor_phone, $svendor_address, $sbuyer_name, $sbuyer_phone, $address){
$mail = new PHPMailer;
$htmlversion= "Order Details <br> Product: <b>".$item."</b> <br> Qty: <b>".$qty."</b> <br> Order ID: <b>".$pay_id."</b> <br> Vendor Name: <b>".$svendor_name."</b> <br> Vendor Phone No: <b>".$svendor_phone."</b> <br> Vendor Address <b>".$svendor_address."</b> <br> Customer Name: <b>".$sbuyer_name."</b> <br> Customer Phone No: <b>".$sbuyer_phone."</b> <br> Customer Address <b>".$address."</b>";
$textversion= 'Order Successful';
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'rfidlibrarypccoe@gmail.com'; // SMTP username
$mail->Password = '14785269'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('rfidlibrarypccoe@gmail.com', 'Grocery Store');
$mail->addAddress('gokhalehemal11@gmail.com'); // Name is optional
$mail->isHTML(true);
$mail->Subject = 'Order Details';
$mail->Body = $htmlversion;
$mail->AltBody = $textversion;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
/*echo 'Message has been sent';*/
}
}
?>
<div class="text-center text-danger mb-2">
<button name="order" class="btn btn-danger" onclick='window.location.href = "http://localhost/big_store/web/order.php"'>Track your Order</button>
<button name="shopping" class="btn btn-success" onclick='window.location.href = "http://localhost/big_store/web/index.php"'>Continue Shoppping</button>
</div>
<?php
$spay_id= $somerand;
$sbuyer_name= $res2['username'];
$sbuyer_email= $res2['email'];
$sbuyer_phone= $res2['phone'];
$sstatus= "Cod";
$allvalues= $_SESSION['kela'];
$delivery= $_SESSION['del'];
if($delivery ==1 )
{
$shipping= "Normal";
}
else{
$shipping= "Express";
}
/* $sent= array();
$vendors= array();
$names= array();
$qtys= array();*/
$some= json_decode($allvalues);
$items = array();
foreach($some as $arr) {
foreach($arr as $key => $value) {
$items[$key] = $value;
}
$sid= $items['id'];
$stitle= $items['name'];
$sprice= $items['price'];
$sqty= $items['quantity'];
$simage= $items['image'];
$svendor='';
$q2= "SELECT * FROM products WHERE product_id= $sid ";
$data2= mysqli_query($conn, $q2);
while($res2= mysqli_fetch_assoc($data2)){
$svendor= $res2['vendor_name'];
$q3= "SELECT * FROM vendors WHERE email= '$svendor' ";
$data3= mysqli_query($conn, $q3);
while($res3= mysqli_fetch_assoc($data3)){
$svendor_name= $res3['username'];
$svendor_address= $res3['street'].", ".$res3['city'].", ".$res3['pincode'];
$svendor_phone= $res3['phone'];
}
}
$q3= "INSERT INTO `orders`(`product_title`, `product_price`, `product_qty`, `product_image`, `vendor_name`, `payment_id`, `payment_status`, `buyer_email`, `buyer_phone`, `buyer_name`,`order_date`,`delivery_status`,`shipping_method`, `buyer_address`) VALUES ('$stitle', '$sprice', '$sqty', '$simage', '$svendor', '$spay_id', '$sstatus', '$sbuyer_email', '$sbuyer_phone', '$sbuyer_name','$date','ND','$shipping','$address')";
if(mysqli_query($conn, $q3)){
send_email($svendor, $stitle, $sqty, $spay_id, $sbuyer_name, $sbuyer_phone, $address);
send_email_customer($cust, $stitle, $sqty, $spay_id, $svendor_name, $svendor_phone, $svendor_address);
send_email_admin($stitle, $sqty, $spay_id, $svendor_name, $svendor_phone, $svendor_address, $sbuyer_name, $sbuyer_phone, $address);
}else {
echo "Error: " . $q3 . "<br>" . mysqli_error($conn);
}
}
?>
</div>
</div>
</div>
<script>
var myVar;
function myFunction() {
myVar = setTimeout(showPage, 3000);
}
function showPage() {
document.getElementById("loader").style.display = "none";
document.getElementById("myDiv").style.display = "block";
}
</script>
</body>
</html>