Julio Montoya 10 vuotta sitten
vanhempi
commit
5cb082885a

+ 19 - 0
main/admin/add_users_to_session.php

@@ -357,6 +357,25 @@ if ($ajax_search) {
     foreach ($users as $user) {
         $sessionUsersList[$user['user_id']] = $user ;
     }
+
+    $sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session);
+
+    // Filter the user list in all courses in the session
+    foreach ($sessionUserInfo as $sessionUser) {
+        // filter students in session
+        if ($sessionUser['status_in_session'] != 0) {
+            continue;
+        }
+        
+        if (!array_key_exists($sessionUser['user_id'], $sessionUsersList)) {
+            continue;
+        }
+
+        if ($sessionUser['count'] != $countSessionCoursesList) {
+            unset($sessionUsersList[$sessionUser['user_id']]);
+        }
+    }
+
     unset($users); //clean to free memory
 } else {
     //Filter by Extra Fields

+ 45 - 0
main/admin/index.php

@@ -400,6 +400,51 @@ if ($useCookieValidation) {
 
 $tpl->assign('web_admin_ajax_url', $admin_ajax_url);
 $tpl->assign('blocks', $blocks);
+
+if (api_is_platform_admin()) {
+    $extraDataForm = new FormValidator(
+        'block_extra_data',
+        'post',
+        '#',
+        null,
+        array(
+            'id' => 'block-extra-data',
+            'class' => 'form-inline'
+        )
+    );
+
+    $extraDataForm->add_html_editor(
+        'extra_content',
+        null,
+        false,
+        false,
+        array(
+            'name' => 'extra-content',
+            'ToolbarSet' => 'AdminPanels',
+            'Width' => 530,
+            'Height' => 300
+        )
+    );
+    $extraDataForm->addElement(
+        'hidden',
+        'block',
+        null,
+        array(
+            'id' => 'extra-block'
+        )
+    );
+    $extraDataForm->add_button(
+        'submit',
+        get_lang('Save'),
+        array(
+            'id' => 'btn-block-editor-save',
+            'class' => 'btn btn-primary'
+        )
+    );
+
+    $tpl->assign('extraDataForm', $extraDataForm->toHtml());
+}
+
 // The template contains the call to the AJAX version checker
 $admin_template = $tpl->get_template('admin/settings_index.tpl');
 $content = $tpl->fetch($admin_template);

+ 2 - 0
main/admin/session_add.php

@@ -19,6 +19,8 @@ $this_section=SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script(true);
 
+api_protect_limit_for_session_admin();
+
 $formSent=0;
 $errorMsg='';
 

+ 1 - 0
main/admin/session_category_list.php

@@ -12,6 +12,7 @@ $cidReset = true;
 require_once '../inc/global.inc.php';
 
 api_protect_admin_script(true);
+api_protect_limit_for_session_admin();
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;

+ 1 - 0
main/admin/session_import.php

@@ -10,6 +10,7 @@ require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
+api_protect_limit_for_session_admin();
 
 $form_sent = 0;
 $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.

+ 1 - 0
main/admin/session_import_drh.php

@@ -10,6 +10,7 @@ require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
+api_protect_limit_for_session_admin();
 
 $form_sent = 0;
 

+ 1 - 0
main/admin/user_add.php

@@ -13,6 +13,7 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 // User permissions
 api_protect_admin_script(true);
+api_protect_limit_for_session_admin();
 
 $is_platform_admin = api_is_platform_admin() ? 1 : 0;
 

+ 1 - 0
main/admin/user_import.php

@@ -336,6 +336,7 @@ function parse_xml_data($file)
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true, null, 'login');
+api_protect_limit_for_session_admin();
 
 $defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
 

+ 1 - 0
main/admin/usergroups.php

@@ -10,6 +10,7 @@ require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
+api_protect_limit_for_session_admin();
 
 //Add the JS needed to use the jqgrid
 $htmlHeadXtra[] = api_get_jqgrid_js();

+ 1 - 0
main/coursecopy/copy_course_session.php

@@ -14,6 +14,7 @@ require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_COURSE_MAINTENANCE;
 
 api_protect_global_admin_script();
+api_protect_limit_for_session_admin();
 
 require_once 'classes/CourseBuilder.class.php';
 require_once 'classes/CourseRestorer.class.php';

+ 5 - 1
main/inc/ajax/admin.ajax.php

@@ -33,7 +33,7 @@ switch ($action) {
         break;
 
     case 'save_block_extra':
-        $content = isset($_POST['content']) ? Security::remove_XSS($_POST['content']) : null;
+        $content = isset($_POST['extra_content']) ? Security::remove_XSS($_POST['extra_content']) : null;
         $blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
 
         if (empty($blockName)) {
@@ -93,6 +93,10 @@ switch ($action) {
             $newUrlDir = api_get_path(SYS_PATH) . "home/admin/";
         }
 
+        if (!file_exists($newUrlDir)) {
+            die;
+        }
+
         if (!Security::check_abs_path("{$newUrlDir}{$blockName}_extra.html", $newUrlDir)) {
             die;
         }

+ 20 - 9
main/inc/ajax/model.ajax.php

@@ -9,10 +9,10 @@ $libpath = api_get_path(LIBRARY_PATH);
 // 1. Setting variables needed by jqgrid
 
 $action = $_GET['a'];
-$page   = intval($_REQUEST['page']); //page
-$limit  = intval($_REQUEST['rows']); //quantity of rows
-$sidx   = $_REQUEST['sidx'];         //index (field) to filter
-$sord   = $_REQUEST['sord'];         //asc or desc
+$page = intval($_REQUEST['page']); //page
+$limit = intval($_REQUEST['rows']); //quantity of rows
+$sidx = $_REQUEST['sidx'];         //index (field) to filter
+$sord = $_REQUEST['sord'];         //asc or desc
 
 if (strpos(strtolower($sidx), 'asc') !== false) {
     $sidx = str_replace(array('asc', ','), '', $sidx);
@@ -370,7 +370,14 @@ switch ($action) {
         $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
         break;
     case 'get_sessions_tracking':
-        $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : null;
+        $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
+
+        $description = '';
+        $setting = api_get_configuration_value('show_session_description');
+        if ($setting) {
+            $description = $keyword;
+        }
+
         if (api_is_drh()) {
             $count = SessionManager::get_sessions_followed_by_drh(
                 api_get_user_id(),
@@ -380,7 +387,8 @@ switch ($action) {
                 false,
                 false,
                 null,
-                $keyword
+                $keyword,
+                $description
             );
         } else {
             // Sessions for the coach
@@ -389,7 +397,8 @@ switch ($action) {
                 null,
                 null,
                 true,
-                $keyword
+                $keyword,
+                $description
             );
         }
         break;
@@ -826,7 +835,8 @@ switch ($action) {
                 false,
                 false,
                 null,
-                $keyword
+                $keyword,
+                $description
             );
         } else {
             // Sessions for the coach
@@ -835,7 +845,8 @@ switch ($action) {
                 $start,
                 $limit,
                 false,
-                $keyword
+                $keyword,
+                $description
             );
         }
 

+ 50 - 0
main/inc/lib/fckeditor/toolbars/default/admin_panels.php

@@ -0,0 +1,50 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * AdminPanels FCKEditor's toolbar
+ * For more information: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options
+ * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
+ * @package chamilo
+ */
+
+// Hide/show SpellCheck buttom
+if ((api_get_setting('allow_spellcheck') == 'true')) {
+    $VSpellCheck = 'SpellCheck';
+} else {
+    $VSpellCheck = '';
+}
+
+// This is the visible toolbar set when the editor has "normal" size.
+$config['ToolbarSets']['Normal'] = array(
+    array('NewPage', '-', 'PasteWord'),
+    array('Undo', 'Redo'),
+    array('Link', 'Image', 'flvPlayer', 'Flash', 'MP3', 'mimetex'),
+    '/',
+    array('Bold', 'Italic', 'Underline', 'TextColor', 'BGColor'),
+    array('UnorderedList', 'OrderedList', 'Rule'),
+    array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'),
+    array('FontFormat', 'FontName', 'FontSize'),
+    array('FitWindow')
+);
+
+// Sets whether the toolbar can be collapsed/expanded or not.
+// Possible values: true , false
+$config['ToolbarCanCollapse'] = true;
+
+// Sets how the editor's toolbar should start - expanded or collapsed.
+// Possible values: true , false
+$config['ToolbarStartExpanded'] = false;
+
+//This option sets the location of the toolbar.
+// Possible values: 'In' , 'None' , 'Out:[TargetId]' , 'Out:[TargetWindow]([TargetId])'
+//$config['ToolbarLocation'] = 'In';
+
+// A setting for blocking copy/paste functions of the editor.
+// This setting activates on leaners only. For users with other statuses there is no blocking copy/paste.
+// Possible values: true , false
+//$config['BlockCopyPaste'] = false;
+
+// Here new width and height of the editor may be set.
+// Possible values, examples: 300 , '250' , '100%' , ...
+//$config['Width'] = '100%';
+//$config['Height'] = '400';

+ 34 - 0
main/inc/lib/fckeditor/toolbars/extended/admin_panels.php

@@ -0,0 +1,34 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * AdminPanels FCKEditor's toolbar
+ * For more information: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options
+ * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
+ * @package chamilo
+ */
+
+// Hide/show SpellCheck buttom
+if ((api_get_setting('allow_spellcheck') == 'true')) {
+    $VSpellCheck = 'SpellCheck';
+} else {
+    $VSpellCheck = '';
+}
+
+// This is the visible toolbar set when the editor is maximized.
+// If it has not been defined, then the toolbar set for the "normal" size is used.
+$config['ToolbarSets']['Maximized'] = array(
+    array('NewPage', '-', 'Preview', 'Print'),
+    array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord'),
+    array('Undo', 'Redo', '-', 'SelectAll', 'Find', '-', 'RemoveFormat'),
+    array('Link', 'Unlink', 'Anchor', 'Glossary'),
+    array('Image', 'imgmapPopup', 'flvPlayer', 'EmbedMovies', 'YouTube', 'Flash', 'MP3', 'googlemaps', 'Smiley', 'SpecialChar', 'insertHtml', 'mimetex', 'asciimath', 'asciisvg', 'fckeditor_wiris_openFormulaEditor', 'fckeditor_wiris_openCAS'),
+    '/',
+    array('TableOC', 'Table', 'TableInsertRowAfter', 'TableDeleteRows', 'TableInsertColumnAfter', 'TableDeleteColumns', 'TableInsertCellAfter', 'TableDeleteCells', 'TableMergeCells', 'TableHorizontalSplitCell', 'TableVerticalSplitCell', 'TableCellProp', '-', 'CreateDiv'),
+    array('UnorderedList', 'OrderedList', 'Rule', '-', 'Outdent', 'Indent', 'Blockquote'),
+    array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'),
+    array('Bold', 'Italic', 'Underline', 'StrikeThrough', '-', 'Subscript', 'Superscript', '-', 'TextColor', 'BGColor'),
+    array($VSpellCheck),
+    array('Style', 'FontFormat', 'FontName', 'FontSize'),
+    array('PageBreak', 'ShowBlocks', 'Source'),
+    array('FitWindow')
+);

+ 110 - 13
main/inc/lib/sessionmanager.lib.php

@@ -2671,8 +2671,9 @@ class SessionManager
                     }
                 }
             }
+        } else {
+            return false;
         }
-        return false;
     }
 
     /**
@@ -2810,6 +2811,8 @@ class SessionManager
      * @param bool $getOnlySessionId
      * @param bool $getSql
      * @param string $orderCondition
+     * @param string $description
+     *
      * @return array sessions
      */
     public static function get_sessions_followed_by_drh(
@@ -2820,7 +2823,8 @@ class SessionManager
         $getOnlySessionId = false,
         $getSql = false,
         $orderCondition = null,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         return self::getSessionsFollowedByUser(
             $userId,
@@ -2831,7 +2835,8 @@ class SessionManager
             $getOnlySessionId,
             $getSql,
             $orderCondition,
-            $keyword
+            $keyword,
+            $description
         );
     }
 
@@ -2845,6 +2850,7 @@ class SessionManager
      * @param bool $getSql
      * @param string $orderCondition
      * @param string $keyword
+     * @param string $description
      * @return array sessions
      */
     public static function getSessionsFollowedByUser(
@@ -2856,11 +2862,12 @@ class SessionManager
         $getOnlySessionId = false,
         $getSql = false,
         $orderCondition = null,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         // Database Table Definitions
-        $tbl_session 			= Database::get_main_table(TABLE_MAIN_SESSION);
-        $tbl_session_rel_user 	= Database::get_main_table(TABLE_MAIN_SESSION_USER);
+        $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+        $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
         $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
         $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
 
@@ -2917,11 +2924,17 @@ class SessionManager
                 break;
         }
 
-        $keywordCondition = null;
+        $keywordCondition = '';
         if (!empty($keyword)) {
             $keyword = Database::escape_string($keyword);
             $keywordCondition = " AND (s.name LIKE '%$keyword%' ) ";
+
+            if (!empty($description)) {
+                $description = Database::escape_string($description);
+                $keywordCondition = " AND (s.name LIKE '%$keyword%' OR s.description LIKE '%$description%' ) ";
+            }
         }
+
         $whereConditions .= $keywordCondition;
 
         $subQuery = $sessionQuery.$courseSessionQuery;
@@ -2958,21 +2971,30 @@ class SessionManager
     }
 
     /**
-     * Gets the list of courses by session filtered by access_url
-     * @param int $session_id
-     * @param string $course_name
-     * @return array list of courses
+     * Gets the list (or the count) of courses by session filtered by access_url
+     * @param int $session_id The session id
+     * @param string $course_name The course code
+     * @param string $orderBy Field to order the data
+     * @param boolean $getCount Optional. Count the session courses
+     * @return array|int List of courses. Whether $getCount is true, return the count
      */
     public static function get_course_list_by_session_id(
         $session_id,
         $course_name = '',
-        $orderBy = null
+        $orderBy = null,
+        $getCount = false
     ) {
         $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
         $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 
         $session_id = intval($session_id);
 
+        $sqlSelect = "SELECT *";
+
+        if ($getCount) {
+            $sqlSelect = "SELECT COUNT(1)";
+        }
+
         // select the courses
         $sql = "SELECT * FROM $tbl_course c
                 INNER JOIN $tbl_session_rel_course src
@@ -2988,7 +3010,11 @@ class SessionManager
             $orderBy = Database::escape_string($orderBy);
             $orderBy = " ORDER BY $orderBy";
         } else {
-            $orderBy .= " ORDER BY position ";
+            if (SessionManager::orderCourseIsEnabled()) {
+                $orderBy .= " ORDER BY position ";
+            } else {
+                $orderBy .= " ORDER BY title ";
+            }
         }
 
         $sql .= Database::escape_string($orderBy);
@@ -2996,6 +3022,12 @@ class SessionManager
         $num_rows = Database::num_rows($result);
         $courses = array();
         if ($num_rows > 0) {
+            if ($getCount) {
+                $count = Database::fetch_array($result);
+
+                return intval($count[0]);
+            }
+
             while ($row = Database::fetch_array($result,'ASSOC'))	{
                 $courses[$row['id']] = $row;
             }
@@ -3260,6 +3292,7 @@ class SessionManager
     /**
      * @param int $user_id
      * @return array
+     * @deprecated use get_sessions_by_general_coach()
      */
     public static function get_sessions_by_coach($user_id)
     {
@@ -5051,6 +5084,21 @@ class SessionManager
         }
     }
 
+    /**
+     * Courses re-ordering in resume_session.php flag see BT#8316
+     */
+    public static function orderCourseIsEnabled()
+    {
+        global $_configuration;
+        if (isset($_configuration['session_course_ordering']) &&
+            $_configuration['session_course_ordering']
+        ) {
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * @param string $direction (up/down)
      * @param int $sessionId
@@ -5059,6 +5107,10 @@ class SessionManager
      */
     public static function move($direction, $sessionId, $courseCode)
     {
+        if (!self::orderCourseIsEnabled()) {
+            return false;
+        }
+
         $sessionId = intval($sessionId);
         $courseCode = Database::escape_string($courseCode);
 
@@ -5138,6 +5190,24 @@ class SessionManager
         return self::move('down', $sessionId, $courseCode);
     }
 
+    /**
+     * Use the session duration to allow/block user access see BT#8317
+     * Needs these DB changes
+     * ALTER TABLE session ADD COLUMN duration int;
+     * ALTER TABLE session_rel_user ADD COLUMN duration int;
+     */
+    public static function durationPerUserIsEnabled()
+    {
+        global $_configuration;
+        if (isset($_configuration['session_duration_feature']) &&
+            $_configuration['session_duration_feature']
+        ) {
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * Returns the number of days the student has left in a session when using
      * sessions durations
@@ -5315,6 +5385,7 @@ class SessionManager
                 $sessions = $newSessions;
             }
         }
+
         return $sessions;
     }
 
@@ -5322,6 +5393,7 @@ class SessionManager
      * Check if the course belongs to the session
      * @param int $sessionId The session id
      * @param string $courseCode The course code
+     *
      * @return bool
      */
     public static function sessionHasCourse($sessionId, $courseCode)
@@ -5444,6 +5516,31 @@ class SessionManager
         ));
     }
 
+	/**
+     * Get the count of user courses in session
+     * @param int $sessionId The session id
+     * @return array
+     */
+    public static function getTotalUserCoursesInSession($sessionId)
+    {
+        $sql = "SELECT COUNT(1) as count, u.user_id, scu.status status_in_session, u.status user_status "
+            . "FROM session_rel_course_rel_user scu "
+            . "INNER JOIN user u ON scu.id_user = u.user_id "
+            . "WHERE scu.id_session = " . intval($sessionId) . " "
+            . "GROUP BY u.user_id";
+
+        $result = Database::query($sql);
+
+        $list = array();
+
+        while ($data = Database::fetch_assoc($result)) {
+            $list[] = $data;
+        }
+
+        return $list;
+    }
+
+
     /**
      * Returns list of a few data from session (name, short description, start
      * date, end date) and the given extra fields if defined based on a

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

@@ -2921,7 +2921,8 @@ class Tracking
      * @param int $start
      * @param int $limit
      * @param bool $getCount
-     * @param null $keyword
+     * @param string $keyword
+     * @param string $description
      * @return mixed
      */
     public static function get_sessions_coached_by_user(
@@ -2929,7 +2930,8 @@ class Tracking
         $start = 0,
         $limit = 0,
         $getCount = false,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         // table definition
         $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
@@ -2947,9 +2949,15 @@ class Tracking
         }
 
         $keywordCondition = null;
+
         if (!empty($keyword)) {
             $keyword = Database::escape_string($keyword);
             $keywordCondition = " AND (name LIKE '%$keyword%' ) ";
+
+            if (!empty($description)) {
+                $description = Database::escape_string($description);
+                $keywordCondition = " AND (name LIKE '%$keyword%' OR description LIKE '%$description%' ) ";
+            }
         }
 
         $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
@@ -2961,7 +2969,10 @@ class Tracking
                 SELECT DISTINCT id, name, date_start, date_end
                 FROM $tbl_session session INNER JOIN $tbl_session_rel_access_url session_rel_url
                 ON (session.id = session_rel_url.session_id)
-                WHERE id_coach = $coach_id AND access_url_id = $access_url_id $keywordCondition
+                WHERE
+                    id_coach = $coach_id AND
+                    access_url_id = $access_url_id
+                    $keywordCondition
             UNION
                 SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
                 FROM $tbl_session as session
@@ -2971,7 +2982,9 @@ class Tracking
                     session_course_user.status=2
                 INNER JOIN $tbl_session_rel_access_url session_rel_url
                 ON (session.id = session_rel_url.session_id)
-                WHERE access_url_id = $access_url_id $keywordCondition
+                WHERE
+                    access_url_id = $access_url_id
+                    $keywordCondition
             ) as sessions $limitCondition
             ";
 

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

@@ -320,4 +320,10 @@ $_configuration['system_stable']     = NEW_VERSION_STABLE;
 //$_configuration['gravatar_type'] = 'mm';
 // Course log - Default columns to hide
 //$_configuration['course_log_hide_columns'] = array(1, 9);
+// Limit for the Session Admin role. The administration page show only
+// User block -> Add user
+// Course Sessions block -> Training session list
+$_configuration['limit_session_admin_role'] = false;
+// Show session description
+//$_configuration['show_session_description'] = false;
 

+ 4 - 2
main/mySpace/session.php

@@ -1,9 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
-/*
+
+/**
  * Sessions reporting
  * @package chamilo.reporting
  */
+
 ob_start();
 $cidReset = true;
 require_once '../inc/global.inc.php';
@@ -89,7 +91,7 @@ $form = new FormValidator('search_course', 'get', api_get_path(WEB_CODE_PATH).'m
 $form->addElement('text', 'keyword', get_lang('Keyword'));
 $form->addElement('button', 'submit', get_lang('Search'));
 $form->addElement('hidden', 'session_id', $sessionId);
-$keyword = null;
+$keyword = '';
 if ($form->validate()) {
     $keyword = $form->getSubmitValue('keyword');
 }