$(document).ready(function() { $(".scrollbar-light").scrollbar(); expandColumnToogle("#hide_bar_template", { selector: "#template_col", width: 3 }, { selector: "#doc_form", width: 9 }); CKEDITOR.on("instanceReady", function (e) { showTemplates(); }); }); '; $_SESSION['whereami'] = 'document/create'; $this_section = SECTION_COURSES; $lib_path = api_get_path(LIBRARY_PATH); $course_info = api_get_course_info(); $group_id = api_get_group_id(); $sessionId = api_get_session_id(); if (api_is_in_group()) { $group_properties = GroupManager::get_group_properties($group_id); } $dir = '/'; $currentDirPath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null; $readonly = false; if (isset($_GET['id'])) { $document_data = DocumentManager::get_document_data_by_id( $_GET['id'], api_get_course_id(), true, 0 ); if (!empty($sessionId) && empty($document_data)) { $document_data = DocumentManager::get_document_data_by_id( $_REQUEST['id'], api_get_course_id(), true, $sessionId ); } $document_id = $document_data['id']; $file = $document_data['path']; $parent_id = DocumentManager::get_document_id($course_info, dirname($file)); $dir = dirname($document_data['path']); $dir_original = $dir; $doc = basename($file); $readonly = $document_data['readonly']; } if (empty($document_data)) { api_not_allowed(true); } $is_certificate_mode = DocumentManager::is_certificate_mode($dir); //Call from $call_from_tool = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null; $slide_id = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null; $file_name = $doc; $group_document = false; $_course = api_get_course_info(); $sessionId = api_get_session_id(); $user_id = api_get_user_id(); $doc_tree = explode('/', $file); $count_dir = count($doc_tree) - 2; // "2" because at the begin and end there are 2 "/" // Level correction for group documents. if (!empty($group_properties['directory'])) { $count_dir = $count_dir > 0 ? $count_dir - 1 : 0; } $relative_url = ''; for ($i = 0; $i < ($count_dir); $i++) { $relative_url .= '../'; } $editorConfig = array( 'ToolbarSet' => (api_is_allowed_to_edit(null, true) ? 'Documents' : 'DocumentsStudent'), 'Width' => '100%', 'Height' => '400', 'cols-size' => [2, 10, 0], 'FullPage' => true, 'InDocument' => true, 'CreateDocumentDir' => $relative_url, 'CreateDocumentWebDir' => (empty($group_properties['directory'])) ? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/' : api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/', 'BaseHref' => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir ); if ($is_certificate_mode) { $editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; $editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; $editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir; } $is_allowed_to_edit = api_is_allowed_to_edit(null, true) || $groupRights || DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId); $noPHP_SELF = true; /* Other initialization code */ $dbTable = Database::get_course_table(TABLE_DOCUMENT); $course_id = api_get_course_int_id(); if (!empty($group_id)) { $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), 'name' => get_lang('GroupSpace'), ); $group_document = true; $noPHP_SELF = true; } if (!$is_certificate_mode) { $interbreadcrumb[] = array( "url" => api_get_path(WEB_CODE_PATH)."document/document.php?curdirpath=".urlencode($currentDirPath).'&'.api_get_cidreq(), "name" => get_lang('Documents'), ); } else { $interbreadcrumb[] = array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); } if (empty($document_data['parents'])) { $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']); } else { foreach ($document_data['parents'] as $document_sub_data) { if ($document_data['title'] == $document_sub_data['title']) { continue; } $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); } } if (!($is_allowed_to_edit || $groupRights || DocumentManager::is_my_shared_folder($user_id, $dir, api_get_session_id())) ) { api_not_allowed(true); } Event::event_access_tool(TOOL_DOCUMENT); //TODO:check the below code and his funcionality if (!api_is_allowed_to_edit()) { if (DocumentManager::check_readonly($course_info, $user_id, $file)) { api_not_allowed(); } } /* MAIN TOOL CODE */ /* Code to change the comment */ if (isset($_POST['comment'])) { // Fixing the path if it is wrong $comment = trim($_POST['comment']); $title = trim($_POST['title']); // Just in case see BT#3525 if (empty($title)) { $title = $document_data['title']; } if (empty($title)) { $title = get_document_title($_POST['filename']); } if (!empty($document_id)) { $params = [ 'comment' => $comment, 'title' => $title, ]; Database::update( $dbTable, $params, ['c_id = ? AND id = ?' => [$course_id, $document_id]] ); Display::addFlash(Display::return_message(get_lang('fileModified'))); } } /* WYSIWYG HTML EDITOR - Program Logic */ if ($is_allowed_to_edit) { if (isset($_POST['formSent']) && $_POST['formSent'] == 1) { $filename = stripslashes($_POST['filename']); $extension = $_POST['extension']; $content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null; $content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY); if ($dir == '/') { $dir = ''; } $file = $dir.'/'.$filename.'.'.$extension; $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; $read_only_flag = empty($read_only_flag) ? 0 : 1; if (empty($filename)) { Display::addFlash(Display::return_message(get_lang('NoFileName'), 'warning')); } else { $file_size = filesize($document_data['absolute_path']); if ($read_only_flag == 0) { if (!empty($content)) { if ($fp = @fopen($document_data['absolute_path'], 'w')) { // For flv player, change absolute path temporarily to prevent from erasing it in the following lines $content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content); fputs($fp, $content); fclose($fp); $filepath = $document_data['absolute_parent_path']; /* if (!is_dir($filepath.'css')) { mkdir($filepath.'css', api_get_permissions_for_new_directories()); $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css'); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id(), null, null, null, null, $sessionId ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $sessionId ); }*/ /*if (!is_file($filepath.'css/frames.css')) { $platform_theme = api_get_setting('stylesheets'); if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) { copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css'); $doc_id = add_document( $_course, $dir . 'css/frames.css', 'file', filesize($filepath . 'css/frames.css'), 'frames.css' ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, $sessionId ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $sessionId ); } }*/ // "WHAT'S NEW" notification: update table item_property $document_id = DocumentManager::get_document_id($_course, $file); if ($document_id) { update_existing_document( $_course, $document_id, $file_size, $read_only_flag ); api_item_property_update( $_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', api_get_user_id(), null, null, null, null, $sessionId ); // Update parent folders item_property_update_on_folder( $_course, $dir, api_get_user_id() ); header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '')); exit; } else { Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); } } else { Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); } } else { if ($document_id) { update_existing_document($_course, $document_id, $file_size, $read_only_flag); } } } else { if ($document_id) { update_existing_document($_course, $document_id, $file_size, $read_only_flag); } } } } } // Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/') $content = null; $extension = null; $filename = null; if (file_exists($document_data['absolute_path'])) { $path_info = pathinfo($document_data['absolute_path']); $filename = $path_info['filename']; if (is_file($document_data['absolute_path'])) { $extension = $path_info['extension']; if (in_array($extension, array('html', 'htm'))) { $content = file($document_data['absolute_path']); $content = implode('', $content); } } } /* Display user interface */ // Display the header $nameTools = get_lang('EditDocument').': '.Security::remove_XSS($document_data['title']); Display::display_header($nameTools, 'Doc'); $document_info = api_get_item_property_info( api_get_course_int_id(), 'document', $document_id, 0 ); // Try to find this document in the session if (!empty($sessionId)) { $document_info = api_get_item_property_info( api_get_course_int_id(), 'document', $document_id, $sessionId ); } $owner_id = $document_info['insert_user_id']; $last_edit_date = $document_info['lastedit_date']; $groupInfo = GroupManager::get_group_properties(api_get_group_id()); if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_edit || GroupManager:: is_user_in_group( api_get_user_id(), $groupInfo ) ) { $action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); if ($is_certificate_mode) { $action .= '&curdirpath=/certificates&selectcat=1'; } $form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical')); // Form title $form->addElement('header', $nameTools); $form->addElement('hidden', 'filename'); $form->addElement('hidden', 'extension'); $form->addElement('hidden', 'file_path'); $form->addElement('hidden', 'commentPath'); $form->addElement('hidden', 'showedit'); $form->addElement('hidden', 'origin'); $form->addElement('hidden', 'origin_opt'); $form->addText('title', get_lang('Title'), true, array('cols-size' => [2, 10, 0], 'autofocus')); $defaults['title'] = $document_data['title']; $form->addElement('hidden', 'formSent'); $defaults['formSent'] = 1; $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; // Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor. // This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573 $defaults['content'] = str_replace('