123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Main script for the documents tool
- *
- * This script allows the user to manage files and directories on a remote http server.
- *
- * The user can : - navigate through files and directories.
- * - upload a file
- * - delete, copy a file or a directory
- * - edit properties & content (name, comments, html content)
- *
- * The script is organised in four sections.
- *
- * 1) Execute the command called by the user
- * Note: somme commands of this section are organised in two steps.
- * The script always begins with the second step,
- * so it allows to return more easily to the first step.
- *
- * Note (March 2004) some editing functions (renaming, commenting)
- * are moved to a separate page, edit_document.php. This is also
- * where xml and other stuff should be added.
- *
- * 2) Define the directory to display
- *
- * 3) Read files and directories from the directory defined in part 2
- * 4) Display all of that on an HTML page
- *
- * @todo eliminate code duplication between
- * document/document.php, scormdocument.php
- *
- * @package chamilo.document
- */
- // Including the global initialization file
- //require_once '../inc/global.inc.php';
- // Including additional libraries
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- // Adding extra javascript to the form
- //$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-upload'));
- // Variables
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $_course = api_get_course_info();
- $groupId = api_get_group_id();
- $courseDir = $_course['path'].'/document';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $base_work_dir = $sys_course_path.$courseDir;
- $sessionId = api_get_session_id();
- $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
- $document_data = [];
- if (isset($_REQUEST['id'])) {
- $document_data = DocumentManager::get_document_data_by_id(
- $_REQUEST['id'],
- api_get_course_id(),
- true,
- $sessionId
- );
- if ($sessionId != 0 && !$document_data) {
- $document_data = DocumentManager::get_document_data_by_id(
- $_REQUEST['id'],
- api_get_course_id(),
- true,
- 0
- );
- }
- }
- if (empty($document_data)) {
- $document_id = $parent_id = 0;
- $path = '/';
- } else {
- $document_id = $document_data['id'];
- $path = $document_data['path'];
- $parent_id = DocumentManager::get_document_id(
- api_get_course_info(),
- dirname($path)
- );
- }
- $group_properties = array();
- $htmlHeadXtra[] = '<script>
- function check_unzip() {
- if (document.upload.unzip.checked){
- document.upload.if_exists[0].disabled=true;
- document.upload.if_exists[1].checked=true;
- document.upload.if_exists[2].disabled=true;
- } else {
- document.upload.if_exists[0].checked=true;
- document.upload.if_exists[0].disabled=false;
- document.upload.if_exists[2].disabled=false;
- }
- }
- function setFocus(){
- $("#title_file").focus();
- }
- </script>';
- $groupIid = 0;
- // This needs cleaning!
- if (!empty($groupId)) {
- // If the group id is set, check if the user has the right to be here
- // Get group info
- $group_properties = GroupManager::get_group_properties($groupId);
- $groupIid = $group_properties['iid'];
- // Only courseadmin or group members allowed
- if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $group_properties['iid'])) {
- $interbreadcrumb[] = array(
- 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
- 'name' => get_lang('GroupSpace'),
- );
- } else {
- api_not_allowed(true);
- }
- } elseif ($is_allowed_to_edit ||
- DocumentManager::is_my_shared_folder(api_get_user_id(), $path, api_get_session_id())) {
- } else {
- // No course admin and no group member...
- api_not_allowed(true);
- }
- // Group docs can only be uploaded in the group directory
- if ($groupId != 0 && $path == '/') {
- $path = $group_properties['directory'];
- }
- // I'm in the certification module?
- $is_certificate_mode = false;
- $is_certificate_array = explode('/', $path);
- array_shift($is_certificate_array);
- if ($is_certificate_array[0] == 'certificates') {
- $is_certificate_mode = true;
- }
- // Title of the tool
- $add_group_to_title = null;
- if ($groupId != 0) {
- // Add group name after for group documents
- $add_group_to_title = ' ('.$group_properties['name'].')';
- }
- if (isset($_REQUEST['certificate'])) {
- $nameTools = get_lang('UploadCertificate').$add_group_to_title;
- $is_certificate_mode = true;
- } else {
- $nameTools = get_lang('UplUploadDocument').$add_group_to_title;
- }
- // Breadcrumbs
- if ($is_certificate_mode) {
- $interbreadcrumb[] = array(
- 'url' => '../gradebook/index.php?'.api_get_cidreq(),
- 'name' => get_lang('Gradebook'),
- );
- } else {
- $interbreadcrumb[] = array(
- 'url' => './document.php?id='.$document_id.'&'.api_get_cidreq(),
- 'name' => get_lang('Documents'),
- );
- }
- // Interbreadcrumb for the current directory root path
- if ($document_data) {
- if (empty($document_data['parents'])) {
- $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
- } else {
- foreach ($document_data['parents'] as $document_sub_data) {
- $interbreadcrumb[] = array(
- 'url' => $document_sub_data['document_url'],
- 'name' => $document_sub_data['title']
- );
- }
- }
- }
- $this_section = SECTION_COURSES;
- // Display the header
- Display::display_header($nameTools, 'Doc');
- /* Here we do all the work */
- $unzip = isset($_POST['unzip']) ? $_POST['unzip'] : null;
- $index = isset($_POST['index_document']) ? $_POST['index_document'] : null;
- // User has submitted a file
- if (!empty($_FILES)) {
- DocumentManager::upload_document(
- $_FILES,
- $_POST['curdirpath'],
- $_POST['title'],
- $_POST['comment'],
- $unzip,
- $_POST['if_exists'],
- $index,
- true
- );
- $redirectUrl = api_get_self() . '?' . api_get_cidreq();
- if ($document_data) {
- $redirectUrl .= '&' . http_build_query([
- 'id' => $document_data['iid']
- ]);
- }
- header("Location: $redirectUrl");
- exit;
- }
- // Display the header
- Display::display_header($nameTools, 'Doc');
- // Actions
- // Link back to the documents overview
- if ($is_certificate_mode) {
- $actions = '<a href="document.php?id='.$document_id.'&selectcat=' . $selectcat.'&'.api_get_cidreq().'">'.
- Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('CertificateOverview'),'',ICON_SIZE_MEDIUM).'</a>';
- } else {
- $actions = '<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>';
- }
- // Link to create a folder
- echo $toolbar = Display::toolbarAction('toolbar-upload', array($actions), 1);
- $folders = DocumentManager::get_all_document_folders(
- $_course,
- $groupIid,
- $is_allowed_to_edit
- );
- if (!$is_certificate_mode) {
- 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;
- $form = new FormValidator(
- 'upload',
- 'POST',
- $action.'#tabs-2',
- '',
- array('enctype' => 'multipart/form-data')
- );
- $form->addElement('hidden', 'id', $document_id);
- $form->addElement('hidden', 'curdirpath', $path);
- $course_quota = format_file_size(DocumentManager::get_course_quota() - DocumentManager::documents_total_space());
- $label = get_lang('MaxFileSize').': '.ini_get('upload_max_filesize').'<br/>'.get_lang('DocumentQuota').': '.$course_quota;
- $form->addElement('file', 'file', array(get_lang('File'), $label), 'style="width: 250px" id="user_upload"');
- $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title_file'));
- $form->addElement('textarea', 'comment', get_lang('Comment'));
- // Advanced parameters
- $form->addButtonAdvancedSettings('advanced_params');
- $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
- // Check box options
- $form->addElement(
- 'checkbox',
- 'unzip',
- get_lang('Options'),
- get_lang('Uncompress'),
- 'onclick="javascript: check_unzip();" value="1"'
- );
- if (api_get_setting('search.search_enabled') == 'true') {
- //TODO: include language file
- $supported_formats = get_lang('SupportedFormatsForIndex').': HTML, PDF, TXT, PDF, Postscript, MS Word, RTF, MS Power Point';
- $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'<div style="font-size: 80%" >'.$supported_formats.'</div>');
- $form->addElement('html', '<br /><div class="sub-form">');
- $form->addElement('html', '<div class="label">'.get_lang('SearchFeatureDocumentLanguage').'</div>');
- $form->addLabel(get_lang('Language'), api_get_languages_combo());
- $form->addElement('html', '</div><div class="sub-form">');
- $specific_fields = get_specific_field_list();
- foreach ($specific_fields as $specific_field) {
- $form->addElement('text', $specific_field['code'], $specific_field['name']);
- }
- $form->addElement('html', '</div>');
- }
- $form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing');
- $form->addElement('radio', 'if_exists', '', get_lang('UplOverwriteLong'), 'overwrite');
- $form->addElement('radio', 'if_exists', '', get_lang('UplRenameLong'), 'rename');
- // Close the java script and avoid the footer up
- $form->addElement('html', '</div>');
- // Button upload document
- $form->addButtonSend(get_lang('SendDocument'), 'submitDocument');
- $form->addProgress('DocumentUpload', 'file');
- $fileExistsOption = api_get_setting('document.if_file_exists_option');
- $defaultFileExistsOption = 'rename';
- if (!empty($fileExistsOption)) {
- $defaultFileExistsOption = $fileExistsOption;
- }
- $defaults = array(
- 'index_document' => 'checked="checked"',
- 'if_exists' => $defaultFileExistsOption
- );
- $form->setDefaults($defaults);
- $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?'.api_get_cidreq().'&a=upload_file&curdirpath='.$path;
- $multipleForm = new FormValidator(
- 'drag_drop',
- 'post',
- '#',
- array('enctype' => 'multipart/form-data')
- );
- $multipleForm->addMultipleUpload($url);
- $headers = array(
- get_lang('Upload'),
- get_lang('Upload').' ('.get_lang('Simple').')'
- );
- echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs');
- Display::display_footer();
|