forked from murtaza98/BookZone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.php
executable file
·75 lines (70 loc) · 3.27 KB
/
order.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
<?php ob_start(); ?>
<?php session_start(); ?>
<?php include "./templates/db.php"; ?>
<?php
if (isset($_GET['notification_id']) && isset($_GET['type']) && isset($_SESSION['username'])) {
$notification_id = $_GET['notification_id'];
$type = $_GET['type'];
$query = "SELECT * FROM notification WHERE notification_id = ".$notification_id;
$query_result = mysqli_query($connection,$query);
if(!$query_result){
die("QUERY FAILED ".mysqli_error($connection));
}else{
$row = mysqli_fetch_assoc($query_result);
$buyer_username = $row['buyer_name'];
$seller_username = $row['username'];
}
switch($type){
case "acceptOrder":
$query = "UPDATE notification SET offer_status = 'accepted' WHERE notification_id = {$notification_id}";
$message = "{$seller_username} has accepted your order";
$reply_query = "INSERT INTO notification(username,message,status,buyer_name,offer_status,date) VALUES('$buyer_username','$message','Unseen','$seller_username','reply',now())";
$mail_query = "SELECT email FROM users WHERE username = '{$buyer_username}'";
$mail_query_result = mysqli_query($connection,$mail_query);
if(!$mail_query_result){
die('QUERY FAILED '.mysqli_error($connection));
}else{
$row = mysqli_fetch_assoc($mail_query_result);
$email = $row['email'];
}
$message = wordwrap($message);
$subject = "Offer accepted";
mail($email, $subject, $message);
break;
case "declineOrder":
$query = "UPDATE notification SET offer_status = 'rejected' WHERE notification_id = {$notification_id}";
$message = "{$seller_username} has rejected your order";
$reply_query = "INSERT INTO notification(username,message,status,buyer_name,offer_status,date) VALUES('$buyer_username','$message','Unseen','$seller_username','reply',now())";
$mail_query = "SELECT email FROM users WHERE username = '{$buyer_username}'";
$mail_query_result = mysqli_query($connection,$mail_query);
if(!$mail_query_result){
die('QUERY FAILED '.mysqli_error($connection));
}else{
$row = mysqli_fetch_assoc($mail_query_result);
$email = $row['email'];
}
$message = wordwrap($message);
$subject = "Offer rejected";
mail($email, $subject, $message);
break;
default:
$query = null;
$reply_query = null;
break;
}
if($query != null && $reply_query != null){
$query_result = mysqli_query($connection,$query);
if(!$query_result){
die("QUERY FAILED ".mysqli_error($connection));
}else{
echo "update success";
}
$query_result = mysqli_query($connection,$reply_query);
if(!$query_result){
die("QUERY FAILED ".mysqli_error($connection));
}else{
echo "Reply success";
}
}
}
?>