Browse Source

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

Julio Montoya 11 years ago
parent
commit
11d6bb693a

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

@@ -591,19 +591,19 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
             $modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
         } else {
             if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id()) == $id) {
-                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
+                $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
             } else {
                 if ($is_certificate_mode) {
-                    $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
+                    $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
                 } else {
                     if (api_get_session_id()) {
                         if ($document_data['session_id'] == api_get_session_id()) {
-                            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
+                            $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
                         } else {
                             $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
                         }
                     } else {
-                        $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;delete=' . urlencode($path) . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
+                        $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&amp;deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
                     }
                 }
             }

+ 7 - 6
main/document/document.php

@@ -666,27 +666,28 @@ if (
 /* 	DELETE FILE OR DIRECTORY */
 //Only teacher and all users into their group
 if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
-    if (isset($_GET['delete'])) {
+    if (isset($_GET['deleteid'])) {
         if (!$is_allowed_to_edit) {
             if (api_is_coach()) {
-                if (!DocumentManager::is_visible($_GET['delete'], $_course, $session_id)) {
+                if (!DocumentManager::is_visible_by_id($_GET['deleteid'], $_course, $session_id, api_get_user_id())) {
                     api_not_allowed();
                 }
             }
-            if (DocumentManager::check_readonly($_course, api_get_user_id(), $_GET['delete'], '', true)) {
+            if (DocumentManager::check_readonly($_course, api_get_user_id(), '', $_GET['deleteid'], true)) {
                 api_not_allowed();
             }
         }
 
-        $document_data = DocumentManager::get_document_id($_course, $_GET['delete']);
+        $document_data = intval($_GET['deleteid']);
+        $documentInfo = DocumentManager::get_document_data_by_id($_GET['deleteid'], $_course['code'], false, $session_id);
         // Check whether the document is in the database
         if (!empty($document_data)) {
-            if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
+            if (DocumentManager::delete_document($_course, null, $base_work_dir, api_get_session_id(), $_GET['deleteid'])) {
                 $certificateId = isset($_GET['delete_certificate_id']) ? $_GET['delete_certificate_id'] : null;
                 DocumentManager::remove_attach_certificate(api_get_course_id(), $certificateId);
                 Display::display_confirmation_message(get_lang('DocDeleted'));
             } else {
-                Display::display_error_message(get_lang('DocDeleteError'));
+                Display::display_warning_message(get_lang('DocDeleteError'));
             }
         } else {
             Display::display_warning_message(get_lang('FileNotFound'));

+ 24 - 7
main/inc/lib/document.lib.php

@@ -780,8 +780,10 @@ class DocumentManager
             $sessionId = intval($sessionId);
         }
 
-        if (!(!empty($document_id) && is_numeric($document_id))) {
+        if (empty($document_id) || !is_numeric($document_id)) {
             $document_id = self::get_document_id($_course, $file, $sessionId);
+        } else {
+            $document_id = intval($document_id);
         }
 
         $TABLE_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
@@ -936,15 +938,25 @@ class DocumentManager
      * @param array $_course
      * @param string $path, path stored in the database
      * @param string $base_work_dir, path to the documents folder
+     * @param int   $sessionId The ID of the session, if any
+     * @param int   $documentId The document id, if available
      * @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, $sessionId = null)
+    public static function delete_document($_course, $path = null, $base_work_dir, $sessionId = null, $documentId = null)
     {
         $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
-
-        if (empty($path) || empty($base_work_dir)) {
-            return false;
+        // @todo We should be able to get rid of this later when using only documentId (check further usage)
+        if (empty ($documentId)) {
+            if (empty($path) || empty($base_work_dir)) {
+                return false;
+            }
+        } else {
+            if (empty($base_work_dir)) {
+                return false;
+            }
+            $docInfo = self::get_document_data_by_id($documentId, $_course['code'], false, $sessionId);
+            $path = $docInfo['path'];
         }
 
         $course_id = $_course['real_id'];
@@ -960,7 +972,11 @@ class DocumentManager
         }
 
         // First, delete the actual document.
-        $document_id = self::get_document_id($_course, $path, $sessionId);
+        if (empty($documentId)) {
+            $document_id = self::get_document_id($_course, $path, $sessionId);
+        } else {
+            $document_id = intval($documentId);
+        }
 
         if (empty($document_id)) {
             return false;
@@ -1045,6 +1061,7 @@ class DocumentManager
         }
 
         // Checking inconsistency
+        //error_log('Doc status: (1 del db :'.($file_deleted_from_db?'yes':'no').') - (2 del disk: '.($file_deleted_from_disk?'yes':'no').') - (3 ren disk: '.($file_renamed_from_disk?'yes':'no').')');
         if ($file_deleted_from_db && $file_deleted_from_disk ||
             $file_deleted_from_db && $file_renamed_from_disk
         ) {
@@ -1137,7 +1154,7 @@ class DocumentManager
             return false;
         }
 
-        if (empty($session_id)) {
+        if (!empty($session_id)) {
             $session_id = intval($session_id);
         } else {
             $session_id = api_get_session_id();

+ 6 - 3
main/inc/lib/fileUpload.lib.php

@@ -286,7 +286,7 @@ function handle_uploaded_document(
 							return $file_path;
 						} else {
 							// Put the document data in the database
-							$document_id = add_document($_course, $file_path, 'file', $file_size, $document_name, null, 0, true);
+							$document_id = add_document($_course, $file_path, 'file', $file_size, $document_name, null, 0, true, null, $current_session_id);
 							if ($document_id) {
 								// Put the document in item_property update
 								api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id);
@@ -859,10 +859,13 @@ function filter_extension(&$filename) {
  * @param string $filetype
  * @param int $filesize
  * @param string $title
+ * @param int $session_id Session ID, if any
  * @return id if inserted document
  */
-function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true, $group_id = null) {
-	$session_id    = api_get_session_id();
+function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true, $group_id = null, $session_id = 0) {
+    if (empty($session_id)) {
+        $session_id    = api_get_session_id();
+    }
 	$readonly      = intval($readonly);
 	$comment       = Database::escape_string($comment);
 	$path          = Database::escape_string($path);

+ 1 - 0
main/inc/lib/main_api.lib.php

@@ -6196,6 +6196,7 @@ function api_is_global_chat_enabled(){
 
 /**
  * @todo Fix tool_visible_by_default_at_creation labels
+ * @todo Add sessionId parameter to avoid using context
  */
 function api_set_default_visibility($item_id, $tool_id, $group_id = null) {
     $original_tool_id = $tool_id;

+ 4 - 1
main/inc/local.inc.php

@@ -443,7 +443,7 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) {
                 /* >>>>>>>> External authentication modules <<<<<<<<< */
             } else { // no standard Chamilo login - try external authentification
                 //huh... nothing to do... we shouldn't get here
-                error_log('Chamilo Authentication file '. $extAuthSource[$uData['auth_source']]['login']. ' could not be found - this might prevent your system from doing the corresponding authentication process',0);
+                error_log('Chamilo Authentication file defined in $extAuthSource could not be found - this might prevent your system from doing the corresponding authentication process',0);
             }
         } else {
             // login failed, Database::num_rows($result) <= 0
@@ -920,6 +920,9 @@ $is_courseCoach     = false; //course coach
 //Course - User permissions
 $is_sessionAdmin    = false;
 $is_courseCoach     = false; //course coach
+$is_courseAdmin     = false;
+$is_courseTutor     = false;
+$is_courseMember    = false;
 
 if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset))
 {

+ 2 - 2
main/user/user_import.php

@@ -46,7 +46,7 @@ if ($form->validate()) {
     if (isset($_FILES['import_file']['size']) && $_FILES['import_file']['size'] !== 0) {
 
         $unsubscribe_users = isset($_POST['unsubscribe_users']) ? true : false;
-
+        //@todo : csv_to_array deprecated
         $users  = Import::csv_to_array($_FILES['import_file']['tmp_name']);
 
         $invalid_users  = array();
@@ -84,7 +84,7 @@ if ($form->validate()) {
                     if (!empty($current_user_list)) {
                         $user_ids = array();
                         foreach ($current_user_list as $user) {
-                            if ($user['status'] <> 1) {
+                            if (!CourseManager::is_course_teacher($user['user_id'], $course_code)) {
                                 $user_ids[]= $user['user_id'];
                             }
                         }