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();
}
';
// 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);
// Only courseadmin or group members allowed
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $groupId)) {
$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 (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
);
}
// Actions
// Link back to the documents overview
if ($is_certificate_mode) {
$actions = ''.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('CertificateOverview'), '', ICON_SIZE_MEDIUM).'';
} else {
$actions = ''.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'';
}
// Link to create a folder
echo $toolbar = Display::toolbarAction('toolbar-upload', array( 0 => $actions), 1);
// Form to select directory
$folders = DocumentManager::get_all_document_folders($_course, $groupId, $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').'
'.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', '