'../group/group_space.php?'.api_get_cidreq(), 'name' => get_lang('Group area'), ]; } else { api_not_allowed(true); } } 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 } else { // No course admin and no group member... api_not_allowed(true); } // Group docs can only be uploaded in the group directory if ($groupIid != 0 && $path == '/') { $path = $group_properties['directory']."/"; } // Breadcrumbs $interbreadcrumb[] = [ 'url' => './document.php?id='.$document_id.'&'.api_get_cidreq(), 'name' => get_lang('Documents'), ]; // Interbreadcrumb for the current directory root path if (empty($document_data['parents'])) { // Hack in order to not add the document to the breadcrumb in case it is a link if ($document_data['filetype'] != 'link') { $interbreadcrumb[] = ['url' => '#', 'name' => $document_data['title']]; } } else { 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 if ($document_data['filetype'] != 'link') { $interbreadcrumb[] = [ 'url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title'], ]; } } } $this_section = SECTION_COURSES; $nameTools = get_lang('Add a link'); $action = api_get_self().'?'.api_get_cidreq().'&id='.$document_id; // URLs in whitelist $urlWL = DocumentManager::getFileHostingWhiteList(); sort($urlWL); $urlWLRegEx = '/(\/\/|\.)('.implode('|', $urlWL).')/i'; //Matches any of the whitelisted urls preceded by // or . $urlWLText = "\n\t* ".implode("\n\t* ", $urlWL); $urlWLHTML = ""; $form = new FormValidator('upload', 'POST', $action, '', ['enctype' => 'multipart/form-data']); $form->addHidden('linkid', $document_id); $form->addHidden('curdirpath', $path); $form->addElement('text', 'name', get_lang('Link name'), ['id' => 'name_link']); $form->addElement('text', 'url', get_lang('URL'), ['id' => 'url_link']); $form->addElement( 'static', 'info', '', ''.get_lang( 'ValidDomainList' ).' ' ); $form->addButtonSend(get_lang('Add link to Cloud file'), 'submitDocument'); $form->addRule('name', get_lang('PleaseEnterCloudLink name'), 'required', null, 'client'); $form->addRule('name', get_lang('PleaseEnterCloudLink name'), 'required', null, 'server'); $form->addRule('url', get_lang('Please enter the URL'), 'required', null, 'client'); $form->addRule('url', get_lang('Please enter the URL'), 'required', null, 'server'); // Well formed url pattern (must have the protocol) $urlRegEx = DocumentManager::getWellFormedUrlRegex(); $form->addRule('url', get_lang('URL field format invalid. Example of expected format: http://dropbox.com/sh/loremipsum/loremipsum?dl=0'), 'regex', $urlRegEx, 'client'); $form->addRule('url', get_lang('URL field format invalid. Example of expected format: http://dropbox.com/sh/loremipsum/loremipsum?dl=0'), 'regex', $urlRegEx, 'server'); $form->addRule('url', get_lang('The domain is not valid. It must be one of the following:').$urlWLText, 'regex', $urlWLRegEx, 'client'); $form->addRule('url', get_lang('The domain is not valid. It must be one of the following:').$urlWLHTML, 'regex', $urlWLRegEx, 'server'); if ($form->validate()) { if (isset($_REQUEST['linkid'])) { $doc_id = DocumentManager::addCloudLink($courseInfo, $path, $_REQUEST['url'], $_REQUEST['name']); if ($doc_id) { Display::addFlash(Display::return_message(get_lang('CloudAdd a linked'), 'success', false)); } else { if (DocumentManager::cloudLinkExists($courseInfo, $path, $_REQUEST['url'])) { Display::addFlash(Display::return_message(get_lang('URLAlreadyExists'), 'warning', false)); } else { Display::addFlash(Display::return_message(get_lang('ErrorAdd link to Cloud file'), 'warning', false)); } } header('Location: document.php?'.api_get_cidreq()); exit; } } // Display the header Display::display_header($nameTools, 'Doc'); // Actions echo '
'; // Link back to the documents overview echo ''. Display::return_icon('back.png', get_lang('Back to').' '.get_lang('Documents overview'), '', ICON_SIZE_MEDIUM). ''; echo '
'; // 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'] : [] ); // Add tooltip and correctly parse its inner HTML echo ''; echo $form->returnForm(); Display::display_footer();