Browse Source

Drag and drop question type based in matching see BT#5980

Julio Montoya 12 years ago
parent
commit
4def1da626

+ 17 - 1
main/css/base.css

@@ -5173,4 +5173,20 @@ i.size-32.icon-new-work {
 
 .advmultiselect .span1 {
     padding-top: 50px;
-}
+}
+
+
+.drag_question {
+    list-style-type: none;
+    margin: 0;
+    padding: 0;
+}
+
+.drag_question li {
+    margin: 3px 3px 3px 0;
+    padding: 1px;
+    float: left;
+    width: 100px;
+    height: 90px;
+    text-align: center;
+}

+ 0 - 2
main/exercice/answer.class.php

@@ -638,6 +638,4 @@ class Answer
                 }
             });</script>';
     }
-
-
 }

+ 18 - 18
main/exercice/draggable.class.php

@@ -45,6 +45,7 @@ class Draggable extends Matching
         if ($form->isSubmitted()) {
             $nb_matches = $form->getSubmitValue('nb_matches');
             $nb_options = $form->getSubmitValue('nb_options');
+
             if (isset($_POST['lessMatches'])) {
                 $nb_matches--;
             }
@@ -70,7 +71,7 @@ class Draggable extends Matching
                             $nb_matches++;
                             $defaults['answer['.$nb_matches.']']    = $answer->selectAnswer($i);
                             $defaults['weighting['.$nb_matches.']'] = float_format($answer->selectWeighting($i), 1);
-                            $defaults['matches['.$nb_matches.']']   = $nb_matches;
+                            $defaults['matches['.$nb_matches.']']   = $answer->correct[$i];//$nb_matches;
                         } else {
                             $nb_options++;
                             $defaults['option['.$nb_options.']'] = $nb_options;
@@ -90,7 +91,7 @@ class Draggable extends Matching
 
         $a_matches = array();
         for ($i = 1; $i <= $nb_matches; ++$i) {
-            $a_matches[$i] = chr(64 + $i); // fill the array with A, B, C.....
+            $a_matches[$i] = $i; // fill the array with A, B, C.....
         }
 
         $form->addElement('hidden', 'nb_matches', $nb_matches);
@@ -123,9 +124,9 @@ class Draggable extends Matching
         for ($i = 1; $i <= $nb_matches; ++$i) {
             $form->addElement('html', '<tr><td>');
             $group = array();
-            $puce  = $form->createElement('text', null, null, 'value="'.$i.'"');
+            /*$puce  = $form->createElement('text', null, null, 'value="'.$i.'"');
             $puce->freeze();
-            $group[] = $puce;
+            $group[] = $puce;*/
 
             $group[] = $form->createElement('text', 'answer['.$i.']', null, ' size="60" style="margin-left: 0em;"');
             $group[] = $form->createElement('select', 'matches['.$i.']', null, $a_matches);
@@ -139,7 +140,7 @@ class Draggable extends Matching
             $form->addElement('html', '</td></tr>');
 
             $defaults['option['.$i.']'] = $i;
-            $defaults['matches['.$i.']']   = $i;
+            //$defaults['matches['.$i.']']   = $i;
         }
 
         $form->addElement('html', '</table></div></div>');
@@ -160,9 +161,15 @@ class Draggable extends Matching
         );
 
 
+        global $text, $class;
+
+        $group[] = $form->createElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"');
+
+
         $form->addGroup($group);
 
         // DISPLAY OPTIONS
+        /*
         $html = '<table class="data_table">
 					<tr style="text-align: center;">
 						<th width="10px">
@@ -190,15 +197,10 @@ class Draggable extends Matching
             $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>');
 
-        global $text, $class;
-
-        $group = array();
-        $group[] = $form->createElement('style_submit_button', 'submitQuestion', $text, 'class="'.$class.'"');
-        $form->addGroup($group);
 
         if (!empty($this->id)) {
             $form->setDefaults($defaults);
@@ -217,19 +219,17 @@ class Draggable extends Matching
      */
     public function processAnswersCreation($form)
     {
-
         $nb_matches      = $form->getSubmitValue('nb_matches');
-        $nb_options      = $form->getSubmitValue('nb_options');
         $this->weighting = 0;
         $objAnswer       = new Answer($this->id);
 
         $position = 0;
 
         // insert the options
-        for ($i = 1; $i <= $nb_options; ++$i) {
+        for ($i = 1; $i <= $nb_matches; ++$i) {
             $position++;
-            $option = $form->getSubmitValue('option['.$i.']');
-            $objAnswer->createAnswer($option, 0, '', 0, $position);
+            //$option = $form->getSubmitValue('option['.$i.']');
+            $objAnswer->createAnswer($position, 0, '', 0, $position);
         }
 
         // insert the answers
@@ -239,6 +239,7 @@ class Draggable extends Matching
             $matches   = $form->getSubmitValue('matches['.$i.']');
             $weighting = $form->getSubmitValue('weighting['.$i.']');
             $this->weighting += $weighting;
+            var_dump($answer, $matches);
             $objAnswer->createAnswer($answer, $matches, '', $weighting, $position);
         }
         $objAnswer->save();
@@ -258,9 +259,8 @@ class Draggable extends Matching
         $header .= '<table class="'.$this->question_table_class.'">';
         $header .= '<tr>
                 <th>'.get_lang('ElementList').'</th>
-                <th>'.get_lang('CorrespondsTo').'</th>
+                <th>'.get_lang('Status').'</th>
               </tr>';
         return $header;
     }
-
 }

+ 28 - 13
main/exercice/exercise.class.php

@@ -2520,7 +2520,7 @@ class Exercise
                 error_log("answer correct: $answerCorrect ");
             }
 
-            //delineation
+            //Delineation
             $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
             $answer_delineation_destination = $objAnswerTmp->selectDestination(1);
 
@@ -2905,6 +2905,7 @@ class Exercise
                     }
                     break;
                 // for matching
+                case DRAGGABLE:
                 case MATCHING :
                     if ($from_database) {
                         $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id="'.$questionId.'" AND correct=0';
@@ -2937,19 +2938,38 @@ class Exercise
                                 $s_user_answer = 0;
                             }
                             $i_answerWeighting = $objAnswerTmp->selectWeighting($i_answer_id);
+
                             $user_answer = '';
                             if (!empty($s_user_answer)) {
                                 if ($s_user_answer == $i_answer_correct_answer) {
                                     $questionScore += $i_answerWeighting;
                                     $totalScore += $i_answerWeighting;
-                                    $user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
+                                    if ($answerType == DRAGGABLE) {
+                                        $user_answer = Display::label(get_lang('Correct'), 'success');
+                                    } else {
+                                        $user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
+                                    }
                                 } else {
-                                    $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
+                                    if ($answerType == DRAGGABLE) {
+                                        $user_answer = Display::label(get_lang('NotCorrect'), 'important');
+                                    } else {
+                                        $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
+                                    }
+                                }
+                            } else {
+                                if ($answerType == DRAGGABLE) {
+                                    $user_answer = Display::label(get_lang('Incorrect'), 'important');
                                 }
                             }
+
                             if ($show_result) {
                                 echo '<tr>';
-                                echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
+                                echo '<td>'.$s_answer_label.'</td>';
+                                echo '<td>'.$user_answer.'';
+                                if ($answerType == MATCHING) {
+                                    echo '<b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b>';
+                                }
+                                echo '</td>';
                                 echo '</tr>';
                             }
                         }
@@ -3060,7 +3080,7 @@ class Exercise
                     }
 
                     //display answers (if not matching type, or if the answer is correct)
-                    if ($answerType != MATCHING || $answerCorrect) {
+                    if (!in_array($answerType, array(DRAGGABLE, MATCHING))|| $answerCorrect) {
                         if (in_array(
                             $answerType,
                             array(
@@ -3582,14 +3602,11 @@ class Exercise
                                 $answerComment
                             );
                             break;
+                        case DRAGGABLE:
                         case MATCHING:
                             if ($origin != 'learnpath') {
                                 echo '<tr>';
-                                echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter(
-                                    $user_answer
-                                ).' / <b><span style="color: #008000;">'.text_filter(
-                                    $answer_matching[$answerCorrect]
-                                ).'</span></b></td>';
+                                echo '<td>'.$answer_matching[$answerId].'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$answer_matching[$answerCorrect].'</span></b></td>';
                                 echo '</tr>';
                             }
                             break;
@@ -3900,7 +3917,7 @@ class Exercise
                 } else {
                     exercise_attempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
                 }
-            } elseif ($answerType == MATCHING) {
+            } elseif ($answerType == MATCHING || $answerType == DRAGGABLE) {
                 if (isset($matching)) {
                     foreach ($matching as $j => $val) {
                         exercise_attempt($questionScore, $val, $quesId, $exeId, $j, $this->id);
@@ -3955,8 +3972,6 @@ class Exercise
         return $return_array;
     }
 
-//End function
-
     /**
      * Sends a notification when a user ends an examn
      *

+ 99 - 11
main/exercice/exercise.lib.php

@@ -83,9 +83,12 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
         $num_suggestions = 0;
 
         if ($answerType == MATCHING || $answerType == DRAGGABLE) {
-
-            $s .= '<div id="drag'.$questionId.'_question" class="drag_question">';
-            $s .= '<table class="data_table">';
+            if ($answerType == DRAGGABLE) {
+                $s .= '<ul class="drag_question">';
+            } else {
+                $s .= '<div id="drag'.$questionId.'_question" class="drag_question">';
+                $s .= '<table class="data_table">';
+            }
 
             $x = 1; //iterate through answers
             $letter = 'A'; //mark letters for each answer
@@ -441,7 +444,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                     $answer = api_preg_replace('/\[[^]]+\]/', Display::input('text', "choice[$questionId][]", '', $attributes), $answer);
                 }
                 $s .= $answer;
-            } elseif ($answerType == MATCHING || $answerType ==  DRAGGABLE) {
+            } elseif ($answerType == MATCHING) {
                 // matching type, showing suggestions and answers
                 // TODO: replace $answerId by $numAnswer
                 if ($answerId == 1) {
@@ -449,7 +452,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                 }
                 if ($answerCorrect != 0) {
                     // only show elements to be answered (not the contents of
-                    // the select boxes, who are corrrect = 0)
+                    // the select boxes, who are correct = 0)
                     $s .= '<tr><td width="45%">';
                     $parsed_answer = $answer;
                     $windowId = $questionId.'_'.$lines_count;
@@ -497,12 +500,8 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                             });
                             </script>';
                     }
-
-
                     $s .= '</select></div></td>';
 
-                    //print_r($select_items);
-                    //right part (answers)
                     $s.='<td width="45%" valign="top" >';
 
                     if (isset($select_items[$lines_count])) {
@@ -533,18 +532,107 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                     }  // end if()
                     $matching_correct_answer++;
                 }
+            } elseif ($answerType ==  DRAGGABLE) {
+                // matching type, showing suggestions and answers
+                // TODO: replace $answerId by $numAnswer
+                if ($answerId == 1) {
+                    //echo $objAnswerTmp->getJs();
+                    //$s .= '<tr>';
+                }
+                if ($answerCorrect != 0) {
+                    // only show elements to be answered (not the contents of
+                    // the select boxes, who are correct = 0)
+                    $s .= '<td>';
+                    $parsed_answer = $answer;
+                    $windowId = $questionId.'_'.$lines_count;
+                    //left part questions
+                    $s .= '<li class="ui-state-default" id="'.$windowId.'"><span class="ui-icon ui-icon-arrow-2-e-w"></span>';
+                    $s .= ' <div id="window_'.$windowId.'" class="window'.$questionId.'_question_draggable">
+                                <b>'.$lines_count.'</b>.&nbsp'.$parsed_answer.'
+                            </div>';
+
+                    $s .= '<div style="display:none">';
+
+                    $s .= '<select id="window_'.$windowId.'_select" name="choice['.$questionId.']['.$numAnswer.']" class="select_option">';
+                    $selectedValue = 0;
+                    // fills the list-box
+                    foreach ($select_items as $key => $val) {
+                        // set $debug_mark_answer to true at function start to
+                        // show the correct answer with a suffix '-x'
+                        $selected = '';
+                        if ($debug_mark_answer) {
+                            if ($val['id'] == $answerCorrect) {
+                                $selected = 'selected="selected"';
+                                $selectedValue = $val['id'];
+                            }
+                        }
+                        if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
+                            $selected = 'selected="selected"';
+                            $selectedValue = $val['id'];
+                        }
+                        $s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>';
+                    }
+
+                    /*if (!empty($answerCorrect) && !empty($selectedValue)) {
+                        $s.= '<script>
+                            jsPlumb.ready(function() {
+                                jsPlumb.connect({
+                                    source: "window_'.$windowId.'",
+                                    target: "window_'.$questionId.'_'.$selectedValue.'_answer",
+                                    endpoint:["Blank", { radius:15 }],
+                                    anchor:["RightMiddle","LeftMiddle"],
+                                    paintStyle:{ strokeStyle:"#8a8888" , lineWidth:8 },
+                                    connector: [connectorType, { curviness: curvinessValue } ],
+                                })
+                            });
+                            </script>';
+                    }*/
+                    $s .= '</select>';
+
+                    if (isset($select_items[$lines_count])) {
+                        $s.= '<div id="window_'.$windowId.'_answer" class="">
+                                <b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'].'
+                              </div>';
+                    } else {
+                        $s.='&nbsp;';
+                    }
+                    //$s .= '</td>';
+
+                    $lines_count++;
+                    //if the left side of the "matching" has been completely
+                    // shown but the right side still has values to show...
+
+                    if (($lines_count - 1) == $num_suggestions) {
+                        // if it remains answers to shown at the right side
+                        while (isset($select_items[$lines_count])) {
+                            $s.='<b>'.$select_items[$lines_count]['letter'].'.</b>';
+                            $s .= $select_items[$lines_count]['answer'];
+                            $lines_count++;
+                        }
+                    }
+                    $s .= '</div>';
+                    $matching_correct_answer++;
+                    $s .= '</li>';
+                }
             }
+            //$s.="</tr>";
+
         } // end for()
+
         if ($show_comment) {
             $s .= '</table>';
         } else {
-            if ($answerType == DRAGGABLE ||  $answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE ||
+            if (  $answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE ||
                 $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
                 $s .= '</table>';
             }
         }
 
-        if ($answerType == MATCHING || $answerType == DRAGGABLE) {
+        if ($answerType == DRAGGABLE) {
+            $s .= '</ul>';
+        }
+
+        if ($answerType == MATCHING) {
             $s .= '</div>';
         }
 

+ 107 - 109
main/exercice/exercise_show.php

@@ -1,14 +1,14 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
- *  Shows the exercise results 
+ *  Shows the exercise results
  *
  * @author Julio Montoya Armas Added switchable fill in blank option added
  * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  * @package chamilo.exercise
  * @todo remove the debug code and use the general debug library
  * @todo small letters for table variables
- * 
+ *
  */
 /**
  * Code
@@ -63,8 +63,8 @@ if (empty($id)) {
 	api_not_allowed(true);
 }
 
-  
-if (api_is_course_session_coach(api_get_user_id(), api_get_course_id(), api_get_session_id())) {    
+
+if (api_is_course_session_coach(api_get_user_id(), api_get_course_id(), api_get_session_id())) {
     if (!api_coach_can_edit_view_results(api_get_course_id(), api_get_session_id())) {
         api_not_allowed(true);
     }
@@ -83,7 +83,7 @@ $exercise_id        = $track_exercise_info['id'];
 $exercise_date      = $track_exercise_info['start_date'];
 $student_id         = $track_exercise_info['exe_user_id'];
 $learnpath_id       = $track_exercise_info['orig_lp_id'];
-$learnpath_item_id  = $track_exercise_info['orig_lp_item_id'];    
+$learnpath_item_id  = $track_exercise_info['orig_lp_item_id'];
 $lp_item_view_id    = $track_exercise_info['orig_lp_item_view_id'];
 $current_user_id    = api_get_user_id();
 
@@ -96,7 +96,7 @@ if (empty($objExercise)) {
 $feedback_type = $objExercise->feedback_type;
 
 
-//Only users can see their own results 
+//Only users can see their own results
 if (!$is_allowedToEdit) {
     if ($student_id != $current_user_id) {
     	api_not_allowed(true);
@@ -166,9 +166,9 @@ $show_only_total_score  = false;
 if (!empty($track_exercise_info)) {
 	// if the results_disabled of the Quiz is 1 when block the script
 	$result_disabled		= $track_exercise_info['results_disabled'];
-	
-	if (!(api_is_platform_admin() || api_is_course_admin()) ) {    
-		if ($result_disabled == 1) {		    
+
+	if (!(api_is_platform_admin() || api_is_course_admin()) ) {
+		if ($result_disabled == 1) {
 			//api_not_allowed();
 			$show_results = false;
 			//Display::display_warning_message(get_lang('CantViewResults'));
@@ -183,7 +183,7 @@ if (!empty($track_exercise_info)) {
 			}
 		} elseif ($result_disabled == 2) {
 		    $show_results = false;
-		    $show_only_total_score = true;			  
+		    $show_only_total_score = true;
 			if ($origin != 'learnpath') {
 			    echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
                       <tr>
@@ -192,8 +192,8 @@ if (!empty($track_exercise_info)) {
 				echo '</td>
 				</tr>
 				</table>';
-			}			  
-		}       
+			}
+		}
 	}
 } else {
 	Display::display_warning_message(get_lang('CantViewResults'));
@@ -220,11 +220,11 @@ $arrans  = array();
 $user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($student_id)." ";
 $query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts
 				INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id
-				INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions 
-				    ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id 
+				INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions
+				    ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
 				    AND quizz_rel_questions.question_id = attempts.question_id
 				    AND quizz_rel_questions.c_id=".api_get_course_int_id()."
-				INNER JOIN ".$TBL_QUESTIONS." AS questions 
+				INNER JOIN ".$TBL_QUESTIONS." AS questions
 				    ON questions.id=quizz_rel_questions.question_id
 				    AND questions.c_id = ".api_get_course_int_id()."
 		  WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
@@ -234,7 +234,7 @@ $result = Database::query($query);
 $question_list_from_database = array();
 $exerciseResult = array();
 
-while ($row = Database::fetch_array($result)) {	
+while ($row = Database::fetch_array($result)) {
 	$question_list_from_database[] = $row['question_id'];
 	$exerciseResult[$row['question_id']] = $row['answer'];
 }
@@ -267,7 +267,7 @@ if (!empty($end_of_message) && ($origin == 'learnpath')) {
 $total_weighting = 0;
 foreach ($questionList as $questionId) {
     $objQuestionTmp     = Question::read($questionId);
-    $total_weighting += $objQuestionTmp->selectWeighting();        
+    $total_weighting += $objQuestionTmp->selectWeighting();
 }
 $counter = 1;
 
@@ -276,38 +276,36 @@ $exercise_content = null;
 $media_list = array();
 $category_list = array();
 foreach ($questionList as $questionId) {
-    
+
 	$choice = $exerciseResult[$questionId];
 	// destruction of the Question object
 	unset($objQuestionTmp);
-	
+
 	// creates a temporary Question object
-	$objQuestionTmp = Question::read($questionId);  
-            
+	$objQuestionTmp = Question::read($questionId);
+
 	$questionWeighting	= $objQuestionTmp->selectWeighting();
 	$answerType			= $objQuestionTmp->selectType();
-	
+
 	// Start buffer
     ob_start();
-    
- 
-    
+
     /* Use switch
-    switch ($answerType) {        
-    }*/	
+    switch ($answerType) {
+    }*/
 	if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
-        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());                    
+        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore   = $question_result['score'];
-        $totalScore      += $question_result['score'];        
+        $totalScore      += $question_result['score'];
 	} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType ==  MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
 		$choice = array();
-        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());                               
+        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore   = $question_result['score'];
-        $totalScore     += $question_result['score'];	
-	} elseif ($answerType == UNIQUE_ANSWER || $answerType ==  UNIQUE_ANSWER_NO_OPTION) {	
+        $totalScore     += $question_result['score'];
+	} elseif ($answerType == UNIQUE_ANSWER || $answerType ==  UNIQUE_ANSWER_NO_OPTION) {
         $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore   = $question_result['score'];
-        $totalScore     += $question_result['score'];  
+        $totalScore     += $question_result['score'];
 		echo '</table>';
 	} elseif ($answerType == FILL_IN_BLANKS) {
         $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
@@ -318,8 +316,8 @@ foreach ($questionList as $questionId) {
         $questionScore   = $question_result['score'];
         $totalScore     += $question_result['score'];
 	} elseif ($answerType == FREE_ANSWER) {
-        $answer = $str;     
-        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());            
+        $answer = $str;
+        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore   = $question_result['score'];
         $totalScore     += $question_result['score'];
 	} elseif ($answerType == ORAL_EXPRESSION) {
@@ -327,22 +325,22 @@ foreach ($questionList as $questionId) {
 		$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
 		$questionScore   = $question_result['score'];
 		$totalScore     += $question_result['score'];
-	} elseif ($answerType == MATCHING) {            
-        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());            
+	} elseif ($answerType == MATCHING || $answerType == DRAGGABLE) {
+        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore   = $question_result['score'];
-        $totalScore     += $question_result['score'];		
-	} elseif ($answerType == HOT_SPOT) {	
+        $totalScore     += $question_result['score'];
+	} elseif ($answerType == HOT_SPOT) {
 	    if ($show_results) {
 		    echo '<table width="500" border="0"><tr>
                     <td valign="top" align="center" style="padding-left:0px;" >
                         <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
-		}		
-        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());            
+		}
+        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
         $questionScore  = $question_result['score'];
         $totalScore    += $question_result['score'];
-        
-        if ($show_results) {                
-			echo '</table></td></tr>';            
+
+        if ($show_results) {
+			echo '</table></td></tr>';
 		 	echo '<tr>
 				<td colspan="2">'.
 					'<object type="application/x-shockwave-flash" data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
@@ -353,7 +351,7 @@ foreach ($questionList as $questionId) {
 			</table><br/>';
         }
 	} else if($answerType == HOT_SPOT_DELINEATION) {
-	        
+
         $question_result  = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
 
         $questionScore    = $question_result['score'];
@@ -367,9 +365,9 @@ foreach ($questionList as $questionId) {
         $missing_color    = $question_result['extra']['missing_color'];
         $excess_color     = $question_result['extra']['excess_color'];
 
-        $threadhold1      = $question_result['extra']['threadhold1'];            
+        $threadhold1      = $question_result['extra']['threadhold1'];
         $threadhold2      = $question_result['extra']['threadhold2'];
-        $threadhold3      = $question_result['extra']['threadhold3'];            
+        $threadhold3      = $question_result['extra']['threadhold3'];
 
         if ($show_results) {
             if ($overlap_color) {
@@ -387,7 +385,7 @@ foreach ($questionList as $questionId) {
                 $excess_color='green';
             } else {
                 $excess_color='red';
-            }        	    
+            }
 
             if (!is_numeric($final_overlap)) {
                 $final_overlap = 0;
@@ -402,9 +400,9 @@ foreach ($questionList as $questionId) {
 
             if ($final_excess>100) {
                 $final_excess = 100;
-            }            
+            }
 
-            $table_resume='<table class="data_table">		
+            $table_resume='<table class="data_table">
             <tr class="row_odd" >
             <td></td>
             <td ><b>'.get_lang('Requirements').'</b></td>
@@ -446,33 +444,33 @@ foreach ($questionList as $questionId) {
                 } else {
                     //show if no error
                     //echo 'no error';
-                    $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);	
+                    $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
                     $answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
                 }
-            } 
+            }
 
             echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
-            if ($answerType == HOT_SPOT_DELINEATION) {			
+            if ($answerType == HOT_SPOT_DELINEATION) {
                 if ($organs_at_risk_hit>0) {
-                    $message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';				
+                    $message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
                     $message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
                 } else {
                     $message='<p>'.get_lang('YourDelineation').'</p>';
-                    $message.=$table_resume;	
+                    $message.=$table_resume;
                     $message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
                 }
-                $message.='<p>'.$comment.'</p>';	
-                echo $message;              			
+                $message.='<p>'.$comment.'</p>';
+                echo $message;
             } else {
                 echo '<p>'.$comment.'</p>';
             }
 
-            //showing the score	
+            //showing the score
             $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
             $resfree = Database::query($queryfree);
             $questionScore= Database::result($resfree,0,"marks");
-            $totalScore+=$questionScore;    
-            echo '</table></td></tr>';        		 				 		
+            $totalScore+=$questionScore;
+            echo '</table></td></tr>';
             echo '<tr>
                     <td colspan="2">
                         <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
@@ -490,13 +488,13 @@ foreach ($questionList as $questionId) {
 	        echo '</table>';
 	    }
 	}
-    
+
 	$comnt = null;
-    
-    if ($show_results) {		
-		if ($is_allowedToEdit && $locked == false && !api_is_drh()) {		
+
+    if ($show_results) {
+		if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
 			$name = "fckdiv".$questionId;
-			$marksname = "marksName".$questionId;            
+			$marksname = "marksName".$questionId;
 			if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
 				$url_name = get_lang('EditCommentsAndMarks');
 			} else {
@@ -507,9 +505,9 @@ foreach ($questionList as $questionId) {
 				}
 			}
             echo '<br />';
-            echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));            
+            echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
 			echo '<br />';
-            
+
             echo '<div id="feedback_'.$name.'" style="width:100%">';
 			$comnt = trim(get_comments($id,$questionId));
 			if (empty($comnt)) {
@@ -518,8 +516,8 @@ foreach ($questionList as $questionId) {
 				echo '<div id="question_feedback">'.$comnt.'</div>';
 			}
 			echo '</div>';
-            
-            echo '<div id="'.$name.'" style="display:none">';            
+
+            echo '<div id="'.$name.'" style="display:none">';
 			$arrid[] = $questionId;
 			$feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
 			$feedback_form->addElement('html','<br>');
@@ -529,25 +527,25 @@ foreach ($questionList as $questionId) {
 			$comnt = get_comments($id, $questionId);
 			$default = array('comments_'.$questionId =>  $comnt);
 			$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
-			$feedback_form->addElement('html','<br>');			
+			$feedback_form->addElement('html','<br>');
 			$feedback_form->setDefaults($default);
 			$feedback_form->display();
 			echo '</div>';
-            
+
 		} else {
 			$comnt = get_comments($id, $questionId);
 			echo '<br />';
 			if (!empty($comnt)) {
 				echo '<b>'.get_lang('Feedback').'</b>';
 				echo '<div id="question_feedback">'.$comnt.'</div>';
-			}			
+			}
 		}
-        
+
 		if ($is_allowedToEdit) {
 			if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
 				$marksname = "marksName".$questionId;
                 echo '<div id="'.$marksname.'" style="display:none">';
-                echo '<form name="marksform_'.$questionId.'" method="post" action="">';				
+                echo '<form name="marksform_'.$questionId.'" method="post" action="">';
 				$arrmarks[] = $questionId;
 				echo get_lang("AssignMarks");
 				echo "&nbsp;<select name='marks' id='marks'>";
@@ -556,7 +554,7 @@ foreach ($questionList as $questionId) {
 				}
 				echo '</select>';
 				echo '</form><br/ ></div>';
-                
+
 				if ($questionScore == -1 ) {
 					$questionScore = 0;
 				  	echo Display::return_message(get_lang('notCorrectedYet'));
@@ -570,13 +568,13 @@ foreach ($questionList as $questionId) {
 			if ($questionScore == -1) {
 				 $questionScore = 0;
 			}
-		}    	
+		}
 	}
-    
+
     $my_total_score  = $questionScore;
-	$my_total_weight = $questionWeighting;   
+	$my_total_weight = $questionWeighting;
     $totalWeighting += $questionWeighting;
-	
+
     $category_was_added_for_this_test = false;
 
     if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
@@ -601,41 +599,41 @@ foreach ($questionList as $questionId) {
     if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
         $my_total_score = 0;
     }
-    
-    $score = array();    
-    if ($show_results) {	    
+
+    $score = array();
+    if ($show_results) {
 		$score['result'] = get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);
-        $score['pass']   = $my_total_score >= $my_total_weight ? true : false;		
-        $score['type']   = $answerType;        
+        $score['pass']   = $my_total_score >= $my_total_weight ? true : false;
+        $score['type']   = $answerType;
         $score['score']  = $my_total_score;
-        $score['weight'] = $my_total_weight;    
-        $score['comments'] = isset($comnt) ? $comnt : null;        
+        $score['weight'] = $my_total_weight;
+        $score['comments'] = isset($comnt) ? $comnt : null;
     }
-        
+
 	unset($objAnswerTmp);
 	$i++;
-    
+
     $contents = ob_get_clean();
-    
+
     $question_content = '<div class="question_row">';
-    
+
     $show_media = false;
     if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) {
-        $show_media = true;        
+        $show_media = true;
         $media_list[] = $objQuestionTmp->parent_id;
-    }    
-    
- 	if ($show_results) { 	    
-        //Shows question title an description        
+    }
+
+ 	if ($show_results) {
+        //Shows question title an description
 	    $question_content .= $objQuestionTmp->return_header(null, $counter, $score, $show_media);
-        
+
         // display question category, if any
  	    $question_content .= Testcategory::getCategoryNamesForQuestion($questionId);
 	}
-    
-	$counter++;    
+
+	$counter++;
     $question_content .= $contents;
-    $question_content .= '</div>';   
+    $question_content .= '</div>';
     $exercise_content .= $question_content;
 } // end of large foreach on questions
 
@@ -645,12 +643,12 @@ $total_score_text = null;
 //Total score
 if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
 	if ($show_results || $show_only_total_score ) {
-        
+
         $total_score_text .= '<div class="question_row">';
-        $my_total_score_temp = $totalScore; 
+        $my_total_score_temp = $totalScore;
 	    if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
 	        $my_total_score_temp = 0;
-	    }          
+	    }
         $total_score_text .= get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true);
         $total_score_text .= '</div>';
 	}
@@ -672,18 +670,18 @@ if (is_array($arrid) && is_array($arrmarks)) {
 }
 
 if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
-	if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) {        
-		echo '<form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=2&comments=update&exeid='.$id.'&origin='.$origin.'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';		
+	if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) {
+		echo '<form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=2&comments=update&exeid='.$id.'&origin='.$origin.'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';
 		echo '<input type = "hidden" name="lp_item_id"       value="'.$learnpath_id.'">';
 		echo '<input type = "hidden" name="lp_item_view_id"  value="'.$lp_item_view_id.'">';
 		echo '<input type = "hidden" name="student_id"       value="'.$student_id.'">';
 		echo '<input type = "hidden" name="total_score"      value="'.$totalScore.'"> ';
-		echo '<input type = "hidden" name="my_exe_exo_id"    value="'.$exercise_id.'"> ';					
+		echo '<input type = "hidden" name="my_exe_exo_id"    value="'.$exercise_id.'"> ';
 	} else {
 		echo ' <form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=1&comments=update&exeid='.$id.'" method="post">';
 	}
 	if ($origin !='learnpath' && $origin!='student_progress') {
-        
+
         echo '<label><input type= "checkbox" name="send_notification"> '.get_lang('SendEmail').'</label>';
 		?>
 		<button type="submit" class="btn btn-primary" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
@@ -714,9 +712,9 @@ if ($origin != 'learnpath') {
 		$lp_mode =  $_SESSION['lp_mode'];
 		$url = '../newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
 		$href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
-		echo '<script type="text/javascript">'.$href.'</script>';		
-		
-		//Record the results in the learning path, using the SCORM interface (API)		
+		echo '<script type="text/javascript">'.$href.'</script>';
+
+		//Record the results in the learning path, using the SCORM interface (API)
 		echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
 		echo '</body></html>';
 	} else {

+ 56 - 10
main/exercice/exercise_submit.php

@@ -70,11 +70,63 @@ $htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
 $htmlHeadXtra[]= '
 <script>
 
+// Draggable js script in order to use jsplumb
+var oldPositionArray;
+
+$(function() {
+    $( ".drag_question" ).sortable({
+        revert: true,
+        start: function(e, ui) {
+            // Getting old positions into array before sorting
+            oldPositionArray = $(this).sortable("toArray");
+            ui.item.startPos = ui.item.index();
+        },
+        stop: function( event, ui ) {
+            $(this).data("new_position", $(this).sortable("toArray"))
+            var newPositionArray = $(this).sortable("toArray");
+
+            var oldPosition = ui.item.startPos;
+            var newPosition = ui.item.index();
+
+            /*console.log(oldPositionArray);
+            console.log(newPositionArray);
+            console.log(oldPosition);
+            console.log(newPosition);
+            */
+            var oldId = "window_"+newPositionArray[oldPosition]+"_select";
+            var newId = "window_"+newPositionArray[newPosition]+"_select";
+
+            var counter = 0;
+            $.each(newPositionArray, function(index, value){
+                console.log(index);
+                newIdValue = "window_"+value+"_select";
+                $("#"+newIdValue +" option").filter(function() {
+                    return $(this).val() == counter+1;
+                }).attr("selected", true);
+                counter++;
+            });
+
+            /*console.log(oldId);
+            console.log(newId);
+
+            $("#"+newId +" option").filter(function() {
+                selectedValue = $(this).val() == newPosition + 1;
+                return selectedValue;
+            }).attr("selected", true);
+
+            $("#"+oldId +" option").filter(function() {
+                selectedValue = $(this).val() == oldPosition + 1;
+                return selectedValue;
+            }).attr("selected", true);*/
+        }
+    });
+});
+
+// Matching js script in order to use jsplumb
 var colorDestination = "#316b31";
 var curvinessValue = 0;
 var connectorType = "Straight";
 
-
 ;(function() {
     window.jsPlumbDemo = {
 	    init : function(questionId) {
@@ -114,15 +166,10 @@ var connectorType = "Straight";
                 isTarget:true,
                 dropOptions : exampleDropOptions,
                 beforeDrop:function(params) {
-
                     var connections = jsPlumb.getConnections({source: params.sourceId});
-
                     jsPlumb.select({source:params.sourceId}).each(function(connection) {
-                        console.log(connection.sourceId);
-
                         jsPlumb.detach(connection);
                     });
-                    console.log(params);
                     var selectId = params.sourceId + "_select";
                     var value = params.targetId.split("_")[2];
 
@@ -214,7 +261,6 @@ jsPlumb.ready(function() {
         $(window).resize(function() {
             jsPlumb.repaintEverything();
         });
-
 	}
 });
 
@@ -229,7 +275,6 @@ $(function(){
         $(this).removeClass("highlight_image_default");
         $(this).addClass("highlight_image_selected");
         $(this).find("label").find("input").attr("checked", "checked");
-
     });
 });
 
@@ -1243,10 +1288,11 @@ function render_question($objExercise, $questionId, $attempt_list, $remind_list,
 
     echo '<div id="question_div_'.$questionId.'" class="main_question '.$remind_highlight.'" >';
 
-        //Shows the question + possible answers
+        //Shows the question and possible answers
+
         showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
 
-        //BUtton save and continue
+        //Button save and continue
         switch ($objExercise->type) {
             case ONE_PER_PAGE:
                 $exercise_actions .= $objExercise->show_button($questionId, $current_question);

+ 7 - 6
main/exercice/matching.class.php

@@ -263,12 +263,13 @@ class Matching extends Question
     function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false)
     {
         $header = parent::return_header($feedback_type, $counter, $score, $show_media);
-        $header .= '<table class="'.$this->question_table_class.'">';
-        $header .= '<tr>
-                <th>'.get_lang('ElementList').'</th>
-                <th>'.get_lang('CorrespondsTo').'</th>
-              </tr>';
+        if ($this->type == MATCHING) {
+            $header .= '<table class="'.$this->question_table_class.'">';
+            $header .= '<tr>
+                    <th>'.get_lang('ElementList').'</th>
+                    <th>'.get_lang('CorrespondsTo').'</th>
+                  </tr>';
+        }
         return $header;
     }
-
 }

+ 2 - 2
main/inc/global.inc.php

@@ -780,7 +780,7 @@ if (is_array($language_files)) {
 /* End loading languages */
 
 //error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
-
+error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
 if (api_get_setting('server_type') == 'test') {
     //error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
 } else {
@@ -831,7 +831,7 @@ if (api_get_setting('server_type') == 'test') {
         }*/
 }
 
-error_reporting(-1);
+//error_reporting(-1);
 
 //Silex filters: before|after|finish