'; $error404 .= '
'; $error404 .= 'The requested URL was not found on this server.
'; $error404 .= ''.''.get_lang("No").' | '.get_lang('Yes').'
'; if (!isset($_GET['copy'])){ Display::display_warning_message($message,false); } if (Security::remove_XSS($_GET['copy']) == 'yes'){ if (!copy($file, $copyfile)) { Display::display_error_message(get_lang('CopyFailed')); } else { Display::display_confirmation_message(get_lang('OverwritenFile')); } } } else { if (!copy($file, $copyfile)) { Display::display_error_message(get_lang('CopyFailed')); } else { Display::display_confirmation_message(get_lang('CopyMade')); } } } /* MOVE FILE OR DIRECTORY */ //Only teacher and all users into their group and each user into his/her shared folder if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($_POST['move_to']), $session_id)) { if (isset($_GET['move']) && $_GET['move'] != '') { $my_get_move = intval($_REQUEST['move']); if (api_is_coach()) { if (!DocumentManager::is_visible_by_id($my_get_move, $course_info, api_get_session_id(), api_get_user_id())) { api_not_allowed(); } } if (!$is_allowed_to_edit) { if (DocumentManager::check_readonly($_course, api_get_user_id(), $my_get_move)) { api_not_allowed(); } } $document_to_move = DocumentManager::get_document_data_by_id($my_get_move, api_get_course_id()); $move_path = $document_to_move['path']; if (!empty($document_to_move)) { $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights); //filter if is my shared folder. TODO: move this code to build_move_to_selector function if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) && !$is_allowed_to_edit){ $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();//only main user shared folder $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//';//all subfolders $user_shared_folders=array(); foreach($folders as $fold){ if($main_user_shared_folder_main==$fold || preg_match($main_user_shared_folder_sub, $fold)){ $user_shared_folders[]=$fold; } } echo ''; echo build_move_to_selector($user_shared_folders, $move_path, $my_get_move, $group_properties['directory']); } else { echo ''; echo build_move_to_selector($folders, $move_path, $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, api_get_user_id(), $_POST['move_file'])) { api_not_allowed(); } } if (api_is_coach()) { if (!DocumentManager::is_visible_by_id($_POST['move_file'], $_course, api_get_session_id(), api_get_user_id())) { api_not_allowed(); } } $document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id()); require_once $lib_path.'fileManage.lib.php'; // Security fix: make sure they can't move files that are not in the document table if (!empty($document_to_move)) { $real_path_target = $base_work_dir.$_POST['move_to'].'/'.basename($document_to_move['path']); $fileExist=false; if(file_exists($real_path_target)){ $fileExist=true; } if (move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) { //if (1) { //$contents = DocumentManager::replace_urls_inside_content_html_when_moving_file(basename($document_to_move['path']), $base_work_dir.dirname($document_to_move['path']), $base_work_dir.$_POST['move_to']); //exit; update_db_info('update', $document_to_move['path'], $_POST['move_to'].'/'.basename($document_to_move['path'])); //update database item property $doc_id=$_POST['move_file']; if(is_dir($real_path_target)){ api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderMoved', api_get_user_id(),$to_group_id,null,null,null,$session_id); Display::display_confirmation_message(get_lang('DirMv')); } elseif(is_file($real_path_target)){ api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentMoved', api_get_user_id(),$to_group_id,null,null,null,$session_id); Display::display_confirmation_message(get_lang('DocMv')); } // Set the current path $curdirpath = $_POST['move_to']; $curdirpathurl = urlencode($_POST['move_to']); } else { if($fileExist){ if(is_dir($real_path_target)){ Display::display_error_message(get_lang('DirExists')); } elseif(is_file($real_path_target)){ Display::display_error_message(get_lang('FileExists')); } } else{ Display::display_error_message(get_lang('Impossible')); } } } else { Display::display_error_message(get_lang('Impossible')); } } } /* DELETE FILE OR DIRECTORY */ //Only teacher and all users into their group if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)){ if (isset($_GET['delete'])) { if (!$is_allowed_to_edit) { if (api_is_coach()) { if (!DocumentManager::is_visible($_GET['delete'], $_course, api_get_session_id())) { api_not_allowed(); } } if (DocumentManager::check_readonly($_course, api_get_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']))) { $default_certificate_id = $_GET['delete_certificate_id']; DocumentManager::remove_attach_certificate(api_get_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, api_get_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 */ //Only teacher and all users into their group and any user into his/her shared folder if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) { // 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 = $_POST['dirname']; if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') { Display::display_error_message(get_lang('CannotCreateDir')); } else { if (!empty($_POST['dir_id'])) { $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id()); $curdirpath = $document_data['path']; } $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, api_get_user_id(), api_get_session_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'])) { echo create_dir_form($document_id); } } /* VISIBILITY COMMANDS */ //Only teacher if ($is_allowed_to_edit) { 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 = intval($_GET['set_visible']); $visibility_command = 'visible'; } else { $update_id = intval($_GET['set_invisible']); $visibility_command = 'invisible'; } if (!$is_allowed_to_edit) { if (api_is_coach()) { if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id(), api_get_user_id())) { api_not_allowed(); } } if (DocumentManager::check_readonly($_course, api_get_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, api_get_user_id(), null, null, null, null, $session_id)) { Display::display_confirmation_message(get_lang('VisibilityChanged'));//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all) } else { Display::display_error_message(get_lang('ViModProb')); } } } /* TEMPLATE ACTION */ //Only teacher and all users into their group if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)){ 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']); $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 $temp = new Image($_FILES['template_image']['tmp_name']); $picture_info = $temp->get_image_info(); $max_width_for_picture = 100; if ($picture_info['width'] > $max_width_for_picture) { $thumbwidth = $max_width_for_picture; if (empty($thumbwidth) || $thumbwidth == 0) { $thumbwidth = $max_width_for_picture; } $new_height = round(($thumbwidth/$picture_info['width'])*$picture_info['height']); $temp->resize($thumbwidth, $new_height, 0); } $temp->send_image($upload_dir.$new_file_name); } } 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']); $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 ACTION MENU // 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, 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, 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(); } $table_footer = ''; $total_size = 0; if (isset($docs_and_folders) && is_array($docs_and_folders)) { // 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(); $count = 1; foreach ($docs_and_folders as $key => $document_data) { $row = array(); $row['id'] = $document_data['id']; //$row['type'] = $document_data['filetype']; $row['type'] = create_document_link($document_data, true, $count, $is_visible); // If the item is invisible, wrap it in a span with class invisible $is_visible = DocumentManager::is_visible_by_id($document_data['id'], $course_info, api_get_session_id(), api_get_user_id(), false); $invisibility_span_open = ($is_visible == 0) ? '' : ''; $invisibility_span_close = ($is_visible == 0) ? '' : ''; // Size (or total size of a directory) $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size']; $row['size'] = format_file_size($size); // Get the title or the basename depending on what we're using if ($use_document_title == 'true' && $document_data['title'] != '') { $document_name = $document_data['title']; } else { $document_name = basename($document_data['path']); } $row['name'] = $document_name; $row['name'] = create_document_link($document_data, false, null, $is_visible).$session_img.'