diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 903b9f0931..990bac7df7 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3902,7 +3902,7 @@ class CourseManager { static function sort_pictures($files, $type) { $pictures = array(); foreach ($files as $key => $value){ - if ($value[$type] != '') { + if (isset($value[$type]) && !empty($value[$type])) { $pictures[][$type] = $value[$type]; } } @@ -3933,7 +3933,7 @@ class CourseManager { $audio_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/audio/'; $flash_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/flash/'; $video_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/video/'; - $cert_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/certificates/'; + $cert_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/certificates/'; $course_documents_folder_images = $sys_course_path.$course_repository.'/document/images/gallery/'; $course_documents_folder_audio = $sys_course_path.$course_repository.'/document/audio/'; @@ -3942,7 +3942,7 @@ class CourseManager { $course_documents_folder_cert = $sys_course_path.$course_repository.'/document/certificates/'; /* Images */ - $files = self::browse_folders($img_code_path, $files, 'images'); + $files = self::browse_folders($img_code_path, array(), 'images'); $pictures_array = self::sort_pictures($files, 'dir'); $pictures_array = array_merge($pictures_array, self::sort_pictures($files, 'file')); @@ -4271,14 +4271,12 @@ class CourseManager { $default_document_array = array(); foreach ($folders_to_copy_from_default_course as $folder) { $default_course_folder_path = $default_course_path.$folder.'/'; - $files = browse_folders($default_course_folder_path, array(), $folder); - $sorted_array = sort_pictures($files, 'dir'); - $sorted_array = array_merge($sorted_array, sort_pictures($files, 'file')); + $files = self::browse_folders($default_course_folder_path, array(), $folder); + $sorted_array = self::sort_pictures($files, 'dir'); + $sorted_array = array_merge($sorted_array, self::sort_pictures($files, 'file')); $default_document_array[$folder] = $sorted_array; } - //echo '
'; print_r($default_document_array);exit;
-
             //Light protection (adding index.html in every document folder)
             $htmlpage = "\n\n \n \n Not authorized\n  \n  \n  \n";
 
diff --git a/main/inc/lib/database.constants.inc.php b/main/inc/lib/database.constants.inc.php
index 6250e77972..0fda7f4644 100644
--- a/main/inc/lib/database.constants.inc.php
+++ b/main/inc/lib/database.constants.inc.php
@@ -73,7 +73,7 @@ define('TABLE_MAIN_USER_REL_TAG',       'user_rel_tag');
 define('TABLE_MAIN_GROUP',              'groups');
 define('TABLE_MAIN_USER_REL_GROUP',     'group_rel_user');
 define('TABLE_MAIN_GROUP_REL_TAG',      'group_rel_tag');
-define('TABLE_MAIN_GROUP_REL_GROUP',		'group_rel_group');
+define('TABLE_MAIN_GROUP_REL_GROUP',    'group_rel_group');
 
 // Search engine
 define('TABLE_MAIN_SPECIFIC_FIELD',         'specific_field');
diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php
index f9b7237671..6a87bba9e0 100755
--- a/main/inc/lib/document.lib.php
+++ b/main/inc/lib/document.lib.php
@@ -469,14 +469,16 @@ class DocumentManager
         $_course,
         $path = '/',
         $to_group_id = 0,
-        $to_user_id = null,
+        $to_user_id = 0,
         $can_see_invisible = false,
         $search = false
     ) {
         $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
         $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
 
-        if (!is_null($to_user_id)) {
+        $to_user_id = Database::escape_string($to_user_id);
+
+        if (!empty($to_user_id)) {
             $to_field = 'last.to_user_id';
             $to_value = $to_user_id;
         } else {
@@ -486,7 +488,7 @@ class DocumentManager
 
         //escape underscores in the path so they don't act as a wildcard
         $path = Database::escape_string(str_replace('_', '\_', $path));
-        $to_user_id = Database::escape_string($to_user_id);
+
         $to_value = Database::escape_string($to_value);
 
         $visibility_bit = ' <> 2';
@@ -497,8 +499,7 @@ class DocumentManager
 
         //condition for the session
         $current_session_id = api_get_session_id();
-        $condition_session = " AND (id_session = '$current_session_id' OR id_session = '0')";
-
+        $condition_session = " AND (id_session = '$current_session_id' OR id_session = '0' OR id_session IS NULL)";
 
         //condition for search (get ALL folders and documents)
         $sql = "SELECT  docs.id,
@@ -513,14 +514,13 @@ class DocumentManager
                         last.lastedit_date,
                         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']})
-                    WHERE
-                        docs.path LIKE '".$path.$added_slash."%' AND
-                        docs.path NOT LIKE '".$path.$added_slash."%/%' AND
-                        ".$to_field." = ".$to_value." AND
-                        last.visibility".$visibility_bit.$condition_session;
-
+                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']})
+                WHERE
+                    docs.path LIKE '".$path.$added_slash."%' AND
+                    docs.path NOT LIKE '".$path.$added_slash."%/%' AND
+                    ".$to_field." = ".$to_value." AND
+                    last.visibility".$visibility_bit.$condition_session;
         $result = Database::query($sql);
 
         $doc_list = array();