-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedulesurvey.php
227 lines (221 loc) · 6.92 KB
/
schedulesurvey.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Administration</title>
<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" />
<script language="javascript" type="text/javascript">
function goTo(URL)
{
window.location.href = URL;
}
</script>
</head>
<body>
<?php
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");
?>
<?php
if(isset($_GET['surveyID']))
{
//from editsection.php or editquestion.php
$surveyID = $_GET['surveyID'];
}
elseif (isset($_POST['delete']))
{
if(isset($_POST['hSurveyID']))
{
$surveyID = $_POST['hSurveyID'];
//Find out ids of all the checkboxes which were checked
$aInstances = $_POST['checkSurveyInstances'];
for ($i=0;$i<count($aInstances);$i++)
{
$delInstances = " DELETE FROM SurveyInstances
WHERE surveyInstanceID = $aInstances[$i]";
$result_query = @mysqli_query($db_connection, $delInstances);
if (($result_query == false) && mysqli_affected_rows($db_connection) == 0)
{
echo "problem deleting from Instancess" . mysqli_error($db_connection);
}
}
}
}
else
{
echo "<h1>Warning</h1>
<p>This page requires data from another form.</p>";
exit();
}
//Get info about survey
$qSurveys = "SELECT title
FROM Surveys
WHERE surveyID = $surveyID";
$qResSurvey = mysqli_query($db_connection, $qSurveys);
$rowSurvey = mysqli_fetch_array($qResSurvey);
$surveyTitle = $rowSurvey['title'];
if(IsAuthor($heraldID))
{
require_once("includes/html/adminheadernew.html");
require_once("includes/html/BreadCrumbsHeader.html");
echo "
<a href=\"admin.php\">Administration</a> >
Schedule survey: ".limitString($surveyTitle,30)."";
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 "<a name=\"maintext\" id=\"maintext\"></a>
<h1>Schedule: $surveyTitle</h1>";
if (isset($_GET['orderBy']))
{
$orderBy = $_GET['orderBy'];
$qSurveyInstances = " SELECT surveyInstanceID, title, startDate, finishDate
FROM SurveyInstances
WHERE surveyID = $surveyID
ORDER BY $orderBy";
}
else
{
$qSurveyInstances = " SELECT surveyInstanceID, title, startDate, finishDate
FROM SurveyInstances
WHERE surveyID = $surveyID
ORDER BY startDate";
}
$qResSurveyInstances = mysqli_query($db_connection, $qSurveyInstances);
if (($qResSurveyInstances == false))
{
echo "problem querying SurveyInstances" . mysqli_error($db_connection);
}
else
{
echo " <div class=\"questionNormal\">
<form id=\"frmDelete\" name=\"frmDelete\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">
<table class=\"matrix\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">
<tr class=\"matrixHeader\">
<th></th>
<th>Title</th>
<th>
<a href=\"".$_SERVER['PHP_SELF']."?orderBy=startDate&surveyID=$surveyID\">Start Date</a>
</th>
<th>
<a href=\"".$_SERVER['PHP_SELF']."?orderBy=finishDate&surveyID=$surveyID\">Finish Date</a>
</th>
<th></th>
</tr>";
$bRowOdd = true;
while($rowSurveyInstances = mysqli_fetch_array($qResSurveyInstances))
{
$surveyInstanceTitle = $rowSurveyInstances['title'];
$surveyInstanceID = $rowSurveyInstances['surveyInstanceID'];
if($rowSurveyInstances['startDate']==NULL)
{
$surveyInstanceStartDate = "Unlimited";
}
else
{
$surveyInstanceStartDate = ODBCDateToTextDateShort($rowSurveyInstances['startDate']);
}
if($rowSurveyInstances['finishDate']==NULL)
{
$surveyInstanceFinishDate = "Unlimited";
}
else
{
$surveyInstanceFinishDate = ODBCDateToTextDateShort($rowSurveyInstances['finishDate']);
}
if($bRowOdd)
{
$rowClass = "matrixRowOdd";
}
else
{
$rowClass = "matrixRowEven";
}
echo " <tr class=\"$rowClass\">
<td><input type=\"checkbox\" id=\"check_$surveyInstanceID\" name=\"checkSurveyInstances[]\" value=\"$surveyInstanceID\"/></td>
<td>".$surveyInstanceTitle."</td>
<td>".$surveyInstanceStartDate."</td>
<td>".$surveyInstanceFinishDate."</td>
<td><input type=\"button\" id=\"editsurveyinstance_$surveyInstanceID\" name=\"editsurveyinstance_$surveyInstanceID\" value=\"Edit schedule\" onClick=\"goTo('editsurveyinstance.php?surveyInstanceID=$surveyInstanceID&surveyID=$surveyID')\" /></td>
</tr>";
$bRowOdd = !$bRowOdd;
}
echo "
</table>
<input type=\"hidden\" id=\"hSurveyID\" name=\"hSurveyID\" value=\"$surveyID\"/>
<input type=\"submit\" id=\"delete\" name=\"delete\" value=\"Delete\" onclick=\"return checkCheckBoxes()\"/>
<input type=\"button\" id=\"add\" name=\"add\" value=\"Add\" onClick=\"goTo('editsurveyinstance.php?surveyInstanceID=add&surveyID=$surveyID')\"/>
</form>
</div>";
}
echo " <script language=\"JavaScript\" type=\"text/javascript\" >
function checkCheckBoxes()
{
var iNoOfInstances = 0;
var aInstances = new Array();";
//resets the mysql_fetch_array to start at the beginning again
mysqli_data_seek($qResSurveyInstances, 0);
while($rowSurveyInstances = mysqli_fetch_array($qResSurveyInstances))
{
$surveyInstanceID = $rowSurveyInstances['surveyInstanceID'];
$surveyInstanceTitle = $rowSurveyInstances['title'];
echo " if (document.getElementById(\"check_$surveyInstanceID\").checked == true)
{
iNoOfInstances=iNoOfInstances+1;
aInstances[iNoOfInstances] = \"$surveyInstanceTitle\";
}";
}
echo " if (iNoOfInstances == 0)
{
alert(\"Please select a schedule to delete.\");
return false;
}
else
{
if (iNoOfInstances == 1)
{
var confirmText = \"Are you sure you want to delete \" + aInstances[iNoOfInstances] + \".\";
}
else
{
var confirmText = \"Are you sure you want to delete these \" + iNoOfInstances + \" instances?\";
}
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=\"admin.php\">Administration</a> >
Schedule survey: ".limitString($surveyTitle,30)."";
require_once("includes/html/BreadCrumbsFooter.html");
}
//footer - including contact info.
require_once("includes/html/footernew.html");
require_once("includes/instructions/inst_schedulesurvey.php");
?>
</body>
</html>