-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.php
375 lines (310 loc) · 11.9 KB
/
library.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
<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<?php
$connection = new mysqli("185.98.131.90", "ferre941045", "HJ4NG32F", "ferre941045");
$error_flag = 0;
$result;
if ($connection->connect_error) {
die('connection failed: '.$connection->connect_error);
}
function secure($unsafe_data)
{
return htmlentities($unsafe_data);
}
function login($email_id_unsafe, $password_unsafe, $table = 'users')
{
global $connection;
$email_id = secure($email_id_unsafe);
$password = secure($password_unsafe);
$sql = "SELECT COUNT(*) FROM $table WHERE email = '$email_id' AND password = '$password';";
$result = $connection->query($sql);
$num_rows = (int) $result->fetch_array()['0'];
if ($num_rows > 1) {
//send email to sysadmin that my site has been hacked
return 0;
} elseif ($num_rows == 0) {
echo status('no-match');
return 0;
} else {
echo "<div class='alert alert-success'> <strong>Well done!</strong> Logged In</div>";
$_SESSION['username'] = $email_id;
if ($table == 'admin') {
$_SESSION['user-type'] = 'admin';
}
if ($table == 'users' || $table == 'doctors' || $table == 'clerks') {
$sql = "SELECT fullname FROM $table WHERE email = '$email_id' AND password = '$password';";
$result = $connection->query($sql);
$fullname = $result->fetch_array()['fullname'];
$_SESSION['fullname'] = $fullname;
if ($table == 'users') {
$_SESSION['user-type'] = 'normal';
} elseif ($table == 'clerks') {
$_SESSION['user-type'] = 'clerk';
} else {
$_SESSION['user-type'] = 'doctor';
}
}
return 1;
}
}
function register($email_id_unsafe, $password_unsafe, $full_name_unsafe, $speciality_unsafe = 'doctor', $table = 'users')
{
global $connection,$error_flag;
$email = secure($email_id_unsafe);
$password = secure($password_unsafe);
$speciality = secure($speciality_unsafe);
$fullname = ucfirst(secure($full_name_unsafe));
$sql;
switch ($table) {
case 'users':
$sql = "INSERT INTO $table VALUES ('$email', '$password', '$fullname');";
break;
case 'doctors':
$sql = "INSERT INTO $table VALUES ('$email', '$password', '$fullname','$speciality');";
break;
case 'clerks':
$sql = "INSERT INTO $table VALUES ('$email', '$password', '$fullname');";
break;
default:
// code...
break;
}
if ($connection->query($sql) === true) {
echo status('record-success');
if ($table == 'users' && $error_flag == 0) {
return login($email, $password);
}
} else {
echo status('record-fail');
}
}
function status($type, $data = 0)
{
$success = "<div class='alert alert-success'> <strong>Done!</strong>";
$fail = "<div class='alert alert-warning'><strong>Sorry!</strong>";
$end = '</div>';
switch ($type) {
case 'record-success':
return "$success New record created successfully! $end";
break;
case 'record-fail':
return "$fail New record creation failed. $end";
break;
case 'record-dup':
return "$fail Duplicate record exists. $end";
break;
case 'no-match':
return "$fail Record did not match. $end";
break;
case 'con-failed':
return "$fail connection Failed! $end";
break;
case 'appointment-success':
return "$success Your appointment is booked successfully! Your appointment no is $data $end";
break;
case 'appointment-fail':
return "$fail Failed to book your appointment Failed! $end";
break;
case 'update-success':
return "$success New record updated successfully! $end";
break;
case 'update-fail':
return "$fail Failed to update data! $end";
break;
default:
// code...
break;
}
}
function enter_patient_info($full_name_unsafe, $age_unsafe, $Convenio_unsafe, $phone_no_unsafe, $address_unsafe)
{
global $connection, $error_flag,$result;
$full_name = ucfirst(secure($full_name_unsafe));
$age = secure($age_unsafe);
$Convenio = secure($Convenio_unsafe);
$phone_no = secure($phone_no_unsafe);
$address = secure($address_unsafe);
$sql = "INSERT INTO `patient_info` VALUES (NULL, '$full_name', $age, '$Convenio', '$phone_no','$address');";
if ($connection->query($sql) === true) {
echo status('record-success');
return $connection->insert_id;
} else {
echo status('record-fail');
return 0;
}
}
function appointment_booking($patient_id_unsafe, $specialist_unsafe,$specialist_corpo_unsafe, $medical_condition_unsafe)
{
global $connection;
$patient_id = secure($patient_id_unsafe);
$specialist = secure($specialist_unsafe);
$corpo = secure($specialist_corpo_unsafe);
$medical_condition = secure($medical_condition_unsafe);
$sql = "INSERT INTO appointments (`appointment_no`, `patient_id`, `speciality`, `corpo`, `medical_condition`, `doctors_suggestion`,`payment_amount`, `case_closed`) VALUES (NULL, $patient_id, '$specialist', '$corpo', '$medical_condition', NULL, NULL, 'no')";
if ($connection->query($sql) === true) {
echo status('appointment-success', $connection->insert_id);
} else {
echo status('appointment-fail');
echo 'Error: '.$sql.'<br>'.$connection->error;
}
}
function update_appointment_info($appointment_no_unsafe, $column_name_unsafe, $data_unsafe)
{
global $connection;
$sql;
$appointment_no = (int) secure($appointment_no_unsafe);
$column_name = secure($column_name_unsafe);
$data = secure($data_unsafe);
if ($column_name == 'payment_amount') {
$data = (int) $data;
$sql = "UPDATE `appointments` SET `payment_amount` = '$data', `case_closed` = 'no' WHERE appointment_no` = $appointment_no";
} else {
$sql = "UPDATE appointments SET $column_name = '$data' WHERE appointment_no = $appointment_no;";
}
echo $sql;
if ($connection->query($sql) === true) {
echo status('update-success');
return 1;
} else {
echo status('update-fail');
echo 'Error: '.$sql.'<br>'.$connection->error;
return 0;
}
}
function getPatientsFor($doctor = 'Dentist')
{
global $connection;
return $connection->query("SELECT appointment_no, full_name, medical_condition FROM patient_info, appointments where speciality='$doctor' AND patient_info.patient_id = appointments.patient_id");
}
function getAllAppointments()
{
global $connection;
return $connection->query('SELECT appointment_no, full_name,speciality, medical_condition ,corpo FROM patient_info, appointments where patient_info.patient_id = appointments.patient_id');
}
function getAllPatientDetail($appointment_no)
{
global $connection;
return $connection->query("SELECT appointment_no, full_name, dob, convenio, phone_no, address, medical_condition FROM patient_info, appointments where appointment_no=$appointment_no AND patient_info.patient_id = appointments.patient_id;");
}
function get_table($purpose, $data)
{
global $connection;
$sql;
switch ($purpose) {
case 'patient_information':
$sql = 'SELECT * FROM patient_info AND (SELECT )';
break;
case 'doctor-home':
$sql = '';
$result = $connection->query($sql);
echo "<table border='1'>
<tr>
<th>appointment_no</th>
<th>patient_name</th>
<th>age</th>
<th>appointment_time</th>
<th>medical_condition</th>
<th>option</th>
</tr>";
while ($row = $result->fetch_array()) {
echo '<tr>';
echo '<td>'.$row['appointment_no'].'</td>';
echo '<td>'.$row['full_name'].'</td>';
echo '<td>'.$row['age'].'</td>';
echo '<td>'.$row['appointment_time'].'</td>';
echo '<td>'.$row['medical_condition'].'</td>';
echo "<td> <button class='btn btn-primary'> Open Case</button> <button class='btn btn-primary'> Close Case</button> </td>";
echo '</tr>';
}
echo '</table>';
break;
case 'all':
$sql = 'SELECT * FROM patient_info AND (SELECT )';
break;
case 'patient_information':
$sql = 'SELECT * FROM patient_info AND (SELECT )';
break;
default:
// code...
break;
}
}
function appointment_status($appointment_no_unsafe)
{
global $connection;
$appointment_no = secure($appointment_no_unsafe);
$i = 0;
$result = $connection->query("SELECT doctors_suggestion FROM appointments WHERE appointment_no=$appointment_no;");
if ($result === false) {
return 0;
} else {
++$i;
}
$result = $connection->query('SELECT payment_amount FROM appointments WHERE appointment_no=appointment_no;');
if ($result->num_rows == 1) {
++$i;
}
return $i;
}
function delete($table, $id_unsafe)
{
global $connection;
$id = secure($id_unsafe);
return $connection->query("DELETE FROM $table WHERE email='$id';");
}
function getListOfEmails($table)
{
global $connection;
return $connection->query("SELECT email FROM $table;");
}
function noAccessForNormal()
{
if (isset($_SESSION['user-type'])) {
if ($_SESSION['user-type'] == 'normal') {
echo '<script type="text/javascript">window.location = "add_patient.php"</script>';
}
}
}
function noAccessForDoctor()
{
if (isset($_SESSION['user-type'])) {
if ($_SESSION['user-type'] == 'doctor') {
echo '<script type="text/javascript">window.location = "patient_info.php"</script>';
}
}
}
function noAccessForClerk()
{
if (isset($_SESSION['user-type'])) {
if ($_SESSION['user-type'] == 'clerk') {
echo '<script type="text/javascript">window.location = "all_appointments.php"</script>';
}
}
}
function noAccessForAdmin()
{
if (isset($_SESSION['user-type'])) {
if ($_SESSION['user-type'] == 'admin') {
echo '<script type="text/javascript">window.location = "admin_home.php"</script>';
}
}
}
function noAccessIfLoggedIn()
{
if (isset($_SESSION['user-type'])) {
noAccessForNormal();
noAccessForAdmin();
noAccessForClerk();
noAccessForDoctor();
}
}
function noAccessIfNotLoggedIn()
{
if (!isset($_SESSION['user-type'])) {
echo '<script type="text/javascript">window.location = "index.php"</script>';
}
}
?>