diff --git a/application/controllers/SurveyAction.php b/application/controllers/SurveyAction.php index 54c2adad85e..35049256cbd 100644 --- a/application/controllers/SurveyAction.php +++ b/application/controllers/SurveyAction.php @@ -721,6 +721,9 @@ function sendreq(surveyid) //Send local variables to the appropriate survey type $redata = compact(array_keys(get_defined_vars())); +// Yii::import('application.helpers.SurveyRuntimeHelper'); +// $tmp = new SurveyRuntimeHelper(); +// $tmp->run($redata); //CALL APPROPRIATE SCRIPT switch ($thissurvey['format']) diff --git a/application/helpers/SurveyRuntimeHelper.php b/application/helpers/SurveyRuntimeHelper.php new file mode 100644 index 00000000000..51ab28bfe1d --- /dev/null +++ b/application/helpers/SurveyRuntimeHelper.php @@ -0,0 +1,994 @@ + ($thissurvey['active'] == 'Y'), + 'allowsave' => ($thissurvey['allowsave'] == 'Y'), + 'anonymized' => ($thissurvey['anonymized'] != 'N'), + 'assessments' => ($thissurvey['assessments'] == 'Y'), + 'datestamp' => ($thissurvey['datestamp'] == 'Y'), + 'hyperlinkSyntaxHighlighting' => (($LEMdebugLevel & LEM_DEBUG_VALIDATION_SUMMARY) == LEM_DEBUG_VALIDATION_SUMMARY), // TODO set this to true if in admin mode but not if running a survey + 'ipaddr' => ($thissurvey['ipaddr'] == 'Y'), + 'refurl' => (($thissurvey['refurl'] == "Y") ? $_SESSION['refurl'] : NULL), + 'rooturl' => (isset($rooturl) ? $rooturl : ''), + 'savetimings' => ($thissurvey['savetimings'] == "Y"), + 'surveyls_dateformat' => (isset($thissurvey['surveyls_dateformat']) ? $thissurvey['surveyls_dateformat'] : 1), + 'startlanguage' => (isset($_SESSION['s_lang']) ? $_SESSION['s_lang'] : 'en'), + 'target' => (isset($uploaddir) ? "{$uploaddir}/surveys/{$thissurvey['sid']}/files/" : "/temp/{$thissurvey['sid']}/files"), + 'tempdir' => (isset($tempdir) ? $tempdir : '/temp/'), + 'timeadjust' => (isset($timeadjust) ? $timeadjust : 0), + 'token' => (isset($clienttoken) ? $clienttoken : NULL), + ); + + //Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB + $previewgrp = false; + if ($surveyMode == 'group' && isset($param['action']) && ($param['action'] == 'previewgroup')) + { + $previewgrp = true; + } + if (isset($param['newtest'])) + if ($param['newtest'] == "Y") + setcookie("limesurvey_timers", "0"); + $show_empty_group = false; + + if ($previewgrp) + { + $_SESSION['prevstep'] = 1; + $_SESSION['maxstep'] = 0; + } + else + { + //RUN THIS IF THIS IS THE FIRST TIME , OR THE FIRST PAGE ######################################## + if (!isset($_SESSION['step'])) // || !$_SESSION['step']) - don't do this for step0, else rebuild the session + { + $totalquestions = buildsurveysession($surveyid); + LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false, $LEMdebugLevel); + $_SESSION['step'] = 0; + if ($surveyMode == 'survey') + { + $move = "movenext"; // to force a call to NavigateForwards() + } + else if (isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') + { + //If explicitply set, hide the welcome screen + $_SESSION['step'] = 1; + } + } + + if (!isset($_SESSION['totalsteps'])) + { + $_SESSION['totalsteps'] = 0; + } + if (!isset($_SESSION['maxstep'])) + { + $_SESSION['maxstep'] = 0; + } + $_SESSION['prevstep'] = $_SESSION['step']; + + if (isset($_SESSION['LEMpostKey']) && (!isset($_POST['LEMpostKey']) || ($_POST['LEMpostKey'] != $_SESSION['LEMpostKey']))) + { + // then trying to resubmit (e.g. Next, Previous, Submit) from a cached copy of the page + // Simply re-display the current page without re-processing POST or re-validating input. Means user will lose whatever data entry the just tried + // Also flash a message + $moveResult = LimeExpressionManager::GetLastMoveResult(); + $move = "movenext"; // so will re-display the survey + $invalidLastPage = true; + $vpopup = "\n"; + } + else + { + //Move current step ########################################################################### + if (isset($move) && $move == 'moveprev' && ($thissurvey['allowprev'] == 'Y' || $thissurvey['allowjumps'] == 'Y')) + { + $moveResult = LimeExpressionManager::NavigateBackwards(); + if ($moveResult['at_start']) + { + $_SESSION['step'] = 0; + unset($moveResult); // so display welcome page again + } + } + if (isset($move) && $move == "movenext") + { + if (isset($_SESSION['LEMreload'])) + { + LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false, $LEMdebugLevel); + $moveResult = LimeExpressionManager::JumpTo($_SESSION['step'], false, false); // if late in the survey, will re-validate contents, which may be overkill + unset($_SESSION['LEMreload']); + } + else + { + $moveResult = LimeExpressionManager::NavigateForwards(); + } + } + if (isset($move) && ($move == 'movesubmit')) + { + if ($surveyMode == 'survey') + { + $moveResult = LimeExpressionManager::NavigateForwards(); + } + else + { + // may be submitting from the navigation bar, in which case need to process all intervening questions + // in order to update equations and ensure there are no intervening relevant mandatory or relevant invalid questions + $moveResult = LimeExpressionManager::JumpTo($_SESSION['totalsteps'] + 1, false); + } + } + if (isset($move) && (preg_match('/^changelang_/', $move))) + { + // jump to current step using new language, processing POST values + $moveResult = LimeExpressionManager::JumpTo($_SESSION['step'], false, true, false, true); // do process the POST data + } + if (isset($move) && bIsNumericInt($move) && $thissurvey['allowjumps'] == 'Y') + { + $move = (int) $move; + if ($move > 0 && (($move <= $_SESSION['step']) || (isset($_SESSION['maxstep']) && $move <= $_SESSION['maxstep']))) + { + $moveResult = LimeExpressionManager::JumpTo($move, false); + } + } + if (!isset($moveResult) && !($surveyMode != 'survey' && $_SESSION['step'] == 0)) + { + // Just in case not set via any other means, but don't do this if it is the welcome page + $moveResult = LimeExpressionManager::GetLastMoveResult(); + } + } + + if (isset($moveResult)) + { + if ($moveResult['finished'] == true) + { + $move = 'movesubmit'; + } + else + { + $_SESSION['step'] = $moveResult['seq'] + 1; // step is index base 1 + $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); + } + if ($move == "movesubmit" && $moveResult['finished'] == false) + { + // then there are errors, so don't finalize the survey + $move = "movenext"; // so will re-display the survey + $invalidLastPage = true; + } + } + + // 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 ($surveyMode != 'survey' && $_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 ( + (isset($move) && ($move == "moveprev" || (is_int($move) && $_SESSION['prevstep'] == $_SESSION['maxstep']) || $_SESSION['prevstep'] == $_SESSION['step'])) || + (isset($_POST['saveall']) && $_POST['saveall'] == $clang->gT("Save your responses so far"))) + { + if (Yii::app()->getConfig('allowmandbackwards') == 1) + { + $backok = "Y"; + } + else + { + $backok = "N"; + } + } + else + { + $backok = "N"; // NA, since not moving backwards + } + + if ($thissurvey['active'] == "Y" && isset($_POST['saveall'])) + { + // must do this here to process the POSTed values + $moveResult = LimeExpressionManager::JumpTo($_SESSION['step'], false); // by jumping to current step, saves data so far + + require_once("save.php"); // for supporting functions only + showsaveform(); // generates a form and exits, awaiting input + } + + if ($thissurvey['active'] == "Y" && isset($_POST['saveprompt'])) + { + // The response from the save form + require_once("save.php"); // for supporting functions only + // CREATE SAVED CONTROL RECORD USING SAVE FORM INFORMATION + $flashmessage = savedcontrol(); + + if (isset($errormsg) && $errormsg != "") + { + showsaveform(); // reshow the form if there is an error + } + + $moveResult = LimeExpressionManager::GetLastMoveResult(); + + // TODO - does this work automatically for token answer persistence? Used to be savedsilent() + } + + //Now, we check mandatory questions if necessary + //CHECK IF ALL CONDITIONAL MANDATORY QUESTIONS THAT APPLY HAVE BEEN ANSWERED + if (isset($moveResult) && !$moveResult['finished']) + { + $unansweredSQList = $moveResult['unansweredSQs']; + if (strlen($unansweredSQList) > 0 && $backok != "N") + { + $notanswered = explode('|', $unansweredSQList); + } + else + { + $notanswered = array(); + } + + //CHECK INPUT + $invalidSQList = $moveResult['invalidSQs']; + if (strlen($invalidSQList) > 0 && $backok != "N") + { + $notvalidated = explode('|', $invalidSQList); + } + else + { + $notvalidated = array(); + } + } + + // CHECK UPLOADED FILES + // TMSW - Move this into LEM::NavigateForwards? + $filenotvalidated = checkUploadedFileValidity($surveyid, $move, $backok); + + //SEE IF THIS GROUP SHOULD DISPLAY + $show_empty_group = false; + + if ($_SESSION['step'] == 0) + $show_empty_group = true; + + $redata = compact(array_keys(get_defined_vars())); + + //SUBMIT ############################################################################### + if ((isset($move) && $move == "movesubmit")) + { + 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); + } + if ($thissurvey['printanswers'] != 'Y') + { + killSession(); + } + + sendcacheheaders(); + doHeader(); + + echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata); + + //Check for assessments + if ($thissurvey['assessments'] == "Y" && $assessments) + { + echo templatereplace(file_get_contents("$thistpl/assessment.pstpl"), array(), $redata); + } + + // 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'] = passthruReplace($thissurvey['surveyls_url'], $thissurvey); + + $content = ''; + $content .= templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata); + + //Check for assessments + if ($thissurvey['assessments'] == "Y") + { + $assessments = doAssessment($surveyid); + if ($assessments) + { + $content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl"), array(), $redata); + } + } + + //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"), array(), $redata); + + //echo $thissurvey['url']; + //Check for assessments + if ($thissurvey['assessments'] == "Y") + { + $assessments = doAssessment($surveyid); + if ($assessments) + { + $content .= templatereplace(file_get_contents("$thistpl/assessment.pstpl"), array(), $redata); + } + } + + + 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 = templatereplace($thissurvey['surveyls_url']); // TODO - check safety of this - provides access to any replacement value + $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 + 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"), array(), $redata); + echo "\n
\n"; + if ((($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING)) + { + echo LimeExpressionManager::GetDebugTimingMessage(); + } + if ((($LEMdebugLevel & LEM_DEBUG_VALIDATION_SUMMARY) == LEM_DEBUG_VALIDATION_SUMMARY)) + { + echo "
Group/Question Validation Results:" . $moveResult['message'] . "
\n"; + } + echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); + doFooter(); + exit; + } + } + + $redata = compact(array_keys(get_defined_vars())); + + // IF GOT THIS FAR, THEN DISPLAY THE ACTIVE GROUP OF QUESTIONSs + //SEE IF $surveyid EXISTS #################################################################### + if ($surveyExists < 1) + { + //SURVEY DOES NOT EXIST. POLITELY EXIT. + echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata); + echo "\t

\n"; + echo "\t" . $clang->gT("Sorry. There is no matching survey.") . "
 \n"; + echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"), array(), $redata); + doFooter(); + exit; + } + createFieldMap($surveyid); + //GET GROUP DETAILS + + if ($surveyMode == 'group' && $previewgrp) + { + setcookie("limesurvey_timers", "0"); + $_gid = sanitize_int($param['gid']); + + LimeExpressionManager::StartSurvey($thissurvey['sid'], 'group', $surveyOptions, false, $LEMdebugLevel); + $gseq = LimeExpressionManager::GetGroupSeq($_gid); + if ($gseq == -1) + { + echo $clang->gT('Invalid group number for this survey: ') . $_gid; + exit; + } + $moveResult = LimeExpressionManager::JumpTo($gseq + 1, true); + if (is_null($moveResult)) + { + echo $clang->gT('This group contains no questions. You must add questions to this group before you can preview it'); + exit; + } + if (isset($moveResult)) + { + $_SESSION['step'] = $moveResult['seq'] + 1; // step is index base 1? + } + + $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); + $gid = $stepInfo['gid']; + $groupname = $stepInfo['gname']; + $groupdescription = $stepInfo['gtext']; + } + 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 if ($surveyMode != 'survey') + { + + $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); + // print_r($stepInfo);die(); + $gid = $stepInfo['gid']; + $groupname = $stepInfo['gname']; + $groupdescription = $stepInfo['gtext']; + } + } + + if ($_SESSION['step'] > $_SESSION['maxstep']) + { + $_SESSION['maxstep'] = $_SESSION['step']; + } + + // If the survey uses answer persistence and a srid is registered in SESSION + // then loadanswers from this srid + /* Only survey mode used this - should all? + if ($thissurvey['tokenanswerspersistence'] == 'Y' && + $thissurvey['anonymized'] == "N" && + isset($_SESSION['srid']) && + $thissurvey['active'] == "Y") + { + loadanswers(); + } + */ + + //****************************************************************************************************** + //PRESENT SURVEY + //****************************************************************************************************** + + $okToShowErrors = (!$previewgrp && (isset($invalidLastPage) || $_SESSION['prevstep'] == $_SESSION['step'])); + + Yii::app()->getController()->loadHelper('qanda'); + + //Iterate through the questions about to be displayed: + $inputnames = array(); + + foreach ($_SESSION['grouplist'] as $gl) + { + $gid = $gl[0]; + $qnumber = 0; + + if ($surveyMode != 'survey') + { + $onlyThisGID = $stepInfo['gid']; + if ($onlyThisGID != $gid) + { + continue; + } + } + + // TMSW - could iterate through LEM::currentQset instead + foreach ($_SESSION['fieldarray'] as $key => $ia) + { + ++$qnumber; + $ia[9] = $qnumber; // incremental question count; + + if ((isset($ia[10]) && $ia[10] == $gid) || (!isset($ia[10]) && $ia[5] == $gid)) + { + if ($surveyMode == 'question' && $ia[0] != $stepInfo['qid']) + { + continue; + } + $qidattributes = Question_attributes::model()->getQuestionAttributes($ia[0], $ia[4])->read(); + if ($ia[4] != '*' && ($qidattributes === false || !isset($qidattributes['hidden']) || $qidattributes['hidden'] == 1)) + { + continue; + } + + //Get the answers/inputnames + // TMSW - can content of retrieveAnswers() be provided by LEM? Review scope of what it provides. + // TODO - retrieveAnswers is slow - queries database separately for each question. May be fixed in _CI or _YII ports, so ignore for now + 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 + // TMSW - get question-level error messages - don't call **_popup() directly + if ($okToShowErrors && $stepInfo['mandViolation']) + { + list($mandatorypopup, $popup) = mandatory_popup($ia, $notanswered); + } + + //Display the "validation" popup if necessary + if ($okToShowErrors && !$stepInfo['valid']) + { + list($validationpopup, $vpopup) = validation_popup($ia, $notvalidated); + } + + // Display the "file validation" popup if necessary + if ($okToShowErrors && isset($filenotvalidated)) + { + list($filevalidationpopup, $fpopup) = file_validation_popup($ia, $filenotvalidated); + } + } + if ($ia[4] == "|") + $upload_file = TRUE; + } //end iteration + } + + if ($surveyMode != 'survey' && isset($thissurvey['showprogress']) && $thissurvey['showprogress'] == 'Y') + { + if ($show_empty_group) + { + $percentcomplete = makegraph($_SESSION['totalsteps'] + 1, $_SESSION['totalsteps']); + } + else + { + $percentcomplete = makegraph($_SESSION['step'], $_SESSION['totalsteps']); + } + } + if (!(isset($languagechanger) && strlen($languagechanger) > 0) && function_exists('makelanguagechanger')) + { + $languagechanger = makelanguagechanger($thissurvey['language']); + } + + //READ TEMPLATES, INSERT DATA AND PRESENT PAGE + sendcacheheaders(); + doHeader(); + + if (isset($popup)) + { + echo $popup; + } + if (isset($vpopup)) + { + echo $vpopup; + } + if (isset($fpopup)) + { + echo $fpopup; + } + + $redata = compact(array_keys(get_defined_vars())); + + echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata); + + //ALTER PAGE CLASS TO PROVIDE WHOLE-PAGE ALTERNATION + if ($surveyMode != 'survey' && $_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 + + if ($surveyMode == 'survey') + { + if (isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') + { + //Hide the welcome screen if explicitly set + } + else + { + echo templatereplace(file_get_contents("$thistpl/welcome.pstpl"), array(), $redata) . "\n"; + } + + if ($thissurvey['anonymized'] == "Y") + { + echo templatereplace(file_get_contents("$thistpl/privacy.pstpl"), array(), $redata) . "\n"; + } + } + + // <-- START THE SURVEY --> + if ($surveyMode != 'survey') + { + echo templatereplace(file_get_contents("{$thistpl}/survey.pstpl"), array(), $redata); + } + + // 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 " + + +END; + + //Display the "mandatory" message on page if necessary + if (isset($showpopups) && $showpopups == 0 && $stepInfo['mandViolation'] && $okToShowErrors) + { + 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 && !$stepInfo['valid'] && $okToShowErrors) + { + 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 && $okToShowErrors) + { + echo "

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

"; + } + + foreach ($_SESSION['grouplist'] as $gl) + { + $gid = $gl[0]; + $groupname = $gl[1]; + $groupdescription = $gl[2]; + + if ($surveyMode != 'survey' && $gid != $onlyThisGID) + { + continue; + } + + $redata = compact(array_keys(get_defined_vars())); + + echo "\n\n\n"; + echo "\n\n
\n"; + echo templatereplace(file_get_contents("$thistpl/startgroup.pstpl"), array(), $redata); + echo "\n"; + + if ($groupdescription) + { + echo templatereplace(file_get_contents("$thistpl/groupdescription.pstpl"), array(), $redata); + } + echo "\n"; + + echo "\n\n\n"; + + if (!empty($qanda)) + { + foreach ($qanda as $qa) // one entry per QID + { + if ($gid != $qa[6]) + { + continue; + } + + $qid = $qa[4]; + $qinfo = LimeExpressionManager::GetQuestionStatus($qid); + $lastgrouparray = explode("X", $qa[7]); + $lastgroup = $lastgrouparray[0] . "X" . $lastgrouparray[1]; // id of the last group, derived from question id + + $q_class = question_class($qinfo['info']['type']); + + $man_class = ''; + if ($qinfo['info']['mandatory'] == 'Y') + { + $man_class .= ' mandatory'; + } + + if ($qinfo['anyUnanswered'] && $_SESSION['maxstep'] != $_SESSION['step']) + { + $man_class .= ' missing'; + } + + $n_q_display = ''; + if ($qinfo['hidden'] && $qinfo['info']['type'] != '*') + { + continue; // skip this one + } + + if (!$qinfo['relevant'] || ($qinfo['hidden'] && $qinfo['info']['type'] == '*')) + { + $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]; + $question['aid'] = $qinfo['info']['aid']; + $question['sqid'] = $qinfo['info']['sqid']; + //=================================================================== + $answer = $qa[1]; + $help = $qinfo['info']['help']; // $qa[2]; + + $redata = compact(array_keys(get_defined_vars())); + + $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, array(), $redata, false, $qa[4]); + echo '
'; + } + else + { + // TMSW - eventually refactor so that only substitutes the QUESTION_** fields - doesn't need full power of template replace + // TMSW - also, want to return a string, and call templatereplace once on that result string once all done. + echo templatereplace($question_template, array(), $redata, false, $qa[4]); + }; + } + if ($surveyMode != 'survey') + { + echo "\n"; // for counting the time spent on each group + } + } + echo "\n\n\n"; + echo templatereplace(file_get_contents("$thistpl/endgroup.pstpl"), array(), $redata); + echo "\n\n
\n"; + } + + LimeExpressionManager::FinishProcessingGroup(); + echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); + LimeExpressionManager::FinishProcessingPage(); + + if (!$previewgrp) + { + $navigator = surveymover(); //This gets globalised in the templatereplace function + $redata = compact(array_keys(get_defined_vars())); + + echo "\n\n\n"; + echo templatereplace(file_get_contents("$thistpl/navigator.pstpl"), array(), $redata); + 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 ($surveyMode != 'survey' && $thissurvey['allowjumps'] == 'Y') + { + echo "\n\n\n"; + + echo '

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

'; + + $stepIndex = LimeExpressionManager::GetStepIndexInfo(); + $lastGseq = -1; + for ($v = 0, $n = 0; $n != $_SESSION['maxstep']; ++$n) + { + if (!isset($stepIndex[$n])) + { + continue; // this is an invalid group - skip it + } + $stepInfo = $stepIndex[$n]; + + if (!$stepInfo['show']) + continue; + + if ($surveyMode == 'question' && $lastGseq != $stepInfo['gseq']) + { + // show the group label + echo '

' . FlattenText($stepInfo['gname']) . "

"; + $lastGseq = $stepInfo['gseq']; + } + + $sText = (($surveyMode == 'group') ? FlattenText($stepInfo['gname'] . ': ' . $stepInfo['gtext']) : FlattenText($stepInfo['qtext'])); + $bGAnsw = !$stepInfo['anyUnanswered']; + + ++$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"; + echo "\n"; + echo "\n"; + $_SESSION['LEMpostKey'] = mt_rand(); + echo "\n"; + + if (isset($token) && !empty($token)) + { + echo "\n\n"; + } + } + + if (($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING) + { + echo LimeExpressionManager::GetDebugTimingMessage(); + } + if (($LEMdebugLevel & LEM_DEBUG_VALIDATION_SUMMARY) == LEM_DEBUG_VALIDATION_SUMMARY) + { + echo "
Group/Question Validation Results:" . $moveResult['message'] . "
\n"; + } + echo "
\n"; + + echo templatereplace(file_get_contents("$thistpl/endpage.pstpl"), array(), $redata); + + echo "\n"; + + doFooter(); + + } +} diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index a5d69fd3ad2..62b4973bc62 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -5876,7 +5876,7 @@ function aGetFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonor { if (!empty($fname['qid'])) { - $attributes = getQuestionAttributes($fname['qid']); + $attributes = Question_attributes::model()->getQuestionAttributes($fname['qid']); if (getQuestionAttributeValue($attributes, 'hidden') == 1) { continue; diff --git a/application/models/Survey.php b/application/models/Survey.php index 2831c27a16e..9e79dbb03aa 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -205,13 +205,13 @@ public function insertNewSurvey($data, $xssfiltering = false) } /** - * !!! DOESN'T WORK !!! - * - * @access public - * @param int $iSurveyID - * @param bool @recursive - * @return void - */ + * Deletes a survey and all its data + * + * @access public + * @param int $iSurveyID + * @param bool @recursive + * @return void + */ public function deleteSurvey($iSurveyID, $recursive=true) { Survey::model()->deleteByPk($iSurveyID);