Source for file document.inc.php
Documentation is available at document.inc.php
<?php // $Id: document.inc.php 15525 2008-06-09 06:24:20Z yannoo $
==============================================================================
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) various contributors
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
==============================================================================
==============================================================================
EXTRA FUNCTIONS FOR DOCUMENT.PHP/UPLOAD.PHP
==============================================================================
/////////////////////////////////////////////////
//--> leave these here or move them elsewhere? //
/////////////////////////////////////////////////
* Builds the form thats enables the user to
* select a directory to browse/upload in
* @param array An array containing the folders we want to be able to select
* @param string The current folder (path inside of the "document" directory, including the prefix "/")
* @param string Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
* @param boolean Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
* @return string html form
$folder_titles = array();
$escaped_folders = array();
$folder_sql = implode("','",$escaped_folders);
$sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('". $folder_sql. "')";
$folder_titles = array();
$folder_titles[$obj->path] = $obj->title;
foreach($folders as $folder)
$folder_titles[$folder] = basename($folder);
$parent_select = $form->addElement('select', 'curdirpath', get_lang('CurrentDirectory'),'','onchange="javascript:document.selector.submit()"');
if($changeRenderer== true){
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<span>{label} : {element}</span> ','curdirpath');
//group documents cannot be uploaded in the root
foreach ($folders as $folder)
$selected = ($curdirpath== $folder)? ' selected="selected"': '';
$path_parts = explode('/',$folder);
$label = str_repeat(' ',count($path_parts)- 2). ' — '. $folder_titles[$folder];
if($selected!= '') $parent_select->setSelected($folder);
foreach ($folders as $folder)
$selected = ($curdirpath== $folder)? ' selected="selected"': '';
$label = $folder_titles[$folder];
if( $folder == $group_dir)
$label = '/ ('. get_lang('HomeDirectory'). ')';
$label = str_repeat(' ',count($path_parts)- 2). ' — '. $label;
if($selected!= '') $parent_select->setSelected($folder);
echo /*"<div id=\"smallmessagebox\">"
.*/ "<p>" . $message . "</p>"
* Create a html hyperlink depending on if it's a folder or a file
* @param string $filetype (file/folder)
* @param int $visibility (1/0)
if(isset ($_SESSION['_gid']))
$req_gid = '&gidReq='. $_SESSION['_gid'];
//add class="invisible" on invisible files
$visibility_class= ($visibility== 0)? ' class="invisible"': '';
//build download link (icon)
//folder download or file download?
$forcedownload_icon= ($filetype== 'folder')? 'folder_zip.gif': 'filesave.gif';
//prevent multiple clicks on zipped folder download
$prevent_multiple_click = ($filetype== 'folder')? " onclick=\"javascript:if(typeof clic_$dbl_click_id == 'undefined' || clic_$dbl_click_id == false) { clic_$dbl_click_id=true; window.setTimeout('clic_". ($dbl_click_id++ ). "=false;',10000); } else { return false; }\"": '';
//"htmlfiles" are shown in a frameset
if($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png')
$url = "showinframes.php?". api_get_cidreq(). "&file=". $url_path. $req_gid;
//url-encode for problematic characters (we may not call them dangerous characters...)
//files that we want opened in a new window
if($ext== 'txt') //add here
//the little download icon
$force_download_html = ($size== 0)? '': '<a href="'. $forcedownload_link. '" style="float:right"'. $prevent_multiple_click. '><img width="16" height="16" src="'. api_get_path(WEB_CODE_PATH). 'img/'. $forcedownload_icon. '" alt="" /></a>';
return '<a href="'. $url. '" title="'. $tooltip_title. '" target="'. $target. '"'. $visibility_class. ' style="float:left">'. $title. '</a>'. $force_download_html;
* Builds an img html tag for the filetype
* @param string $type (file/folder)
* @return string img html tag
$icon= 'folder_document.gif';
* Creates the row of edit icons for a file/folder
* @param string $curdirpath current path (cfr open folder)
* @param string $type (file/folder)
* @param string $path dbase path of file/folder
* @param int $visibility (1/0)
* @param int $id dbase id of the document
* @return string html img tags with hyperlinks
function build_edit_icons($curdirpath,$type,$path,$visibility,$id,$is_template,$is_read_only= 0)
if(isset ($_SESSION['_gid']))
$req_gid = '&gidReq='. $_SESSION['_gid'];
//build URL-parameters for table-sorting
if( isset ($_GET['column']))
$sort_params[] = 'column='. $_GET['column'];
if( isset ($_GET['page_nr']))
$sort_params[] = 'page_nr='. $_GET['page_nr'];
if( isset ($_GET['per_page']))
$sort_params[] = 'per_page='. $_GET['per_page'];
if( isset ($_GET['direction']))
$sort_params[] = 'direction='. $_GET['direction'];
$sort_params = implode('&',$sort_params);
$visibility_icon = ($visibility== 0)? 'invisible': 'visible';
$visibility_command = ($visibility== 0)? 'set_visible': 'set_invisible';
$modify_icons = '<img src="../img/edit_na.gif" border="0" title="'. get_lang('Modify'). '" alt="" />';
$modify_icons .= ' <img src="../img/delete_na.gif" border="0" title="'. get_lang('Delete'). '" alt="" />';
$modify_icons .= ' <img src="../img/deplacer_fichier_na.gif" border="0" title="'. get_lang('Move'). '" alt="" />';
$modify_icons .= ' <img src="../img/'. $visibility_icon. '_na.gif" border="0" title="'. get_lang('Visible'). '" alt="" />';
$modify_icons = '<a href="edit_document.php?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&file='. urlencode($path). $req_gid. '"><img src="../img/edit.gif" border="0" title="'. get_lang('Modify'). '" alt="" /></a>';
$modify_icons .= ' <a href="'. api_get_self(). '?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&delete='. urlencode($path). $req_gid. '&'. $sort_params. '" onclick="return confirmation(\''. basename($path). '\');"><img src="../img/delete.gif" border="0" title="'. get_lang('Delete'). '" alt="" /></a>';
$modify_icons .= ' <a href="'. api_get_self(). '?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&move='. urlencode($path). $req_gid. '"><img src="../img/deplacer_fichier.gif" border="0" title="'. get_lang('Move'). '" alt="" /></a>';
$modify_icons .= ' <a href="'. api_get_self(). '?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&'. $visibility_command. '='. $id. $req_gid. '&'. $sort_params. '"><img src="../img/'. $visibility_icon. '.gif" border="0" title="'. get_lang('Visible'). '" alt="" /></a>';
if($type == 'file' && pathinfo($path,PATHINFO_EXTENSION)== 'html')
$modify_icons .= ' <a href="'. api_get_self(). '?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&add_as_template='. $id. $req_gid. '&'. $sort_params. '"><img src="../img/wizard_small.gif" border="0" title="'. get_lang('AddAsTemplate'). '" alt="'. get_lang('AddAsTemplate'). '" /></a>';
$modify_icons .= ' <a href="'. api_get_self(). '?'. api_get_cidreq(). '&curdirpath='. $curdirpath. '&remove_as_template='. $id. $req_gid. '&'. $sort_params. '"><img src="../img/wizard_gray_small.gif" border="0" title="'. get_lang('RemoveAsTemplate'). '" alt=""'. get_lang('RemoveAsTemplate'). '" /></a>';
$form = '<form name="move_to" action="'. api_get_self(). '" method="post">'. "\n";
$form .= '<input type="hidden" name="move_file" value="'. $move_file. '" />'. "\n";
$form .= get_lang('MoveTo'). ' <select name="move_to">'. "\n";
//group documents cannot be uploaded in the root
$form .= '<option value="/">/ ('. get_lang('HomeDirectory'). ')</option>';
foreach ($folders AS $folder)
//you cannot move a file to:
//2. inside the folder you want to move
//3. inside a subfolder of the folder you want to move
if(($curdirpath!= $folder) && ($folder!= $move_file) && (substr($folder,0,strlen($move_file)+ 1) != $move_file. '/'))
$path_displayed = $folder;
// if document title is used, we have to display titles instead of real paths...
$form .= '<option value="'. $folder. '">'. $path_displayed. '</option>'. "\n";
foreach ($folders AS $folder)
if(($curdirpath!= $folder) && ($folder!= $move_file) && (substr($folder,0,strlen($move_file)+ 1) != $move_file. '/'))//cannot copy dir into his own subdir
$display_folder = substr($path_displayed,strlen($group_dir));
$display_folder = ($display_folder == '')? '/ ('. get_lang('HomeDirectory'). ')': $display_folder;
$form .= '<option value="'. $folder. '">'. $display_folder. '</option>'. "\n";
$form .= '</select>'. "\n";
$form .= '<input type="submit" name="move_file_submit" value="'. get_lang('Ok'). '" />'. "\n";
* get the path translated with title of docs and folders
* @param string the real path
* @return the path which should be displayed
global $tmp_folders_titles;
for($i= 0; $i< $nb_slashes; $i++ )
{ // foreach folders of the path, retrieve title.
$current_slash_pos = strpos($path,'/',$current_slash_pos+ 1);
$tmp_path = substr($path,strpos($path,'/',0),$current_slash_pos);
if(empty($tmp_path)) // if empty, then we are in the final part of the path
if(!empty($tmp_folders_titles[$tmp_path])) // if this path has soon been stored here we don't need a new query
$path_displayed .= $tmp_folders_titles[$tmp_path];
$path_displayed .= $tmp_title;
$tmp_folders_titles[$tmp_path] = $tmp_title;
|