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 advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\'
'.get_lang('AdvancedParameters').'\';
} else {
document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'img_plus_and_minus\').innerHTML=\'
'.get_lang('AdvancedParameters').'\';
}
}
function setFocus(){
$("#title_file").focus();
}
$(document).ready(function () {
setFocus();
});
';
$htmlHeadXtra[] = "
";
// Variables
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$courseDir = $_course['path'].'/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path.$courseDir;
$noPHP_SELF = true;
// What's the current path?
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
$path = $_GET['curdirpath'];
} elseif (isset($_POST['curdirpath'])) {
$path = $_POST['curdirpath'];
} else {
$path = '/';
}
// Check the path: if the path is not found (no document id), set the path to /
if (!DocumentManager::get_document_id($_course, $path)) {
$path = '/';
}
// This needs cleaning!
if (api_get_group_id()) { // 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
$group_properties = GroupManager::get_group_properties(api_get_group_id());
$noPHP_SELF = true;
if ($is_allowed_to_edit || GroupManager::is_user_in_group($_user['user_id'], api_get_group_id())) { // Only courseadmin or group members allowed
$to_group_id = api_get_group_id();
$req_gid = '&gidReq='.api_get_group_id();
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.api_get_group_id(), 'name' => get_lang('GroupSpace'));
} else {
api_not_allowed(true);
}
} elseif ($is_allowed_to_edit || is_my_shared_folder($_user['user_id'], $path,api_get_session_id())) { // 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...
api_not_allowed(true);
}
// Group docs can only be uploaded in the group directory
if ($to_group_id != 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;
}
// Variables
//$max_filled_space = DocumentManager::get_course_quota();
// Title of the tool
if ($to_group_id != 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;
} else {
$nameTools = get_lang('UplUploadDocument').$add_group_to_title;
}
// Breadcrumbs
if ($is_certificate_mode) {
$interbreadcrumb[] = array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
} else {
$interbreadcrumb[] = array('url' => './document.php?curdirpath='.urlencode($path).$req_gid, 'name'=> get_lang('Documents'));
}
$this_section = SECTION_COURSES;
// Display the header
Display::display_header($nameTools, 'Doc');
/* Here we do all the work */
// User has submitted a file
if (!empty($_FILES)) {
DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $_POST['title'], $_POST['comment'], $_POST['unzip'], $_POST['if_exists'], $_POST['index_document'], true);
}
// @todo remove this submit_image ???
/*
// Missing images are submitted
if (isset($_POST['submit_image'])) {
$number_of_uploaded_images = count($_FILES['img_file']['name']);
//if images are uploaded
if ($number_of_uploaded_images > 0) {
// We could also create a function for this, I'm not sure...
// Create a directory for the missing files
$img_directory = str_replace('.', '_', $_POST['related_file'].'_files');
$missing_files_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $img_directory);
// Put the uploaded files in the new directory and get the paths
$paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space);
// Open the html file and replace the paths
replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir.$_POST['related_file']);
// Update parent folders
item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
}
}
*/
//@todo keep it simple this page should only upload files!
/*
// They want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
$added_slash = ($path=='/') ? '' : '/';
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
$created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
if ($created_dir) {
Display::display_confirmation_message(get_lang('DirCr'), false);
$path = $created_dir;
} else {
display_error(get_lang('CannotCreateDir'));
}
}*/
// Tracking not needed here?
//event_access_tool(TOOL_DOCUMENT);
/* They want to create a new directory */
/*
if (isset($_GET['createdir'])) {
// create the form that asks for the directory name
$new_folder_text = '