Fix move document see BT#14005

pull/2458/head
jmontoyaa 8 years ago
parent aaafcbcc10
commit 9835041cca
  1. 33
      main/document/document.php
  2. 2
      main/inc/lib/document.lib.php

@ -121,7 +121,7 @@ DocumentManager::create_directory_certificate_in_course($courseInfo);
$dbl_click_id = 0; $dbl_click_id = 0;
$selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null; $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
$moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null; $moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null;
$moveFile = isset($_POST['move_file']) && is_int($_POST['move_file']) ? $_POST['move_file'] : null; $moveFile = isset($_POST['move_file']) ? (int) $_POST['move_file'] : 0;
$certificateLink = ''; $certificateLink = '';
if ($is_certificate_mode) { if ($is_certificate_mode) {
@ -596,17 +596,17 @@ if (isset($document_id) && empty($action)) {
$groupIid $groupIid
); );
if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file' || $document_data['filetype'] == 'link') { if (!empty($document_data['filetype']) &&
($document_data['filetype'] == 'file' || $document_data['filetype'] == 'link')
) {
if ($visibility && api_is_allowed_to_session_edit()) { if ($visibility && api_is_allowed_to_session_edit()) {
$url = api_get_path(WEB_COURSE_PATH). $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();
$courseInfo['path'].'/document'.$document_data['path'].'?'
.api_get_cidreq();
header("Location: $url"); header("Location: $url");
exit;
} }
exit;
} else { } else {
if (!$visibility && !$isAllowedToEdit) { if (!$visibility && !$isAllowedToEdit) {
api_not_allowed(); api_not_allowed(true);
} }
} }
$_GET['curdirpath'] = $document_data['path']; $_GET['curdirpath'] = $document_data['path'];
@ -621,7 +621,6 @@ if (isset($document_id) && empty($action)) {
} else { } else {
$curdirpath = '/'; $curdirpath = '/';
} }
$curdirpathurl = urlencode($curdirpath); $curdirpathurl = urlencode($curdirpath);
} else { } else {
// What's the current path? // What's the current path?
@ -962,10 +961,11 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
} }
if (!$isAllowedToEdit) { if (!$isAllowedToEdit) {
if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $my_get_move)) { if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $my_get_move)) {
api_not_allowed(true); api_not_allowed(true);
} }
} }
// Get the document data from the ID // Get the document data from the ID
$document_to_move = DocumentManager::get_document_data_by_id( $document_to_move = DocumentManager::get_document_data_by_id(
$my_get_move, $my_get_move,
@ -983,6 +983,7 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
false, false,
$curdirpath $curdirpath
); );
$moveForm .= '<legend>'.get_lang('Move').': '.$document_to_move['title'].'</legend>';
// filter if is my shared folder. TODO: move this code to build_move_to_selector function // filter if is my shared folder. TODO: move this code to build_move_to_selector function
if (DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) && if (DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) &&
@ -1000,8 +1001,6 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
$user_shared_folders[] = $fold; $user_shared_folders[] = $fold;
} }
} }
$moveForm .= '<legend>'.get_lang('Move').'</legend>';
$moveForm .= DocumentManager::build_move_to_selector( $moveForm .= DocumentManager::build_move_to_selector(
$user_shared_folders, $user_shared_folders,
$move_path, $move_path,
@ -1009,7 +1008,6 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
$group_properties['directory'] $group_properties['directory']
); );
} else { } else {
$moveForm .= '<legend>'.get_lang('Move').'</legend>';
$moveForm .= DocumentManager::build_move_to_selector( $moveForm .= DocumentManager::build_move_to_selector(
$folders, $folders,
$move_path, $move_path,
@ -1022,7 +1020,7 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
if (!empty($moveTo) && isset($moveFile)) { if (!empty($moveTo) && isset($moveFile)) {
if (!$isAllowedToEdit) { if (!$isAllowedToEdit) {
if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $moveFile)) { if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $moveFile)) {
api_not_allowed(true); api_not_allowed(true);
} }
} }
@ -1047,7 +1045,12 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
$real_path_target = $base_work_dir.$moveTo.'/'; $real_path_target = $base_work_dir.$moveTo.'/';
if (!DocumentManager::cloudLinkExists($_course, $moveTo, $document_to_move['comment'])) { if (!DocumentManager::cloudLinkExists($_course, $moveTo, $document_to_move['comment'])) {
$doc_id = $moveFile; $doc_id = $moveFile;
DocumentManager::updateDBInfoCloudLink($document_to_move['path'], $moveTo.'/', $doc_id); //DocumentManager::updateDbInfo($document_to_move['path'], $moveTo.'/', $doc_id);
DocumentManager::updateDbInfo(
'update',
$document_to_move['path'],
$moveTo.'/'.basename($document_to_move['path'])
);
// Update database item property // Update database item property
api_item_property_update( api_item_property_update(
@ -1056,7 +1059,7 @@ if ($isAllowedToEdit || $group_member_with_upload_rights ||
$doc_id, $doc_id,
'FileMoved', 'FileMoved',
api_get_user_id(), api_get_user_id(),
$to_group_id, $group_properties,
null, null,
null, null,
null, null,

@ -5895,7 +5895,7 @@ class DocumentManager
$form = new FormValidator('move_to', 'post', api_get_self().'?'.api_get_cidreq()); $form = new FormValidator('move_to', 'post', api_get_self().'?'.api_get_cidreq());
// Form title // Form title
$form->addElement('hidden', 'move_file', $move_file); $form->addHidden('move_file', $move_file);
$options = []; $options = [];

Loading…
Cancel
Save