Bladeren bron

Fixing folder selector see #5555 + removing some comments

Julio Montoya 12 jaren geleden
bovenliggende
commit
52135886ba
3 gewijzigde bestanden met toevoegingen van 67 en 38 verwijderingen
  1. 3 3
      main/document/document.inc.php
  2. 7 3
      main/document/document.php
  3. 57 32
      main/inc/lib/document.lib.php

+ 3 - 3
main/document/document.inc.php

@@ -31,7 +31,7 @@ function build_directory_selector($folders, $document_id, $group_dir = '', $chan
         $sql = "SELECT * FROM $doc_table WHERE filetype = 'folder' AND c_id = $course_id AND path IN ('".$folder_sql."')";
         $res = Database::query($sql);
         $folder_titles = array();
-        while ($obj = Database::fetch_object($res)) {
+        while ($obj = Database::fetch_object($res)) {        
             $folder_titles[$obj->path] = $obj->title;
         }
     }
@@ -86,8 +86,8 @@ function build_directory_selector($folders, $document_id, $group_dir = '', $chan
             }
         }
     }
-    $form = $form->toHtml();
-    return $form;
+    $html = $form->toHtml();
+    return $html;
 }
 
 

+ 7 - 3
main/document/document.php

@@ -1055,7 +1055,11 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
         if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
             $row[] = $document_data['path'];
         }
-
+        
+        if (DocumentManager::is_folder_to_avoid($document_data['path'])) {
+            continue;
+        }
+/*
         // Hide HotPotatoes Certificates and all css folders
         if ($document_data['path'] == '/HotPotatoes_files' || $document_data['path'] == '/certificates' || basename($document_data['path']) == 'css') {
             continue;
@@ -1074,7 +1078,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
         //Admin setting for Hide/Show chat history folder
         if (api_get_setting('show_chat_folder') == 'false' && $document_data['path'] == '/chat_files') {
             continue;
-        }
+        }*/
 
         // Show the owner of the file only in groups
         $user_link = '';
@@ -1104,7 +1108,7 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
 
         // Comments => display comment under the document name
         $display_size = format_file_size($size);
-        $row[] = '<span style="display:none;">' . $size . '</span>' . $invisibility_span_open . $display_size . $invisibility_span_close;
+        $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
 
         // Last edit date
         

+ 57 - 32
main/inc/lib/document.lib.php

@@ -470,12 +470,7 @@ class DocumentManager {
         $to_user_id = Database::escape_string($to_user_id);
         $to_value	= Database::escape_string($to_value);
 
-        //if they can't see invisible files, they can only see files with visibility 1
-        //$visibility_bit = ' = 1';
-        //if they can see invisible files, only deleted files (visibility 2) are filtered out
-        //if ($can_see_invisible) {
         $visibility_bit = ' <> 2';
-        //}
 
         //the given path will not end with a slash, unless it's the root '/'
         //so no root -> add slash
@@ -485,10 +480,6 @@ class DocumentManager {
         $current_session_id = api_get_session_id();
         $condition_session = " AND (id_session = '$current_session_id' OR id_session = '0')";
 
-        if (!$can_see_invisible) {
-            //$condition_session = " AND (id_session = '$current_session_id' ) ";
-        }
-
         //condition for search (get ALL folders and documents)
   
         $sql = "SELECT  docs.id, 
@@ -504,14 +495,12 @@ 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 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
-                        last.tool = '".TOOL_DOCUMENT."' AND
+                        docs.path NOT LIKE '".$path.$added_slash."%/%' AND                        
                         ".$to_field." = ".$to_value." AND 
-                        last.visibility".$visibility_bit.$condition_session;
-       
+                        last.visibility".$visibility_bit.$condition_session;        
         $result = Database::query($sql);
 
         $doc_list = array();
@@ -569,8 +558,7 @@ class DocumentManager {
                 //Checking disponibility in a session
                 foreach($my_repeat_ids as $id) {
                     foreach($doc_list as $row ) {
-                        if ($id == $row['id']) {
-                            //var_dump($row['visibility'].' - '.$row['session_id'].' - '.$row['item_property_session_id']);
+                        if ($id == $row['id']) {                            
                             if ($row['visibility'] == 0 && $row['item_property_session_id'] == 0) {
                                 $delete_repeated[$id] = true;
                             }
@@ -581,18 +569,13 @@ class DocumentManager {
                     }
                 }
 
-                //var_dump($delete_repeated);
-
-                foreach($doc_list as $key=>$row) {
-                    //&& !in_array($row['id'],$my_repeat_ids)
-                    //var_dump($row['id'].' - '.$row['visibility']);
+                foreach($doc_list as $key=>$row) {                    
                     if (in_array($row['visibility'], array('0','2')) && !in_array($row['id'],$my_repeat_ids) ) {
                         $ids_to_remove[] = $row['id'];
                         unset($doc_list[$key]);
                     }
                 }
-                //var_dump($ids_to_remove);
-
+                
                 foreach($document_data as $row) {
                     if (in_array($row['id'], $ids_to_remove)) {
                         unset($document_data[$row['id']]);
@@ -607,12 +590,12 @@ class DocumentManager {
                 foreach ($document_data as $row) {
                 	$is_visible = DocumentManager::check_visibility_tree($row['id'], $_course['code'], $current_session_id, api_get_user_id());
                 	if ($is_visible) {
-                		$final_document_data[$row['id']]=$row;
+                		$final_document_data[$row['id']] = $row;
                 	}
                 }
             } else {
             	$final_document_data = $document_data;
-            }
+            }            
             return $final_document_data;
         } else {
             //display_error("Error getting document info from database (".Database::error().")!");
@@ -638,19 +621,21 @@ class DocumentManager {
             //condition for the session
             $session_id = api_get_session_id();
             $condition_session = api_get_session_condition($session_id);
-            $sql = "SELECT DISTINCT docs.id, path FROM  ".$TABLE_ITEMPROPERTY."  AS last, ".$TABLE_DOCUMENT."  AS docs
-					WHERE 	docs.id 			= last.ref AND
-							docs.filetype 		= 'folder' AND
-							last.tool 			= '".TOOL_DOCUMENT."' AND
+            $sql = "SELECT DISTINCT docs.id, path 
+                    FROM $TABLE_ITEMPROPERTY  AS last INNER JOIN $TABLE_DOCUMENT  AS docs
+                    ON (docs.id = last.ref AND last.tool = '".TOOL_DOCUMENT."' AND last.c_id = {$_course['real_id']} AND docs.c_id = {$_course['real_id']} )
+					WHERE 	
+							docs.filetype 		= 'folder' AND							
 							last.to_group_id	= ".$to_group_id." AND
-            				last.visibility 	<> 2 $condition_session AND
-                            last.c_id           = {$_course['real_id']} AND
-            				docs.c_id 			= {$_course['real_id']} ";
+            				last.visibility 	<> 2 $condition_session ";
 
             $result = Database::query($sql);
 
             if ($result && Database::num_rows($result) != 0) {
                 while ($row = Database::fetch_array($result, 'ASSOC')) {
+                    if (DocumentManager::is_folder_to_avoid($row['path'])) {
+                        continue;
+                    }
                     $document_folders[$row['id']] = $row['path'];
                 }
                 //sort($document_folders);
@@ -3153,5 +3138,45 @@ class DocumentManager {
     public static function get_web_odf_extension_list(){
         return array('ods', 'odt');
     }
+    
+    public static function is_folder_to_avoid($path) {
+        $folders_to_avoid = array(
+            '/HotPotatoes_files',
+            '/certificates',             
+        );        
+        
+       if (basename($path) == 'css') {
+           return true;
+       }
+       
+       //Skip hotpotatoes results
+       if (strstr($path, 'HotPotatoes_files')) {
+           return true;
+       }
+
+        //Admin setting for Hide/Show the folders of all users
+        if (api_get_setting('show_users_folders') == 'false') {
+            $folders_to_avoid[] =  '/shared_folder';
+            
+            if (strstr($path, 'shared_folder_session_')) {
+                return true;
+            }
+        }
+
+        //Admin setting for Hide/Show Default folders to all users
+        if (api_get_setting('show_default_folders') == 'false') {
+            $folders_to_avoid[] =  '/images';
+            $folders_to_avoid[] =  '/flash';
+            $folders_to_avoid[] =  '/audio';
+            $folders_to_avoid[] =  '/video';
+        }
+
+        //Admin setting for Hide/Show chat history folder
+        if (api_get_setting('show_chat_folder') == 'false') {
+            $folders_to_avoid[] =  '/chat_files';
+        }
+        return in_array($path, $folders_to_avoid);
+        
+    }
 }
 //end class DocumentManager