0){echo str_repeat(' ',2).'$submitQuestion is true'."
\n";}
$questionName=trim(stripslashes($_POST['questionName']));
$questionDescription=trim(stripslashes($_POST['questionDescription']));
$_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']);
$hotspotErr = false;
// no name given
if(!$modifyQuestion && (empty($questionName) || ($answerType == HOT_SPOT && ($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg')) || ($answerType == HOT_SPOT && empty($_FILES['imageUpload']['name']))))
{
if(($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg') && !$modifyQuestion)
{
$msgErr = get_lang('langOnlyJPG');
$hotspotErr = true;
}
if(empty($_FILES['imageUpload']['name']) && !$modifyQuestion)
{
$msgErr=get_lang('NoImage');
$hotspotErr = true;
}
if(empty($questionName))
{
$msgErr=get_lang('GiveQuestion');
}
}
// checks if the question is used in several exercises
elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1)
{
if($debug>0){echo str_repeat(' ',4).'$exerciseId is set and $modifyIn is unset and this question is in more than one exercise'."
\n";}
$usedInSeveralExercises=1;
// if a picture has been set
if($_FILES['imageUpload']['size'])
{
// saves the picture into a temporary file
$objQuestion->setTmpPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']);
}
}
else
{
if($debug>0){echo str_repeat(' ',4).'You have chosen to modify/add a question locally'."
\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($modifyQuestion);
$nbrQuestions--;
// construction of the duplicated Question
$objQuestion=new Question();
$objQuestion->read($questionId);
// adds the exercise ID into the exercise list of the Question object
$objQuestion->addToList($exerciseId);
// construction of the Answer object
$objAnswerTmp=new Answer($modifyQuestion);
// copies answers from $modifyQuestion to $questionId
$objAnswerTmp->duplicate($questionId);
// destruction of the Answer object
unset($objAnswerTmp);
}
$objQuestion->updateTitle($questionName);
$objQuestion->updateDescription($questionDescription);
$objQuestion->updateType($_REQUEST['answerType']);
$objQuestion->save($exerciseId);
// if a picture has been set or checkbox "delete" has been checked
if($_FILES['imageUpload']['size'] || $deletePicture)
{
// we remove the picture
$objQuestion->removePicture();
// if we add a new picture
if($_FILES['imageUpload']['size'])
{
// image is already saved in a temporary file
if($modifyIn)
{
$objQuestion->getTmpPicture();
}
// saves the picture coming from POST FILE
else
{
$objQuestion->uploadPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']);
if(!$objQuestion->resizePicture("any", 350))
{
$msgErr = get_lang('langHotspotBadMetadata');
$hotspotErr = true;
$objQuestion->removePicture();
}
}
}
if($hotspotErr === false)
{
$objQuestion->save($exerciseId);
}
else
{
if($newQuestion)
$objQuestion->removeFromList($exerciseId);
}
}
if($hotspotErr === false)
{
$questionId=$objQuestion->selectId();
if($exerciseId)
{
// adds the question ID into the question list of the Exercise object
if($objExercise->addToList($questionId))
{
$objExercise->save();
$nbrQuestions++;
}
}
if($newQuestion)
{
// goes to answer administration
// -> answer_admin.inc.php
$modifyAnswers=$questionId;
}
else
{
// goes to exercise viewing
$editQuestion=$questionId;
}
// avoids displaying the following form in case we're editing the answer
unset($newQuestion,$modifyQuestion);
}
}
if($debug>0){echo str_repeat(' ',2).'$submitQuestion is true - end'."
\n";}
}
else
{
if($debug>0){echo str_repeat(' ',2).'$submitQuestion was unset'."
\n";}
// if we don't come here after having cancelled the warning message "used in serveral exercises"
if(!$buttonBack)
{
if($debug>0){echo str_repeat(' ',4).'$buttonBack was unset'."
\n";}
$questionName=$objQuestion->selectTitle();
$questionDescription=$objQuestion->selectDescription();
$answerType= isset($_REQUEST['answerType']) ? $_REQUEST['answerType'] : $objQuestion->selectType();
$pictureName=$objQuestion->selectPicture();
}
$okPicture=empty($pictureName)?false:true;
if($debug>0){echo str_repeat(' ',2).'$submitQuestion was unset - end'."
\n";}
}
if(($newQuestion || $modifyQuestion) && !$usedInSeveralExercises)
{
if($debug>0){echo str_repeat(' ',2).'$newQuestion or modifyQuestion was set but the question only exists in this exercise'."
\n";}
?>