Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Angel Fernando Quiroz Campos 6 years ago
parent
commit
41fc1c8f0e

+ 3 - 1
app/Resources/public/css/base.css

@@ -24,8 +24,10 @@ body {
     bottom: 0;
     width: 100%;
     /* Set the fixed height of the footer here */
-    height: 60px;
+    height: auto;
     background-color: #f5f5f5;
+    display: inline-flex;
+    padding-bottom: 15px;
 }
 /* Custom page CSS
 -------------------------------------------------- */

+ 5 - 6
main/exercise/exercise_show.php

@@ -328,7 +328,7 @@ $sql = "SELECT attempts.question_id, answer
             questions.id = quizz_rel_questions.question_id AND
             questions.c_id = ".api_get_course_int_id()."
         WHERE
-            attempts.exe_id = ".intval($id)." $user_restriction
+            attempts.exe_id = ".$id." $user_restriction
 		GROUP BY quizz_rel_questions.question_order, attempts.question_id";
 $result = Database::query($sql);
 $question_list_from_database = [];
@@ -735,10 +735,9 @@ foreach ($questionList as $questionId) {
             if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
                 $url_name = get_lang('EditCommentsAndMarks');
             } else {
+                $url_name = get_lang('AddComments');
                 if ($action == 'edit') {
                     $url_name = get_lang('EditIndividualComment');
-                } else {
-                    $url_name = get_lang('AddComments');
                 }
             }
             echo '<p>';
@@ -1011,7 +1010,7 @@ if ($show_results) {
     echo $totalScoreText;
 }
 
-if ($action == 'export') {
+if ($action === 'export') {
     $content = ob_get_clean();
     // needed in order to mpdf to work
     ob_clean();
@@ -1037,8 +1036,8 @@ if ($action == 'export') {
 
 if ($isFeedbackAllowed) {
     if (is_array($arrid) && is_array($arrmarks)) {
-        $strids = implode(",", $arrid);
-        $marksid = implode(",", $arrmarks);
+        $strids = implode(',', $arrid);
+        $marksid = implode(',', $arrmarks);
     }
 }
 

+ 4 - 11
main/exercise/export/aiken/aiken_import.inc.php

@@ -196,13 +196,6 @@ function aiken_import_exercise($file)
             $question->type = constant($type);
             $question->save($exercise);
 
-            if (isset($question_array['code'])) {
-                $result = $question->addCode($question_array['code']);
-                if (empty($result)) {
-                    Display::addFlash(Display::return_message(get_lang('QuestionCodeNotSaved')));
-                }
-            }
-
             $last_question_id = $question->selectId();
             //3. Create answer
             $answer = new Answer($last_question_id);
@@ -307,8 +300,8 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
             $exercise_info['question'][$question_index]['weighting'][$correct_answer_index] = 1;
         } elseif (preg_match('/^SCORE:\s?(.*)/', $info, $matches)) {
             $exercise_info['question'][$question_index]['score'] = (float) $matches[1];
-        } elseif (preg_match('/^CODE:\s?(.*)/', $info, $matches)) {
-            $exercise_info['question'][$question_index]['code'] = $matches[1];
+        } elseif (preg_match('/^DESCRIPTION:\s?(.*)/', $info, $matches)) {
+            $exercise_info['question'][$question_index]['description'] = $matches[1];
         } elseif (preg_match('/^ANSWER_EXPLANATION:\s?(.*)/', $info, $matches)) {
             //Comment of correct answer
             $correct_answer_index = array_search($matches[1], $answers_array);
@@ -350,10 +343,10 @@ function aiken_parse_file(&$exercise_info, $exercisePath, $file, $questionFile)
                 } else {
                     //Question itself (use a 100-chars long title and a larger description)
                     $exercise_info['question'][$question_index]['title'] = trim(substr($info, 0, 100)).'...';
-                    $exercise_info['question'][$question_index]['description'] = $info;
+                    //$exercise_info['question'][$question_index]['description'] = $info;
                 }
             } else {
-                $exercise_info['question'][$question_index]['description'] = $info;
+                //$exercise_info['question'][$question_index]['description'] = $info;
             }
         }
     }

+ 5 - 44
main/exercise/question.class.php

@@ -18,6 +18,7 @@ use Chamilo\CourseBundle\Entity\CQuizAnswer;
 abstract class Question
 {
     public $id;
+    public $iid;
     public $question;
     public $description;
     public $weighting;
@@ -77,6 +78,7 @@ abstract class Question
     public function __construct()
     {
         $this->id = 0;
+        $this->iid = 0;
         $this->question = '';
         $this->description = '';
         $this->weighting = 0;
@@ -155,6 +157,7 @@ abstract class Question
             $objQuestion = self::getInstance($object->type);
             if (!empty($objQuestion)) {
                 $objQuestion->id = (int) $id;
+                $objQuestion->iid = (int) $object->iid;
                 $objQuestion->question = $object->question;
                 $objQuestion->description = $object->description;
                 $objQuestion->weighting = $object->ponderation;
@@ -232,8 +235,8 @@ abstract class Question
     {
         $showQuestionTitleHtml = api_get_configuration_value('save_titles_as_html');
         $title = '';
-        if (!empty($this->code) && api_get_configuration_value('allow_question_code')) {
-            $title .= '<h4>'.$this->code.'</h4>';
+        if (api_get_configuration_value('show_question_id')) {
+            $title .= '<h4>#'.$this->iid.'</h4>';
         }
 
         $title .= $showQuestionTitleHtml ? '' : '<strong>';
@@ -1683,10 +1686,6 @@ abstract class Question
             //$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
         }
 
-        if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
-            $form->addText('code', get_lang('QuestionCode'));
-        }
-
         $form->addElement('html', '</div>');
 
         if (!isset($_GET['fromExercise'])) {
@@ -1726,10 +1725,6 @@ abstract class Question
         $defaults['questionCategory'] = $this->category;
         $defaults['feedback'] = $this->feedback;
 
-        if (api_get_configuration_value('allow_question_code') && api_is_platform_admin()) {
-            $defaults['code'] = $this->code;
-        }
-
         // Came from he question pool
         if (isset($_GET['fromExercise'])) {
             $form->setDefaults($defaults);
@@ -1764,13 +1759,6 @@ abstract class Question
             // modify the exercise
             $exercise->addToList($this->id);
             $exercise->update_question_positions();
-
-            if (api_is_platform_admin()) {
-                $result = $this->addCode($form->getSubmitValue('code'));
-                if (empty($result)) {
-                    Display::addFlash(Display::return_message(get_lang('QuestionCodeNotSaved')));
-                }
-            }
         }
     }
 
@@ -2371,33 +2359,6 @@ abstract class Question
         return $count > 1;
     }
 
-    /**
-     * @param string $code
-     *
-     * @return bool
-     */
-    public function addCode($code)
-    {
-        if (api_get_configuration_value('allow_question_code') && !empty($this->id)) {
-            $code = Database::escape_string($code);
-            $table = Database::get_course_table(TABLE_QUIZ_QUESTION);
-
-            $sql = "SELECT * FROM $table WHERE code = '$code' AND iid <> {$this->id}  ";
-            $result = Database::query($sql);
-            $rows = Database::num_rows($result);
-
-            if (empty($rows)) {
-                $sql = "UPDATE $table SET code = '$code' 
-                        WHERE iid = {$this->id} AND c_id = {$this->course['real_id']}";
-                Database::query($sql);
-
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     /**
      * Resizes a picture || Warning!: can only be called after uploadPicture,
      * or if picture is already available in object.

+ 1 - 2
main/exercise/question_list_admin.inc.php

@@ -15,7 +15,6 @@ use ChamiloSession as Session;
  *    It is included from the script admin.php
  */
 
-
 $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
 
 // deletes a question from the exercise (not from the data base)
@@ -240,7 +239,7 @@ if (!$inATest) {
                     api_get_self().'?'.api_get_cidreq().'&clone_question='.$id,
                     ['class' => 'btn btn-default btn-sm']
                 );
-                $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered())
+                $edit_link = $objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()
                     ? Display::span(
                         Display::return_icon(
                             'edit_na.png',

+ 51 - 12
main/exercise/question_pool.php

@@ -35,6 +35,8 @@ $selected_course = isset($_GET['selected_course']) ? intval($_GET['selected_cour
 $course_id_changed = isset($_GET['course_id_changed']) ? intval($_GET['course_id_changed']) : null;
 // save the id of the previous exercise selected by user to reset menu if we detect that user change course hub 13-10-2011
 $exercise_id_changed = isset($_GET['exercise_id_changed']) ? intval($_GET['exercise_id_changed']) : null;
+$questionId = isset($_GET['question_id']) && !empty($_GET['question_id']) ? (int) $_GET['question_id'] : '';
+$description = isset($_GET['description']) ? Database::escape_string($_GET['description']) : '';
 
 // by default when we go to the page for the first time, we select the current course
 if (!isset($_GET['selected_course']) && !isset($_GET['exerciseId'])) {
@@ -49,12 +51,12 @@ if (empty($objExercise) && !empty($fromExercise)) {
 }
 
 $nameTools = get_lang('QuestionPool');
-$interbreadcrumb[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')];
+$interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
 
 if (!empty($objExercise)) {
     $interbreadcrumb[] = [
-        "url" => "admin.php?exerciseId=".$objExercise->id."&".api_get_cidreq(),
-        "name" => $objExercise->selectTitle(true),
+        'url' => 'admin.php?exerciseId='.$objExercise->id.'&'.api_get_cidreq(),
+        'name' => $objExercise->selectTitle(true),
     ];
 }
 
@@ -71,9 +73,7 @@ if ($is_allowedToEdit) {
         $old_question_obj = Question::read($old_question_id, $origin_course_id);
         $courseId = $current_course['real_id'];
         if ($old_question_obj) {
-            $old_question_obj->updateTitle(
-                $old_question_obj->selectTitle().' - '.get_lang('Copy')
-            );
+            $old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
             //Duplicating the source question, in the current course
             $new_id = $old_question_obj->duplicate($current_course);
             //Reading new question
@@ -97,6 +97,10 @@ if ($is_allowedToEdit) {
 
     // Deletes a question from the database and all exercises
     if ($delete) {
+        $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
+        if ($limitTeacherAccess && !api_is_platform_admin()) {
+            api_not_allowed(true);
+        }
         // Construction of the Question object
         $objQuestionTmp = Question::read($delete);
         // if the question exists
@@ -207,10 +211,9 @@ Display::display_header($nameTools, 'Exercise');
 
 // Menu
 echo '<div class="actions">';
+$url = api_get_self();
 if (isset($type)) {
     $url = api_get_self().'?type=1';
-} else {
-    $url = api_get_self();
 }
 if (isset($fromExercise) && $fromExercise > 0) {
     echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$fromExercise.'">'.
@@ -224,9 +227,9 @@ if (isset($fromExercise) && $fromExercise > 0) {
 }
 echo '</div>';
 
-if ($displayMessage != "") {
+if ($displayMessage != '') {
     echo Display::return_message($displayMessage, 'confirm');
-    $displayMessage = "";
+    $displayMessage = '';
 }
 
 // Form
@@ -417,6 +420,12 @@ $select_answer_html = Display::select(
 );
 
 echo Display::form_row(get_lang('AnswerType'), $select_answer_html);
+echo Display::form_row(get_lang('Id'), Display::input('text', 'question_id', $questionId));
+echo Display::form_row(
+    get_lang('Description'),
+    Display::input('text', 'description', Security::remove_XSS($description))
+);
+
 $button = '<button class="btn btn-primary save" type="submit" name="name" value="'.get_lang('Filter').'">'.get_lang('Filter').'</button>';
 echo Display::form_row('', $button);
 echo "<input type='hidden' id='course_id_changed' name='course_id_changed' value='0' />";
@@ -446,6 +455,15 @@ if ($exerciseId > 0) {
     if (isset($answerType) && $answerType > 0) {
         $where .= ' AND type='.$answerType;
     }
+
+    if (!empty($questionId)) {
+        $where .= ' AND qu.iid='.$questionId;
+    }
+
+    if (!empty($description)) {
+        $where .= " AND qu.description LIKE '%$description%'";
+    }
+
     $sql = "SELECT DISTINCT
                 id,
                 question,
@@ -486,6 +504,14 @@ if ($exerciseId > 0) {
         $answer_where = ' AND type='.$answerType;
     }
 
+    if (!empty($questionId)) {
+        $answer_where .= ' AND q.iid='.$questionId;
+    }
+
+    if (!empty($description)) {
+        $answer_where .= " AND q.description LIKE '%$description%'";
+    }
+
     // @todo fix this query with the new id field
     $sql = " (
                 SELECT q.* FROM $TBL_QUESTIONS q
@@ -548,6 +574,14 @@ if ($exerciseId > 0) {
         $filter .= ' AND qu.type='.$answerType.' ';
     }
 
+    if (!empty($questionId)) {
+        $filter .= ' AND qu.iid='.$questionId;
+    }
+
+    if (!empty($description)) {
+        $filter .= " AND qu.description LIKE '%$description%'";
+    }
+
     if (!empty($session_id) && $session_id != '-1') {
         $mainQuestionList = [];
         if (!empty($course_list)) {
@@ -900,11 +934,16 @@ function get_action_icon_for_question(
     $in_session_id,
     $in_exercise_id
 ) {
+    $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
     $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercise_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
+    $res = '';
     switch ($in_action) {
         case 'delete':
+            if ($limitTeacherAccess && !api_is_platform_admin()) {
+                break;
+            }
             $res = "<a href='".api_get_self()."?".api_get_cidreq().$getParams."&delete=$in_questionid' onclick='return confirm_your_choice()'>";
-            $res .= Display::return_icon("delete.png", get_lang('Delete'));
+            $res .= Display::return_icon('delete.png', get_lang('Delete'));
             $res .= "</a>";
             break;
         case 'edit':
@@ -913,7 +952,7 @@ function get_action_icon_for_question(
                 $from_exercise,
                 $in_questionid,
                 $in_questiontype,
-                Display::return_icon("edit.png", get_lang('Modify')),
+                Display::return_icon('edit.png', get_lang('Modify')),
                 $in_session_id
             );
             break;

+ 2 - 3
main/install/configuration.dist.php

@@ -1072,9 +1072,8 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1,
 // Hide social media links
 //$_configuration['hide_social_media_links'] = false;
 
-// Allow code field in exercise questions
-//ALTER TABLE c_quiz_question ADD COLUMN code VARCHAR(255) NULL DEFAULT NULL;
-// $_configuration['allow_question_code'] = false;
+// Show chamilo unique question id in exercises
+// $_configuration['show_question_id'] = false;
 
 // Show pagination if question list is bigger than "x" value, if 0 pagination will not appear.
 // Option only when building an exercise as a teacher

+ 3 - 3
main/tracking/courseLog.php

@@ -221,6 +221,7 @@ $users_tracking_per_page = '';
 if (isset($_GET['users_tracking_per_page'])) {
     $users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
 }
+
 $actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$addional_param.$users_tracking_per_page.'">
      '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
 $actionsRight .= '</div>';
@@ -338,6 +339,7 @@ $trackingDirection = isset($_GET['users_tracking_direction']) ? $_GET['users_tra
 // Show the charts part only if there are students subscribed to this course/session
 if ($nbStudents > 0) {
     $usersTracking = TrackingCourseLog::get_user_data(null, $nbStudents, $trackingColumn, $trackingDirection, false);
+
     $numberStudentsCompletedLP = 0;
     $averageStudentsTestScore = 0;
     $scoresDistribution = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
@@ -477,9 +479,7 @@ if (count($a_students) > 0) {
     $table = new SortableTable(
         'users_tracking',
         ['TrackingCourseLog', 'get_number_of_users'],
-        function () use ($usersTracking) {
-            return $usersTracking;
-        },
+        ['TrackingCourseLog', 'get_user_data'],
         1
     );