diff --git a/admin/preview.php b/admin/preview.php index f4d503ca85b..1c7d7279f12 100644 --- a/admin/preview.php +++ b/admin/preview.php @@ -62,9 +62,9 @@ 7 => 'N', 8 => 'N' ); // ia[8] is usedinconditions -LimeExpressionManager::StartSurvey($thissurvey['sid'], 'question', ($thissurvey['anonymized']!="N"), false); +LimeExpressionManager::StartSurvey($thissurvey['sid'], 'question', ($thissurvey['anonymized']!="N"), false,$LEMdebugLevel); $qseq = LimeExpressionManager::GetQuestionSeq($qid); -$moveResult = LimeExpressionManager::JumpTo($qseq+1,false,($LEMdebugLevel>=2),true); +$moveResult = LimeExpressionManager::JumpTo($qseq+1,false,true); $answers = retrieveAnswers($ia); @@ -129,9 +129,8 @@ function noop_checkconditions(value, name, type) $content .= templatereplace(file_get_contents("$thistpl/endgroup.pstpl")).$dummy_js; $content .= '

 '; -$content .= templatereplace(file_get_contents("$thistpl/endpage.pstpl")); -LimeExpressionManager::FinishProcessingPage($LEMdebugLevel); +LimeExpressionManager::FinishProcessingPage(); echo $content; @@ -141,6 +140,9 @@ function noop_checkconditions(value, name, type) if ($LEMdebugLevel >= 2) { echo "
Group/Question Validation Results:".$moveResult['message']."
\n"; } + +$content .= templatereplace(file_get_contents("$thistpl/endpage.pstpl")); + echo "\n"; diff --git a/classes/eval/LimeExpressionManager.php b/classes/eval/LimeExpressionManager.php index 7a301c9a8b7..5cc712d9824 100644 --- a/classes/eval/LimeExpressionManager.php +++ b/classes/eval/LimeExpressionManager.php @@ -14,7 +14,12 @@ class LimeExpressionManager { private $groupRelevanceInfo; private $sid; private $groupNum; - private $debugLEM = false; // set this to false to turn off debugging + private $debugLevel=0; + // 0=none + // 1=timings only + // 2=#1 + summary results of validating questions and groups + // 3=#1 + pretty-printed results of validating questions and groups + // 4=#3 + LimeExpressionManager internal debugging (fine grained) private $knownVars; private $pageRelevanceInfo; private $pageTailorInfo; @@ -1419,7 +1424,7 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force . "','relevance':'" . htmlspecialchars(preg_replace('/[[:space:]]/',' ',$relevance),ENT_QUOTES) . "'".$ansList."}"; - if ($this->debugLEM) + if ($this->debugLevel>=4) { $this->debugLog[] = array( 'code' => $code, @@ -1464,7 +1469,7 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force 'relevanceNum'=>'', ); - if ($this->debugLEM) + if ($this->debugLevel>=4) { $this->debugLog[] = array( 'code' => $key, @@ -1501,7 +1506,7 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force } $this->runtimeTimings[] = array(__METHOD__ . ' - process fieldMap',(microtime(true) - $now)); - if ($this->debugLEM) + if ($this->debugLevel>=4) { $debugLog_html = ""; $debugLog_html .= ""; @@ -1677,7 +1682,7 @@ static function ProcessString($string, $questionNum=NULL, $replacementFields=arr $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); } - if ($LEM->debugLEM) + if ($LEM->debugLevel>=4) { $varsUsed = $LEM->em->GetJSVarsUsed(); if (is_array($varsUsed) and count($varsUsed) > 0) { @@ -1855,9 +1860,8 @@ static function GetLastPrettyPrintExpression() * Should be first function called on each page - sets/clears internally needed variables * @param $navigationIndex - true if should compute the navigation index (list of questions or groups to display) * @param $allOnOnePage - true if StartProcessingGroup will be called multiple times on this page - does some optimizatinos - * @param $debug - whether to generate debug logs */ - static function StartProcessingPage($navigationIndex=false,$allOnOnePage=false,$debug=true) + static function StartProcessingPage($navigationIndex=false,$allOnOnePage=false) { // $now = microtime(true); $LEM =& LimeExpressionManager::singleton(); @@ -1872,7 +1876,7 @@ static function StartProcessingPage($navigationIndex=false,$allOnOnePage=false,$ // $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); - if ($debug && $LEM->debugLEM) + if ($LEM->debugLevel>=4) { $LEM->pageTailoringLog .= ''; } @@ -1887,11 +1891,12 @@ static function StartProcessingPage($navigationIndex=false,$allOnOnePage=false,$ * @param $forceRefresh */ - static function StartSurvey($surveyid,$surveyMode='group',$anonymized=false,$forceRefresh=false) + static function StartSurvey($surveyid,$surveyMode='group',$anonymized=false,$forceRefresh=false,$debugLevel=0) { $LEM =& LimeExpressionManager::singleton(); $LEM->sid=$surveyid; // TMSW - santize this? $LEM->anonymized=$anonymized; + $LEM->debugLevel=$debugLevel; switch ($surveyMode) { case 'survey': $LEM->allOnOnePage=true; @@ -1924,10 +1929,11 @@ static function StartSurvey($surveyid,$surveyMode='group',$anonymized=false,$for ); } - static function NavigateBackwards($debug=false) + static function NavigateBackwards() { $now = microtime(true); $LEM =& LimeExpressionManager::singleton(); + $debug = ($LEM->debugLevel>=2); $LEM->RelevanceResultCache=array(); // to avoid running same test more than once for a given group @@ -1957,7 +1963,7 @@ static function NavigateBackwards($debug=false) */ $LEM->currentQset = array(); // reset active list of questions - $result = $LEM->_ValidateSurvey($debug); + $result = $LEM->_ValidateSurvey(); if (!$result['relevant'] || $result['hidden']) { // then there are no relevant, visible questions in the survey @@ -1992,7 +1998,7 @@ static function NavigateBackwards($debug=false) ); } - $result = $LEM->_ValidateGroup($LEM->currentGroupSeq, $debug); + $result = $LEM->_ValidateGroup($LEM->currentGroupSeq); $message .= $result['message']; if (!$result['relevant'] || $result['hidden']) { @@ -2048,7 +2054,7 @@ static function NavigateBackwards($debug=false) $LEM->ProcessAllNeededRelevance($LEM->currentQuestionSeq); $LEM->_CreateSubQLevelRelevanceAndValidationEqns($LEM->currentQuestionSeq); - $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq, $debug); + $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq); $message .= $result['message']; if (!$result['relevant'] || $result['hidden']) @@ -2081,11 +2087,11 @@ static function NavigateBackwards($debug=false) /** * * @param $force - if true, continue to go forward even if there are violations to the mandatory and/or validity rules - * @param $debug - if true, show more detailed debug messages */ - static function NavigateForwards($force=false,$debug=false) { + static function NavigateForwards($force=false) { $now = microtime(true); $LEM =& LimeExpressionManager::singleton(); + $debug = ($LEM->debugLevel>=2); $LEM->RelevanceResultCache=array(); // to avoid running same test more than once for a given group @@ -2115,7 +2121,7 @@ static function NavigateForwards($force=false,$debug=false) { */ $LEM->currentQset = array(); // reset active list of questions - $result = $LEM->_ValidateSurvey($debug); + $result = $LEM->_ValidateSurvey(); if (!$result['relevant'] || $result['hidden']) { // then there are no relevant, visible questions in the survey @@ -2135,18 +2141,20 @@ static function NavigateForwards($force=false,$debug=false) { $LEM->StartProcessingPage(); $LEM->ProcessCurrentResponses(); $updatedValues=array(); + $message = ''; if (!$force && $LEM->currentGroupSeq != -1) { - $result = $LEM->_ValidateGroup($LEM->currentGroupSeq,$debug); + $result = $LEM->_ValidateGroup($LEM->currentGroupSeq); + $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if (!is_null($result) && ($result['mandViolation'] || !$result['valid'])) { // redisplay the current group - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, - 'message'=>$result['message'], + 'message'=>$message, 'gseq'=>$LEM->currentGroupSeq, 'seq'=>$LEM->currentGroupSeq, 'mandViolation'=>$result['mandViolation'], @@ -2156,13 +2164,12 @@ static function NavigateForwards($force=false,$debug=false) { ); } } - $message = ''; while (true) { $LEM->currentQset = array(); // reset active list of questions if (++$LEM->currentGroupSeq >= $LEM->numGroups) { - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>true, @@ -2176,7 +2183,7 @@ static function NavigateForwards($force=false,$debug=false) { ); } - $result = $LEM->_ValidateGroup($LEM->currentGroupSeq, $debug); + $result = $LEM->_ValidateGroup($LEM->currentGroupSeq); $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if (!$result['relevant'] || $result['hidden']) @@ -2187,7 +2194,7 @@ static function NavigateForwards($force=false,$debug=false) { else { // display new group - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, @@ -2206,18 +2213,20 @@ static function NavigateForwards($force=false,$debug=false) { $LEM->StartProcessingPage(); $LEM->ProcessCurrentResponses(); $updatedValues=array(); + $message = ''; if (!$force && $LEM->currentQuestionSeq != -1) { - $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq,$debug); + $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq); + $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if (!is_null($result) && ($result['mandViolation'] || !$result['valid'])) { // redisplay the current question - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, - 'message'=>$result['message'], + 'message'=>$message, 'qseq'=>$LEM->currentQuestionSeq, 'gseq'=>$LEM->currentGroupSeq, 'seq'=>$LEM->currentQuestionSeq, @@ -2228,13 +2237,12 @@ static function NavigateForwards($force=false,$debug=false) { ); } } - $message = ''; while (true) { $LEM->currentQset = array(); // reset active list of questions if (++$LEM->currentQuestionSeq >= $LEM->numQuestions) { - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>true, @@ -2261,7 +2269,7 @@ static function NavigateForwards($force=false,$debug=false) { $LEM->ProcessAllNeededRelevance($LEM->currentQuestionSeq); $LEM->_CreateSubQLevelRelevanceAndValidationEqns($LEM->currentQuestionSeq); - $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq, $debug); + $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq); $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); @@ -2273,7 +2281,7 @@ static function NavigateForwards($force=false,$debug=false) { else { // display new question - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, @@ -2317,27 +2325,29 @@ function UpdateValuesInDatabase($updatedValues) $query .= implode(', ', $setter); $query .= " WHERE ID="; -// echo $query; - if (isset($_SESSION['srid'])) { $query .= $_SESSION['srid']; db_execute_assoc($query); } + if ($this->debugLevel >= 2) { + return $query; + } } + return ''; } /** * Jump to a specific question or group sequence. * @param $seq * @param $force - if true, then skip validation of current group (e.g. will jump even if there are errors) - * @param $debug - if true, generate detailed debug information * @param $preview - if true, then treat this group/question as relevant, even if it is not, so that it can be displayed * @return */ - static function JumpTo($seq,$force=false,$debug=false,$preview=false) { + static function JumpTo($seq,$force=false,$preview=false) { $now = microtime(true); $LEM =& LimeExpressionManager::singleton(); + $debug = ($LEM->debugLevel>=2); $LEM->RelevanceResultCache=array(); // to avoid running same test more than once for a given group --$seq; // convert to 0-based numbering @@ -2352,18 +2362,20 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { $LEM->StartProcessingPage(); $LEM->ProcessCurrentResponses(); $updatedValues=array(); + $message = ''; if (!$force && $LEM->currentGroupSeq != -1 && $seq > $LEM->currentGroupSeq) // only re-validate if jumping forward { - $result = $LEM->_ValidateGroup($LEM->currentGroupSeq,$debug); + $result = $LEM->_ValidateGroup($LEM->currentGroupSeq); + $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if (!is_null($result) && ($result['mandViolation'] || !$result['valid'])) { // redisplay the current group - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, - 'message'=>$result['message'], + 'message'=>$message, 'gseq'=>$LEM->currentGroupSeq, 'seq'=>$LEM->currentGroupSeq, 'mandViolation'=>$result['mandViolation'], @@ -2373,14 +2385,13 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { ); } } - $message = ''; $LEM->currentGroupSeq = $seq-1; // Try to jump to the requested group, but navigate to next if needed while (true) { $LEM->currentQset = array(); // reset active list of questions if (++$LEM->currentGroupSeq >= $LEM->numGroups) { - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>true, @@ -2394,7 +2405,7 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { ); } - $result = $LEM->_ValidateGroup($LEM->currentGroupSeq, $debug); + $result = $LEM->_ValidateGroup($LEM->currentGroupSeq); $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if (!$preview && (!$result['relevant'] || $result['hidden'])) @@ -2405,7 +2416,7 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { else { // display new group - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, @@ -2424,18 +2435,20 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { $LEM->StartProcessingPage(); $LEM->ProcessCurrentResponses(); $updatedValues=array(); + $message = ''; if (!$force && $LEM->currentQuestionSeq != -1 && $seq > $LEM->currentQuestionSeq) { - $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq,$debug); + $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq); + $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); if ($result['mandViolation'] || !$result['valid']) { // redisplay the current question - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, - 'message'=>$result['message'], + 'message'=>$message, 'qseq'=>$LEM->currentQuestionSeq, 'gseq'=>$LEM->currentGroupSeq, 'seq'=>$LEM->currentQuestionSeq, @@ -2446,14 +2459,13 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { ); } } - $message = ''; $LEM->currentQuestionSeq=$seq-1; // try to jump to requeted question, but go on to next if needed while (true) { $LEM->currentQset = array(); // reset active list of questions if (++$LEM->currentQuestionSeq >= $LEM->numQuestions) { - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>true, @@ -2480,7 +2492,7 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { $LEM->ProcessAllNeededRelevance($LEM->currentQuestionSeq); $LEM->_CreateSubQLevelRelevanceAndValidationEqns($LEM->currentQuestionSeq); - $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq, $debug); + $result = $LEM->_ValidateQuestion($LEM->currentQuestionSeq); $message .= $result['message']; $updatedValues = array_merge($updatedValues,$result['updatedValues']); @@ -2492,7 +2504,7 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { else { // display new question - $LEM->UpdateValuesInDatabase($updatedValues); + $message .= $LEM->UpdateValuesInDatabase($updatedValues); $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); return array( 'finished'=>false, @@ -2511,7 +2523,7 @@ static function JumpTo($seq,$force=false,$debug=false,$preview=false) { } } - function _ValidateSurvey($debug=false) + function _ValidateSurvey() { $LEM =& $this; @@ -2523,7 +2535,7 @@ function _ValidateSurvey($debug=false) for ($i=0;$i<$LEM->numGroups;++$i) { $LEM->currentGroupSeq=$i; - $gStatus = $LEM->_ValidateGroup($i,$debug); + $gStatus = $LEM->_ValidateGroup($i); $message .= $gStatus['message']; if ($gStatus['relevant']) { @@ -2554,12 +2566,12 @@ function _ValidateSurvey($debug=false) /** * * @param $groupSeq - the index-0 sequence number for this group - * @param $debug - if true, generate detailed debug messages. * @return - detailed information about this group */ - function _ValidateGroup($groupSeq, $debug=false) + function _ValidateGroup($groupSeq) { $LEM =& $this; + $debug = ($LEM->debugLevel>=2); if ($groupSeq < 0 || $groupSeq >= $LEM->numGroups) { return NULL; // TODO - what is desired behavior? @@ -2582,7 +2594,7 @@ function _ValidateGroup($groupSeq, $debug=false) for ($i=$groupSeqInfo['qstart'];$i<=$groupSeqInfo['qend']; ++$i) { - $qStatus = $LEM->_ValidateQuestion($i, $debug); + $qStatus = $LEM->_ValidateQuestion($i); $updatedValues = array_merge($updatedValues,$qStatus['updatedValues']); @@ -2612,7 +2624,7 @@ function _ValidateGroup($groupSeq, $debug=false) // Done processing all questions/sub-questions in the potentially relevant group // Now check whether the group as a whole is relevant, valid, and/or hidden - if ($debug) // always want to see this + if ($LEM->debugLevel>=2) // always want to see this { $debug_message .= '
[G#' . $LEM->currentGroupSeq . ']' . '[' . $groupSeqInfo['qstart'] . '-' . $groupSeqInfo['qend'] . ']' @@ -2632,7 +2644,7 @@ function _ValidateGroup($groupSeq, $debug=false) { // At least one question is invalid, so re-show this group // Validation logic needs to happen before trying to move to the next group - if ($debug) + if ($LEM->debugLevel>=2) { $debug_message .= "**At least one relevant question was invalid, so re-show this group
\n"; $debug_message .= "**Validity Violators: " . implode(', ', explode('|',$invalidSQList)) . "
\n"; @@ -2642,7 +2654,7 @@ function _ValidateGroup($groupSeq, $debug=false) { // At least one releavant question was mandatory but not answered // Mandatory logic needs to happen before trying to move to the next group - if ($debug) + if ($LEM->debugLevel>=2) { $debug_message .= "**At least one relevant question was mandatory but unanswered, so re-show this group
\n"; $debug_message .= '**Mandatory Violators: ' . implode(', ', explode('|',$unansweredSQList)). "
\n"; @@ -2652,7 +2664,7 @@ function _ValidateGroup($groupSeq, $debug=false) if ($ghidden == true) { // This group has at least one relevant question, but they are all hidden. - if ($debug) + if ($LEM->debugLevel>=2) { $debug_message .= '** Page is relevant but hidden, so NULL irrelevant values and save relevant Equation results:
'; } @@ -2661,7 +2673,7 @@ function _ValidateGroup($groupSeq, $debug=false) else { // This group contains no relevant questions - if ($debug) + if ($LEM->debugLevel>=2) { $debug_message .= '** Page is irrelevant, so NULL all questions in this group
'; } @@ -2707,11 +2719,10 @@ function _ValidateGroup($groupSeq, $debug=false) * (d) answered - if $_SESSION[sgqa]=='' or NULL, then it is not answered * (e) validity - whether relevant questions pass their validity tests * @param $questionSeq - the 0-index sequence number for this question - * @param $debug - if true, generate detailed debug messages * @return of information about this question and its sub-questions */ - function _ValidateQuestion($questionSeq, $debug=false) + function _ValidateQuestion($questionSeq) { $LEM =& $this; $qInfo = $LEM->questionSeq2relevance[$questionSeq]; // this array is by group and question sequence @@ -2736,7 +2747,7 @@ function _ValidateQuestion($questionSeq, $debug=false) if (isset($LEM->RelevanceResultCache[$relevanceEqn])) { $qrel = $LEM->RelevanceResultCache[$relevanceEqn]['result']; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintRelEqn = $LEM->RelevanceResultCache[$relevanceEqn]['prettyPrint']; } @@ -2748,7 +2759,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $qrel=false; // default to invalid so that can show the error } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintRelEqn = $LEM->em->GetPrettyPrintString(); } @@ -2810,7 +2821,7 @@ function _ValidateQuestion($questionSeq, $debug=false) if (isset($LEM->RelevanceResultCache[$sq['eqn']])) { $sqrel = $LEM->RelevanceResultCache[$sq['eqn']]['result']; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqns[] = $LEM->RelevanceResultCache[$sq['eqn']]['prettyPrint']; } @@ -2823,7 +2834,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $sqrel=false; // default to invalid so that can show the error } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqn = $LEM->em->GetPrettyPrintString(); $prettyPrintSQRelEqns[] = $prettyPrintSQRelEqn; @@ -2851,7 +2862,7 @@ function _ValidateQuestion($questionSeq, $debug=false) if (isset($LEM->RelevanceResultCache[$sq['eqn']])) { $sqrel = $LEM->RelevanceResultCache[$sq['eqn']]['result']; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqns[] = $LEM->RelevanceResultCache[$sq['eqn']]['prettyPrint']; } @@ -2864,7 +2875,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $sqrel=false; // default to invalid so that can show the error } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqn = $LEM->em->GetPrettyPrintString(); $prettyPrintSQRelEqns[] = $prettyPrintSQRelEqn; @@ -2897,7 +2908,7 @@ function _ValidateQuestion($questionSeq, $debug=false) if (isset($LEM->RelevanceResultCache[$sq['eqn']])) { $sqrel = $LEM->RelevanceResultCache[$sq['eqn']]['result']; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqns[] = $LEM->RelevanceResultCache[$sq['eqn']]['prettyPrint']; } @@ -2910,7 +2921,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $sqrel=false; // default to invalid so that can show the error } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqn = $LEM->em->GetPrettyPrintString(); $prettyPrintSQRelEqns[] = $prettyPrintSQRelEqn; @@ -2931,13 +2942,13 @@ function _ValidateQuestion($questionSeq, $debug=false) } break; case 'L': //LIST drop-down/radio-button list - if ($sgqa == $sq['sgqa'] || $sgqa == ($sq['sgqa'] . 'other')) + if ($sgqa == ($sq['sgqa'] . 'other') && $sgqa == $sq['rowdivid']) // don't do sub-q level validition to main question, just to other option { $foundSQrelevance=true; if (isset($LEM->RelevanceResultCache[$sq['eqn']])) { $sqrel = $LEM->RelevanceResultCache[$sq['eqn']]['result']; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqns[] = $LEM->RelevanceResultCache[$sq['eqn']]['prettyPrint']; } @@ -2950,7 +2961,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $sqrel=false; // default to invalid so that can show the error } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqn = $LEM->em->GetPrettyPrintString(); $prettyPrintSQRelEqns[] = $prettyPrintSQRelEqn; @@ -2983,7 +2994,7 @@ function _ValidateQuestion($questionSeq, $debug=false) } // end foreach($sgqa) [assessing each sub-question] } // end of processing relevant question - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintSQRelEqns = array_unique($prettyPrintSQRelEqns); } @@ -3100,7 +3111,7 @@ function _ValidateQuestion($questionSeq, $debug=false) { $validationJS = $LEM->em->GetJavaScriptEquivalentOfExpression(); } - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintValidEqn = $LEM->em->GetPrettyPrintString(); } @@ -3108,13 +3119,13 @@ function _ValidateQuestion($questionSeq, $debug=false) $stringToParse = implode('
',$LEM->qid2validationEqn[$qid]['tips']); // pretty-print them $validTip = $LEM->ProcessString($stringToParse, $qid,NULL,false,1,1,false,false); - if ($debug) { + if ($LEM->debugLevel>=3) { $prettyPrintValidTip = $LEM->GetLastPrettyPrintExpression(); } } else { - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintValidEqn = 'Question is Irrelevant, so no need to further validate it'; } @@ -3126,7 +3137,7 @@ function _ValidateQuestion($questionSeq, $debug=false) $invalidSQs = $LEM->qid2code[$qid]; // TODO - currently invalidates all - should only invalidate those that truly fail validation rules. } - if ($debug) + if ($LEM->debugLevel>=2) { $debug_qmessage .= '--[Q#' . $qInfo['questionSeq'] . ']' . "[" @@ -3139,67 +3150,70 @@ function _ValidateQuestion($questionSeq, $debug=false) . $prettyPrintRelEqn . "
\n"; - if ($mandatoryTip != '') - { - $debug_qmessage .= '----Mandatory Tip: ' . $mandatoryTip . "
\n"; - } - - if ($prettyPrintValidTip != '') - { - $debug_qmessage .= '----Pretty Validation Tip: ' . $prettyPrintValidTip . "
\n"; - } - if ($validTip != '') - { - $debug_qmessage .= '----Validation Tip: ' . $validTip . "
\n"; - } - - if ($prettyPrintValidEqn != '') - { - $debug_qmessage .= '----Validation Eqn: ' . $prettyPrintValidEqn . "
\n"; - } - if ($validationJS != '') + if ($LEM->debugLevel>=3) { - $debug_qmessage .= '----Validation JavaScript: ' . $validationJS . "
\n"; - } + if ($mandatoryTip != '') + { + $debug_qmessage .= '----Mandatory Tip: ' . $mandatoryTip . "
\n"; + } - // what are the database question codes for this question? - $subQList = '{' . implode('}, {', explode('|',$LEM->qid2code[$qid])) . '}'; - // pretty-print them - $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); - $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); - $debug_qmessage .= '----SubQs=> ' . $prettyPrintSubQList . "
\n"; + if ($prettyPrintValidTip != '') + { + $debug_qmessage .= '----Pretty Validation Tip: ' . $prettyPrintValidTip . "
\n"; + } + if ($validTip != '') + { + $debug_qmessage .= '----Validation Tip: ' . $validTip . "
\n"; + } - if (count($prettyPrintSQRelEqns) > 0) - { - $debug_qmessage .= "----Array Filters Applied:
\n" . implode('
',$prettyPrintSQRelEqns) . "
\n"; - } + if ($prettyPrintValidEqn != '') + { + $debug_qmessage .= '----Validation Eqn: ' . $prettyPrintValidEqn . "
\n"; + } + if ($validationJS != '') + { + $debug_qmessage .= '----Validation JavaScript: ' . $validationJS . "
\n"; + } - if (count($relevantSQs) > 0) - { - $subQList = '{' . implode('}, {', $relevantSQs) . '}'; + // what are the database question codes for this question? + $subQList = '{' . implode('}, {', explode('|',$LEM->qid2code[$qid])) . '}'; // pretty-print them $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); - $debug_qmessage .= '----Relevant SubQs: ' . $prettyPrintSubQList . "
\n"; - } + $debug_qmessage .= '----SubQs=> ' . $prettyPrintSubQList . "
\n"; - if (count($irrelevantSQs) > 0) - { - $subQList = '{' . implode('}, {', $irrelevantSQs) . '}'; - // pretty-print them - $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); - $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); - $debug_qmessage .= '----Irrelevant SubQs: ' . $prettyPrintSubQList . "
\n"; - } + if (count($prettyPrintSQRelEqns) > 0) + { + $debug_qmessage .= "----Array Filters Applied:
\n" . implode('
',$prettyPrintSQRelEqns) . "
\n"; + } - // show which relevant subQs were not answered - if (count($unansweredSQs) > 0) - { - $subQList = '{' . implode('}, {', $unansweredSQs) . '}'; - // pretty-print them - $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); - $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); - $debug_qmessage .= '----Unanswered Relevant SubQs: ' . $prettyPrintSubQList . "
\n"; + if (count($relevantSQs) > 0) + { + $subQList = '{' . implode('}, {', $relevantSQs) . '}'; + // pretty-print them + $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); + $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); + $debug_qmessage .= '----Relevant SubQs: ' . $prettyPrintSubQList . "
\n"; + } + + if (count($irrelevantSQs) > 0) + { + $subQList = '{' . implode('}, {', $irrelevantSQs) . '}'; + // pretty-print them + $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); + $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); + $debug_qmessage .= '----Irrelevant SubQs: ' . $prettyPrintSubQList . "
\n"; + } + + // show which relevant subQs were not answered + if (count($unansweredSQs) > 0) + { + $subQList = '{' . implode('}, {', $unansweredSQs) . '}'; + // pretty-print them + $LEM->ProcessString($subQList, $qid,NULL,false,1,1,false,false); + $prettyPrintSubQList = $LEM->GetLastPrettyPrintExpression(); + $debug_qmessage .= '----Unanswered Relevant SubQs: ' . $prettyPrintSubQList . "
\n"; + } } } @@ -3222,7 +3236,7 @@ function _ValidateQuestion($questionSeq, $debug=false) // Store the result of the Equation in the SESSION $_SESSION[$sgqa] = $result; $updatedValues[$sgqa] = $result; - if ($debug) + if ($LEM->debugLevel>=3) { $prettyPrintEqn = $LEM->em->GetPrettyPrintString(); $debug_qmessage .= '** Process Hidden but Relevant Equation [' . $sgqa . '](' . $prettyPrintEqn . ') => ' . $result . "
\n"; @@ -3431,14 +3445,14 @@ static function GetDebugTimingMessage() /** * Should be called at end of each page */ - static function FinishProcessingPage($debugLevel=0) + static function FinishProcessingPage() { $LEM =& LimeExpressionManager::singleton(); $_SESSION['EM_pageTailoringLog'] = $LEM->pageTailoringLog; $_SESSION['EM_surveyLogicFile'] = $LEM->surveyLogicFile; $totalTime = 0.; - if ($debugLevel >= 1 && count($LEM->runtimeTimings)>0) { + if ($LEM->debugLevel >= 1 && count($LEM->runtimeTimings)>0) { $LEM->debugTimingMsg=''; foreach($LEM->runtimeTimings as $unit) { $totalTime += $unit[1]; @@ -3482,7 +3496,7 @@ static function FinishProcessingPage($debugLevel=0) } /** - * Show the HTML for the logic file if $debugLEM was true + * Show the HTML for the logic file if $debugLevel>=3 * @return */ static function ShowLogicFile() @@ -3494,7 +3508,7 @@ static function ShowLogicFile() } /** - * Show the HTML of the tailorings on this page if $debugLEM was true + * Show the HTML of the tailorings on this page if $debugLevel>=3 * @return */ static function ShowPageTailorings() @@ -4031,7 +4045,7 @@ static function UnitTestRelevance() $LEM =& LimeExpressionManager::singleton(); - LimeExpressionManager::StartProcessingPage(false,true,true); + LimeExpressionManager::StartProcessingPage(false,true); LimeExpressionManager::StartProcessingGroup(1); // pretending this is group 1 // collect variables diff --git a/classes/eval/test/navigation_test.php b/classes/eval/test/navigation_test.php index a099a48edf3..554743a9c57 100644 --- a/classes/eval/test/navigation_test.php +++ b/classes/eval/test/navigation_test.php @@ -23,11 +23,13 @@ // 24811, ); + $LEMdebugLevel = 3; + foreach ($surveys as $surveyid) { print '

Starting survey ' . $surveyid . "

"; $now = microtime(true); - LimeExpressionManager::StartSurvey($surveyid, 'group', false, true); + LimeExpressionManager::StartSurvey($surveyid, 'group', false, true,$LEMdebugLevel); print '[StartSurvey() took ' . (microtime(true) - $now) . ' seconds]
'; while(true) { diff --git a/group1.php b/group1.php index 2b7732f400f..5c84e595a6d 100644 --- a/group1.php +++ b/group1.php @@ -42,7 +42,7 @@ if (!isset($_SESSION['step'])) // || !$_SESSION['step']) - don't do this for step0, else rebuild the session { $totalquestions = buildsurveysession(); - LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, ($thissurvey['anonymized']!="N"), true); + LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, ($thissurvey['anonymized']!="N"), true,$LEMdebugLevel); $_SESSION['step'] = 0; if(isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') { //If explicitply set, hide the welcome screen @@ -57,7 +57,7 @@ //Move current step ########################################################################### if (isset($move) && $move == 'moveprev' && ($thissurvey['allowprev']=='Y' || $thissurvey['allowjumps']=='Y')) { - $moveResult = LimeExpressionManager::NavigateBackwards(($LEMdebugLevel>=2)); + $moveResult = LimeExpressionManager::NavigateBackwards(); if ($moveResult['at_start']) { $_SESSION['step']=0; unset($moveResult); // so display welcome page again @@ -65,13 +65,13 @@ } if (isset($move) && $move == "movenext") { - $moveResult = LimeExpressionManager::NavigateForwards(false,($LEMdebugLevel>=2)); + $moveResult = LimeExpressionManager::NavigateForwards(false); } 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,($LEMdebugLevel>=2)); + $moveResult = LimeExpressionManager::JumpTo($move,false); } } @@ -80,9 +80,6 @@ $move = 'movesubmit'; } $_SESSION['step']= $moveResult['seq']+1; // step is index base 1 - if ($LEMdebugLevel>=2) { - $LEMmsg = $moveResult['message']; - } $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); } @@ -338,17 +335,14 @@ { setcookie("limesurvey_timers", "0"); - LimeExpressionManager::StartSurvey($thissurvey['sid'], 'group', ($thissurvey['anonymized']!="N"), false); + LimeExpressionManager::StartSurvey($thissurvey['sid'], 'group', ($thissurvey['anonymized']!="N"), false,$LEMdebugLevel); $gseq = LimeExpressionManager::GetGroupSeq($_REQUEST['gid']); if ($gseq == -1) { echo 'Invalid Group' . $_REQUEST['gid']; } - $moveResult = LimeExpressionManager::JumpTo($gseq+1,false,($LEMdebugLevel>=2),true); + $moveResult = LimeExpressionManager::JumpTo($gseq+1,false,true); if (isset($moveResult)) { $_SESSION['step']= $moveResult['seq']+1; // step is index base 1? - if ($LEMdebugLevel>=2) { - $LEMmsg = $moveResult['message']; - } } $stepInfo = LimeExpressionManager::GetStepIndexInfo($moveResult['seq']); @@ -642,7 +636,7 @@ function checkconditions(value, name, type) LimeExpressionManager::FinishProcessingGroup(); echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); -LimeExpressionManager::FinishProcessingPage($LEMdebugLevel); +LimeExpressionManager::FinishProcessingPage(); if (!$previewgrp){ $navigator = surveymover(); //This gets globalised in the templatereplace function @@ -719,7 +713,7 @@ function checkconditions(value, name, type) echo LimeExpressionManager::GetDebugTimingMessage(); } if ($LEMdebugLevel >= 2) { - echo "
CodeTypeVarNameCodeValDisplayValJSnameWritable?Set On This Page?RelevanceHiddenQuestion
SourcePretty PrintResult
Group/Question Validation Results:".$LEMmsg."
\n"; + echo "
Group/Question Validation Results:".$moveResult['message']."
\n"; } echo "\n"; diff --git a/index.php b/index.php index d420d76d44b..c7bfb9fa12b 100644 --- a/index.php +++ b/index.php @@ -895,7 +895,7 @@ switch ($thissurvey['format']) { case "A": //All in one - require_once("survey.php"); + require_once("survey1.php"); break; case "S": //One at a time require_once("group1.php"); // question.php"); diff --git a/printanswers.php b/printanswers.php index ff02e1b7799..4719c5bd65b 100644 --- a/printanswers.php +++ b/printanswers.php @@ -174,7 +174,7 @@ } $printoutput .= "\t

".$clang->gT("Survey name (ID):")." $surveyname ($surveyid)

 \n"; -LimeExpressionManager::StartProcessingPage(false,true,true); // means that all variables are on the same page +LimeExpressionManager::StartProcessingPage(false,true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group 1 LimeExpressionManager::StartProcessingGroup(1,($thissurvey['anonymized']!="N"),$surveyid); diff --git a/survey.php b/survey.php index 1764b7060ca..aa48e76faa4 100644 --- a/survey.php +++ b/survey.php @@ -250,7 +250,7 @@ $inputnames=array(); $groupUnconditionnalQuestionsCount=array(); -LimeExpressionManager::StartProcessingPage(false,true,true); // means that all variables are on the same page +LimeExpressionManager::StartProcessingPage(false,true); // means that all variables are on the same page foreach ($_SESSION['grouplist'] as $gl) { diff --git a/survey1.php b/survey1.php index 212fd491157..1db043ca52a 100644 --- a/survey1.php +++ b/survey1.php @@ -22,6 +22,8 @@ if (!isset($_SESSION['totalsteps'])) {$_SESSION['totalsteps']=0;} if (isset($move) && $move == "moveprev") {$_SESSION['step'] = $thisstep-1;} if (isset($move) && $move == "movenext") {$_SESSION['step'] = $thisstep+1;} +$_SESSION['maxstep']=1; +$_SESSION['prevstep']=$_SESSION['step']; // 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 @@ -240,7 +242,7 @@ //****************************************************************************************************** //GET GROUP DETAILS -require_once("qanda.php"); +require_once("qanda1.php"); // TMSW Mandatory -> EM //$mandatorys=array(); //$mandatoryfns=array(); @@ -250,7 +252,7 @@ $inputnames=array(); $groupUnconditionnalQuestionsCount=array(); -LimeExpressionManager::StartProcessingPage(false,true,true); // means that all variables are on the same page +LimeExpressionManager::StartProcessingPage(false,true); // means that all variables are on the same page foreach ($_SESSION['grouplist'] as $gl) {