-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuspendOneRequest.php
More file actions
78 lines (52 loc) · 2.09 KB
/
Copy pathsuspendOneRequest.php
File metadata and controls
78 lines (52 loc) · 2.09 KB
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include("credentials.php");
include ("functionSet.php");
$id = "";
$state = 'Suspended';
$position = -1;
//Query for ID and position
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("SELECT * FROM Queue WHERE Handling_By = :handling_by;");
$stmt->bindParam(':handling_by', $_SESSION['username']);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach ($rows as $row) {
$id = $row['rID'];
$position = $row['Position'];
}
if ($id == ""){
echo "<script type='text/javascript'> alert('The request has been canceled by the student!') </script>";
echo "<meta http-equiv='Refresh' content='0;URL=admin.php'>";
exit(0);
}
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error for ID and position query!') </script>";
echo "<meta http-equiv='Refresh' content='0;URL=admin.php'>";
exit(0);
}
//Delete queue
deleteQueueByHandling_By($_SESSION['username'], 'admin', $db_database, $db_username, $db_password, $db_host);
//Decrement position(s)
decrementPosition($position, "admin", $db_database, $db_username, $db_password, $db_host);
//Change request state
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("UPDATE Requests SET Handled_By = :handled_by, State = :state WHERE ID = :id;");
$stmt->bindParam(':handled_by', $_SESSION['username']);
$stmt->bindParam(':state', $state);
$stmt->bindParam(':id', $id);
$stmt->execute();
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error for request state change!') </script>";
echo "<meta http-equiv='Refresh' content='0;URL=admin.php'>";
exit(0);
}
echo "<meta http-equiv='Refresh' content='0;URL=admin.php'>";