';
$error404 .= '';
$error404 .= '';
echo $error404;
exit;
}
// Launch event
event_download($my_get_id);
// Check visibility of document and paths
if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible($my_get_id, $_course)) {
api_not_allowed();
}
$doc_url = $my_get_id;
$full_file_name = $base_work_dir.$doc_url;
DocumentManager::file_send_for_download($full_file_name, true);
exit;
}
// Download a folder
if (isset($_GET['action']) && $_GET['action'] == 'downloadfolder' && (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) {
//filter when I am into shared folder, I can donwload only my shared folder
if(is_any_user_shared_folder($_GET['path'],$current_session_id))
{
if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin())
{
require 'downloadfolder.inc.php';
}
}
else
{
require 'downloadfolder.inc.php';
}
}
// Slideshow inititalisation
$_SESSION['image_files_only'] = '';
$image_files_only = '';
/* Header */
if ($is_certificate_mode) {
$interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook'));
} else {
$interbreadcrumb[]= array('url' => '', 'name' => get_lang('Documents'));
}
// Interbreadcrumb for the current directory root path
$dir_array = explode('/', $curdirpath);
$array_len = count($dir_array);
if (!$is_certificate_mode) {
if ($array_len > 1) {
if (empty($_SESSION['_gid'])) {
$url_dir = 'document.php?&curdirpath=/';
$interbreadcrumb[] = array('url' => $url_dir, 'name' => get_lang('HomeDirectory'));
}
}
}
$dir_acum = '';
for ($i = 0; $i < $array_len; $i++) {
$url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
//Max char 80
$url_to_who = cut($dir_array[$i],80);
if ($is_certificate_mode) {
$interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
} else {
$interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
}
$dir_acum .= $dir_array[$i].'/';
}
Display::display_header('','Doc');
// Lib for event log, stats & tracking & record of the access
event_access_tool(TOOL_DOCUMENT);
/* DISPLAY */
if ($to_group_id != 0) { // Add group name after for group documents
$add_group_to_title = ' ('.$group_properties['name'].')';
}
/* Introduction section (editable by course admins) */
if (!empty($_SESSION['_gid'])) {
Display::display_introduction_section(TOOL_DOCUMENT.$_SESSION['_gid']);
} else {
Display::display_introduction_section(TOOL_DOCUMENT);
}
if ($is_allowed_to_edit || $group_member_with_upload_rights) { // TEACHER ONLY
/* MOVE FILE OR DIRECTORY */
$my_get_move = Security::remove_XSS($_GET['move']);
if (isset($_GET['move']) && $_GET['move'] != '') {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) {
api_not_allowed();
}
}
if (DocumentManager::get_document_id($_course, $my_get_move)) {
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
echo '
'.get_lang('Move').'
';
echo build_move_to_selector($folders, Security::remove_XSS($_GET['curdirpath']), $my_get_move, $group_properties['directory']);
}
}
if (isset($_POST['move_to']) && isset($_POST['move_file'])) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $my_get_move)) {
api_not_allowed();
}
}
require_once $lib_path.'fileManage.lib.php';
// This is needed for the update_db_info function
//$dbTable = $_course['dbNameGlu'].'document';
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
// Security fix: make sure they can't move files that are not in the document table
if (DocumentManager::get_document_id($_course, $_POST['move_file'])) {
if (move($base_work_dir.$_POST['move_file'], $base_work_dir.$_POST['move_to'])) {
update_db_info('update', $_POST['move_file'], $_POST['move_to'].'/'.basename($_POST['move_file']));
// Set the current path
$curdirpath = $_POST['move_to'];
$curdirpathurl = urlencode($_POST['move_to']);
Display::display_confirmation_message(get_lang('DirMv'));
} else {
Display::display_error_message(get_lang('Impossible'));
}
} else {
Display::display_error_message(get_lang('Impossible'));
}
}
/* DELETE FILE OR DIRECTORY */
if (isset($_GET['delete'])) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $_GET['delete'], '', true)) {
api_not_allowed();
}
}
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) {
$course_id = api_get_course_id();
$default_certificate_id = $_GET['delete_certificate_id'];
DocumentManager::remove_attach_certificate($course_id, $default_certificate_id);
}
Display::display_confirmation_message(get_lang('DocDeleted'));
} else {
Display::display_error_message(get_lang('DocDeleteError'));
}
}
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'delete':
foreach ($_POST['path'] as $index => & $path) {
if (!$is_allowed_to_edit) {
if (DocumentManager::check_readonly($_course, $_user['user_id'], $path)) {
Display::display_error_message(get_lang('CantDeleteReadonlyFiles'));
break 2;
}
}
}
foreach ($_POST['path'] as $index => & $path) {
if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
continue;
} else {
$delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir);
}
}
if (!empty($delete_document)) {
Display::display_confirmation_message(get_lang('DocDeleted'));
}
break;
}
}
/* CREATE DIRECTORY */
// Create directory with $_POST data
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
// Needed for directory creation
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$post_dir_name = Security::remove_XSS($_POST['dirname']);
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
Display::display_error_message(get_lang('CannotCreateDir'));
} else {
$added_slash = ($curdirpath == '/') ? '' : '/';
$dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
$dir_name = disable_dangerous_file($dir_name);
$dir_check = $base_work_dir.$dir_name;
if (!is_dir($dir_check)) {
$created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
if ($created_dir) {
Display::display_confirmation_message(''.get_lang('DirCr').'', false);
// Uncomment if you want to enter the created dir
//$curdirpath = $created_dir;
//$curdirpathurl = urlencode($curdirpath);
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
}
}
// Show them the form for the directory name
if (isset($_GET['createdir'])) {
// Show the form
echo create_dir_form();
}
/* VISIBILITY COMMANDS */
if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) && $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*') {
// Make visible or invisible?
if (isset($_GET['set_visible'])) {
$update_id = $_GET['set_visible'];
$visibility_command = 'visible';
} else {
$update_id = $_GET['set_invisible'];
$visibility_command = 'invisible';
}
if (!$is_allowed_to_edit) {
if(DocumentManager::check_readonly($_course, $_user['user_id'], '', $update_id)) {
api_not_allowed();
}
}
// Update item_property to change visibility
if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, $_user['user_id'], null, null, null, null, $current_session_id)) {
Display::display_confirmation_message(get_lang('ViMod'));
} else {
Display::display_error_message(get_lang('ViModProb'));
}
}
/* TEMPLATE ACTION */
if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
$document_id_for_template = intval($_GET['add_as_template']);
// Create the form that asks for the directory name
$template_text = '';
// Show the form
Display::display_normal_message($template_text, false);
} elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
$document_id_for_template = intval(Database::escape_string($_GET['add_as_template']));
$title = Security::remove_XSS($_POST['template_title']);
//$description = Security::remove_XSS($_POST['template_description']);
$course_code = api_get_course_id();
$user_id = api_get_user_id();
// Create the template_thumbnails folder in the upload folder (if needed)
if (!is_dir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/')) {
@mkdir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/', api_get_permissions_for_new_directories());
}
// Upload the file
if (!empty($_FILES['template_image']['name'])) {
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$upload_ok = process_uploaded_file($_FILES['template_image']);
if ($upload_ok) {
// Try to add an extension to the file if it hasn't one
$new_file_name = $_course['sysCode'].'-'.add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
// Upload dir
$upload_dir = api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/';
// Resize image to max default and end upload
require_once (api_get_path(LIBRARY_PATH).'image.lib.php');
$temp = new image($_FILES['template_image']['tmp_name']);
$picture_infos = @getimagesize($_FILES['template_image']['tmp_name']);
$max_width_for_picture = 100;
if ($picture_infos[0] > $max_width_for_picture) {
$thumbwidth = $max_width_for_picture;
if (empty($thumbwidth) || $thumbwidth == 0) {
$thumbwidth = $max_width_for_picture;
}
$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
$temp->resize($thumbwidth, $new_height, 0);
}
$type = $picture_infos[2];
switch (!empty($type)) {
case 2 : $temp->send_image('JPG', $upload_dir.$new_file_name);
break;
case 3 : $temp->send_image('PNG', $upload_dir.$new_file_name);
break;
case 1 : $temp->send_image('GIF', $upload_dir.$new_file_name);
break;
}
}
}
DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $new_file_name);
Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
}
if (isset($_GET['remove_as_template'])) {
$document_id_for_template = intval($_GET['remove_as_template']);
$course_code = api_get_course_id();
$user_id = api_get_user_id();
DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
}
} // END is allowed to edit
// Attach certificate in the gradebook
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_certificate']) && $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))) {
if (isset($_GET['cidReq'])) {
$course_id = Security::remove_XSS($_GET['cidReq']); // course id
$document_id = Security::remove_XSS($_GET['set_certificate']); // document id
DocumentManager::attach_gradebook_certificate ($course_id,$document_id);
Display::display_normal_message(get_lang('IsDefaultCertificate'));
}
}
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
if(isset($_GET['keyword']) && !empty($_GET['keyword'])){
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, $search=true);
}else{
$docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, $search=false);
}
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
if ($folders === false) {
$folders = array();
}
echo '
';
/* BUILD SEARCH FORM */
echo '';
$form = new FormValidator('search_document', 'get', '', '', null, false);
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('{element} ');
$form->add_textfield('keyword', '', false);
$form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
$form->display();
echo '';
/* GO TO PARENT DIRECTORY */
if ($curdirpath!= '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
?>
');
//print_r($docs_and_folders);
//echo('');
// Do we need the title field for the document name or not?
// We get the setting here, so we only have to do it once
$use_document_title = api_get_setting('use_document_title');
// Create a sortable table with our data
$sortable_data = array();
while (list($key, $id) = each($docs_and_folders)) {
$row = array();
// If the item is invisible, wrap it in a span with class invisible
$invisibility_span_open = ($id['visibility'] == 0) ? '' : '';
$invisibility_span_close = ($id['visibility'] == 0) ? '' : '';
// Size (or total size of a directory)
$size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id['size'];
// Get the title or the basename depending on what we're using
if ($use_document_title == 'true' && $id['title'] != '') {
$document_name = $id['title'];
} else {
$document_name = basename($id['path']);
}
// Data for checkbox
if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
$row[] = $id['path'];
}
// Show the owner of the file only in groups
$user_link = '';
if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
if (!empty($id['insert_user_id'])) {
$user_info = UserManager::get_user_info_by_id($id['insert_user_id']);
$user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
$user_link = '