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 PREGS $notvalidated=checkpregs($move,$backok); //CHECK QUOTA if ($thissurvey['active'] == "Y") { check_quota('enforce',$surveyid); } //SEE IF THIS GROUP SHOULD DISPLAY if (isset($move) && $_SESSION['step'] != 0 && $move != "movesubmit") { while(checkgroupfordisplay($_SESSION['grouplist'][$_SESSION['step']-1][0]) === false) { if (isset($move) && $move == "moveprev") { $_SESSION['step']=$_SESSION['step']-1; } if (isset($move) && $move == "movenext") { $_SESSION['step']=$_SESSION['step']+1; } if ($_SESSION['step']>$_SESSION['totalsteps']) { $move = "movesubmit"; submitanswer(); // complete this answer (submitdate) break; } } } //SUBMIT ############################################################################### if ((isset($move) && $move == "movesubmit") && (!isset($notanswered) || !$notanswered) && (!isset($notvalidated) || !$notvalidated )) { 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") { 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 = "
".$clang->gT("Did Not Save")."

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

\n"; $completed .= "".$clang->gT("Clear Responses")."

\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 = "
" . $clang->gT("Thank you")."

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


\n"; //Update the token if needed and send a confirmation email if (isset($clienttoken) && $clienttoken) { submittokens(); } //Send notification to survey administrator //Thanks to Jeff Clement http://jclement.ca if ($thissurvey['sendnotification'] > 0 && $thissurvey['adminemail']) { sendsubmitnotification($thissurvey['sendnotification']); } $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 = "
" .$clang->gT("Thank you")."

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


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

" ."" .$clang->gT("Click here to print your answers.") ."
\n"; } //***************************************** $_SESSION['finished']=true; $_SESSION['sid']=$surveyid; sendcacheheaders(); if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['url']) { //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}",$clienttoken, $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
\n"; echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); doFooter(); if($thissurvey['printanswers'] != 'Y' && $thissurvey['usecookie'] != 'Y' && $tokensexist !=1) { session_unset(); session_destroy(); } 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; } //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
\n"; echo "\n\n\n"; echo templatereplace(file_get_contents("$thistpl/welcome.pstpl"))."\n"; if ($thissurvey['private'] == "Y") { echo templatereplace(file_get_contents("$thistpl/privacy.pstpl"))."\n"; } $navigator = surveymover(); echo templatereplace(file_get_contents("$thistpl/navigator.pstpl")); if ($thissurvey['active'] != "Y") { echo "\t\t
".$clang->gT("This survey is not currently active. You will not be able to save your responses.")."
\n"; } echo "\n\n"; echo "\n\n"; echo "\n
\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 title 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; echo "\n\n\n"; echo " \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 << \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"; echo "\n\n\n"; if (isset($qanda) && is_array($qanda)) { foreach ($qanda as $qa) { echo "\n\t\n"; echo "\t\t\t\t
\n";} else {echo " style='display: none'>\n";} $question=""; $answer=$qa[1]; $help=$qa[2]; $questioncode=$qa[5]; echo templatereplace(file_get_contents("$thistpl/question.pstpl")); echo "\t\t\t\t
\n"; } } echo "\n\n\n"; echo templatereplace(file_get_contents("$thistpl/endgroup.pstpl")); echo "\n"; $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 "\t\t
".$clang->gT("This survey is not currently active. You will not be able to save your responses.")."
\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"; echo "\n"; echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); echo "\n"; doFooter(); ?>