selectTitle();
$answerType=$objQuestion->selectType();
$pictureName=$objQuestion->selectPicture();
$debug = 0; // debug variable to get where we are
$okPicture=empty($pictureName)?false:true;
// if we come from the warning box "this question is used in serveral exercises"
if($modifyIn)
{
if($debug>0){echo '$modifyIn was set'."
\n";}
// if the user has chosed to modify the question only in the current exercise
if($modifyIn == 'thisExercise')
{
// duplicates the question
$questionId=$objQuestion->duplicate();
// deletes the old question
$objQuestion->delete($exerciseId);
// removes the old question ID from the question list of the Exercise object
$objExercise->removeFromList($modifyAnswers);
// adds the new question ID into the question list of the Exercise object
$objExercise->addToList($questionId);
// construction of the duplicated Question
$objQuestion = Question :: read($questionId);
// adds the exercise ID into the exercise list of the Question object
$objQuestion->addToList($exerciseId);
// copies answers from $modifyAnswers to $questionId
$objAnswer->duplicate($questionId);
// construction of the duplicated Answers
$objAnswer=new Answer($questionId);
}
$color=unserialize($color);
$reponse=unserialize($reponse);
$comment=unserialize($comment);
$weighting=unserialize($weighting);
$hotspot_coordinates=unserialize($hotspot_coordinates);
$hotspot_type=unserialize($hotspot_type);
unset($buttonBack);
}
// the answer form has been submitted
if($submitAnswers || $buttonBack)
{
if($debug>0){echo '$submitAnswers or $buttonBack was set'."
\n";}
$questionWeighting=$nbrGoodAnswers=0;
for($i=1;$i <= $nbrAnswers;$i++)
{
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."
\n";}
$reponse[$i]=trim($reponse[$i]);
$comment[$i]=trim($comment[$i]);
$weighting[$i]=$weighting[$i]; // it can be float
// checks if field is empty
if(empty($reponse[$i]) && $reponse[$i] != '0') {
$msgErr=get_lang('HotspotGiveAnswers');
// clears answers already recorded into the Answer object
$objAnswer->cancel();
break;
}
if($weighting[$i] <= 0) {
$msgErr=get_lang('HotspotWeightingError');
// clears answers already recorded into the Answer object
$objAnswer->cancel();
break;
}
if($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
$msgErr=get_lang('HotspotNotDrawn');
// clears answers already recorded into the Answer object
$objAnswer->cancel();
break;
}
} // end for()
if(empty($msgErr)) {
for($i=1;$i <= $nbrAnswers;$i++) {
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."
\n";}
$reponse[$i]=trim($reponse[$i]);
$comment[$i]=trim($comment[$i]);
$weighting[$i]=($weighting[$i]); //it can be float
if($weighting[$i]) {
$questionWeighting+=$weighting[$i];
}
// creates answer
$objAnswer->createAnswer($reponse[$i], '',$comment[$i],$weighting[$i],$i,$hotspot_coordinates[$i],$hotspot_type[$i]);
} // end for()
// saves the answers into the data base
$objAnswer->save();
// sets the total weighting of the question
$objQuestion->updateWeighting($questionWeighting);
$objQuestion->save($exerciseId);
$editQuestion=$questionId;
unset($modifyAnswers);
echo '';
}
if($debug>0){echo '$modifyIn was set - end'."
\n";}
}
if($modifyAnswers)
{
if($debug>0){echo str_repeat(' ',0).'$modifyAnswers is set'."
\n";}
// construction of the Answer object
$objAnswer=new Answer($objQuestion -> id);
api_session_register('objAnswer');
if($debug>0){echo str_repeat(' ',2).'$answerType is HOT_SPOT'."
\n";}
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
if(!$nbrAnswers)
{
$nbrAnswers=$objAnswer->selectNbrAnswers();
$reponse=Array();
$comment=Array();
$weighting=Array();
$hotspot_coordinates=Array();
$hotspot_type=array();
for($i=1;$i <= $nbrAnswers;$i++)
{
$reponse[$i]=$objAnswer->selectAnswer($i);
$comment[$i]=$objAnswer->selectComment($i);
$weighting[$i]=$objAnswer->selectWeighting($i);
$hotspot_coordinates[$i]=$objAnswer->selectHotspotCoordinates($i);
$hotspot_type[$i]=$objAnswer->selectHotspotType($i);
}
}
$_SESSION['tmp_answers'] = array();
$_SESSION['tmp_answers']['answer'] = $reponse;
$_SESSION['tmp_answers']['comment'] = $comment;
$_SESSION['tmp_answers']['weighting'] = $weighting;
$_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
$_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
if($lessAnswers)
{
// At least 1 answer
if ($nbrAnswers > 1) {
$nbrAnswers--;
// Remove the last answer
$tmp = array_pop($_SESSION['tmp_answers']['answer']);
$tmp = array_pop($_SESSION['tmp_answers']['comment']);
$tmp = array_pop($_SESSION['tmp_answers']['weighting']);
$tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
$tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
}
else
{
$msgErr=get_lang('MinHotspot');
}
}
if($moreAnswers)
{
if ($nbrAnswers < 12)
{
$nbrAnswers++;
// Add a new answer
$_SESSION['tmp_answers']['answer'][]='';
$_SESSION['tmp_answers']['comment'][]='';
$_SESSION['tmp_answers']['weighting'][]='1';
$_SESSION['tmp_answers']['hotspot_coordinates'][]='0;0|0|0';
$_SESSION['tmp_answers']['hotspot_type'][]='square';
}
else
{
$msgErr=get_lang('MaxHotspot');
}
}
if($debug>0){echo str_repeat(' ',2).'$usedInSeveralExercises is untrue'."
\n";}
if($debug>0){echo str_repeat(' ',4).'$answerType is HOT_SPOT'."
\n";}
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
"#4271B5",
"#FE8E16",
"#3B3B3B",
"#BCD631",
"#D63173",
"#D7D7D7",
"#90AFDD",
"#AF8640",
"#4F9242",
"#F4EB24",
"#ED2024",
"#45C7F0",
"#F7BDE2");
?>