-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurview.php
More file actions
303 lines (227 loc) · 6.04 KB
/
surview.php
File metadata and controls
303 lines (227 loc) · 6.04 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
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
<?php
if($_POST['check'] == 1) {
process_form();
} else {
print_form();
}
function process_form() {
$crn = $_COOKIE['crn'];
$gswid = $_COOKIE['gswid'];
$cid = $_COOKIE['cid'];
$info = array();
array_push($info, "Course CRN: $crn");
include('inc/functions.php');
if(($crn == '') || ($gswid == '') || ($cid == '')) {
$errors = array("Something went wrong. Please <a href='survey.php'>validate</a> and resubmit the survey.");
print_error_out($errors);
die;
}
include_once('inc/mysql.php');
/* insert data into surveys table */
$timestamp = time();
$colpart = "(course_id, timestamp";
$datapart = "($cid, $timestamp";
for($i=1; $i <= 17; $i++) {
$key = 'q' . $i;
$value = $_POST[$key];
if(is_numeric($value)) {
$colpart .= ", $key";
$datapart .= ", $value";
} else {
$errors = array("Something went wrong. Please <a href='survey.php'>validate</a> and resubmit the survey.");
print_error_out($errors);
die;
}
}
$colpart .= ")";
$datapart .= ")";
$si_sql = ""
. "INSERT INTO surveys"
. " $colpart"
. " VALUES"
. " $datapart"
;
$si_res = mysql_query($si_sql);
if(!$si_res) {
die("Database error (survey data): " . mysql_error());
}
array_push($info, "Survey data added");
/* insert comment */
$comment = $_POST['comments'];
if($comment != '') {
if(get_magic_quotes_gpc()) {
$comment = stripslashes($comment);
}
$comment = mysql_real_escape_string($comment);
$ci_sql = ''
. 'INSERT INTO comments'
. ' (course_id, comment)'
. ' VALUES'
. " ($cid, \"$comment\")"
;
$ci_res = mysql_query($ci_sql);
if(!$ci_res) {
die("Database error (comment): " . mysql_error());
}
array_push($info, "Comment added: $comment");
} else {
array_push($info, "No comment to add");
}
/* update survey_log table set survey_complete = 1 */
$slup_sql = ''
. 'UPDATE survey_login'
. ' SET'
. " survey_complete = $timestamp"
. ' WHERE'
. " gswid = $gswid"
. ' AND'
. " course_id = $cid"
;
$slup_res = mysql_query($slup_sql);
if(!$slup_res) {
die("Database error (completion): " . mysql_error());
}
foreach(array_keys($_COOKIE) as $key) {
setcookie($key, '');
}
array_push($info, "Survey Complete. Thank you!");
print <<<ENDRESULTS
<div id='head'>
<table align='center'>
<tr><td align='center'>
<img src='img/seal.gif'/>
</td><td align='left'>
<p><strong>Georgia Southwestern State University</strong></p>
<p><strong>Teaching Evaluation Survey</strong></p>
</td></tr>
</table>
</div>
<div id='content' align='left'>
<h1>Summary:</h1>
<p>
<ul>
ENDRESULTS;
foreach($info as $line) {
print "<li>$line</li>\n";
}
print <<<ENDRESULTS2
</ul>
</p>
</div>
ENDRESULTS2;
}
function print_form() {
$crn = $_COOKIE['crn'];
$gswid = $_COOKIE['gswid'];
$cid = $_COOKIE['cid'];
include('inc/functions.php');
if(($crn == '') || ($gswid == '') || ($cid == '')) {
$errors = array("You must <a href='survey.php'>validate</a> before you view the survey");
print_error_out($errors);
die;
}
$questions = array();
/* get info for the survey */
include('inc/mysql.php');
$survey_sql = ""
. "SELECT DISTINCT ques_no, ques_txt, answ_txt, answ_value"
. " FROM survey_questions, survey_answers, courses"
. " WHERE survey_questions.ques_id = survey_answers.ques_id"
. " AND survey_questions.is_online = courses.is_online"
. " AND courses.course_id = $cid"
. " ORDER BY ques_no, answ_value"
;
$survey_res = mysql_query($survey_sql);
if(!$survey_res) {
die("Database error (survey): " . mysql_error());
}
while($row = mysql_fetch_assoc($survey_res)) {
$ques_no = $row['ques_no'];
$ques_txt = $row['ques_txt'];
$answ_txt = $row['answ_txt'];
$answ_value = $row['answ_value'];
if(!is_array($questions[$ques_no])) {
$questions[$ques_no] = array();
}
if(!is_array($questions[$ques_no]['answers'])) {
$questions[$ques_no]['answers'] = array();
}
$questions[$ques_no]['question'] = $ques_txt;
$questions[$ques_no]['answers'][$answ_value] = $answ_txt;
}
/* get info about the course */
$course_sql = ""
. "SELECT course_crn, course_name, instr_lname, instr_fname"
. " FROM courses, course_instructor, instructors"
. " WHERE courses.course_id = course_instructor.course_id"
. " AND course_instructor.instr_id = instructors.instr_id"
. " AND courses.course_id = $cid"
;
$course_res = mysql_query($course_sql);
if(!$course_res) {
die("Database error (course info): " . mysql_error());
}
$instructors = '';
while($row = mysql_fetch_assoc($course_res)) {
$course_crn = $row['course_crn'];
$course_name = $row['course_name'];
$instr_lname = $row['instr_lname'];
$instr_fname = $row['instr_fname'];
if($instr_names != '') {
$instructors .= "; ";
}
$instructors .= $instr_lname . ", " . $instr_fname;
}
$thisdoc = $_SERVER['PHP_SELF'];
include('inc/head.php');
print <<<ENDCI
<div id='head'>
<table align='center'>
<tr><td align='center'>
<img src='img/seal.gif'/>
</td><td align='left'>
<p><strong>Georgia Southwestern State University</strong></p>
<p><strong>Teaching Evaluation Survey</strong></p>
</td></tr>
</table>
</div>
<div id='content' align='left'>
<p>
<b>Instructor(s):</b> $instructors
<br/><b>Course Name:</b> $course_name
<br/><b>Course CRN:</b> $course_crn
</p>
<form method='post' action='$thisdoc'>
ENDCI;
/* print the form */
foreach($questions as $ques_no => $question) {
$ques_txt = $question['question'];
$input_name = 'q' . $ques_no;
print "<p>\n<b>$ques_no) $ques_txt</b>\n";
print "<br/>\n<select name='$input_name'>\n";
print "<option value='0'>No Response</option>\n";
/* loop through answers array */
foreach($question['answers'] as $value => $answ_txt) {
print "<option value='$value'>$answ_txt</option>\n";
}
print "</select>\n</p>";
}
print <<<ENDLB
<p>
<b>Comments</b>
<br/>
<textarea name='comments' cols='70' rows='10'>
</textarea>
</p>
<input type='hidden' name='check' value='1'/>
<input type='submit' value='Submit'/>
<input type='reset' value='Clear'/>
</form>
</div>
ENDLB;
include('inc/foot.php');
print '<pre>';
print_r($_COOKIE);
print '</pre>';
}
?>