Browse Source

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

Yannick Warnier 10 years ago
parent
commit
fda08095ef

+ 9 - 8
composer.lock

@@ -1365,16 +1365,16 @@
         },
         {
             "name": "monolog/monolog",
-            "version": "1.12.0",
+            "version": "1.13.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Seldaek/monolog.git",
-                "reference": "1fbe8c2641f2b163addf49cc5e18f144bec6b19f"
+                "reference": "c41c218e239b50446fd883acb1ecfd4b770caeae"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1fbe8c2641f2b163addf49cc5e18f144bec6b19f",
-                "reference": "1fbe8c2641f2b163addf49cc5e18f144bec6b19f",
+                "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c41c218e239b50446fd883acb1ecfd4b770caeae",
+                "reference": "c41c218e239b50446fd883acb1ecfd4b770caeae",
                 "shasum": ""
             },
             "require": {
@@ -1391,6 +1391,7 @@
                 "phpunit/phpunit": "~4.0",
                 "raven/raven": "~0.5",
                 "ruflin/elastica": "0.90.*",
+                "swiftmailer/swiftmailer": "~5.3",
                 "videlalvaro/php-amqplib": "~2.4"
             },
             "suggest": {
@@ -1407,7 +1408,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.12.x-dev"
+                    "dev-master": "1.13.x-dev"
                 }
             },
             "autoload": {
@@ -1433,19 +1434,19 @@
                 "logging",
                 "psr-3"
             ],
-            "time": "2014-12-29 21:29:35"
+            "time": "2015-03-05 01:12:12"
         },
         {
             "name": "mpdf/mpdf",
             "version": "v5.7.4",
             "source": {
                 "type": "git",
-                "url": "https://github.com/finwe/mpdf.git",
+                "url": "https://github.com/mpdf/mpdf.git",
                 "reference": "f9a374c7ea975ce8c795cec4dfd17ef55addac9c"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/finwe/mpdf/zipball/f9a374c7ea975ce8c795cec4dfd17ef55addac9c",
+                "url": "https://api.github.com/repos/mpdf/mpdf/zipball/f9a374c7ea975ce8c795cec4dfd17ef55addac9c",
                 "reference": "f9a374c7ea975ce8c795cec4dfd17ef55addac9c",
                 "shasum": ""
             },

+ 0 - 4
main/attendance/attendance_list.php

@@ -18,10 +18,6 @@ if (api_is_allowed_to_edit(null, true)) {
     echo '<div class="actions">';
     echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.
         Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).'</a>';
-
-    /*echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_logins">'.
-        Display::return_icon('attendance_list.png',get_lang('Logins'),'',ICON_SIZE_MEDIUM).'</a>';*/
-
     echo '</div>';
 }
 $attendance = new Attendance();

+ 60 - 22
main/coursecopy/classes/CourseRestorer.class.php

@@ -889,7 +889,7 @@ class CourseRestorer
 			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
                 $params = (array)$forum->obj;
                 if ($this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id == -1) {
-                    $cat_id = $this->restore_forum_category($params['forum_category']);
+                    $cat_id = $this->restore_forum_category($params['forum_category'], $sessionId);
                 } else {
                     $cat_id = $this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id;
                 }
@@ -924,7 +924,7 @@ class CourseRestorer
 				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
 					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
 						if ($topic->obj->forum_id == $id) {
-							$this->restore_topic($topic_id, $new_id);
+							$this->restore_topic($topic_id, $new_id, $sessionId);
 							$forum_topics ++;
 						}
 					}
@@ -941,7 +941,7 @@ class CourseRestorer
 	/**
 	 * Restore forum-categories
 	 */
-    public function restore_forum_category($my_id = null)
+    public function restore_forum_category($my_id = null, $sessionId = 0)
     {
 		$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
 		$resources = $this->course->resources;
@@ -964,7 +964,14 @@ class CourseRestorer
                     }
                     $params = (array) $forum_cat->obj;
                     $params['c_id'] = $this->destination_course_id;
-                    $params['cat_comment']    = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['cat_comment'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
+                    $params['cat_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
+                        $params['cat_comment'],
+                        $this->course->code,
+                        $this->course->destination_path,
+                        $this->course->backup_path,
+                        $this->course->info['path']
+                    );
+                    $params['session_id'] = intval($sessionId);
                     unset($params['cat_id']);
                     $params = self::DBUTF8_array($params);
                     $new_id = Database::insert($forum_cat_table, $params);
@@ -980,14 +987,14 @@ class CourseRestorer
 	/**
 	 * Restore a forum-topic
 	 */
-    public function restore_topic($thread_id, $forum_id)
+    public function restore_topic($thread_id, $forum_id, $sessionId = 0)
     {
 		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
 		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
 
         $params = (array)$topic->obj;
         $params = self::DBUTF8_array($params);
-        $params['c_id']     = $this->destination_course_id;
+        $params['c_id'] = $this->destination_course_id;
         $params['forum_id'] = $forum_id;
         $params['thread_poster_id'] = $this->first_teacher_id;
         $params['thread_date'] = api_get_utc_datetime();
@@ -995,19 +1002,31 @@ class CourseRestorer
         $params['thread_last_post'] = 0;
         $params['thread_replies'] = 0;
         $params['thread_views'] = 0;
+        $params['session_id'] = intval($sessionId);
         unset($params['thread_id']);
 
         $new_id = Database::insert($table, $params);
-        api_item_property_update($this->destination_course_info, TOOL_FORUM_THREAD, $new_id, 'ThreadAdded', api_get_user_id(), 0, 0, null, null);
+        api_item_property_update(
+            $this->destination_course_info,
+            TOOL_FORUM_THREAD,
+            $new_id,
+            'ThreadAdded',
+            api_get_user_id(),
+            0,
+            0,
+            null,
+            null,
+            $sessionId
+        );
 
 		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
 
 		$topic_replies = -1;
 
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
+		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
 			if ($post->obj->thread_id == $thread_id) {
 				$topic_replies++;
-				$this->restore_post($post_id, $new_id, $forum_id);
+				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
 			}
 		}
 		return $new_id;
@@ -1017,7 +1036,7 @@ class CourseRestorer
 	 * Restore a forum-post
 	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
 	 */
-    public function restore_post($id, $topic_id, $forum_id)
+    public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
     {
 		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
 		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
@@ -1028,9 +1047,26 @@ class CourseRestorer
         $params['poster_id'] = $this->first_teacher_id;
         $params['post_date'] = api_get_utc_datetime();
         unset($params['post_id']);
-        $params['post_text']    = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['post_text'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
+        $params['post_text'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
+            $params['post_text'],
+            $this->course->code,
+            $this->course->destination_path,
+            $this->course->backup_path,
+            $this->course->info['path']
+        );
         $new_id = Database::insert($table_post, $params);
-        api_item_property_update($this->destination_course_info, TOOL_FORUM_POST, $new_id, 'PostAdded', api_get_user_id(), 0, 0, null, null);
+        api_item_property_update(
+            $this->destination_course_info,
+            TOOL_FORUM_POST,
+            $new_id,
+            'PostAdded',
+            api_get_user_id(),
+            0,
+            0,
+            null,
+            null,
+            $sessionId
+        );
 		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
 		return $new_id;
 	}
@@ -1045,7 +1081,8 @@ class CourseRestorer
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_LINK] as $id => $link) {
 				$cat_id = $this->restore_link_category($link->category_id, $session_id);
-				$sql = "SELECT MAX(display_order) FROM  $link_table WHERE c_id = ".$this->destination_course_id."  AND category_id='" . self::DBUTF8escapestring($cat_id). "'";
+				$sql = "SELECT MAX(display_order) FROM  $link_table
+				        WHERE c_id = ".$this->destination_course_id." AND category_id='" . self::DBUTF8escapestring($cat_id). "'";
 				$result = Database::query($sql);
     			list($max_order) = Database::fetch_array($result);
 
@@ -1055,13 +1092,13 @@ class CourseRestorer
     			}
 
 				$sql = "INSERT INTO ".$link_table." SET
-				            c_id            = ".$this->destination_course_id." ,
-				            url             = '".self::DBUTF8escapestring($link->url)."',
-				            title           = '".self::DBUTF8escapestring($link->title)."',
-				            description     = '".self::DBUTF8escapestring($link->description)."',
-				            category_id     = '".$cat_id."',
-				            on_homepage     = '".$link->on_homepage."',
-				            display_order   = '".($max_order+1)."' $condition_session";
+                        c_id            = ".$this->destination_course_id." ,
+                        url             = '".self::DBUTF8escapestring($link->url)."',
+                        title           = '".self::DBUTF8escapestring($link->title)."',
+                        description     = '".self::DBUTF8escapestring($link->description)."',
+                        category_id     = '".$cat_id."',
+                        on_homepage     = '".$link->on_homepage."',
+                        display_order   = '".($max_order+1)."' $condition_session";
 
 				Database::query($sql);
 				$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id();
@@ -2632,14 +2669,15 @@ class CourseRestorer
                                     api_get_user_id(),
                                     $this->destination_course_info,
                                     0,
-                                    0
+                                    $sessionId
                                 );
                             } else {
                                 $workId = $workData['id'];
                                 updateWork(
                                     $workId,
                                     $obj->params,
-                                    $this->destination_course_info
+                                    $this->destination_course_info,
+                                    $sessionId
                                 );
                                 updatePublicationAssignment(
                                     $workId,

+ 5 - 5
main/gradebook/gradebook_flatview.php

@@ -97,6 +97,11 @@ if (!empty($keyword)) {
 }
 $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
 
+$addparams = array('selectcat' => $cat[0]->get_id());
+if (isset($_GET['search'])) {
+    $addparams['search'] = $keyword;
+}
+
 // Main course category
 $mainCourseCategory = Category::load(
     null,
@@ -237,11 +242,6 @@ if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report')
     }
 }
 
-$addparams = array ('selectcat' => $cat[0]->get_id());
-if (isset($_GET['search'])) {
-    $addparams['search'] = $keyword;
-}
-
 $this_section = SECTION_COURSES;
 
 if (isset($_GET['exportpdf'])) {

+ 94 - 41
main/gradebook/lib/be/category.class.php

@@ -22,25 +22,40 @@ class Category implements GradebookItem
     private $grade_model_id;
     private $generateCertificates;
 
+    /**
+     * Consctructor
+     */
     public function __construct()
     {
     }
 
+    /**
+     * @return int
+     */
     public function get_id()
     {
         return $this->id;
     }
 
+    /**
+     * @return string
+     */
     public function get_name()
     {
         return $this->name;
     }
 
+    /**
+     * @return string
+     */
     public function get_description()
     {
         return $this->description;
     }
 
+    /**
+     * @return int
+     */
     public function get_user_id()
     {
         return $this->user_id;
@@ -249,7 +264,8 @@ class Category implements GradebookItem
      * @param int      $parent_id parent category
      * @param bool     $visible
      * @param int      $session_id (in case we are in a session)
-     * @param bool     $order_by Whether to show all "session" categories (true) or hide them (false) in case there is no session id
+     * @param bool     $order_by Whether to show all "session"
+     * categories (true) or hide them (false) in case there is no session id
      */
     public static function load(
         $id = null,
@@ -522,7 +538,9 @@ class Category implements GradebookItem
     {
         $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
 
-        $sql = 'UPDATE '.$tbl_grade_categories." SET name = '".Database::escape_string($this->get_name())."'".', description = ';
+        $sql = 'UPDATE '.$tbl_grade_categories." SET
+                name = '".Database::escape_string($this->get_name())."'".',
+                description = ';
         if (isset($this->description)) {
             $sql .= "'".Database::escape_string($this->get_description())."'";
         } else {
@@ -604,7 +622,7 @@ class Category implements GradebookItem
      * Update link weights see #5168
      * @param type $new_weight
      */
-    function update_children_weight($new_weight)
+    public function update_children_weight($new_weight)
     {
         $links = $this->get_links();
         $old_weight = $this->get_weight();
@@ -636,7 +654,8 @@ class Category implements GradebookItem
     public function update_category_delete($course_id)
     {
         $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
-        $sql = 'UPDATE '.$tbl_grade_categories.' SET visible=3 WHERE course_code ="'.Database::escape_string($course_id).'"';
+        $sql = 'UPDATE '.$tbl_grade_categories.' SET visible=3
+                WHERE course_code ="'.Database::escape_string($course_id).'"';
         Database::query($sql);
     }
 
@@ -668,7 +687,9 @@ class Category implements GradebookItem
             return null;
         } else {
             $tbl_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
-            $sql='SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id, generate_certificates FROM '.$tbl_category.' c WHERE c.id='.intval($selectcat);
+            $sql = 'SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id, generate_certificates
+                    FROM '.$tbl_category.' c
+                    WHERE c.id='.intval($selectcat);
             $result       = Database::query($sql);
             $row          = Database::fetch_array($result, 'ASSOC');
 
@@ -727,7 +748,7 @@ class Category implements GradebookItem
      */
     public function is_certificate_available($user_id)
     {
-        $score = $this->calc_score($user_id, $this->course_code);
+        $score = $this->calc_score($user_id, null, $this->course_code);
 
         if (isset($score) && isset($score[0])) {
             // Get a percentage score to compare to minimum certificate score
@@ -760,7 +781,7 @@ class Category implements GradebookItem
      * @return    array (score sum, weight sum)
      *             or null if no scores available
      */
-    public function calc_score($stud_id = null, $course_code = '', $session_id = null)
+    public function calc_score($stud_id = null, $type = null, $course_code = '', $session_id = null)
     {
         // Get appropriate subcategories, evaluations and links
         if (!empty($course_code)) {
@@ -773,22 +794,25 @@ class Category implements GradebookItem
             $links = $this->get_links($stud_id);
         }
 
-        // calculate score
-        $rescount  = 0;
-        $ressum    = 0;
+        // Calculate score
+        $rescount = 0;
+        $ressum = 0;
         $weightsum = 0;
+        $bestResult = 0;
 
         if (!empty($cats)) {
             /** @var Category $cat */
             foreach ($cats as $cat) {
-                $catres = $cat->calc_score($stud_id, $course_code, $session_id);
+                $score = $cat->calc_score($stud_id, $type, $course_code, $session_id);
+
                 if ($cat->get_weight() != 0) {
                     $catweight = $cat->get_weight();
                     $rescount++;
                     $weightsum += $catweight;
                 }
-                if (isset($catres)) {
-                    $ressum += (($catres[0]/$catres[1]) * $catweight);
+                if (isset($score)) {
+                    $ressum += $score[0]/$score[1] * $catweight;
+                    $bestResult += $ressum;
                 }
             }
         }
@@ -796,13 +820,13 @@ class Category implements GradebookItem
         if (!empty($evals)) {
             /** @var Evaluation $eval */
             foreach ($evals as $eval) {
-                $evalres = $eval->calc_score($stud_id);
+                $evalres = $eval->calc_score($stud_id, $type);
 
                 if (isset($evalres) && $eval->get_weight() != 0) {
                     $evalweight = $eval->get_weight();
                     $weightsum += $evalweight;
                     $rescount++;
-                    $ressum += (($evalres[0]/$evalres[1]) * $evalweight);
+                    $ressum += $evalres[0]/$evalres[1] * $evalweight;
                 } else {
                     if ($eval->get_weight() != 0) {
                         $evalweight = $eval->get_weight();
@@ -810,18 +834,25 @@ class Category implements GradebookItem
                     }
                 }
             }
+            if ($type == 'best') {
+                //var_dump($ressum);
+            }
         }
 
         if (!empty($links)) {
+
+            $bestResult = 0;
+            $weight = 0;
+
             /** @var EvalLink|ExerciseLink $link */
-            foreach ($links as $link) {
-                $linkres = $link->calc_score($stud_id);
+           foreach ($links as $link) {
+                $linkres = $link->calc_score($stud_id, $type);
                 if (!empty($linkres) && $link->get_weight() != 0) {
                     $linkweight = $link->get_weight();
                     $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
                     $rescount++;
                     $weightsum += $linkweight;
-                    $ressum += ($linkres[0] / $link_res_denom) * $linkweight;
+                    $ressum += $linkres[0] / $link_res_denom * $linkweight;
                 } else {
                     // Adding if result does not exists
                     if ($link->get_weight() != 0) {
@@ -830,11 +861,21 @@ class Category implements GradebookItem
                     }
                 }
             }
+            if ($type == 'best') {
+                //var_dump($ressum);
+            }
         }
 
         if ($rescount == 0) {
             return null;
         } else {
+            if ($type == 'best') {
+                return array($ressum, $weightsum);
+            }
+            if ($type == 'average') {
+                return array($ressum, $weightsum);
+            }
+
             return array($ressum, $weightsum);
         }
     }
@@ -872,7 +913,7 @@ class Category implements GradebookItem
      * @param string    Course code
      * @param int       Session id
      */
-    public function get_root_categories_for_student ($stud_id, $course_code = null, $session_id = null)
+    public function get_root_categories_for_student($stud_id, $course_code = null, $session_id = null)
     {
         $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
         $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
@@ -1063,7 +1104,7 @@ class Category implements GradebookItem
      */
     private function can_be_moved_to_cat ($cat)
     {
-        return ($cat->get_id() != $this->get_id());
+        return $cat->get_id() != $this->get_id();
     }
 
     /**
@@ -1073,7 +1114,7 @@ class Category implements GradebookItem
      * of all underlying categories and evaluations. All links will
      * be deleted as well !
      */
-    public function move_to_cat ($cat)
+    public function move_to_cat($cat)
     {
         $this->set_parent_id($cat->get_id());
         if ($this->get_course_code() != $cat->get_course_code()) {
@@ -1086,7 +1127,7 @@ class Category implements GradebookItem
     /**
      * Internal function used by move_to_cat()
      */
-    private function apply_course_code_to_children ()
+    private function apply_course_code_to_children()
     {
         $cats = Category::load(null, null, null, $this->id, null);
         $evals = Evaluation::load(null, null, null, $this->id, null);
@@ -1305,11 +1346,12 @@ class Category implements GradebookItem
 
     /**
      * Get appropriate subcategories visible for the user (and optionally the course and session)
-     * @param int      $stud_id student id (default: all students)
-     * @param string   Course code (optional)
-     * @param int      Session ID (optional)
-     *
-     * @return array   Array of subcategories
+     * @param int    $stud_id student id (default: all students)
+     * @param string $course_code Course code (optional)
+     * @param int    $session_id Session ID (optional)
+     * @param bool   $order
+
+     * @return array Array of subcategories
      */
     public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null)
     {
@@ -1374,8 +1416,11 @@ class Category implements GradebookItem
      *
      * @return array
      */
-    public function get_evaluations($stud_id = null, $recursive = false, $course_code = '')
-    {
+    public function get_evaluations(
+        $stud_id = null,
+        $recursive = false,
+        $course_code = ''
+    ) {
         $evals = array();
 
         if (empty($course_code)) {
@@ -1384,14 +1429,14 @@ class Category implements GradebookItem
 
         // 1 student
         if (isset($stud_id) && !empty($stud_id)) {
-            // special case: this is the root
+            // Special case: this is the root
             if ($this->id == 0) {
                 $evals = Evaluation::get_evaluations_with_result_for_student(0, $stud_id);
             } else {
                 $evals = Evaluation::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1);
             }
         } else {
-            // all students
+            // All students
             // course admin
             if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && !api_is_platform_admin()) {
                 // root
@@ -1404,8 +1449,7 @@ class Category implements GradebookItem
                     // course independent
                     $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null);
                 }
-            } elseif (api_is_platform_admin()) {
-                //platform admin
+            } else {
                 $evals = Evaluation::load(null, null, $course_code, $this->id, null);
             }
         }
@@ -1433,8 +1477,12 @@ class Category implements GradebookItem
      *
      * @return array
      */
-    public function get_links($stud_id = null, $recursive = false, $course_code = '', $sessionId = null)
-    {
+    public function get_links(
+        $stud_id = null,
+        $recursive = false,
+        $course_code = '',
+        $sessionId = null
+    ) {
         $links = array();
 
         if (empty($course_code)) {
@@ -1458,8 +1506,9 @@ class Category implements GradebookItem
                 $this->id,
                 api_is_allowed_to_edit() ? null : 1
             );
-        } elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) {
-            // all students -> only for course/platform admin
+            //} elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) {
+        } else {
+            // All students -> only for course/platform admin
             $links = LinkFactory::load(
                 null,
                 null,
@@ -1502,7 +1551,8 @@ class Category implements GradebookItem
     public function getCategories($catId)
     {
         $tblGradeCategories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
-        $sql='SELECT * FROM '.$tblGradeCategories.' WHERE parent_id = '.intval($catId);
+        $sql = 'SELECT * FROM '.$tblGradeCategories.'
+                WHERE parent_id = '.intval($catId);
 
         $result = Database::query($sql);
         $allcats = Category::create_category_objects_from_sql_result($result);
@@ -1561,7 +1611,8 @@ class Category implements GradebookItem
     }
 
     /**
-     * This function, locks a category , only one who can unlock it is the platform administrator.
+     * This function, locks a category , only one who can unlock it is
+     * the platform administrator.
      * @param int locked 1 or unlocked 0
 
      * @return bool
@@ -1569,7 +1620,8 @@ class Category implements GradebookItem
     public function lock($locked)
     {
         $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
-        $sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
+        $sql = "UPDATE $table SET locked = '".intval($locked)."'
+                WHERE id='".intval($this->id)."'";
         Database::query($sql);
     }
 
@@ -1673,7 +1725,8 @@ class Category implements GradebookItem
         $cattotal = Category::load($category_id);
         $scoretotal = $cattotal[0]->calc_score($user_id);
 
-        //Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
+        // Do not remove this the gradebook/lib/fe/gradebooktable.class.php
+        // file load this variable as a global
         $scoredisplay = ScoreDisplay::instance();
         $my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
 

+ 111 - 34
main/gradebook/lib/fe/gradebooktable.class.php

@@ -164,6 +164,11 @@ class GradebookTable extends SortableTable
         $total_categories_weight = 0;
         $scoredisplay = ScoreDisplay :: instance();
 
+        $totalResult = [0, 0];
+        $totalGlobal = [0, 0];
+        $totalBest = [0, 0];
+        $totalAverage = [0, 0];
+
         // Categories.
         foreach ($data_array as $data) {
 
@@ -239,13 +244,15 @@ class GradebookTable extends SortableTable
                 $score = $item->calc_score(api_get_user_id());
 
                 if (!empty($score[1])) {
+                    $categoryScoreArray = $score;
                     $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
                     $score = $score[0]/$score[1]*$item->get_weight();
-
                     $score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
+
                     $categoryScore = $scoredisplay->display_score(array($score, $mainCategoryWeight), SCORE_DIV);
                     $scoreToDisplay = Display::tip($score, $completeScore);
                 } else {
+                    $categoryScoreArray = [0, $item->get_weight()];
                     $scoreToDisplay = '-';
                     $categoryScore = null;
                 }
@@ -256,21 +263,38 @@ class GradebookTable extends SortableTable
                     $best = isset($data['best']) ? $data['best'] : null;
                     $average = isset($data['average']) ? $data['average'] : null;
 
-                    //if (!is_null($value_data)) {
-                        // Student result
-                        $row[] = Display::tag('h4', $value_data);
-                        // Global
-                        $row[] = Display::tag('h4', $categoryScore);
-                        // Best
-                        $row[] = Display::tag('h4', $best);
-                        // Average
-                        $row[] = Display::tag('h4', $average);
-
+                    $totalResult = [
+                        $totalResult[0] + $data['result_score'][0],
+                        $totalResult[1] + $data['result_score'][1],
+                    ];
+
+                    $totalGlobal = [
+                        $totalGlobal[0] +  $categoryScoreArray[0],
+                        $totalGlobal[1] + $categoryScoreArray[1],
+                    ];
+
+                    $totalBest = [
+                        $totalBest[0] + $data['best_score'][0],
+                        $totalBest[1] + $data['best_score'][1],
+                    ];
+
+                    $totalAverage = [
+                        $totalAverage[0] + $data['average_score'][0],
+                        $totalAverage[1] + $data['average_score'][1],
+                    ];
+
+                    // Student result
+                    $row[] = $value_data;
+                    // Global
+                    $row[] = $categoryScore;
+                    // Best
+                    $row[] = $best;
+                    // Average
+                    $row[] = $average;
+
+                    if (get_class($item) == 'Category') {
                         $row[] = $this->build_edit_column($item);
-
-                    /*} else {
-
-                    }*/
+                    }
                 } else {
                     $row[] = $scoreToDisplay;
 
@@ -300,20 +324,20 @@ class GradebookTable extends SortableTable
                     $data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page);
                     $total_weight = 0;
 
-                    //$score = $cats[0]->calc_score(api_get_user_id());
-                    //$categoryScore = $scoredisplay->display_score(array($score, $cats[0]->get_weight()), SCORE_DIV);
-
                     // Links.
                     foreach ($data_array as $data) {
+
                         $row = array();
                         $item = $data[0];
 
                         //if the item is invisible, wrap it in a span with class invisible
-                        $invisibility_span_open  = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
-                        $invisibility_span_close = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '</span>' : '';
+                        $invisibility_span_open = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '<span class="invisible">' : '';
+                        $invisibility_span_close = api_is_allowed_to_edit() && $item->is_visible() == '0' ? '</span>' : '';
 
-                        $main_categories[$parent_id]['children'][$item->get_id()]['name']   = $item->get_name();
-                        $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight();
+                        if (isset($item)) {
+                            $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name();
+                            $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight();
+                        }
 
                         if (api_is_allowed_to_edit(null, true)) {
                             $row[] = $this->build_id_column($item);
@@ -348,16 +372,18 @@ class GradebookTable extends SortableTable
                                 $row[] = $this->build_edit_column($item);
                             }
                         } else {
-                            //students get the results and certificates columns
+                            // Students get the results and certificates columns
                             $eval_n_links = array_merge($alleval, $alllink);
 
-                            if (count($eval_n_links)> 0 && $status_user!=1 ) {
+                            if (count($eval_n_links)> 0 && $status_user != 1) {
                                 $value_data = isset($data[4]) ? $data[4] : null;
+
                                 if (!is_null($value_data)) {
                                     $score = $item->calc_score(api_get_user_id());
                                     $new_score = $data[3] * $score[0] / $score[1];
                                     $new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals')));
-                                    //$row[] = Display::tip($new_score, $data[4]);
+
+                                    // Result
                                     $row[] = $value_data;
 
                                     $best = isset($data['best']) ? $data['best'] : null;
@@ -368,13 +394,14 @@ class GradebookTable extends SortableTable
                                         array($new_score, $cattotal[0]->get_weight()),
                                         SCORE_DIV
                                     );
-                                    $row[] = Display::tag('h4', $categoryScore);
+                                    $row[] = $categoryScore;
                                     // Best
-                                    $row[] = Display::tag('h4', $best);
+                                    $row[] = $best;
                                     // Average
-                                    $row[] = Display::tag('h4', $average);
+                                    $row[] = $average;
                                 }
                             }
+
                             if (!empty($cats)) {
                                 $row[] = null;
                             }
@@ -413,6 +440,7 @@ class GradebookTable extends SortableTable
         } //end looping categories
 
         if (api_is_allowed_to_edit()) {
+            // Total for teacher.
             if (count($main_cat) > 1) {
                 $main_weight = intval($main_cat[0]->get_weight());
 
@@ -421,7 +449,54 @@ class GradebookTable extends SortableTable
                 } else {
                     $total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning');
                 }
-                $row = array(null, null, '<h3>'.get_lang('Total').'</h3>', null, $total);
+                $row = array(
+                    null,
+                    null,
+                    '<h3>' . get_lang('Total') . '</h3>',
+                    null,
+                    $total
+                );
+                $sortable_data[] = $row;
+            }
+        } else {
+            // Total for student.
+            if (count($main_cat) > 1) {
+                $main_weight = intval($main_cat[0]->get_weight());
+
+                $global = null;
+                $average = null;
+
+                $totalResult = $scoredisplay->display_score(
+                    $totalResult,
+                    SCORE_DIV
+                );
+
+                $totalGlobal = $scoredisplay->display_score(
+                    $totalGlobal,
+                    SCORE_DIV
+                );
+
+                $totalBest = $scoredisplay->display_score(
+                    $totalBest,
+                    SCORE_DIV
+                );
+
+                $totalAverage = $scoredisplay->display_score(
+                    $totalAverage,
+                    SCORE_DIV
+                );
+
+                $row = array(
+                    null,
+                    '<h3>' . get_lang('Total') . '</h3>',
+                    null,
+                    $main_weight,
+                    $totalResult,
+                    $totalGlobal,
+                    $totalBest,
+                    $totalAverage,
+                );
+
                 $sortable_data[] = $row;
             }
         }
@@ -430,7 +505,9 @@ class GradebookTable extends SortableTable
         $view = isset($_GET['view']) ? $_GET['view']: null;
         if (api_is_allowed_to_edit()) {
 
-            if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view <> 'presence') {
+            if (isset($_GET['selectcat']) &&
+                $_GET['selectcat'] > 0 && $view <> 'presence'
+            ) {
                 $id_cat = intval($_GET['selectcat']);
                 $category = Category::load($id_cat);
 
@@ -492,7 +569,9 @@ class GradebookTable extends SortableTable
                         $certificate_min_score = intval($certificate_min_scores[$x]);
                         $course_code = $course_codes[$x];
 
-                        if (empty($certificate_min_score) || ($certificate_min_score > $weight_category)) {
+                        if (empty($certificate_min_score) ||
+                            ($certificate_min_score > $weight_category)
+                        ) {
                             $warning_message .= $course_code .'&nbsp;-&nbsp;'.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').'&nbsp;'.$weight_category.'<br />';
                         }
                     }
@@ -558,7 +637,7 @@ class GradebookTable extends SortableTable
      * @param array $attributes
      * @return string
      */
-    private function build_type_column ($item, $attributes = array())
+    private function build_type_column($item, $attributes = array())
     {
         return GradebookUtils::build_type_icon_tag($item->get_icon_name(), $attributes);
     }
@@ -592,11 +671,9 @@ class GradebookTable extends SortableTable
             case 'E' :
                 $cat = new Category();
                 $course_id = CourseManager::get_course_by_category($_GET['selectcat']);
-
                 $show_message = $cat->show_message_resource_delete($course_id);
 
                 // course/platform admin can go to the view_results page
-
                 if (api_is_allowed_to_edit() && $show_message===false) {
                     if ($item->get_type() == 'presence') {
                         return '&nbsp;'

+ 2 - 2
main/gradebook/lib/flatview_data_generator.class.php

@@ -553,12 +553,12 @@ class FlatViewDataGenerator
             $score = $item->calc_score($user_id);
 
             $real_score = $score;
-            $divide = (($score[1])==0 ) ? 1 : $score[1];
+            $divide = isset($score[1]) && !empty($score[1]) ? $score[1] : 1;
 
             // Sub cat weight
             $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
 
-            $item_value = $score[0]/$divide;
+            $item_value = isset($score[0]) ? $score[0]/$divide : 0;
 
             // Fixing total when using one or multiple gradebooks.
             if (empty($parentCategoryIdFilter)) {

+ 55 - 14
main/gradebook/lib/gradebook_data_generator.class.php

@@ -119,28 +119,45 @@ class GradebookDataGenerator
         // Generate the data to display
         $data = array();
         /** @var GradebookItem $item */
+        $totalWeight = 0;
         foreach ($visibleitems as $item) {
-            $row = array ();
+            $row = array();
             $row[] = $item;
             $row[] = $item->get_name();
             // display the 2 first line of description, and all description on mouseover (https://support.chamilo.org/issues/6588)
             $row[] = '<span title="'.api_remove_tags_with_space($item->get_description()).'">'.
                 api_get_short_text_from_html($item->get_description(), 160).'</span>';
+            $totalWeight += $item->get_weight();
             $row[] = $item->get_weight();
             if (count($this->evals_links) > 0) {
                 if (!api_is_allowed_to_edit() || $status_user != 1 ) {
-                    $row[] = $this->build_result_column($item, $ignore_score_color);
-                    $row['best'] = $this->buildBestResultColumn($item);
-                    $row['average'] = $this->buildAverageResultColumn($item);
+                    $row[] = $this->build_result_column($item, $ignore_score_color)['display'];
+                    $row['result_score'] = $this->build_result_column($item, $ignore_score_color)['score'];
+                    $row['best'] = $this->buildBestResultColumn($item)['display'];
+                    $row['best_score'] = $this->buildBestResultColumn($item)['score'];
+                    $row['average'] = $this->buildAverageResultColumn($item)['display'];
+                    $row['average_score'] = $this->buildAverageResultColumn($item)['score'];
                     $row[] = $item;
                 }
             } else {
-                $row[] = $this->build_result_column($item, $ignore_score_color, true);
-                $row['best'] = $this->buildBestResultColumn($item);
-                $row['average'] = $this->buildAverageResultColumn($item);
+                $row[] = $this->build_result_column($item, $ignore_score_color, true)['display'];
+                $row['result_score'] = $this->build_result_column($item, $ignore_score_color)['score'];
+                $row['best'] = $this->buildBestResultColumn($item)['display'];
+                $row['best_score'] = $this->buildBestResultColumn($item)['score'];
+                $row['average'] = $this->buildAverageResultColumn($item)['display'];
+                $row['average_score'] = $this->buildAverageResultColumn($item)['score'];
             }
             $data[] = $row;
         }
+
+        // Total
+        /*$totalRow = [];
+        $totalRow[] = null;
+        $totalRow[] = get_lang('Total');
+        $totalRow[] = null; // Description
+        $totalRow[] = $totalWeight;
+        $data[] = $totalRow;*/
+
         return $data;
     }
 
@@ -161,7 +178,10 @@ class GradebookDataGenerator
 
         $scoreDisplay = ScoreDisplay :: instance();
 
-        return $scoreDisplay->display_score($score, SCORE_DIV);
+        return array(
+            'display' => $scoreDisplay->display_score($score, SCORE_DIV),
+            'score' => $score
+        );
     }
 
     /**
@@ -172,7 +192,11 @@ class GradebookDataGenerator
     {
         $score = $item->calc_score(null, 'average');
         $scoreDisplay = ScoreDisplay :: instance();
-        return $scoreDisplay->display_score($score, SCORE_DIV);
+
+        return array(
+            'display' => $scoreDisplay->display_score($score, SCORE_DIV),
+            'score' => $score
+        );
     }
 
     /**
@@ -195,11 +219,21 @@ class GradebookDataGenerator
                             $displaytype |= SCORE_IGNORE_SPLIT;
                         }
                         if ($forceSimpleResult) {
-                            return $scoredisplay->display_score($score, SCORE_DIV);
+                            return
+                                array(
+                                    'display' => $scoredisplay->display_score($score, SCORE_DIV),
+                                    'score' => $score
+                                );
                         }
-                        return get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype);
+                        return array(
+                            'display' => get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype),
+                            'score' => $score
+                        );
                     } else {
-                        return '';
+                        return array(
+                            'display' => null,
+                            'score' => $score
+                        );
                     }
                     break;
                 // evaluation and link
@@ -209,10 +243,17 @@ class GradebookDataGenerator
                     if ($ignore_score_color) {
                         $displaytype |= SCORE_IGNORE_SPLIT;
                     }*/
-                    return $scoredisplay->display_score($score, SCORE_DIV_PERCENT_WITH_CUSTOM);
+                    return array(
+                        'display' => $scoredisplay->display_score($score, SCORE_DIV),
+                        'score' => $score,
+                    );
             }
         }
-        return null;
+
+        return array(
+            'display' => null,
+            'score' => null
+        );
     }
 
     /**

+ 23 - 9
main/gradebook/lib/scoredisplay.class.php

@@ -3,7 +3,7 @@
 
 /**
  * Class ScoreDisplay
- * Class to display scores according to the settings made by the platform admin.
+ * Display scores according to the settings made by the platform admin.
  * This class works as a singleton: call instance() to retrieve an object.
  * @author Bert Steppé
  * @package chamilo.gradebook
@@ -19,6 +19,7 @@ class ScoreDisplay
 
     /**
      * Get the instance of this class
+     * @param int $category_id
      */
     public static function instance($category_id = 0)
     {
@@ -48,7 +49,6 @@ class ScoreDisplay
             } else {
                 return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1);
             }
-
         }
     }
 
@@ -224,6 +224,10 @@ class ScoreDisplay
         Database::query($sql);
     }
 
+    /**
+     * @param int $category_id
+     * @return bool
+     */
     public function insert_defaults($category_id)
     {
         if (empty($category_id)) {
@@ -252,6 +256,9 @@ class ScoreDisplay
         }
     }
 
+    /**
+     * @return int|null|string
+     */
     public function get_number_decimals()
     {
         $number_decimals = api_get_setting('gradebook_number_decimals');
@@ -284,8 +291,12 @@ class ScoreDisplay
      *
      * @return string
      */
-    public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false)
-    {
+    public function display_score(
+        $score,
+        $type = SCORE_DIV_PERCENT,
+        $what = SCORE_BOTH,
+        $no_color = false
+    ) {
         $my_score = $score == 0 ? 1 : $score;
 
         if ($type == SCORE_BAR) {
@@ -306,8 +317,9 @@ class ScoreDisplay
         }
 
         if ($this->coloring_enabled && $no_color == false) {
-            $my_score_denom = ($score[1]==0)?1:$score[1];
-            if (($score[0] / $my_score_denom) < ($this->color_split_value / 100)) {
+            $my_score_denom = isset($score[1]) && !empty($score[1]) ? $score[1] : 1;
+            $scoreCleaned = isset($score[0]) ? $score[0] : 0;
+            if (($scoreCleaned / $my_score_denom) < ($this->color_split_value / 100)) {
                 $display = Display::tag('font', $display, array('color'=>'red'));
             }
         }
@@ -319,7 +331,7 @@ class ScoreDisplay
      * @param $type
      * @return float|string
      */
-    private function display_default ($score, $type)
+    private function display_default($score, $type)
     {
         switch ($type) {
             case SCORE_DIV :                            // X / Y
@@ -422,7 +434,7 @@ class ScoreDisplay
      * Depends on the teacher's configuration of thresholds. i.e. [0 50] "Bad", [50:100] "Good"
      * @param array $score
      */
-    private function display_custom ($score)
+    private function display_custom($score)
     {
         $my_score_denom= ($score[1]==0) ? 1 : $score[1];
         $scaledscore = $score[0] / $my_score_denom;
@@ -480,7 +492,9 @@ class ScoreDisplay
         } else {
             $category_id = $this->get_current_gradebook_category_id();
         }
-        $sql = 'SELECT * FROM '.$tbl_display.' WHERE category_id = '.$category_id.' ORDER BY score';
+        $sql = 'SELECT * FROM '.$tbl_display.'
+                WHERE category_id = '.$category_id.'
+                ORDER BY score';
         $result = Database::query($sql);
         return Database::store_result($result,'ASSOC');
     }

+ 87 - 13
main/gradebook/lib/user_data_generator.class.php

@@ -146,7 +146,7 @@ class UserDataGenerator
 			$row[] = $this->build_course_name($item);
 			$row[] = $this->build_category_name($item);
 			$row[] = $this->build_average_column($item, $ignore_score_color);
-			$row[] = $this->build_result_column($item, $ignore_score_color);
+			$row[] = $this->build_result_column($item, $ignore_score_color)['display'];
 			if ($scoredisplay->is_custom())
 				$row[] = $this->build_mask_column($item, $ignore_score_color);
 			$data[] = $row;
@@ -154,9 +154,11 @@ class UserDataGenerator
 		return $data;
 	}
 
-	// Sort functions
-	// Make sure to only use functions as defined in the GradebookItem interface !
-
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_type($item1, $item2)
 	{
 		if ($item1->get_item_type() == $item2->get_item_type()) {
@@ -166,6 +168,11 @@ class UserDataGenerator
 		}
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_course($item1, $item2)
 	{
 		$name1 = api_strtolower($this->get_course_name_from_code_cached($item1->get_course_code()));
@@ -173,6 +180,11 @@ class UserDataGenerator
 		return api_strnatcmp($name1, $name2);
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_category($item1, $item2)
 	{
 		$cat1 = $this->get_category_cached($item1->get_category_id());
@@ -182,11 +194,21 @@ class UserDataGenerator
 		return api_strnatcmp($name1, $name2);
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_name($item1, $item2)
 	{
 		return api_strnatcmp($item1->get_name(),$item2->get_name());
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_average($item1, $item2)
 	{
 		$score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()];
@@ -194,6 +216,11 @@ class UserDataGenerator
 		return $this->compare_scores($score1, $score2);
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_score($item1, $item2)
 	{
 		$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()];
@@ -201,6 +228,11 @@ class UserDataGenerator
 		return $this->compare_scores($score1, $score2);
 	}
 
+	/**
+	 * @param $item1
+	 * @param $item2
+	 * @return int
+	 */
 	function sort_by_mask($item1, $item2)
 	{
 		$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()];
@@ -208,7 +240,12 @@ class UserDataGenerator
 		return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2);
 	}
 
-	function compare_scores ($score1, $score2)
+	/**
+	 * @param $score1
+	 * @param $score2
+	 * @return int
+	 */
+	function compare_scores($score1, $score2)
 	{
 		if (!isset($score1)) {
 			return (isset($score2) ? 1 : 0);
@@ -221,19 +258,32 @@ class UserDataGenerator
 		}
 	}
 
-	private function build_course_name ($item)
+	/**
+	 * @param $item
+	 * @return mixed
+	 */
+	private function build_course_name($item)
 	{
 		return $this->get_course_name_from_code_cached($item->get_course_code());
 	}
 
-	private function build_category_name ($item)
+	/**
+	 * @param $item
+	 * @return string
+	 */
+	private function build_category_name($item)
 	{
 		$cat = $this->get_category_cached($item->get_category_id());
 
 		return $this->get_category_name_to_display($cat);
 	}
 
-	private function build_average_column ($item, $ignore_score_color)
+	/**
+	 * @param $item
+	 * @param $ignore_score_color
+	 * @return string
+	 */
+	private function build_average_column($item, $ignore_score_color)
 	{
 		if (isset($this->avgcache)) {
 			$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()];
@@ -249,7 +299,12 @@ class UserDataGenerator
 		return $scoredisplay->display_score($avgscore, $displaytype);
 	}
 
-	private function build_result_column ($item, $ignore_score_color)
+	/**
+	 * @param $item
+	 * @param $ignore_score_color
+	 * @return string
+	 */
+	private function build_result_column($item, $ignore_score_color)
 	{
 		$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()];
 		$scoredisplay = ScoreDisplay :: instance();
@@ -260,6 +315,11 @@ class UserDataGenerator
 		return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT);
 	}
 
+	/**
+	 * @param $item
+	 * @param $ignore_score_color
+	 * @return string
+	 */
 	private function build_mask_column($item, $ignore_score_color)
 	{
 		$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()];
@@ -271,8 +331,12 @@ class UserDataGenerator
 		return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM);
 	}
 
-
-	private function get_course_name_from_code_cached ($coursecode) {
+	/**
+	 * @param $coursecode
+	 * @return mixed
+	 */
+	private function get_course_name_from_code_cached($coursecode)
+	{
 		if (isset ($this->coursecodecache)
 			&& isset ($this->coursecodecache[$coursecode])) {
 			return $this->coursecodecache[$coursecode];
@@ -283,7 +347,12 @@ class UserDataGenerator
 		}
 	}
 
-	private function get_category_cached ($category_id) {
+	/**
+	 * @param $category_id
+	 * @return null
+	 */
+	private function get_category_cached($category_id)
+	{
 		if (isset ($this->categorycache)
 			&& isset ($this->categorycache[$category_id])) {
 			return $this->categorycache[$category_id];
@@ -297,7 +366,12 @@ class UserDataGenerator
 		}
 	}
 
-	private function get_category_name_to_display ($cat) {
+	/**
+	 * @param $cat
+	 * @return string
+	 */
+	private function get_category_name_to_display($cat)
+	{
 		if (isset($cat)) {
 			if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){
 				return '';

+ 22 - 8
main/inc/lib/attendance.lib.php

@@ -182,11 +182,14 @@ class Attendance
 				$actions .= '<center>';
 
 				if (api_is_platform_admin()) {
-					$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
+					$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.
+						Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
 					if ($attendance[5] == 1) {
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
+						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.
+							Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
 					} else {
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_restore&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
+						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_restore&attendance_id='.$attendance[0].$param_gradebook.'">'.
+							Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
 						$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
 					}
 				} else {
@@ -195,8 +198,10 @@ class Attendance
 						$actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
 						$actions .= Display::return_icon('visible.png', get_lang('Hide'));
 					} else {
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
+						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].$param_gradebook.'">'.
+							Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
+						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].$param_gradebook.'">'.
+							Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
 					}
 				}
 
@@ -204,22 +209,31 @@ class Attendance
 				$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
 
 				if ($is_done_all_calendar) {
-					$locked   = $attendance[4];
+					$locked = $attendance[4];
 					if ($locked == 0) {
 						if (api_is_platform_admin()) {
 							$message_alert = get_lang('AreYouSureToLockTheAttendance');
 						} else {
 							$message_alert = get_lang('UnlockMessageInformation');
 						}
-						$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
+						$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.
+							Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
 					} else {
 						if (api_is_platform_admin()) {
-							$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
+							$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].$param_gradebook.'">'.
+								Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
 						} else {
 							$actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
 						}
 					}
 				}
+				/*if (api_is_allowed_to_edit(null, true)) {
+					$message_alert = get_lang('AreYouSureToDelete');
+					$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\'' . $message_alert . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=delete_attendance&attendance_id=' . $attendance[0] . $param_gradebook . '">' .
+						Display::return_icon('delete.png',
+							get_lang('DeleteAttendance')) . '</a>';
+				}*/
+
 				$actions .= '</center>';
 
 				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);

+ 3 - 1
main/install/db_main.sql

@@ -3464,8 +3464,10 @@ CREATE TABLE track_e_attempt_coeff (
 );
 
 -- Course
-
+DROP TABLE IF EXISTS c_student_publication_rel_document;
 CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, document_id INT NOT NULL, c_id INT NOT NULL);
+DROP TABLE IF EXISTS c_student_publication_rel_user;
 CREATE TABLE IF NOT EXISTS c_student_publication_rel_user ( id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, user_id INT NOT NULL, c_id INT NOT NULL);
+DROP TABLE IF EXISTS c_student_publication_comment;
 CREATE TABLE IF NOT EXISTS c_student_publication_comment ( id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, c_id INT NOT NULL, comment text, file VARCHAR(255), user_id int NOT NULL, sent_at datetime NOT NULL);
 

+ 16 - 10
main/newscorm/lp_controller.php

@@ -34,16 +34,22 @@ $language_file[] = 'exercice';
 // Including the global initialization file.
 require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_LEARNPATH;
-if (api_get_setting('show_glossary_in_documents') == 'ismanual' ||
-    api_get_setting('show_glossary_in_documents') == 'isautomatic'
-) {
-    $htmlHeadXtra[] = '<script>
-<!--
-    var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
--->
-</script>';
-    $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
-    $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
+
+$glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
+$showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
+
+if ($showGlossary) {
+    if (api_get_setting('show_glossary_in_documents') == 'ismanual' ||
+        api_get_setting('show_glossary_in_documents') == 'isautomatic'
+    ) {
+        $htmlHeadXtra[] = '<script>
+    <!--
+        var jQueryFrameReadyConfigPath = \'' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.min.js\';
+    -->
+    </script>';
+            $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
+            $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
+    }
 }
 
 $htmlHeadXtra[] = '<script>

+ 13 - 7
main/newscorm/scorm_api.php

@@ -336,14 +336,20 @@ function LMSInitialize() {
             update_toc(olms.lesson_status, olms.lms_item_id);
         }
 
-        <?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?>
-            if (olms.lms_item_type == 'sco') {
+        <?php
+        $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
+        $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
+        if ($showGlossary) {
+            if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
+                ?>
+                if (olms.lms_item_type == 'sco') {
+                    attach_glossary_into_scorm('automatic');
+                } else {
+                    attach_glossary_into_scorm('manual');
+                }
+                <?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
                 attach_glossary_into_scorm('automatic');
-            } else {
-                attach_glossary_into_scorm('manual');
-            }
-            <?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
-            attach_glossary_into_scorm('automatic');
+            <?php } ?>
         <?php } ?>
         return('true');
     }