From 95fe84d391d88fc7964f8e2c6d9a6ffdf5fccbbe Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 3 Dec 2011 06:13:27 +0000 Subject: [PATCH] Dev EM-based validation and navigation sub-system: Dev Survey (All-in-one) mode now 99% functional. Works perfectly with EM debug level = 3, but not for lesser debug levels git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev_tms@11569 b72ed6b6-b9f8-46b5-92b4-906544132732 --- classes/eval/ExpressionManager.php | 2 +- classes/eval/LimeExpressionManager.php | 103 +++++------- classes/eval/test/navigation_test.php | 2 +- group1.php | 219 +++++++++++++++++-------- index.php | 2 +- 5 files changed, 190 insertions(+), 138 deletions(-) diff --git a/classes/eval/ExpressionManager.php b/classes/eval/ExpressionManager.php index e355e781cc9..ddcbba1c180 100644 --- a/classes/eval/ExpressionManager.php +++ b/classes/eval/ExpressionManager.php @@ -1374,7 +1374,7 @@ public function GetPrettyPrintString() } $stringParts[] = "hyperlinkSyntaxHighlighting) { + if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid)) { // Modify this link to utilize a different framework $editlink = $this->rooturl . '/admin/admin.php?sid=' . $this->sid . '&gid=' . $gid . '&qid=' . $qid; $stringParts[] = " onclick='window.open(\"" . $editlink . "\");'"; diff --git a/classes/eval/LimeExpressionManager.php b/classes/eval/LimeExpressionManager.php index 7885155ab27..a58a8f54a25 100644 --- a/classes/eval/LimeExpressionManager.php +++ b/classes/eval/LimeExpressionManager.php @@ -1981,42 +1981,7 @@ static function NavigateBackwards() switch ($LEM->surveyMode) { case 'survey': - $LEM->StartProcessingPage(true); - /* What is right way to check validity after a submit? - if ($LEM->currentGroupSeq != -1) { - // then a repeated showing of survey - if (!$force) - { - $result = $LEM->_ValidateSurvey($debug); - if ($result['mandViolation'] || !$result['valid']) - { - // redisplay the current group - - } - } - // have submitted the survey - return array( - 'finished'=>true, - 'message'=>$result['message'], - ); - } - */ - - $LEM->currentQset = array(); // reset active list of questions - $result = $LEM->_ValidateSurvey(); - if (!$result['relevant'] || $result['hidden']) - { - // then there are no relevant, visible questions in the survey - } - else - { - // display the survey - $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); - return array( - 'finished'=>true, - 'message'=>$result['message'], - ); - } + // should never be called? break; case 'group': // First validate the current group @@ -2142,42 +2107,35 @@ static function NavigateForwards($force=false) { switch ($LEM->surveyMode) { case 'survey': + $startingGroup = $LEM->currentGroupSeq; $LEM->StartProcessingPage(true); - /* What is right way to check validity after a submit? - if ($LEM->currentGroupSeq != -1) { - // then a repeated showing of survey - if (!$force) - { - $result = $LEM->_ValidateSurvey($debug); - if ($result['mandViolation'] || !$result['valid']) - { - // redisplay the current group - - } - } - // have submitted the survey - return array( - 'finished'=>true, - 'message'=>$result['message'], - ); - } - */ + $updatedValues=$LEM->ProcessCurrentResponses(); + $message = ''; $LEM->currentQset = array(); // reset active list of questions $result = $LEM->_ValidateSurvey(); - if (!$result['relevant'] || $result['hidden']) + $message .= $result['message']; + $updatedValues = array_merge($updatedValues,$result['updatedValues']); + if (!$force && !is_null($result) && ($result['mandViolation'] || !$result['valid'] || $startingGroup == -1)) { - // then there are no relevant, visible questions in the survey + $finished=false; } else { - // display the survey - $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); - return array( - 'finished'=>true, - 'message'=>$result['message'], - ); + $finished = true; } + $message .= $LEM->_UpdateValuesInDatabase($updatedValues,$finished); + $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now)); + return array( + 'finished'=>$finished, + 'message'=>$message, + 'gseq'=>1, + 'seq'=>1, + 'mandViolation'=>$result['mandViolation'], + 'valid'=>$result['valid'], + 'unansweredSQs'=>$result['unansweredSQs'], + 'invalidSQs'=>$result['invalidSQs'], + ); break; case 'group': // First validate the current group @@ -2645,7 +2603,7 @@ static function JumpTo($seq,$force=false,$preview=false) { } } - function _ValidateSurvey() + private function _ValidateSurvey() { $LEM =& $this; @@ -2654,6 +2612,9 @@ function _ValidateSurvey() $shidden=true; $smandViolation=false; $svalid=true; + $unansweredSQs = array(); + $invalidSQs = array(); + $updatedValues = array(); for ($i=0;$i<$LEM->numGroups;++$i) { $LEM->currentGroupSeq=$i; @@ -2673,7 +2634,15 @@ function _ValidateSurvey() $svalid=false; } - // TODO - Note, this is needed to generate proper JavaScript - will this prevent tailoring of questions and answers since it closes the group? + if (strlen($gStatus['unansweredSQs']) > 0) { + $unansweredSQs = array_merge($unansweredSQs, explode('|',$gStatus['unansweredSQs'])); + } + if (strlen($gStatus['invalidSQs']) > 0) { + $invalidSQs = array_merge($invalidSQs, explode('|',$gStatus['invalidSQs'])); + } + $updatedValues = array_merge($updatedValues, $gStatus['updatedValues']); + $LEM->currentQset = array_merge($LEM->currentQset, $gStatus['qset']); + $LEM->FinishProcessingGroup(); } return array( @@ -2682,6 +2651,10 @@ function _ValidateSurvey() 'mandViolation' => $smandViolation, 'valid' => $svalid, 'message' => $message, + 'unansweredSQs' => implode('|',$unansweredSQs), + 'invalidSQs' => implode('|',$invalidSQs), + 'updatedValues' => $updatedValues, + 'seq'=>1, ); } diff --git a/classes/eval/test/navigation_test.php b/classes/eval/test/navigation_test.php index db3b72dd4a5..299a2cf4b60 100644 --- a/classes/eval/test/navigation_test.php +++ b/classes/eval/test/navigation_test.php @@ -39,7 +39,7 @@ { print '

Starting survey ' . $surveyid . "

"; $now = microtime(true); - LimeExpressionManager::StartSurvey($surveyid, 'group', $surveyOptions, true,$LEMdebugLevel); + LimeExpressionManager::StartSurvey($surveyid, 'survey', $surveyOptions, true,$LEMdebugLevel); print '[StartSurvey() took ' . (microtime(true) - $now) . ' seconds]
'; while(true) { diff --git a/group1.php b/group1.php index fd989e5ce3e..64ad2cd6b0d 100644 --- a/group1.php +++ b/group1.php @@ -18,8 +18,20 @@ // 1=timings only // 2=timings + pretty-printed results of validating questions and groups // 3=#1 + pretty-printed results of validating questions and groups -$LEMdebugLevel=0; -$surveyMode = (($thissurvey['format'] == 'G') ? 'group' : 'question'); +$LEMdebugLevel=3; +switch ($thissurvey['format']) +{ + case "A": //All in one + $surveyMode='survey'; + break; + default: + case "S": //One at a time + $surveyMode='question'; + break; + case "G": //Group at a time + $surveyMode='group'; + break; +} $surveyOptions = array( 'active'=>($thissurvey['active']=='Y'), 'allowsave'=>($thissurvey['allowsave']=='Y'), @@ -39,7 +51,7 @@ //Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB $previewgrp = false; -if (isset($_REQUEST['action']) && ($_REQUEST['action']=='previewgroup') && $thissurvey['format'] == 'G'){ +if ( $surveyMode=='group' && isset($_REQUEST['action']) && ($_REQUEST['action']=='previewgroup')){ $previewgrp = true; } if (isset($_REQUEST['newtest'])) @@ -61,7 +73,10 @@ $totalquestions = buildsurveysession(); LimeExpressionManager::StartSurvey($thissurvey['sid'], $surveyMode, $surveyOptions, true,$LEMdebugLevel); $_SESSION['step'] = 0; - if(isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') { + 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; } @@ -107,7 +122,7 @@ // Previously we used to keep the session and redirect the user to the // submit page. - if ($_SESSION['step'] == 0) { + if ($surveyMode != 'survey' && $_SESSION['step'] == 0) { display_first_page(); exit; } @@ -337,6 +352,12 @@ echo templatereplace(file_get_contents("$thistpl/completed.pstpl")); echo "\n
\n"; + if ($LEMdebugLevel >= 1) { + echo LimeExpressionManager::GetDebugTimingMessage(); + } + if ($LEMdebugLevel >= 2) { + echo "
Group/Question Validation Results:".$moveResult['message']."
\n"; + } echo templatereplace(file_get_contents("$thistpl/endpage.pstpl")); doFooter(); exit; @@ -359,7 +380,7 @@ //GET GROUP DETAILS -if ($previewgrp) +if ($surveyMode == 'group' && $previewgrp) { setcookie("limesurvey_timers", "0"); @@ -400,6 +421,18 @@ $_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 //****************************************************************************************************** @@ -412,62 +445,77 @@ //Iterate through the questions about to be displayed: $inputnames=array(); -$qnumber = 0; - -foreach ($_SESSION['fieldarray'] as $key=>$ia) +foreach ($_SESSION['grouplist'] as $gl) { - ++$qnumber; - $ia[9] = $qnumber; // incremental question count; + $gid = $gl[0]; + $qnumber = 0; - if ((isset($ia[10]) && $ia[10] == $gid) || (!isset($ia[10]) && $ia[5] == $gid)) + if ($surveyMode != 'survey') { - if ($surveyMode == 'question' && $ia[0] != $stepInfo['qid']) { - continue; - } - $qidattributes=getQuestionAttributes($ia[0],$ia[4]); - if ($ia[4] != '*' && ($qidattributes===false || $qidattributes['hidden']==1)) { + $onlyThisGID = $stepInfo['gid']; + if ($onlyThisGID != $gid) + { 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); - } + foreach ($_SESSION['fieldarray'] as $key => $ia) + { + ++$qnumber; + $ia[9] = $qnumber; // incremental question count; - //Display the "mandatory" popup if necessary - // TMSW - get question-level error messages - don't call **_popup() directly - if (!$previewgrp && $stepInfo['mandViolation'] && $_SESSION['prevstep'] == $_SESSION['step']) + if ((isset($ia[10]) && $ia[10] == $gid) || (!isset($ia[10]) && $ia[5] == $gid)) { - list($mandatorypopup, $popup)=mandatory_popup($ia, $notanswered); - } + if ($surveyMode == 'question' && $ia[0] != $stepInfo['qid']) + { + continue; + } + $qidattributes = getQuestionAttributes($ia[0], $ia[4]); + if ($ia[4] != '*' && ($qidattributes === false || $qidattributes['hidden'] == 1)) + { + continue; + } - //Display the "validation" popup if necessary - if (!$previewgrp && !$stepInfo['valid'] && $_SESSION['prevstep'] == $_SESSION['step']) - { - list($validationpopup, $vpopup)=validation_popup($ia, $notvalidated); - } + //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 "file validation" popup if necessary - if (!$previewgrp && isset($filenotvalidated) && $_SESSION['prevstep'] == $_SESSION['step']) - { - list($filevalidationpopup, $fpopup) = file_validation_popup($ia, $filenotvalidated); + //Display the "mandatory" popup if necessary + // TMSW - get question-level error messages - don't call **_popup() directly + if (!$previewgrp && $stepInfo['mandViolation'] && $_SESSION['prevstep'] == $_SESSION['step']) + { + list($mandatorypopup, $popup) = mandatory_popup($ia, $notanswered); + } + + //Display the "validation" popup if necessary + if (!$previewgrp && !$stepInfo['valid'] && $_SESSION['prevstep'] == $_SESSION['step']) + { + list($validationpopup, $vpopup) = validation_popup($ia, $notvalidated); + } + + // Display the "file validation" popup if necessary + if (!$previewgrp && isset($filenotvalidated) && $_SESSION['prevstep'] == $_SESSION['step']) + { + list($filevalidationpopup, $fpopup) = file_validation_popup($ia, $filenotvalidated); + } } - } - if ($ia[4] == "|") - $upload_file = TRUE; -} //end iteration + if ($ia[4] == "|") + $upload_file = TRUE; + } //end iteration +} -if (isset($thissurvey['showprogress']) && $thissurvey['showprogress'] == 'Y') +if ($surveyMode != 'survey' && isset($thissurvey['showprogress']) && $thissurvey['showprogress'] == 'Y') { if ($show_empty_group) { @@ -491,7 +539,7 @@ echo templatereplace(file_get_contents("$thistpl/startpage.pstpl")); //ALTER PAGE CLASS TO PROVIDE WHOLE-PAGE ALTERNATION -if ($_SESSION['step'] != $_SESSION['prevstep'] || +if ($surveyMode != 'survey' && $_SESSION['step'] != $_SESSION['prevstep'] || (isset($_SESSION['stepno']) && $_SESSION['stepno'] % 2)) { if (!isset($_SESSION['stepno'])) $_SESSION['stepno'] = 0; @@ -518,9 +566,24 @@ // <-- END FEATURE - SAVE -// <-- START THE SURVEY --> +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"))."\n"; + } -echo templatereplace(file_get_contents("{$thistpl}/survey.pstpl")); + if ($thissurvey['anonymized'] == "Y") + { + echo templatereplace(file_get_contents("$thistpl/privacy.pstpl"))."\n"; + } +} + +// <-- START THE SURVEY --> +if ($surveyMode != 'survey') { + echo templatereplace(file_get_contents("{$thistpl}/survey.pstpl")); +} // 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) @@ -561,16 +624,6 @@ function checkconditions(value, name, type) END; -echo "\n\n\n"; -echo templatereplace(file_get_contents("$thistpl/startgroup.pstpl")); -echo "\n"; - -if ($groupdescription) -{ - echo templatereplace(file_get_contents("$thistpl/groupdescription.pstpl")); -} -echo "\n"; - //Display the "mandatory" message on page if necessary if (isset($showpopups) && $showpopups == 0 && $stepInfo['mandViolation'] && $_SESSION['prevstep'] == $_SESSION['step']) { @@ -589,10 +642,35 @@ function checkconditions(value, name, type) echo "

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

"; } -echo "\n\n\n"; +foreach ($_SESSION['grouplist'] as $gl) { + $gid=$gl[0]; + $groupname=$gl[1]; + $groupdescription=$gl[2]; + + if ($surveyMode != 'survey' && $gid != $onlyThisGID) { + continue; + } + + echo "\n\n\n"; + echo "\n\n
\n"; + echo templatereplace(file_get_contents("$thistpl/startgroup.pstpl")); + echo "\n"; + + if ($groupdescription) + { + echo templatereplace(file_get_contents("$thistpl/groupdescription.pstpl")); + } + echo "\n"; + + echo "\n\n\n"; + 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]); @@ -654,13 +732,14 @@ function checkconditions(value, name, type) echo templatereplace($question_template,NULL,false,$qa[4]); }; } - echo "\n"; // for counting the time spent on each group - + 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")); + echo "\n\n
\n"; } -echo "\n\n\n"; -echo templatereplace(file_get_contents("$thistpl/endgroup.pstpl")); -echo "\n"; LimeExpressionManager::FinishProcessingGroup(); echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); @@ -679,7 +758,7 @@ function checkconditions(value, name, type) } - if($thissurvey['allowjumps']=='Y') + if($surveyMode != 'survey' && $thissurvey['allowjumps']=='Y') { echo "\n\n\n"; diff --git a/index.php b/index.php index 0d40462f97c..a0daf731a6e 100644 --- a/index.php +++ b/index.php @@ -895,7 +895,7 @@ switch ($thissurvey['format']) { case "A": //All in one - require_once("survey1.php"); + require_once("group1.php"); break; case "S": //One at a time require_once("group1.php"); // question.php");