diff --git a/main/document/document.php b/main/document/document.php index 7370de43ae..dcfcd16792 100755 --- a/main/document/document.php +++ b/main/document/document.php @@ -9,19 +9,19 @@ use ChamiloSession as Session; * 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) + * - 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: 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. + * 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 @@ -67,9 +67,9 @@ if (!$allowUseTool) { DocumentManager::removeGeneratedAudioTempFile(); if ( - isset($_SESSION['temp_realpath_image']) && - !empty($_SESSION['temp_realpath_image']) && - file_exists($_SESSION['temp_realpath_image']) + isset($_SESSION['temp_realpath_image']) + && !empty($_SESSION['temp_realpath_image']) + && file_exists($_SESSION['temp_realpath_image']) ) { unlink($_SESSION['temp_realpath_image']); } @@ -109,15 +109,15 @@ $capturePluginInstalled = in_array('jcapture', $pluginList); if ($capturePluginInstalled) { $jcapturePath = api_get_path(WEB_PLUGIN_PATH).'jcapture/plugin_applet.php'; - $htmlHeadXtra[] = ''; + + '; } if (empty($courseInfo)) { @@ -196,9 +196,10 @@ if (!empty($groupId)) { ); // Allowed to upload? - if ($isAllowedToEdit || - GroupManager::is_subscribed($userId, $group_properties) || - GroupManager::is_tutor_of_group($userId, $group_properties, $courseId) + if ( + $isAllowedToEdit + || GroupManager::is_subscribed($userId, $group_properties) + || GroupManager::is_tutor_of_group($userId, $group_properties, $courseId) ) { // Only course admin or group members can upload $group_member_with_upload_rights = true; @@ -222,10 +223,11 @@ $curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpat switch ($action) { case 'delete_item': - if ($isAllowedToEdit || - $group_member_with_upload_rights || - DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) || - DocumentManager::is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId) + if ( + $isAllowedToEdit + || $group_member_with_upload_rights + || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) + || DocumentManager::is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId) ) { if (isset($_GET['deleteid'])) { if (!$isAllowedToEdit) { @@ -241,14 +243,7 @@ switch ($action) { } } - if (DocumentManager::check_readonly( - $courseInfo, - api_get_user_id(), - '', - $_GET['deleteid'], - true - ) - ) { + if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $_GET['deleteid'], true)) { api_not_allowed(); } } @@ -318,8 +313,10 @@ switch ($action) { // Launch event Event::event_download($document_data['url']); // Check visibility of document and paths - if (!($isAllowedToEdit || $group_member_with_upload_rights) - && !DocumentManager::is_visible_by_id($document_id, $courseInfo, $sessionId, api_get_user_id())) { + if ( + !($isAllowedToEdit || $group_member_with_upload_rights) + && !DocumentManager::is_visible_by_id($document_id, $courseInfo, $sessionId, api_get_user_id()) + ) { api_not_allowed(true); } $full_file_name = $base_work_dir.$document_data['path']; @@ -358,9 +355,11 @@ switch ($action) { //filter when I am into shared folder, I can download only my shared folder if (DocumentManager::is_any_user_shared_folder($document_data['path'], $sessionId)) { - if (DocumentManager::is_my_shared_folder(api_get_user_id(), $document_data['path'], $sessionId) + if ( + DocumentManager::is_my_shared_folder(api_get_user_id(), $document_data['path'], $sessionId) || $isAllowedToEdit - || api_is_platform_admin()) { + || api_is_platform_admin() + ) { require 'downloadfolder.inc.php'; } } else { @@ -372,26 +371,27 @@ switch ($action) { } break; case 'export_to_pdf': - if (api_get_setting('students_export2pdf') == 'true' || $isAllowedToEdit || api_is_platform_admin()) { + if ( + api_get_setting('students_export2pdf') == 'true' + || $isAllowedToEdit + || api_is_platform_admin() + ) { $orientation = 'landscape'; $showHeaderAndFooter = true; + if ($is_certificate_mode) { $orientation = api_get_configuration_value('certificate_pdf_orientation'); $showHeaderAndFooter = !api_get_configuration_value('hide_header_footer_in_certificate'); } - DocumentManager::export_to_pdf( - $document_id, - $course_code, - $orientation, - $showHeaderAndFooter - ); + DocumentManager::export_to_pdf($document_id, $course_code, $orientation, $showHeaderAndFooter); } break; case 'copytomyfiles': // Copy a file to general my files user's - if (api_get_setting('allow_my_files') == 'true' && - api_get_setting('users_copy_files') == 'true' + if ( + api_get_setting('allow_my_files') == 'true' + && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0 && !api_is_anonymous() ) { @@ -433,7 +433,8 @@ switch ($action) { } $file_link = Display::url( get_lang('SeeFile'), - api_get_path(WEB_CODE_PATH).'social/myfiles.php?'.api_get_cidreq_params($cidReq, $id_session, $gidReq). + api_get_path(WEB_CODE_PATH).'social/myfiles.php?' + .api_get_cidreq_params($cidReq, $id_session, $gidReq). '&parent_id='.$parent_id ); @@ -443,16 +444,18 @@ switch ($action) { if (file_exists($copyfile)) { $message = get_lang('CopyAlreadyDone').'
'; - $message .= ''. - get_lang("No"). - ''. - ' | '. - ''. - get_lang('Yes'). - '
'; + $message .= '' + .get_lang("No") + .'' + .' | ' + .'' + .get_lang('Yes') + .''; if (!isset($_GET['copy'])) { Display::addFlash(Display::return_message($message, 'warning', false)); } @@ -480,10 +483,12 @@ switch ($action) { break; case 'convertToPdf': // PDF format as target by default - $formatTarget = $_REQUEST['formatTarget'] ? - strtolower(Security::remove_XSS($_REQUEST['formatTarget'])) : 'pdf'; - $formatType = $_REQUEST['formatType'] ? - strtolower(Security::remove_XSS($_REQUEST['formatType'])) : 'text'; + $formatTarget = $_REQUEST['formatTarget'] + ? strtolower(Security::remove_XSS($_REQUEST['formatTarget'])) + : 'pdf'; + $formatType = $_REQUEST['formatType'] + ? strtolower(Security::remove_XSS($_REQUEST['formatType'])) + : 'text'; // Get the document data from the ID $document_info = DocumentManager::get_document_data_by_id( $document_id, @@ -491,8 +496,7 @@ switch ($action) { true, $session_id ); - $file = $sys_course_path.$courseInfo['directory']. - '/document'.$document_info['path']; + $file = $sys_course_path.$courseInfo['directory'].'/document'.$document_info['path']; $fileInfo = pathinfo($file); if ($fileInfo['extension'] == $formatTarget) { Display::addFlash(Display::return_message( @@ -503,18 +507,13 @@ switch ($action) { !( in_array( $fileInfo['extension'], - DocumentManager::getJodconverterExtensionList( - 'from', - $formatType - ) + DocumentManager::getJodconverterExtensionList('from', $formatType) ) - ) || !( + ) + || !( in_array( $formatTarget, - DocumentManager::getJodconverterExtensionList( - 'to', - $formatType - ) + DocumentManager::getJodconverterExtensionList('to', $formatType) ) ) ) { @@ -523,9 +522,9 @@ switch ($action) { 'warning' )); } else { - $convertedFile = $fileInfo['dirname'].DIRECTORY_SEPARATOR. - $fileInfo['filename'].'_from_'.$fileInfo['extension']. - '.'.$formatTarget; + $convertedFile = $fileInfo['dirname'].DIRECTORY_SEPARATOR + .$fileInfo['filename'].'_from_'.$fileInfo['extension'] + .'.'.$formatTarget; $convertedTitle = $document_info['title']; $obj = new OpenofficePresentation(true); if (file_exists($convertedFile)) { @@ -550,8 +549,10 @@ switch ($action) { $gidReq = Security::remove_XSS($_GET['gidReq']); $file_link = Display::url( get_lang('SeeFile'), - api_get_path(WEB_CODE_PATH). - 'document/showinframes.php?'.api_get_cidreq_params($cidReq, $id_session, $gidReq).'&id='.current($result) + api_get_path(WEB_CODE_PATH) + .'document/showinframes.php?' + .api_get_cidreq_params($cidReq, $id_session, $gidReq) + .'&id='.current($result) ); Display::addFlash(Display::return_message( get_lang('CopyMade').' '.$file_link, @@ -677,10 +678,10 @@ if (!$parent_id) { $current_folder_id = $document_id; // Show preview -if (isset($_GET['curdirpath']) && - $_GET['curdirpath'] == '/certificates' && - isset($_GET['set_preview']) && - $_GET['set_preview'] == strval(intval($_GET['set_preview'])) +if ( + isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' + && isset($_GET['set_preview']) + && $_GET['set_preview'] == strval(intval($_GET['set_preview'])) ) { if (isset($_GET['set_preview'])) { // Generate document HTML @@ -772,12 +773,12 @@ function convertModal (id, format) { $("." + format + "FormatType").show(); $("#convertSelect").change(function() { var formatTarget = $(this).val(); - window.location.href = "'. - api_get_self().'?'.api_get_cidreq(). - '&curdirpath='.$curdirpath. - '&action=convertToPdf&formatTarget='. - '" + formatTarget + "&id=" + id + "&'. - api_get_cidreq().'&formatType=" + format; + window.location.href = "' + .api_get_self().'?'.api_get_cidreq() + .'&curdirpath='.$curdirpath + .'&action=convertToPdf&formatTarget=' + .'" + formatTarget + "&id=" + id + "&' + .api_get_cidreq().'&formatType=" + format; }); $("#convertModal").on("hidden", function(){ $("." + format + "FormatType").hide(); @@ -796,7 +797,10 @@ if ($groupId != 0 && $curdirpath == '/') { //if (!$isAllowedToEdit || api_is_coach()) { before if (!$isAllowedToEdit && api_is_coach()) { - if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $courseInfo, $sessionId, 'folder'))) { + if ( + $curdirpath != '/' + && !(DocumentManager::is_visible($curdirpath, $courseInfo, $sessionId, 'folder')) + ) { api_not_allowed(true); } } @@ -887,12 +891,21 @@ $_SESSION['image_files_only'] = ''; $image_files_only = ''; if ($is_certificate_mode) { - $interbreadcrumb[] = array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook')); + $interbreadcrumb[] = array( + 'url' => '../gradebook/index.php', + 'name' => get_lang('Gradebook') + ); } else { if ((isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath']) || isset($_GET['createdir'])) { - $interbreadcrumb[] = array('url' => 'document.php', 'name' => get_lang('Documents')); + $interbreadcrumb[] = array( + 'url' => 'document.php', + 'name' => get_lang('Documents') + ); } else { - $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Documents')); + $interbreadcrumb[] = array( + 'url' => '#', + 'name' => get_lang('Documents') + ); } } @@ -904,7 +917,10 @@ if (empty($document_data['parents'])) { 'name' => $document_data['title'], ); } else { - $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); + $interbreadcrumb[] = array( + 'url' => '#', + 'name' => $document_data['title'] + ); } } else { $counter = 0; @@ -933,8 +949,10 @@ if (isset($_GET['createdir'])) { $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/'; -$htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; $mediaplayer_path = api_get_path(WEB_LIBRARY_PATH).'mediaplayer/player.swf'; $documentAndFolders = DocumentManager::get_all_document_data( @@ -983,7 +1001,8 @@ if (!empty($documentAndFolders)) { $extension = 'oga'; } - $params = array('url' => $document_data['direct_url'], + $params = array( + 'url' => $document_data['direct_url'], 'extension' => $extension, 'count' => $count ); @@ -994,12 +1013,14 @@ if (!empty($documentAndFolders)) { } } -$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ' + +'; // Lib for event log, stats & tracking & record of the access Event::event_access_tool(TOOL_DOCUMENT); @@ -1013,10 +1034,10 @@ $moveForm = ''; /* MOVE FILE OR DIRECTORY */ //Only teacher and all users into their group and each user into his/her shared folder -if ($isAllowedToEdit || - $group_member_with_upload_rights || - DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) || - DocumentManager::is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId) +if ( + $isAllowedToEdit || $group_member_with_upload_rights + || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) + || DocumentManager::is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId) ) { if (isset($_GET['move']) && $_GET['move'] != '') { $my_get_move = intval($_REQUEST['move']); @@ -1051,8 +1072,9 @@ if ($isAllowedToEdit || ); // filter if is my shared folder. TODO: move this code to build_move_to_selector function - if (DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) && - !$isAllowedToEdit + if ( + DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) + && !$isAllowedToEdit ) { //only main user shared folder $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id(); @@ -1060,7 +1082,10 @@ if ($isAllowedToEdit || $user_shared_folders = array(); foreach ($folders as $fold) { - if ($main_user_shared_folder_main == $fold || preg_match($main_user_shared_folder_sub, $fold)) { + if ( + $main_user_shared_folder_main == $fold + || preg_match($main_user_shared_folder_sub, $fold) + ) { $user_shared_folders[] = $fold; } } @@ -1176,9 +1201,9 @@ if ($isAllowedToEdit || /* DELETE FILE OR DIRECTORY */ //Only teacher and all users into their group -if ($isAllowedToEdit || - $group_member_with_upload_rights || - DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) +if ( + $isAllowedToEdit || $group_member_with_upload_rights + || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ) { if (isset($_POST['action']) && isset($_POST['ids'])) { $files = $_POST['ids']; @@ -1214,7 +1239,10 @@ if ($isAllowedToEdit || null, $sessionId )) { - $messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['title'], 'confirmation'); + $messages .= Display::return_message( + get_lang('VisibilityChanged').': '.$data['title'], + 'confirmation' + ); } else { $messages .= Display::return_message(get_lang('ViModProb'), 'error'); } @@ -1233,7 +1261,10 @@ if ($isAllowedToEdit || null, $sessionId )) { - $messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['title'], 'confirmation'); + $messages .= Display::return_message( + get_lang('VisibilityChanged').': '.$data['title'], + 'confirmation' + ); } else { $messages .= Display::return_message(get_lang('ViModProb'), 'error'); } @@ -1246,13 +1277,14 @@ if ($isAllowedToEdit || foreach ($files as $id) { if (!$isAllowedToEdit) { if (DocumentManager::check_readonly( - $courseInfo, - api_get_user_id(), - null, - $id, - false, - $sessionId - )) { + $courseInfo, + api_get_user_id(), + null, + $id, + false, + $sessionId + ) + ) { $messages .= Display::return_message( get_lang('CantDeleteReadonlyFiles'), 'error' @@ -1293,9 +1325,9 @@ $dirForm = ''; /* CREATE DIRECTORY */ //Only teacher and all users into their group and any user into his/her shared folder -if ($isAllowedToEdit || - $group_member_with_upload_rights || - DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) +if ( + $isAllowedToEdit || $group_member_with_upload_rights + || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ) { // Create directory with $_POST data if (isset($_POST['create_dir']) && $_POST['dirname'] != '') { @@ -1369,8 +1401,9 @@ if ($isAllowedToEdit || /* VISIBILITY COMMANDS */ if ($isAllowedToEdit) { - if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || - (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) + if ( + (isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) + || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) ) { // Make visible or invisible? if (isset($_GET['set_visible'])) { @@ -1423,35 +1456,38 @@ $templateForm = ''; /* TEMPLATE ACTION */ //Only teacher and all users into their group -if ($isAllowedToEdit || - $group_member_with_upload_rights || - DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) +if ( + $isAllowedToEdit || $group_member_with_upload_rights + || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ) { 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 $templateForm .= ' -