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 ) ) {
$exerciseId = intval($_GET['exerciseId']);
if (empty($exerciseId)) {
$exerciseId = isset($_GET['exerciseId']) ? intval($_GET['exerciseId']):'0';
}
if ( empty ( $newQuestion ) ) {
$newQuestion = $_GET['newQuestion'];
}
if ( empty ( $modifyAnswers ) ) {
$modifyAnswers = $_GET['modifyAnswers'];
if (empty($newQuestion)) {
$newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0;
}
if ( empty ( $editQuestion ) ) {
$editQuestion = $_GET['editQuestion'];
if (empty($modifyAnswers)) {
$modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
}
if ( empty ( $modifyQuestion ) ) {
$modifyQuestion = $_GET['modifyQuestion'];
if (empty($editQuestion)) {
$editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0;
}
if ( empty ( $deleteQuestion ) ) {
$deleteQuestion = $_GET['deleteQuestion'];
if (empty($modifyQuestion)) {
$modifyQuestion = isset($_GET['modifyQuestion']) ? $_GET['modifyQuestion'] : 0;
}
if ( empty ($clone_question) ) {
$clone_question = $_GET['clone_question'];
if (empty($deleteQuestion)) {
$deleteQuestion = isset($_GET['deleteQuestion']) ? $_GET['deleteQuestion'] : 0;
}
if ( empty ( $questionId ) ) {
$questionId = $_SESSION['questionId'];
$clone_question = isset($_REQUEST['clone_question']) ? $_REQUEST['clone_question'] : 0;
if (empty($questionId)) {
$questionId = isset($_SESSION['questionId']) ? $_SESSION['questionId'] : 0;
}
if ( empty ( $modifyExercise ) ) {
$modifyExercise = $_GET['modifyExercise'];
if (empty($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());
@ -139,7 +143,7 @@ $aType = array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('Fil
// 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';
$export = export_question($_GET['questionId'],true);
$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
if(!$fromExercise) {
if (!$fromExercise) {
// gets the right exercise ID, and if 0 creates a new exercise
if(!$exerciseId = $objExercise->selectId()) {
if (!$exerciseId = $objExercise->selectId()) {
$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 = $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
*
* @author Eric Marguin
* @author Julio Montoya multiple fill in blank option added
* @package chamilo.exercise
**/
class FillBlanks extends Question
{
static $typePicture = 'fill_in_blanks.gif';
static $explanationLangVar = 'FillBlanks';
/**
* Constructor
*/
function FillBlanks()
{
parent::question();
$this -> type = FILL_IN_BLANKS;
$this -> isContent = $this-> getIsContent();
}
/**
* Constructor
*/
public function FillBlanks()
{
parent::question();
$this -> type = FILL_IN_BLANKS;
$this -> isContent = $this-> getIsContent();
}
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
*/
function createAnswersForm($form)
{
$defaults = array();
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
*/
function createAnswersForm ($form) {
$defaults = array();
if (!empty($this->id)) {
$objAnswer = new answer($this->id);
if (!empty($this->id)) {
$objAnswer = new answer($this->id);
// the question is encoded like this
// [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
// [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));
$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
$sz = count($pre_array);
$is_set_switchable = explode('@', $pre_array[$sz-1]);
if ($is_set_switchable[1]) {
$defaults['multiple_answer'] = 1;
} else {
$defaults['multiple_answer'] = 0;
}
if ($is_set_switchable[1]) {
$defaults['multiple_answer'] = 1;
} else {
$defaults['multiple_answer'] = 0;
}
//Take the complete string except after the last '::'
//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'] = '';
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');
}
$setValues = null;
if (isset($a_weightings) && count($a_weightings) > 0) {
foreach ($a_weightings as $i => $weighting) {
$setValues .= 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
}
}
// javascript
echo '<script>
function FCKeditor_OnComplete( editorInstance ) {
function FCKeditor_OnComplete(editorInstance) {
if (window.attachEvent) {
editorInstance.EditorDocument.attachEvent("onkeyup", updateBlanks) ;
} else {
@ -113,35 +122,30 @@ class FillBlanks extends Question
document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>";
if (firstTime) {
firstTime = false;
';
if (count($a_weightings) > 0) {
foreach($a_weightings as $i => $weighting) {
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
}
}
echo '}
'.$setValues.'
}
}
window.onload = updateBlanks;
</script>';
// answer
$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('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 -> addRule ('answer',get_lang('GiveText'),'required');
$form -> addRule ('answer',get_lang('DefineBlanks'),'regex','/\[.*\]/');
$form->addRule('answer', get_lang('GiveText'),'required');
$form->addRule('answer', get_lang('DefineBlanks'),'regex','/\[.*\]/');
//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;
// 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);
} else {
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
* @param the formvalidator instance
* @param FormValidator $form
*/
function processAnswersCreation($form)
{

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

Loading…
Cancel
Save