Minor - fixing PHP warnings.

1.9.x
Julio Montoya 11 years ago
parent d555a949a4
commit 2c7e7ff431
  1. 54
      main/exercice/admin.php
  2. 127
      main/exercice/fill_blanks.class.php
  3. 24
      main/exercice/question_admin.inc.php

@ -87,36 +87,40 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') {
} }
} }
// get vars from GET if (empty($exerciseId)) {
if ( empty ( $exerciseId ) ) { $exerciseId = isset($_GET['exerciseId']) ? intval($_GET['exerciseId']):'0';
$exerciseId = intval($_GET['exerciseId']);
} }
if ( empty ( $newQuestion ) ) {
$newQuestion = $_GET['newQuestion']; if (empty($newQuestion)) {
} $newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0;
if ( empty ( $modifyAnswers ) ) {
$modifyAnswers = $_GET['modifyAnswers'];
} }
if ( empty ( $editQuestion ) ) { if (empty($modifyAnswers)) {
$editQuestion = $_GET['editQuestion']; $modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
} }
if ( empty ( $modifyQuestion ) ) { if (empty($editQuestion)) {
$modifyQuestion = $_GET['modifyQuestion']; $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0;
} }
if ( empty ( $deleteQuestion ) ) { if (empty($modifyQuestion)) {
$deleteQuestion = $_GET['deleteQuestion']; $modifyQuestion = isset($_GET['modifyQuestion']) ? $_GET['modifyQuestion'] : 0;
} }
if ( empty ($clone_question) ) { if (empty($deleteQuestion)) {
$clone_question = $_GET['clone_question']; $deleteQuestion = isset($_GET['deleteQuestion']) ? $_GET['deleteQuestion'] : 0;
} }
if ( empty ( $questionId ) ) { $clone_question = isset($_REQUEST['clone_question']) ? $_REQUEST['clone_question'] : 0;
$questionId = $_SESSION['questionId']; if (empty($questionId)) {
$questionId = isset($_SESSION['questionId']) ? $_SESSION['questionId'] : 0;
} }
if ( empty ( $modifyExercise ) ) { if (empty($modifyExercise)) {
$modifyExercise = $_GET['modifyExercise']; $modifyExercise = isset($_GET['modifyExercise']) ? $_GET['modifyExercise'] : null;
} }
//Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc $fromExercise = isset($fromExercise) ? $fromExercise : null;
$cancelExercise = isset($cancelExercise) ? $cancelExercise : null;
$cancelAnswers = isset($cancelAnswers) ? $cancelAnswers : null;
$modifyIn = isset($modifyIn) ? $modifyIn : null;
$cancelQuestion = isset($cancelQuestion) ? $cancelQuestion : null;
// Cleaning all incomplete attempts of the admin/teacher to avoid weird problems when changing the exercise settings, number of questions, etc
delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_id(), api_get_session_id()); delete_all_incomplete_attempts(api_get_user_id(), $exerciseId, api_get_course_id(), api_get_session_id());
@ -139,7 +143,7 @@ $aType = array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('Fil
// tables used in the exercise tool // tables used in the exercise tool
if ($_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) { if (!empty($_GET['action']) && $_GET['action'] == 'exportqti2' && !empty($_GET['questionId'])) {
require_once 'export/qti2/qti2_export.php'; require_once 'export/qti2/qti2_export.php';
$export = export_question($_GET['questionId'],true); $export = export_question($_GET['questionId'],true);
$qid = (int)$_GET['questionId']; $qid = (int)$_GET['questionId'];
@ -176,9 +180,9 @@ if (!is_object($objExercise)) {
} }
// doesn't select the exercise ID if we come from the question pool // doesn't select the exercise ID if we come from the question pool
if(!$fromExercise) { if (!$fromExercise) {
// gets the right exercise ID, and if 0 creates a new exercise // gets the right exercise ID, and if 0 creates a new exercise
if(!$exerciseId = $objExercise->selectId()) { if (!$exerciseId = $objExercise->selectId()) {
$modifyExercise='yes'; $modifyExercise='yes';
} }
} }
@ -234,7 +238,7 @@ if ($cancelQuestion) {
} }
} }
if (isset($clone_question) && !empty($objExercise->id)) { if (!empty($clone_question) && !empty($objExercise->id)) {
$old_question_obj = Question::read($clone_question); $old_question_obj = Question::read($clone_question);
$old_question_obj->question = $old_question_obj->question.' - '.get_lang('Copy'); $old_question_obj->question = $old_question_obj->question.' - '.get_lang('Copy');

@ -12,73 +12,82 @@
*/ */
/** /**
CLASS FillBlanks
* *
* This class allows to instantiate an object of type MULTIPLE_ANSWER (MULTIPLE CHOICE, MULTIPLE ANSWER), * This class allows to instantiate an object of type MULTIPLE_ANSWER
* (MULTIPLE CHOICE, MULTIPLE ANSWER),
* extending the class question * extending the class question
* *
* @author Eric Marguin * @author Eric Marguin
* @author Julio Montoya multiple fill in blank option added * @author Julio Montoya multiple fill in blank option added
* @package chamilo.exercise * @package chamilo.exercise
**/ **/
class FillBlanks extends Question class FillBlanks extends Question
{ {
static $typePicture = 'fill_in_blanks.gif'; static $typePicture = 'fill_in_blanks.gif';
static $explanationLangVar = 'FillBlanks'; static $explanationLangVar = 'FillBlanks';
/** /**
* Constructor * Constructor
*/ */
function FillBlanks() public function FillBlanks()
{ {
parent::question(); parent::question();
$this -> type = FILL_IN_BLANKS; $this -> type = FILL_IN_BLANKS;
$this -> isContent = $this-> getIsContent(); $this -> isContent = $this-> getIsContent();
} }
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
*/
function createAnswersForm($form)
{
$defaults = array();
/** if (!empty($this->id)) {
* function which redifines Question::createAnswersForm $objAnswer = new answer($this->id);
* @param the formvalidator instance
*/
function createAnswersForm ($form) {
$defaults = array();
if (!empty($this->id)) { // the question is encoded like this
$objAnswer = new answer($this->id); // [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a switchable fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
// the question is encoded like this $pre_array = explode('::', $objAnswer->selectAnswer(1));
// [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a switchable fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
$pre_array = explode('::', $objAnswer->selectAnswer(1)); //make sure we only take the last bit to find special marks
$sz = count($pre_array);
$is_set_switchable = explode('@', $pre_array[$sz-1]);
//make sure we only take the last bit to find special marks if ($is_set_switchable[1]) {
$sz = count($pre_array); $defaults['multiple_answer'] = 1;
$is_set_switchable = explode('@', $pre_array[$sz-1]); } else {
$defaults['multiple_answer'] = 0;
}
if ($is_set_switchable[1]) { //Take the complete string except after the last '::'
$defaults['multiple_answer'] = 1;
} else {
$defaults['multiple_answer'] = 0;
}
//Take the complete string except after the last '::' $defaults['answer'] = '';
for ($i=0; $i<($sz-1); $i++) {
$defaults['answer'] .= $pre_array[$i];
}
$a_weightings = explode(',', $is_set_switchable[0]);
} else {
$defaults['answer'] = get_lang('DefaultTextInBlanks');
}
$defaults['answer'] = ''; $setValues = null;
for ($i=0;$i<($sz-1);$i++) {
$defaults['answer'] .= $pre_array[$i]; if (isset($a_weightings) && count($a_weightings) > 0) {
} foreach ($a_weightings as $i => $weighting) {
$a_weightings = explode(',', $is_set_switchable[0]); $setValues .= 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
} else { }
$defaults['answer'] = get_lang('DefaultTextInBlanks'); }
}
// javascript // javascript
echo '<script> echo '<script>
function FCKeditor_OnComplete( editorInstance ) {
function FCKeditor_OnComplete(editorInstance) {
if (window.attachEvent) { if (window.attachEvent) {
editorInstance.EditorDocument.attachEvent("onkeyup", updateBlanks) ; editorInstance.EditorDocument.attachEvent("onkeyup", updateBlanks) ;
} else { } else {
@ -113,35 +122,30 @@ class FillBlanks extends Question
document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>"; document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>";
if (firstTime) { if (firstTime) {
firstTime = false; firstTime = false;
'; '.$setValues.'
}
if (count($a_weightings) > 0) {
foreach($a_weightings as $i => $weighting) {
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
}
}
echo '}
} }
window.onload = updateBlanks; window.onload = updateBlanks;
</script>'; </script>';
// answer // answer
$form -> addElement ('label', null, '<br /><br />'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank')); $form->addElement('label', null, '<br /><br />'.get_lang('TypeTextBelow').', '.get_lang('And').' '.get_lang('UseTagForBlank'));
$form -> addElement ('html_editor', 'answer', '<img src="../img/fill_field.png">','id="answer" cols="122" rows="6" onkeyup="javascript: updateBlanks(this);"', array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '350')); $form->addElement('html_editor', 'answer', '<img src="../img/fill_field.png">','id="answer" cols="122" rows="6" onkeyup="javascript: updateBlanks(this);"', array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '350'));
$form -> addRule ('answer',get_lang('GiveText'),'required'); $form->addRule('answer', get_lang('GiveText'),'required');
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/'); $form->addRule('answer', get_lang('DefineBlanks'),'regex','/\[.*\]/');
//added multiple answers //added multiple answers
$form -> addElement ('checkbox','multiple_answer','', get_lang('FillInBlankSwitchable')); $form->addElement('checkbox', 'multiple_answer','', get_lang('FillInBlankSwitchable'));
$form -> addElement('html','<div id="blanks_weighting"></div>'); $form->addElement('html', '<div id="blanks_weighting"></div>');
global $text, $class; global $text, $class;
// setting the save button here and not in the question class.php // setting the save button here and not in the question class.php
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"'); $form->addElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"');
if (!empty($this -> id)) { if (!empty($this->id)) {
$form -> setDefaults($defaults); $form -> setDefaults($defaults);
} else { } else {
if ($this->isContent == 1) { if ($this->isContent == 1) {
@ -150,10 +154,9 @@ class FillBlanks extends Question
} }
} }
/** /**
* abstract function which creates the form to create / edit the answers of the question * abstract function which creates the form to create / edit the answers of the question
* @param the formvalidator instance * @param FormValidator $form
*/ */
function processAnswersCreation($form) function processAnswersCreation($form)
{ {

@ -23,7 +23,7 @@ if (isset($_GET['editQuestion'])) {
if (is_object($objQuestion)) { if (is_object($objQuestion)) {
//FORM CREATION //FORM CREATION
$form = new FormValidator('question_admin_form','post', $action); $form = new FormValidator('question_admin_form','post', $action);
if (isset($_GET['editQuestion'])) { if (isset($_GET['editQuestion'])) {
$class="btn save"; $class="btn save";
$text=get_lang('ModifyQuestion'); $text=get_lang('ModifyQuestion');
@ -39,32 +39,32 @@ if (is_object($objQuestion)) {
// form title // form title
$form->addElement('header', $text.': '.$form_title_extra); $form->addElement('header', $text.': '.$form_title_extra);
// question form elements // question form elements
$objQuestion->createForm($form); $objQuestion->createForm($form);
// answer form elements // answer form elements
$objQuestion->createAnswersForm($form); $objQuestion->createAnswersForm($form);
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
if ($objExercise->edit_exercise_in_lp == false) { if ($objExercise->edit_exercise_in_lp == false) {
$form->freeze(); $form->freeze();
} }
// FORM VALIDATION // FORM VALIDATION
if (isset($_POST['submitQuestion']) && $form->validate()) { if (isset($_POST['submitQuestion']) && $form->validate()) {
// question // question
$objQuestion->processCreation($form, $objExercise); $objQuestion->processCreation($form, $objExercise);
// answers // answers
$objQuestion->processAnswersCreation($form, $nb_answers); $objQuestion->processAnswersCreation($form, $nb_answers);
// TODO: maybe here is the better place to index this tool, including answers text // TODO: maybe here is the better place to index this tool, including answers text
// redirect // redirect
if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) { if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
if(isset($_GET['editQuestion'])) { if(isset($_GET['editQuestion'])) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>'; echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
} else { } else {
@ -74,9 +74,11 @@ if (is_object($objQuestion)) {
} else { } else {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>'; echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
} }
} else { } else {
echo '<h3>'.$questionName.'</h3>'; if (isset($questionName)) {
if(!empty($pictureName)){ echo '<h3>'.$questionName.'</h3>';
}
if (!empty($pictureName)) {
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">'; echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
} }
if(!empty($msgErr)) { if(!empty($msgErr)) {

Loading…
Cancel
Save