-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_script.php
161 lines (159 loc) · 5.92 KB
/
request_script.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
<?php
sleep(2);
session_start();
$con= new PDO("mysql:host=localhost;dbname=student_clearance", "root","");
$message = '';
$error = '';
if ($_POST['cl_request'] === '1') {
$stmt = $con->prepare("SELECT COUNT(*) FROM clearance_apply WHERE student_id = :user_id");
$stmt->execute([
':user_id' => $_SESSION['ID']
]);
$count = $stmt->fetchColumn();
if ($count > 0) {
$stmtReq = $con->prepare("UPDATE clearance_apply SET is_accademic_head = :is_accademic WHERE student_id = :student_id");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_accademic' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
} else {
$stmtReq = $con->prepare("INSERT INTO clearance_apply (student_id,is_accademic_head) VALUES (:student_id,:is_accademic)");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_accademic' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
}
} else if ($_POST['cl_request'] === '2') {
$stmt = $con->prepare("SELECT COUNT(*) FROM clearance_apply WHERE student_id = :user_id");
$stmt->execute([
':user_id' => $_SESSION['ID']
]);
$count = $stmt->fetchColumn();
if ($count > 0) {
$stmtReq = $con->prepare("UPDATE clearance_apply SET is_faculty = :is_faculty WHERE student_id = :student_id");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_faculty' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
} else {
$stmtReq = $con->prepare("INSERT INTO clearance_apply (student_id,is_faculty) VALUES (:student_id,:is_faculty)");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_faculty' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
}
} else if ($_POST['cl_request'] === '3') {
$stmt = $con->prepare("SELECT COUNT(*) FROM clearance_apply WHERE student_id = :user_id");
$stmt->execute([
':user_id' => $_SESSION['ID']
]);
$count = $stmt->fetchColumn();
if ($count > 0) {
$stmtReq = $con->prepare("UPDATE clearance_apply SET is_dip_library = :is_dip_library WHERE student_id = :student_id");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_dip_library' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
} else {
$stmtReq = $con->prepare("INSERT INTO clearance_apply (student_id,is_dip_library) VALUES (:student_id,:is_dip_library)");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_dip_library' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
}
} else if ($_POST['cl_request'] === '4') {
$stmt = $con->prepare("SELECT COUNT(*) FROM clearance_apply WHERE student_id = :user_id");
$stmt->execute([
':user_id' => $_SESSION['ID']
]);
$count = $stmt->fetchColumn();
if ($count > 0) {
$stmtReq = $con->prepare("UPDATE clearance_apply SET is_kill = :is_kill WHERE student_id = :student_id");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_kill' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
} else {
$stmtReq = $con->prepare("INSERT INTO clearance_apply (student_id,is_kill) VALUES (:student_id,:is_kill)");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_kill' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
}
} else if ($_POST['cl_request'] === '5') {
$stmt = $con->prepare("SELECT COUNT(*) FROM clearance_apply WHERE student_id = :user_id");
$stmt->execute([
':user_id' => $_SESSION['ID']
]);
$count = $stmt->fetchColumn();
if ($count > 0) {
$stmtReq = $con->prepare("UPDATE clearance_apply SET is_sport = :is_sport WHERE student_id = :student_id");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_sport' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
} else {
$stmtReq = $con->prepare("INSERT INTO clearance_apply (student_id,is_sport) VALUES (:student_id,:is_sport)");
$stmtReq->execute([
':student_id' => $_SESSION['ID'],
':is_sport' => 1
]);
if ($stmtReq) {
$message = "Request Sent";
} else {
$error = "An error occurred";
}
}
}
// For example, you can create a response array
$response = array(
'message' => $message,
'error' => $error
);
echo json_encode($response);
?>