diff --git a/application/helpers/SurveyRuntimeHelper.php b/application/helpers/SurveyRuntimeHelper.php index b19bd6490e4..4ff46fa0e57 100644 --- a/application/helpers/SurveyRuntimeHelper.php +++ b/application/helpers/SurveyRuntimeHelper.php @@ -23,6 +23,7 @@ class SurveyRuntimeHelper { */ function run($surveyid,$args) { extract($args); + $LEMsessid = 'survey_' . $surveyid; // $LEMdebugLevel - customizable debugging for Lime Expression Manager $LEMdebugLevel = 0; // LEM_DEBUG_TIMING; // (LEM_DEBUG_TIMING + LEM_DEBUG_VALIDATION_SUMMARY + LEM_DEBUG_VALIDATION_DETAIL); @@ -52,10 +53,10 @@ function run($surveyid,$args) { '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'), 'radix'=>$radix, - 'refurl' => (($thissurvey['refurl'] == "Y") ? $_SESSION['survey_'.$surveyid]['refurl'] : NULL), + 'refurl' => (($thissurvey['refurl'] == "Y") ? $_SESSION[$LEMsessid]['refurl'] : NULL), 'savetimings' => ($thissurvey['savetimings'] == "Y"), 'surveyls_dateformat' => (isset($thissurvey['surveyls_dateformat']) ? $thissurvey['surveyls_dateformat'] : 1), - 'startlanguage' => (isset($_SESSION['survey_'.$surveyid]['s_lang']) ? $_SESSION['survey_'.$surveyid]['s_lang'] : 'en'), + 'startlanguage' => (isset($_SESSION[$LEMsessid]['s_lang']) ? $_SESSION[$LEMsessid]['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), @@ -79,18 +80,18 @@ function run($surveyid,$args) { if ($previewgrp || $previewquestion) { - $_SESSION['survey_'.$surveyid]['prevstep'] = 1; - $_SESSION['survey_'.$surveyid]['maxstep'] = 0; + $_SESSION[$LEMsessid]['prevstep'] = 1; + $_SESSION[$LEMsessid]['maxstep'] = 0; } else { //RUN THIS IF THIS IS THE FIRST TIME , OR THE FIRST PAGE ######################################## - if (!isset($_SESSION['survey_'.$surveyid]['step'])) // || !$_SESSION['step']) - don't do this for step0, else rebuild the session + if (!isset($_SESSION[$LEMsessid]['step'])) // || !$_SESSION[$LEMsessid]['step']) - don't do this for step0, else rebuild the session { $totalquestions = buildsurveysession($surveyid); LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false, $LEMdebugLevel); - $_SESSION['survey_'.$surveyid]['step'] = 0; + $_SESSION[$LEMsessid]['step'] = 0; if ($surveyMode == 'survey') { $move = "movenext"; // to force a call to NavigateForwards() @@ -98,21 +99,21 @@ function run($surveyid,$args) { else if (isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') { //If explicitply set, hide the welcome screen - $_SESSION['survey_'.$surveyid]['step'] = 0; + $_SESSION[$LEMsessid]['step'] = 0; $move = "movenext"; } } - if (!isset($_SESSION['survey_'.$surveyid]['totalsteps'])) + if (!isset($_SESSION[$LEMsessid]['totalsteps'])) { - $_SESSION['survey_'.$surveyid]['totalsteps'] = 0; + $_SESSION[$LEMsessid]['totalsteps'] = 0; } - if (!isset($_SESSION['survey_'.$surveyid]['maxstep'])) + if (!isset($_SESSION[$LEMsessid]['maxstep'])) { - $_SESSION['survey_'.$surveyid]['maxstep'] = 0; + $_SESSION[$LEMsessid]['maxstep'] = 0; } - if (isset($_SESSION['LEMpostKey']) && isset($_POST['LEMpostKey']) && $_POST['LEMpostKey'] != $_SESSION['LEMpostKey']) + if (isset($_SESSION[$LEMsessid]['LEMpostKey']) && isset($_POST['LEMpostKey']) && $_POST['LEMpostKey'] != $_SESSION[$LEMsessid]['LEMpostKey']) { // then trying to resubmit (e.g. Next, Previous, Submit) from a cached copy of the page // Does not try to save anything from the page to the database @@ -138,19 +139,19 @@ function run($surveyid,$args) { if (!(isset($_POST['saveall']) || isset($_POST['saveprompt']) || isset($_POST['loadall']) || isset($_GET['sid']) || $LEMskipReprocessing || (isset($move) && (preg_match('/^changelang_/',$move))))) { - $_SESSION['survey_'.$surveyid]['prevstep'] = $_SESSION['survey_'.$surveyid]['step']; + $_SESSION[$LEMsessid]['prevstep'] = $_SESSION[$LEMsessid]['step']; } - if (!isset($_SESSION['prevstep'])) + if (!isset($_SESSION[$LEMsessid]['prevstep'])) { - $_SESSION['survey_'.$surveyid]['prevstep']=-1; // this only happens on re-load + $_SESSION[$LEMsessid]['prevstep']=-1; // this only happens on re-load } - if (isset($_SESSION['LEMtokenResume'])) + if (isset($_SESSION[$LEMsessid]['LEMtokenResume'])) { LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false,$LEMdebugLevel); - $moveResult = LimeExpressionManager::JumpTo($_SESSION['survey_'.$surveyid]['step']+1,false,false); // if late in the survey, will re-validate contents, which may be overkill - unset($_SESSION['LEMtokenResume']); - unset($_SESSION['LEMreload']); + $moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step']+1,false,false); // if late in the survey, will re-validate contents, which may be overkill + unset($_SESSION[$LEMsessid]['LEMtokenResume']); + unset($_SESSION[$LEMsessid]['LEMreload']); } else if (!$LEMskipReprocessing) { @@ -160,17 +161,17 @@ function run($surveyid,$args) { $moveResult = LimeExpressionManager::NavigateBackwards(); if ($moveResult['at_start']) { - $_SESSION['survey_'.$surveyid]['step'] = 0; + $_SESSION[$LEMsessid]['step'] = 0; unset($moveResult); // so display welcome page again } } if (isset($move) && $move == "movenext") { - if (isset($_SESSION['survey_'.$surveyid]['LEMreload'])) + if (isset($_SESSION[$LEMsessid]['LEMreload'])) { LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, false, $LEMdebugLevel); - $moveResult = LimeExpressionManager::JumpTo($_SESSION['survey_'.$surveyid]['step'], false, false); // if late in the survey, will re-validate contents, which may be overkill - unset($_SESSION['survey_'.$surveyid]['LEMreload']); + $moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, false); // if late in the survey, will re-validate contents, which may be overkill + unset($_SESSION[$LEMsessid]['LEMreload']); } else { @@ -187,23 +188,23 @@ function run($surveyid,$args) { { // 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['survey_'.$surveyid]['totalsteps'] + 1, false); + $moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['totalsteps'] + 1, false); } } if (isset($move) && (preg_match('/^changelang_/', $move))) { // jump to current step using new language, processing POST values - $moveResult = LimeExpressionManager::JumpTo($_SESSION['survey_'.$surveyid]['step'], false, true, false, true); // do process the POST data + $moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, true, false, true); // do process the POST data } if (isset($move) && isNumericInt($move) && $thissurvey['allowjumps'] == 'Y') { $move = (int) $move; - if ($move > 0 && (($move <= $_SESSION['survey_'.$surveyid]['step']) || (isset($_SESSION['survey_'.$surveyid]['maxstep']) && $move <= $_SESSION['survey_'.$surveyid]['maxstep']))) + if ($move > 0 && (($move <= $_SESSION[$LEMsessid]['step']) || (isset($_SESSION[$LEMsessid]['maxstep']) && $move <= $_SESSION[$LEMsessid]['maxstep']))) { $moveResult = LimeExpressionManager::JumpTo($move, false); } } - if (!isset($moveResult) && !($surveyMode != 'survey' && $_SESSION['survey_'.$surveyid]['step'] == 0)) + if (!isset($moveResult) && !($surveyMode != 'survey' && $_SESSION[$LEMsessid]['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(true); @@ -219,7 +220,7 @@ function run($surveyid,$args) { } else { - $_SESSION['survey_'.$surveyid]['step'] = $moveResult['seq'] + 1; // step is index base 1 + $_SESSION[$LEMsessid]['step'] = $moveResult['seq'] + 1; // step is index base 1 $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); } if ($move == "movesubmit" && $moveResult['finished'] == false) @@ -234,9 +235,9 @@ function run($surveyid,$args) { // Previously we used to keep the session and redirect the user to the // submit page. - if ($surveyMode != 'survey' && $_SESSION['survey_'.$surveyid]['step'] == 0) + if ($surveyMode != 'survey' && $_SESSION[$LEMsessid]['step'] == 0) { - $_SESSION['test']=time(); + $_SESSION[$LEMsessid]['test']=time(); display_first_page(); exit; } @@ -244,7 +245,7 @@ function run($surveyid,$args) { //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['survey_'.$surveyid]['prevstep'] == $_SESSION['survey_'.$surveyid]['maxstep']) || $_SESSION['survey_'.$surveyid]['prevstep'] == $_SESSION['survey_'.$surveyid]['step'])) || + (isset($move) && ($move == "moveprev" || (is_int($move) && $_SESSION[$LEMsessid]['prevstep'] == $_SESSION[$LEMsessid]['maxstep']) || $_SESSION[$LEMsessid]['prevstep'] == $_SESSION[$LEMsessid]['step'])) || (isset($_POST['saveall']) && $_POST['saveall'] == $clang->gT("Save your responses so far"))) { if (Yii::app()->getConfig('allowmandbackwards') == 1) @@ -268,7 +269,7 @@ function run($surveyid,$args) { if ($thissurvey['active'] == "Y" && isset($_POST['saveall'])) { // must do this here to process the POSTed values - $moveResult = LimeExpressionManager::JumpTo($_SESSION['survey_'.$surveyid]['step'], false); // by jumping to current step, saves data so far + $moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false); // by jumping to current step, saves data so far $cSave->showsaveform(); // generates a form and exits, awaiting input } @@ -325,7 +326,7 @@ function run($surveyid,$args) { //SEE IF THIS GROUP SHOULD DISPLAY $show_empty_group = false; - if ($_SESSION['survey_'.$surveyid]['step'] == 0) + if ($_SESSION[$LEMsessid]['step'] == 0) $show_empty_group = true; $redata = compact(array_keys(get_defined_vars())); @@ -336,9 +337,9 @@ function run($surveyid,$args) { // setcookie("limesurvey_timers", "", time() - 3600); // remove the timers cookies //@todo fix - sometimes results in headers already sent error if ($thissurvey['refurl'] == "Y") { - if (!in_array("refurl", $_SESSION['survey_'.$surveyid]['insertarray'])) //Only add this if it doesn't already exist + if (!in_array("refurl", $_SESSION[$LEMsessid]['insertarray'])) //Only add this if it doesn't already exist { - $_SESSION['survey_'.$surveyid]['insertarray'][] = "refurl"; + $_SESSION[$LEMsessid]['insertarray'][] = "refurl"; } } @@ -368,9 +369,9 @@ function run($surveyid,$args) { // 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++) + for($i = 1; isset($_SESSION[$LEMsessid]['files'][$i]); $i++) { - unlink('upload/tmp/'.$_SESSION['files'][$i]['filename']); + unlink('upload/tmp/'.$_SESSION[$LEMsessid]['files'][$i]['filename']); } */ $completed = $thissurvey['surveyls_endtext']; @@ -463,7 +464,7 @@ function run($surveyid,$args) { // Link to Public statistics ********** if ($thissurvey['publicstatistics'] == 'Y') { - $url = Yii::app()->getController()->createUrl("statistics_user/sid/{$surveyid}/lang/".$_SESSION['survey_'.$surveyid]['s_lang']); + $url = Yii::app()->getController()->createUrl("statistics_user/sid/{$surveyid}/lang/".$_SESSION[$LEMsessid]['s_lang']); $completed .= "

" . "" . $clang->gT("View the statistics for this survey.") @@ -471,8 +472,8 @@ function run($surveyid,$args) { } //***************************************** - $_SESSION['survey_'.$surveyid]['finished'] = true; - $_SESSION['survey_'.$surveyid]['sid'] = $surveyid; + $_SESSION[$LEMsessid]['finished'] = true; + $_SESSION[$LEMsessid]['sid'] = $surveyid; sendCacheHeaders(); if (isset($thissurvey['autoredirect']) && $thissurvey['autoredirect'] == "Y" && $thissurvey['surveyls_url']) @@ -529,7 +530,7 @@ function run($surveyid,$args) { doFooter(); exit; } - createFieldMap($surveyid,'full',false,false,$_SESSION['survey_'.$surveyid]['s_lang']); + createFieldMap($surveyid,'full',false,false,$_SESSION[$LEMsessid]['s_lang']); //GET GROUP DETAILS if ($surveyMode == 'group' && $previewgrp) @@ -552,7 +553,7 @@ function run($surveyid,$args) { } if (isset($moveResult)) { - $_SESSION['survey_'.$surveyid]['step'] = $moveResult['seq'] + 1; // step is index base 1? + $_SESSION[$LEMsessid]['step'] = $moveResult['seq'] + 1; // step is index base 1? } $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); @@ -562,7 +563,7 @@ function run($surveyid,$args) { } else { - if (($show_empty_group) || !isset($_SESSION['survey_'.$surveyid]['grouplist'])) + if (($show_empty_group) || !isset($_SESSION[$LEMsessid]['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"); @@ -587,12 +588,12 @@ function run($surveyid,$args) { } if ($previewquestion) { - $_SESSION['survey_'.$surveyid]['step'] = 0; //maybe unset it after the question has been displayed? + $_SESSION[$LEMsessid]['step'] = 0; //maybe unset it after the question has been displayed? } - if ($_SESSION['survey_'.$surveyid]['step'] > $_SESSION['survey_'.$surveyid]['maxstep']) + if ($_SESSION[$LEMsessid]['step'] > $_SESSION[$LEMsessid]['maxstep']) { - $_SESSION['survey_'.$surveyid]['maxstep'] = $_SESSION['survey_'.$surveyid]['step']; + $_SESSION[$LEMsessid]['maxstep'] = $_SESSION[$LEMsessid]['step']; } // If the survey uses answer persistence and a srid is registered in SESSION @@ -600,7 +601,7 @@ function run($surveyid,$args) { /* Only survey mode used this - should all? if ($thissurvey['tokenanswerspersistence'] == 'Y' && $thissurvey['anonymized'] == "N" && - isset($_SESSION['srid']) && + isset($_SESSION[$LEMsessid]['srid']) && $thissurvey['active'] == "Y") { loadanswers(); @@ -611,7 +612,7 @@ function run($surveyid,$args) { //PRESENT SURVEY //****************************************************************************************************** - $okToShowErrors = (!$previewgrp && (isset($invalidLastPage) || $_SESSION['survey_'.$surveyid]['prevstep'] == $_SESSION['survey_'.$surveyid]['step'])); + $okToShowErrors = (!$previewgrp && (isset($invalidLastPage) || $_SESSION[$LEMsessid]['prevstep'] == $_SESSION[$LEMsessid]['step'])); Yii::app()->getController()->loadHelper('qanda'); setNoAnswerMode($thissurvey); @@ -619,7 +620,7 @@ function run($surveyid,$args) { //Iterate through the questions about to be displayed: $inputnames = array(); - foreach ($_SESSION['survey_'.$surveyid]['grouplist'] as $gl) + foreach ($_SESSION[$LEMsessid]['grouplist'] as $gl) { $gid = $gl[0]; $qnumber = 0; @@ -634,7 +635,7 @@ function run($surveyid,$args) { } // TMSW - could iterate through LEM::currentQset instead - foreach ($_SESSION['survey_'.$surveyid]['fieldarray'] as $key => $ia) + foreach ($_SESSION[$LEMsessid]['fieldarray'] as $key => $ia) { ++$qnumber; $ia[9] = $qnumber; // incremental question count; @@ -694,16 +695,16 @@ function run($surveyid,$args) { { if ($show_empty_group) { - $percentcomplete = makegraph($_SESSION['survey_'.$surveyid]['totalsteps'] + 1, $_SESSION['survey_'.$surveyid]['totalsteps']); + $percentcomplete = makegraph($_SESSION[$LEMsessid]['totalsteps'] + 1, $_SESSION[$LEMsessid]['totalsteps']); } else { - $percentcomplete = makegraph($_SESSION['survey_'.$surveyid]['step'], $_SESSION['survey_'.$surveyid]['totalsteps']); + $percentcomplete = makegraph($_SESSION[$LEMsessid]['step'], $_SESSION[$LEMsessid]['totalsteps']); } } if (!(isset($languagechanger) && strlen($languagechanger) > 0) && function_exists('makeLanguageChangerSurvey')) { - $languagechanger = makeLanguageChangerSurvey($_SESSION['survey_'.$surveyid]['s_lang']); + $languagechanger = makeLanguageChangerSurvey($_SESSION[$LEMsessid]['s_lang']); } //READ TEMPLATES, INSERT DATA AND PRESENT PAGE @@ -728,14 +729,14 @@ function run($surveyid,$args) { echo templatereplace(file_get_contents("$thistpl/startpage.pstpl"), array(), $redata); //ALTER PAGE CLASS TO PROVIDE WHOLE-PAGE ALTERNATION - if ($surveyMode != 'survey' && $_SESSION['survey_'.$surveyid]['step'] != $_SESSION['survey_'.$surveyid]['prevstep'] || - (isset($_SESSION['survey_'.$surveyid]['stepno']) && $_SESSION['survey_'.$surveyid]['stepno'] % 2)) + if ($surveyMode != 'survey' && $_SESSION[$LEMsessid]['step'] != $_SESSION[$LEMsessid]['prevstep'] || + (isset($_SESSION[$LEMsessid]['stepno']) && $_SESSION[$LEMsessid]['stepno'] % 2)) { - if (!isset($_SESSION['survey_'.$surveyid]['stepno'])) - $_SESSION['survey_'.$surveyid]['stepno'] = 0; - if ($_SESSION['survey_'.$surveyid]['step'] != $_SESSION['survey_'.$surveyid]['prevstep']) - ++$_SESSION['survey_'.$surveyid]['stepno']; - if ($_SESSION['survey_'.$surveyid]['stepno'] % 2) + if (!isset($_SESSION[$LEMsessid]['stepno'])) + $_SESSION[$LEMsessid]['stepno'] = 0; + if ($_SESSION[$LEMsessid]['step'] != $_SESSION[$LEMsessid]['prevstep']) + ++$_SESSION[$LEMsessid]['stepno']; + if ($_SESSION[$LEMsessid]['stepno'] % 2) { echo "