'; //jQuery $htmlHeadXtra[] = ''; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; require_once api_get_path(LIBRARY_PATH).'document.lib.php'; require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; if (isset($_REQUEST['certificate'])) { $nameTools = get_lang('CreateCertificate'); } else { $nameTools = get_lang('CreateDocument'); } $nameTools = get_lang('CreateDocument'); /* Constants and variables */ $dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']); /* MAIN CODE */ if (api_is_in_group()) { $group_properties = GroupManager::get_group_properties($_SESSION['_gid']); } // Please, do not modify this dirname formatting if (strstr($dir, '..')) { $dir = '/'; } if ($dir[0] == '.') { $dir = substr($dir, 1); } if ($dir[0] != '/') { $dir = '/'.$dir; } if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; } // Configuration for the FCKEDITOR $doc_tree= explode('/', $dir); $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 .= '../'; } // We do this in order to avoid the condition in html_editor.php ==> if ($this -> fck_editor->Config['CreateDocumentWebDir']=='' || $this -> fck_editor->Config['CreateDocumentDir']== '') if ($relative_url== '') { $relative_url = '/'; } $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $html_editor_config = array( 'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' :'DocumentsStudent'), 'Width' => '100%', 'Height' => '600', '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 ); $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$dir; if (!is_dir($filepath)) { $filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/'; $dir = '/'; } //I'm in the certification module? $is_certificate_mode = false; $is_certificate_array = explode('/',$_GET['dir']); array_shift($is_certificate_array); if ($is_certificate_array[0]=='certificates') { $is_certificate_mode = true; } $to_group_id = 0; if (!$is_certificate_mode) { if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != '') { $req_gid = '&gidReq='.$_SESSION['_gid']; $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace')); $noPHP_SELF = true; $to_group_id = $_SESSION['_gid']; $group = GroupManager :: get_group_properties($to_group_id); $path = explode('/', $dir); if ('/'.$path[1] != $group['directory']) { api_not_allowed(true); } } $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($_GET['dir']).$req_gid, "name" => get_lang('Documents')); } else { $interbreadcrumb[]= array ( 'url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); } if (!$is_allowed_in_course) { api_not_allowed(true); } if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'])) { api_not_allowed(true); } /* Header */ event_access_tool(TOOL_DOCUMENT); $display_dir = $dir; if (isset ($group)) { $display_dir = explode('/', $dir); unset ($display_dir[0]); unset ($display_dir[1]); $display_dir = implode('/', $display_dir); } // Create a new form $form = new FormValidator('create_document','post',api_get_self().'?dir='.Security::remove_XSS(urlencode($_GET['dir'])).'&selectcat='.Security::remove_XSS($_GET['selectcat'])); // form title $form->addElement('header', '', $nameTools); if (isset($_REQUEST['certificate'])) {//added condition for certicate in gradebook $form->addElement('hidden','certificate','true',array('id'=>'certificate')); if (isset($_GET['selectcat'])) $form->addElement('hidden','selectcat',intval($_GET['selectcat'])); } $renderer = & $form->defaultRenderer(); // Hidden element with current directory $form->addElement('hidden', 'dir'); $default['dir'] = $dir; // Filename $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"'); /** * Check if a document width the choosen filename allready exists */ function document_exists($filename) { global $filepath; $filename = addslashes(trim($filename)); $filename = Security::remove_XSS($filename); $filename = replace_dangerous_char($filename); $filename = disable_dangerous_file($filename); return !file_exists($filepath.$filename.'.html'); } // Change the default renderer for the filename-field to display the dir and extension /* $renderer = & $form->defaultRenderer(); */ //$filename_template = str_replace('{element}', "$display_dir {element} .html", $renderer->_elementTemplate); $filename_template = str_replace('{element}', '{element}', $renderer->_elementTemplate); // TODO: What is the point of this statement? $renderer->setElementTemplate($filename_template, 'filename'); // Initialize group array $group = array(); // If allowed, add element for document title if (api_get_setting('use_document_title') == 'true') { //$group[]= $form->add_textfield('title', get_lang('Title'),true,'class="input_titles" id="title"'); // replace the add_textfield with this $group[]=$form->createElement('text','title',get_lang('Title'),'class="input_titles" id="document_title"'); //$form->applyFilter('title','trim'); //$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); // Added by Ivan Tcholakov, 10-OCT-2009. $form->addElement('hidden', 'filename', '', array('id' => 'filename')); // } else { //$form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename" onblur="javascript: check_if_still_empty();"'); // replace the add_textfield with this $group[]=$form->createElement('text', 'filename', get_lang('FileName'), 'class="input_titles" id="document_title" onblur="javascript: check_if_still_empty();"'); //$form->applyFilter('filename','trim'); //$form->addRule('filename', get_lang('ThisFieldIsRequired'), 'required'); //$form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists'); // Added by Ivan Tcholakov, 10-OCT-2009. $form->addElement('hidden', 'title', '', array('id' => 'title')); // } // Show read-only box only in groups if (!empty($_SESSION['_gid'])) { //$renderer->setElementTemplate('
{element}{label}
', 'readonly'); $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly')); } // Add group to the form if ($is_certificate_mode) $form->addGroup($group, 'filename_group', get_lang('CertificateName') ,'   ', false); else $form->addGroup($group, 'filename_group', api_get_setting('use_document_title') == 'true' ? get_lang('Title') : get_lang('FileName') ,'   ', false); $form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required'); if (api_get_setting('use_document_title') == 'true') { $form->addGroupRule('filename_group', array( 'title' => array( array(get_lang('ThisFieldIsRequired'), 'required'), array(get_lang('FileExists'),'callback', 'document_exists') ) )); } else { $form->addGroupRule('filename_group', array( 'filename' => array( array(get_lang('ThisFieldIsRequired'), 'required'), array(get_lang('FileExists'),'callback', 'document_exists') ) )); } $current_session_id = api_get_session_id(); //$form->addElement('style_submit_button', 'submit', get_lang('SaveDocument'), 'class="save"'); // HTML-editor $renderer->setElementTemplate('
{element}
', 'content'); $form->add_html_editor('content','', false, false, $html_editor_config); // Comment-field //$form->addElement('textarea', 'comment', get_lang('Comment'), array ('rows' => 5, 'cols' => 50)); if ($is_certificate_mode) $form->addElement('style_submit_button', 'submit', get_lang('CreateCertificate'), 'class="save"'); else $form->addElement('style_submit_button', 'submit', get_lang('langCreateDoc'), 'class="save"'); $form->setDefaults($default); // HTML /* $form->addElement('html','
'); */ // If form validates -> save the new document if ($form->validate()) { $values = $form->exportValues(); $readonly = isset($values['readonly']) ? 1 : 0; $values['title'] = addslashes(trim($values['title'])); $values['title'] = Security::remove_XSS($values['title']); $values['title'] = replace_dangerous_char($values['title']); $values['title'] = disable_dangerous_file($values['title']); $values['filename'] = addslashes(trim($values['filename'])); $values['filename'] = Security::remove_XSS($values['filename']); $values['filename'] = replace_dangerous_char($values['filename']); $values['filename'] = disable_dangerous_file($values['filename']); if (api_get_setting('use_document_title') != 'true') { $values['title'] = $values['filename']; } else { $values['filename'] = $values['title']; } $filename = $values['filename']; $title = $values['title']; $extension = 'html'; $content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY); if (strpos($content, '/css/frames.css') === false) { $content = str_replace('', ' ', $content); } if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) { $content = text_filter($content); $content = str_replace(api_get_path('WEB_COURSE_PATH'), $_configuration['url_append'].'/courses/', $content); // change the path of mp3 to absolute // first regexp deals with ../../../ urls // Disabled by Ivan Tcholakov. //$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content); //second regexp deals with audio/ urls // Disabled by Ivan Tcholakov. //$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content); fputs($fp, $content); fclose($fp); chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files()); 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', $_user['user_id'], null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id); } if (!is_file($filepath.'css/frames.css')) { // Make a copy of the current css for the new document copy(api_get_path(SYS_CODE_PATH).'css/'.api_get_setting('stylesheets').'/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', $_user['user_id'], null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id); } $file_size = filesize($filepath.$filename.'.'.$extension); $save_file_path = $dir.$filename.'.'.$extension; $document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename, null, $readonly); if ($document_id) { api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $to_group_id, null, null, null, $current_session_id); // Update parent folders item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']); $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; $new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; if ($new_comment || $new_title) { $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); $ct = ''; if ($new_comment) $ct .= ", comment='$new_comment'"; if ($new_title) $ct .= ", title='$new_title'"; Database::query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'"); } $dir= substr($dir,0,-1); $selectcat = ''; if (isset($_REQUEST['selectcat'])) $selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']); header('Location: document.php?curdirpath='.urlencode($dir).$selectcat); exit (); } else { Display :: display_header($nameTools, 'Doc'); Display :: display_error_message(get_lang('Impossible')); Display :: display_footer(); } } else { Display :: display_header($nameTools, 'Doc'); //api_display_tool_title($nameTools); Display :: display_error_message(get_lang('Impossible')); Display :: display_footer(); } } else { Display :: display_header($nameTools, "Doc"); //api_display_tool_title($nameTools); // actions if (isset($_REQUEST['certificate'])) { $all_information_by_create_certificate=DocumentManager::get_all_info_to_certificate(); $str_info=''; foreach ($all_information_by_create_certificate[0] as $info_value) { $str_info.=$info_value.'
'; } $create_certificate=get_lang('CreateCertificateWithTags'); Display::display_normal_message($create_certificate.':

'.$str_info,false); } echo '
'; // link back to the documents overview if ($is_certificate_mode) echo ''.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview')).get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview').''; else echo ''.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('DocumentsOverview')).get_lang('BackTo').' '.get_lang('DocumentsOverview').''; echo '
'; $form->display(); Display :: display_footer(); }