diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 205a24b7cb..9bc8578704 100755 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -500,5 +500,4 @@ api_session_register('objExercise'); api_session_register('objQuestion'); api_session_register('objAnswer'); -Display::display_footer(); -?> \ No newline at end of file +Display::display_footer(); \ No newline at end of file diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 579b10c3af..9cf38b6ebc 100755 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.php @@ -45,10 +45,9 @@ class Answer * @author Olivier Brouckaert * @param integer Question ID that answers belong to */ - function Answer($questionId) - { + function Answer($questionId) { //$this->questionType=$questionType; - $this->questionId = (int)$questionId; + $this->questionId = intval($questionId); $this->answer = array(); $this->correct = array(); $this->comment = array(); @@ -75,8 +74,7 @@ class Answer * * @author - Olivier Brouckaert */ - function cancel() - { + function cancel() { $this->new_answer = array(); $this->new_correct = array(); $this->new_comment = array(); @@ -93,8 +91,7 @@ class Answer * * @author - Olivier Brouckaert */ - function read() - { + function read() { global $_course; $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); @@ -102,7 +99,7 @@ class Answer //$answerType=$this->selectType(); $sql="SELECT id,answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination, id_auto FROM - $TBL_ANSWER WHERE question_id ='".Database::escape_string($questionId)."' ORDER BY position"; + $TBL_ANSWER WHERE question_id ='".$questionId."' ORDER BY position"; $result=Database::query($sql); @@ -130,24 +127,20 @@ class Answer * @param string DESC or ASC * @author Frederic Vauthier */ - function readOrderedBy($field,$order=ASC) - { + function readOrderedBy($field,$order='ASC') { global $_course; $field = Database::escape_string($field); - if(empty($field)) { + if (empty($field)) { $field = 'position'; } - if($order != 'ASC' and $order!='DESC') - { + + if ($order != 'ASC' && $order!='DESC') { $order = 'ASC'; } $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); - $questionId=$this->questionId; - //$answerType=$this->selectType(); - $sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " . - "FROM $TBL_ANSWER WHERE question_id='".Database::escape_string($questionId)."' " . + "FROM $TBL_ANSWER WHERE question_id='".$questionId."' " . "ORDER BY $field $order"; $result=Database::query($sql); @@ -155,8 +148,7 @@ class Answer $i=1; // while a record is found - while($object=Database::fetch_object($result)) - { + while($object=Database::fetch_object($result)) { $this->answer[$i] = $object->answer; $this->correct[$i] = $object->correct; $this->comment[$i] = $object->comment; @@ -231,7 +223,6 @@ class Answer * return array answer by id else return a bool */ function selectAnswerByAutoId($auto_id) { - $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); $auto_id = intval($auto_id); $sql="SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'"; @@ -252,8 +243,7 @@ class Answer * @param - integer $id - answer ID * @return - bool - answer title */ - function selectAnswerIdByPosition($pos) - { + function selectAnswerIdByPosition($pos) { foreach ($this->position as $k => $v) { if ($v != $pos) { continue; } return $k; @@ -266,8 +256,7 @@ class Answer * @author Yannick Warnier * @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting */ - function getAnswersList($decode = false) - { + function getAnswersList($decode = false) { $list = array(); for($i = 1; $i<=$this->nbrAnswers;$i++){ if(!empty($this->answer[$i])){ @@ -316,7 +305,7 @@ class Answer function getQuestionType() { $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); - $sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".Database::escape_string($this->questionId)."'"; + $sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".$this->questionId."'"; $res = Database::query($sql); if(Database::num_rows($res)<=0){ return null; diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 92a80aab65..97507676a2 100755 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -827,8 +827,7 @@ if ($show == 'test') { echo '
'.get_count_exam_results($row['id']).' '.get_lang('Attempts'); //Special buttons - echo '
'; - + echo '
'; echo Display::url(Display::return_icon('quiz.gif',get_lang('Questions'), array('width'=>'22px'))." ".get_lang('Questions'),'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']); echo ' '; echo Display::url(Display::return_icon('preview.gif',get_lang('Preview'), array('width'=>'22px'))." ".get_lang('Preview'), 'exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id']); diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 7507571a99..1ed7256f3a 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2388,7 +2388,7 @@ class Exercise { } elseif ($answerType == FREE_ANSWER) { $answer = $choice; exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); - } elseif ($answerType == UNIQUE_ANSWER) { + } elseif ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) { $answer = $choice; exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); } elseif ($answerType == HOT_SPOT) { diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 3030951a45..8fe5d13425 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -88,6 +88,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre $s .= ''; // construction of the Answer object (also gets all answers details) $objAnswerTmp=new Answer($questionId); + $nbrAnswers=$objAnswerTmp->selectNbrAnswers(); $quiz_question_options = Question::readQuestionOption($questionId); @@ -255,15 +256,15 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre if ($debug_mark_answer) { if ($answerCorrect) { $help = 'x-'; - $selected = 'checked="checked"'; + $selected = 'checked'; } } $answer = text_filter($answer); $answer = Security::remove_XSS($answer, STUDENT); - $s .= ''. + $s .= Display::input('hidden','choice2['.$questionId.']','0'). ''; @@ -413,6 +414,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre } } // end for() + + //Adding divs for the new MATCHING interface if ($answerType == MATCHING && !$freeze) { diff --git a/main/exercice/question_admin.inc.php b/main/exercice/question_admin.inc.php index 4a42ccec79..c406af69fc 100755 --- a/main/exercice/question_admin.inc.php +++ b/main/exercice/question_admin.inc.php @@ -90,6 +90,7 @@ if(is_object($objQuestion)) { // question $objQuestion -> processCreation($form,$objExercise); // answers + $objQuestion -> processAnswersCreation($form,$nb_answers); // TODO: maybe here is the better place to index this tool, including answers text diff --git a/main/exercice/question_list_admin.inc.php b/main/exercice/question_list_admin.inc.php index 5b0f3c2774..3ad47963df 100755 --- a/main/exercice/question_list_admin.inc.php +++ b/main/exercice/question_list_admin.inc.php @@ -119,6 +119,7 @@ if ($nbrQuestions) { $questionList=$my_exercise->selectQuestionList(); $i=1; + if (is_array($questionList)) { echo '
'; foreach($questionList as $id) { @@ -140,49 +141,25 @@ if ($nbrQuestions) { echo '
'; $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved')); echo Display::tag('h3',''.$move.' '.$objQuestionTmp->selectTitle().''); - echo '
'; - - echo '

'; - echo $actions; - - - echo get_lang($question_class.$label); - echo '
'; - - echo get_lang('Level').': '.$objQuestionTmp->selectLevel(); - echo '
'; - $description = $objQuestionTmp->selectDescription(); - if (!empty($description)) { - echo get_lang('Description').': '.$description; - } - - - showQuestion($id, false, '', '',false, true); - - /* - if($i != 1) { ?> - <?php echo get_lang('MoveUp'); ?> - '; - } - } - if($i != $nbrQuestions) { - if($i == 1){ - echo ''; - } - ?> - <?php echo get_lang('MoveDown'); ?> - - - '; - echo '

'; - echo '
'; - unset($objQuestionTmp); + echo '
'; + + echo '

'; + echo $actions; + echo get_lang($question_class.$label); + echo '
'; + + echo get_lang('Level').': '.$objQuestionTmp->selectLevel(); + echo '
'; + $description = $objQuestionTmp->selectDescription(); + if (!empty($description)) { + echo get_lang('Description').': '.$description; + } + showQuestion($id, false, '', '',false, true); + echo '

'; + + echo '
'; + echo '
'; + unset($objQuestionTmp); } echo ''; } diff --git a/main/exercice/unique_answer_no_option.class.php b/main/exercice/unique_answer_no_option.class.php index 999c09bdb9..565e901188 100755 --- a/main/exercice/unique_answer_no_option.class.php +++ b/main/exercice/unique_answer_no_option.class.php @@ -249,52 +249,51 @@ class UniqueAnswerNoOption extends Question { } - //Adding I don't know question option - $i = 666; - $form -> addElement ('html', ''); - - $defaults['answer['.$i.']'] = get_lang('DontKnow'); - $defaults['weighting['.$i.']'] = 0; - - $defaults['scenario']=$temp_scenario; - $renderer = & $form->defaultRenderer(); - $renderer->setElementTemplate(''); - $renderer->setElementTemplate('','html'); - $answer_number=$form->addElement('text', null,null,'value="-"'); - $answer_number->freeze(); - - $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); - $form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config); - - - $form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required'); - - if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { - // feedback - $form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config); - } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { -/* // direct feedback - $form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config); - //Adding extra feedback fields - $group = array(); - $group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' ); - $group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id); - $group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question); - $group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px')); - - $form -> addGroup($group, 'scenario', 'scenario'); - $renderer->setGroupElementTemplate('
{label}
{element}
','scenario');*/ - } - - //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); - - $form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0" readonly="readonly" '); - $form->addElement ('html', ''); + //Adding the "I don't know" question answer + if(empty($this -> id)) { + $i = 666; + $form -> addElement ('html', ''); + + $defaults['answer['.$i.']'] = get_lang('DontKnow'); + $defaults['weighting['.$i.']'] = 0; + + $defaults['scenario']=$temp_scenario; + $renderer = & $form->defaultRenderer(); + $renderer->setElementTemplate(''); + $renderer->setElementTemplate('','html'); + $answer_number=$form->addElement('text', null,null,'value="-"'); + $answer_number->freeze(); + + $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); + $form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config); + $form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required'); + + + if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) { + // feedback + $form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config); + } elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { + /* // direct feedback + $form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config); + //Adding extra feedback fields + $group = array(); + $group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' ); + $group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id); + $group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question); + $group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px')); + $form -> addGroup($group, 'scenario', 'scenario'); + $renderer->setGroupElementTemplate('
{label}
{element}
','scenario');*/ + } + //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); + + $form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0" readonly="readonly" '); + $form->addElement ('html', ''); - - + } + + $form -> addElement ('html', '

'. - '

'. + ''.Display::input('radio','choice['.$questionId.']', $numAnswer, array('class'=>'checkbox','selected'=>$selected)).'

'. '
'. $answer. '
{error}
{element}
{error}
{element}
{error}
{element}
{error}
{element}
'); $form -> addElement ('html', '
'); $navigator_info = api_get_navigator(); @@ -347,16 +346,16 @@ class UniqueAnswerNoOption extends Question { $correct = $form -> getSubmitValue('correct'); $objAnswer = new Answer($this->id); $nb_answers = $form -> getSubmitValue('nb_answers'); + - for($i=1 ; $i <= $nb_answers ; $i++) - { - $answer = trim($form -> getSubmitValue('answer['.$i.']')); - $comment = trim($form -> getSubmitValue('comment['.$i.']')); - $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); + for ($i=1 ; $i <= $nb_answers ; $i++) { + $answer = trim($form -> getSubmitValue('answer['.$i.']')); + $comment = trim($form -> getSubmitValue('comment['.$i.']')); + $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); $scenario= $form -> getSubmitValue('scenario'); - echo '
';
+            
            	//$list_destination = $form -> getSubmitValue('destination'.$i);
            	//$destination_str = $form -> getSubmitValue('destination'.$i);
 
@@ -387,12 +386,10 @@ class UniqueAnswerNoOption extends Question {
 
         	$goodAnswer= ($correct == $i) ? true : false;
 
-        	if($goodAnswer)
-        	{
+        	if($goodAnswer) {
         		$nbrGoodAnswers++;
         		$weighting = abs($weighting);
-        		if($weighting > 0)
-                {
+        		if($weighting > 0) {
                     $questionWeighting += $weighting;
                 }
         	}
@@ -400,30 +397,33 @@ class UniqueAnswerNoOption extends Question {
  			if (empty($try))
  				$try=0;
 
- 			if (empty($lp))
- 			{
+ 			if (empty($lp)) {
  				$lp=0;
  			}
 
- 			if (empty($destination))
- 			{
+ 			if (empty($destination)) {
  				$destination=0;
  			}
-
-
-
- 			if ($url=='')
- 			{
+            
+ 			if ($url=='') {
  				$url=0;
  			}
 
- 			//1@@1;2;@@2;4;4;@@http://www.dokeos.com
+ 			//1@@1;2;@@2;4;4;@@http://www.chamilo.org
 			$dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url;
         	$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest);
-
         }
-
-
+        
+        //Create 666 answer
+        $i = 666;
+        $answer     = trim($form -> getSubmitValue('answer['.$i.']'));
+        $comment    = trim($form -> getSubmitValue('comment['.$i.']'));
+        $weighting  = trim($form -> getSubmitValue('weighting['.$i.']'));
+        $goodAnswer= ($correct == $i) ? true : false;
+        $dest       = '';
+            
+        $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest);
+        
     	// saves the answers into the data base
         $objAnswer -> save();