-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateDBNotifications.php
116 lines (75 loc) · 4 KB
/
updateDBNotifications.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
<?php
require_once('functions.php');
connectdb();
$type = $_POST["type"];
$slno = $_POST["serialNo"];
if($type=="1"){
$query = 'SELECT * from notifications WHERE slno="'.$slno.'"';
$result = mysql_query($query) or die("error!!!");
$stat = $_POST["stat"];
$row = mysql_fetch_array($result);
$sender = $row["sender"];
$receiver= $row["receiver"];
$newType=3;
$newStatus=$stat;
$cid=$row["cid"];
$timeStamp = date("Y-m-d H:i:s");
$query = 'UPDATE notifications SET status="' .$stat. '" WHERE slno="' .$slno. '"';
$result = mysql_query($query) or die("error!!!");
$query = 'INSERT INTO notifications(sender,receiver,type,cid,timestamp,status) VALUES ("'.$receiver.'","'.$sender.'","'.$newType.'","'.$cid.'","'.$timeStamp.'","'.$newStatus.'")';
$result = mysql_query($query) or die("error!!!");
if($stat=="Approved"){
$query = 'SELECT people from offers WHERE id="'.$cid.'"';
$result = mysql_query($query) or die("error!!!");
$row = mysql_fetch_array($result);
$noOfPeople = (int)$row["people"]-1;
$query = 'UPDATE offers SET people ="' .$noOfPeople .'" WHERE id="' .$cid. '"';
$result = mysql_query($query) or die("error!!!");
$query = 'SELECT * from offers WHERE id="'.$cid.'"';
$result = mysql_query($query) or die("error!!!");
$row = mysql_fetch_array($result);
$source = $row["from"];
$dest = $row["to"];
$query = 'SELECT * from cities WHERE city_name="'.$source.'"';
$result = mysql_query($query) or die("error!!!");
$row = mysql_fetch_array($result);
$sourceLat= $row["latitude"];
$sourceLon =$row["longitude"];
$query = 'SELECT * from cities WHERE city_name="'.$dest.'"';
$result = mysql_query($query) or die("error!");
$row = mysql_fetch_array($result);
$destLat= $row["latitude"];
$destLon =$row["longitude"];
$distance = sqrt(pow(((float)$destLat -(float)$sourceLat) , 2)+ pow(((float)$destLon -(float)$sourceLon) , 2));
$query = 'SELECT credits from users WHERE uid="'.$sender.'"';
$result = mysql_query($query) or die("error!!!");
$row = mysql_fetch_array($result);
$senderCredits = (float)($distance) + (float)($row["credits"]);
$query = 'UPDATE users SET credits="' .$senderCredits .'" WHERE uid="' .$sender. '"';
$result = mysql_query($query) or die("error!!!3");
/*************************/
$query = 'SELECT credits from users WHERE uid="'.$receiver.'"';
$result = mysql_query($query) or die("error!!!1");
$row = mysql_fetch_array($result);
$receiverCredits = (float)($distance) + (float)($row["credits"]);
$query = 'UPDATE users SET credits ="' .$receiverCredits .'" WHERE uid="' .$receiver. '"';
$result = mysql_query($query) or die("error!!!2");
}
}
else if($type=="2"){
// change the parameter in notification table
// create one more notification
// update offers
$query = 'SELECT * from notifications WHERE slno="'.$slno.'"';
$result = mysql_query($query) or die("error!!!");
$comment = $_POST["rating"];
$row = mysql_fetch_array($result);
$receiver = $row["receiver"];
$cid = $row["cid"];
$query = 'INSERT INTO comments(sender,comment,cid) VALUES ("'.$receiver.'","'.$comment.'","'.$cid.'")';
$result = mysql_query($query) or die("error!!!");
$query = 'DELETE FROM notifications WHERE slno="'.$slno.'"';
$result = mysql_query($query) or die("error!!!");
echo "YO man!";
}
?>