Source for file create_document.php
Documentation is available at create_document.php
// $Id: create_document.php 15322 2008-05-19 16:31:13Z juliomontoya $
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Olivier Brouckaert
Copyright (c) Bart Mollet, Hogeschool Gent
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
==============================================================================
==============================================================================
* This file allows creating new html documents with an online WYSIWYG html380
* @package dokeos.document
==============================================================================
==============================================================================
==============================================================================
// name of the language file that needs to be included
$language_file = 'document';
include ('../inc/global.inc.php');
$_SESSION['whereami'] = 'document/create';
$htmlHeadXtra[]= '<script>
function InnerDialogLoaded()
var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
function launch_templates()
//document.getElementById(\'frmModel\').style.display="block";
//document.getElementById(\'content___Frame\').width=\'70%\';
//window.frames[0].FCKToolbarItems.GetItem("Template").Click;
function FCKeditor_OnComplete( editorInstance )
editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;
document.getElementById(\'frmModel\').innerHTML = "<iframe height=950px; width=97%; frameborder=0 src=\''. api_get_path(WEB_LIBRARY_PATH). 'fckeditor/editor/fckdialogframe.html \'>";
function check_for_title()
// This functions shows that you can interact directly with the editor area
// DOM. In this way you have the freedom to do anything you want with it.
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance(\'content\') ;
// Get the Editor Area DOM (Document object).
var oDOM = oEditor.EditorDocument ;
var bestandsnaamNieuw = "";
var bestandsnaamOud = "";
// The are two diffent ways to get the text (without HTML markups).
// It is browser specific.
if( document.all ) // If Internet Explorer.
contentText = oDOM.body.innerText ;
var r = oDOM.createRange() ;
r.selectNodeContents( oDOM.body ) ;
contentText = r.toString() ;
var index=contentText.indexOf("/*<![CDATA");
contentText=contentText.substr(0,index);
// Compose title if there is none
contentTextArray = contentText.split(\' \') ;
for(x=0; (x<5 && x<contentTextArray.length); x++)
bestandsnaamNieuw += contentTextArray[x] + \' \';
bestandsnaamNieuw += contentTextArray[x];
if(document.getElementById(\'title_edited\').value == "false")
document.getElementById(\'filename\').value = bestandsnaamNieuw;
document.getElementById(\'title\').value = bestandsnaamNieuw;
while(s.substring(0,1) == \' \') {
s = s.substring(1,s.length);
while(s.substring(s.length-1,s.length) == \' \') {
s = s.substring(0,s.length-1);
function check_if_still_empty()
if(trim(document.getElementById(\'filename\').value) != "")
document.getElementById(\'title_edited\').value = "true";
include (api_get_path(LIBRARY_PATH). 'fileUpload.lib.php');
include (api_get_path(LIBRARY_PATH). 'document.lib.php');
include (api_get_path(LIBRARY_PATH). 'groupmanager.lib.php');
include (api_get_path(LIBRARY_PATH). 'events.lib.inc.php');
include (api_get_path(LIBRARY_PATH). 'formvalidator/FormValidator.class.php');
$nameTools = get_lang('CreateDocument');
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '950';
$fck_attribute['ToolbarSet'] = 'Full';
$fck_attribute['Config']['FullPage'] = true;
-----------------------------------------------------------
-----------------------------------------------------------
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
==============================================================================
==============================================================================
if ($dir[strlen($dir) - 1] != '/')
$filepath = api_get_path('SYS_COURSE_PATH'). $_course['path']. '/document'. $dir;
$filepath = api_get_path('SYS_COURSE_PATH'). $_course['path']. '/document/';
/**************************************************/
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'));
$to_group_id = $_SESSION['_gid'];
if ('/'. $path[1] != $group['directory'])
$interbreadcrumb[] = array ("url" => "./document.php?curdirpath=". urlencode($_GET['dir']). $req_gid, "name" => get_lang('Documents'));
if (!$is_allowed_in_course)
if (!($is_allowedToEdit || $_SESSION['group_member_with_upload_rights']))
-----------------------------------------------------------
-----------------------------------------------------------
$display_dir = implode('/', $display_dir);
// Hidden element with current directory
$form->addElement('hidden', 'dir');
$form->addElement('hidden','title_edited','false','id="title_edited"');
* Check if a document width the choosen filename allready exists
// Change the default renderer for the filename-field to display the dir and extension
$renderer = & $form->defaultRenderer();
//$filename_template = str_replace('{element}', "<tt>$display_dir</tt> {element} <tt>.html</tt>", $renderer->_elementTemplate);
$filename_template = str_replace('{element}', "{element}", $renderer->_elementTemplate);
$renderer->setElementTemplate($filename_template, 'filename');
// initialize group array
// If allowed, add element for document title
//$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="title"');
//$form->applyFilter('title','trim');
//$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
//$form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename" onblur="check_if_still_empty()"');
// replace the add_textfield with this
$group[]= $form->createElement('text','filename',get_lang('FileName'),'class="input_titles" id="filename" onblur="check_if_still_empty()"');
//$form->applyFilter('filename','trim');
//$form->addRule('filename', get_lang('ThisFieldIsRequired'), 'required');
//$form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists');
/* Show read-only box only in groups */
if(!empty($_SESSION['_gid']))
//$renderer->setElementTemplate('<div class="row"><div class="label"></div><div class="formw">{element}{label}</div></div>', 'readonly');
$group[]= $form->createElement('checkbox','readonly','',get_lang('ReadOnly'));
$form->addGroup($group, 'filename_group', get_lang('FileName') ,' ', false);
$form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required');
$form->addGroupRule('filename_group', array(
array(get_lang('ThisFieldIsRequired'), 'required'),
array(get_lang('FileExists'),'callback', 'document_exists')
$form->addGroupRule('filename_group', array(
array(get_lang('ThisFieldIsRequired'), 'required'),
array(get_lang('FileExists'),'callback', 'document_exists')
$form->addElement('submit', 'submit', get_lang('Ok'));
$form->add_html_editor('content','', false, false);
//$form->addElement('textarea', 'comment', get_lang('Comment'), array ('rows' => 5, 'cols' => 50));
$form->addElement('submit', 'submit', get_lang('Ok'));
$form->setDefaults($default);
$form->addElement('html','<div id="frmModel" style="display:block; height:950px;width:20%; position:absolute; top:135px; left:1px;"></div>');
// If form validates -> save the new document
$values = $form->exportValues();
$readonly = isset ($values['readonly']) ? 1 : 0;
$clean_val= $values['filename'];
$values['filename']= $clean_val;
$values['title'] = $values['filename'];
$values['filename'] = $values['title'];
$texte = $values['content'];
$title = $values['filename'];
if (!strstr($texte, '/css/frames.css'))
$texte = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /></head>', $texte);
if ($fp = @ fopen($filepath. $filename. '.'. $extension, 'w'))
// replace fake by flv player if needed (fake is present only in templates)
'<object type="application/x-shockwave-flash" data="'. api_get_path(REL_PATH). 'main/inc/lib/flv_player/player_flv_mini.swf" height="240" width="320">
<param name="movie" value="'. api_get_path(REL_PATH). 'main/inc/lib/flv_player/player_flv_mini.swf" />
<param name="FlashVars" value="flv=',$content);
$content = str_replace('&endflv" alt="" />','&autoplay=1" /></object><style type="text/css">body{}</style>',$content);
$texte = str_replace('mp3player.swf?son='. urlencode($path_to_remove), 'mp3player.swf?son=.%2F', $texte);
$files_perm = octdec(!empty($files_perm)? $files_perm: '0770');
chmod($filepath. $filename. '.'. $extension,$files_perm);
$perm = octdec(!empty($perm)? $perm: '0770');
chmod($filepath. 'css', $perm);
$doc_id = add_document($_course, $dir. 'css', 'folder', 0, 'css');
if (!is_file($filepath. 'css/frames.css'))
//make a copy of the current css for the new document
$doc_id = add_document($_course, $dir. 'css/frames.css', 'file', filesize($filepath. 'css/frames.css'), 'frames.css');
$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);
$new_comment = isset ($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset ($_POST['title']) ? trim($_POST['title']) : '';
if ($new_comment || $new_title)
$ct .= ", comment='$new_comment'";
$ct .= ", title='$new_title'";
api_sql_query("UPDATE $TABLE_DOCUMENT SET". substr($ct, 1). " WHERE id = '$document_id'", __FILE__ , __LINE__ );
//api_display_tool_title($nameTools);
//api_display_tool_title($nameTools);
|