-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowdeletestudents.php
309 lines (301 loc) · 11.7 KB
/
showdeletestudents.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
//Include config.php which contains db details and connects to the db)
require_once("includes/config.php");
require_once("includes/getuser.php");
require_once("includes/isauthor.php");
require_once("includes/limitstring.php");
require_once("includes/ODBCDateToTextDate.php");
if (isset($_POST['delete']))
{
$surveyID = $_POST['hSurveyID'];
$instanceID = $_POST['hSurveyInstanceID'];
//Find out ids of all the checkboxes which were checked
$aStudents = $_POST['checkHeraldIDs'];
for ($i=0;$i<count($aStudents);$i++)
{
//first get answerIDs from Answers
$qAnswers = " SELECT answerID
FROM Answers
WHERE surveyInstanceID = $instanceID
AND heraldID = '$aStudents[$i]'";
$qResAnswers = mysqli_query($db_connection, $qAnswers);
if (($qResAnswers == false))
{
echo "problem querying Answers" . mysqli_error($db_connection);
}
else
{
while($rowAnswers = mysqli_fetch_array($qResAnswers))
{
//delete comments, items and dates where answerID is associated with herald and surveyinstance in answers table
//delete comments
$delComments = " DELETE FROM AnswerComments
WHERE answerID = $rowAnswers[answerID]";
$delResComments = @mysqli_query($db_connection,$delComments);
if (($delResComments == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from AnswerComments " . mysqli_error($db_connection);
}
//delete items
$delItems = " DELETE FROM AnswerItems
WHERE answerID = $rowAnswers[answerID]";
$delResItems = @mysqli_query($db_connection,$delItems);
if (($delResItems == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from AnswerItems " . mysqli_error($db_connection);
}
//delete dates
$delDates = " DELETE FROM AnswerDates
WHERE answerID = $rowAnswers[answerID]";
$delResDates = @mysqli_query($db_connection,$delDates);
if (($delResDates == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from AnswerDates " . mysqli_error($db_connection);
}
}
}
//then delete from Answers
$delAnswers = " DELETE FROM Answers
WHERE surveyInstanceID = $instanceID
AND heraldID = '$aStudents[$i]'";
$delResAnswers = @mysqli_query($db_connection,$delAnswers);
if (($delResAnswers == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from Answers " . mysqli_error($db_connection);
}
//then finally delete from SurveyInstanceParticipants
//then delete from Answers
$delSIP = " DELETE FROM SurveyInstanceParticipants
WHERE surveyInstanceID = $instanceID
AND heraldID = '$aStudents[$i]'";
$delResSIP = @mysqli_query($db_connection, $delSIP);
if (($delResSIP == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from SurveyInstanceParticipants " . mysqli_error($db_connection);
}
}
}
elseif(isset($_POST['bShowStudents']))
{
//extract data from viewstudents.php
$surveyID = $_POST['surveyID'];
$instanceID = $_POST['sSchedule'];
echo "<title>$surveyTitle - Students</title>";
}
else
{
echo "This page requires input from another page. Please go to <a href=\"deletestudents.php\">deletestudents.php</a>";
exit;
}
//Get survey information
$qSurveys = "SELECT title
FROM Surveys
WHERE surveyID = $surveyID";
$qResSurvey = mysqli_query($db_connection, $qSurveys);
$rowSurvey = mysqli_fetch_array($qResSurvey);
$surveyTitle = $rowSurvey['title'];
$qSurveyInstances = "SELECT title, startDate, finishDate
FROM SurveyInstances
WHERE surveyInstanceID = $instanceID";
$qResSurveyInstance = mysqli_query($db_connection, $qSurveyInstances);
$rowSurveyInstance = mysqli_fetch_array($qResSurveyInstance);
$surveyInstanceTitle = $rowSurveyInstance['title'];
$surveyInstanceStartDate = $rowSurveyInstance['startDate'];
$surveyInstanceFinishDate = $rowSurveyInstance['finishDate'];
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/SurveyStyles.css">
<link rel="stylesheet" type="text/css" href="css/msdstyle2.css" media="screen"/>
<link href="css/msdprint.css" rel="stylesheet" type="text/css" media="print" />
</head>
<body>
<?php
if(IsAuthor($heraldID))
{
require_once("includes/html/adminheadernew.html");
require_once("includes/html/BreadCrumbsHeader.html");
echo "<a href=\"results.php\">Results</a> > <a href=\"deletestudents.php\">Delete Results</a> > $surveyInstanceTitle - Delete Results";
require_once("includes/html/BreadCrumbsFooter.html");
}
else
{
require_once("includes/html/header.html");
echo "You do not have the necessary permissions to view this page";
exit();
}
echo "<h1>$surveyInstanceTitle - Delete Results</h1>";
echo "<a name=\"maintext\" id=\"maintext\"></a>";
$qStudents = " SELECT DISTINCT SurveyInstanceParticipants.heraldID
FROM SurveyInstanceParticipants, SurveyInstances
WHERE SurveyInstances.surveyID = $surveyID
AND SurveyInstanceParticipants.surveyInstanceID = SurveyInstances.surveyInstanceID ".
($instanceID!=0?" AND SurveyInstances.surveyInstanceID = $instanceID" : "");
$qResStudents = @mysqli_query($db_connection, $qStudents);
if (($qResStudents == false))
{
echo "problem querying SurveyInstanceParticipants" . mysqli_error($db_connection);
}
else
{
echo "<h2>Total number of students = ".mysqli_num_rows($qResStudents)."</h2>";
if(mysqli_num_rows($qResStudents)>0)
{
//Prevents one student's answers being associated with them
echo "<form id=\"frmDelete\" name=\"frmDelete\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">
<table class=\"matrix\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo " <tr class=\"matrixHeader\">
<td class=\"question\"> </td>
<td class=\"question\">heraldID</td>
<td class=\"question\">Name</td>
</tr>";
$bRowOdd = true;
while($rowStudents = mysqli_fetch_array($qResStudents))
{
$studentHeraldID = $rowStudents['heraldID'];
if($bRowOdd)
{
$rowClass = "matrixRowOdd";
}
else
{
$rowClass = "matrixRowEven";
}
echo " <tr class=\"$rowClass\">
<td>
<input type=\"checkbox\" id=\"check_$studentHeraldID\" name=\"checkHeraldIDs[]\" value=\"$studentHeraldID\"/>
</td>
<td>".$rowStudents['heraldID']."</td>
<td>";
//connect to heraldID and name database
//$dbstudent_connection = mysql_connect ($dbstudent_info['host'], $dbstudent_info['username'], $dbstudent_info['password']) or die (mysql_error());
//$db_select = mysql_select_db ($dbstudent_info['dbname'], $dbstudent_connection) or die (mysql_error());
$dbstudent_connection = mysqli_connect ($dbstudent_info['host'], $dbstudent_info['username'], $dbstudent_info['password'], $dbstudent_info['dbname']) or die (mysqli_error());
$qStudentName = " SELECT LASTNAME, FORENAMES
FROM cards
WHERE USERNAME = '".$rowStudents['heraldID']."'";
$qResStudentName = @mysqli_query($dbstudent_connection, $qStudentName);
if (($qResStudentName == false))
{
echo "problem querying cards" . mysqli_error($dbstudent_connection);
}
else
{
if (mysqli_num_rows($qResStudentName)==1)
{
$rowStudentName = mysqli_fetch_array($qResStudentName);
echo $rowStudentName['LASTNAME'] . ", " . $rowStudentName['FORENAMES'];
}
else
{
echo "Name not found";
}
}
mysqli_close($dbstudent_connection);
//$db_connection = mysqli_connect ($db_info['host'], $db_info['username'], $db_info['password']) or die (mysqli_error());
//$db_select = mysqli_select_db ($db_info['dbname'], $db_connection) or die (mysqli_error($db_connection));
$db_connection = mysqli_connect ($db_info['host'], $db_info['username'], $db_info['password'], $db_info['dbname']) or die (mysqli_error());
echo"</td>
</tr>";
$bRowOdd = !$bRowOdd;
}
echo "<tr>
<td colspan=\"3\">
<input type=\"hidden\" id=\"hSurveyInstanceID\" name=\"hSurveyInstanceID\" value = \"$instanceID\"/>
<input type=\"hidden\" id=\"hSurveyID\" name=\"hSurveyID\" value = \"$surveyID\"/>
<input type=\"submit\" id=\"delete\" name=\"delete\" value=\"Delete\" onclick=\"return checkCheckBoxes()\"/>
</td>
</tr>";
echo"
</table>
</form>";
}
}
echo " <script language=\"JavaScript\" type=\"text/javascript\" >
function checkCheckBoxes()
{
var iNoOfStudents = 0;
var aStudents = new Array();";
//resets the mysql_fetch_array to start at the beginning again
idata_seek($qResStudents, 0);
while($rowStudents = mysqli_fetch_array($qResStudents))
{
$studentHeraldID = $rowStudents['heraldID'];
//connect to heraldID and name database
//$dbstudent_connection = mysqli_connect ($dbstudent_info['host'], $dbstudent_info['username'], $dbstudent_info['password']) or die (mysqli_error());
//$db_select = mysqli_select_db ($dbstudent_info['dbname'], $dbstudent_connection) or die (mysqlii_error($dbstudent_connection));
$dbstudent_connection= mysqli_connect ($dbstudent_info['host'], $dbstudent_info['username'], $dbstudent_info['password'], $dbstudent_info['dbname']) or die (mysqli_error());
$qStudentName = " SELECT LASTNAME, FORENAMES
FROM cards
WHERE USERNAME = '".$rowStudents['heraldID']."'";
$qResStudentName = @mysqli_query($dbstudent_connection, $qStudentName);
if (($qResStudentName == false))
{
echo "problem querying cards" . mysqli_error($dbstudent_connection);
}
else
{
if (mysqli_num_rows($qResStudentName)==1)
{
$rowStudentName = mysqli_fetch_array($qResStudentName);
$studentName = $rowStudentName['LASTNAME'] . ", " . $rowStudentName['FORENAMES'];
}
else
{
$studentName = "Name not found";
}
}
mysqli_close($dbstudent_connection);
//$db_connection = mysqli_connect ($db_info['host'], $db_info['username'], $db_info['password']) or die (mysqli_error());
//$db_select = mysqli_select_db ($db_info['dbname'], $db_connection) or die (mysqli_error($db_connection));
$db_connection = mysqli_connect ($db_info['host'], $db_info['username'], $db_info['password'], $db_info['dbname']) or die (mysqli_error());
echo " if (document.getElementById(\"check_$studentHeraldID\").checked == true)
{
iNoOfStudents=iNoOfStudents+1;
aStudents[iNoOfStudents] = \"$studentHeraldID - $studentName\";
}";
}
echo " if (iNoOfStudents == 0)
{
alert(\"Please select a student whose results you want to delete.\");
return false;
}
else
{
if (iNoOfStudents == 1)
{
var confirmText = \"Are you sure you want to permanently delete all the results for \" + aStudents[iNoOfStudents] + \" for schedule $surveyInstanceTitle?\";
}
else
{
var confirmText = \"Are you sure you want to permanently delete all the results for these \" + iNoOfStudents + \" students for schedule $surveyInstanceTitle?\";
}
var answer = confirm (confirmText);
if (answer)
{
return true;
}
else
{
return false;
}
}
}
</script>";
?>
<?php
//Breadcrumb
if(IsAuthor($heraldID))
{
require_once("includes/html/BreadCrumbsHeader.html");
echo "<a href=\"results.php\">Results</a> > <a href=\"deletestudents.php\">Delete Results</a> > $surveyInstanceTitle - Delete Results";
require_once("includes/html/BreadCrumbsFooter.html");
}
//footer - including contact info.
require_once("includes/html/footernew.html");
require_once("includes/instructions/inst_showdeletestudents.php");
?>
</body>
</html>