|
|
|
@ -4,33 +4,21 @@ |
|
|
|
* This script allows to add cloud file links to the document structure |
|
|
|
* This script allows to add cloud file links to the document structure |
|
|
|
* @package chamilo.document |
|
|
|
* @package chamilo.document |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
/** |
|
|
|
|
|
|
|
* Code |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Including the global initialization file |
|
|
|
|
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
|
|
|
|
|
|
|
|
|
|
|
// Including additional libraries |
|
|
|
|
|
|
|
require_once __DIR__.'/../inc/lib/document.lib.php'; |
|
|
|
|
|
|
|
require_once __DIR__.'/../inc/lib/urlUtils.lib.php'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fileLinkEnabled = api_get_configuration_value('enable_add_file_link'); |
|
|
|
$fileLinkEnabled = api_get_configuration_value('enable_add_file_link'); |
|
|
|
|
|
|
|
|
|
|
|
if (!$fileLinkEnabled) { |
|
|
|
if (!$fileLinkEnabled) { |
|
|
|
api_not_allowed(true); |
|
|
|
api_not_allowed(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$course_info = api_get_course_info(); |
|
|
|
$courseInfo = api_get_course_info(); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($course_info)) { |
|
|
|
if (empty($courseInfo)) { |
|
|
|
api_not_allowed(true); |
|
|
|
api_not_allowed(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$dir = '/'; |
|
|
|
if ($is_certificate_mode) { |
|
|
|
|
|
|
|
api_not_allowed(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$document_data = DocumentManager::get_document_data_by_id($_REQUEST['id'], api_get_course_id(), true); |
|
|
|
$document_data = DocumentManager::get_document_data_by_id($_REQUEST['id'], api_get_course_id(), true); |
|
|
|
if (empty($document_data)) { |
|
|
|
if (empty($document_data)) { |
|
|
|
$document_id = $parent_id = 0; |
|
|
|
$document_id = $parent_id = 0; |
|
|
|
@ -41,39 +29,48 @@ if (empty($document_data)) { |
|
|
|
$path = $document_data['path'].'/'; |
|
|
|
$path = $document_data['path'].'/'; |
|
|
|
$parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path)); |
|
|
|
$parent_id = DocumentManager::get_document_id(api_get_course_info(), dirname($path)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$dir = dirname($document_data['path']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$is_certificate_mode = DocumentManager::is_certificate_mode($dir); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($is_certificate_mode) { |
|
|
|
|
|
|
|
api_not_allowed(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); |
|
|
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$groupIid = 0; |
|
|
|
if (api_get_group_id()) { |
|
|
|
if (api_get_group_id()) { |
|
|
|
// If the group id is set, check if the user has the right to be here |
|
|
|
// If the group id is set, check if the user has the right to be here |
|
|
|
// Needed for group related stuff |
|
|
|
|
|
|
|
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; |
|
|
|
|
|
|
|
// Get group info |
|
|
|
// Get group info |
|
|
|
$group_properties = GroupManager::get_group_properties(api_get_group_id()); |
|
|
|
$group_properties = GroupManager::get_group_properties(api_get_group_id()); |
|
|
|
|
|
|
|
if ($is_allowed_to_edit || GroupManager::is_user_in_group($_user['user_id'], api_get_group_id())) { |
|
|
|
if ($is_allowed_to_edit || GroupManager::is_user_in_group($_user['user_id'], api_get_group_id())) { // Only courseadmin or group members allowed |
|
|
|
// Only courseadmin or group members allowed |
|
|
|
$to_group_id = api_get_group_id(); |
|
|
|
$groupIid = $group_properties['iid']; |
|
|
|
$req_gid = '&gidReq='.api_get_group_id(); |
|
|
|
$interbreadcrumb[] = array( |
|
|
|
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.api_get_group_id(), 'name' => get_lang('GroupSpace')); |
|
|
|
'url' => '../group/group_space.php?'.api_get_cidreq(), |
|
|
|
|
|
|
|
'name' => get_lang('GroupSpace'), |
|
|
|
|
|
|
|
); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
api_not_allowed(true); |
|
|
|
api_not_allowed(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} elseif ($is_allowed_to_edit || DocumentManager::is_my_shared_folder(api_get_user_id(), $path, api_get_session_id())) { |
|
|
|
} elseif ($is_allowed_to_edit || DocumentManager::is_my_shared_folder(api_get_user_id(), $path, api_get_session_id())) { |
|
|
|
// Admin for "regular" upload, no group documents. And check if is my shared folder |
|
|
|
// Admin for "regular" upload, no group documents. And check if is my shared folder |
|
|
|
$to_group_id = 0; |
|
|
|
|
|
|
|
$req_gid = ''; |
|
|
|
|
|
|
|
} else { // No course admin and no group member... |
|
|
|
} else { // No course admin and no group member... |
|
|
|
api_not_allowed(true); |
|
|
|
api_not_allowed(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Group docs can only be uploaded in the group directory |
|
|
|
// Group docs can only be uploaded in the group directory |
|
|
|
if ($to_group_id != 0 && $path == '/') { |
|
|
|
if ($groupIid != 0 && $path == '/') { |
|
|
|
$path = $group_properties['directory'] . "/"; |
|
|
|
$path = $group_properties['directory'] . "/"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Breadcrumbs |
|
|
|
// Breadcrumbs |
|
|
|
$interbreadcrumb[] = array('url' => './document.php?id='.$document_id.$req_gid, 'name'=> get_lang('Documents')); |
|
|
|
$interbreadcrumb[] = array( |
|
|
|
|
|
|
|
'url' => './document.php?id='.$document_id.'&'.api_get_cidreq(), |
|
|
|
|
|
|
|
'name' => get_lang('Documents'), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Interbreadcrumb for the current directory root path |
|
|
|
// Interbreadcrumb for the current directory root path |
|
|
|
if (empty($document_data['parents'])) { |
|
|
|
if (empty($document_data['parents'])) { |
|
|
|
@ -85,7 +82,10 @@ if (empty($document_data['parents'])) { |
|
|
|
foreach ($document_data['parents'] as $document_sub_data) { |
|
|
|
foreach ($document_data['parents'] as $document_sub_data) { |
|
|
|
// Hack in order to not add the document to the breadcrumb in case it is a link |
|
|
|
// Hack in order to not add the document to the breadcrumb in case it is a link |
|
|
|
if ($document_data['filetype'] != 'link') { |
|
|
|
if ($document_data['filetype'] != 'link') { |
|
|
|
$interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); |
|
|
|
$interbreadcrumb[] = array( |
|
|
|
|
|
|
|
'url' => $document_sub_data['document_url'], |
|
|
|
|
|
|
|
'name' => $document_sub_data['title'], |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -93,46 +93,29 @@ if (empty($document_data['parents'])) { |
|
|
|
$this_section = SECTION_COURSES; |
|
|
|
$this_section = SECTION_COURSES; |
|
|
|
|
|
|
|
|
|
|
|
$nameTools = get_lang('LinkAdd'); |
|
|
|
$nameTools = get_lang('LinkAdd'); |
|
|
|
|
|
|
|
|
|
|
|
// Display the header |
|
|
|
|
|
|
|
Display::display_header($nameTools, 'Doc'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Here we do all the work */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actions |
|
|
|
|
|
|
|
echo '<div class="actions">'; |
|
|
|
|
|
|
|
// Link back to the documents overview |
|
|
|
|
|
|
|
echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
|
|
|
|
|
|
echo '</div>'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Form to select directory |
|
|
|
|
|
|
|
$folders = DocumentManager::get_all_document_folders( |
|
|
|
|
|
|
|
$_course, |
|
|
|
|
|
|
|
$groupIid, |
|
|
|
|
|
|
|
$is_allowed_to_edit |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo DocumentManager::build_directory_selector( |
|
|
|
|
|
|
|
$folders, |
|
|
|
|
|
|
|
$document_id, |
|
|
|
|
|
|
|
(isset($group_properties['directory']) ? $group_properties['directory'] : array()) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$action = api_get_self().'?'.api_get_cidreq().'&id='.$document_id; |
|
|
|
$action = api_get_self().'?'.api_get_cidreq().'&id='.$document_id; |
|
|
|
|
|
|
|
|
|
|
|
// URLs in whitelist |
|
|
|
// URLs in whitelist |
|
|
|
$urlWL = URLUtils::getFileHostingsWL(); |
|
|
|
$urlWL = DocumentManager::getFileHostingWhiteList(); |
|
|
|
|
|
|
|
|
|
|
|
sort($urlWL); |
|
|
|
sort($urlWL); |
|
|
|
$urlWLRegEx = '/(\/\/|\.)('.implode('|', $urlWL).')/i'; //Matches any of the whitelisted urls preceded by // or . |
|
|
|
$urlWLRegEx = '/(\/\/|\.)('.implode('|', $urlWL).')/i'; //Matches any of the whitelisted urls preceded by // or . |
|
|
|
$urlWLText = "\n\t* ".implode("\n\t* ", $urlWL); |
|
|
|
$urlWLText = "\n\t* ".implode("\n\t* ", $urlWL); |
|
|
|
$urlWLHTML = "<ul><li>".implode("</li><li>", $urlWL)."</li></ul>"; |
|
|
|
$urlWLHTML = "<ul><li>".implode("</li><li>", $urlWL)."</li></ul>"; |
|
|
|
|
|
|
|
|
|
|
|
$form = new FormValidator('upload', 'POST', $action, '', array('enctype' => 'multipart/form-data')); |
|
|
|
$form = new FormValidator('upload', 'POST', $action, '', array('enctype' => 'multipart/form-data')); |
|
|
|
$form->addElement('hidden', 'linkid', $document_id); |
|
|
|
$form->addHidden('linkid', $document_id); |
|
|
|
$form->addElement('hidden', 'curdirpath', $path); |
|
|
|
$form->addHidden('curdirpath', $path); |
|
|
|
$form->addElement('text', 'name', get_lang('LinkName'), array('id' => 'name_link')); |
|
|
|
$form->addElement('text', 'name', get_lang('LinkName'), array('id' => 'name_link')); |
|
|
|
$form->addElement('text', 'url', get_lang('Url'), array('id' => 'url_link')); |
|
|
|
$form->addElement('text', 'url', get_lang('Url'), array('id' => 'url_link')); |
|
|
|
$form->addElement('static', 'info', '', '<span class="text-primary" data-toggle="tooltip" title="'.$urlWLHTML.'">'.get_lang('ValidDomainList').' <span class="glyphicon glyphicon-question-sign"></span></span>'); |
|
|
|
$form->addElement( |
|
|
|
|
|
|
|
'static', |
|
|
|
|
|
|
|
'info', |
|
|
|
|
|
|
|
'', |
|
|
|
|
|
|
|
'<span class="text-primary" data-toggle="tooltip" title="'.$urlWLHTML.'">'.get_lang( |
|
|
|
|
|
|
|
'ValidDomainList' |
|
|
|
|
|
|
|
).' <span class="glyphicon glyphicon-question-sign"></span></span>' |
|
|
|
|
|
|
|
); |
|
|
|
$form->addButtonSend(get_lang('AddCloudLink'), 'submitDocument'); |
|
|
|
$form->addButtonSend(get_lang('AddCloudLink'), 'submitDocument'); |
|
|
|
|
|
|
|
|
|
|
|
$form->addRule('name', get_lang('PleaseEnterCloudLinkName'), 'required', null, 'client'); |
|
|
|
$form->addRule('name', get_lang('PleaseEnterCloudLinkName'), 'required', null, 'client'); |
|
|
|
@ -140,7 +123,7 @@ $form->addRule('name', get_lang('PleaseEnterCloudLinkName'), 'required', null, ' |
|
|
|
$form->addRule('url', get_lang('PleaseEnterURL'), 'required', null, 'client'); |
|
|
|
$form->addRule('url', get_lang('PleaseEnterURL'), 'required', null, 'client'); |
|
|
|
$form->addRule('url', get_lang('PleaseEnterURL'), 'required', null, 'server'); |
|
|
|
$form->addRule('url', get_lang('PleaseEnterURL'), 'required', null, 'server'); |
|
|
|
// Well formed url pattern (must have the protocol) |
|
|
|
// Well formed url pattern (must have the protocol) |
|
|
|
$urlRegEx = URLUtils::getWellformedUrlRegex(); |
|
|
|
$urlRegEx = DocumentManager::getWellFormedUrlRegex(); |
|
|
|
$form->addRule('url', get_lang('NotValidURL'), 'regex', $urlRegEx, 'client'); |
|
|
|
$form->addRule('url', get_lang('NotValidURL'), 'regex', $urlRegEx, 'client'); |
|
|
|
$form->addRule('url', get_lang('NotValidURL'), 'regex', $urlRegEx, 'server'); |
|
|
|
$form->addRule('url', get_lang('NotValidURL'), 'regex', $urlRegEx, 'server'); |
|
|
|
$form->addRule('url', get_lang('NotValidDomain').$urlWLText, 'regex', $urlWLRegEx, 'client'); |
|
|
|
$form->addRule('url', get_lang('NotValidDomain').$urlWLText, 'regex', $urlWLRegEx, 'client'); |
|
|
|
@ -148,32 +131,57 @@ $form->addRule('url', get_lang('NotValidDomain').$urlWLHTML, 'regex', $urlWLRegE |
|
|
|
|
|
|
|
|
|
|
|
if ($form->validate()) { |
|
|
|
if ($form->validate()) { |
|
|
|
if (isset($_REQUEST['linkid'])) { |
|
|
|
if (isset($_REQUEST['linkid'])) { |
|
|
|
$doc_id = DocumentManager::addCloudLink($course_info, $path, $_REQUEST['url'], $_REQUEST['name']); |
|
|
|
$doc_id = DocumentManager::addCloudLink($courseInfo, $path, $_REQUEST['url'], $_REQUEST['name']); |
|
|
|
if ($doc_id) { |
|
|
|
if ($doc_id) { |
|
|
|
Display::display_confirmation_message(get_lang('CloudLinkAdded') . '<br />', false); |
|
|
|
Display::addFlash(Display::return_message(get_lang('CloudLinkAdded'), 'success', false)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (DocumentManager::cloudLinkExists($course_info, $path, $_REQUEST['url'])) { |
|
|
|
if (DocumentManager::cloudLinkExists($courseInfo, $path, $_REQUEST['url'])) { |
|
|
|
Display::display_error_message(get_lang('UrlAlreadyExists'), false); |
|
|
|
Display::addFlash(Display::return_message(get_lang('UrlAlreadyExists'), 'warning', false)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Display::display_error_message(get_lang('ErrorAddCloudLink'), false); |
|
|
|
Display::addFlash(Display::return_message(get_lang('ErrorAddCloudLink'), 'warning', false)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
header('Location: document.php?'.api_get_cidreq()); |
|
|
|
|
|
|
|
exit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Display the header |
|
|
|
|
|
|
|
Display::display_header($nameTools, 'Doc'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actions |
|
|
|
|
|
|
|
echo '<div class="actions">'; |
|
|
|
|
|
|
|
// Link back to the documents overview |
|
|
|
|
|
|
|
echo '<a href="document.php?id='.$document_id.'&'.api_get_cidreq().'">'. |
|
|
|
|
|
|
|
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM). |
|
|
|
|
|
|
|
'</a>'; |
|
|
|
|
|
|
|
echo '</div>'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Form to select directory |
|
|
|
|
|
|
|
$folders = DocumentManager::get_all_document_folders( |
|
|
|
|
|
|
|
$_course, |
|
|
|
|
|
|
|
$groupIid, |
|
|
|
|
|
|
|
$is_allowed_to_edit |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo DocumentManager::build_directory_selector( |
|
|
|
|
|
|
|
$folders, |
|
|
|
|
|
|
|
$document_id, |
|
|
|
|
|
|
|
isset($group_properties['directory']) ? $group_properties['directory'] : array() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Add tooltip and correctly parse its inner HTML |
|
|
|
// Add tooltip and correctly parse its inner HTML |
|
|
|
echo '<script> |
|
|
|
echo '<script> |
|
|
|
$(document).ready(function() { |
|
|
|
$(document).ready(function() { |
|
|
|
$("[data-toggle=\'tooltip\']").tooltip( |
|
|
|
$("[data-toggle=\'tooltip\']").tooltip({ |
|
|
|
{ |
|
|
|
|
|
|
|
content: |
|
|
|
content: |
|
|
|
function() { |
|
|
|
function() { |
|
|
|
return $(this).attr("title"); |
|
|
|
return $(this).attr("title"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
</script>'; |
|
|
|
</script>'; |
|
|
|
|
|
|
|
|
|
|
|
echo $form->return_form(); |
|
|
|
echo $form->returnForm(); |
|
|
|
Display::display_footer(); |
|
|
|
Display::display_footer(); |
|
|
|
|