/
feedback.php
498 lines (444 loc) · 17.8 KB
/
feedback.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<?php
// feedback.php - Display a form for customers to provide feedback
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net>, June 2004
require ('core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');
// External variables
$hashcode = $_REQUEST['ax'];
$mode = $_REQUEST['mode'];
if (!empty($hashcode)) $decodehash = str_rot13(@gzuncompress(base64_decode(urldecode($hashcode))));
else $hashcode = '';
$hashvars = explode('&&',$decodehash);
$formid = mysql_real_escape_string($hashvars['0']);
$contactid = mysql_real_escape_string($hashvars['1']);
$incidentid = urldecode(mysql_real_escape_string($hashvars['2']));
unset($errorfields);
/**
* @author Ivan Lucas
* @param string $name. Field name
* @param string $required. 'true' or 'false' is the field mandatory?
* @param string $options. delimited list of options
* @param string $answer (optional).
* @returns string HTML
*/
function feedback_html_rating($name, $required, $options, $answer='')
{
global $CONFIG;
// Rate things out of 'score_max' number
$score_max = $CONFIG['feedback_max_score'];
$option_list = explode('{@}', $options);
$promptleft = $option_list[0];
$promptright = $option_list[1];
$colwidth = round(100/$score_max);
$html .= "<table class='feedback'>\n";
if (empty($promptleft) == FALSE OR empty($promptright) == FALSE)
{
$html .= "<tr>";
/* for($c=1;$c<=$score_max;$c++)
{
if ($c==1) $html.="<th width='$colwidth%'>$promptleft</th>";
elseif ($c==$score_max) $html.="<th width='$colwidth%'>$promptright</th>";
else $html.="<th width='$colwidth%'> </th>";
}
*/
$html .= "<th colspan='{$score_max}' style='text-align: left;'>";
$html .= "<div style='float: right;'>{$promptright}</div><div>{$promptleft}</div></th>";
if ($required != 'true')
{
$html .= "<th> </th>";
}
$html .= "</tr>\n";
}
echo "<tr>";
for ($c = 1; $c <= $score_max; $c++)
{
$html .= "<td width='{$colwidth}%' style='text-align: center;'><input type='radio' name='{$name}' value='{$c}' ";
if ($answer == $c)
{
$html .= "checked='checked'";
}
$html .= " />$c</td>\n";
}
if ($required != 'true')
{
$html .= "<td><input type='radio' name='{$name}' value='0' ";
if ($answer == 0)
{
$html .= "checked='checked'";
}
$html .= "/>{$strNotApplicableAbbrev}</td>";
}
$html .= "</tr>\n";
$html .= "</table>\n";
return $html;
}
/**
* @author Ivan Lucas
* @param string $name. Field name
* @param string $required. 'true' or 'false' is the field mandatory?
* @param string $options. delimited list of options
* @param string $answer (optional).
*/
function feedback_html_options($name, $required, $options, $answer='')
{
$option_list = explode('{@}', $options);
$option_count = count($option_list);
if ($option_count > 3)
{
$html .= "<select name='{$name}'>\n";
foreach ($option_list AS $key=>$option)
{
$value = strtolower(trim(str_replace(' ', '_', $option)));
$html .= "<option value='{$value}'";
if ($answer == $value)
{
$html .= " selected='selected'";
}
$html .= ">".trim($option)."</option>\n";
}
$html .= "</select>\n";
}
else
{
foreach ($option_list AS $key=>$option)
{
$value = strtolower(trim(str_replace(' ', '_', $option)));
$html .= "<input type='radio' name='{$name}' value='{$value}'";
if ($answer == $value)
{
$html .= " selected='selected'";
}
$html .= " />".trim($option)." \n";
}
}
return $html;
}
/**
* @author Ivan Lucas
* @param string $name. Field name
* @param string $required. 'true' or 'false' is the field mandatory?
* @param string $options. delimited list of options
*/
function html_multioptions($name, $required, $options)
{
$option_list = explode('{@}', $options);
$option_count = count($option_list);
if ($option_count > 3)
{
$html .= "<select name='{$name}[]' multiple='multiple'>\n";
foreach ($option_list AS $key=>$option)
{
$value = strtolower(trim(str_replace(' ', '_', $option)));
$html .= "<option value='{$value}'>".trim($option)."</option>\n";
}
$html .= "</select>\n";
}
else
{
foreach ($option_list AS $key=>$option)
{
$value = strtolower(trim(str_replace(' ', '_', $option)));
$html .= "<input type='checkbox' name='{$name}' value='{$value}' />".trim($option)." \n";
}
}
return $html;
}
/**
* @author Ivan Lucas
* @param string $name. Field name
* @param string $required. 'true' or 'false' is the field mandatory?
* @param string $options. delimited list of options
* @param string $answer (optional).
*/
function feedback_html_text($name, $required, $options, $answer='')
{
$option_list = explode('{@}', $options);
$cols = $option_list[0] ? $option_list[0] : 60;
$rows = $option_list[1] ? $option_list[1] : 5;
if ($rows == 1)
{
$html .= "<input type='text' name='{$name}' size='{$cols}' value='{$answer}' />\n";
}
else
{
$html .= "<textarea name ='{$name}' rows='{$rows}' cols='{$cols}' />{$answer}</textarea>\n";
}
return $html;
}
/**
* @author Ivan Lucas
* @param string $name. Field name
* @param string $required. 'true' or 'false' is the field mandatory?
* @param string $options. delimited list of options
* @param string $answer (optional).
*/
function feedback_html_question($type, $name, $required, $options, $answer='')
{
$options = nl2br(trim($options));
$options = str_replace('<br>', '{@}', $options);
$options = str_replace('<br />', '{@}', $options);
$options = str_replace('<br/>', '{@}', $options);
switch ($type)
{
case 'rating':
$html = feedback_html_rating($name, $required, $options, $answer);
break;
case 'options':
$html = feedback_html_options($name, $required, $options, $answer);
break;
case 'multioptions':
$html = feedback_html_multioptions($name, $required, $options, $answer);
break;
case 'text':
$html = feedback_html_text($name, $required, $options, $answer);
break;
default:
$html = sprintf($GLOBALS['strErrorNoHandlerDefinedForQuestionTypeX'], $type);
break;
}
return $html;
}
switch ($_REQUEST['action'])
{
case 'save':
// FIXME external vars
// Have a look to see if this respondant has already responded to this form
// Get respondentid
//print_r($_REQUEST);
$sql = "SELECT id AS respondentid FROM `{$dbFeedbackRespondents}` ";
$sql .= "WHERE contactid='$contactid' AND formid='$formid' AND incidentid='$incidentid'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) < 1)
{
// FIXME: Proper error here
echo "<p>{$strErrorNoEmptyForm}</p>";
}
else
{
list($respondentid)=mysql_fetch_row($result);
}
// Store this respondent and references
// Loop through the questions in this form and store the results
$sql = "SELECT * FROM `{$dbFeedbackQuestions}` WHERE formid='{$formid}'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
while ($question = mysql_fetch_object($result))
{
$qid = $question->id;
$options = nl2br(trim($question->options));
$options = str_replace('<br>', '{@}', $options);
$options = str_replace('<br />', '{@}', $options);
$options = str_replace('<br/>', '{@}', $options);
$option_list = explode('{@}', $options);
$fieldname="Q{$question->id}";
// Check required fields are filled
if ($question->required == 'true' AND (strlen($_POST[$fieldname]) < 1 OR
isset($_POST[$fieldname]) == FALSE)) $errorfields[] = "{$question->id}";
// Store text responses in the appropriate field
if ($question->type=='text')
{
if (strlen($_POST[$fieldname]) < 255 AND $option_list[1] < 2)
{
// If we've got just one row and less than 255 characters store it in the result field
$qresult = $_POST[$fieldname];
$qresulttext = '';
}
else
{
// If we've got more than one row or more than 255 chars store it in the resulttext field (which is a blob)
$qresult = '';
$qresulttext = $_POST[$fieldname];
}
}
/*
elseif ($question->type='multioptions')
{
$qresult = '';
$qresulttext=implode(',',$_POST[$fieldname]);
}
*/
else
{
// Store all other types of results in the result field.
$qresult = $_POST[$fieldname];
$qresulttext = $_POST[$fieldname];
}
$debugtext .= "_POST[$fieldname]={$_POST[$fieldname]}\n";
// Put the SQL to be executed into an array to execute later
$rsql[] = "INSERT INTO `{$dbFeedbackResults}` (respondentid, questionid, result, resulttext) VALUES ('$respondentid', '$qid','$qresult', '$qresulttext')";
// Store the field in an array
$fieldarray[$question->id]=$_POST[$fieldname];
}
if (count($errorfields) >= 1)
{
$error=implode(",",$errorfields);
$fielddata=base64_encode(serialize($fieldarray));
//echo "<p>Error: $errortext</p>";
//print_r($errorfields);
//exit;
$errortext=urlencode($fielddata.','.$error);
echo "<?";
echo "xml version=\"1.0\" encoding=\"\"?";
echo ">";
// FIXME check this code
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="refresh" content="0;URL=feedback.php?ax=<?php echo "{$hashcode}&error={$errortext}&mode={$mode}"; ?>" />
<title><?php echo $strPleaseWaitRedirect ?></title>
<style>
body { font:10pt Arial, Helvetica, sans-serif; }
</style>
</head>
<body>
<p><?php echo $strPleaseWaitRedirect ?></p>
<p><?php echo $strIfYourBrowserNotReload; ?><a href='feedback.php?ax=<?php echo "{$hashcode}&error={$errortext}&mode={$mode}"; ?>'><?php echo $strFollowThisLink;?></a>.</p>
</body>
</head>
<?php
// header("Location: feedback.php?ax={$hashcode}&error={$errortext}");
exit;
}
if (empty($_REQUEST['rr'])) $rsql[] = "UPDATE `{$dbFeedbackRespondents}` SET completed='yes' WHERE formid='{$formid}' AND contactid='$contactid' AND incidentid='$incidentid'";
// Loop through array and execute the array to insert the form data
foreach ($rsql AS $sql)
{
## echo $sql."<br />";
mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
$sqltext.=$sql."\n";
}
// $sql = "UPDATE feedbackrespondents ";
//$sql .= "SET completed='yes' ";
//$sql .= "WHERE formid='$formid' AND respondent='$respondent' AND responseref='$responseref' ";
//mysql_query($sql);
//if (mysql_error()) trigger_error(mysql_error(), E_USER_ERROR);
//if (mysql_affected_rows() < 1) echo "<p>No rows affected: ($sql)</p>";
// Output thanks page
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
echo "<html>\n";
echo "<head>\n";
echo "<title>{$strThankYou}</title>\n";
echo "</head>\n";
echo "<body>\n";
echo "<div id='pagecontent'><h2>{$strThankYou}</h2>";
echo "<p>{$strThankYouCompleteForm}</p>";
//echo "<!-- \n {$sqltext} \n\n\n {$debugtext} -->";
echo "</div>\n</body>\n";
echo "</html>\n";
break;
default:
if ($_REQUEST['mode']!='bare') include (APPLICATION_INCPATH . 'htmlheader.inc.php');
else echo "<html>\n<head>\n<title>{$strFeedbackForm}</title>\n</head>\n<body>\n<div id='pagecontent'>\n\n";
$errorfields = explode(",",urldecode($_REQUEST['error']));
$fielddata = unserialize(base64_decode($errorfields[0])); // unserialize(
// Have a look to see if this person has a form waiting to be filled
$rsql = "SELECT id FROM `{$dbFeedbackRespondents}` WHERE contactid='$contactid' AND incidentid='$incidentid' AND formid='$formid' ";
if ($_REQUEST['rr'])
{
$rsql .= "AND completed='yes' ";
}
$rresult = mysql_query($rsql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
$waitingforms = mysql_num_rows($rresult);
$waitingform = mysql_fetch_object($rresult);
if ($waitingforms < 1)
{
echo "<h2>{$strError}</h2>";
echo "<p>{$strNoFeedBackFormToCompleteHere}</p>";
echo "\n\n<!-- f: $formid r:$respondent rr:$responseref dh:$decodehash hc:$hashcode -->\n\n";
}
else
{
$sql = "SELECT * FROM `{$dbFeedbackForms}` WHERE id='{$formid}'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
if (mysql_num_rows($result) < 1)
{
echo "<h2>{$strError}</h2>";
echo "<p>{$strNoFeedBackFormToCompleteHere}</p>";
echo "\n\n<!-- f: $formid r:$respondent rr:$responseref dh:$decodehash hc:$hashcode -->\n\n";
}
else
{
$reqd=0;
while ($form = mysql_fetch_object($result))
{
echo "<form action='feedback.php' method='post'>\n";
echo "<h2>{$form->name}</h2>\n";
echo "<p>{$strRelatingToIncident} <strong>#{$incidentid}</strong> — <strong>".incident_title($incidentid)."</strong><br />";
echo sprintf($strOpenedbyXonY, contact_realname(incident_contact($incidentid)), ldate($CONFIG['dateformat_date'],db_read_column('opened', $dbIncidents, $incidentid)));
echo ' ';
echo sprintf($strClosedOnX, ldate($CONFIG['dateformat_date'],db_read_column('closed', $dbIncidents, $incidentid))).".</p>";
if (!empty($_REQUEST['error']))
{
echo "<p style='color: red'>{$strErrorRequiredQuestionsNotCompleted}</p>";
}
echo nl2br($form->introduction);
$qsql = "SELECT * FROM `{$dbFeedbackQuestions}` ";
$qsql .= "WHERE formid='{$form->id}' ";
$qsql .= "ORDER BY taborder ASC";
$qresult=mysql_query($qsql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
while ($question = mysql_fetch_object($qresult))
{
if (strlen(trim($question->sectiontext)) > 3)
{
echo "<hr />{$question->sectiontext}\n";
}
echo "<h4>Q{$question->taborder}: {$question->question}";
if ($question->required=='true')
{
echo "<sup style='color: red; font-size: 120%;'>*</sup>";
$reqd++;
}
echo "</h4>";
if (!empty($question->questiontext))
{
echo "<p>{$question->questiontext}</p>";
}
if (!empty($fielddata[$question->id]))
{
$answer = $fielddata[$question->id];
}
else
{
$answer='';
}
echo feedback_html_question($question->type, "Q{$question->id}", $question->required, $question->options, $answer);
if (in_array($question->id, $errorfields))
{
echo "<p style='color: red'>".sprintf($strQuestionXNeedsAnsweringBeforeContinuing, $question->taborder)."</p>";
}
echo "<br />";
}
echo nl2br($form->thanks);
echo "<br /><input type='hidden' name='action' value='save' />\n";
echo "<input type='hidden' name='ax' value='".strip_tags($_REQUEST['ax'])."' />\n";
echo "<input type='submit' value='Submit' />\n";
echo "</form>\n";
if ($reqd >= 1)
{
echo "<p><sup style='color: red; font-size: 120%;'>*</sup> {$strQuestionRequired}</p>";
}
}
}
}
if ($_REQUEST['mode']!='bare')
{
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else echo "\n</div>\n</body>\n</html>\n";
break;
}
?>