Browse Source

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

Yannick Warnier 11 years ago
parent
commit
6d383ade02

+ 51 - 45
main/inc/lib/course.lib.php

@@ -254,12 +254,11 @@ class CourseManager
         if (!is_array($user_id)) {
             $user_id = array($user_id);
         }
+
         if (count($user_id) == 0) {
             return;
         }
 
-        $table_user = Database::get_main_table(TABLE_MAIN_USER);
-
         if (!empty($session_id)) {
             $session_id = intval($session_id);
         } else {
@@ -282,77 +281,76 @@ class CourseManager
             $user_list[] = $user_id;
         }
 
-
         $course_info = api_get_course_info($course_code);
         $course_id = $course_info['real_id'];
 
         // Unsubscribe user from all groups in the course.
-        Database::query("DELETE FROM ".Database::get_course_table(TABLE_GROUP_USER)."  WHERE c_id = $course_id AND user_id IN (".$user_ids.")");
-        Database::query("DELETE FROM ".Database::get_course_table(TABLE_GROUP_TUTOR)." WHERE c_id = $course_id AND user_id IN (".$user_ids.")");
+        $sql = "DELETE FROM ".Database::get_course_table(TABLE_GROUP_USER)."  WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
+        Database::query($sql);
+        $sql = "DELETE FROM ".Database::get_course_table(TABLE_GROUP_TUTOR)." WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
+        Database::query($sql);
 
         // Erase user student publications (works) in the course - by André Boivin
 
-        /*
-        $sqlu = "SELECT * FROM $table_user WHERE user_id IN (".$user_ids.")";
-        $resu = Database::query($sqlu);
-        $username = Database::fetch_array($resu,'ASSOC');
-        $userfirstname = $username['firstname'];
-        $userlastname = $username['lastname'];
-        $publication_name = $userfirstname.' '.$userlastname ;
-
-        $table_course_user_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
-        $sql = "DELETE FROM $table_course_user_publication WHERE c_id = $course_id AND author = '".Database::escape_string($publication_name)."'";
-        Database::query($sql);*/
-
-        foreach ($user_ids as $userId) {
-            // Getting all work from user
-            $workList = getWorkPerUser($userId);
-            if (!empty($workList)) {
-                foreach ($workList as $work) {
-                    $work = $work['work'];
-                    // Getting user results
-                    if (!empty($work->user_results)) {
-                        foreach ($work->user_results as $workSent) {
-                            deleteWorkItem($workSent['id'], $course_info);
+        if (!empty($user_list)) {
+            require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
+            foreach ($user_list as $userId) {
+                // Getting all work from user
+                $workList = getWorkPerUser($userId);
+                if (!empty($workList)) {
+                    foreach ($workList as $work) {
+                        $work = $work['work'];
+                        // Getting user results
+                        if (!empty($work->user_results)) {
+                            foreach ($work->user_results as $workSent) {
+                                deleteWorkItem($workSent['id'], $course_info);
+                            }
                         }
                     }
                 }
             }
         }
 
-
         // Unsubscribe user from all blogs in the course.
         Database::query("DELETE FROM ".Database::get_course_table(TABLE_BLOGS_REL_USER)." WHERE c_id = $course_id AND  user_id IN (".$user_ids.")");
         Database::query("DELETE FROM ".Database::get_course_table(TABLE_BLOGS_TASKS_REL_USER)." WHERE c_id = $course_id AND  user_id IN (".$user_ids.")");
 
-        //Deleting users in forum_notification and mailqueue course tables
-        $sql_delete_forum_notification = "DELETE FROM  ".Database::get_course_table(TABLE_FORUM_NOTIFICATION)." WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
-        Database::query($sql_delete_forum_notification);
+        // Deleting users in forum_notification and mailqueue course tables
+        $sql = "DELETE FROM  ".Database::get_course_table(TABLE_FORUM_NOTIFICATION)."
+                WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
+        Database::query($sql);
 
-        $sql_delete_mail_queue = "DELETE FROM ".Database::get_course_table(TABLE_FORUM_MAIL_QUEUE)." WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
-        Database::query($sql_delete_mail_queue);
+        $sql = "DELETE FROM ".Database::get_course_table(TABLE_FORUM_MAIL_QUEUE)."
+                WHERE c_id = $course_id AND user_id IN (".$user_ids.")";
+        Database::query($sql);
 
         // Unsubscribe user from the course.
         if (!empty($session_id)) {
+
             // Delete in table session_rel_course_rel_user
             $sql = "DELETE FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
-                    WHERE id_session ='".$session_id."' AND course_code = '".Database::escape_string($course_info['code'])."' AND id_user IN ($user_ids)";
+                    WHERE   id_session ='".$session_id."' AND
+                            course_code = '".Database::escape_string($course_info['code'])."' AND
+                            id_user IN ($user_ids)";
             Database::query($sql);
 
-            foreach ($user_id as $uid) {
+            foreach ($user_list as $uid) {
                 // check if a user is register in the session with other course
-                $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='$session_id' AND id_user='$uid'";
+                $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
+                        WHERE id_session='$session_id' AND id_user='$uid'";
                 $rs = Database::query($sql);
+
                 if (Database::num_rows($rs) == 0) {
                     // Delete in table session_rel_user
-                    Database::query("DELETE FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                                     WHERE id_session ='".$session_id."' AND id_user='$uid' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."");
+                    $sql = "DELETE FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
+                            WHERE id_session ='".$session_id."' AND id_user='$uid' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
+                    Database::query($sql);
                 }
             }
 
             // Update the table session
             $sql = "SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_USER)."
-                    WHERE id_session = '".$session_id."' AND relation_type<>".SESSION_RELATION_TYPE_RRHH;
+                    WHERE id_session = '".$session_id."' AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
             $row = Database::fetch_array(Database::query($sql));
             $count = $row[0];
             // number of users by session
@@ -361,24 +359,32 @@ class CourseManager
             Database::query($sql);
 
             // Update the table session_rel_course
-            $sql = "SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session = '$session_id' AND course_code = '$course_code' AND status<>2";
+            $sql = "SELECT COUNT(*) FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
+                    WHERE id_session = '$session_id' AND course_code = '$course_code' AND status<>2";
             $row = Database::fetch_array(@Database::query($sql));
             $count = $row[0];
+
             // number of users by session and course
-            Database::query("UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." SET nbr_users = '$count' WHERE id_session = '$session_id' AND course_code = '$course_code'");
+            $sql = "UPDATE ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)."
+                    SET nbr_users = '$count'
+                    WHERE id_session = '$session_id' AND course_code = '$course_code'";
+            Database::query($sql);
 
         } else {
             $sql = "DELETE FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
-                    WHERE user_id IN (".$user_ids.") AND relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_code = '".$course_code."'";
+                    WHERE
+                        user_id IN (".$user_ids.") AND
+                        relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
+                        course_code = '".$course_code."'";
             Database::query($sql);
 
             // add event to system log
             $user_id = api_get_user_id();
             event_system(LOG_UNSUBSCRIBE_USER_FROM_COURSE, LOG_COURSE_CODE, $course_code, api_get_utc_datetime(), $user_id);
 
-            foreach ($user_list as $user_id_to_delete) {
-                $user_info = api_get_user_info($user_id_to_delete);
-                event_system(LOG_UNSUBSCRIBE_USER_FROM_COURSE, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), $user_id);
+            foreach ($user_list as $userId) {
+                $userInfo = api_get_user_info($userId);
+                event_system(LOG_UNSUBSCRIBE_USER_FROM_COURSE, LOG_USER_OBJECT, $userInfo, api_get_utc_datetime(), $user_id);
             }
         }
     }

+ 191 - 97
main/inc/lib/document.lib.php

@@ -16,15 +16,12 @@
  */
 class DocumentManager
 {
-    /**
-     *
-     */
     private function __construct()
     {
-
     }
 
     /**
+     * @param string
      * @return the document folder quota for the current course, in bytes, or the default quota
      */
     public static function get_course_quota($course_code = null)
@@ -56,6 +53,7 @@ class DocumentManager
      * 	@param string $filename or boolean TRUE to return complete array
      * 	@author ? first version
      * 	@author Bert Vanderkimpen
+     *  @return string
      *
      */
     public static function file_get_mime_type($filename)
@@ -275,14 +273,15 @@ class DocumentManager
     }
 
     /**
+     *  @param string
+     *  @param string
      * 	@return true if the user is allowed to see the document, false otherwise
      * 	@author Sergio A Kessler, first version
-     * 	@author Roan Embrechts, bugfix
-     *   @todo ??not only check if a file is visible, but also check if the user is allowed to see the file??
+     * 	@author Roan Embrechts, bugfix     *
+     *  @todo not only check if a file is visible, but also check if the user is allowed to see the file??
      */
-    public static function file_visible_to_user($this_course, $doc_url) {
-        $current_session_id = api_get_session_id();
-
+    public static function file_visible_to_user($this_course, $doc_url)
+    {
         $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
 
         if ($is_allowed_to_edit) {
@@ -291,10 +290,8 @@ class DocumentManager
             $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
             $tbl_item_property = $this_course . 'item_property';
             $doc_url = Database::escape_string($doc_url);
-            //$doc_url = addslashes($doc_url);
             $query = "SELECT 1 FROM $tbl_document AS docs,$tbl_item_property AS props
                       WHERE props.tool = 'document' AND docs.id=props.ref AND props.visibility <> '1' AND docs.path = '$doc_url'";
-            //echo $query;
             $result = Database::query($query);
 
             return (Database::num_rows($result) == 0);
@@ -393,7 +390,8 @@ class DocumentManager
      * @param string The name of the file in the end (including extension)
      * @return false if file doesn't exist, true if stream succeeded
      */
-    public static function string_send_for_download($full_string, $forced = false, $name = '') {
+    public static function string_send_for_download($full_string, $forced = false, $name = '')
+    {
         $filename = $name;
         $len = strlen($full_string);
 
@@ -520,7 +518,8 @@ class DocumentManager
                         last.visibility,
                         last.insert_user_id
                     FROM $TABLE_ITEMPROPERTY AS last 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']})
+                        ON (docs.id = last.ref AND last.tool = '".TOOL_DOCUMENT."' AND
+                        docs.c_id = {$_course['real_id']} AND last.c_id = {$_course['real_id']})
                     WHERE
                         docs.path LIKE '" . $path . $added_slash . "%' AND
                         docs.path NOT LIKE '" . $path . $added_slash . "%/%' AND
@@ -635,7 +634,8 @@ class DocumentManager
      * @param int $to_group_id
      * @return array with paths
      */
-    public static function get_all_document_folders($_course, $to_group_id = '0', $can_see_invisible = false) {
+    public static function get_all_document_folders($_course, $to_group_id = '0', $can_see_invisible = false)
+    {
         $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
 
@@ -678,10 +678,8 @@ class DocumentManager
                     }
                     $document_folders[$row['id']] = $row['path'];
                 }
-                //sort($document_folders);
                 natsort($document_folders);
 
-                //return results
                 return $document_folders;
             } else {
                 return false;
@@ -767,7 +765,8 @@ class DocumentManager
      * @param int    $document_id in case you dont have the file path ,insert the id of the file here and leave $file in blank ''
      * @return boolean true/false
      * */
-    public static function check_readonly($_course, $user_id, $file, $document_id = '', $to_delete = false) {
+    public static function check_readonly($_course, $user_id, $file, $document_id = '', $to_delete = false)
+    {
         if (!(!empty($document_id) && is_numeric($document_id))) {
             $document_id = self::get_document_id($_course, $file);
         }
@@ -831,15 +830,24 @@ class DocumentManager
      * @param int    $document_id of the item
      * @return boolean true/false
      * */
-    public static function is_folder($_course, $document_id) {
+    public static function is_folder($_course, $document_id)
+    {
         $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
         $course_id = $_course['real_id'];
         $document_id = Database::escape_string($document_id);
-        $result = Database::fetch_array(Database::query("SELECT filetype FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND id= $document_id"), 'ASSOC');
+        $sql = "SELECT filetype FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND id= $document_id";
+        $result = Database::fetch_array(Database::query($sql), 'ASSOC');
         return $result['filetype'] == 'folder';
     }
 
-    public static function delete_document_from_db($document_id, $course_info = array(), $session_id = 0, $remove_content_from_db = false) {
+    /**
+     * @param int $document_id
+     * @param array $course_info
+     * @param int $session_id
+     * @param bool $remove_content_from_db
+     */
+    public static function delete_document_from_db($document_id, $course_info = array(), $session_id = 0, $remove_content_from_db = false)
+    {
         $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
         $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
 
@@ -853,7 +861,7 @@ class DocumentManager
             $session_id = api_get_session_id();
         }
 
-        //Soft DB delete
+        // Soft DB delete
         api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'delete', $user_id, null, null, null, null, $session_id);
         self::delete_document_from_search_engine($course_info['code'], $document_id);
         self::unset_document_as_template($document_id, $course_info['code'], $user_id);
@@ -870,7 +878,11 @@ class DocumentManager
         }
     }
 
-    public static function delete_document_metadata($document_id) {
+    /**
+     * @param int $document_id
+     */
+    public static function delete_document_metadata($document_id)
+    {
         //needed to deleted medadata
         require_once api_get_path(SYS_CODE_PATH) . 'metadata/md_funcs.php';
         require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
@@ -892,7 +904,8 @@ class DocumentManager
      * @return boolean true/false
      * @todo now only files/folders in a folder get visibility 2, we should rename them too.
      */
-    public static function delete_document($_course, $path, $base_work_dir) {
+    public static function delete_document($_course, $path, $base_work_dir)
+    {
         $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
 
         if (empty($path) || empty($base_work_dir)) {
@@ -914,8 +927,8 @@ class DocumentManager
 
         if ($document_id) {
             self::delete_document_from_db($document_id);
-            //checking
-            //$file_exists_in_db = self::get_document_data_by_id($document_id, $_course['code']);
+            // Checking
+            // $file_exists_in_db = self::get_document_data_by_id($document_id, $_course['code']);
             $file_deleted_from_db = true;
         }
 
@@ -923,38 +936,37 @@ class DocumentManager
 
             if (api_get_setting('permanently_remove_deleted_files') == 'true') {
                 //Deleted files are *really* deleted
-                $what_to_delete_sql = "SELECT id FROM " . $TABLE_DOCUMENT . " WHERE c_id = $course_id AND path='" . $path . "' OR path LIKE BINARY '" . $path . "/%'";
-                //get all id's of documents that are deleted
-                $what_to_delete_result = Database::query($what_to_delete_sql);
-
-                if ($what_to_delete_result && Database::num_rows($what_to_delete_result) != 0) {
-                    //delete all item_property entries
-                    while ($row = Database::fetch_array($what_to_delete_result)) {
-                        //query to delete from item_property table (hard way)
+                $sql = "SELECT id FROM $TABLE_DOCUMENT
+                        WHERE c_id = $course_id AND path='".$path."' OR path LIKE BINARY '".$path."/%'";
+                // Get all id's of documents that are deleted
+                $result = Database::query($sql);
+
+                if ($result && Database::num_rows($result) != 0) {
+                    // Delete all item_property entries
+                    while ($row = Database::fetch_array($result)) {
+                        // Query to delete from item_property table (hard way)
                         self::delete_document_from_db($row['id'], $_course, $current_session_id, true);
                     }
-                    //delete documents, do it like this so metadata get's deleted too
-                    //update_db_info('delete', $path);
-                    //throw it away
+                    // Delete documents, do it like this so metadata gets deleted too
                     my_delete($base_work_dir . $path);
                     $file_deleted_from_disk = true;
                 }
             } else {
-                //Set visibility to 2 and rename file/folder to xxx_DELETED_#id (soft delete)
+                // Set visibility to 2 and rename file/folder to xxx_DELETED_#id (soft delete)
 
                 if (is_file($base_work_dir . $path) || is_dir($base_work_dir . $path)) {
-                    if (rename($base_work_dir . $path, $base_work_dir . $new_path)) {
+                    if (rename($base_work_dir . $path, $base_work_dir.$new_path)) {
 
-                        $sql = "UPDATE $TABLE_DOCUMENT set path='" . $new_path . "' WHERE c_id = $course_id AND id='" . $document_id . "'";
+                        $sql = "UPDATE $TABLE_DOCUMENT set path='".$new_path."' WHERE c_id = $course_id AND id='".$document_id."'";
                         Database::query($sql);
 
-                        $sql = "SELECT id, path FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND path LIKE BINARY '" . $path . "/%'";
+                        $sql = "SELECT id, path FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND path LIKE BINARY '".$path."/%'";
                         $result = Database::query($sql);
                         if ($result && Database::num_rows($result) > 0) {
                             while ($deleted_items = Database::fetch_array($result, 'ASSOC')) {
                                 self::delete_document_from_db($deleted_items['id']);
 
-                                //Change path of subfolders and documents in database
+                                // Change path of subfolders and documents in database.
                                 $old_item_path = $deleted_items['path'];
                                 $new_item_path = $new_path . substr($old_item_path, strlen($path));
 
@@ -964,16 +976,17 @@ class DocumentManager
                         }
                         $file_renamed_from_disk = true;
                     } else {
-                        //Couldn't rename - file permissions problem?
-                        error_log(__FILE__ . ' ' . __LINE__ . ': Error renaming ' . $base_work_dir . $path . ' to ' . $base_work_dir . $new_path . '. This is probably due to file permissions', 0);
+                        // Couldn't rename - file permissions problem?
+                        error_log(__FILE__ . ' ' . __LINE__ . ': Error renaming '.$base_work_dir.$path.' to '.$base_work_dir.$new_path.'. This is probably due to file permissions', 0);
                     }
                 }
             }
         }
 
-        //Checking inconsistency
+        // Checking inconsistency
         if ($file_deleted_from_db && $file_deleted_from_disk ||
-                $file_deleted_from_db && $file_renamed_from_disk) {
+            $file_deleted_from_db && $file_renamed_from_disk
+        ) {
             return true;
         } else {
             //Something went wrong
@@ -981,7 +994,7 @@ class DocumentManager
             // This means it has been removed externally. To prevent a
             // blocking error from happening, we drop the related items from the
             // item_property and the document table.
-            error_log(__FILE__ . ' ' . __LINE__ . ': System inconsistency detected. The file or directory ' . $base_work_dir . $path . ' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database', 0);
+            error_log(__FILE__.' '.__LINE__.': System inconsistency detected. The file or directory '.$base_work_dir.$path.' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database', 0);
             return false;
         }
     }
@@ -992,7 +1005,8 @@ class DocumentManager
      * @param string $course_id Course code
      * @param int $document_id Document id to delete
      */
-    public static function delete_document_from_search_engine($course_id, $document_id) {
+    public static function delete_document_from_search_engine($course_id, $document_id)
+    {
         // remove from search engine if enabled
         if (api_get_setting('search_enabled') == 'true') {
             $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
@@ -1022,7 +1036,8 @@ class DocumentManager
      * @param string $path
      * @return int id of document / false if no doc found
      */
-    public static function get_document_id($course_info, $path) {
+    public static function get_document_id($course_info, $path)
+    {
         $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
         $course_id = $course_info['real_id'];
         $path = Database::escape_string($path);
@@ -1120,7 +1135,8 @@ class DocumentManager
      * @param string $couse_code
      * @param int $user_id
      */
-    public static function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id, $image) {
+    public static function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id, $image)
+    {
         // Database table definition
         $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
 
@@ -1146,7 +1162,8 @@ class DocumentManager
      * @param string $couse_code
      * @param int $user_id
      */
-    public static function unset_document_as_template($document_id, $course_code, $user_id) {
+    public static function unset_document_as_template($document_id, $course_code, $user_id)
+    {
 
         $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
         $course_code = Database::escape_string($course_code);
@@ -1170,8 +1187,11 @@ class DocumentManager
      *
      * @param string $document_path the relative complete path of the document
      * @param array  $course the _course array info of the document's course
+     * @param int
+     * @param string
      */
-    public static function is_visible($doc_path, $course, $session_id = 0, $file_type = 'file') {
+    public static function is_visible($doc_path, $course, $session_id = 0, $file_type = 'file')
+    {
         $docTable = Database::get_course_table(TABLE_DOCUMENT);
         $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
 
@@ -1233,10 +1253,13 @@ class DocumentManager
      *
      * @param   int     document id
      * @param   array   course info
-     * @param   array  	$course the _course array info of the document's course
+     * @param   int
+     * @param   int
+     * @param bool
      * @return  bool
      */
-    public static function is_visible_by_id($doc_id, $course_info, $session_id, $user_id, $admins_can_see_everything = true) {
+    public static function is_visible_by_id($doc_id, $course_info, $session_id, $user_id, $admins_can_see_everything = true)
+    {
         $is_visible = false;
         $user_in_course = false;
 
@@ -1324,7 +1347,8 @@ class DocumentManager
      * @param int The document id
      * @return void()
      */
-    function attach_gradebook_certificate($course_id, $document_id) {
+    function attach_gradebook_certificate($course_id, $document_id)
+    {
         $tbl_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
         $session_id = api_get_session_id();
         if ($session_id == 0 || is_null($session_id)) {
@@ -1344,7 +1368,8 @@ class DocumentManager
      * @param string The course id
      * @return int The default certificate id
      */
-    static function get_default_certificate_id($course_id) {
+    static function get_default_certificate_id($course_id)
+    {
         $tbl_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
         $session_id = api_get_session_id();
         if ($session_id == 0 || is_null($session_id)) {
@@ -1369,7 +1394,8 @@ class DocumentManager
      * @param string The course code
      * @return string The html content of the certificate
      */
-    static function replace_user_info_into_html($user_id, $course_code, $is_preview = false) {
+    static function replace_user_info_into_html($user_id, $course_code, $is_preview = false)
+    {
         $user_id = intval($user_id);
         $course_info = api_get_course_info($course_code);
         $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
@@ -1400,7 +1426,8 @@ class DocumentManager
     /**
      * return all content to replace and all content to be replace
      */
-    static function get_all_info_to_certificate($user_id, $course_id, $is_preview = false) {
+    static function get_all_info_to_certificate($user_id, $course_id, $is_preview = false)
+    {
         $info_list = array();
         $user_id = intval($user_id);
 
@@ -1496,7 +1523,8 @@ class DocumentManager
      * @param int The document id of the default certificate
      * @return void()
      */
-    function remove_attach_certificate($course_id, $default_certificate_id) {
+    function remove_attach_certificate($course_id, $default_certificate_id)
+    {
         $default_certificate = self::get_default_certificate_id($course_id);
         if ((int) $default_certificate == (int) $default_certificate_id) {
             $tbl_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
@@ -1520,7 +1548,8 @@ class DocumentManager
      * @param string The course id
      * @return void()
      */
-    static function create_directory_certificate_in_course($course_id) {
+    static function create_directory_certificate_in_course($course_id)
+    {
         $course_info = api_get_course_info($course_id);
         if (!empty($course_info)) {
             $to_group_id = 0;
@@ -1546,7 +1575,8 @@ class DocumentManager
      * @param string The course id
      * @return int The document id of the directory certificate
      */
-    static function get_document_id_of_directory_certificate() {
+    static function get_document_id_of_directory_certificate()
+    {
         $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
         $course_id = api_get_course_int_id();
         $sql = "SELECT id FROM $tbl_document WHERE c_id = $course_id AND path='/certificates' ";
@@ -1560,8 +1590,9 @@ class DocumentManager
      * @param string path of directory
      * @return bool  true if is a certificate or false otherwise
      */
-    static function is_certificate_mode($dir) {
-        //I'm in the certification module?
+    static function is_certificate_mode($dir)
+    {
+        // I'm in the certification module?
         $is_certificate_mode = false;
         $is_certificate_array = explode('/', $dir);
         array_shift($is_certificate_array);
@@ -1579,11 +1610,13 @@ class DocumentManager
      * to be an HTML file or string html. If it is not, then the function will return and empty list.
      * @param	string  source html (content or path)
      * @param	bool  	is file or string html
-     * @param	string	type (one of the Dokeos tools) - optional (otherwise takes the current item's type)
+     * @param	string	type (one of the app tools) - optional (otherwise takes the current item's type)
      * @param	int		level of recursivity we're in
-     * @return	array	List of file paths. An additional field containing 'local' or 'remote' helps determine if the file should be copied into the zip or just linked
+     * @return	array	List of file paths. An additional field containing 'local' or 'remote' helps determine
+     * if the file should be copied into the zip or just linked
      */
-    static function get_resources_from_source_html($source_html, $is_file = false, $type = null, $recursivity = 1) {
+    static function get_resources_from_source_html($source_html, $is_file = false, $type = null, $recursivity = 1)
+    {
         $max = 5;
         $attributes = array();
         $wanted_attributes = array('src', 'url', '@import', 'href', 'value', 'flashvars');
@@ -1668,7 +1701,9 @@ class DocumentManager
                                     } else {
                                         $files_list[] = array($source, 'local', 'abs');
                                     }
-                                    continue; //skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't)
+                                    /* skipping anything else to avoid two entries
+                                    (while the others can have sub-files in their url, flv's can't)*/
+                                    continue;
                                 }
                             }
                             if (strpos($source, '://') > 0) {
@@ -1861,10 +1896,12 @@ class DocumentManager
      *
      * @param    string  HTML attribute string
      * @param	 array	 List of attributes that we want to get back
+     * @param    array
      * @return   array   An associative array of attributes
-     * @author 	 Based on a function from the HTML_Common2 PEAR module
+     * @author 	 Based on a function from the HTML_Common2 PEAR module     *
      */
-    static function parse_HTML_attributes($attrString, $wanted = array(), $explode_variables = array()) {
+    static function parse_HTML_attributes($attrString, $wanted = array(), $explode_variables = array())
+    {
         $attributes = array();
         $regs = array();
         $reduced = false;
@@ -1940,8 +1977,6 @@ class DocumentManager
                     }
                 }
             }
-        } else {
-            //error_log('preg_match did not find anything', 0);
         }
         return $attributes;
     }
@@ -1951,9 +1986,16 @@ class DocumentManager
      * @param string		content html
      * @param string		origin course code
      * @param string		destination course directory
+     * @param string
      * @return string	new content html with replaced urls or return false if content is not a string
      */
-    static function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory, $origin_course_path_from_zip = null, $origin_course_info_path = null) {
+    static function replace_urls_inside_content_html_from_copy_course(
+        $content_html,
+        $origin_course_code,
+        $destination_course_directory,
+        $origin_course_path_from_zip = null,
+        $origin_course_info_path = null
+    ) {
         require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
 
         if (empty($content_html)) {
@@ -2078,7 +2120,8 @@ class DocumentManager
      * @param string     destination
      * @return string    new content html with replaced urls or return false if content is not a string
      */
-    function replace_urls_inside_content_html_when_moving_file($file_name, $original_path, $destiny_path) {
+    function replace_urls_inside_content_html_when_moving_file($file_name, $original_path, $destiny_path)
+    {
         if (substr($original_path, strlen($original_path) - 1, strlen($original_path)) == '/') {
             $original = $original_path . $file_name;
         } else {
@@ -2225,7 +2268,8 @@ class DocumentManager
      * @param int $document_id
      * @param string $course_code
      */
-    public static function export_to_pdf($document_id, $course_code) {
+    public static function export_to_pdf($document_id, $course_code)
+    {
         require_once api_get_path(LIBRARY_PATH) . 'pdf.lib.php';
         $course_data = api_get_course_info($course_code);
         $document_data = self::get_document_data_by_id($document_id, $course_code);
@@ -2328,7 +2372,8 @@ class DocumentManager
      * Obtains the text inside the file with the right parser
 
      */
-    function get_text_content($doc_path, $doc_mime) {
+    function get_text_content($doc_path, $doc_mime)
+    {
         // TODO: review w$ compatibility
         // Use usual exec output lines array to store stdout instead of a temp file
         // because we need to store it at RAM anyway before index on ChamiloIndexer object
@@ -2408,7 +2453,8 @@ class DocumentManager
      * @param  int $to_group_id (to calculate group document space)
      * @return int total size
      */
-    static function documents_total_space($course_id = null, $group_id = null, $session_id = null) {
+    static function documents_total_space($course_id = null, $group_id = null, $session_id = null)
+    {
         $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
 
@@ -2454,7 +2500,8 @@ class DocumentManager
     /**
      *  Here we count 1 kilobyte = 1000 byte, 12 megabyte = 1000 kilobyte.
      */
-    static function display_quota($course_quota, $already_consumed_space) {
+    static function display_quota($course_quota, $already_consumed_space)
+    {
         $course_quota_m = round($course_quota / 1000000);
         $already_consumed_space_m = round($already_consumed_space / 1000000);
 
@@ -2502,7 +2549,8 @@ class DocumentManager
      *
      *  Here we count 1 kilobyte = 1000 byte, 12 megabyte = 1000 kilobyte.
      */
-    static function display_simple_quota($course_quota, $already_consumed_space) {
+    static function display_simple_quota($course_quota, $already_consumed_space)
+    {
         $course_quota_m = round($course_quota / 1000000);
         $already_consumed_space_m = round($already_consumed_space / 1000000, 2);
         $percentage = $already_consumed_space / $course_quota * 100;
@@ -2518,7 +2566,6 @@ class DocumentManager
      *
      * @author Bert Vanderkimpen
      * @param  int file_size size of the file in byte
-     * @param array $_course
      * @param  int max_dir_space maximum size
      * @return boolean true if there is enough space, false otherwise
      *
@@ -2535,11 +2582,11 @@ class DocumentManager
     }
 
     /**
-     *
      * @param array paremeters: count, url, extension
      * @return string
      */
-    static function generate_jplayer_jquery($params = array()) {
+    static function generate_jplayer_jquery($params = array())
+    {
         $js_path = api_get_path(WEB_LIBRARY_PATH) . 'javascript/';
 
         $jplayer_definition = ' $("#jquery_jplayer_' . $params['count'] . '").jPlayer({
@@ -2567,9 +2614,11 @@ class DocumentManager
      *
      * Shows a play icon next to the document title in the document list
      * @param int
+     * @param string
      * @return string	html content
      */
-    static function generate_media_preview($i, $type = 'simple') {
+    static function generate_media_preview($i, $type = 'simple')
+    {
         $i = intval($i);
 
         $extra_controls = $progress = '';
@@ -2602,7 +2651,12 @@ class DocumentManager
         return $html;
     }
 
-    static function generate_video_preview($document_data = array()) {
+    /**
+     * @param array $document_data
+     * @return string
+     */
+    static function generate_video_preview($document_data = array())
+    {
         $html = '
         <div id="jp_container_1" class="jp-video">
 			<div class="jp-type-single">
@@ -2653,7 +2707,24 @@ class DocumentManager
         return $html;
     }
 
-    static function get_document_preview($course_info, $lp_id = false, $target = '', $session_id = 0, $add_move_button = false, $filter_by_folder = null, $overwrite_url = null) {
+    /**
+     * @param array $course_info
+     * @param bool $lp_id
+     * @param string $target
+     * @param int $session_id
+     * @param bool $add_move_button
+     * @param string $filter_by_folder
+     * @param string $overwrite_url
+     * @return string
+     */
+    static function get_document_preview(
+        $course_info, $lp_id = false,
+        $target = '',
+        $session_id = 0,
+        $add_move_button = false,
+        $filter_by_folder = null,
+        $overwrite_url = null
+    ) {
         if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) {
             return '';
         }
@@ -2843,11 +2914,26 @@ class DocumentManager
      * Generate and return an HTML list of resources based on a given array.
      * This list is used to show the course creator a list of available resources to choose from
      * when creating a learning path.
-     * @param	array	Array of elements to add to the list
-     * @param	integer Enables the tree display by shifting the new elements a certain distance to the right
-     * @return	string	The HTML list
+     * @param array $course_info
+     * @param int $session_id
+     * @param array $resources_sorted
+     * @param int $num
+     * @param bool $lp_id
+     * @param string $target
+     * @param bool $add_move_button
+     * @param string $overwrite_url
+     * @return string
      */
-    public static function write_resources_tree($course_info, $session_id, $resources_sorted, $num = 0, $lp_id = false, $target = '', $add_move_button = false, $overwrite_url = null) {
+    public static function write_resources_tree(
+        $course_info,
+        $session_id,
+        $resources_sorted,
+        $num = 0,
+        $lp_id = false,
+        $target = '',
+        $add_move_button = false,
+        $overwrite_url = null
+    ) {
         require_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php';
 
         $img_path = api_get_path(WEB_IMG_PATH);
@@ -2983,7 +3069,8 @@ class DocumentManager
      * @param int $user_id
      * @return bool
      */
-    public static function check_visibility_tree($doc_id, $course_code, $session_id, $user_id) {
+    public static function check_visibility_tree($doc_id, $course_code, $session_id, $user_id)
+    {
         $document_data = self::get_document_data_by_id($doc_id, $course_code);
 
         if (!empty($document_data)) {
@@ -3021,7 +3108,15 @@ class DocumentManager
      * @param   bool    When set to true, this runs the indexer without actually saving anything to any database
      * @return  bool    Returns true on presumed success, false on failure
      */
-    public function index_document($docid, $course_code, $session_id = 0, $lang = 'english', $specific_fields_values = array(), $if_exists = '', $simulation = false) {
+    public function index_document(
+        $docid,
+        $course_code,
+        $session_id = 0,
+        $lang = 'english',
+        $specific_fields_values = array(),
+        $if_exists = '',
+        $simulation = false
+    ) {
         if (api_get_setting('search_enabled') !== 'true') {
             return false;
         }
@@ -3210,16 +3305,18 @@ class DocumentManager
     /**
      * @return array
      */
-    public static function get_web_odf_extension_list() {
+    public static function get_web_odf_extension_list()
+    {
         return array('ods', 'odt');
     }
 
     /**
-     * @param $path
+     * @param string $path
      * @param bool $is_certificate_mode
      * @return bool
      */
-    public static function is_folder_to_avoid($path, $is_certificate_mode = false) {
+    public static function is_folder_to_avoid($path, $is_certificate_mode = false)
+    {
         $folders_to_avoid = array(
             '/HotPotatoes_files',
             '/certificates',
@@ -3268,7 +3365,8 @@ class DocumentManager
     /**
      * @return array
      */
-    static function get_system_folders() {
+    static function get_system_folders()
+    {
         $system_folders = array(
             '/certificates',
             '/chat_files',
@@ -3337,9 +3435,5 @@ class DocumentManager
                 );
             }
         }
-
     }
-
 }
-
-//end class DocumentManager

+ 64 - 41
main/inc/lib/sessionmanager.lib.php

@@ -23,7 +23,7 @@ class SessionManager
     /**
     * Fetches a session from the database
     * @param   int     Session ID
-    * @return  array   Session details (id, id_coach, name, nbr_courses, nbr_users, nbr_classes, date_start, date_end, nb_days_access_before_beginning,nb_days_access_after_end, session_admin_id)
+    * @return  array   Session details
     */
     public static function fetch($id)
     {
@@ -57,11 +57,28 @@ class SessionManager
     * @param  integer     Visibility after end date (0 = read-only, 1 = invisible, 2 = accessible)
     * @param  string      Start limit = true if the start date has to be considered
     * @param  string      End limit = true if the end date has to be considered
+    * @param  string $fix_name
     * @todo use an array to replace all this parameters or use the model.lib.php ...
     * @return mixed       Session ID on success, error message otherwise
     **/
-    public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after, $nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true, $fix_name = false)
-    {
+    public static function create_session(
+        $sname,
+        $syear_start,
+        $smonth_start,
+        $sday_start,
+        $syear_end,
+        $smonth_end,
+        $sday_end,
+        $snb_days_acess_before,
+        $snb_days_acess_after,
+        $nolimit,
+        $coach_username,
+        $id_session_category,
+        $id_visibility,
+        $start_limit = true,
+        $end_limit = true,
+        $fix_name = false
+    ) {
 		global $_configuration;
 
 		//Check portal limits
@@ -76,19 +93,19 @@ class SessionManager
             }
         }
 
-		$name                 = Database::escape_string(trim($sname));
-		$year_start           = intval($syear_start);
-		$month_start          = intval($smonth_start);
-		$day_start            = intval($sday_start);
-		$year_end             = intval($syear_end);
-		$month_end            = intval($smonth_end);
-		$day_end              = intval($sday_end);
-		$nb_days_acess_before = intval($snb_days_acess_before);
-		$nb_days_acess_after  = intval($snb_days_acess_after);
-		$id_session_category  = intval($id_session_category);
-		$id_visibility        = intval($id_visibility);
-		$tbl_user		      = Database::get_main_table(TABLE_MAIN_USER);
-		$tbl_session	      = Database::get_main_table(TABLE_MAIN_SESSION);
+        $name                 = Database::escape_string(trim($sname));
+        $year_start           = intval($syear_start);
+        $month_start          = intval($smonth_start);
+        $day_start            = intval($sday_start);
+        $year_end             = intval($syear_end);
+        $month_end            = intval($smonth_end);
+        $day_end              = intval($sday_end);
+        $nb_days_acess_before = intval($snb_days_acess_before);
+        $nb_days_acess_after  = intval($snb_days_acess_after);
+        $id_session_category  = intval($id_session_category);
+        $id_visibility        = intval($id_visibility);
+        $tbl_user		      = Database::get_main_table(TABLE_MAIN_USER);
+        $tbl_session	      = Database::get_main_table(TABLE_MAIN_SESSION);
 
 		if (is_int($coach_username)) {
 			$id_coach = $coach_username;
@@ -200,7 +217,7 @@ class SessionManager
         $tbl_session            = Database::get_main_table(TABLE_MAIN_SESSION);
         $tbl_session_category   = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
         $tbl_user               = Database::get_main_table(TABLE_MAIN_USER);
-        $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
+        $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
         $tbl_session_rel_user 	= Database::get_main_table(TABLE_MAIN_SESSION_USER);
 
         $where = 'WHERE 1=1 ';
@@ -492,6 +509,11 @@ class SessionManager
 	 * @param 	integer		nolimit
 	 * @param 	integer		id_coach
 	 * @param 	integer		id_session_category
+     * @param   int $id_visibility
+     * @param bool
+     * @param bool
+     * @param string $description
+     * @param int  $showDescription
 	 * @return $id;
 	 * The parameter id is a primary key
 	**/
@@ -514,8 +536,7 @@ class SessionManager
         $end_limit = true,
         $description = null,
         $showDescription = null
-    )
-    {
+    ) {
 		$name = trim(stripslashes($name));
 		$year_start=intval($year_start);
 		$month_start=intval($month_start);
@@ -929,8 +950,9 @@ class SessionManager
      * @param	bool	Whether to unsubscribe existing users (true, default) or not (false)
      * @return	void	Nothing, or false on error
      **/
-     public static function add_courses_to_session ($id_session, $course_list, $empty_courses = true) {
-     	// security checks
+     public static function add_courses_to_session($id_session, $course_list, $empty_courses = true)
+     {
+     	// Security checks
      	if ($id_session!= strval(intval($id_session))) {
             return false;
         }
@@ -1070,15 +1092,15 @@ class SessionManager
 				$order = $row[0]+1;
 			}
 
-			$sql = "INSERT INTO $t_sf
-						                SET field_type = '$fieldtype',
-						                field_variable = '$fieldvarname',
-						                field_display_text = '$fieldtitle',
-						                field_order = '$order',
-						                tms = FROM_UNIXTIME($time)";
-			$result = Database::query($sql);
+			$sql = "INSERT INTO $t_sf SET
+                    field_type = '$fieldtype',
+                    field_variable = '$fieldvarname',
+                    field_display_text = '$fieldtitle',
+                    field_order = '$order',
+                    tms = FROM_UNIXTIME($time)";
+			Database::query($sql);
 
-			$field_id=Database::insert_id();
+			$field_id = Database::insert_id();
 		}
 		return $field_id;
 	}
@@ -1325,7 +1347,7 @@ class SessionManager
         Database::query($sql);
 
 		$sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (".$id_checked.")";
-		$result = @Database::query($sql);
+		$result = Database::query($sql);
 		while ($rows = Database::fetch_array($result)) {
 			$session_id = $rows['id'];
 			if ($delete_session) {
@@ -1337,8 +1359,7 @@ class SessionManager
 			}
 		}
 		$sql = "DELETE FROM $tbl_session_category WHERE id IN (".$id_checked.")";
-		$rs = Database::query($sql);
-		$result = Database::affected_rows();
+		Database::query($sql);
 
 		// Add event to system log
 		$user_id = api_get_user_id();
@@ -1540,6 +1561,7 @@ class SessionManager
     * Subscribes sessions to human resource manager (Dashboard feature)
     * @param	int 		Human Resource Manager id
     * @param	array 		Sessions id
+    * @return int
     **/
 	public static function suscribe_sessions_to_hr_manager($hr_manager_id, $sessions_list)
     {
@@ -2047,17 +2069,17 @@ class SessionManager
     /**
      * @param string $file
      * @param bool $updatesession options:
-     * true: if the session exists it will be updated
-     * false: if session exists a new session will be created adding a counter session1, session2, etc
+     *  true: if the session exists it will be updated.
+     *  false: if session exists a new session will be created adding a counter session1, session2, etc
      * @param int $user_id
      * @param $logger
-     * @param array convert a file row to an extra field. Example in CSV file there's a SessionID then it will
+     * @param array $extraFields convert a file row to an extra field. Example in CSV file there's a SessionID then it will
      * converted to extra_external_session_id if you set this: array('SessionId' => 'extra_external_session_id')
-     * @param array extra fields
-     * @param string extra field id
+     * @param string $extraFieldId
      * @param int $daysCoachAccessBeforeBeginning
      * @param int $daysCoachAccessAfterBeginning
      * @param int $sessionVisibility
+     * @param array $fieldsToAvoidUpdate
      * @return array
      */
     static function importCSV(
@@ -2238,7 +2260,6 @@ class SessionManager
 
                         // We get the last insert id.
                         $my_session_result = SessionManager::get_session_by_name($enreg['SessionName']);
-
                         $session_id = $my_session_result['id'];
 
                         if ($debug) {
@@ -2257,7 +2278,7 @@ class SessionManager
 
                         // Updating the session.
                         $params = array(
-                            'id_coach' =>  $coach_id,
+                            'id_coach' => $coach_id,
                             'date_start' => $date_start,
                             'date_end' => $date_end,
                             'visibility' => $visibility,
@@ -2290,6 +2311,7 @@ class SessionManager
                             }
                         }
 
+                        // Delete session-user relation only for students
                         $sql = "DELETE FROM $tbl_session_user
                                 WHERE id_session = '$session_id' AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
                         Database::query($sql);
@@ -2297,7 +2319,7 @@ class SessionManager
                         $sql = "DELETE FROM $tbl_session_course WHERE id_session = '$session_id'";
                         Database::query($sql);
 
-                        // Delete session course user relation ships *only* for students
+                        // Delete session-course-user relation ships *only* for students
                         $sql = "DELETE FROM $tbl_session_course_user WHERE id_session = '$session_id' AND status <> 2";
                         Database::query($sql);
                     }
@@ -2306,7 +2328,7 @@ class SessionManager
 
                 $users = explode('|', $enreg['Users']);
 
-                // Adding the relationship "Session - User".
+                // Adding the relationship "Session - User" for students
                 if (is_array($users)) {
                     foreach ($users as $user) {
                         $user_id = UserManager::get_user_id_from_username($user);
@@ -2394,6 +2416,7 @@ class SessionManager
                             }
                         }
 
+
                         // Adding Students, updating relationship "Session - Course - User".
                         foreach ($course_users as $user) {
                             $user = trim($user);

+ 3 - 3
main/user/user.php

@@ -419,14 +419,14 @@ function get_number_of_users() {
 		$a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0);
 	}
 	foreach ($a_course_users as $user_id => $o_course_user) {
-		if ((isset($_GET['keyword']) && search_keyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
+		if ((isset($_GET['keyword']) && searchUserKeyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
 			$counter++;
 		}
 	}
 	return $counter;
 }
 
-function search_keyword($firstname, $lastname, $username, $official_code, $keyword) {
+function searchUserKeyword($firstname, $lastname, $username, $official_code, $keyword) {
 	if (api_strripos($firstname, $keyword) !== false || api_strripos($lastname, $keyword) !== false || api_strripos($username, $keyword) !== false || api_strripos($official_code, $keyword) !== false) {
 		return true;
 	} else {
@@ -491,7 +491,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
     $a_course_users = CourseManager :: get_user_list_from_course_code($course_code, $session_id, $limit, $order_by);
 
 	foreach ($a_course_users as $user_id => $o_course_user) {
-		if ((isset($_GET['keyword']) && search_keyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
+		if ((isset($_GET['keyword']) && searchUserKeyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
 
 			$groups_name = GroupManager :: get_user_group_name($user_id);
 			$temp = array();

+ 0 - 31
main/work/add_document.php

@@ -120,34 +120,3 @@ if (empty($docId)) {
     $form->display();
 }
 
-/**
- * DB changes needed for new features in work tool
- *
- *
- * 1. Create tables
- *
-CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
-    id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
-    work_id INT NOT NULL,
-    document_id INT NOT NULL,
-    c_id INT NOT NULL
-);
-
-CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
-    id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
-    work_id INT NOT NULL,
-    user_id INT NOT NULL,
-    c_id INT NOT NULL
-);
-
-CREATE TABLE IF NOT EXISTS c_student_publication_comment (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,  work_id INT NOT NULL,  c_id INT NOT NULL,  comment text,  user_id int NOT NULL,  sent_at datetime NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE c_student_publication ADD COLUMN document_id int DEFAULT 0;
- *
- * Update configuration.php:
- *  $_configuration['add_document_to_work'] = true;
-
- *
-*/
-
-

+ 29 - 0
main/work/extra.sql

@@ -0,0 +1,29 @@
+-- Extra DB changes needed for new features in work tool
+
+CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
+    id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+    work_id INT NOT NULL,
+    document_id INT NOT NULL,
+    c_id INT NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
+    id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+    work_id INT NOT NULL,
+    user_id INT NOT NULL,
+    c_id INT NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS c_student_publication_comment (
+  id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
+  work_id INT NOT NULL,
+  c_id INT NOT NULL,
+  comment text,
+  user_id int NOT NULL,
+  sent_at datetime NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE c_student_publication ADD COLUMN document_id int DEFAULT 0;
+
+-- Update configuration.php:
+-- $_configuration['add_document_to_work'] = true;