-
Notifications
You must be signed in to change notification settings - Fork 3
/
query.php
137 lines (100 loc) · 3.96 KB
/
query.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
<?php
session_start();
//connect to database
require_once('db_connect.php');
//if confirm delete is clicked on modify
if (isset($_GET['trash'])) {
$bid = $_GET['trash'];
$sql="UPDATE books b SET b.trash='1' WHERE bid='$bid'";
mysqli_query($link,$sql);
$query = "update users set points=points-1 where id='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$query);
$_SESSION['points']--;
header('location: modify.php');
}
//if confirm delete is clicked on trash
else if (isset($_GET['del'])) {
$bid = $_GET['del'];
$sql="DELETE FROM books WHERE bid='$bid'";
mysqli_query($link,$sql);
header('location: trash.php');
}
//if confirm restore is clicked on trash
else if (isset($_GET['res'])) {
$bid = $_GET['res'];
$sql="UPDATE books b SET b.trash='0' WHERE bid='$bid'";
mysqli_query($link,$sql);
$query = "update users set points=points+1 where id='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$query);
$_SESSION['points']++;
header('location:trash.php');
}
//if request is clicked on search
else if(isset($_GET["request"])) {
$bid = $_GET['request'];
$to_user = $_GET['to_user'];
$sql = "insert into requests values('" . $bid . "','" . $_SESSION['user_id'] . "','" . $to_user . "',0,1,0)";
mysqli_query($link,$sql);
header('location:borrow.php');
}
//if request again is clicked on borrowed
else if(isset($_GET["request_again"])) {
$bid = $_GET['request_again'];
$to_user = $_GET['to_user'];
$sql = "delete from requests where bid='" . $bid . "' and from_user='" . $_SESSION['user_id'] . "' and to_user='" . $to_user . "'";
mysqli_query($link,$sql);
$sql = "insert into requests values('" . $bid . "','" . $_SESSION['user_id'] . "','" . $to_user . "',0,1,0)";
mysqli_query($link,$sql);
header('location:borrow.php');
}
//if return is clicked on borrow
else if(isset($_GET["return"])) {
$bid = $_GET['return'];
$to_user = $_GET['to_user'];
$sql = "delete from requests where bid='" . $bid . "' and from_user='" . $_SESSION['user_id'] . "' and to_user='" . $to_user . "'";
mysqli_query($link,$sql);
header('location:borrow.php');
}
//if accept is clicked on lent
else if(isset($_GET["accept"])) {
$bid=$_GET['accept'];
$from_user = $_GET['from_user'];
$sql="UPDATE requests SET sn=1,rn=0,status=1 WHERE bid='$bid' and from_user='$from_user' and to_user='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$sql);
$query = "update users set points=points+4 where id='" . $from_user . "'";
mysqli_query($link,$query);
$_SESSION['points'] += 4;
$query = "update users set points=points-2 where id='" . $to_user . "'";
mysqli_query($link,$query);
header('location:lent.php');
}
//if decline is clicked on lent
else if(isset($_GET["decline"])) {
$bid=$_GET['decline'];
$from_user = $_GET['from_user'];
$sql="UPDATE requests SET sn=1,rn=0,status=2 WHERE bid='$bid' and from_user='$from_user' and to_user='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$sql);
header('location:lent.php');
}
//if cancel is clicked on lent
else if(isset($_GET["cancel"])) {
$bid=$_GET['cancel'];
$from_user = $_GET['from_user'];
$sql="UPDATE requests r SET r.sn=0,r.rn=1,status=0 WHERE bid='$bid' and from_user='$from_user' and to_user='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$sql);
$query = "update users set points=points-4 where id='" . $from_user . "'";
mysqli_query($link,$query);
$_SESSION['points'] -= 4;
$query = "update users set points=points+2 where id='" . $to_user . "'";
mysqli_query($link,$query);
header('location:lent.php');
}
//if delete request is clicked on lent
else if(isset($_GET["delete"])) {
$bid=$_GET['delete'];
$from_user = $_GET['from_user'];
$sql="DELETE from requests WHERE bid='$bid' and from_user='$from_user' and to_user='" . $_SESSION['user_id'] . "'";
mysqli_query($link,$sql);
header('location:lent.php');
}
?>