-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.php
381 lines (348 loc) · 13.4 KB
/
action.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
session_start();
include('dbconnect.php');
if(isset($_POST["category"])){
$category_query="SELECT * FROM categories";
$run_query=mysqli_query($conn,$category_query);
echo "<div class='nav nav-pills nav-stacked'>
<li class='active'><a href='#'><h4>Categories</h4></a></li>";
if(mysqli_num_rows($run_query)){
while($row=mysqli_fetch_array($run_query)){
$cid=$row['cat_id'];
$cat_name=$row['cat_title'];
echo "<li><a href='#' class='category' cid='$cid'>$cat_name</a></li>";
}
echo "</div>";
}
}
if(isset($_POST["brand"])){
$category_query="SELECT * FROM brands";
$run_query=mysqli_query($conn,$category_query);
echo "<div class='nav nav-pills nav-stacked'>
<li class='active'><a href='#'><h4>Brands</h4></a></li>";
if(mysqli_num_rows($run_query)){
while($row=mysqli_fetch_array($run_query)){
$bid=$row['brand_id'];
$brand_name=$row['brand_title'];
echo "<li><a href='#' class='brand' bid='$bid'>$brand_name</a></li>";
}
echo "</div>";
}
}
if(isset($_POST['page']))
{
$sql="SELECT * FROM products";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
$pageno=ceil($count/6);
for($i=1;$i<=$pageno;$i++)
{
echo "
<li><a href='#' page='$i' class='page'>$i</a></li>
";
}
}
if(isset($_POST['getProduct'])){
$limit= 6;
if(isset($_POST['setPage'])){
$pageno=$_POST['pageNumber'];
$start=($pageno * $limit)-$limit;
}
else{$start=0;}
if(isset($_POST['price_sorted'])){
$product_query="SELECT * FROM products ORDER BY product_price";
}
elseif(isset($_POST['pop_sorted'])){
$product_query="SELECT * FROM products ORDER BY RAND()";
}
else{
$product_query="SELECT * FROM products LIMIT $start,$limit";
}
$run_query=mysqli_query($conn,$product_query);
if(mysqli_num_rows($run_query)){
while($row=mysqli_fetch_array($run_query)){
$pro_id=$row['product_id'];
$pro_cat=$row['product_cat'];
$brand=$row['product_brand'];
$title=$row['product_title'];
$price=$row['product_price'];
$img=$row['product_image'];
echo "<div class='col-md-4'>
<div class='panel panel-info'>
<div class='panel-heading'>$title</div>
<div class='panel-body'>
<a href='#' class='imageproduct' pid='$pro_id'>
<img src='assets/prod_images/$img' style='width:200px; height:250px;' >
</a>
</div>
<div class='panel-heading'>Rs $price
<button pid='$pro_id' class='quicklook btn btn-danger btn-xs' style='float:right;margin-left:10px;'>Quick look</button>
<button pid='$pro_id' class='product btn btn-danger btn-xs' style='float:right;'>Add to Cart</button>
</div>
</div></div>";
}
}
}
if(isset($_POST['get_selected_Category']) || isset($_POST['get_selected_brand']) || isset($_POST['search']) || isset($_POST['price_sorted']))
{
if(isset($_POST['get_selected_Category'])){
$cid=$_POST['cat_id'];
$sql="SELECT * FROM products WHERE product_cat=$cid";
}
elseif(isset($_POST['get_selected_brand'])){
$bid=$_POST['brand_id'];
$sql="SELECT * FROM products WHERE product_brand=$bid";
if(isset($_POST['price_sorted'])){
$sql="SELECT * FROM products ORDER BY product_price";
}
}
elseif(isset($_POST['search'])){
$keyword=$_POST['keyword'];
$sql="SELECT * FROM products WHERE product_keywords LIKE '%$keyword%'";
if(isset($_POST['price_sorted'])){
$sql="SELECT * FROM products ORDER BY product_price";
}
}
$run_query=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($run_query)){
$pro_id=$row['product_id'];
$pro_cat=$row['product_cat'];
$brand=$row['product_brand'];
$title=$row['product_title'];
$price=$row['product_price'];
$img=$row['product_image'];
echo "<div class='col-md-4'>
<div class='panel panel-info'>
<div class='panel-heading'>$title</div>
<div class='panel-body' class='imageproduct' pid='$pro_id'><img src='assets/prod_images/$img' style='width:200px; height:250px;'></div>
<div class='panel-heading'>Rs $price
<button pid='$pro_id' class='quicklook btn btn-warning btn-xs' style='float:right;'>Quick look</button>
<button pid='$pro_id' class='product btn btn-danger btn-xs' style='float:right;'>Add to Cart</button>
</div>
</div></div>";
}
}
if(isset($_POST['addToProduct'])){
if(!(isset($_SESSION['uid']))){echo "
<div class='alert alert-danger' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Hey there!</strong> Sign in to buy stuff!
</div>
";}
else{
$pid=$_POST['proId'];
$uid=$_SESSION['uid'];
$sql = "SELECT * FROM cart WHERE p_id = '$pid' AND user_id = '$uid'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count>0)
{
echo "<div class='alert alert-danger' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Already added!
</div>";
}
else
{
$sql = "SELECT * FROM products WHERE product_id = '$pid'";
$run_query = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($run_query);
$id = $row["product_id"];
$pro_title = $row["product_title"];
$pro_image = $row["product_image"];
$pro_price = $row["product_price"];
$sql="INSERT INTO cart(p_id,ip_add,user_id,product_title,product_image,qty,price,total_amount) VALUES('$pid','0.0.0.0','$uid','$pro_title','$pro_image','1','$pro_price','$pro_price')";
$run_query = mysqli_query($conn,$sql);
if($run_query){
echo "
<div class='alert alert-success' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Product added to cart!
</div>
";
}
}
}
}
if(isset($_POST['cartmenu']) || isset($_POST['cart_checkout']))
{
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
if($count>0){
$i=1;
$total_amt=0;
while($row=mysqli_fetch_array($run_query))
{
$sl=$i++;
$pid=$row['p_id'];
$product_image=$row['product_image'];
$product_title=$row['product_title'];
$product_price=$row['price'];
$qty=$row['qty'];
$total=$row['total_amount'];
$price_array=array($total);
$total_sum=array_sum($price_array);
$total_amt+=$total_sum;
if(isset($_POST['cartmenu']))
{
echo "
<div class='row'>
<div class='col-md-3'>$sl</div>
<div class='col-md-3'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-3'>$product_title</div>
<div class='col-md-3'>Rs $product_price</div>
</div>
";
}
else
{
echo "
<div class='row'>
<div class='col-md-2'><a href='#' remove_id='$pid' class='btn btn-danger remove'><span class='glyphicon glyphicon-trash'></span></a>
<a href='#' update_id='$pid' class='btn btn-success update'><span class='glyphicon glyphicon-ok-sign'></span></a>
</div>
<div class='col-md-2'><img src='assets/prod_images/$product_image' width='60px' height='60px'></div>
<div class='col-md-2'>$product_title</div>
<div class='col-md-2'><input class='form-control price' type='text' size='10px' pid='$pid' id='price-$pid' value='$product_price' disabled></div>
<div class='col-md-2'><input class='form-control qty' type='text' size='10px' pid='$pid' id='qty-$pid' value='$qty'></div>
<div class='col-md-2'><input class='total form-control price' type='text' size='10px' pid='$pid' id='amt-$pid' value='$total' disabled></div>
</div>
";
}
}
if(isset($_POST['cart_checkout'])){
echo "
<div class='row'>
<div class='col-md-8'></div>
<div class='col-md-4'>
<b>Total: $$total_amt</b>
</div>
</div>
";
}
}
}
if(isset($_POST['removeFromCart']))
{
$pid=$_POST['pid'];
$uid=$_SESSION['uid'];
$sql="DELETE FROM cart WHERE p_id='$pid' AND user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
if($run_query){
echo "
<div class='alert alert-danger' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Item removed from cart!
</div>
";
}
}
if(isset($_POST['updateProduct']))
{
$pid=$_POST['updateId'];
$uid=$_SESSION['uid'];
$qty=$_POST['qty'];
$price=$_POST['price'];
$total=$_POST['total'];
$sql="UPDATE cart SET qty='$qty', price='$price', total_amount='$total' WHERE p_id='$pid' AND user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
if($run_query){
echo "
<div class='alert alert-success' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Item updated!
</div>
";
}
}
if(isset($_POST['cartcount'])){
if(!(isset($_SESSION['uid']))){echo "0";}else{
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$count=mysqli_num_rows($run_query);
echo $count;
}
}
if(isset($_POST['payment_checkout'])){
echo 'Hii';
$uid=$_SESSION['uid'];
$sql="SELECT * FROM cart WHERE user_id='$uid'";
$run_query=mysqli_query($conn,$sql);
$i=rand();
while($cart_row=mysqli_fetch_array($run_query))
{
$sql2 = 'SELECT `p_qty`,`pid` FROM `customer_order` WHERE `id`="'.$cart_row['p_id'].'"';
$prorow = mysqli_fetch_array(mysqli_query($conn,$sql2));
if($prorow['p_qty'] <= 15)
{
$sql5 = 'SELECT `sm_id` FROM `products` WHERE `product_id`='.$prorow['pid'];
$rowpro = mysqli_fetch_array(mysqli_query($conn,$sql5));
$sql4 = 'SELECT `email`,`name` FROM `sales_manager` WHERE `id`='.$rowpro['sm_id'];
$smemail = mysqli_fetch_array(mysqli_query($conn,$sql4));
require_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
/*$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);*/
$body = "Dear ".$smemail['name']." <br> Product ".$cart_row['product_title']." Out Of Stock.";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl"; // enable SMTP authentication
$mail->Host = "smtp.gmail.com"; // sets the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server 465 587
$mail->IsHTML(true);
$mail->Mailer= "smtp";
$mail->Username = "[email protected]"; // SMTP account username
$mail->Password = "Gatu@1999"; // SMTP account password
$mail->SetFrom('[email protected]', 'Ceramika');
$mail->AddAddress($smemail['email']);
$mail->Subject = "Product is Out of Stock.";
//$mail->Body = "";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->Send();
}
$cart_prod_id=$cart_row['p_id'];
$cart_prod_title=$cart_row['product_title'];
$cart_qty=$cart_row['qty'];
$cart_price_total=$cart_row['total_amount'];
$sql2="INSERT INTO customer_order (uid,pid,p_name,p_price,p_qty,p_status,tr_id) VALUES ('$uid','$cart_prod_id','$cart_prod_title','$cart_price_total','$cart_qty','CONFIRMED','$i')";
$run_query2=mysqli_query($conn,$sql2);
}
$i++;
$sql3="DELETE FROM cart WHERE user_id='$uid'";
$run_query3=mysqli_query($conn,$sql3);
}
if(isset($_POST['product_detail'])){
$pid=$_POST['pid'];
$sql="SELECT * FROM products WHERE product_id='$pid'";
$run_query=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($run_query);
$pro_id=$row['product_id'];
$image=$row['product_image'];
$title=$row['product_title'];
$price=$row['product_price'];
$desc=$row['product_desc'];
$tags=$row['product_keywords'];
echo "
<div class='row'>
<div class='col-md-6'>
<img src='assets/prod_images/$image' class='img-thumbnail' style='width:250px;height:300px;'>
</div>
<div class='col-md-6'>
<div class='row'> <div class='col-md-12'><h1>$title</h1></div></div>
<div class='row'> <div class='col-md-12'>Price:<h3 class='text-muted'>$price</h3></div></div>
<div class='row'> <div class='col-md-12'>Description:<h4 class='text-muted'>$desc</h4></div></div><br><br>
<div class='row'> <div class='col-md-12'>Tags:<h4 class='text-muted'>$tags</h4></div></div>
<button pid='$pro_id' class='product btn btn-danger'>Add to Cart</button>
</div>
</div>
";
}
?>