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 .= "