-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteSession.php
executable file
·91 lines (74 loc) · 2.89 KB
/
deleteSession.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
<?php
require_once ('control/connection.php');
// include('classes/InstructionSession.php');
// include('classes/User.php');
require_once('control/startSession.php');
if ($_POST) {
if (isset($_POST['inID']) && is_numeric($_POST['inID'])) {
$inID = $_POST['inID'];
} else {
die('Non-numeric or nonexistant session ID!');
}
$output = 'Deleting session '.$inID.'...<br/>';
try {
mysqli_autocommit($dbc, false);
$stmt = mysqli_prepare($dbc, 'delete from outcomesassessed where otcaotctID in (select otctID from outcomestaught where otctsesdID=?)');
mysqli_stmt_bind_param($stmt, 'i', $inID);
if (mysqli_stmt_execute($stmt)) {
$output .= 'Outcomes assessed prepared for deletion<br/>';
} else {
throw new Exception('Failed to prepare outcomes assessed for deletion: ' . $stmt->error);
}
$stmt = mysqli_prepare($dbc, 'delete from outcomestaught where otctsesdID=?');
mysqli_stmt_bind_param($stmt, 'i', $inID);
if (mysqli_stmt_execute($stmt)) {
$output .= 'Outcomes taught prepared for deletion<br/>';
} else {
throw new Exception('Failed to prepare outcomes taught for deletion: ' . $stmt->error);
}
$stmt = mysqli_prepare($dbc, 'delete from resourcesintroduced where rsrisesdID=?');
mysqli_stmt_bind_param($stmt, 'i', $inID);
if (mysqli_stmt_execute($stmt)) {
$output .= 'Resources introduced prepared for deletion<br/>';
} else {
throw new Exception('Failed to prepare resources introduced for deletion: ' . $stmt->error);
}
$stmt = mysqli_prepare($dbc, 'delete from sessionnotes where sesnsesdID=?');
mysqli_stmt_bind_param($stmt, 'i', $inID);
if (mysqli_stmt_execute($stmt)) {
$output .= 'Session notes prepared for deletion<br/>';
} else {
throw new Exception('Failed to prepare session notes for deletion: ' . $stmt->error);
}
$stmt = mysqli_prepare($dbc, 'delete from sessiondesc where sesdID=?');
mysqli_stmt_bind_param($stmt, 'i', $inID);
if (mysqli_stmt_execute($stmt)) {
$output .= 'Session description prepared for deletion<br/>';
} else {
throw new Exception('Failed to prepare session description for deletion: ' . $stmt->error);
}
if (mysqli_commit($dbc)) {
$output .= 'Successfully deleted.<br/>';
} else {
throw new Exception('Failed to delete session and associated data: ' . mysqli_error($dbc));
}
mysqli_autocommit($dbc, true);
} catch (Exception $e) {
mysqli_rollback($dbc);
mysqli_autocommit($dbc, true);
die('Error: ' . $e->getMessage());
}
$_SESSION['dialogText'] = $output;
$_SESSION['dialogTitle'] = "Result";
//echo $output;
header('Location: mySessions.php');
exit();
}
$sesdID = htmlspecialchars($_GET['sesdID']);
echo '
<form method="post" action="deleteSession.php">
Really delete session '.$sesdID.'?
<input type="hidden" value="'.$sesdID.'" name="inID">
<input type="submit">
</form>';
?>