Browse Source

Update from 1.11.x

jmontoyaa 8 years ago
parent
commit
ea24d35f70
34 changed files with 646 additions and 339 deletions
  1. 2 2
      main/admin/teacher_time_report.php
  2. 30 21
      main/forum/forumfunction.inc.php
  3. 12 10
      main/gradebook/lib/GradebookUtils.php
  4. 1 1
      main/gradebook/lib/be/category.class.php
  5. 26 0
      main/inc/ajax/course_home.ajax.php
  6. 4 0
      main/inc/global.inc.php
  7. 42 31
      main/inc/lib/AnnouncementManager.php
  8. 151 146
      main/inc/lib/course.lib.php
  9. 2 2
      main/inc/lib/course_category.lib.php
  10. 18 5
      main/inc/lib/display.lib.php
  11. 5 4
      main/inc/lib/document.lib.php
  12. 38 0
      main/inc/lib/javascript/ckeditor/plugins/inserthtml/dialogs/inserthtml.js
  13. BIN
      main/inc/lib/javascript/ckeditor/plugins/inserthtml/inserthtml.png
  14. 30 0
      main/inc/lib/javascript/ckeditor/plugins/inserthtml/plugin.js
  15. 49 0
      main/inc/lib/javascript/ckeditor/plugins/inserthtml/readme.txt
  16. 39 26
      main/inc/lib/message.lib.php
  17. 10 8
      main/inc/lib/sessionmanager.lib.php
  18. 2 1
      main/inc/lib/template.lib.php
  19. 21 17
      main/inc/lib/tracking.lib.php
  20. 12 13
      main/inc/lib/usermanager.lib.php
  21. 13 39
      main/inc/lib/userportal.lib.php
  22. 3 0
      main/install/configuration.dist.php
  23. 1 1
      main/lp/learnpath.class.php
  24. 3 1
      main/work/work.lib.php
  25. 2 1
      plugin/google_maps/lang/english.php
  26. 2 1
      plugin/google_maps/lang/french.php
  27. 1 0
      plugin/google_maps/lang/spanish.php
  28. 3 1
      plugin/google_maps/src/GoogleMapsPluginPlugin.php
  29. 46 0
      plugin/google_maps/src/map_coordinates.php
  30. 50 0
      plugin/google_maps/view/map_coordinates.tpl
  31. 1 0
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php
  32. 2 2
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php
  33. 0 0
      src/Chamilo/CoreBundle/Resources/public/ckeditor/skins/bootstrapck/dialog.css
  34. 25 6
      user_portal.php

+ 2 - 2
main/admin/teacher_time_report.php

@@ -119,7 +119,7 @@ if (!empty($selectedCourse)) {
     foreach ($sessionsByCourse as $session) {
         $coaches = CourseManager::get_coachs_from_course($session['id'], $course['real_id']);
 
-        if ($coaches) {
+        if (!empty($coaches)) {
             foreach ($coaches as $coach) {
                 $totalTime = UserManager::getTimeSpentInCourses(
                     $coach['user_id'],
@@ -173,7 +173,7 @@ if (!empty($selectedSession)) {
 
         $coaches = CourseManager::get_coachs_from_course($selectedSession, $course['id']);
 
-        if ($coaches) {
+        if (!empty($coaches)) {
             foreach ($coaches as $coach) {
                 $totalTime = UserManager::getTimeSpentInCourses(
                     $coach['user_id'],

+ 30 - 21
main/forum/forumfunction.inc.php

@@ -5036,57 +5036,66 @@ function get_forums_of_group($groupId)
     // Student
     // Select all the forum information of all forums (that are visible to students).
 
-    $sql = "SELECT * FROM $table_forums forum, $table_item_property item_properties
+    $sql = "SELECT * FROM $table_forums forum 
+            INNER JOIN $table_item_property item_properties
+            ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
             WHERE
                 forum.forum_of_group = $groupId AND
                 forum.c_id = $course_id AND
-                item_properties.c_id = $course_id AND
-                forum.forum_id = item_properties.ref AND
+                item_properties.c_id = $course_id AND                
                 item_properties.visibility = 1 AND
                 item_properties.tool = '".TOOL_FORUM."'
             ORDER BY forum.forum_order ASC";
+
     // Select the number of threads of the forums (only the threads that are visible).
-    $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
-            FROM $table_threads threads, $table_item_property item_properties
-            WHERE
-                threads.thread_id = item_properties.ref AND
+    $sql2 = "SELECT 
+                count(thread_id) AS number_of_threads, 
+                threads.forum_id
+            FROM $table_threads threads 
+            INNER JOIN $table_item_property item_properties
+            ON (threads.thread_id = item_properties.ref AND item_properties.c_id = threads.c_id)
+            WHERE                
                 threads.c_id = $course_id AND
                 item_properties.c_id = $course_id AND
                 item_properties.visibility = 1 AND
                 item_properties.tool='".TOOL_FORUM_THREAD."'
             GROUP BY threads.forum_id";
+
     // Select the number of posts of the forum (post that are visible and that are in a thread that is visible).
     $sql3 = "SELECT count(post_id) AS number_of_posts, posts.forum_id
-            FROM $table_posts posts, $table_threads threads, $table_item_property item_properties
-            WHERE posts.visible=1 AND
+            FROM $table_posts posts 
+            INNER JOIN $table_threads threads 
+            ON (posts.thread_id = threads.thread_id AND posts.c_id = threads.c_id)
+            INNER JOIN $table_item_property item_properties
+            ON (threads.thread_id = item_properties.ref AND item_properties.c_id = threads.c_id)
+            WHERE 
+                posts.visible=1 AND
                 posts.c_id = $course_id AND
                 item_properties.c_id = $course_id AND
-                threads.c_id = $course_id
-                AND posts.thread_id=threads.thread_id
-                AND threads.thread_id=item_properties.ref
-                AND item_properties.visibility = 1
-                AND item_properties.tool='".TOOL_FORUM_THREAD."'
+                threads.c_id = $course_id AND 
+                item_properties.visibility = 1 AND 
+                item_properties.tool='".TOOL_FORUM_THREAD."'
             GROUP BY threads.forum_id";
 
     // Course Admin
     if (api_is_allowed_to_edit()) {
         // Select all the forum information of all forums (that are not deleted).
         $sql = "SELECT *
-                FROM $table_forums forum, $table_item_property item_properties
+                FROM $table_forums forum INNER JOIN $table_item_property item_properties
+                ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
                 WHERE
                     forum.forum_of_group = $groupId AND
                     forum.c_id = $course_id AND
-                    item_properties.c_id = $course_id AND
-                    forum.forum_id = item_properties.ref AND
+                    item_properties.c_id = $course_id AND                    
                     item_properties.visibility <> 2 AND
                     item_properties.tool = '".TOOL_FORUM."'
                 ORDER BY forum_order ASC";
 
         // Select the number of threads of the forums (only the threads that are not deleted).
         $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
-                 FROM $table_threads threads, $table_item_property item_properties
+                 FROM $table_threads threads INNER JOIN $table_item_property item_properties
+                 ON (threads.thread_id=item_properties.ref AND item_properties.c_id = threads.c_id)
                  WHERE
-                    threads.thread_id=item_properties.ref AND
                     threads.c_id = $course_id AND
                     item_properties.c_id = $course_id AND
                     item_properties.visibility <> 2 AND
@@ -5097,7 +5106,6 @@ function get_forums_of_group($groupId)
                 FROM $table_posts
                 WHERE c_id = $course_id 
                 GROUP BY forum_id";
-
     }
 
     // Handling all the forum information.
@@ -5384,7 +5392,8 @@ function count_number_of_post_for_user_thread($thread_id, $user_id)
 {
     $table_posts = Database::get_course_table(TABLE_FORUM_POST);
     $course_id = api_get_course_int_id();
-    $sql = "SELECT count(*) as count FROM $table_posts
+    $sql = "SELECT count(iid) as count 
+            FROM $table_posts
             WHERE c_id = $course_id AND
                   thread_id=".intval($thread_id)." AND
                   poster_id = ".intval($user_id)." AND visible = 1 ";

+ 12 - 10
main/gradebook/lib/GradebookUtils.php

@@ -573,19 +573,21 @@ class GradebookUtils
 
     /**
      * register user info about certificate
-     * @param int The category id
-     * @param int The user id
-     * @param float The score obtained for certified
-     * @param Datetime The date when you obtained the certificate
-     * @param integer $cat_id
-     * @param integer $user_id
-     * @param string $date_certificate
+     * @param int $cat_id The category id
+     * @param int $user_id The user id
+     * @param float $score_certificate The score obtained for certified
+     * @param string $date_certificate The date when you obtained the certificate
+     *
      * @return void
      */
-    public static function register_user_info_about_certificate($cat_id, $user_id, $score_certificate, $date_certificate)
-    {
+    public static function registerUserInfoAboutCertificate(
+        $cat_id,
+        $user_id,
+        $score_certificate,
+        $date_certificate
+    ) {
         $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
-        $sql = 'SELECT COUNT(*) as count
+        $sql = 'SELECT COUNT(id) as count
                 FROM ' . $table . ' gc
                 WHERE gc.cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '" ';
         $rs_exist = Database::query($sql);

+ 1 - 1
main/gradebook/lib/be/category.class.php

@@ -1992,7 +1992,7 @@ class Category implements GradebookItem
         );
 
         if (empty($my_certificate)) {
-            GradebookUtils::register_user_info_about_certificate(
+            GradebookUtils::registerUserInfoAboutCertificate(
                 $category_id,
                 $user_id,
                 $my_score_in_gradebook,

+ 26 - 0
main/inc/ajax/course_home.ajax.php

@@ -1,5 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
+
+use ChamiloSession as Session;
+
 // @todo refactor this script, create a class that manage the jqgrid requests
 /**
  * Responses to AJAX calls
@@ -503,8 +506,31 @@ switch ($action) {
         $response->records = $count;
 
         echo json_encode($response);
+        break;
+    case 'get_notification':
+        $courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
+        $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0;
+        $status = isset($_REQUEST['status']) ? (int) $_REQUEST['status'] : 0;
+        if (empty($courseId)) {
+            break;
+        }
+        require_once __DIR__.'/../global.inc.php';
+
+        $courseInfo = api_get_course_info_by_id($courseId);
+        $courseInfo['id_session'] = $sessionId;
+        $courseInfo['status'] = $status;
+
+        $id = 'notification_'.$courseId.'_'.$sessionId.'_'.$status;
+
+        $notificationId = Session::read($id);
+        if ($notificationId) {
+            echo Display::show_notification($courseInfo, false);
+            Session::erase($notificationId);
+        }
+
         break;
     default:
         echo '';
+
 }
 exit;

+ 4 - 0
main/inc/global.inc.php

@@ -287,6 +287,10 @@ if (api_get_setting('server_type') == 'test') {
     ini_set('display_errors', '1');
     ini_set('log_errors', '1');
     error_reporting(-1);
+
+    if (function_exists('opcache_reset')) {
+        opcache_reset();
+    }
 } else {
     error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
 }

+ 42 - 31
main/inc/lib/AnnouncementManager.php

@@ -1608,14 +1608,18 @@ class AnnouncementManager
                 } else {
                     $group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0 OR ip.to_group_id IS NULL)";
                 }
-                $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
-				FROM $tbl_announcement announcement, $tbl_item_property ip
+                $sql = "SELECT 
+                            announcement.*, 
+                            ip.visibility, 
+                            ip.to_group_id, 
+                            ip.insert_user_id
+				FROM $tbl_announcement announcement INNER JOIN $tbl_item_property ip
+				ON (announcement.c_id = ip.c_id AND announcement.id = ip.ref)
 				WHERE
-				    announcement.c_id   = $course_id AND
-                    ip.c_id             = $course_id AND
-                    announcement.id     = ip.ref AND
-                    ip.tool             = 'announcement' AND
-                    ip.visibility       <> '2'
+				    announcement.c_id = $course_id AND
+                    ip.c_id = $course_id AND                    
+                    ip.tool = 'announcement' AND
+                    ip.visibility <> '2'
                     $group_condition
                     $condition_session
 				GROUP BY ip.ref
@@ -1665,18 +1669,19 @@ class AnnouncementManager
                 // his group announcements AND the general announcements
                 if (is_array($group_memberships) && count($group_memberships)>0) {
                     $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
-                    FROM $tbl_announcement announcement, $tbl_item_property ip
-                    WHERE
-                        announcement.c_id = $course_id AND
-                        ip.c_id = $course_id AND
-                        announcement.id = ip.ref AND
-                        ip.tool='announcement'
-                        AND ip.visibility='1'
-                        $cond_user_id
-                        $condition_session
-                    GROUP BY ip.ref
-                    ORDER BY display_order DESC
-                    LIMIT 0, $maximum";
+                            FROM $tbl_announcement announcement 
+                            INNER JOIN $tbl_item_property ip
+                            ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id)
+                            WHERE
+                                announcement.c_id = $course_id AND
+                                ip.c_id = $course_id AND                                
+                                ip.tool='announcement' AND 
+                                ip.visibility='1'
+                                $cond_user_id
+                                $condition_session
+                            GROUP BY ip.ref
+                            ORDER BY display_order DESC
+                            LIMIT 0, $maximum";
                 } else {
                     // the user is not member of any group
                     // this is an identified user => show the general announcements AND his personal announcements
@@ -1690,13 +1695,14 @@ class AnnouncementManager
                             $cond_user_id = " AND ( ip.to_user_id='".$userId."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL) ";
                         }
                         $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
-                            FROM $tbl_announcement announcement, $tbl_item_property ip
+                            FROM $tbl_announcement announcement 
+                            INNER JOIN $tbl_item_property ip
+                            ON (announcement.c_id = ip.c_id AND announcement.id = ip.ref)
                             WHERE
                                 announcement.c_id = $course_id AND
-                                ip.c_id = $course_id AND
-                                announcement.id = ip.ref
-                                AND ip.tool='announcement'
-                                AND ip.visibility='1'
+                                ip.c_id = $course_id AND 
+                                ip.tool='announcement' AND 
+                                ip.visibility='1'
                                 $cond_user_id
                                 $condition_session
                             GROUP BY ip.ref
@@ -1713,15 +1719,20 @@ class AnnouncementManager
                         }
 
                         // the user is not identiefied => show only the general announcements
-                        $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
-                                FROM $tbl_announcement announcement, $tbl_item_property ip
+                        $sql = "SELECT 
+                                    announcement.*, 
+                                    ip.visibility, 
+                                    ip.to_group_id, 
+                                    ip.insert_user_id
+                                FROM $tbl_announcement announcement 
+                                INNER JOIN $tbl_item_property ip
+                                ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id)
                                 WHERE
                                     announcement.c_id = $course_id AND
-                                    ip.c_id = $course_id AND
-                                    announcement.id = ip.ref
-                                    AND ip.tool='announcement'
-                                    AND ip.visibility='1'
-                                    AND ip.to_group_id='0'
+                                    ip.c_id = $course_id AND 
+                                    ip.tool='announcement' AND 
+                                    ip.visibility='1' AND 
+                                    ip.to_group_id='0'
                                     $condition_session
                                 GROUP BY ip.ref
                                 ORDER BY display_order DESC

+ 151 - 146
main/inc/lib/course.lib.php

@@ -298,12 +298,12 @@ class CourseManager
 
     /**
      * Returns the status of a user in a course, which is COURSEMANAGER or STUDENT.
-     * @param   int $user_id
+     * @param   int $userId
      * @param   int $courseId
      *
      * @return int|bool the status of the user in that course (or false if the user is not in that course)
      */
-    public static function getUserInCourseStatus($user_id, $courseId)
+    public static function getUserInCourseStatus($userId, $courseId)
     {
         $courseId = (int) $courseId;
         if (empty($courseId)) {
@@ -315,7 +315,7 @@ class CourseManager
                 "SELECT status FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
                 WHERE
                     c_id  = $courseId AND
-                    user_id = " . intval($user_id)
+                    user_id = " . intval($userId)
             )
         );
 
@@ -1717,7 +1717,8 @@ class CourseManager
         $courseInfo = api_get_course_info($course_code);
         $courseId = $courseInfo['real_id'];
 
-        $sql = 'SELECT DISTINCT count(*) as count  FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
+        $sql = 'SELECT DISTINCT count(user.id) as count  
+                FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $where = array();
         if (!empty($session_id)) {
             $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' as session_course_user
@@ -1760,8 +1761,8 @@ class CourseManager
 
     /**
      * Get a list of coaches of a course and a session
-     * @param   string  Course code
-     * @param   int     Session ID
+     * @param   string  $course_code
+     * @param   int     $session_id
      * @param   bool $addGeneralCoach
      * @return  array   List of users
      */
@@ -1864,7 +1865,6 @@ class CourseManager
 
         // students subscribed to the course through a session
         if ($with_session) {
-
             $joinSession = "";
             //Session creation date
             if (!empty($date_from) && !empty($date_to)) {
@@ -1937,17 +1937,19 @@ class CourseManager
         return $teachers;
     }
 
-
     /**
      * Return user info array of all teacher-users registered in a course
      * This only returns the users that are registered in this actual course, not linked courses.
      *
      * @param int $courseId
+     * @param bool $loadAvatars
+     *
      * @return array with user id
      */
-    public static function getTeachersFromCourse($courseId)
+    public static function getTeachersFromCourse($courseId, $loadAvatars = true)
     {
         $courseId = (int) $courseId;
+
         if (empty($courseId)) {
             return false;
         }
@@ -1968,18 +1970,23 @@ class CourseManager
         $rs = Database::query($sql);
         $listTeachers = array();
         $teachers = array();
+        $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup';
         while ($teacher = Database::fetch_array($rs)) {
-            $userPicture = UserManager::getUserPicture($teacher['user_id'], USER_IMAGE_SIZE_SMALL);
             $teachers['id'] = $teacher['user_id'];
             $teachers['lastname'] = $teacher['lastname'];
             $teachers['firstname'] = $teacher['firstname'];
             $teachers['email'] = $teacher['email'];
             $teachers['username'] = $teacher['username'];
             $teachers['status'] = $teacher['status'];
-            $teachers['avatar'] = $userPicture;
-            $teachers['url'] = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $teacher['user_id'];
-            $listTeachers[]=$teachers;
+            $teachers['avatar'] = '';
+            if ($loadAvatars) {
+                $userPicture = UserManager::getUserPicture($teacher['user_id'], USER_IMAGE_SIZE_SMALL);
+                $teachers['avatar'] = $userPicture;
+            }
+            $teachers['url'] = $url.'&user_id='. $teacher['user_id'];
+            $listTeachers[] = $teachers;
         }
+
         return $listTeachers;
     }
 
@@ -2020,7 +2027,7 @@ class CourseManager
             }
 
             if (!empty($list)) {
-                if ($orderList === true){
+                if ($orderList === true) {
                     $html .= '<ul class="user-teacher">';
                     foreach ($list as $teacher){
                         $html .= Display::tag('li', Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY) . ' ' . $teacher);
@@ -2058,7 +2065,6 @@ class CourseManager
 
         $tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
         $tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-        $coaches = array();
 
         $sql = "SELECT DISTINCT 
                     u.user_id,
@@ -2074,15 +2080,15 @@ class CourseManager
                     scu.status = 2";
         $rs = Database::query($sql);
 
+        $coaches = array();
         if (Database::num_rows($rs) > 0) {
             while ($row = Database::fetch_array($rs)) {
                 $completeName = api_get_person_name($row['firstname'], $row['lastname']);
                 $coaches[] = $row + ['full_name' => $completeName];
             }
-            return $coaches;
-        } else {
-            return false;
         }
+
+        return $coaches;
     }
 
     /**
@@ -2094,17 +2100,16 @@ class CourseManager
      */
     public static function get_coachs_from_course_to_string(
         $session_id = 0,
-        $courseId = null,
+        $courseId = 0,
         $separator = self::USER_SEPARATOR,
         $add_link_to_profile = false,
         $orderList = false
     ) {
-        $coachs_course = self::get_coachs_from_course($session_id, $courseId);
+        $coachList = self::get_coachs_from_course($session_id, $courseId);
         $course_coachs = array();
-        $html = '';
-        if (is_array($coachs_course)) {
-            foreach ($coachs_course as $coach_course) {
-                $coach_name = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
+        if (!empty($coachList)) {
+            foreach ($coachList as $coach_course) {
+                $coach_name = $coach_course['full_name'];
                 if ($add_link_to_profile) {
                     $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $coach_course['user_id'];
                     $coach_name = Display::url(
@@ -2119,19 +2124,21 @@ class CourseManager
                 $course_coachs[] = $coach_name;
             }
         }
-        $coaches_to_string = null;
 
+        $html = '';
         if (!empty($course_coachs)) {
-            if ($orderList === true){
+            if ($orderList === true) {
                 $html .= '<ul class="user-coachs">';
-                    foreach ($course_coachs as $coachs){
-                        $html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
-                    }
+                foreach ($course_coachs as $coachs) {
+                    $html .= Display::tag(
+                        'li',
+                        Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs
+                    );
+                }
                 $html .= '</ul>';
             } else {
-                $coaches_to_string = array_to_string($course_coachs, $separator);
+                $html = array_to_string($course_coachs, $separator);
             }
-
         }
 
         return $html;
@@ -2148,15 +2155,13 @@ class CourseManager
      */
     public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0)
     {
-        $complete_user_list = array();
-
-        //get users from real course
-        $user_list = self::get_user_list_from_course_code($course_code, $session_id);
-        foreach ($user_list as $this_user) {
-            $complete_user_list[] = $this_user;
+        $list = array();
+        $userList = self::get_user_list_from_course_code($course_code, $session_id);
+        foreach ($userList as $user) {
+            $list[] = $user;
         }
 
-        return $complete_user_list;
+        return $list;
     }
 
     /**
@@ -2397,7 +2402,7 @@ class CourseManager
 
     /**
      * Creates a file called mysql_dump.sql in the course folder
-     * @param $course_code The code of the course
+     * @param string $course_code The code of the course
      * @todo Implementation for single database
      */
     public static function create_database_dump($course_code)
@@ -2630,7 +2635,7 @@ class CourseManager
         $extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
 
         // get course list auto-register
-        $sql = "SELECT DISTINCT(c.code)
+        $sql = "SELECT DISTINCT(c.id)
                 FROM $tbl_course_field_value tcfv
                 INNER JOIN $tbl_course_field tcf
                 ON tcfv.field_id =  tcf.id $join_access_url
@@ -2646,7 +2651,7 @@ class CourseManager
 
         if (Database::num_rows($result) > 0) {
             while ($result_row = Database::fetch_array($result)) {
-                $courseList[] = $result_row['code'];
+                $courseList[] = $result_row['id'];
             }
         }
 
@@ -2657,19 +2662,20 @@ class CourseManager
      * Get the course codes that have been restricted in the catalogue, and if byUserId is set
      * then the courses that the user is allowed or not to see in catalogue
      *
-     * @param boolean allowed Either if the courses have some users that are or are not allowed to see in catalogue
-     * @param boolean byUserId if the courses are or are not allowed to see to the user
+     * @param boolean $allowed Either if the courses have some users that are or are not allowed to see in catalogue
+     * @param boolean $byUserId if the courses are or are not allowed to see to the user
      * @return array Course codes allowed or not to see in catalogue by some user or the user
      */
     public static function getCatalogueCourseList($allowed = true, $byUserId = -1)
     {
         $courseTable = Database:: get_main_table(TABLE_MAIN_COURSE);
         $tblCourseRelUserCatalogue = Database:: get_main_table(TABLE_MAIN_COURSE_CATALOGUE_USER);
-        $visibility = ($allowed?1:0);
+        $visibility = $allowed ? 1 : 0;
 
         // Restriction by user id
         $currentUserRestriction = "";
         if ($byUserId > 0) {
+            $byUserId = (int) $byUserId;
             $currentUserRestriction = " AND tcruc.user_id = $byUserId ";
         }
 
@@ -2732,8 +2738,8 @@ class CourseManager
             $with_special_courses = $without_special_courses = '';
             if (!empty($special_course_list)) {
                 $sc_string = '"' . implode('","', $special_course_list) . '"';
-                $with_special_courses = ' course.code IN (' . $sc_string . ')';
-                $without_special_courses = ' AND course.code NOT IN (' . $sc_string . ')';
+                $with_special_courses = ' course.id IN (' . $sc_string . ')';
+                $without_special_courses = ' AND course.id NOT IN (' . $sc_string . ')';
             }
 
             if (!empty($with_special_courses)) {
@@ -2793,7 +2799,8 @@ class CourseManager
 
     /**
      * Get course ID from a given course directory name
-     * @param   string  Course directory (without any slash)
+     * @param   string  $path Course directory (without any slash)
+     *
      * @return  string  Course code, or false if not found
      */
     public static function get_course_id_from_path($path)
@@ -2831,10 +2838,10 @@ class CourseManager
 
     /**
      * Get emails of tutors to course
-     * @param string Visual code
-     * @param integer $courseId
+     * @param int $courseId
      * @return array List of emails of tutors to course
-     * @author @author Carlos Vargas <carlos.vargas@dokeos.com>, Dokeos Latino
+     *
+     * @author Carlos Vargas <carlos.vargas@dokeos.com>, Dokeos Latino
      * */
     public static function get_emails_of_tutors_to_course($courseId)
     {
@@ -2926,9 +2933,10 @@ class CourseManager
      * Updates course attribute. Note that you need to check that your
      * attribute is valid before you use this function
      *
-     * @param int Course id
-     * @param string Attribute name
-     * @param string Attribute value
+     * @param int $id Course id
+     * @param string $name Attribute name
+     * @param string $value Attribute value
+     *
      * @return Doctrine\DBAL\Driver\Statement|null True if attribute was successfully updated,
      * false if course was not found or attribute name is invalid
      */
@@ -2998,11 +3006,15 @@ class CourseManager
      */
     public static function get_session_category_id_by_session_id($session_id)
     {
+        if (empty($session_id)) {
+            return [];
+        }
+
         $sql = 'SELECT sc.id session_category
                 FROM ' . Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY) . ' sc
                 INNER JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION) . ' s
                 ON sc.id = s.session_category_id 
-                WHERE s.id="' . Database::escape_string($session_id) . '"';
+                WHERE s.id="' . intval($session_id) . '"';
 
         return Database::result(
             Database::query($sql),
@@ -3014,8 +3026,8 @@ class CourseManager
     /**
      * Gets the value of a course extra field. Returns null if it was not found
      *
-     * @param string Name of the extra field
-     * @param string Course code
+     * @param string $variable Name of the extra field
+     * @param string $code Course code
      *
      * @return string Value
      */
@@ -3081,7 +3093,8 @@ class CourseManager
     public static function get_course_category($code)
     {
         $table_categories = Database::get_main_table(TABLE_MAIN_CATEGORY);
-        $sql = "SELECT * FROM $table_categories WHERE code = '$code';";
+        $code = Database::escape_string($code);
+        $sql = "SELECT * FROM $table_categories WHERE code = '$code'";
         return Database::fetch_array(Database::query($sql));
     }
 
@@ -3108,9 +3121,10 @@ class CourseManager
      * @param  string $table   The table of which the rows should be counted
      * @param  int $session_id       optionally count rows by session id
      * @return int $course_id    The number of rows in the given table.
+     *
      * @deprecated
      */
-    public static function count_rows_course_table($table, $session_id = '', $course_id = null)
+    public static function count_rows_course_table($table, $session_id = '', $course_id = 0)
     {
         $condition_session = '';
         if ($session_id !== '') {
@@ -3327,6 +3341,7 @@ class CourseManager
                 $courses[$row['code']] = $row;
             }
         }
+
         return $courses;
     }
 
@@ -3455,6 +3470,7 @@ class CourseManager
         $html .= '<div class="pull-right course-box-actions">' . $params['right_actions'] . '</div>';
         $html .= '</div>';
         $html .= '</div>';
+
         return $html;
     }
 
@@ -3587,8 +3603,8 @@ class CourseManager
      *
      * Special courses are courses that stick on top of the list and are "auto-registerable"
      * in the sense that any user clicking them is registered as a student
-     * @param int       User id
-     * @param bool      Whether to show the document quick-loader or not
+     * @param int       $user_id User id
+     * @param bool      $load_dirs Whether to show the document quick-loader or not
      * @return string
      */
     public static function returnSpecialCourses($user_id, $load_dirs = false)
@@ -3596,12 +3612,10 @@ class CourseManager
         $user_id = intval($user_id);
         $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
         $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
-
         $special_course_list = self::get_special_course_list();
-
         $with_special_courses = '';
         if (!empty($special_course_list)) {
-            $with_special_courses = ' course.code IN ("' . implode('","', $special_course_list) . '")';
+            $with_special_courses = ' AND course.id IN ("' . implode('","', $special_course_list) . '")';
         }
 
         $courseList = [];
@@ -3617,8 +3631,9 @@ class CourseManager
                         course_rel_user.user_id
                     FROM $tbl_course course
                     LEFT JOIN $tbl_course_user course_rel_user
-                    ON course.id = course_rel_user.c_id AND course_rel_user.user_id = '$user_id'
-                    WHERE $with_special_courses group by course.code";
+                    ON (course.id = course_rel_user.c_id) 
+                    WHERE course_rel_user.user_id = '$user_id' $with_special_courses 
+                    GROUP BY course.code";
 
             $rs_special_course = Database::query($sql);
             $number_of_courses = Database::num_rows($rs_special_course);
@@ -3670,7 +3685,7 @@ class CourseManager
                     $params['title'] = $course_info['title'];
                     $params['link'] = $course_info['course_public_url'].'?id_session=0&autoreg=1';
                     if (api_get_setting('display_teacher_in_courselist') === 'true') {
-                        $params['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id']);
+                        $params['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
                     }
 
                     if ($showCustomIcon === 'true') {
@@ -3683,22 +3698,20 @@ class CourseManager
                     }
 
                     $params['is_special_course'] = true;
-
                     $courseList[] = $params;
-
                 }
             }
         }
 
-    return $courseList;
-}
+        return $courseList;
+    }
 
     /**
      * Display courses (without special courses) as several HTML divs
      * of course categories, as class userportal-catalog-item.
      * @uses displayCoursesInCategory() to display the courses themselves
-     * @param int        user id
-     * @param bool      Whether to show the document quick-loader or not
+     * @param int $user_id
+     * @param bool  $load_dirs Whether to show the document quick-loader or not
      * @param integer $user_id
      * @return string
      */
@@ -3713,15 +3726,15 @@ class CourseManager
         $sql = "SELECT id, title FROM $table
                 WHERE user_id = '" . $user_id . "'
                 ORDER BY sort ASC";
+
         $result = Database::query($sql);
         $listItems = [
             'in_category' => [],
             'not_category' => []
         ];
-
         while ($row = Database::fetch_array($result)) {
             // We simply display the title of the category.
-            $courseInCategory = self:: returnCoursesCategories(
+            $courseInCategory = self::returnCoursesCategories(
                 $row['id'],
                 $load_dirs
             );
@@ -3735,7 +3748,8 @@ class CourseManager
         }
 
         // Step 2: We display the course without a user category.
-        $coursesNotCategory = self::returnCoursesWithoutCategories(0, $load_dirs);
+        $coursesNotCategory = self::returnCoursesCategories(0, $load_dirs);
+
         if ($coursesNotCategory) {
             $listItems['not_category'] = $coursesNotCategory;
         }
@@ -3746,8 +3760,8 @@ class CourseManager
     /**
      *  Display courses inside a category (without special courses) as HTML dics of
      *  class userportal-course-item.
-     * @param int      User category id
-     * @param bool      Whether to show the document quick-loader or not
+     * @param int      $user_category_id User category id
+     * @param bool     $load_dirs Whether to show the document quick-loader or not
      * @return string
      */
     public static function returnCoursesCategories($user_category_id, $load_dirs = false)
@@ -3764,25 +3778,18 @@ class CourseManager
 
         $without_special_courses = '';
         if (!empty($special_course_list)) {
-            $without_special_courses = ' AND course.code NOT IN ("' . implode('","', $special_course_list) . '")';
+            $without_special_courses = ' AND course.id NOT IN ("' . implode('","', $special_course_list) . '")';
         }
 
-        //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
         $sql = "SELECT
-                course.id,
-                course.title,
-                course.code,
-                course.subscribe subscr,
-                course.unsubscribe unsubscr,
-                course_rel_user.status status,
-                course_rel_user.sort sort,
-                course_rel_user.user_course_cat user_course_cat
-                FROM $TABLECOURS course,
-                     $TABLECOURSUSER course_rel_user,
-                     $TABLE_ACCESS_URL_REL_COURSE url
+                    course.id,
+                    course_rel_user.status status
+                FROM $TABLECOURS course 
+                INNER JOIN $TABLECOURSUSER course_rel_user
+                ON (course.id = course_rel_user.c_id)
+                INNER JOIN $TABLE_ACCESS_URL_REL_COURSE url
+                ON (url.c_id = course.id)
                 WHERE
-                    course.id = course_rel_user.c_id AND
-                    url.c_id = course.id AND
                     course_rel_user.user_id = '" . $user_id . "' AND
                     course_rel_user.user_course_cat = '" . $user_category_id . "'
                     $without_special_courses ";
@@ -3800,28 +3807,26 @@ class CourseManager
         $courseList = array();
         $showCustomIcon = api_get_setting('course_images_in_courses_list');
         // Browse through all courses.
-        while ($course = Database::fetch_array($result)) {
-            $course_info = api_get_course_info($course['code']);
+        while ($row = Database::fetch_array($result)) {
+            $course_info = api_get_course_info_by_id($row['id']);
             if (isset($course_info['visibility']) &&
                 $course_info['visibility'] == COURSE_VISIBILITY_HIDDEN
             ) {
                 continue;
             }
             $course_info['id_session'] = null;
-            $course_info['status'] = $course['status'];
-
+            $course_info['status'] = $row['status'];
             // For each course, get if there is any notification icon to show
             // (something that would have changed since the user's last visit).
             $showNotification = Display::show_notification($course_info);
             $iconName = basename($course_info['course_image']);
 
+            $params = array();
             if ($showCustomIcon === 'true' && $iconName != 'course.png') {
                 $params['thumbnails'] = $course_info['course_image'];
                 $params['image'] = $course_info['course_image_large'];
             }
 
-            $params = array();
-
             $thumbnails = null;
             $image = null;
 
@@ -3832,12 +3837,12 @@ class CourseManager
                 $image = Display::return_icon('session_default.png', null, null, null,null, true);
             }
 
-            $params['course_id'] = $course['id'];
+            $params['course_id'] = $course_info['real_id'];
             $params['edit_actions'] = '';
             $params['document'] = '';
             if (api_is_platform_admin()) {
-                $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'];
-                if($load_dirs){
+                $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course_info['code'];
+                if ($load_dirs) {
                     $params['document'] = '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview btn btn-default btn-sm" href="javascript:void(0);">'
                                . Display::returnFontAwesomeIcon('folder-open') . '</a>';
                     $params['document'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_0', 'class' => 'document_preview_container'));
@@ -3850,13 +3855,12 @@ class CourseManager
             }
 
             $courseUrl = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/index.php?id_session=0';
-
+            $teachers = [];
             if (api_get_setting('display_teacher_in_courselist') === 'true') {
-                $teachers = CourseManager::getTeachersFromCourse($course_info['real_id']);
+                $teachers = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
             }
 
-            $params['status'] = $course['status'];
-
+            $params['status'] = $row['status'];
             if (api_get_setting('display_coursecode_in_courselist') == 'true') {
                 $params['code_course'] = '(' . $course_info['visual_code'] . ') ';
             }
@@ -3882,6 +3886,7 @@ class CourseManager
     /**
      *  Display courses inside a category (without special courses) as HTML dics of
      *  class userportal-course-item.
+     * @deprecated use self::returnCoursesCategories(0);
      * @param int      User category id
      * @param bool      Whether to show the document quick-loader or not
      * @return string
@@ -3901,25 +3906,24 @@ class CourseManager
 
         $without_special_courses = '';
         if (!empty($special_course_list)) {
-            $without_special_courses = ' AND course.code NOT IN ("' . implode('","', $special_course_list) . '")';
+            $without_special_courses = ' AND course.id NOT IN ("' . implode('","', $special_course_list) . '")';
         }
 
-        //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
         $sql = "SELECT
-                course.id,
-                course.title,
-                course.code,
-                course.subscribe subscr,
-                course.unsubscribe unsubscr,
-                course_rel_user.status status,
-                course_rel_user.sort sort,
-                course_rel_user.user_course_cat user_course_cat
-                FROM $TABLECOURS course,
-                     $TABLECOURSUSER course_rel_user,
-                     $TABLE_ACCESS_URL_REL_COURSE url
+                    course.id,
+                    course.title,
+                    course.code,
+                    course.subscribe subscr,
+                    course.unsubscribe unsubscr,
+                    course_rel_user.status status,
+                    course_rel_user.sort sort,
+                    course_rel_user.user_course_cat user_course_cat
+                FROM $TABLECOURS course 
+                INNER JOIN $TABLECOURSUSER course_rel_user
+                ON (course.id = course_rel_user.c_id)
+                INNER JOIN $TABLE_ACCESS_URL_REL_COURSE url
+                ON (url.c_id = course.id)
                 WHERE
-                    course.id = course_rel_user.c_id AND
-                    url.c_id = course.id AND
                     course_rel_user.user_id = '" . $user_id . "' AND
                     course_rel_user.user_course_cat = '" . $user_category_id . "'
                     $without_special_courses ";
@@ -3935,15 +3939,15 @@ class CourseManager
 
         $showCustomIcon = api_get_setting('course_images_in_courses_list');
         // Browse through all courses.
-        while ($course = Database::fetch_array($result)) {
-            $course_info = api_get_course_info($course['code']);
+        while ($row = Database::fetch_array($result)) {
+            $course_info = api_get_course_info($row['code']);
             if (isset($course_info['visibility']) &&
                 $course_info['visibility'] == COURSE_VISIBILITY_HIDDEN
             ) {
                 continue;
             }
             $course_info['id_session'] = null;
-            $course_info['status'] = $course['status'];
+            $course_info['status'] = $row['status'];
 
             // For each course, get if there is any notification icon to show
             // (something that would have changed since the user's last visit).
@@ -3964,7 +3968,7 @@ class CourseManager
             $params['edit_actions'] = '';
             $params['document'] = '';
             if (api_is_platform_admin()) {
-                $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'];
+                $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course_info['code'];
                 if($load_dirs){
                     $params['document'] = '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview btn btn-default btn-sm" href="javascript:void(0);">'
                                . Display::returnFontAwesomeIcon('folder-open') . '</a>';
@@ -3979,12 +3983,11 @@ class CourseManager
 
             $course_title_url = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/index.php?id_session=0';
 
-            $teachers = '';
-
+            $teachers = [];
             if (api_get_setting('display_teacher_in_courselist') === 'true') {
-                $teachers = CourseManager::getTeachersFromCourse($course_info['real_id']);
+                $teachers = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
             }
-            $params['status'] = $course['status'];
+            $params['status'] = $row['status'];
 
             if (api_get_setting('display_coursecode_in_courselist') == 'true') {
                 $params['code_course'] = '(' . $course_info['visual_code'] . ') ';
@@ -4003,7 +4006,6 @@ class CourseManager
             }
 
             $courseList[] = $params;
-
         }
 
         return $courseList;
@@ -4024,7 +4026,8 @@ class CourseManager
 
         $output = array();
         $table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
-        $sql = "SELECT * FROM $table_category WHERE user_id = '".intval($realUserId)."'";
+        $sql = "SELECT * FROM $table_category 
+                WHERE user_id = '".intval($realUserId)."'";
         $result = Database::query($sql);
         while ($row = Database::fetch_array($result)) {
             $output[$row['id']] = $row['title'];
@@ -4069,7 +4072,7 @@ class CourseManager
      *
      * @param string $value Original course code
      * @param string $variable Original field name
-     * @return int Course id
+     * @return array
      */
     public static function getCourseInfoFromOriginalId($value, $variable)
     {
@@ -4084,7 +4087,7 @@ class CourseManager
             return $courseInfo;
         }
 
-        return 0;
+        return [];
     }
 
     /**
@@ -4119,7 +4122,6 @@ class CourseManager
         $session_accessible = true,
         $load_dirs = false
     ) {
-        $entityManager = Database::getManager();
         $now = date('Y-m-d h:i:s');
         $user_id = api_get_user_id();
         $course_info = api_get_course_info_by_id($course['real_id']);
@@ -4137,7 +4139,7 @@ class CourseManager
         $course_info['status'] = empty($session_id) ? $userInCourseStatus : STUDENT;
         $course_info['id_session'] = $session_id;
 
-        $is_coach = api_is_coach($course_info['id_session'], $course_info['real_id']);
+        $is_coach = api_is_coach($session_id, $course_info['real_id']);
 
         // Display course entry.
         // Show a hyperlink to the course, unless the course is closed and user is not course admin.
@@ -4154,8 +4156,10 @@ class CourseManager
 
         // Display the "what's new" icons
         $notifications = '';
-        if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
-            $notifications .= Display:: show_notification($course_info);
+        if ($course_visibility != COURSE_VISIBILITY_CLOSED &&
+            $course_visibility != COURSE_VISIBILITY_HIDDEN
+        ) {
+            $notifications .= Display::show_notification($course_info);
         }
 
         if ($session_accessible) {
@@ -4230,7 +4234,8 @@ class CourseManager
 
         if (api_get_setting('display_teacher_in_courselist') === 'true') {
             $teacher_list = CourseManager::getTeachersFromCourse(
-                $course_info['real_id']
+                $course_info['real_id'],
+                false
             );
 
             $course_coachs = self::get_coachs_from_course(
@@ -4300,6 +4305,7 @@ class CourseManager
             );
 
             if (api_get_setting('allow_skills_tool') === 'true') {
+                $entityManager = Database::getManager();
                 $objUser = $entityManager->find('ChamiloUserBundle:User', $user_id);
                 $objCourse = $entityManager->find('ChamiloCoreBundle:Course', $course['real_id']);
                 $objSession = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
@@ -4404,7 +4410,7 @@ class CourseManager
             $wanted_code = CourseManager::generate_course_code($wanted_code);
             $table = Database::get_main_table(TABLE_MAIN_COURSE);
             $wanted_code = Database::escape_string($wanted_code);
-            $sql = "SELECT count(*) as count
+            $sql = "SELECT count(id) as count
                     FROM $table
                     WHERE code LIKE '$wanted_code%'";
             $result = Database::query($sql);
@@ -4860,11 +4866,8 @@ class CourseManager
     public static function process_hot_course_item($courses, $my_course_code_list = array())
     {
         $hotCourses = [];
-
         $ajax_url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=add_course_vote';
-
         $stok = Security::get_existing_token();
-
         $user_id = api_get_user_id();
 
         foreach ($courses as $courseId) {
@@ -4881,8 +4884,8 @@ class CourseManager
                 $my_course_code_list
             );
 
-            $user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $course_info['code']);
-            $user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $course_info['code']);
+            $user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $courseCode);
+            $user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $courseCode);
             $user_registerd_in_course_as_student = ($user_registerd_in_course && !$user_registerd_in_course_as_teacher);
 
             // if user registered as student
@@ -4959,13 +4962,14 @@ class CourseManager
                 );
             //}
             /* get_lang('Description') */
-            $my_course['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id']);
+            $my_course['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
             $point_info = self::get_course_ranking($course_info['real_id'], 0);
             $my_course['rating_html'] = Display::return_rating_system('star_' . $course_info['real_id'],
                 $ajax_url . '&course_id=' . $course_info['real_id'], $point_info);
 
             $hotCourses[] = $my_course;
         }
+
         return $hotCourses;
     }
 
@@ -4985,6 +4989,7 @@ class CourseManager
             'all',
             true
         );
+
         return $result;
     }
 
@@ -5094,7 +5099,7 @@ class CourseManager
 
         $withoutSpecialCourses = '';
         if (!empty($specialCourseList)) {
-            $withoutSpecialCourses = ' AND c.code NOT IN ("' . implode('","', $specialCourseList) . '")';
+            $withoutSpecialCourses = ' AND c.id NOT IN ("' . implode('","', $specialCourseList) . '")';
         }
 
         $visibilityCondition = self::getCourseVisibilitySQLCondition('c');
@@ -6029,7 +6034,7 @@ class CourseManager
 
         $without_special_courses = '';
         if (!empty($special_course_list)) {
-            $without_special_courses = ' AND course.code NOT IN ("'.implode('","',$special_course_list).'")';
+            $without_special_courses = ' AND course.id NOT IN ("'.implode('","',$special_course_list).'")';
         }
 
         //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."

+ 2 - 2
main/inc/lib/course_category.lib.php

@@ -595,7 +595,7 @@ class CourseCategory
         $specialCourseList = CourseManager::get_special_course_list();
         $without_special_courses = '';
         if (!empty($specialCourseList)) {
-            $without_special_courses = ' AND course.code NOT IN ("'.implode('","', $specialCourseList).'")';
+            $without_special_courses = ' AND course.id NOT IN ("'.implode('","', $specialCourseList).'")';
         }
 
         $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition('course');
@@ -661,7 +661,7 @@ class CourseCategory
         $specialCourseList = CourseManager::get_special_course_list();
         $without_special_courses = '';
         if (!empty($specialCourseList)) {
-            $without_special_courses = ' AND course.code NOT IN ("'.implode('","', $specialCourseList).'")';
+            $without_special_courses = ' AND course.id NOT IN ("'.implode('","', $specialCourseList).'")';
         }
         $visibilityCondition = CourseManager::getCourseVisibilitySQLCondition("course");
 

+ 18 - 5
main/inc/lib/display.lib.php

@@ -1286,10 +1286,11 @@ class Display
      * if the user never entered the course before, he will not see notification
      * icons. This function takes session ID into account (if any) and only shows
      * the corresponding notifications.
-     * @param array     Course information array, containing at least elements 'db' and 'k'
+     * @param array $course_info Course information array, containing at least elements 'db' and 'k'
+     * @param bool $loadAjax
      * @return string   The HTML link to be shown next to the course
      */
-    public static function show_notification($course_info)
+    public static function show_notification($course_info, $loadAjax = true)
     {
         if (empty($course_info)) {
             return '';
@@ -1301,8 +1302,20 @@ class Display
         $course_code = Database::escape_string($course_info['code']);
 
         $user_id = api_get_user_id();
-        $course_id = intval($course_info['real_id']);
-        $sessionId = intval($course_info['id_session']);
+        $course_id = (int) $course_info['real_id'];
+        $sessionId = (int) $course_info['id_session'];
+        $status = (int) $course_info['status'];
+
+        $loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
+
+        if ($loadNotificationsByAjax) {
+            if ($loadAjax) {
+                $id = 'notification_'.$course_id.'_'.$sessionId.'_'.$status;
+                Session::write($id, true);
+
+                return '<span id ="'.$id.'" class="course_notification"></span>';
+            }
+        }
 
         // Get the user's last access dates to all tools of this course
         $sql = "SELECT *
@@ -1379,7 +1392,7 @@ class Display
                 )
                 // Take only what's visible or "invisible but where the user is a teacher" or where the visibility is unset.
                 && ($item_property['visibility'] == '1'
-                    || ($course_info['status'] == '1' && $item_property['visibility'] == '0')
+                    || ($status == '1' && $item_property['visibility'] == '0')
                     || !isset($item_property['visibility']))
             ) {
                 // Also drop announcements and events that are not for the user or his group.

+ 5 - 4
main/inc/lib/document.lib.php

@@ -609,11 +609,12 @@ class DocumentManager
                 INNER JOIN $TABLE_DOCUMENT AS docs
                 ON (
                     docs.id = last.ref AND
-                    last.tool = '".TOOL_DOCUMENT."' AND
-                    docs.c_id = {$_course['real_id']} AND
-                    last.c_id = {$_course['real_id']}
+                    docs.c_id = last.c_id
                 )
-                WHERE
+                WHERE                                
+                    last.tool = '".TOOL_DOCUMENT."' AND 
+                    docs.c_id = {$_course['real_id']} AND
+                    last.c_id = {$_course['real_id']} AND
                     docs.path LIKE '" . Database::escape_string($path . $added_slash.'%'). "' AND
                     docs.path NOT LIKE '" . Database::escape_string($path . $added_slash.'%/%')."' AND
                     docs.path NOT LIKE '%_DELETED_%' AND

+ 38 - 0
main/inc/lib/javascript/ckeditor/plugins/inserthtml/dialogs/inserthtml.js

@@ -0,0 +1,38 @@
+/*********************************************************************************************************/
+/**
+ * inserthtml plugin for CKEditor 4.x (Author: gpickin ; email: gpickin@gmail.com)
+ * version:	2.0
+ * Released: On 2015-03-10
+ * Download: http://www.github.com/gpickin/ckeditor-inserthtml
+ *
+ *
+ * Modified from original: inserthtml plugin for CKEditor 3.x (Author: Lajox ; Email: lajox@19www.com)
+ * mod-version:	 1.0
+ * mod-Released: On 2009-12-11
+ * mod-Download: http://code.google.com/p/lajox
+ */
+/*********************************************************************************************************/
+
+CKEDITOR.dialog.add('inserthtmlDialog',function(editor){
+	return{
+		title:'Insert HTML',
+		minWidth:380,
+		minHeight:220,
+		contents:[
+			{	id:'info',
+				label:'HTML',
+				elements:[
+				  { type:'textarea',
+				    id:'insertcode_area',
+					label:''
+				  }
+				]
+			}
+		],
+		onOk: function() {
+			var sInsert=this.getValueOf('info','insertcode_area');
+			if ( sInsert.length > 0 )
+			editor.insertHtml(sInsert);
+		}
+	};
+});

BIN
main/inc/lib/javascript/ckeditor/plugins/inserthtml/inserthtml.png


+ 30 - 0
main/inc/lib/javascript/ckeditor/plugins/inserthtml/plugin.js

@@ -0,0 +1,30 @@
+/*********************************************************************************************************/
+/**
+ * inserthtml plugin for CKEditor 4.x (Author: gpickin ; email: gpickin@gmail.com)
+ * version:	2.0
+ * Released: On 2015-03-10
+ * Download: http://www.github.com/gpickin/ckeditor-inserthtml
+ *
+ *
+ * Modified from original: inserthtml plugin for CKEditor 3.x (Author: Lajox ; Email: lajox@19www.com)
+ * mod-version:	 1.0
+ * mod-Released: On 2009-12-11
+ * mod-Download: http://code.google.com/p/lajox
+ */
+/*********************************************************************************************************/
+(function() {
+    CKEDITOR.plugins.add('inserthtml',
+      {
+        init: function( editor ) {
+            editor.addCommand( 'inserthtml', new CKEDITOR.dialogCommand( 'inserthtmlDialog' ) );
+            editor.ui.addButton( 'inserthtml', {
+                label: 'Insert HTML',
+                command: 'inserthtml',
+                toolbar: 'insert',
+                icon : this.path + 'inserthtml.png'
+            });
+
+            CKEDITOR.dialog.add( 'inserthtmlDialog', this.path + 'dialogs/inserthtml.js' );
+        }
+    });
+})();

+ 49 - 0
main/inc/lib/javascript/ckeditor/plugins/inserthtml/readme.txt

@@ -0,0 +1,49 @@
+/*********************************************************************************************************/
+/**
+ * inserthtml plugin for CKEditor 4.x (Author: gpickin ; email: gpickin@gmail.com)
+ * version:	2.0
+ * Released: On 2015-03-10
+ * Download: http://www.github.com/gpickin/ckeditor-inserthtml 
+ *
+ *
+ * Modified from original: inserthtml plugin for CKEditor 3.x (Author: Lajox ; Email: lajox@19www.com)
+ * mod-version:	 1.0
+ * mod-Released: On 2009-12-11
+ * mod-Download: http://code.google.com/p/lajox
+ */
+/*********************************************************************************************************/
+
+/**************************************************************************************************************
+inserthtml plugin for CKEditor 4.x
+
+ --Insert Html Code Plugin
+
+Plugin Description: CKEditor 4.0+ Insert Html Code Plugin 2.0
+
+***************************************************************************************************************/
+
+
+/**************Help Begin***************/
+
+1. Upload inserthtml folder to  ckeditor/plugins/
+
+2. Configured in the ckeditor/config.js :
+    Add to config.toolbar a value 'inserthtml'
+e.g. 
+
+config.toolbar = 
+[
+    [ 'Source', '-', 'Bold', 'Italic', 'inserthtml' ]
+];
+
+
+3. Again Configured in the ckeditor/config.js ,
+   Expand the extra plugin 'inserthtml' such as:
+
+config.extraPlugins='myplugin1,myplugin2,inserthtml';
+
+4. Language Features Removed due to compatibility issues
+
+/**************Help End***************/
+
+

+ 39 - 26
main/inc/lib/message.lib.php

@@ -15,23 +15,24 @@ use Chamilo\UserBundle\Entity\User;
 class MessageManager
 {
     /**
-     * Get the new messages for the current user from the database.
+     * Get count new messages for the current user from the database.
      * @return int
      */
-    public static function get_new_messages()
+    public static function getCountNewMessages()
     {
         $table = Database::get_main_table(TABLE_MESSAGE);
         if (!api_get_user_id()) {
             return false;
         }
-        $sql = "SELECT * FROM $table
+        $sql = "SELECT COUNT(id) as count 
+                FROM $table
                 WHERE
                     user_receiver_id=" . api_get_user_id() . " AND
                     msg_status=" . MESSAGE_STATUS_UNREAD;
         $result = Database::query($sql);
-        $i = Database::num_rows($result);
+        $row = Database::fetch_assoc($result);
 
-        return $i;
+        return $row['count'];
     }
 
     /**
@@ -68,7 +69,7 @@ class MessageManager
             $keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') ";
         }
 
-        $sql = "SELECT COUNT(*) as number_messages
+        $sql = "SELECT COUNT(id) as number_messages
                 FROM $table_message
                 WHERE $condition_msg_status AND
                     user_receiver_id=" . api_get_user_id() . "
@@ -97,8 +98,9 @@ class MessageManager
             $direction = 'DESC';
         } else {
             $column = intval($column);
-            if (!in_array($direction, array('ASC', 'DESC')))
+            if (!in_array($direction, array('ASC', 'DESC'))) {
                 $direction = 'ASC';
+            }
         }
 
         $keyword = Session::read('message_search_keyword');
@@ -110,7 +112,12 @@ class MessageManager
 
         $table_message = Database::get_main_table(TABLE_MESSAGE);
 
-        $sql = "SELECT id as col0, user_sender_id as col1, title as col2, send_date as col3, msg_status as col4
+        $sql = "SELECT 
+                    id as col0, 
+                    user_sender_id as col1, 
+                    title as col2, 
+                    send_date as col3, 
+                    msg_status as col4
                 FROM $table_message
                 WHERE
                   user_receiver_id=" . api_get_user_id() . " AND
@@ -471,7 +478,7 @@ class MessageManager
     /**
      * @param int $user_receiver_id
      * @param int $id
-     * @return bool|resource
+     * @return bool
      */
     public static function delete_message_by_user_receiver($user_receiver_id, $id)
     {
@@ -491,9 +498,9 @@ class MessageManager
             // delete message
             $query = "UPDATE $table_message SET msg_status=3
                       WHERE user_receiver_id=" . $user_receiver_id . " AND id=" . $id;
-            $result = Database::query($query);
+            Database::query($query);
 
-            return $result;
+            return true;
         } else {
             return false;
         }
@@ -502,9 +509,9 @@ class MessageManager
     /**
      * Set status deleted
      * @author Isaac FLores Paz <isaac.flores@dokeos.com>
-     * @param  integer
-     * @param  integer
-     * @return array
+     * @param  int
+     * @param  int
+     * @return bool
      */
     public static function delete_message_by_user_sender($user_sender_id, $id)
     {
@@ -524,11 +531,12 @@ class MessageManager
             // delete attachment file
             self::delete_message_attachment_file($id, $user_sender_id);
             // delete message
-            $sql = "UPDATE $table_message SET msg_status=3
+            $sql = "UPDATE $table_message 
+                    SET msg_status=3
                     WHERE user_sender_id='$user_sender_id' AND id='$id'";
-            $result = Database::query($sql);
+            Database::query($sql);
 
-            return $result;
+            return true;
         }
 
         return false;
@@ -867,7 +875,12 @@ class MessageManager
         }
 
         $sql = "SELECT
-                    id as col0, user_sender_id as col1, title as col2, send_date as col3, user_receiver_id as col4, msg_status as col5
+                    id as col0, 
+                    user_sender_id as col1, 
+                    title as col2, 
+                    send_date as col3, 
+                    user_receiver_id as col4, 
+                    msg_status as col5
                 FROM $table_message
                 WHERE
                     user_sender_id=" . api_get_user_id() . " AND
@@ -931,7 +944,8 @@ class MessageManager
             $keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') ";
         }
 
-        $sql = "SELECT COUNT(*) as number_messages FROM $table_message
+        $sql = "SELECT COUNT(id) as number_messages 
+                FROM $table_message
                 WHERE
                   msg_status=" . MESSAGE_STATUS_OUTBOX . " AND
                   user_sender_id=" . api_get_user_id() . "
@@ -1111,7 +1125,6 @@ class MessageManager
         $query_vars = array('id' => $group_id, 'topics_page_nr' => 0);
 
         if (is_array($rows) && count($rows) > 0) {
-
             // prepare array for topics with its items
             $topics = array();
             $x = 0;
@@ -1339,7 +1352,6 @@ class MessageManager
         $main_content .= '<div class="message">'. $main_message['content'] . $attachment . '</div></div>';
         $main_content .= '</div>';
         $main_content .= '</div>';
-        //$main_content = Security::remove_XSS($main_content, STUDENT, true);
 
         $html .= Display::div(
             Display::div(
@@ -1538,7 +1550,9 @@ class MessageManager
         $tbl_message = Database::get_main_table(TABLE_MESSAGE);
         $message_id = intval($message_id);
         $sql = "SELECT * FROM $tbl_message
-                WHERE id = '$message_id' AND msg_status <> '" . MESSAGE_STATUS_DELETED . "' ";
+                WHERE 
+                    id = '$message_id' AND 
+                    msg_status <> '" . MESSAGE_STATUS_DELETED . "' ";
         $res = Database::query($sql);
         $item = array();
         if (Database::num_rows($res) > 0) {
@@ -1570,7 +1584,7 @@ class MessageManager
     {
         $form = new FormValidator('send_invitation');
         $form->addTextarea('content', get_lang('AddPersonalMessage'), ['id' => 'content_invitation_id', 'rows' => 5]);
-        return $form->return_form();
+        return $form->returnForm();
     }
 
     //@todo this functions should be in the message class
@@ -1754,7 +1768,7 @@ class MessageManager
      * Get the data of the last received messages for a user
      * @param int $userId The user id
      * @param int $lastId The id of the last received message
-     * @return int The count of new messages
+     * @return array
      */
     public static function getMessagesFromLastReceivedMessage($userId, $lastId = 0)
     {
@@ -1768,8 +1782,6 @@ class MessageManager
         $messagesTable = Database::get_main_table(TABLE_MESSAGE);
         $userTable = Database::get_main_table(TABLE_MAIN_USER);
 
-        $messages = array();
-
         $sql = "SELECT m.*, u.user_id, u.lastname, u.firstname
                 FROM $messagesTable as m
                 INNER JOIN $userTable as u
@@ -1782,6 +1794,7 @@ class MessageManager
 
         $result = Database::query($sql);
 
+        $messages = [];
         if ($result !== false) {
             while ($row = Database::fetch_assoc($result)) {
                 $messages[] = $row;

+ 10 - 8
main/inc/lib/sessionmanager.lib.php

@@ -947,17 +947,19 @@ class SessionManager
                     FROM $workTable w
                     LEFT JOIN $workTableAssignment a
                     ON (a.publication_id = w.id AND a.c_id = w.c_id)
-                    WHERE w.c_id = %s
-                    AND parent_id = 0
-                    AND active IN (1, 0)";
+                    WHERE 
+                        w.c_id = %s AND 
+                        parent_id = 0 AND 
+                        active IN (1, 0)";
         } else {
             $sql = "SELECT count(w.id) as count
                     FROM $workTable w
                     LEFT JOIN $workTableAssignment a
                     ON (a.publication_id = w.id AND a.c_id = w.c_id)
-                    WHERE w.c_id = %s
-                    AND parent_id = 0
-                    AND active IN (1, 0)";
+                    WHERE 
+                        w.c_id = %s AND 
+                        parent_id = 0 AND 
+                        active IN (1, 0)";
 
             if (empty($sessionId)) {
                 $sql .= ' AND w.session_id = NULL ';
@@ -3139,6 +3141,7 @@ class SessionManager
      * @param bool $getOnlySessionId
      * @param bool $getSql
      * @param string $orderCondition
+     * @param string $keyword
      * @param string $description
      *
      * @return array sessions
@@ -3265,7 +3268,6 @@ class SessionManager
         }
 
         $whereConditions .= $keywordCondition;
-
         $subQuery = $sessionQuery.$courseSessionQuery;
 
         $sql = " $select FROM $tbl_session s
@@ -3381,7 +3383,7 @@ class SessionManager
         $sql = "SELECT $sqlSelect
                 FROM $tbl_course c
                 INNER JOIN $tbl_session_rel_course src
-                ON c.id = src.c_id
+                ON (c.id = src.c_id)
 		        WHERE src.session_id = '$session_id' ";
 
         if (!empty($course_name)) {

+ 2 - 1
main/inc/lib/template.lib.php

@@ -155,6 +155,7 @@ class Template
         $this->twig->addFilter('img', new Twig_Filter_Function('Template::get_image'));
         $this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
         $this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time'));
+        $this->twig->addFilter('user_info', new Twig_Filter_Function('api_get_user_info'));
 
         /*
           $lexer = new Twig_Lexer($this->twig, array(
@@ -507,7 +508,7 @@ class Template
                 $user_info['is_admin'] = 1;
             }
 
-            $user_info['messages_count'] = MessageManager::get_new_messages();
+            $user_info['messages_count'] = MessageManager::getCountNewMessages();
             $this->user_is_logged_in = true;
         }
         // Setting the $_u array that could be use in any template

+ 21 - 17
main/inc/lib/tracking.lib.php

@@ -2712,9 +2712,9 @@ class Tracking
      * This function does not take the results of a Test out of a LP
      *
      * @param   int|array   Array of user ids or an user id
-     * @param   string      Course code
-     * @param   array       List of LP ids
-     * @param   int         Session id (optional), if param $session_id is null(default)
+     * @param   string      $course_code Course code
+     * @param   array       $lp_ids List of LP ids
+     * @param   int         $session_id Session id (optional), if param $session_id is 0(default)
      * it'll return results including sessions, 0 = session is not filtered
      * @param   bool        Returns an array of the type [sum_score, num_score] if set to true
      * @param   bool        get only the latest attempts or ALL attempts
@@ -2722,9 +2722,9 @@ class Tracking
      */
     public static function getAverageStudentScore(
         $student_id,
-        $course_code = null,
+        $course_code = '',
         $lp_ids = array(),
-        $session_id = null
+        $session_id = 0
     ) {
         if (empty($student_id)) {
             return 0;
@@ -2764,9 +2764,9 @@ class Tracking
         }
 
         $conditionsToString = implode('AND ', $conditions);
-        $sql = "SELECT  SUM(lp_iv.score) sum_score,
-                        SUM(lp_i.max_score) sum_max_score,
-                        count(*) as count
+        $sql = "SELECT  
+                    SUM(lp_iv.score) sum_score,
+                    SUM(lp_i.max_score) sum_max_score
                 FROM $lp_table as lp
                 INNER JOIN $lp_item_table as lp_i
                 ON lp.id = lp_id AND lp.c_id = lp_i.c_id
@@ -2776,7 +2776,7 @@ class Tracking
                 ON lp_i.id = lp_iv.lp_item_id AND lp_view.c_id = lp_iv.c_id AND lp_iv.lp_view_id = lp_view.id
                 WHERE (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') AND
                 $conditionsToString
-                ";
+        ";
         $result = Database::query($sql);
         $row = Database::fetch_array($result, 'ASSOC');
 
@@ -2784,7 +2784,7 @@ class Tracking
             return 0;
         }
 
-        return ($row['sum_score'] / $row['sum_max_score'])*100;
+        return ($row['sum_score'] / $row['sum_max_score']) * 100;
 
     }
 
@@ -3481,8 +3481,9 @@ class Tracking
 
         if (empty($courseCode)) {
             $sql = "SELECT count(poster_id) as count
-                    FROM $tbl_forum_post post INNER JOIN $tbl_forum forum
-                    ON forum.forum_id = post.forum_id
+                    FROM $tbl_forum_post post 
+                    INNER JOIN $tbl_forum forum
+                    ON (forum.forum_id = post.forum_id AND forum.c_id = post.c_id)
                     WHERE $conditionsToString";
 
             $rs = Database::query($sql);
@@ -4017,7 +4018,7 @@ class Tracking
      * BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES
      * @param   int     User Id
      * @param   int     Course Id
-     * @param   int     Session Id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
+     * @param   int     Session Id (optional), if param $session_id is 0 (default) it'll return results including sessions, 0 = session is not filtered
      * @param   string  Date from
      * @param   string  Date to
      * @return  array   Data
@@ -4146,7 +4147,7 @@ class Tracking
      * @param    int        Limit (optional, default = 0, 0 = without limit)
      * @return    array     documents downloaded
      */
-    public static function get_documents_most_downloaded_by_course($course_code, $session_id = null, $limit = 0)
+    public static function get_documents_most_downloaded_by_course($course_code, $session_id = 0, $limit = 0)
     {
         //protect data
         $courseId = api_get_course_int_id($course_code);
@@ -4154,11 +4155,14 @@ class Tracking
 
         $TABLETRACK_DOWNLOADS   = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
         $condition_session = '';
-        if (isset($session_id)) {
-            $session_id = intval($session_id);
+        $session_id = intval($session_id);
+        if (!empty($session_id)) {
             $condition_session = ' AND down_session_id = '. $session_id;
         }
-        $sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
+        $sql = "SELECT 
+                    down_doc_path, 
+                    COUNT(DISTINCT down_user_id), 
+                    COUNT(down_doc_path) as count_down
                 FROM $TABLETRACK_DOWNLOADS
                 WHERE c_id = $courseId
                     $condition_session

+ 12 - 13
main/inc/lib/usermanager.lib.php

@@ -2618,9 +2618,9 @@ class UserManager
                     sc.dateEnd AS session_category_date_end,
                     s.coachAccessStartDate AS coach_access_start_date,
                     s.coachAccessEndDate AS coach_access_end_date
-                FROM ChamiloCoreBundle:Session AS s
+                FROM ChamiloCoreBundle:Session AS s                                
+                INNER JOIN ChamiloCoreBundle:SessionRelCourseRelUser AS scu WITH scu.session = s
                 LEFT JOIN ChamiloCoreBundle:SessionCategory AS sc WITH s.category = sc
-                LEFT JOIN ChamiloCoreBundle:SessionRelCourseRelUser AS scu WITH scu.session = s
                 WHERE scu.user = :user OR s.generalCoach = :user
                 ORDER BY sc.name, s.name";
 
@@ -2994,7 +2994,6 @@ class UserManager
         /* This query is very similar to the query below, but it will check the
         session_rel_course_user table if there are courses registered
         to our user or not */
-
         $sql = "SELECT DISTINCT
                     c.visibility,
                     c.id as real_id,                    
@@ -3041,7 +3040,7 @@ class UserManager
                     WHERE
                       s.id = $session_id AND
                       (
-                        (scu.user_id = $user_id AND scu.status=2) OR
+                        (scu.user_id = $user_id AND scu.status = 2) OR
                         s.id_coach = $user_id
                       )
                     $where_access_url
@@ -3060,12 +3059,12 @@ class UserManager
         }
 
         if (api_is_drh()) {
-            $session_list = SessionManager::get_sessions_followed_by_drh($user_id);
-            $session_list = array_keys($session_list);
-            if (in_array($session_id, $session_list)) {
-                $course_list = SessionManager::get_course_list_by_session_id($session_id);
-                if (!empty($course_list)) {
-                    foreach ($course_list as $course) {
+            $sessionList = SessionManager::get_sessions_followed_by_drh($user_id);
+            $sessionList = array_keys($sessionList);
+            if (in_array($session_id, $sessionList)) {
+                $courseList = SessionManager::get_course_list_by_session_id($session_id);
+                if (!empty($courseList)) {
+                    foreach ($courseList as $course) {
                         if (!in_array($course['id'], $courses)) {
                             $personal_course_list[] = $course;
                         }
@@ -3076,9 +3075,9 @@ class UserManager
             //check if user is general coach for this session
             $sessionInfo = api_get_session_info($session_id);
             if ($sessionInfo['id_coach'] == $user_id) {
-                $course_list = SessionManager::get_course_list_by_session_id($session_id);
-                if (!empty($course_list)) {
-                    foreach ($course_list as $course) {
+                $courseList = SessionManager::get_course_list_by_session_id($session_id);
+                if (!empty($courseList)) {
+                    foreach ($courseList as $course) {
                         if (!in_array($course['id'], $courses)) {
                             $personal_course_list[] = $course;
                         }

+ 13 - 39
main/inc/lib/userportal.lib.php

@@ -912,7 +912,7 @@ class IndexManager
         //  @todo Add a platform setting to add the user image.
         if (api_get_setting('allow_message_tool') == 'true') {
             // New messages.
-            $number_of_new_messages = MessageManager::get_new_messages();
+            $number_of_new_messages = MessageManager::getCountNewMessages();
             // New contact invitations.
             $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
 
@@ -1105,7 +1105,7 @@ class IndexManager
      */
     public function returnCoursesAndSessions($user_id)
     {
-        $gamificationModeIsActive = api_get_setting('gamification_mode');
+        $gameModeIsActive = api_get_setting('gamification_mode');
         $listCourse = '';
         $specialCourseList = '';
         $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
@@ -1123,20 +1123,9 @@ class IndexManager
             $session_categories = UserManager::get_sessions_by_category($user_id, false);
         }
 
-        $html = '';
-        // Showing history title
-        if ($load_history) {
-            $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
-            if (empty($session_categories)) {
-                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
-            }
-        }
-
         $sessionCount = 0;
         $courseCount = 0;
 
-        $template = new Template(null, false, false, false, false, false, false);
-
         // If we're not in the history view...
         if (!isset($_GET['history'])) {
             // Display special courses.
@@ -1157,21 +1146,21 @@ class IndexManager
             }
 
             if ($specialCourses) {
-                $template->assign('courses', $specialCourses);
+                $this->tpl->assign('courses', $specialCourses);
 
-                $specialCourseList = $template->fetch(
+                $specialCourseList = $this->tpl->fetch(
                     $this->tpl->get_template($coursesWithoutCategoryTemplate)
                 );
             }
 
             if ($courses['in_category'] || $courses['not_category']) {
-                $template->assign('courses', $courses['not_category']);
-                $template->assign('categories', $courses['in_category']);
+                $this->tpl->assign('courses', $courses['not_category']);
+                $this->tpl->assign('categories', $courses['in_category']);
 
-                $listCourse = $template->fetch(
+                $listCourse = $this->tpl->fetch(
                     $this->tpl->get_template($coursesWithCategoryTemplate)
                 );
-                $listCourse .= $template->fetch(
+                $listCourse .= $this->tpl->fetch(
                     $this->tpl->get_template($coursesWithoutCategoryTemplate)
                 );
             }
@@ -1191,7 +1180,6 @@ class IndexManager
         if (is_array($session_categories)) {
             foreach ($session_categories as $session_category) {
                 $session_category_id = $session_category['session_category']['id'];
-
                 // Sessions and courses that are not in a session category
                 if (
                     empty($session_category_id) &&
@@ -1306,13 +1294,12 @@ class IndexManager
                                 $params['show_simple_session_info'] = true;
                             }
 
-                            if ($gamificationModeIsActive) {
+                            if ($gameModeIsActive) {
                                 $params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
                                 $params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
                                 $params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
                             }
                             $listSession[] = $params;
-
                             $sessionCount++;
                         }
                     }
@@ -1470,7 +1457,7 @@ class IndexManager
             $this->tpl->assign('all_courses', $allCoursesInSessions);
             $this->tpl->assign('session', $listSession);
             $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false));
-            $this->tpl->assign('gamification_mode', $gamificationModeIsActive);
+            $this->tpl->assign('gamification_mode', $gameModeIsActive);
 
             if (api_get_configuration_value('view_grid_courses')) {
                 $sessions_with_no_category = $this->tpl->fetch(
@@ -1519,7 +1506,7 @@ class IndexManager
     }
 
     /**
-     * UserPortal view for session, return the HTLK of the course list
+     * UserPortal view for session, return the HTML of the course list
      * @param $user_id
      * @return string
      */
@@ -1527,7 +1514,6 @@ class IndexManager
     {
         $sessionCount = 0;
         $courseCount = 0;
-
         $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
 
         if ($load_history) {
@@ -1538,16 +1524,6 @@ class IndexManager
             $session_categories = UserManager::get_sessions_by_category($user_id, false);
         }
 
-        $html = '';
-
-        //Showing history title
-        if ($load_history) {
-            $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
-            if (empty($session_categories)) {
-                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
-            }
-        }
-
         $html = '';
         $loadDirs = $this->load_directories_preview;
 
@@ -1562,10 +1538,8 @@ class IndexManager
             $specialCourses = $specialCoursesResult;
 
             if ($specialCourses) {
-                $specialCoursesTemplate = new Template(null, false, false, false, false, false, false);
-                $specialCoursesTemplate->assign('courses', $specialCourses);
-
-                $html = $specialCoursesTemplate->fetch(
+                $this->tpl->assign('courses', $specialCourses);
+                $html = $this->tpl->fetch(
                     $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
                 );
             }

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

@@ -257,3 +257,6 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
 //$_configuration['block_registered_users_access_to_open_course_contents'] = false;
 // Allows syncing the database with the current entity schema
 //$_configuration['sync_db_with_schema'] = false;
+// Load course notifications in user_portal.php using ajax
+//$_configuration['user_portal_load_notification_by_ajax'] = false;
+

+ 1 - 1
main/lp/learnpath.class.php

@@ -2220,7 +2220,7 @@ class learnpath
         // Getting all the information about the item.
         $sql = "SELECT * FROM $tbl_lp_item as lp
                 INNER JOIN $tbl_lp_item_view as lp_view
-                ON lp.id = lp_view.lp_item_id
+                ON (lp.id = lp_view.lp_item_id AND lp.c_id = lp_view.c_id)
                 WHERE
                     lp.id = '".$_SESSION['oLP']->current."' AND
                     lp.c_id = $course_id AND

+ 3 - 1
main/work/work.lib.php

@@ -1335,9 +1335,10 @@ function getWorkListStudent(
         $groupInfo = GroupManager::get_group_properties($group_id);
         $groupIid = $groupInfo['iid'];
     }
+    $groupIid = (int) $groupIid;
 
     // Get list from database
-    if (!empty($group_id)) {
+    if (!empty($groupIid)) {
         $group_query = " WHERE w.c_id = $course_id AND post_group_id = $groupIid";
         $subdirs_query = "AND parent_id = 0";
     } else {
@@ -1468,6 +1469,7 @@ function getWorkListTeacher(
         $groupInfo = GroupManager::get_group_properties($group_id);
         $groupIid = $groupInfo['iid'];
     }
+    $groupIid = (int) $groupIid;
 
     $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
     if (!in_array($direction, array('asc', 'desc'))) {

+ 2 - 1
plugin/google_maps/lang/english.php

@@ -1,4 +1,5 @@
 <?php
 
 $strings['plugin_title'] = "Google Maps";
-$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
+$strings['plugin_comment'] = "Enable the functionality to show google maps";
+$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

+ 2 - 1
plugin/google_maps/lang/french.php

@@ -1,4 +1,5 @@
 <?php
 
 $strings['plugin_title'] = "Google Maps";
-$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
+$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
+$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

+ 1 - 0
plugin/google_maps/lang/spanish.php

@@ -2,3 +2,4 @@
 
 $strings['plugin_title'] = "Google Maps";
 $strings['plugin_comment'] = "Enable the functionality to show google maps";
+$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

+ 3 - 1
plugin/google_maps/src/GoogleMapsPluginPlugin.php

@@ -1,5 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * The google maps class allows to use
  * @author José Loguercio Silva <jose.loguercio@beeznest.com>
@@ -14,7 +15,8 @@ class GoogleMapsPlugin extends Plugin
     {
         $parameters = array(
             'enable_api' => 'boolean',
-            'api_key' => 'text'
+            'api_key' => 'text',
+            'extra_field_name' => 'text'
         );
 
         parent::__construct('1.0', 'José Loguercio Silva', $parameters);

+ 46 - 0
plugin/google_maps/src/map_coordinates.php

@@ -0,0 +1,46 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * Show the map coordinates of all users geo extra field
+ * @author José Loguercio Silva <jose.loguercio@beeznest.com>
+ * @package chamilo.plugin.google_maps
+ */
+
+
+$cidReset = true;
+
+require_once __DIR__.'/../../../main/inc/global.inc.php';
+
+api_protect_admin_script();
+
+$plugin = GoogleMapsPlugin::create();
+
+$apiIsEnable = $plugin->get('enable_api') === 'true';
+$extraFieldName = $plugin->get('extra_field_name');
+
+if ($apiIsEnable) {
+    $gmapsApiKey = $plugin->get('api_key');
+    $htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key='. $gmapsApiKey . '" ></script>';
+}
+
+$em = Database::getManager();
+
+$extraField = $em->getRepository('ChamiloCoreBundle:ExtraField');
+$extraField = $extraField->findOneBy(['variable' => $extraFieldName]);
+
+$extraFieldValues = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
+$extraFieldValues = $extraFieldValues->findBy(['field' => $extraField->getId()]);
+
+$templateName = get_lang('UsersCoordinatesMap');
+
+$tpl = new Template($templateName);
+
+$tpl->assign('extra_field_values', $extraFieldValues);
+
+$content = $tpl->fetch('google_maps/view/map_coordinates.tpl');
+
+$tpl->assign('header', $templateName);
+$tpl->assign('content', $content);
+$tpl->display_one_col_template();
+

+ 50 - 0
plugin/google_maps/view/map_coordinates.tpl

@@ -0,0 +1,50 @@
+<div id="map" style="width:100%; height:400px;">
+
+</div>
+<script>
+    $(document).ready(function() {
+        initMap();
+    });
+
+    function initMap() {
+        var center = new google.maps.LatLng(-3.480523, 7.866211);
+
+        var bounds = new google.maps.LatLngBounds();
+        var infoWindow = new google.maps.InfoWindow();
+
+        var map = new google.maps.Map(document.getElementById("map"), {
+            zoom: 2,
+            center: center,
+            mapTypeControl: true,
+            mapTypeControlOptions: {
+                style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
+            },
+            navigationControl: true,
+            mapTypeId: google.maps.MapTypeId.ROADMAP
+        });
+
+        {% for field in extra_field_values %}
+
+            var latLng = '{{ field.value }}';
+            latLng = latLng.split(',');
+
+            var lat = latLng[0];
+            var lng = latLng[1];
+
+            var location = new google.maps.LatLng(lat, lng);
+
+            {% set userInfo = field.itemId | user_info %}
+
+            var marker = new google.maps.Marker({
+                map: map,
+                position: location,
+                label: "{{ userInfo.complete_name }}"
+            });
+
+            bounds.extend(marker.position);
+            map.fitBounds(bounds);
+
+        {% endfor %}
+
+    }
+</script>

+ 1 - 0
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php

@@ -60,6 +60,7 @@ class Basic extends Toolbar
         'widget',
         'wikilink',
         'wordcount',
+        'inserthtml',
         'xml',
     );
 

+ 2 - 2
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php

@@ -54,7 +54,7 @@ class Documents extends Basic
     {
         return [
             ['Maximize', 'PasteFromWord', '-', 'Undo', 'Redo'],
-            ['Link', 'Unlink', 'Anchor', 'Glossary'],
+            ['Link', 'Unlink', 'Anchor', 'inserthtml', 'Glossary'],
             [
                 'Image',
                 'Video',
@@ -94,7 +94,7 @@ class Documents extends Basic
     protected function getMinimizedToolbar()
     {
         return [
-            ['Save', 'NewPage', 'Templates', '-', 'PasteFromWord'],
+            ['Save', 'NewPage', 'Templates', '-', 'PasteFromWord', 'inserthtml'],
             ['Undo', 'Redo'],
             [
                 'Link',

File diff suppressed because it is too large
+ 0 - 0
src/Chamilo/CoreBundle/Resources/public/ckeditor/skins/bootstrapck/dialog.css


+ 25 - 6
user_portal.php

@@ -39,6 +39,30 @@ $load_dirs = api_get_setting('show_documents_preview');
 $displayMyCourseViewBySessionLink = api_get_setting('my_courses_view_by_session') === 'true';
 $nameTools = get_lang('MyCourses');
 
+// Load course notification by ajax
+$loadNotificationsByAjax = api_get_configuration_value('user_portal_load_notification_by_ajax');
+if ($loadNotificationsByAjax) {
+    $htmlHeadXtra[] = '<script>
+    $(function() {
+        $(".course_notification").each(function(index) {
+            var div = $(this);
+            var id = $(this).attr("id");       
+            var idList = id.split("_");
+            var courseId = idList[1];
+            var sessionId = idList[2];
+            var status = idList[3];
+            $.ajax({			
+                type: "GET",
+                url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=get_notification&course_id="+courseId+"&session_id="+sessionId+"&status="+status,			
+                success: function(data) {			    
+                    div.append(data);			    
+                }
+            });
+        });
+    });
+    </script>';
+}
+
 /*
     Header
     Include the HTTP, HTML headers plus the top banner.
@@ -104,9 +128,6 @@ if ($displayMyCourseViewBySessionLink) {
 
 $controller = new IndexManager(get_lang('MyCourses'));
 
-// Main courses and session list
-//$courseAndSessions = $controller->returnCoursesAndSessions($userId);
-
 // Main courses and session list
 if (isset($_COOKIE['defaultMyCourseView'.$userId]) &&
     $_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION && $displayMyCourseViewBySessionLink
@@ -225,9 +246,7 @@ $controller->tpl->assign('course_block', $controller->return_course_block());
 $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
 $controller->tpl->assign('search_block', $controller->return_search_block());
 $controller->tpl->assign('classes_block', $controller->return_classes_block());
-//if (api_is_platform_admin() || api_is_drh()) {
 $controller->tpl->assign('skills_block', $controller->return_skills_links());
-//}
 $historyClass = '';
 if (!empty($_GET['history'])) {
     $historyClass = 'courses-history';
@@ -238,4 +257,4 @@ $controller->tpl->display_two_col_template();
 // Deleting the session_id.
 Session::erase('session_id');
 Session::erase('studentview');
-api_remove_in_gradebook('in_gradebook');
+api_remove_in_gradebook();

Some files were not shown because too many files changed in this diff