diff --git a/main/document/upload.php b/main/document/upload.php index 96ceb801ab..b06b439afb 100755 --- a/main/document/upload.php +++ b/main/document/upload.php @@ -4,7 +4,6 @@ /** * @package chamilo.document */ -// Including the global initialization file require_once __DIR__.'/../inc/global.inc.php'; // Including additional libraries diff --git a/main/inc/ajax/document.ajax.php b/main/inc/ajax/document.ajax.php index fcd70238b0..b070c29490 100755 --- a/main/inc/ajax/document.ajax.php +++ b/main/inc/ajax/document.ajax.php @@ -88,7 +88,7 @@ switch ($action) { foreach ($fileList as $file) { $globalFile = []; $globalFile['files'] = $file; - $result = DocumentManager::upload_document( + $document = DocumentManager::upload_document( $globalFile, $currentDirectory, '', @@ -101,15 +101,16 @@ switch ($action) { ); $json = []; - if (!empty($result) && is_array($result)) { + if (!empty($document)) { $json['name'] = Display::url( - api_htmlentities($result['title']), - api_htmlentities($result['url']), + api_htmlentities($document->getTitle()), + api_htmlentities($document->getTitle()), ['target' => '_blank'] ); - $json['url'] = $result['url']; - $json['size'] = format_file_size($file['size']); - $json['type'] = api_htmlentities($file['type']); + $json['url'] = '#'; + $json['size'] = format_file_size($document->getSize()); + //$json['type'] = api_htmlentities($file['type']); + $json['type'] = ''; $json['result'] = Display::return_icon( 'accept.png', get_lang('Uploaded') diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 8abf020f3c..8855ca596c 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -2826,7 +2826,7 @@ class DocumentManager * @param string $fileKey * @param bool $treat_spaces_as_hyphens * - * @return array|bool + * @return CDocument|false */ public static function upload_document( $files, @@ -2849,7 +2849,7 @@ class DocumentManager if (isset($files[$fileKey])) { $uploadOk = process_uploaded_file($files[$fileKey], $show_output); if ($uploadOk) { - $new_path = handle_uploaded_document( + $document = handle_uploaded_document( $course_info, $files[$fileKey], $base_work_dir, @@ -2868,7 +2868,7 @@ class DocumentManager ); // Showing message when sending zip files - if ($new_path === true && $unzip == 1) { + if ($document && $unzip == 1) { if ($show_output) { echo Display::return_message( get_lang('UplUploadSucceeded').'
', @@ -2877,20 +2877,11 @@ class DocumentManager ); } - return [ - 'title' => $files[$fileKey]['name'], - 'url' => '#', - ]; + return $document; } - if ($new_path) { - $documentId = self::get_document_id( - $course_info, - $new_path, - $sessionId - ); - - if (!empty($documentId)) { + if ($document) { + /* $table_document = Database::get_course_table(TABLE_DOCUMENT); $params = []; @@ -2912,29 +2903,20 @@ class DocumentManager ], ] ); - } + }*/ if ($index_document) { self::index_document( - $documentId, + $document->getId(), $course_info['code'], null, - $_POST['language'], + $_POST['language'] ?? '', $_REQUEST, $ifExists ); } - if (!empty($documentId) && is_numeric($documentId)) { - $documentData = self::get_document_data_by_id( - $documentId, - $course_info['code'], - false, - $sessionId - ); - - return $documentData; - } + return $document; } } } diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 6e178ecd2a..d713415b38 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -216,11 +216,12 @@ function process_uploaded_file($uploaded_file, $show_output = true) * @param string $comment * @param int $sessionId * @param bool $treat_spaces_as_hyphens + * @param string $uploadKey * * So far only use for unzip_uploaded_document function. * If no output wanted on success, set to false. * - * @return string path of the saved file + * @return CDocument|false */ function handle_uploaded_document( $courseInfo, @@ -546,7 +547,6 @@ function handle_uploaded_document( break; case 'rename': // Rename the file if it exists - // Always rename. $cleanName = DocumentManager::getUniqueFileName( $uploadPath, $cleanName, @@ -577,7 +577,7 @@ function handle_uploaded_document( if (true) { ///chmod($fullPath, $filePermissions); // Put the document data in the database - $documentId = add_document( + $document = add_document( $courseInfo, $filePath, 'file', @@ -593,41 +593,19 @@ function handle_uploaded_document( $content ); - if ($documentId) { - // Update document item_property - /*api_item_property_update( - $courseInfo, - TOOL_DOCUMENT, - $documentId, - 'DocumentAdded', - $userId, - $groupInfo, - $toUserId, - null, - null, - $sessionId - );*/ - - // Redo visibility - //api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo); - } - - // If the file is in a folder, we need to update all parent folders - //item_property_update_on_folder($courseInfo, $uploadPath, $userId); - // Display success message to user if ($output) { Display::addFlash( Display::return_message( get_lang('UplUploadSucceeded').'
'. - get_lang('UplFileSavedAs').' '.$documentTitle, + get_lang('UplFileSavedAs').' '.$document->getTitle(), 'success', false ) ); } - return $filePath; + return $document; } else { /*if ($output) { Display::addFlash( @@ -1333,7 +1311,7 @@ function filter_extension(&$filename) * @param bool $sendNotification * @param string $content * - * @return int id if inserted document + * @return CDocument */ function add_document( $courseInfo, @@ -1459,7 +1437,7 @@ function add_document( $sql = "UPDATE $table SET id = iid WHERE iid = $documentId"; Database::query($sql); - if ($saveVisibility) { + /*if ($saveVisibility) { api_set_default_visibility( $documentId, TOOL_DOCUMENT, @@ -1468,7 +1446,7 @@ function add_document( $sessionId, $userId ); - } + }*/ $allowNotification = api_get_configuration_value('send_notification_when_document_added'); if ($sendNotification && $allowNotification) { @@ -1493,10 +1471,10 @@ function add_document( MessageManager::sendMessageToAllUsersInCourse($subject, $message, $courseInfo, $sessionId); } - return $documentId; - } else { - return false; + return $document; } + + return false; } /**