0 && (($move <= $_SESSION['step']) || (isset($_SESSION['maxstep']) && $move <= $_SESSION['maxstep']))) $_SESSION['step'] = $move; } // We do not keep the participant session anymore when the same browser is used to answer a second time a survey (let's think of a library PC for instance). // Previously we used to keep the session and redirect the user to the // submit page. //if (isset($_SESSION['finished'])) {$move='movesubmit'; } if ($_SESSION['step'] == 0) { display_first_page(); exit; } //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($move) && ($move == "moveprev" || (is_int($move) && $_SESSION['prevstep'] == $_SESSION['maxstep']))) || (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($move,$backok),checkconditionalmandatorys($move,$backok)); //CHECK INPUT $notvalidated=checkpregs($move,$backok); // CHECK UPLOADED FILES $filenotvalidated = checkUploadedFileValidity($move, $backok); //SEE IF THIS GROUP SHOULD DISPLAY $show_empty_group = false; if ($_SESSION['step']==0) $show_empty_group = true; if (isset($move) && $_SESSION['step'] != 0 && $move != "movesubmit") { while(isset($_SESSION['grouplist'][$_SESSION['step']-1]) && checkgroupfordisplay($_SESSION['grouplist'][$_SESSION['step']-1][0]) === false) { if ($_SESSION['prevstep'] > $_SESSION['step']) { $_SESSION['step']=$_SESSION['step']-1; } else { $_SESSION['step']=$_SESSION['step']+1; } if ($_SESSION['step']>$_SESSION['totalsteps']) { // We are skipping groups, but we moved 'off' the last group. // Now choose to implement an implicit submit (old behaviour), // or create an empty page giving the user the explicit option to submit. if (isset($show_empty_group_if_the_last_group_is_hidden) && $show_empty_group_if_the_last_group_is_hidden == true) { $show_empty_group = true; break; } else { $move = "movesubmit"; submitanswer(); // complete this answer (submitdate) break; } } } } //SUBMIT ############################################################################### if ((isset($move) && $move == "movesubmit") && (!isset($notanswered) || !$notanswered) && (!isset($notvalidated) || !$notvalidated ) && (!isset($filenotvalidated) || !$filenotvalidated)) { setcookie ("limesurvey_timers", "", time() - 3600);// remove the timers cookies if ($thissurvey['refurl'] == "Y") { if (!in_array("refurl", $_SESSION['insertarray'])) //Only add this if it doesn't already exist { $_SESSION['insertarray'][] = "refurl"; } } //COMMIT CHANGES TO DATABASE if ($thissurvey['active'] != "Y") //If survey is not active, don't really commit { if ($thissurvey['assessments']== "Y") { $assessments = doAssessment($surveyid); } $thissurvey['surveyls_url']=dTexts::run($thissurvey['surveyls_url']); if($thissurvey['printanswers'] != 'Y') { killSession(); } sendcacheheaders(); doHeader(); echo templatereplace(file_get_contents("$thistpl/startpage.pstpl")); //Check for assessments if ($thissurvey['assessments']== "Y" && $assessments) { echo templatereplace(file_get_contents("$thistpl/assessment.pstpl")); } // fetch all filenames from $_SESSIONS['files'] and delete them all // from the /upload/tmp/ directory /*echo "
";print_r($_SESSION);echo "
"; for($i = 1; isset($_SESSION['files'][$i]); $i++) { unlink('upload/tmp/'.$_SESSION['files'][$i]['filename']); } */ $completed = $thissurvey['surveyls_endtext']; $completed .= "
".$clang->gT("Did Not Save")."

\n\n"; $completed .= $clang->gT("Your survey responses have not been recorded. This survey is not yet active.")."

\n"; if ($thissurvey['printanswers'] == 'Y') { // ClearAll link is only relevant for survey with printanswers enabled // in other cases the session is cleared at submit time $completed .= "".$clang->gT("Clear Responses")."

\n"; } } else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY { if ($thissurvey['usecookie'] == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used { $cookiename="PHPSID".returnglobal('sid')."STATUS"; setcookie("$cookiename", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days } //Before doing the "templatereplace()" function, check the $thissurvey['url'] //field for limereplace stuff, and do transformations! $thissurvey['surveyls_url']=dTexts::run($thissurvey['surveyls_url']); $thissurvey['surveyls_url']=passthruReplace($thissurvey['surveyls_url'], $thissurvey); $content=''; $content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl")); //Check for assessments if ($thissurvey['assessments']== "Y") { $assessments = doAssessment($surveyid); if ($assessments) { $content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl")); } } //Update the token if needed and send a confirmation email if (isset($clienttoken) && $clienttoken) { submittokens(); } //Send notifications SendSubmitNotifications(); $content=''; $content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl")); //echo $thissurvey['url']; //Check for assessments if ($thissurvey['assessments']== "Y") { $assessments = doAssessment($surveyid); if ($assessments) { $content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl")); } } if (trim(strip_tags($thissurvey['surveyls_endtext']))=='') { $completed = "
".$clang->gT("Thank you!")."

\n\n" . $clang->gT("Your survey responses have been recorded.")."

\n"; } else { $completed = $thissurvey['surveyls_endtext']; } // Link to Print Answer Preview ********** if ($thissurvey['printanswers']=='Y') { $completed .= "

" ."" .$clang->gT("Print your answers.") ."
\n"; } //***************************************** if ($thissurvey['publicstatistics']=='Y' && $thissurvey['printanswers']=='Y') {$completed .='
'.$clang->gT("or");} // Link to Public statistics ********** if ($thissurvey['publicstatistics']=='Y') { $completed .= "

" ."" .$clang->gT("View the statistics for this survey.") ."
\n"; } //***************************************** $_SESSION['finished']=true; $_SESSION['sid']=$surveyid; sendcacheheaders(); if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['surveyls_url']) { //Automatically redirect the page to the "url" setting for the survey $url = $thissurvey['surveyls_url']; $url = dTexts::run($thissurvey['surveyls_url']); $url = passthruReplace($url, $thissurvey); $url = str_replace("{SAVEDID}",$saved_id, $url); // to activate the SAVEDID in the END URL $url = str_replace("{TOKEN}",$clienttoken, $url); // to activate the TOKEN in the END URL $url = str_replace("{SID}", $surveyid, $url); // to activate the SID in the END URL $url = str_replace("{LANG}", $clang->getlangcode(), $url); // to activate the LANG in the END URL //queXS Addition include_once("quexs.php"); $quexs_url = get_start_interview_url(); $url = str_replace("{STARTINTERVIEWURL}", $quexs_url, $url); $end_url = get_end_interview_url(); $url = str_replace("{ENDINTERVIEWURL}", $end_url, $url); header("Location: {$url}"); } //if($thissurvey['printanswers'] != 'Y' && $thissurvey['usecookie'] != 'Y' && $tokensexist !=1) if($thissurvey['printanswers'] != 'Y') { killSession(); } doHeader(); echo $content; } echo templatereplace(file_get_contents("$thistpl/completed.pstpl")); echo "\n
\n"; 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

\n"; echo "\t".$clang->gT("Sorry. There is no matching survey.")."
 \n"; echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); doFooter(); exit; } //GET GROUP DETAILS if ($previewgrp) { setcookie("limesurvey_timers", "0"); $_SESSION['step'] = $_REQUEST['gid']+1; foreach($_SESSION['grouplist'] as $index=>$group) { if ($group[0]==$_REQUEST['gid']){ $grouparrayno = $index; break; } } $gid=$_SESSION['grouplist'][$grouparrayno][0]; $groupname=$_SESSION['grouplist'][$grouparrayno][1]; $groupdescription=$_SESSION['grouplist'][$grouparrayno][2]; } else { if (($show_empty_group)||!isset($_SESSION['grouplist'])) { $gid=-1; // Make sure the gid is unused. This will assure that the foreach (fieldarray as ia) has no effect. $groupname=$clang->gT("Submit your answers"); $groupdescription=$clang->gT("There are no more questions. Please press the button to finish this survey."); } else { $grouparrayno=$_SESSION['step']-1; $gid=$_SESSION['grouplist'][$grouparrayno][0]; $groupname=$_SESSION['grouplist'][$grouparrayno][1]; $groupdescription=$_SESSION['grouplist'][$grouparrayno][2]; } } //Setup an inverted fieldnamesInfo for quick lookup of field answers. $aFieldnamesInfoInv = aArrayInvert($_SESSION['fieldnamesInfo']); if ($_SESSION['step'] > $_SESSION['maxstep']) { $_SESSION['maxstep'] = $_SESSION['step']; } //****************************************************************************************************** //PRESENT SURVEY //****************************************************************************************************** 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(); $qtypesarray = array(); $qnumber = 0; foreach ($_SESSION['fieldarray'] as $key=>$ia) { $qtypesarray[$ia[1]] = $ia[4]; ++$qnumber; $ia[9] = $qnumber; // incremental question count; if ((isset($ia[10]) && $ia[10] == $gid) || (!isset($ia[10]) && $ia[5] == $gid)) { if(IsSet($hideQuestion[$ia[0]]) && $hideQuestion[$ia[0]]==true){ continue; } $qidattributes=getQuestionAttributes($ia[0]); if ($qidattributes===false || $qidattributes['hidden']==1) { // Should we really skip the question here, maybe the result won't be stored if we do that continue; } // Following line DISABLED BY lemeur // It prevents further calls to checkquestionfordisplay if using PREVIOUS button // from the LimeSurvey Navigator Toolbar // $_SESSION['fieldarray'][$key][7]='N'; //Get the answers/inputnames list($plus_qanda, $plus_inputnames)=retrieveAnswers($ia); if ($plus_qanda) { $plus_qanda[] = $ia[4]; $plus_qanda[] = $ia[6]; // adds madatory identifyer for adding mandatory class to question wrapping div $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); } // Display the "file validation" popup if necessary if (isset($filenotvalidated)) { list($filevalidationpopup, $fpopup) = file_validation_popup($ia, $filenotvalidated); } //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); } } if ($ia[4] == "|") $upload_file = TRUE; } //end iteration if (isset($thissurvey['showprogress']) && $thissurvey['showprogress'] == 'Y') { if ($show_empty_group) { $percentcomplete = makegraph($_SESSION['totalsteps']+1, $_SESSION['totalsteps']); } else { $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;} if (isset($fpopup)) {echo $fpopup;} //foreach(file("$thistpl/startpage.pstpl") as $op) //{ // echo templatereplace($op); //} echo templatereplace(file_get_contents("$thistpl/startpage.pstpl")); //ALTER PAGE CLASS TO PROVIDE WHOLE-PAGE ALTERNATION if ($_SESSION['step'] != $_SESSION['prevstep'] || (isset($_SESSION['stepno']) && $_SESSION['stepno'] % 2)) { if (!isset($_SESSION['stepno'])) $_SESSION['stepno'] = 0; if ($_SESSION['step'] != $_SESSION['prevstep']) ++$_SESSION['stepno']; if ($_SESSION['stepno'] % 2) { echo "\n"; } } $hiddenfieldnames=implode("|", $inputnames); if (isset($upload_file) && $upload_file) echo "
\n"; else echo " \n"; echo sDefaultSubmitHandler(); // <-- END FEATURE - SAVE // <-- START THE SURVEY --> echo templatereplace(file_get_contents("{$thistpl}/survey.pstpl")); // the runonce element has been changed from a hidden to a text/display:none one // in order to workaround an not-reproduced issue #4453 (lemeur) echo " \n\n"; // End checkconditions javascript function echo "\n\n\n"; echo templatereplace(file_get_contents("$thistpl/startgroup.pstpl")); echo "\n"; if ($groupdescription) { echo templatereplace(file_get_contents("$thistpl/groupdescription.pstpl")); } echo "\n"; //Display the "mandatory" message on page if necessary if (isset($showpopups) && $showpopups == 0 && isset($notanswered) && $notanswered == true) { echo "

" . $clang->gT("One or more mandatory questions have not been answered. You cannot proceed until these have been completed.") . "

"; } //Display the "validation" message on page if necessary if (isset($showpopups) && $showpopups == 0 && isset($notvalidated) && $notvalidated == true) { echo "

" . $clang->gT("One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid.") . "

"; } //Display the "file validation" message on page if necessary if (isset($showpopups) && $showpopups == 0 && isset($filenotvalidated) && $filenotvalidated == true) { echo "

" . $clang->gT("One or more uploaded files are not in proper format/size. You cannot proceed until these files are valid.") . "

"; } echo "\n\n\n"; if (isset($qanda) && is_array($qanda)) { foreach ($qanda as $qa) { $lastgrouparray = explode("X",$qa[7]); $lastgroup = $lastgrouparray[0]."X".$lastgrouparray[1]; // id of the last group, derived from question id $q_class = question_class($qa[8]); // render question class (see common.php) if ($qa[9] == 'Y') { $man_class = ' mandatory'; } else { $man_class = ''; } if (!bCheckQuestionForAnswer($qa[7], $aFieldnamesInfoInv) && $_SESSION['maxstep'] != $_SESSION['step']) { $man_class .= ' missing'; } if ($qa[3] != 'Y') {$n_q_display = '';} else { $n_q_display = ' style="display: none;"';} $question= $qa[0]; //=================================================================== // The following four variables offer the templating system the // capacity to fully control the HTML output for questions making the // above echo redundant if desired. $question['essentials'] = 'id="question'.$qa[4].'"'.$n_q_display; $question['class'] = $q_class; $question['man_class'] = $man_class; $question['code']=$qa[5]; $question['sgq']=$qa[7]; //=================================================================== $answer=$qa[1]; $help=$qa[2]; $question_template = file_get_contents($thistpl.'/question.pstpl'); if( preg_match( '/\{QUESTION_ESSENTIALS\}/' , $question_template ) === false || preg_match( '/\{QUESTION_CLASS\}/' , $question_template ) === false ) { // if {QUESTION_ESSENTIALS} is present in the template but not {QUESTION_CLASS} remove it because you don't want id="" and display="" duplicated. $question_template = str_replace( '{QUESTION_ESSENTIALS}' , '' , $question_template ); $question_template = str_replace( '{QUESTION_CLASS}' , '' , $question_template ); echo '
'; echo templatereplace($question_template); echo '
'; } else { echo templatereplace($question_template); }; } echo "\n"; // for counting the time spent on each group } echo "\n\n\n"; echo templatereplace(file_get_contents("$thistpl/endgroup.pstpl")); echo "\n"; if (!$previewgrp){ $navigator = surveymover(); //This gets globalised in the templatereplace function echo "\n\n\n"; echo templatereplace(file_get_contents("$thistpl/navigator.pstpl")); echo "\n"; if ($thissurvey['active'] != "Y") { echo "

".$clang->gT("This survey is currently not active. You will not be able to save your responses.")."

\n"; } if($thissurvey['allowjumps']=='Y') { echo "\n\n\n"; echo '

' . $clang->gT("Question index") . '

'; for($v = 0, $n = 0; $n != $_SESSION['maxstep']; ++$n) { $g = $_SESSION['grouplist'][$n]; if(!checkgroupfordisplay($g[0])) continue; $sText = FlattenText($g[1]); $bGAnsw = true; foreach($_SESSION['fieldarray'] as $ia) { if($ia[5] != $g[0]) continue; $qidattributes=getQuestionAttributes($ia[0], $ia[4]); if($qidattributes['hidden']==1 || !checkquestionfordisplay($ia[0])) continue; if (!bCheckQuestionForAnswer($ia[1], $aFieldnamesInfoInv)) { $bGAnsw = false; break; } } ++$v; $class = ($n == $_SESSION['step'] - 1? 'current': ($bGAnsw? 'answer': 'missing')); if($v % 2) $class .= " odd"; $s = $n + 1; echo "
$v$sText
"; } if($_SESSION['maxstep'] == $_SESSION['totalsteps']) { echo "\n"; } echo '
'; /* Can be replaced by php or in global js */ echo "\n"; echo "\n"; } echo "\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 "\n"; } } } //SOME STUFF FOR MANDATORY QUESTIONS if (remove_nulls_from_array($mandatorys)) { $mandatory=implode("|", remove_nulls_from_array($mandatorys)); echo "\n"; } if (remove_nulls_from_array($conmandatorys)) { $conmandatory=implode("|", remove_nulls_from_array($conmandatorys)); echo "\n"; } if (remove_nulls_from_array($mandatoryfns)) { $mandatoryfn=implode("|", remove_nulls_from_array($mandatoryfns)); echo "\n"; } if (remove_nulls_from_array($conmandatoryfns)) { $conmandatoryfn=implode("|", remove_nulls_from_array($conmandatoryfns)); echo "\n"; } echo "\n"; echo "\n"; echo "\n"; if (isset($token) && !empty($token)) { echo "\n\n"; } } echo "
\n"; echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); echo "\n"; doFooter(); // Closing PHP tag intentionally left out - yes, it is okay