Minor - format code

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 3df83b1511
commit 9bae4ead33
  1. 317
      main/document/create_document.php

@ -4,18 +4,16 @@
use ChamiloSession as Session;
/**
* This file allows creating new html documents with an online WYSIWYG html editor.
* This file allows creating new html documents with an online WYSIWYG html editor.
*
* @package chamilo.document
* @package chamilo.document
*/
require_once __DIR__.'/../inc/global.inc.php';
$_SESSION['whereami'] = 'document/create';
$this_section = SECTION_COURSES;
$groupRights = Session::read('group_member_with_upload_rights');
$htmlHeadXtra[] = '
<script>
$(document).ready(function() {
@ -159,11 +157,11 @@ if (api_is_in_group()) {
}
$relative_url = '';
for ($i = 0; $i < ($count_dir); $i++) {
$relative_url .= '../';
$relative_url .= '../';
}
if ($relative_url == '') {
$relative_url = '/';
$relative_url = '/';
}
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
@ -175,11 +173,11 @@ $editorConfig = array(
'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
'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) {
@ -191,41 +189,44 @@ if ($is_certificate_mode) {
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
if (!is_dir($filepath)) {
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
$dir = '/';
$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
$dir = '/';
}
$to_group_id = 0;
if (!$is_certificate_mode) {
if (api_is_in_group()) {
if (api_is_in_group()) {
$interbreadcrumb[] = array(
"url" => "../group/group_space.php?".api_get_cidreq(),
"name" => get_lang('GroupSpace'),
);
$noPHP_SELF = true;
$to_group_id = $group_properties['iid'];
$path = explode('/', $dir);
if ('/'.$path[1] != $group_properties['directory']) {
api_not_allowed(true);
}
}
$noPHP_SELF = true;
$to_group_id = $group_properties['iid'];
$path = explode('/', $dir);
if ('/'.$path[1] != $group_properties['directory']) {
api_not_allowed(true);
}
}
$interbreadcrumb[] = array(
"url" => "./document.php?curdirpath=".urlencode($dir)."&".api_get_cidreq(),
"name" => get_lang('Documents'),
);
} else {
$interbreadcrumb[] = array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
$interbreadcrumb[] = array(
'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
'name' => get_lang('Gradebook'),
);
}
if (!api_is_allowed_in_course()) {
api_not_allowed(true);
api_not_allowed(true);
}
if (!($is_allowed_to_edit ||
$groupRights ||
DocumentManager::is_my_shared_folder($userId, $dir, api_get_session_id()))
) {
api_not_allowed(true);
api_not_allowed(true);
}
/* Header */
@ -233,10 +234,10 @@ Event::event_access_tool(TOOL_DOCUMENT);
$display_dir = $dir;
if (isset($group_properties)) {
$display_dir = explode('/', $dir);
unset($display_dir[0]);
unset($display_dir[1]);
$display_dir = implode('/', $display_dir);
$display_dir = explode('/', $dir);
unset($display_dir[0]);
unset($display_dir[1]);
$display_dir = implode('/', $display_dir);
}
$select_cat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : null;
@ -253,9 +254,14 @@ $form = new FormValidator(
$form->addElement('header', $nameTools);
if ($is_certificate_mode) {//added condition for certicate in gradebook
$form->addElement('hidden', 'certificate', 'true', array('id'=>'certificate'));
if (isset($_GET['selectcat'])) {
$form->addElement('hidden', 'selectcat', $select_cat);
$form->addElement(
'hidden',
'certificate',
'true',
array('id' => 'certificate')
);
if (isset($_GET['selectcat'])) {
$form->addElement('hidden', 'selectcat', $select_cat);
}
}
@ -301,7 +307,14 @@ $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists');
$current_session_id = api_get_session_id();
$form->addHtmlEditor('content', get_lang('Content'), true, true, $editorConfig, true);
$form->addHtmlEditor(
'content',
get_lang('Content'),
true,
true,
$editorConfig,
true
);
// Comment-field
$folders = DocumentManager::get_all_document_folders(
@ -329,7 +342,7 @@ if (!$is_certificate_mode &&
array('cols-size' => [2, 10, 0])
);
$folder_titles = array();
$folder_titles = array();
if (is_array($folders)) {
$escaped_folders = array();
foreach ($folders as $key => & $val) {
@ -366,22 +379,22 @@ if (!$is_certificate_mode &&
}
}
if (empty($group_dir)) {
$parent_select -> addOption(get_lang('HomeDirectory'), '/');
if (is_array($folders)) {
foreach ($folders as & $folder) {
//Hide some folders
if ($folder == '/HotPotatoes_files' || $folder == '/certificates' || basename($folder) == 'css') {
if (empty($group_dir)) {
$parent_select -> addOption(get_lang('HomeDirectory'), '/');
if (is_array($folders)) {
foreach ($folders as & $folder) {
//Hide some folders
if ($folder == '/HotPotatoes_files' || $folder == '/certificates' || basename($folder) == 'css') {
continue;
}
//Admin setting for Hide/Show the folders of all users
if (api_get_setting('show_users_folders') == 'false' &&
}
//Admin setting for Hide/Show the folders of all users
if (api_get_setting('show_users_folders') == 'false' &&
(strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))
) {
continue;
}
//Admin setting for Hide/Show Default folders to all users
if (api_get_setting('show_default_folders') == 'false' &&
continue;
}
//Admin setting for Hide/Show Default folders to all users
if (api_get_setting('show_default_folders') == 'false' &&
(
$folder == '/images' ||
$folder == '/flash' ||
@ -391,82 +404,82 @@ if (!$is_certificate_mode &&
$folder == '/video/flv'
)
) {
continue;
}
//Admin setting for Hide/Show chat history folder
if (api_get_setting('show_chat_folder') == 'false' &&
continue;
}
//Admin setting for Hide/Show chat history folder
if (api_get_setting('show_chat_folder') == 'false' &&
$folder == '/chat_files'
) {
continue;
}
continue;
}
$selected = (substr($dir, 0, -1) == $folder) ? ' selected="selected"' : '';
$path_parts = explode('/', $folder);
$folder_titles[$folder] = cut($folder_titles[$folder], 80);
$selected = (substr($dir, 0, -1) == $folder) ? ' selected="selected"' : '';
$path_parts = explode('/', $folder);
$folder_titles[$folder] = cut($folder_titles[$folder], 80);
$space_counter = count($path_parts) - 2;
if ($space_counter > 0) {
$label = str_repeat('&nbsp;&nbsp;&nbsp;', $space_counter).' &mdash; '.$folder_titles[$folder];
} else {
$label = ' &mdash; '.$folder_titles[$folder];
}
$parent_select -> addOption($label, $folder);
if ($selected != '') {
$parent_select->setSelected($folder);
}
}
}
} else {
if (is_array($folders) && !empty($folders)) {
foreach ($folders as & $folder) {
$selected = (substr($dir, 0, -1) == $folder) ? ' selected="selected"' : '';
$label = $folder_titles[$folder];
if ($folder == $group_dir) {
$label = '/ ('.get_lang('HomeDirectory').')';
} else {
$path_parts = explode('/', str_replace($group_dir, '', $folder));
$label = cut($label, 80);
$label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
}
$parent_select->addOption($label, $folder);
if ($selected != '') {
$parent_select->setSelected($folder);
}
}
}
}
$parent_select -> addOption($label, $folder);
if ($selected != '') {
$parent_select->setSelected($folder);
}
}
}
} else {
if (is_array($folders) && !empty($folders)) {
foreach ($folders as & $folder) {
$selected = (substr($dir, 0, -1) == $folder) ? ' selected="selected"' : '';
$label = $folder_titles[$folder];
if ($folder == $group_dir) {
$label = '/ ('.get_lang('HomeDirectory').')';
} else {
$path_parts = explode('/', str_replace($group_dir, '', $folder));
$label = cut($label, 80);
$label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
}
$parent_select->addOption($label, $folder);
if ($selected != '') {
$parent_select->setSelected($folder);
}
}
}
}
}
$form->addHidden('dirValue', '');
if ($is_certificate_mode) {
$form->addButtonCreate(get_lang('CreateCertificate'));
$form->addButtonCreate(get_lang('CreateCertificate'));
} else {
$form->addButtonCreate(get_lang('CreateDoc'));
$form->addButtonCreate(get_lang('CreateDoc'));
}
$form->setDefaults($defaults);
// If form validates -> save the new document
if ($form->validate()) {
$values = $form->exportValues();
$readonly = isset($values['readonly']) ? 1 : 0;
$values['title'] = trim($values['title']);
$values = $form->exportValues();
$readonly = isset($values['readonly']) ? 1 : 0;
$values['title'] = trim($values['title']);
if (!empty($values['dirValue'])) {
$dir = $values['dirValue'];
}
if ($dir[strlen($dir) - 1] != '/') {
$dir .= '/';
}
$dir .= '/';
}
$filepath = $filepath.$dir;
// Setting the filename
$filename = $values['title'];
$filename = addslashes(trim($filename));
$filename = Security::remove_XSS($filename);
$filename = api_replace_dangerous_char($filename);
$filename = disable_dangerous_file($filename);
$filename = $values['title'];
$filename = addslashes(trim($filename));
$filename = Security::remove_XSS($filename);
$filename = api_replace_dangerous_char($filename);
$filename = disable_dangerous_file($filename);
$filename .= DocumentManager::getDocumentSuffix(
$_course,
api_get_session_id(),
@ -474,16 +487,16 @@ if ($form->validate()) {
);
// Setting the title
$title = $values['title'];
$title = $values['title'];
// Setting the extension
$extension = 'html';
$extension = 'html';
$content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
$content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
/*if (strpos($content, '/css/frames.css') == false) {
$content = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /><style> body{margin:50px;}</style></head>', $content);
}*/
/*if (strpos($content, '/css/frames.css') == false) {
$content = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /><style> body{margin:50px;}</style></head>', $content);
}*/
// Don't create file with the same name.
@ -494,21 +507,21 @@ if ($form->validate()) {
exit;
}
if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
$content = str_replace(
api_get_path(WEB_COURSE_PATH),
$content = str_replace(
api_get_path(WEB_COURSE_PATH),
api_get_configuration_value('url_append').api_get_path(REL_COURSE_PATH),
$content
);
fputs($fp, $content);
fclose($fp);
chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
fputs($fp, $content);
fclose($fp);
chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
$file_size = filesize($filepath.$filename.'.'.$extension);
$save_file_path = $dir.$filename.'.'.$extension;
$file_size = filesize($filepath.$filename.'.'.$extension);
$save_file_path = $dir.$filename.'.'.$extension;
$document_id = add_document(
$_course,
@ -520,8 +533,8 @@ if ($form->validate()) {
$readonly
);
if ($document_id) {
api_item_property_update(
if ($document_id) {
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$document_id,
@ -533,13 +546,13 @@ if ($form->validate()) {
null,
$current_session_id
);
// Update parent folders
item_property_update_on_folder($_course, $dir, $userId);
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
// Update parent folders
item_property_update_on_folder($_course, $dir, $userId);
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
$new_title = htmlspecialchars($new_title);
if ($new_comment || $new_title) {
$ct = '';
if ($new_comment || $new_title) {
$ct = '';
$params = [];
if ($new_comment) {
$params['comment'] = $new_comment;
@ -554,39 +567,39 @@ if ($form->validate()) {
['c_id = ? AND id = ?' => [$course_id, $document_id]]
);
}
}
$dir = substr($dir, 0, -1);
$selectcat = '';
}
$dir = substr($dir, 0, -1);
$selectcat = '';
if (isset($_REQUEST['selectcat'])) {
$selectcat = "&selectcat=".intval($_REQUEST['selectcat']);
}
$certificate_condition = '';
if ($is_certificate_mode) {
$df = DocumentManager::get_default_certificate_id($_course['code']);
$certificate_condition = '';
if ($is_certificate_mode) {
$df = DocumentManager::get_default_certificate_id($_course['code']);
if (!isset($df)) {
DocumentManager::attach_gradebook_certificate($_course['code'], $document_id);
}
$certificate_condition = '&certificate=true&curdirpath=/certificates';
}
}
$certificate_condition = '&certificate=true&curdirpath=/certificates';
}
Display::addFlash(Display::return_message(get_lang('ItemAdded')));
header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
exit();
} else {
Display :: display_header($nameTools, 'Doc');
Display :: display_error_message(get_lang('Impossible'));
Display :: display_footer();
}
} else {
Display :: display_header($nameTools, 'Doc');
Display :: display_error_message(get_lang('Impossible'));
Display :: display_footer();
}
header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
exit();
} else {
Display :: display_header($nameTools, 'Doc');
Display :: display_error_message(get_lang('Impossible'));
Display :: display_footer();
}
} else {
Display :: display_header($nameTools, 'Doc');
Display :: display_error_message(get_lang('Impossible'));
Display :: display_footer();
}
} else {
// Copied from document.php
$dir_array = explode('/', $dir);
$array_len = count($dir_array);
// Copied from document.php
$dir_array = explode('/', $dir);
$array_len = count($dir_array);
// Breadcrumb for the current directory root path
// Breadcrumb for the current directory root path
if (!empty($document_data)) {
if (empty($document_data['parents'])) {
$interbreadcrumb[] = array(
@ -603,11 +616,11 @@ if ($form->validate()) {
}
}
Display :: display_header($nameTools, "Doc");
// actions
Display :: display_header($nameTools, "Doc");
// actions
// link back to the documents overview
if ($is_certificate_mode) {
// link back to the documents overview
if ($is_certificate_mode) {
$actionsLeft = '<a href="document.php?certificate=true&id='.$folder_id.'&selectcat='.Security::remove_XSS($_GET['selectcat']).'">'.
Display::return_icon('back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.
@ -622,19 +635,19 @@ if ($form->validate()) {
echo $toolbar = Display::toolbarAction('actions-documents', array($actionsLeft));
if ($is_certificate_mode) {
if ($is_certificate_mode) {
$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(
api_get_user_id(),
api_get_course_id()
);
$str_info = '';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info .= $info_value.'<br/>';
}
$create_certificate = get_lang('CreateCertificateWithTags');
Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info, false);
}
$str_info = '';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info .= $info_value.'<br/>';
}
$create_certificate = get_lang('CreateCertificateWithTags');
Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info, false);
}
// HTML-editor
echo '<div class="page-create">
@ -650,5 +663,5 @@ if ($form->validate()) {
'.$form->returnForm().'
</div>
</div></div>';
Display :: display_footer();
Display :: display_footer();
}

Loading…
Cancel
Save