Cleaning exercise classes in order to be loaded by a controller. This classes print echos when editing a question so it can't be managed by a controller.

skala
Julio Montoya 13 years ago
parent b0e315664c
commit 8010cd2e77
  1. 5
      main/css/base.css
  2. 2
      main/exercice/admin.php
  3. 4
      main/exercice/answer.class.php
  4. 39
      main/exercice/draggable.class.php
  5. 16
      main/exercice/exercise.class.php
  6. 167
      main/exercice/exercise_admin.php
  7. 2
      main/exercice/fill_blanks.class.php
  8. 4
      main/exercice/global_multiple_answer.class.php
  9. 2
      main/exercice/hotspot_savescore.inc.php
  10. 2
      main/exercice/matching.class.php
  11. 8
      main/exercice/multiple_answer.class.php
  12. 4
      main/exercice/multiple_answer_combination.class.php
  13. 6
      main/exercice/multiple_answer_true_false.class.php
  14. 83
      main/exercice/question.class.php
  15. 6
      main/exercice/question_admin.inc.php
  16. 16
      main/exercice/unique_answer.class.php
  17. 4
      main/exercice/unique_answer_image.class.php
  18. 4
      main/exercice/unique_answer_no_option.class.php
  19. 5
      main/inc/lib/database.lib.php

@ -5270,4 +5270,9 @@ i.size-32.icon-new-work {
.exercise_pagination { .exercise_pagination {
margin: 0px; margin: 0px;
}
#question_admin_form .media {
display:none;
} }

@ -204,7 +204,7 @@ if ($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) {
// reads question data // reads question data
if ($editQuestion) { if ($editQuestion) {
// question not found // question not found
if (!$objQuestion = Question::read($editQuestion)) { if (!$objQuestion = Question::read($editQuestion, null, $objExercise)) {
api_not_allowed(); api_not_allowed();
} }
// saves the object into the session // saves the object into the session

@ -120,7 +120,7 @@ class Answer
*/ */
$sql = "SELECT iid, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination $sql = "SELECT iid, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination
FROM $TBL_ANSWER FROM $TBL_ANSWER
WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position"; WHERE question_id ='".$questionId."' ORDER BY position";
$result = Database::query($sql); $result = Database::query($sql);
$counter = 1; $counter = 1;
@ -605,7 +605,7 @@ class Answer
} }
$question_info = Question::read($questionId); $question_info = Question::read($questionId);
if ($question_info->type == MATCHING) { if ($question_info->type == MATCHING) {
//Fixing real answer id //Fixing real answer id

@ -100,7 +100,6 @@ class Draggable extends Matching
// DISPLAY MATCHES // DISPLAY MATCHES
$html = '<table class="data_table"> $html = '<table class="data_table">
<tr> <tr>
<th width="40%"> <th width="40%">
'.get_lang('Answer').' '.get_lang('Answer').'
</th> </th>
@ -112,7 +111,7 @@ class Draggable extends Matching
</th> </th>
</tr>'; </tr>';
$form->addElement('label', get_lang('MakeCorrespond').'<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('MakeCorrespond').'<br /> '.Display::return_icon('fill_field.png'), $html);
if ($nb_matches < 1) { if ($nb_matches < 1) {
$nb_matches = 1; $nb_matches = 1;
@ -122,9 +121,6 @@ class Draggable extends Matching
for ($i = 1; $i <= $nb_matches; ++$i) { for ($i = 1; $i <= $nb_matches; ++$i) {
$form->addElement('html', '<tr><td>'); $form->addElement('html', '<tr><td>');
$group = array(); $group = array();
/*$puce = $form->createElement('text', null, null, 'value="'.$i.'"');
$puce->freeze();
$group[] = $puce;*/
$group[] = $form->createElement('text', 'answer['.$i.']', null, ' size="60" style="margin-left: 0em;"'); $group[] = $form->createElement('text', 'answer['.$i.']', null, ' size="60" style="margin-left: 0em;"');
$group[] = $form->createElement('select', 'matches['.$i.']', null, $a_matches); $group[] = $form->createElement('select', 'matches['.$i.']', null, $a_matches);
@ -138,13 +134,11 @@ class Draggable extends Matching
$form->addElement('html', '</td></tr>'); $form->addElement('html', '</td></tr>');
$defaults['option['.$i.']'] = $i; $defaults['option['.$i.']'] = $i;
//$defaults['matches['.$i.']'] = $i;
} }
$form->addElement('html', '</table></div></div>'); $form->addElement('html', '</table></div></div>');
$group = array(); $group = array();
$group[] = $form->createElement( $group[] = $form->createElement(
'style_submit_button', 'style_submit_button',
'moreMatches', 'moreMatches',
@ -162,37 +156,6 @@ class Draggable extends Matching
$group[] = $form->createElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"'); $group[] = $form->createElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"');
$form->addGroup($group); $form->addGroup($group);
// DISPLAY OPTIONS
/*
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
'.get_lang('Number').'
</th>
<th width="90%"
'.get_lang('Answer').'
</th>
</tr>';
//$form -> addElement ('html', $html);
$form->addElement('label', null, $html);
if ($nb_options < 1)
{
$nb_options = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$form->addElement('html', '<tr><td>');
$group = array();
$puce = $form->createElement('text', null, null, 'value="'.chr(64 + $i).'"');
$puce->freeze();
$group[] = $puce;
$group[] = $form->createElement('text', 'option['.$i.']', null, array('class' => 'span6'));
$form->addGroup($group, null, null, '</td><td>');
$form->addElement('html', '</td></tr>');
}*/
$form->addElement('html', '</table></div></div>'); $form->addElement('html', '</table></div></div>');
if (!empty($this->id)) { if (!empty($this->id)) {

@ -1155,7 +1155,7 @@ class Exercise
' '
<a href="javascript://" onclick=" return show_media()"> <a href="javascript://" onclick=" return show_media()">
<span id="media_icon"> <span id="media_icon">
<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" /> '.addslashes( '.Display::return_icon('looknfeel.png').' '.addslashes(
api_htmlentities(get_lang('ExerciseDescription')) api_htmlentities(get_lang('ExerciseDescription'))
).' ).'
</span> </span>
@ -1168,16 +1168,18 @@ class Exercise
$editor_config = array_merge($editor_config, $type); $editor_config = array_merge($editor_config, $type);
} }
$form->addElement('html', '<div class="HideFCKEditor" id="HiddenFCKexerciseDescription" >'); $form->addElement('html', '<div class="HideFCKEditor" id="HiddenFCKexerciseDescription" >');
$form->add_html_editor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config); $form->add_html_editor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config);
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
$form->addElement( $form->addElement('advanced_settings',
'advanced_settings', '<a href="javascript://" onclick=" return advanced_parameters()">
'<a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" > <span id="img_plus_and_minus">
<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.addslashes( <div style="vertical-align:top;" >
api_htmlentities(get_lang('AdvancedParameters')) '.Display::return_icon('div_show.gif').' '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'</div>
).'</div></span></a>' </span>
</a>'
); );
// Random questions // Random questions

@ -30,7 +30,6 @@ $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?1=1';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />'; $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
function check() { function check() {
$("#category_id option:selected").each(function() { $("#category_id option:selected").each(function() {
@ -81,107 +80,106 @@ $htmlHeadXtra[] = '<script>
function advanced_parameters() { function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') { if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\'; document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\'; document.getElementById(\'img_plus_and_minus\').innerHTML=\' '.Display::return_icon('div_hide.gif').' '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
} else { } else {
document.getElementById(\'options\').style.display = \'none\'; document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\' <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\'; document.getElementById(\'img_plus_and_minus\').innerHTML=\' '.Display::return_icon('div_show.gif').' '.addslashes(api_htmlentities(get_lang('AdvancedParameters'))).'\';
} }
} }
function FCKeditor_OnComplete( editorInstance ) { function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) { if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (editorInstance.Name); HideFCKEditorByInstanceName (editorInstance.Name);
} }
} }
function HideFCKEditorByInstanceName ( editorInstanceName ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" )
{
document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
}
}
function show_media() {
var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
if(my_display== \'none\' || my_display == \'\') {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeelna.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
} else {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
document.getElementById(\'media_icon\').innerHTML=\' <img src="../img/looknfeel.png" alt="" /> '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
}
}
function activate_start_date() { function HideFCKEditorByInstanceName ( editorInstanceName ) {
if(document.getElementById(\'start_date_div\').style.display == \'none\') { if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) {
document.getElementById(\'start_date_div\').style.display = \'block\'; document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
} else { }
document.getElementById(\'start_date_div\').style.display = \'none\'; }
}
}
function activate_end_date() { function show_media() {
if(document.getElementById(\'end_date_div\').style.display == \'none\') { var my_display = document.getElementById(\'HiddenFCKexerciseDescription\').style.display;
document.getElementById(\'end_date_div\').style.display = \'block\'; if(my_display== \'none\' || my_display == \'\') {
document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'block\';
document.getElementById(\'media_icon\').innerHTML=\' '.Display::return_icon('looknfeel.png').' '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
} else { } else {
document.getElementById(\'end_date_div\').style.display = \'none\'; document.getElementById(\'HiddenFCKexerciseDescription\').style.display = \'none\';
document.getElementById(\'media_icon\').innerHTML=\' '.Display::return_icon('looknfeel.png').' '.addslashes(api_htmlentities(get_lang('ExerciseDescription'))).'\';
} }
}
function activate_start_date() {
if(document.getElementById(\'start_date_div\').style.display == \'none\') {
document.getElementById(\'start_date_div\').style.display = \'block\';
} else {
document.getElementById(\'start_date_div\').style.display = \'none\';
} }
}
function activate_end_date() {
if(document.getElementById(\'end_date_div\').style.display == \'none\') {
document.getElementById(\'end_date_div\').style.display = \'block\';
} else {
document.getElementById(\'end_date_div\').style.display = \'none\';
}
}
function feedbackselection() {
var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
if (index == \'1\') { function feedbackselection() {
document.exercise_admin.exerciseType[1].checked=true; var index = document.exercise_admin.exerciseFeedbackType.selectedIndex;
document.exercise_admin.exerciseType[0].disabled=true;
} else {
document.exercise_admin.exerciseType[0].disabled=false;
}
}
function option_time_expired() { if (index == \'1\') {
if(document.getElementById(\'timercontrol\').style.display == \'none\') document.exercise_admin.exerciseType[1].checked=true;
{ document.exercise_admin.exerciseType[0].disabled=true;
document.getElementById(\'timercontrol\').style.display = \'block\'; } else {
} else { document.exercise_admin.exerciseType[0].disabled=false;
document.getElementById(\'timercontrol\').style.display = \'none\'; }
} }
}
function check_per_page_one() {
/*if (document.getElementById(\'divtimecontrol\').style.display==\'none\') {
document.getElementById(\'divtimecontrol\').style.display=\'block\';
document.getElementById(\'divtimecontrol\').display=block;
document.getElementById(\'timecontrol\').display=none;
}*/
document.getElementById(\'exerciseType_0\').checked=true;
}
function check_per_page_all() { function option_time_expired() {
/*if (document.getElementById(\'divtimecontrol\').style.display==\'block\') { if(document.getElementById(\'timercontrol\').style.display == \'none\')
document.getElementById(\'divtimecontrol\').style.display=\'none\'; {
document.getElementById(\'enabletimercontroltotalminutes\').value=\'\'; document.getElementById(\'timercontrol\').style.display = \'block\';
}*/ } else {
document.getElementById(\'timercontrol\').style.display = \'none\';
}
}
if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) { function check_per_page_one() {
document.getElementById(\'exerciseType_0\').checked = true; /*if (document.getElementById(\'divtimecontrol\').style.display==\'none\') {
} document.getElementById(\'divtimecontrol\').style.display=\'block\';
} document.getElementById(\'divtimecontrol\').display=block;
document.getElementById(\'timecontrol\').display=none;
}*/
document.getElementById(\'exerciseType_0\').checked=true;
}
function check_feedback() { function check_per_page_all() {
document.getElementById(\'result_disabled_0\').checked = true; /*if (document.getElementById(\'divtimecontrol\').style.display==\'block\') {
} document.getElementById(\'divtimecontrol\').style.display=\'none\';
document.getElementById(\'enabletimercontroltotalminutes\').value=\'\';
}*/
function check_direct_feedback() { if (document.getElementById(\'exerciseType_1\') && document.getElementById(\'exerciseType_1\').checked) {
document.getElementById(\'option_page_one\').checked = true; document.getElementById(\'exerciseType_0\').checked = true;
document.getElementById(\'result_disabled_0\').checked = true; }
} }
function check_results_disabled() { function check_feedback() {
document.getElementById(\'exerciseType_2\').checked = true; document.getElementById(\'result_disabled_0\').checked = true;
} }
</script>';
function check_direct_feedback() {
document.getElementById(\'option_page_one\').checked = true;
document.getElementById(\'result_disabled_0\').checked = true;
}
function check_results_disabled() {
document.getElementById(\'exerciseType_2\').checked = true;
}
</script>';
// to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters; // to correct #4029 Random and number of attempt menu empty added window.onload=advanced_parameters;
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
@ -265,9 +263,6 @@ if ($form->validate()) {
Display::display_error_message(get_lang('SearchXapianModuleNotInstalled')); Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
} }
// to hide the exercise description
echo '<style> .media { display:none;}</style>';
if ($objExercise->id != 0 && $objExercise->edit_exercise_in_lp == false) { if ($objExercise->id != 0 && $objExercise->edit_exercise_in_lp == false) {
$form->freeze(); $form->freeze();
} }

@ -126,7 +126,7 @@ class FillBlanks extends Question
// 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', Display::return_icon('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','/\[.*\]/');

@ -25,7 +25,7 @@ class GlobalMultipleAnswer extends Question
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
/* Mise en variable de Affichage "Reponses" et son icone, "N<EFBFBD>", "Vrai", "Reponse" */ /* Mise en variable de Affichage "Reponses" et son icone, "N<EFBFBD>", "Vrai", "Reponse" */
$html = '<table class="data_table"> $html = '<table class="data_table">
@ -47,7 +47,7 @@ class GlobalMultipleAnswer extends Question
$html .='</tr>'; $html .='</tr>';
$form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('Answers') . '<br />'.Display::return_icon('fill_field.png'), $html);
/* Initialiation variable */ /* Initialiation variable */
$defaults = array(); $defaults = array();

@ -17,7 +17,7 @@ include('../inc/lib/database.lib.php');
$courseCode = $_GET['coursecode']; $courseCode = $_GET['coursecode'];
$questionId = $_GET['questionId']; $questionId = $_GET['questionId'];
$coordinates = $_GET['coord']; $coordinates = $_GET['coord'];
$objExcercise = $_SESSION['objExercise']; $objExcercise = $this->exercise;
$exerciseId = $objExcercise->selectId(); $exerciseId = $objExcercise->selectId();
// Save clicking order // Save clicking order
$answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids'])+1; $answerOrderId = count($_SESSION['exerciseResult'][$questionId]['ids'])+1;

@ -113,7 +113,7 @@ class Matching extends Question
</th> </th>
</tr>'; </tr>';
$form->addElement('label', get_lang('MakeCorrespond').'<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('MakeCorrespond').'<br /> '.Display::return_icon('fill_field.png'), $html);
if ($nb_matches < 1) { if ($nb_matches < 1) {
$nb_matches = 1; $nb_matches = 1;

@ -28,8 +28,8 @@ class MultipleAnswer extends Question {
*/ */
function MultipleAnswer() { function MultipleAnswer() {
parent::question(); parent::question();
$this -> type = MULTIPLE_ANSWER; $this ->type = MULTIPLE_ANSWER;
$this -> isContent = $this-> getIsContent(); $this ->isContent = $this-> getIsContent();
} }
/** /**
@ -42,7 +42,7 @@ class MultipleAnswer extends Question {
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759. $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$html='<table class="data_table"> $html='<table class="data_table">
<tr> <tr>
@ -65,7 +65,7 @@ class MultipleAnswer extends Question {
'.get_lang('Weighting').' '.get_lang('Weighting').'
</th> </th>
</tr>'; </tr>';
$form -> addElement ('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form -> addElement ('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array(); $defaults = array();
$correct = 0; $correct = 0;

@ -42,7 +42,7 @@ class MultipleAnswerCombination extends Question
function createAnswersForm ($form) { function createAnswersForm ($form) {
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0)); $nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$html= '<table class="data_table"> $html= '<table class="data_table">
<tr style="text-align: center;"> <tr style="text-align: center;">
<th width="10px"> <th width="10px">
@ -59,7 +59,7 @@ class MultipleAnswerCombination extends Question
$html .='<th>'.get_lang('Comment').'</th>'; $html .='<th>'.get_lang('Comment').'</th>';
} }
$html .= '</tr>'; $html .= '</tr>';
$form -> addElement ('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form -> addElement ('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array(); $defaults = array();
$correct = 0; $correct = 0;

@ -43,7 +43,7 @@ class MultipleAnswerTrueFalse extends Question
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$renderer = & $form->defaultRenderer(); $renderer = & $form->defaultRenderer();
@ -68,7 +68,7 @@ class MultipleAnswerTrueFalse extends Question
$html .='<th>'.get_lang('Comment').'</th>'; $html .='<th>'.get_lang('Comment').'</th>';
} }
$html .= '</tr>'; $html .= '</tr>';
$form -> addElement ('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form -> addElement ('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$correct = 0; $correct = 0;
if (!empty($this -> id)) { if (!empty($this -> id)) {
@ -101,7 +101,7 @@ class MultipleAnswerTrueFalse extends Question
$answer_number->freeze(); $answer_number->freeze();
if (is_object($answer)) { if (is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i); $answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id]; $defaults['answer['.$i.']'] = $answer->answer[$answer_id];

@ -35,13 +35,14 @@ abstract class Question
public $parent_id; public $parent_id;
public $isContent; public $isContent;
public $course; public $course;
static $typePicture = 'new_question.png'; public static $typePicture = 'new_question.png';
static $explanationLangVar = ''; public static $explanationLangVar = '';
public $question_table_class = 'table table-striped'; public $question_table_class = 'table table-striped';
public $editionMode = 'normal'; public $editionMode = 'normal';
public $exercise; // exercise obj
public $setDefaultValues = false;
static $questionTypes = array( public static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'), UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php', 'MultipleAnswer'), MULTIPLE_ANSWER => array('multiple_answer.class.php', 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php', 'FillBlanks'), FILL_IN_BLANKS => array('fill_blanks.class.php', 'FillBlanks'),
@ -129,7 +130,7 @@ abstract class Question
* *
* @return boolean - true if question exists, otherwise false * @return boolean - true if question exists, otherwise false
*/ */
static function read($id, $course_id = null) static function read($id, $course_id = null, Exercise $exercise = null)
{ {
$id = intval($id); $id = intval($id);
@ -142,13 +143,14 @@ abstract class Question
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
if (empty($course_id) || $course_id == -1) { if (empty($course_id) || $course_id == -1) {
return false; //return false;
} }
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id AND c_id = $course_id"; //$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id AND c_id = $course_id";
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id";
$result = Database::query($sql); $result = Database::query($sql);
@ -170,8 +172,10 @@ abstract class Question
$objQuestion->course = $course_info; $objQuestion->course = $course_info;
$objQuestion->parent_id = $object->parent_id; $objQuestion->parent_id = $object->parent_id;
$objQuestion->category_list = Testcategory::getCategoryForQuestion($id); $objQuestion->category_list = Testcategory::getCategoryForQuestion($id);
$objQuestion->exercise = $exercise;
$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id"; //$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id";
$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id = $id";
$result_exercise_list = Database::query($sql); $result_exercise_list = Database::query($sql);
// fills the array with the exercises which this question is in // fills the array with the exercises which this question is in
@ -1305,14 +1309,16 @@ abstract class Question
* @param integer $type the type of the question * @param integer $type the type of the question
* @return an instance of a Question subclass (or of Questionc class by default) * @return an instance of a Question subclass (or of Questionc class by default)
*/ */
static function getInstance($type) static function getInstance($type, Exercise $exercise = null)
{ {
if (!is_null($type)) { if (!is_null($type)) {
list($file_name, $class_name) = self::get_question_type($type); list($file_name, $class_name) = self::get_question_type($type);
if (!empty($file_name)) { if (!empty($file_name)) {
include_once $file_name; include_once $file_name;
if (class_exists($class_name)) { if (class_exists($class_name)) {
return new $class_name(); $obj = new $class_name();
$obj->exercise = $exercise;
return $obj;
} else { } else {
echo 'Can\'t instanciate class '.$class_name.' of type '.$type; echo 'Can\'t instanciate class '.$class_name.' of type '.$type;
} }
@ -1325,16 +1331,15 @@ abstract class Question
/** /**
* Creates the form to create / edit a question * Creates the form to create / edit a question
* A subclass can redifine this function to add fields... * A subclass can redifine this function to add fields...
*
* @param FormValidator $form the formvalidator instance (by reference) * @param FormValidator $form the formvalidator instance (by reference)
*/ */
function createForm(&$form, $fck_config = 0) public function createForm(&$form, $fck_config = 0)
{ {
$url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?1=1'; $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?1=1';
echo '<style> $js = null;
.media { display:none;}
</style>';
if ($this->type != MEDIA_QUESTION) { if ($this->type != MEDIA_QUESTION) {
echo '<script> $js = '<script>
function check() { function check() {
$("#category_id option:selected").each(function() { $("#category_id option:selected").each(function() {
var id = $(this).val(); var id = $(this).val();
@ -1378,7 +1383,8 @@ abstract class Question
}); });
</script>'; </script>';
} }
echo '<script>
$js .= '<script>
// hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700 // hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700
function FCKeditor_OnComplete( editorInstance ) { function FCKeditor_OnComplete( editorInstance ) {
@ -1395,38 +1401,35 @@ abstract class Question
function show_media(){ function show_media(){
var my_display = document.getElementById(\'HiddenFCKquestionDescription\').style.display; var my_display = document.getElementById(\'HiddenFCKquestionDescription\').style.display;
if(my_display== \'none\' || my_display == \'\') { if (my_display== \'none\' || my_display == \'\') {
document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'block\'; document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'block\';
document.getElementById(\'media_icon\').innerHTML=\'&nbsp;<img style="vertical-align: middle;" src="../img/looknfeelna.png" alt="" />&nbsp;'.get_lang( document.getElementById(\'media_icon\').innerHTML=\'&nbsp;'.Display::return_icon('looknfeelna.png').'&nbsp;'.get_lang('EnrichQuestion').'\';
'EnrichQuestion'
).'\';
} else { } else {
document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'none\'; document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'none\';
document.getElementById(\'media_icon\').innerHTML=\'&nbsp;<img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang( document.getElementById(\'media_icon\').innerHTML=\'&nbsp;'.Display::return_icon('looknfeel.png').'&nbsp;'.get_lang('EnrichQuestion').'\';
'EnrichQuestion'
).'\';
} }
} }
// hub 13-12-2010 // hub 13-12-2010
function visiblerDevisibler(in_id) { function visiblerDevisibler(in_id) {
if (document.getElementById(in_id)) { if (document.getElementById(in_id)) {
if (document.getElementById(in_id).style.display == "none") { if (document.getElementById(in_id).style.display == "none") {
document.getElementById(in_id).style.display = "block"; document.getElementById(in_id).style.display = "block";
if (document.getElementById(in_id+"Img")) { if (document.getElementById(in_id+"Img")) {
document.getElementById(in_id+"Img").src = "../img/div_hide.gif"; document.getElementById(in_id+"Img").html = "'.addslashes(Display::return_icon('div_hide.gif')).'";
} }
} } else {
else {
document.getElementById(in_id).style.display = "none"; document.getElementById(in_id).style.display = "none";
if (document.getElementById(in_id+"Img")) { if (document.getElementById(in_id+"Img")) {
document.getElementById(in_id+"Img").src = "../img/div_show.gif"; document.getElementById(in_id+"Img").html = "dsdsds'.addslashes(Display::return_icon('div_show.gif')).'";
} }
} }
} }
} }
</script>'; </script>';
$form->addElement('html', $js);
// question name // question name
$form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6')); $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6'));
$form->addRule('questionName', get_lang('GiveQuestion'), 'required'); $form->addRule('questionName', get_lang('GiveQuestion'), 'required');
@ -1450,9 +1453,8 @@ abstract class Question
$form->addElement( $form->addElement(
'advanced_settings', 'advanced_settings',
'<a href="javascript://" onclick=" return show_media()"><span id="media_icon"><img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang( '<a href="javascript://" onclick=" return show_media()"><span id="media_icon">
'EnrichQuestion' '.Display::return_icon('looknfeel.png').'&nbsp;'.get_lang('EnrichQuestion').'</span></a>
).'</span></a>
' '
); );
@ -1467,18 +1469,13 @@ abstract class Question
if ($this->type != MEDIA_QUESTION) { if ($this->type != MEDIA_QUESTION) {
// Advanced parameters // Advanced parameters
$form->addElement( $form->addElement('advanced_settings', '<a class="btn btn-show advanced_parameters" id="advanced_params" href="javascript://">'.get_lang('AdvancedParameters').'</a>');
'advanced_settings',
'<a href="javascript:void(0)" onclick="visiblerDevisibler(\'id_advancedOption\')"><img id="id_advancedOptionImg" style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang(
"AdvancedParameters"
).'</a>'
);
$form->addElement('html', '<div id="id_advancedOption" style="display:none;">'); $form->addElement('html', '<div id="advanced_params_options" style="display:none;">');
$select_level = Question::get_default_levels(); $select_level = Question::get_default_levels();
$form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level); $form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level);
$categoryJS = null;
if (!empty($this->category_list)) { if (!empty($this->category_list)) {
$trigger = ''; $trigger = '';
foreach ($this->category_list as $category_id) { foreach ($this->category_list as $category_id) {
@ -1489,8 +1486,9 @@ abstract class Question
} }
} }
} }
echo '<script>$(function() { '.$trigger.' });</script>'; $categoryJS .= '<script>$(function() { '.$trigger.' });</script>';
} }
$form->addElement('html', $categoryJS);
$form->addElement( $form->addElement(
'select', 'select',
@ -1542,8 +1540,7 @@ abstract class Question
} }
// default values // default values
$defaults = array(); $defaults = array();
$defaults['questionName'] = $this->question; $defaults['questionName'] = $this->question;
$defaults['questionDescription'] = $this->description; $defaults['questionDescription'] = $this->description;
$defaults['questionLevel'] = $this->level; $defaults['questionLevel'] = $this->level;
@ -1562,6 +1559,10 @@ abstract class Question
$form->setDefaults($defaults); $form->setDefaults($defaults);
} }
} }
if ($this->setDefaultValues) {
$form->setDefaults($defaults);
}
} }

@ -15,15 +15,17 @@ $course_id = api_get_course_int_id();
// INIT QUESTION // INIT QUESTION
if (isset($_GET['editQuestion'])) { if (isset($_GET['editQuestion'])) {
$objQuestion = Question::read($_GET['editQuestion']); $objQuestion = Question::read($_GET['editQuestion'], null, $objExercise);
$action = api_get_self()."?".api_get_cidreq( $action = api_get_self()."?".api_get_cidreq(
)."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id."&exerciseId=$exerciseId"; )."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id."&exerciseId=$exerciseId";
} else { } else {
$objQuestion = Question :: getInstance($_REQUEST['answerType']); $objQuestion = Question::getInstance($_REQUEST['answerType'], $objExercise);
$action = api_get_self()."?".api_get_cidreq( $action = api_get_self()."?".api_get_cidreq(
)."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion."&exerciseId=$exerciseId"; )."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion."&exerciseId=$exerciseId";
} }
/** @var Question $objQuestion */
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);

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* File containing the UNIQUE_ANSWER class. * File containing the UNIQUE_ANSWER class.
* @package chamilo.exercise * @package chamilo.exercise
* @author Eric Marguin * @author Eric Marguin
*/ */
@ -29,7 +29,7 @@ class UniqueAnswer extends Question
/** /**
* Constructor * Constructor
*/ */
function UniqueAnswer() public function UniqueAnswer()
{ {
//this is highly important //this is highly important
parent::question(); parent::question();
@ -42,10 +42,10 @@ class UniqueAnswer extends Question
* @param the formvalidator instance * @param the formvalidator instance
* @param the answers number to display * @param the answers number to display
*/ */
function createAnswersForm($form) public function createAnswersForm($form)
{ {
// Getting the exercise list // Getting the exercise list
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
@ -91,7 +91,7 @@ class UniqueAnswer extends Question
</th> </th>
</tr>'; </tr>';
$form->addElement('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array(); $defaults = array();
$correct = 0; $correct = 0;
@ -316,7 +316,7 @@ class UniqueAnswer extends Question
* @param the formvalidator instance * @param the formvalidator instance
* @param the answers number to display * @param the answers number to display
*/ */
function processAnswersCreation($form) public function processAnswersCreation($form)
{ {
$questionWeighting = $nbrGoodAnswers = 0; $questionWeighting = $nbrGoodAnswers = 0;
@ -396,7 +396,7 @@ class UniqueAnswer extends Question
$this->save(); $this->save();
} }
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) public function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
{ {
$header = parent::return_header($feedback_type, $counter, $score, $show_media); $header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class.'"> $header .= '<table class="'.$this->question_table_class.'">
@ -427,7 +427,7 @@ class UniqueAnswer extends Question
* @assert (1,null,'a','',1,1,null) === false * @assert (1,null,'a','',1,1,null) === false
* @assert (1,1,'','',1,1,null) === false * @assert (1,1,'','',1,1,null) === false
*/ */
function create_answer( public function create_answer(
$id = 1, $id = 1,
$question_id, $question_id,
$answer_title, $answer_title,

@ -45,7 +45,7 @@ class UniqueAnswerImage extends UniqueAnswer
function createAnswersForm($form) function createAnswersForm($form)
{ {
// Getting the exercise list // Getting the exercise list
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$editor_config = array('ToolbarSet' => 'UniqueAnswerImage', 'Width' => '100%', 'Height' => '125'); $editor_config = array('ToolbarSet' => 'UniqueAnswerImage', 'Width' => '100%', 'Height' => '125');
@ -84,7 +84,7 @@ class UniqueAnswerImage extends UniqueAnswer
</th> </th>
</tr>'; </tr>';
$form->addElement('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array(); $defaults = array();
$correct = 0; $correct = 0;

@ -44,7 +44,7 @@ class UniqueAnswerNoOption extends Question
*/ */
function createAnswersForm ($form) { function createAnswersForm ($form) {
// getting the exercise list // getting the exercise list
$obj_ex = $_SESSION['objExercise']; $obj_ex = $this->exercise;
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
@ -88,7 +88,7 @@ class UniqueAnswerNoOption extends Question
'.get_lang('Weighting').' '.get_lang('Weighting').'
</th> </th>
</tr>'; </tr>';
$form->addElement('label', get_lang('Answers').'<br /> <img src="../img/fill_field.png">', $html); $form->addElement('label', get_lang('Answers').'<br />'.Display::return_icon('fill_field.png'), $html);
$defaults = array(); $defaults = array();
$correct = 0; $correct = 0;

@ -775,7 +775,10 @@ class Database
strpos($query, 'c_id') === false && strpos($query, 'c_id') === false &&
strpos($query, 'c_quiz_question_rel_category') === false && strpos($query, 'c_quiz_question_rel_category') === false &&
strpos($query, 'c_quiz_category') === false && strpos($query, 'c_quiz_category') === false &&
strpos($query, 'c_quiz_rel_question') === false &&
strpos($query, 'c_quiz_answer') === false &&
strpos($query, 'c_quiz_question') === false &&
strpos($query, 'c_quiz_rel_question') === false &&
strpos($query, 'create table') === false && strpos($query, 'create table') === false &&
strpos($query, 'CREATE TABLE') === false && strpos($query, 'CREATE TABLE') === false &&
strpos($query, 'AUTO_INCREMENT') === false strpos($query, 'AUTO_INCREMENT') === false

Loading…
Cancel
Save