From 87287da2e7a641bff348de85be6b6a91c888bf17 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 8 May 2008 22:28:28 +0200 Subject: [PATCH] [svn r15251] Improved isolation of tests. Now allows reloading a test if GET['exerciseId'] is different from the Id of the exercise in the session. Allows for linking exercises in another exercise's answer comments. See FS#2520 --- main/exercice/exercice_submit.php | 277 ++++++++++++++++-------------- 1 file changed, 144 insertions(+), 133 deletions(-) diff --git a/main/exercice/exercice_submit.php b/main/exercice/exercice_submit.php index f9db05f565..d076b44217 100644 --- a/main/exercice/exercice_submit.php +++ b/main/exercice/exercice_submit.php @@ -33,7 +33,7 @@ * the administrator * @package dokeos.exercise * @author Olivier Brouckaert -* @version $Id: exercice_submit.php 14930 2008-04-16 21:41:35Z juliomontoya $ +* @version $Id: exercice_submit.php 15251 2008-05-08 20:28:28Z yannoo $ */ @@ -100,7 +100,7 @@ if ( empty ( $exerciseType ) ) { $exerciseType = $_REQUEST['exerciseType']; } if ( empty ( $exerciseId ) ) { - $exerciseId = $_REQUEST['exerciseId']; + $exerciseId = intval($_REQUEST['exerciseId']); } if ( empty ( $choice ) ) { $choice = $_REQUEST['choice']; @@ -114,6 +114,7 @@ if ( empty ( $nbrQuestions ) ) { if ( empty ($buttonCancel) ) { $buttonCancel = $_REQUEST['buttonCancel']; } +$error = ''; // if the user has clicked on the "Cancel" button if($buttonCancel) @@ -199,24 +200,26 @@ if($formSent) } // if the object is not in the session -if(!isset($_SESSION['objExercise']) || $origin == 'learnpath') +if(!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) { if($debug>0){echo str_repeat(' ',0).'$_SESSION[objExercise] was unset'."
\n";} // construction of Exercise $objExercise=new Exercise(); - - #$sql="SELECT title,description,sound,type,random,active FROM `$TBL_EXERCICES` WHERE id='$exerciseId'"; + unset($_SESSION['questionList']); // if the specified exercise doesn't exist or is disabled if(!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath') )) { - die(get_lang('ExerciseNotFound')); + unset($objExercise); + $error = get_lang('ExerciseNotFound'); + //die(get_lang('ExerciseNotFound')); + } + else + { + // saves the object into the session + api_session_register('objExercise'); + if($debug>0){echo str_repeat(' ',0).'$_SESSION[objExercise] was unset - set now - end'."
\n";} } - - // saves the object into the session - api_session_register('objExercise'); - if($debug>0){echo str_repeat(' ',0).'$_SESSION[objExercise] was unset - set now - end'."
\n";} - } if(!isset($objExcercise) && isset($_SESSION['objExercise'])){ @@ -410,7 +413,7 @@ else "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - + @@ -423,30 +426,46 @@ else echo "

".$exerciseTitle."

"; -if(!empty($exerciseSound)) +if(!empty($error)) { - echo "", - ",get_lang('Sound')."; + Display::display_error_message($error,false); } - - -// Get number of hotspot questions for javascript validation -$number_of_hotspot_questions = 0; -$onsubmit = ''; -$i=0; - -foreach($questionList as $questionId) +else { - $i++; - $objQuestionTmp = Question :: read($questionId); - // for sequential exercises - if($exerciseType == 2) + if(!empty($exerciseSound)) { - // if it is not the right question, goes to the next loop iteration - if($questionNum != $i) + echo "", + ",get_lang('Sound')."; + } + + + // Get number of hotspot questions for javascript validation + $number_of_hotspot_questions = 0; + $onsubmit = ''; + $i=0; + + foreach($questionList as $questionId) + { + $i++; + $objQuestionTmp = Question :: read($questionId); + + // for sequential exercises + if($exerciseType == 2) { - continue; + // if it is not the right question, goes to the next loop iteration + if($questionNum != $i) + { + continue; + } + else + { + if ($objQuestionTmp->selectType() == HOT_SPOT) + { + $number_of_hotspot_questions++; + } + break; + } } else { @@ -454,119 +473,111 @@ foreach($questionList as $questionId) { $number_of_hotspot_questions++; } - break; } } - else + + if($number_of_hotspot_questions > 0) { - if ($objQuestionTmp->selectType() == HOT_SPOT) - { - $number_of_hotspot_questions++; - } + $onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."');\""; } -} - -if($number_of_hotspot_questions > 0) -{ - $onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."');\""; -} -$s="

$exerciseDescription

"; - -if($origin == 'learnpath' && $exerciseType==2){ - $s2 = "&exerciseId=".$exerciseId; -} -$s.="
- - - - - - - - - -
- "; -echo $s; - -$i=0; - -foreach($questionList as $questionId) -{ - $i++; - - // for sequential exercises - if($exerciseType == 2) + $s="

$exerciseDescription

"; + + if($origin == 'learnpath' && $exerciseType==2){ + $s2 = "&exerciseId=".$exerciseId; + } + $s.=" + + + + + + + +
+ + + + +
+ "; + echo $s; + + $i=0; + + foreach($questionList as $questionId) { - // if it is not the right question, goes to the next loop iteration - if($questionNum != $i) - { - continue; - } - else + $i++; + + // for sequential exercises + if($exerciseType == 2) { - // if the user has already answered this question - if(isset($exerciseResult[$questionId])) + // if it is not the right question, goes to the next loop iteration + if($questionNum != $i) { - // construction of the Question object - $objQuestionTmp = Question::read($questionId); - - $questionName=$objQuestionTmp->selectTitle(); - - // destruction of the Question object - unset($objQuestionTmp); - - echo ''; - - break; + continue; + } + else + { + // if the user has already answered this question + if(isset($exerciseResult[$questionId])) + { + // construction of the Question object + $objQuestionTmp = Question::read($questionId); + + $questionName=$objQuestionTmp->selectTitle(); + + // destruction of the Question object + unset($objQuestionTmp); + + echo ''; + + break; + } } } - } - - $s=" - - '; - + + $s=" + + '; + + echo $s; + + // shows the question and its answers + showQuestion($questionId, false, $origin); + + // for sequential exercises + if($exerciseType == 2) + { + // quits the loop + break; + } + } // end foreach() + + $s="
'.get_lang('AlreadyAnswered').' "'.$questionName.'"
'.get_lang('AlreadyAnswered').' "'.$questionName.'"
- ".get_lang('Question')." "; - $s.=$i; - if($exerciseType == 2) $s.=' / '.$nbrQuestions; - $s.='
+ ".get_lang('Question')." "; + $s.=$i; + if($exerciseType == 2) $s.=' / '.$nbrQuestions; + $s.='
+

+ + '; + $s.="
"; + + $b=2; echo $s; - - // shows the question and its answers - showQuestion($questionId, false, $origin); - - // for sequential exercises - if($exerciseType == 2) - { - // quits the loop - break; - } -} // end foreach() - -$s="
- - - -
- - '; - $s.=""; - -$b=2; -echo $s; +} if ($origin != 'learnpath') { //so we are not in learnpath tool Display::display_footer();