|
|
|
@ -265,7 +265,8 @@ function handle_uploaded_document( |
|
|
|
|
$sessionId, |
|
|
|
|
$groupId, |
|
|
|
|
$output, |
|
|
|
|
$onlyUploadFile |
|
|
|
|
$onlyUploadFile, |
|
|
|
|
$whatIfFileExists |
|
|
|
|
); |
|
|
|
|
} elseif ($unzip == 1 && !preg_match('/.zip$/', strtolower($uploadedFile['name']))) { |
|
|
|
|
// We can only unzip ZIP files (no gz, tar,...) |
|
|
|
@ -360,27 +361,6 @@ function handle_uploaded_document( |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$documentList = DocumentManager::getDocumentByPathInCourse( |
|
|
|
|
$courseInfo, |
|
|
|
|
$filePath //$filePath |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// This means that the path already exists in this course. |
|
|
|
|
if (!empty($documentList) && $whatIfFileExists != 'overwrite') { |
|
|
|
|
//$found = false; |
|
|
|
|
// Checking if we are talking about the same course + session |
|
|
|
|
/*foreach ($documentList as $document) { |
|
|
|
|
if ($document['session_id'] == $sessionId) { |
|
|
|
|
$found = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
//if ($found == false) { |
|
|
|
|
//$whatIfFileExists = 'rename'; |
|
|
|
|
//} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// What to do if the target file exists |
|
|
|
|
switch ($whatIfFileExists) { |
|
|
|
|
// Overwrite the file if it exists |
|
|
|
@ -470,11 +450,13 @@ function handle_uploaded_document( |
|
|
|
|
|
|
|
|
|
// 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 with extra info to user |
|
|
|
|
if ($output) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
get_lang('UplUploadSucceeded').'<br /> '.$documentTitle.' '.get_lang('UplFileOverwritten'), |
|
|
|
|
get_lang('UplUploadSucceeded').'<br /> '. |
|
|
|
|
$documentTitle.' '.get_lang('UplFileOverwritten'), |
|
|
|
|
'confirmation', |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
@ -611,7 +593,8 @@ function handle_uploaded_document( |
|
|
|
|
if ($output) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
get_lang('UplUploadSucceeded').'<br />'.get_lang('UplFileSavedAs').' '.$documentTitle, |
|
|
|
|
get_lang('UplUploadSucceeded').'<br />'. |
|
|
|
|
get_lang('UplFileSavedAs').' '.$documentTitle, |
|
|
|
|
'success', |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
@ -633,12 +616,27 @@ function handle_uploaded_document( |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'nothing': |
|
|
|
|
$fileExists = file_exists($fullPath); |
|
|
|
|
if ($fileExists) { |
|
|
|
|
if ($output) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
$uploadPath.$cleanName.' '.get_lang('UplAlreadyExists'), |
|
|
|
|
'warning', |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// no break |
|
|
|
|
default: |
|
|
|
|
// Only save the file if it doesn't exist or warn user if it does exist |
|
|
|
|
if (file_exists($fullPath) && $docId) { |
|
|
|
|
if ($output) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message($cleanName.' '.get_lang('UplAlreadyExists'), 'error', false) |
|
|
|
|
Display::return_message($cleanName.' '.get_lang('UplAlreadyExists'), 'warning', false) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -1095,6 +1093,7 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_ |
|
|
|
|
* @param int $groupId group.id |
|
|
|
|
* @param bool $output Optional. If no output not wanted on success, set to false. |
|
|
|
|
* @param bool $onlyUploadFile |
|
|
|
|
* @param string $whatIfFileExists |
|
|
|
|
* |
|
|
|
|
* @return boolean true if it succeeds false otherwise |
|
|
|
|
*/ |
|
|
|
@ -1108,7 +1107,8 @@ function unzip_uploaded_document( |
|
|
|
|
$sessionId = 0, |
|
|
|
|
$groupId = 0, |
|
|
|
|
$output = true, |
|
|
|
|
$onlyUploadFile = false |
|
|
|
|
$onlyUploadFile = false, |
|
|
|
|
$whatIfFileExists = 'overwrite' |
|
|
|
|
) { |
|
|
|
|
$zip = new PclZip($uploaded_file['tmp_name']); |
|
|
|
|
|
|
|
|
@ -1128,7 +1128,7 @@ function unzip_uploaded_document( |
|
|
|
|
$destinationDir = api_get_path(SYS_ARCHIVE_PATH).$folder; |
|
|
|
|
mkdir($destinationDir, api_get_permissions_for_new_directories(), true); |
|
|
|
|
|
|
|
|
|
/* Uncompress zip file*/ |
|
|
|
|
// Uncompress zip file |
|
|
|
|
// We extract using a callback function that "cleans" the path |
|
|
|
|
$zip->extract( |
|
|
|
|
PCLZIP_OPT_PATH, |
|
|
|
@ -1148,7 +1148,8 @@ function unzip_uploaded_document( |
|
|
|
|
$sessionId, |
|
|
|
|
$groupId, |
|
|
|
|
$output, |
|
|
|
|
['path' => $uploadPath] |
|
|
|
|
['path' => $uploadPath], |
|
|
|
|
$whatIfFileExists |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
// Copy result |
|
|
|
@ -1650,7 +1651,7 @@ function create_unexisting_directory( |
|
|
|
|
$visibilities = [ |
|
|
|
|
0 => 'invisible', |
|
|
|
|
1 => 'visible', |
|
|
|
|
2 => 'delete' |
|
|
|
|
2 => 'delete', |
|
|
|
|
]; |
|
|
|
|
api_item_property_update( |
|
|
|
|
$_course, |
|
|
|
@ -1859,13 +1860,15 @@ function build_missing_files_form($missing_files, $upload_path, $file_name) |
|
|
|
|
* |
|
|
|
|
* @param array $courseInfo |
|
|
|
|
* @param array $userInfo |
|
|
|
|
* @param string $base_work_dir |
|
|
|
|
* @param string $folderPath |
|
|
|
|
* @param string $base_work_dir course document dir |
|
|
|
|
* @param string $folderPath folder to read |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param int $groupId group.id |
|
|
|
|
* @param bool $output |
|
|
|
|
* @param array $parent |
|
|
|
|
* @param string $uploadPath |
|
|
|
|
* @param string $whatIfFileExists |
|
|
|
|
* |
|
|
|
|
* @return bool |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
function add_all_documents_in_folder_to_database( |
|
|
|
@ -1876,7 +1879,8 @@ function add_all_documents_in_folder_to_database( |
|
|
|
|
$sessionId = 0, |
|
|
|
|
$groupId = 0, |
|
|
|
|
$output = false, |
|
|
|
|
$parent = [] |
|
|
|
|
$parent = [], |
|
|
|
|
$whatIfFileExists = 'overwrite' |
|
|
|
|
) { |
|
|
|
|
if (empty($userInfo) || empty($courseInfo)) { |
|
|
|
|
return false; |
|
|
|
@ -1894,12 +1898,11 @@ function add_all_documents_in_folder_to_database( |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$parentPath = null; |
|
|
|
|
|
|
|
|
|
$parentPath = ''; |
|
|
|
|
if (!empty($parent) && isset($parent['path'])) { |
|
|
|
|
$parentPath = $parent['path']; |
|
|
|
|
if ($parentPath == '/') { |
|
|
|
|
$parentPath = null; |
|
|
|
|
$parentPath = ''; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1916,14 +1919,52 @@ function add_all_documents_in_folder_to_database( |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if ($folderExists === true) { |
|
|
|
|
$documentId = DocumentManager::get_document_id($courseInfo, $completePath, $sessionId); |
|
|
|
|
if ($documentId) { |
|
|
|
|
$newFolderData = DocumentManager::get_document_data_by_id( |
|
|
|
|
$documentId, |
|
|
|
|
$courseInfo['code'], |
|
|
|
|
false, |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
switch ($whatIfFileExists) { |
|
|
|
|
case 'overwrite': |
|
|
|
|
$documentId = DocumentManager::get_document_id($courseInfo, $completePath, $sessionId); |
|
|
|
|
if ($documentId) { |
|
|
|
|
$newFolderData = DocumentManager::get_document_data_by_id( |
|
|
|
|
$documentId, |
|
|
|
|
$courseInfo['code'], |
|
|
|
|
false, |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'rename': |
|
|
|
|
$newFolderData = create_unexisting_directory( |
|
|
|
|
$courseInfo, |
|
|
|
|
$userId, |
|
|
|
|
$sessionId, |
|
|
|
|
$groupId, |
|
|
|
|
null, |
|
|
|
|
$base_work_dir, |
|
|
|
|
$completePath, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
case 'nothing': |
|
|
|
|
if ($output) { |
|
|
|
|
$documentId = DocumentManager::get_document_id($courseInfo, $completePath, $sessionId); |
|
|
|
|
if ($documentId) { |
|
|
|
|
$folderData = DocumentManager::get_document_data_by_id( |
|
|
|
|
$documentId, |
|
|
|
|
$courseInfo['code'], |
|
|
|
|
false, |
|
|
|
|
$sessionId |
|
|
|
|
); |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
$folderData['path']. ' '.get_lang('UplAlreadyExists'), |
|
|
|
|
'warning' |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
continue 2; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$newFolderData = create_unexisting_directory( |
|
|
|
@ -1949,17 +1990,17 @@ function add_all_documents_in_folder_to_database( |
|
|
|
|
$sessionId, |
|
|
|
|
$groupId, |
|
|
|
|
$output, |
|
|
|
|
$newFolderData |
|
|
|
|
$newFolderData, |
|
|
|
|
$whatIfFileExists |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
// Rename |
|
|
|
|
$uploadedFile = [ |
|
|
|
|
'name' => $file, |
|
|
|
|
'tmp_name' => $sysFolderPath, |
|
|
|
|
'size' => filesize($sysFolderPath), |
|
|
|
|
'type' => null, |
|
|
|
|
'from_file' => true, |
|
|
|
|
'move_file' => true |
|
|
|
|
'move_file' => true, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
handle_uploaded_document( |
|
|
|
@ -1971,7 +2012,7 @@ function add_all_documents_in_folder_to_database( |
|
|
|
|
$groupId, |
|
|
|
|
null, |
|
|
|
|
0, |
|
|
|
|
'overwrite', |
|
|
|
|
$whatIfFileExists, |
|
|
|
|
$output, |
|
|
|
|
false, |
|
|
|
|
null, |
|
|
|
|