-
Notifications
You must be signed in to change notification settings - Fork 2
/
abort.php
executable file
·213 lines (199 loc) · 8.12 KB
/
abort.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
<?php
session_start();
include_once "../php_lib/pdo.inc.php";
//include_once "../php_lib/erase.inc.php";
ob_start();
try{
//erase db from create_quiz_B.php
if (isset($_POST['abort']) && !empty($_POST['abort'])){
//erase SESSION if starting again from create_quiz.php
$_SESSION['debug'] = TRUE;
try{
$sql = 'DELETE FROM document
WHERE document.id = :document_id;
ALTER table simple_quiz.document AUTO_INCREMENT = 1;';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':document_id'=>$_SESSION['document.id']
));
}
catch (PDOexception $e){
include("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e,"../logs/error_log.csv");
}
$_SESSION['abort']="yes";
header( "Location: ../manage/app.php" );
}
//erase db from create_quiz_C.php
if (isset($_POST['abortb']) && !empty($_POST['abortb'])){
//erase SESSION if starting again from create_quiz.php
$_SESSION['debug'] = TRUE;
try{
$sql = 'DELETE simple_quiz.group
FROM simple_quiz.group
INNER JOIN document
ON group.id_document = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.group AUTO_INCREMENT = 1;
DELETE FROM document
WHERE document.id = :document_id;
ALTER table simple_quiz.document AUTO_INCREMENT = 1;
';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':document_id'=>$_SESSION['document.id']
));
}
catch (PDOexception $e){
include("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e,"../logs/error_log.csv");
}
$_SESSION['abort']="yes";
header( "Location: ../manage/app.php" );
}
//erase db from create_quiz_D.php
if (isset($_POST['abortc']) && !empty($_POST['abortc'])){
//use $_SESSION["group.id"] to obtain the id of the group
//erase SESSION if starting again from create_quiz.php
$_SESSION['debug'] = TRUE;
//bind $_SESSION["group.id"]
try{
$sql = '
DELETE simple_quiz.questions
FROM simple_quiz.questions
INNER JOIN simple_quiz.group
ON questions.id_group = group.id
WHERE group.id = :group_id;
ALTER table simple_quiz.questions AUTO_INCREMENT = 1;
DELETE simple_quiz.group
FROM simple_quiz.group
INNER JOIN document
ON group.id_document = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.group AUTO_INCREMENT = 1;
DELETE FROM document
WHERE document.id = :document_id;
ALTER table simple_quiz.document AUTO_INCREMENT = 1;
';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':group_id'=>$_SESSION["group.id"],
':document_id'=>$_SESSION['document.id']
));
}
catch (PDOexception $e){
include("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e,"../logs/error_log.csv");
}
$_SESSION['abort']="yes";
header( "Location: ../manage/app.php" );
}
//erase db from create_quiz_E.php
if (isset($_POST['abortd']) && !empty($_POST['abortd'])){
/*
check first if form is being submitted or not
using $_SESSION['form_submitted'] from create_quiz_E.php
*/
if (!$_SESSION['form_submitted']){
//erase SESSION if starting again from create_quiz.php
$_SESSION['debug'] = TRUE;
//first part is a double Join based on $_SESSION["group.id"];
try{
$sql = '
DELETE simple_quiz.choices
FROM simple_quiz.choices
INNER JOIN simple_quiz.questions
ON choices.id_questions = questions.id
INNER JOIN simple_quiz.group
ON questions.id_group = group.id
WHERE group.id = :group_id;
ALTER table simple_quiz.choices AUTO_INCREMENT = 1;
DELETE simple_quiz.questions
FROM simple_quiz.questions
INNER JOIN simple_quiz.group
ON questions.id_group = group.id
WHERE group.id = :group_id;
ALTER table simple_quiz.questions AUTO_INCREMENT = 1;
DELETE simple_quiz.group
FROM simple_quiz.group
INNER JOIN document
ON group.id_document = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.group AUTO_INCREMENT = 1;
DELETE FROM document
WHERE document.id = :document_id;
ALTER table simple_quiz.document AUTO_INCREMENT = 1;
';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':group_id'=>$_SESSION["group.id"],
':document_id'=>$_SESSION['document.id']
));
}
catch (PDOexception $e){
include("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e,"../logs/error_log.csv");
}
}
else{
try{
$sql = '
DELETE simple_quiz.randomness
FROM simple_quiz.randomness
INNER JOIN simple_quiz.document
ON randomness.id_titleR = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.randomness AUTO_INCREMENT = 1;
DELETE simple_quiz.percentage
FROM simple_quiz.percentage
INNER JOIN simple_quiz.document
ON percentage.id_titleP = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.percentage AUTO_INCREMENT = 1;
DELETE simple_quiz.choices
FROM simple_quiz.choices
INNER JOIN simple_quiz.questions
ON choices.id_questions = questions.id
INNER JOIN simple_quiz.group
ON questions.id_group = group.id
WHERE group.id = :group_id;
ALTER table simple_quiz.choices AUTO_INCREMENT = 1;
DELETE simple_quiz.questions
FROM simple_quiz.questions
INNER JOIN simple_quiz.group
ON questions.id_group = group.id
WHERE group.id = :group_id;
ALTER table simple_quiz.questions AUTO_INCREMENT = 1;
DELETE simple_quiz.group
FROM simple_quiz.group
INNER JOIN document
ON group.id_document = document.id
WHERE document.id = :document_id;
ALTER table simple_quiz.group AUTO_INCREMENT = 1;
DELETE FROM document
WHERE document.id = :document_id;
ALTER table simple_quiz.document AUTO_INCREMENT = 1;
';
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':document_id'=>$_SESSION['document.id'],
':group_id'=>$_SESSION["group.id"]
));
}
catch (PDOexception $e){
include("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e,"../logs/error_log.csv");
}
}
$_SESSION['abort']="yes";
header( "Location: ../manage/app.php" );
}
}//end try
catch(Exception $e) {
include ("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e, "../logs/error_log.csv");
}
catch(Error $e) {
include ("../php_lib/myExceptionHandling.inc.php");
echo myExceptionHandling($e, "../logs/error_log.csv");
}