forked from LimeSurvey/LimeSurvey
/
group.php
845 lines (744 loc) · 28.7 KB
/
group.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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/
// Performance optimized : Nov 27, 2006
// Performance Improvement : 41% (Call to templatereplace())
// Optimized By : swales
if (empty($homedir)) {die ("Cannot run this script directly");}
//Move current step ###########################################################################
if (!isset($_SESSION['step'])) {$_SESSION['step']=0;}
if (!isset($_SESSION['totalsteps'])) {$_SESSION['totalsteps']=0;}
if (!isset($_POST['thisstep'])) {$_POST['thisstep'] = "";}
if (!isset($gl)) {$gl=array("null");}
if (isset($_POST['move']) && $_POST['move'] == "moveprev") {$_SESSION['step'] = $_POST['thisstep']-1;}
if (isset($_POST['move']) && $_POST['move'] == "movenext") {$_SESSION['step']=$_POST['thisstep']+1;}
if (isset($_POST['move']) && $_POST['move'] == "movelast") {$_SESSION['step'] = $_POST['thisstep']+1;}
// If on SUBMIT page and select SAVE SO FAR it will return to SUBMIT page
if ($_SESSION['step'] > $_SESSION['totalsteps'] && $_POST['move'] != "movesubmit")
{
$_POST['move'] = "movelast";
}
//CHECK IF ALL MANDATORY QUESTIONS HAVE BEEN ANSWERED ############################################
//First, see if we are moving backwards or doing a Save so far, and its OK not to check:
if ($allowmandbackwards==1 && ((isset($_POST['move']) && $_POST['move'] == "moveprev") || (isset($_POST['saveall']) && $_POST['saveall'] == $clang->gT("Save your responses so far"))))
{
$backok="Y";
}
else
{
$backok="N";
}
//Now, we check mandatory questions if necessary
//CHECK IF ALL CONDITIONAL MANDATORY QUESTIONS THAT APPLY HAVE BEEN ANSWERED
$notanswered=addtoarray_single(checkmandatorys($backok),checkconditionalmandatorys($backok));
//CHECK PREGS
$notvalidated=checkpregs($backok);
//SEE IF THIS GROUP SHOULD DISPLAY
if (isset($_POST['move']) && $_SESSION['step'] != 0 && $_POST['move'] != "movelast" && $_POST['move'] != "movesubmit")
{
while(checkgroupfordisplay($_SESSION['grouplist'][$_SESSION['step']-1][0]) === false)
{
if (isset($_POST['move']) && $_POST['move'] == "moveprev")
{
$_SESSION['step']=$_SESSION['step']-1;
}
if (isset($_POST['move']) && $_POST['move'] == "movenext")
{
$_SESSION['step']=$_SESSION['step']+1;
}
if ($_SESSION['step']-1 == $_SESSION['totalsteps'])
{
$_POST['move'] = "movelast";
break;
}
}
}
//SUBMIT ###############################################################################
if (isset($_POST['move']) && $_POST['move'] == "movesubmit")
{
if ($thissurvey['refurl'] == "Y")
{
if (!in_array("refurl", $_SESSION['insertarray'])) //Only add this if it doesn't already exist
{
$_SESSION['insertarray'][] = "refurl";
}
//$_SESSION['refurl'] = $_SESSION['refurl'];
}
//COMMIT CHANGES TO DATABASE
if ($thissurvey['active'] != "Y")
{
sendcacheheaders();
doHeader();
echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
//Check for assessments
$assessments = doAssessment($surveyid);
if ($assessments)
{
echo templatereplace(file_get_contents("$thistpl/assessment.pstpl"));
}
$completed = "<br /><strong><font size='2' color='red'>".$clang->gT("Did Not Save")."</font></strong><br /><br />\n\n";
$completed .= $clang->gT("Your survey responses have not been recorded. This survey is not yet active.")."<br /><br />\n";
$completed .= "<a href='{$_SERVER['PHP_SELF']}?sid=$surveyid&move=clearall'>".$clang->gT("Clear Responses")."</a><br /><br />\n";
}
else
{
if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1)
{
$cookiename="PHPSID".returnglobal('sid')."STATUS";
setcookie("$cookiename", "COMPLETE", time() + 31536000);
}
$content='';
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
//echo $thissurvey['url'];
//Check for assessments
$assessments = doAssessment($surveyid);
if ($assessments)
{
$content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl"));
}
/* Here I must study the possibility to branch if the questionnarie were
completed or not */
$completed = "<br /><font size='2'><font color='green'><strong>"
. $clang->gT("Thank you")."</strong></font><br /><br />\n\n"
. $clang->gT("Your survey responses have been recorded.")."<br />\n"
. "<a href='javascript:window.close()'>"
. $clang->gT("Close this Window")."</a></font><br /><br />\n";
//Update the token if needed and send a confirmation email
if (isset($_POST['token']) && $_POST['token'])
{
submittokens();
}
//Send notification to survey administrator //Thanks to Jeff Clement http://jclement.ca
if ($thissurvey['sendnotification'] > 0 && $thissurvey['adminemail'])
{
sendsubmitnotification($thissurvey['sendnotification']);
}
session_unset();
session_destroy();
$content='';
$content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
//echo $thissurvey['url'];
//Check for assessments
$assessments = doAssessment($surveyid);
if ($assessments)
{
$content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl"));
}
$completed = "<br /><font size='2'><font color='green'><strong>"
.$clang->gT("Thank you")."</strong></font><br /><br />\n\n"
. $clang->gT("Your survey responses have been recorded.")."<br />\n"
. "<a href='javascript:window.close()'>"
.$clang->gT("Close this Window")."</a></font><br /><br />\n";
//Update the token if needed and send a confirmation email
if (isset($_POST['token']) && $_POST['token'])
{
submittokens();
}
//Send notification to survey administrator //Thanks to Jeff Clement http://jclement.ca
if ($thissurvey['sendnotification'] > 0 && $thissurvey['adminemail'])
{
sendsubmitnotification($thissurvey['sendnotification']);
}
session_unset();
session_destroy();
sendcacheheaders();
if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['url'])
{
session_write_close();
//Automatically redirect the page to the "url" setting for the survey
/* this part doesn't have sense because $mytoken is not declared nor asigned value anywhere
$redir = $thissurvey['url'];
// Add the token to the redirect just in case
if (isset($mytoken))
{
$redir .= "?token=".$mytoken;
}
header("Location: {$redir}"); */
$url = $thissurvey['url'];
$url=str_replace("{SAVEDID}",$saved_id, $url); // to activate the SAVEDID in the END URL
$url=str_replace("{TOKEN}",$_POST['token'], $url); // to activate the TOKEN in the END URL
$url=str_replace("{SID}", $surveyid, $url); // to activate the SID in the RND URL
header("Location: {$url}");
}
doHeader();
echo $content;
}
echo templatereplace(file_get_contents("$thistpl/completed.pstpl"));
echo "\n<br />\n";
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
exit;
// {
// echo templatereplace($op);
// }
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
exit;
}
//LAST PHASE ###########################################################################
if (isset($_POST['move']) && $_POST['move'] == "movelast" && (!isset($notanswered) || !$notanswered) && (!isset($notvalidated) && !$notvalidated))
{
//READ TEMPLATES, INSERT DATA AND PRESENT PAGE
sendcacheheaders();
doHeader();
if ($thissurvey['private'] != "N")
{
$privacy="";
$privacy .= templatereplace(file_get_contents("$thistpl/privacy.pstpl"));
}
echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
echo "\n<form method='post' action='{$_SERVER['PHP_SELF']}' id='limesurvey' name='limesurvey'>\n";
echo "\n\n<!-- START THE SURVEY -->\n";
echo templatereplace(file_get_contents("$thistpl/survey.pstpl"));
//READ SUBMIT TEMPLATE
echo templatereplace(file_get_contents("$thistpl/submit.pstpl"));
$navigator = surveymover();
echo "\n\n<!-- PRESENT THE NAVIGATOR -->\n";
echo templatereplace(file_get_contents("$thistpl/navigator.pstpl"));
print <<<END
<input type='hidden' name='thisstep' value='{$_SESSION['step']}' id='thisstep' />
<input type='hidden' name='sid' value='$surveyid' id='sid' />
<input type='hidden' name='token' value='$token' id='token' />
</form>
END;
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
doFooter();
exit;
}
//SEE IF $surveyid EXISTS ####################################################################
if ($surveyexists <1)
{
//SURVEY DOES NOT EXIST. POLITELY EXIT.
echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
echo "\t<center><br />\n";
echo "\t".$clang->gT("Sorry. There is no matching survey.")."<br /></center> \n";
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
doFooter();
exit;
}
//RUN THIS IF THIS IS THE FIRST TIME , OR THE FIRST PAGE ########################################
if (!isset($_SESSION['step']) || !$_SESSION['step'])
{
$totalquestions = buildsurveysession();
sendcacheheaders();
doHeader();
echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
echo "\n<form method='post' action='{$_SERVER['PHP_SELF']}' id='limesurvey' name='limesurvey'>\n";
echo "\n\n<!-- START THE SURVEY -->\n";
echo templatereplace(file_get_contents("$thistpl/welcome.pstpl"));
echo "\n";
$navigator = surveymover();
echo templatereplace(file_get_contents("$thistpl/navigator.pstpl"));
if ($thissurvey['active'] != "Y")
{
echo "\t\t<center><font color='red' size='2'>".$clang->gT("This survey is not currently active. You will not be able to save your responses.")."</font></center>\n";
}
echo "\n<input type='hidden' name='sid' value='$surveyid' id='sid' />\n";
echo "\n<input type='hidden' name='token' value='$token' id='token' />\n";
echo "\n</form>\n";
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
doFooter();
exit;
}
//******************************************************************************************************
//PRESENT SURVEY
//******************************************************************************************************
//GET GROUP DETAILS
$grouparrayno=$_SESSION['step']-1;
$gid=$_SESSION['grouplist'][$grouparrayno][0];
$groupname=$_SESSION['grouplist'][$grouparrayno][1];
$groupdescription=$_SESSION['grouplist'][$grouparrayno][2];
require_once("qanda.php"); //This should be qanda.php when finished
//Iterate through the questions about to be displayed:
$mandatorys=array();
$mandatoryfns=array();
$conmandatorys=array();
$conmandatoryfns=array();
$conditions=array();
$inputnames=array();
// Latter is needed an array to get the tittle of the question and
// its id for the form, with this will be more easy locate the
// key for to construct the javascript code
$titlejsid = array();
foreach ($_SESSION['fieldarray'] as $ia)
{
$titlejsid[$ia[2]] = $ia[1];
if ($ia[5] == $gid)
{
//Get the answers/inputnames
list($plus_qanda, $plus_inputnames)=retrieveAnswers($ia);
if ($plus_qanda)
{
$qanda[]=$plus_qanda;
}
if ($plus_inputnames)
{
$inputnames = addtoarray_single($inputnames, $plus_inputnames);
}
//Display the "mandatory" popup if necessary
if (isset($notanswered))
{
list($mandatorypopup, $popup)=mandatory_popup($ia, $notanswered);
}
//Display the "validation" popup if necessary
if (isset($notvalidated))
{
list($validationpopup, $vpopup)=validation_popup($ia, $notvalidated);
}
//Get list of mandatory questions
list($plusman, $pluscon)=create_mandatorylist($ia);
if ($plusman !== null)
{
list($plus_man, $plus_manfns)=$plusman;
$mandatorys=addtoarray_single($mandatorys, $plus_man);
$mandatoryfns=addtoarray_single($mandatoryfns, $plus_manfns);
}
if ($pluscon !== null)
{
list($plus_conman, $plus_conmanfns)=$pluscon;
$conmandatorys=addtoarray_single($conmandatorys, $plus_conman);
$conmandatoryfns=addtoarray_single($conmandatoryfns, $plus_conmanfns);
}
//Build an array containing the conditions that apply for this page
$plus_conditions=retrieveConditionInfo($ia); //Returns false if no conditions
if ($plus_conditions)
{
$conditions = addtoarray_single($conditions, $plus_conditions);
}
}
} //end iteration
$percentcomplete = makegraph($_SESSION['step'], $_SESSION['totalsteps']);
$languagechanger = makelanguagechanger();
//READ TEMPLATES, INSERT DATA AND PRESENT PAGE
sendcacheheaders();
doHeader();
if (isset($popup)) {echo $popup;}
if (isset($vpopup)) {echo $vpopup;}
//foreach(file("$thistpl/startpage.pstpl") as $op)
//{
// echo templatereplace($op);
//}
echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"));
$hiddenfieldnames=implode("|", $inputnames);
print <<<END
<form method='post' action='{$_SERVER['PHP_SELF']}' id='limesurvey' name='limesurvey'>
<!-- INPUT NAMES -->
<input type='hidden' name='fieldnames' value='{$hiddenfieldnames}' id='fieldnames' />
END;
// --> START NEW FEATURE - SAVE
// Used to keep track of the fields modified, so only those are updated during save
echo "\t<input type='hidden' name='modfields' value='";
// Debug - uncomment if you want to see the value of modfields on the next page source (to see what was modified)
// however doing so will cause the save routine to save all fields that have ever been modified whether
// they are on the current page or not. Recommend just using this for debugging.
//if (isset($_POST['modfields']) && $_POST['modfields']) {
// $inputmodfields=explode("|", $_POST['modfields']);
// echo implode("|", $inputmodfields);
//}
echo "' id='modfields' />\n";
echo "\n";
echo "\n\n<!-- JAVASCRIPT FOR MODIFIED QUESTIONS -->\n";
echo " <script type='text/javascript'>\n";
echo " <!--\n";
echo " function modfield(name)\n";
echo " {\n";
echo " temp=document.getElementById('modfields').value;\n";
echo " if (temp=='') {\n";
echo " document.getElementById('modfields').value=name;\n";
echo " }\n";
echo " else {\n";
echo " myarray=temp.split('|');\n";
echo " if (!inArray(name, myarray)) {\n";
echo " myarray.push(name);\n";
echo " document.getElementById('modfields').value=myarray.join('|');\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "\n";
echo " function inArray(needle, haystack)\n";
echo " {\n";
echo " for (h in haystack) {\n";
echo " if (haystack[h] == needle) {\n";
echo " return true;\n";
echo " }\n";
echo " }\n";
echo " return false;\n";
echo " } \n";
echo "\n";
echo " function ValidDate(oObject)\n";
echo " {// --- Regular expression used to check if date is in correct format\n";
echo " var str_regexp = /[1-9][0-9]{3}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])/;\n";
echo " var pattern = new RegExp(str_regexp);\n";
echo " if ( oObject.value=='')\n";
echo " { return true;\n";
echo " }\n";
echo " if ((oObject.value.match(pattern)!=null))\n";
echo " {var date_array = oObject.value.split('-');\n";
echo " var day = date_array[2];\n";
echo " var month = date_array[1];\n";
echo " var year = date_array[0];\n";
echo " str_regexp = /1|3|5|7|8|10|12/;\n";
echo " pattern = new RegExp(str_regexp);\n";
echo " if ( day <= 31 && (month.match(pattern)!=null))\n";
echo " { return true;\n";
echo " }\n";
echo " str_regexp = /4|6|9|11/;\n";
echo " pattern = new RegExp(str_regexp);\n";
echo " if ( day <= 30 && (month.match(pattern)!=null))\n";
echo " { return true;\n";
echo " }\n";
echo " if (day == 29 && month == 2 && (year % 4 == 0))\n";
echo " { return true;\n";
echo " }\n";
echo " if (day <= 28 && month == 2)\n";
echo " { return true;\n";
echo " } \n";
echo " }\n";
echo " window.alert('".$clang->gT("Date is not valid!")."');\n";
echo " oObject.focus();\n";
echo " oObject.select();\n";
echo " return false;\n";
echo " }\n";
echo " //-->\n";
echo " </script>\n\n";
// <-- END NEW FEATURE - SAVE
// <-- START THE SURVEY -->
//foreach(file("$thistpl/survey.pstpl") as $op)
//{
// echo "\t".templatereplace($op);
//}
echo templatereplace(file_get_contents("$thistpl/survey.pstpl"));
print <<<END
<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->
<script type='text/javascript'>
<!--
END;
// Find out if there are any array_filter questions in this group
$array_filterqs = getArrayFiltersForGroup($gid);
// Put in the radio button reset javascript for the array filter unselect
if (isset($array_filterqs) && is_array($array_filterqs))
{
print <<<END
function radio_unselect(radioObj)
{
var radioLength = radioObj.length;
for(var i = 0; i < radioLength; i++)
{
radioObj[i].checked = false;
}
}
END;
}
print <<<END
function checkconditions(value, name, type)
{
END;
// If there are conditions or arrray_filter questions then include the appropriate Javascript
if ((isset($conditions) && is_array($conditions)) ||
(isset($array_filterqs) && is_array($array_filterqs)))
{
if (!isset($endzone))
{
$endzone="";
}
// if (type == 'radio' || type == 'select-one' || type == 'text')
print <<<END
if (type == 'radio' || type == 'select-one')
{
var hiddenformname='java'+name;
document.getElementById(hiddenformname).value=value;
}
if (type == 'checkbox')
{
var hiddenformname='java'+name;
var chkname='answer'+name;
if (document.getElementById(chkname).checked)
{
document.getElementById(hiddenformname).value='Y';
} else
{
document.getElementById(hiddenformname).value='';
}
}
END;
$java="";
$cqcount=1;
/* $conditions element structure
* $condition[n][0] => question id
* $condition[n][1] => question with value to evaluate
* $condition[n][2] => internal field name of element [1]
* $condition[n][3] => value to be evaluated on answers labeled.
* *NEW* tittle of questions to evaluate.
* $condition[n][4] => type of question
* $condition[n][5] => equal to [2], but concatenated in this time (why the same value 2 times?)
* $condition[n][6] => method used to evaluate *NEW*
*/
foreach ($conditions as $cd)
{
if ((isset($oldq) && $oldq != $cd[0]) || !isset($oldq)) //New if statement
{
$java .= $endzone;
$endzone = "";
$cqcount=1;
$java .= "\n\tif ((";
}
if (!isset($oldcq) || !$oldcq)
{
$oldcq = $cd[2];
}
if ($cd[4] == "L") //Just in case the dropdown threshold is being applied, check number of answers here
{
$cccquery="SELECT COUNT(*) FROM {$dbprefix}answers WHERE qid={$cd[1]} AND language='".$_SESSION['s_lang']."'";
$cccresult=db_execute_num($cccquery);
list($cccount) = $cccresult->FetchRow();
}
if ($cd[4] == "R")
{
$idname="fvalue_".$cd[1].substr($cd[2], strlen($cd[2])-1,1);
}
elseif ($cd[4] == "5" ||
$cd[4] == "A" ||
$cd[4] == "B" ||
$cd[4] == "C" ||
$cd[4] == "E" ||
$cd[4] == "F" ||
$cd[4] == "H" ||
$cd[4] == "G" ||
$cd[4] == "Y" ||
($cd[4] == "L" && $cccount <= $dropdownthreshold))
{
$idname="java$cd[2]";
}
elseif ($cd[4] == "M" ||
$cd[4] == "P")
{
$idname="java$cd[2]$cd[3]";
}
elseif ($cd[4] == "D" ||
$cd[4] == "S" ||
$cd[4] == "N" ||
$cd[4] == "S" ||
$cd[4] == "T" ||
$cd[4] == "U" )
{
$idname="answer$cd[2]";
}
else
{
$idname="java".$cd[2];
}
if ($cqcount > 1 && $oldcq ==$cd[2])
{
$java .= " || ";
}
elseif ($cqcount >1 && $oldcq != $cd[2])
{
$java .= ") && (";
}
// The [3] element is for the value used to be compared with
// If it is '' (empty) means not answered
// then a space or a false are interpreted as no answer
// as we let choose if the questions is answered or not
// and doesn´t care the answer, so we wait for a == or !=
// TempFix by lemeur ==> add a check on cd[3]=' ' as well because
// condition editor seems not updated yet
if ($cd[3] == '' || $cd[3] == ' ')
{
if ($cd[6] == '==')
{
$java .= "document.getElementById('$idname').value == ' ' || !document.getElementById('$idname').value";
} else
{
// strange thing, isn´t? whell 0, ' ', '' or false are all false logic values then...
$java .= "document.getElementById('$idname').value";
}
}
elseif ($cd[4] == "M" ||
$cd[4] == "P" ||
$cd[4] == "!")
{
//$java .= "!document.getElementById('$idname') || document.getElementById('$idname').value == ' '";
$java .= "document.getElementById('$idname').value == 'Y'"; //
} else
{
/* NEW
* If the value is enclossed by @
* the value of this question must be evaluated instead.
* Remember $titlejs array? It will be used now
* Another note: It´s not clear why is used a norma to call
* some elements like java*, answer* or just the fieldname
* as far I can see now it´s used the field name for text elements
* so, I´ll use by id with the prefix answer
*/
if (ereg('^@[^@]+@', $cd[3]))
{
$auxqtitle = substr($cd[3],1,strlen($cd[3])-2);
$java .= "(document.getElementById('answer" . $cd[2] . "').value != '') && ";
if (in_array($titlejsid[$auxqtitle], $_SESSION['insertarray']))
{
$java .= "(document.getElementById('answer" . $titlejsid[$auxqtitle] . "').value != '') && ";
$java .= "(document.getElementById('answer" . $cd[2] . "').value $cd[6] document.getElementById('answer".$titlejsid[$auxqtitle]."').value)";
} else
{
$java .= "(document.getElementById('answer" . $titlejsid[$auxqtitle] . "').value != '') && ";
$java .= "(document.getElementById('answer" . $cd[2] . "').value $cd[6] document.getElementById('answer".$titlejsid[$auxqtitle]."').value)";
}
} else
{
if ($cd[3]) //Well supose that we are comparing a non empty value
{
$java .= "document.getElementById('$idname').value != '' && ";
}
$java .= "document.getElementById('$idname').value $cd[6] '$cd[3]'";
}
}
if ((isset($oldq) && $oldq != $cd[0]) || !isset($oldq))//Close if statement
{
$endzone = "))\n";
$endzone .= "\t{\n";
$endzone .= "\t\tdocument.getElementById('question$cd[0]').style.display='';\n";
$endzone .= "\t\tdocument.getElementById('display$cd[0]').value='on';\n";
$endzone .= "\t}\n";
$endzone .= "\telse\n";
$endzone .= "\t{\n";
$endzone .= "\t\tdocument.getElementById('question$cd[0]').style.display='none';\n";
$endzone .= "\t\tdocument.getElementById('display$cd[0]').value='';\n";
$endzone .= "\t}\n";
$cqcount++;
}
$oldq = $cd[0]; //Update oldq for next loop
$oldcq = $cd[2]; //Update oldcq for next loop
} // end foreach
$java .= $endzone;
}
if (isset($array_filterqs) && is_array($array_filterqs))
{
if (!isset($appendj)) {$appendj="";}
foreach ($array_filterqs as $attralist)
{
//die(print_r($attrflist));
$qbase = $surveyid."X".$gid."X".$attralist['qid'];
$qfbase = $surveyid."X".$gid."X".$attralist['fid'];
if ($attralist['type'] == "M")
{
$qquery = "SELECT code FROM {$dbprefix}answers WHERE qid='".$attralist['qid']."' AND language='".$_SESSION['s_lang']."' order by code;";
$qresult = db_execute_assoc($qquery);
while ($fansrows = $qresult->FetchRow())
{
$fquestans = "java".$qfbase.$fansrows['code'];
$tbody = "javatbd".$qbase.$fansrows['code'];
$dtbody = "tbdisp".$qbase.$fansrows['code'];
$tbodyae = $qbase.$fansrows['code'];
$appendj .= "\n";
$appendj .= "\tif ((document.getElementById('$fquestans').value == 'Y'))\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='';\n";
$appendj .= "\t\tdocument.getElementById('$dtbody').value='on';\n";
$appendj .= "\t}\n";
$appendj .= "\telse\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='none';\n";
$appendj .= "\t\tdocument.getElementById('$dtbody').value='off';\n";
$appendj .= "\t\tradio_unselect(document.forms['phpsurveyor'].elements['$tbodyae']);\n";
$appendj .= "\t}\n";
}
}
}
$java .= $appendj;
}
if (isset($java)) {echo $java;}
echo "\t\t\tif (navigator.appVersion.indexOf('Safari')>-1 && name !== undefined )\n"
."\t\t\t{ // Safari eats the onchange so run modfield manually, except when called at onload time\n"
."\t\t\t\t//alert('For Safari calling modfield for ' + name);\n"
."\t\t\t\tmodfield(name);\n"
."\t\t\t}\n"
."\t\t}\n"
."\t//-->\n"
."\t</script>\n\n"; // End checkconditions javascript function
echo "\n\n<!-- START THE GROUP -->\n";
echo templatereplace(file_get_contents("$thistpl/startgroup.pstpl"));
echo "\n";
if ($groupdescription)
{
echo templatereplace(file_get_contents("$thistpl/groupdescription.pstpl"));
}
echo "\n";
echo "\n\n<!-- PRESENT THE QUESTIONS -->\n";
if (isset($qanda) && is_array($qanda))
{
foreach ($qanda as $qa)
{
echo "\n\t<!-- NEW QUESTION -->\n";
echo "\t\t\t\t<div id='question$qa[4]'";
if ($qa[3] != "Y") {echo ">\n";} else {echo " style='display: none'>\n";}
$question="<label for='answer$qa[7]'>" . $qa[0] . "</label>";
$answer=$qa[1];
$help=$qa[2];
$questioncode=$qa[5];
echo templatereplace(file_get_contents("$thistpl/question.pstpl"));
echo "\t\t\t\t</div>\n";
}
}
echo "\n\n<!-- END THE GROUP -->\n";
echo templatereplace(file_get_contents("$thistpl/endgroup.pstpl"));
echo "\n";
$navigator = surveymover(); //This gets globalised in the templatereplace function
echo "\n\n<!-- PRESENT THE NAVIGATOR -->\n";
echo templatereplace(file_get_contents("$thistpl/navigator.pstpl"));
echo "\n";
if ($thissurvey['active'] != "Y")
{
echo "\t\t<center><font color='red' size='2'>".$clang->gT("This survey is not currently active. You will not be able to save your responses.")."</font></center>\n";
}
echo "<!-- group2.php -->\n"; //This can go eventually - it's redundent for debugging
if (isset($conditions) && is_array($conditions) && count($conditions) != 0)
{
//if conditions exist, create hidden inputs for 'previously' answered questions
// Note that due to move 'back' possibility, there may be answers from next pages
// However we make sure that no answer from this page are inserted here
foreach (array_keys($_SESSION) as $SESak)
{
if (in_array($SESak, $_SESSION['insertarray']) && !in_array($SESak, $inputnames))
{
echo "<input type='hidden' name='java$SESak' id='java$SESak' value='" . htmlspecialchars($_SESSION[$SESak],ENT_QUOTES). "' />\n";
}
}
}
//SOME STUFF FOR MANDATORY QUESTIONS
if (remove_nulls_from_array($mandatorys))
{
$mandatory=implode("|", remove_nulls_from_array($mandatorys));
echo "<input type='hidden' name='mandatory' value='$mandatory' id='mandatory' />\n";
}
if (remove_nulls_from_array($conmandatorys))
{
$conmandatory=implode("|", remove_nulls_from_array($conmandatorys));
echo "<input type='hidden' name='conmandatory' value='$conmandatory' id='conmandatory' />\n";
}
if (remove_nulls_from_array($mandatoryfns))
{
$mandatoryfn=implode("|", remove_nulls_from_array($mandatoryfns));
echo "<input type='hidden' name='mandatoryfn' value='$mandatoryfn' id='mandatoryfn' />\n";
}
if (remove_nulls_from_array($conmandatoryfns))
{
$conmandatoryfn=implode("|", remove_nulls_from_array($conmandatoryfns));
echo "<input type='hidden' name='conmandatoryfn' value='$conmandatoryfn' id='conmandatoryfn' />\n";
}
echo "<input type='hidden' name='thisstep' value='{$_SESSION['step']}' id='thisstep' />\n";
echo "<input type='hidden' name='sid' value='$surveyid' id='sid' />\n";
echo "<input type='hidden' name='token' value='$token' id='token' />\n";
echo "</form>\n";
echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"));
echo "\n";
doFooter();
?>