dokeos-document
[ class tree: dokeos-document ] [ index: dokeos-document ] [ all elements ]

Source for file document.php

Documentation is available at document.php

  1. <?php // $Id: document.php 15525 2008-06-09 06:24:20Z yannoo $
  2.  
  3. /*
  4. ==============================================================================
  5.     Dokeos - elearning and course management software
  6.  
  7.     Copyright (c) 2004-2008 Dokeos SPRL
  8.     Copyright (c) 2003 Ghent University (UGent)
  9.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10.     Copyright (c) various contributors
  11.  
  12.     For a full list of contributors, see "credits.txt".
  13.     The full license can be read in "license.txt".
  14.  
  15.     This program is free software; you can redistribute it and/or
  16.     modify it under the terms of the GNU General Public License
  17.     as published by the Free Software Foundation; either version 2
  18.     of the License, or (at your option) any later version.
  19.  
  20.     See the GNU General Public License for more details.
  21.  
  22.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  23.     Mail: info@dokeos.com
  24. ==============================================================================
  25. */
  26. /**
  27. ==============================================================================
  28. * Main script for the documents tool
  29. *
  30. * This script allows the user to manage files and directories on a remote http server.
  31. *
  32. * The user can : - navigate through files and directories.
  33. *                 - upload a file
  34. *                 - delete, copy a file or a directory
  35. *                 - edit properties & content (name, comments, html content)
  36. *
  37. * The script is organised in four sections.
  38. *
  39. * 1) Execute the command called by the user
  40. *                Note: somme commands of this section are organised in two steps.
  41. *                The script always begins with the second step,
  42. *                so it allows to return more easily to the first step.
  43. *
  44. *                Note (March 2004) some editing functions (renaming, commenting)
  45. *                are moved to a separate page, edit_document.php. This is also
  46. *                where xml and other stuff should be added.
  47. *
  48. * 2) Define the directory to display
  49. *
  50. * 3) Read files and directories from the directory defined in part 2
  51. * 4) Display all of that on an HTML page
  52. *
  53. @todo eliminate code duplication between
  54. *  document/document.php, scormdocument.php
  55. *
  56. @package dokeos.document
  57. ==============================================================================
  58. */
  59.  
  60. /*
  61. ==============================================================================
  62.         INIT SECTION
  63. ==============================================================================
  64. */
  65.  
  66. // name of the language file that needs to be included
  67. $language_file['document';
  68. $language_file['slideshow';
  69.  
  70. require("../inc/global.inc.php");
  71. $this_section=SECTION_COURSES;
  72. require('document.inc.php');
  73.  
  74.  
  75. //session
  76. if(isset($_GET['id_session']))
  77.     $_SESSION['id_session'$_GET['id_session'];
  78.  
  79. $htmlHeadXtra[=
  80. "<script type=\"text/javascript\">
  81. function confirmation (name)
  82. {
  83.     if (confirm(\" "get_lang("AreYouSureToDelete"." \"+ name + \" ?\"))
  84.         {return true;}
  85.     else
  86.         {return false;}
  87. }
  88. </script>";
  89.  
  90. /*
  91. -----------------------------------------------------------
  92.     Variables
  93.     - some need defining before inclusion of libraries
  94. -----------------------------------------------------------
  95. */
  96.  
  97. //what's the current path?
  98. //we will verify this a bit further down
  99. if(isset($_GET['curdirpath']&& $_GET['curdirpath']!='')
  100. {
  101.     $curdirpath $_GET['curdirpath'];
  102. }
  103. elseif (isset($_POST['curdirpath']&& $_POST['curdirpath']!='')
  104. {
  105.     $curdirpath $_POST['curdirpath'];
  106. }
  107. else
  108. {
  109.     $curdirpath '/';
  110. }
  111. $curdirpathurl urlencode($curdirpath);
  112.  
  113. $course_dir   $_course['path']."/document";
  114. $sys_course_path api_get_path(SYS_COURSE_PATH);
  115. $base_work_dir $sys_course_path.$course_dir;
  116. $http_www api_get_path('WEB_COURSE_PATH').$_course['path'].'/document';
  117. $dbl_click_id 0// used to avoid double-click
  118. $is_allowed_to_edit api_is_allowed_to_edit();
  119. $group_member_with_upload_rights false;
  120.  
  121. //if the group id is set, we show them group documents
  122. if(isset($_SESSION['_gid']&& $_SESSION['_gid']!='')
  123. {
  124.     //needed for group related stuff
  125.     include_once(api_get_path(LIBRARY_PATH'groupmanager.lib.php');
  126.     //get group info
  127.     $group_properties GroupManager::get_group_properties($_SESSION['_gid']);
  128.     $noPHP_SELF=true;
  129.     //let's assume the user cannot upload files for the group
  130.     $group_member_with_upload_rights false;
  131.  
  132.     if($group_properties['doc_state']==2//documents are private
  133.     {
  134.         if($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) //only courseadmin or group members (members + tutors) allowed
  135.         {
  136.             $to_group_id $_SESSION['_gid'];
  137.             $req_gid '&amp;gidReq='.$_SESSION['_gid'];
  138.             $interbreadcrumb[]array ("url"=>"../group/group.php""name"=> get_lang('Groups'));
  139.             $interbreadcrumb[]array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid']"name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  140.             //they are allowed to upload
  141.             $group_member_with_upload_rights true;
  142.         }
  143.         else
  144.         {
  145.             $to_group_id 0;
  146.             $req_gid '';
  147.         }
  148.     }
  149.     elseif($group_properties['doc_state']==1)  //documents are public
  150.     {
  151.         $to_group_id $_SESSION['_gid'];
  152.         $req_gid '&amp;gidReq='.$_SESSION['_gid'];
  153.         
  154.         $interbreadcrumb[]array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid']"name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  155.         //allowed to upload?
  156.         if($is_allowed_to_edit || GroupManager::is_subscribed($_user['user_id'],$_SESSION['_gid'])) //only courseadmin or group members can upload
  157.         {
  158.             $group_member_with_upload_rights true;
  159.         }
  160.     }
  161.     else //documents not active for this group
  162.     {
  163.         $to_group_id 0;
  164.         $req_gid '';
  165.     }
  166.     $_SESSION['group_member_with_upload_rights'$group_member_with_upload_rights;
  167. }
  168. else
  169. {
  170.     $to_group_id 0;
  171.     $req_gid '';
  172. }
  173. /*
  174. -----------------------------------------------------------
  175.     Libraries
  176. -----------------------------------------------------------
  177. */
  178. //the main_api.lib.php, database.lib.php and display.lib.php
  179. //libraries are included by default
  180.  
  181. include_once(api_get_path(LIBRARY_PATH'fileDisplay.lib.php');
  182. include_once(api_get_path(LIBRARY_PATH'events.lib.inc.php');
  183. include_once(api_get_path(LIBRARY_PATH'document.lib.php');
  184. include_once(api_get_path(LIBRARY_PATH'tablesort.lib.php');
  185. include_once(api_get_path(LIBRARY_PATH'fileUpload.lib.php');
  186.  
  187.  
  188. //-----------------------------------------------------------
  189. //check the path
  190. //if the path is not found (no document id), set the path to /
  191. if(!DocumentManager::get_document_id($_course,$curdirpath))
  192. {
  193.     $curdirpath '/';
  194.     //urlencoded version
  195.     $curdirpathurl '%2F';
  196. }
  197. //if they are looking at group documents they can't see the root
  198. if($to_group_id!=&& $curdirpath=='/')
  199. {
  200.     $curdirpath $group_properties['directory'];
  201.     $curdirpathurl urlencode($group_properties['directory']);
  202. }
  203. //-----------------------------------------------------------
  204.  
  205. /*
  206. -----------------------------------------------------------
  207.     Constants and variables
  208. -----------------------------------------------------------
  209. */
  210.  
  211. $course_quota DocumentManager::get_course_quota();
  212.  
  213. /*
  214. ==============================================================================
  215.         MAIN SECTION
  216. ==============================================================================
  217. */
  218.  
  219. //-------------------------------------------------------------------//
  220. if (isset($_GET['action']&& $_GET['action']=="download")
  221. {
  222.     //check if the document is in the database
  223.     if(!DocumentManager::get_document_id($_course,$_GET['id']))
  224.     {
  225.         //file not found!
  226.         header('HTTP/1.0 404 Not Found');
  227.         $error404 '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
  228.         $error404 .= '<html><head>';
  229.         $error404 .= '<title>404 Not Found</title>';
  230.         $error404 .= '</head><body>';
  231.         $error404 .= '<h1>Not Found</h1>';
  232.         $error404 .= '<p>The requested URL was not found on this server.</p>';
  233.         $error404 .= '<hr>';
  234.         $error404 .= '</body></html>';
  235.         echo($error404);
  236.         exit;
  237.     }
  238.     // launch event
  239.     event_download($_GET['id']);
  240.     $doc_url=$_GET['id'];
  241.     $full_file_name $base_work_dir.$doc_url;
  242.     DocumentManager::file_send_for_download($full_file_name,true);
  243.     exit;
  244.  }
  245. //-------------------------------------------------------------------//
  246.  
  247. //download of an completed folder
  248. if(isset($_GET['action']&& $_GET['action']=="downloadfolder")
  249. {
  250.     include('downloadfolder.inc.php');
  251. }
  252. //-------------------------------------------------------------------//
  253.  
  254. // slideshow inititalisation
  255. $_SESSION['image_files_only']='';
  256. $image_files_only='';
  257.  
  258. /*
  259. -----------------------------------------------------------
  260.     Header
  261. -----------------------------------------------------------
  262. */
  263.  
  264. $interbreadcrumb[]array ('url'=>'#''name'=> get_lang('Document'));
  265.  
  266. //------interbreadcrumb for the current directory root path
  267.  
  268. $dir_array=explode("/",$curdirpath);
  269. $array_len=count($dir_array);
  270.  
  271. if ($array_len >1)
  272. {
  273.     if(empty($_SESSION['_gid']))
  274.     {
  275.         $url_dir='document.php?&curdirpath=/'
  276.         $interbreadcrumb[]array ('url'=>$url_dir'name'=> get_lang('HomeDirectory'));
  277.     }
  278.  
  279. $dir_acum='';
  280. for ($i=0$i<$array_len;$i++)
  281.     $url_dir='document.php?&curdirpath='.$dir_acum.$dir_array[$i]
  282.     $interbreadcrumb[]array ('url'=>$url_dir'name'=> $dir_array[$i]);
  283.     $dir_acum.=$dir_array[$i].'/';
  284. }
  285.  
  286. $is_allowed_to_edit  api_is_allowed_to_edit();
  287.  
  288. /*
  289.  * Lib for event log, stats & tracking
  290.  * plus record of the access
  291.  */
  292.  
  293. /*
  294. ==============================================================================
  295.         DISPLAY
  296. ==============================================================================
  297. */
  298. if($to_group_id !=0//add group name after for group documents
  299. {
  300.     $add_group_to_title ' ('.$group_properties['name'].')';
  301. }
  302. //api_display_tool_title($tool_name.$add_group_to_title);
  303.  
  304. /*
  305. -----------------------------------------------------------
  306.     Introduction section
  307.     (editable by course admins)
  308. -----------------------------------------------------------
  309. */
  310.  
  311. if(!empty($_SESSION['_gid']))
  312. {
  313. }
  314. else
  315. {
  316. }
  317.  
  318. /*============================================================================*/
  319.  
  320. if($is_allowed_to_edit || $group_member_with_upload_rights// TEACHER ONLY
  321. {
  322.     /*======================================
  323.                 MOVE FILE OR DIRECTORY
  324.       ======================================*/
  325.  
  326.     if (isset($_GET['move']&& $_GET['move']!='')
  327.     {
  328.         if(DocumentManager::get_document_id($_course,$_GET['move']))
  329.         {
  330.             $folders DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit || $group_member_with_upload_rights);
  331.             Display::display_normal_message(build_move_to_selector($folders,$_GET['curdirpath'],$_GET['move'],$group_properties['directory']),false);
  332.         }
  333.     }
  334.  
  335.     if (isset($_POST['move_to']&& isset($_POST['move_file']))
  336.     {
  337.         include_once(api_get_path(LIBRARY_PATH'fileManage.lib.php');
  338.         //this is needed for the update_db_info function
  339.         //$dbTable = $_course['dbNameGlu']."document";
  340.         $dbTable Database::get_course_table(TABLE_DOCUMENT);
  341.  
  342.         //security fix: make sure they can't move files that are not in the document table
  343.         if(DocumentManager::get_document_id($_course,$_POST['move_file']))
  344.         {
  345.             if move($base_work_dir.$_POST['move_file'],$base_work_dir.$_POST['move_to']) )
  346.             {
  347.                 update_db_info("update"$_POST['move_file']$_POST['move_to']."/".basename($_POST['move_file']));
  348.                 //set the current path
  349.                 $curdirpath $_POST['move_to'];
  350.                 $curdirpathurl urlencode($_POST['move_to']);
  351.                 Display::display_confirmation_message(get_lang('DirMv'));
  352.             }
  353.             else
  354.             {
  355.                 Display::display_error_message(get_lang('Impossible'));
  356.             }
  357.         }
  358.         else
  359.         {
  360.             Display::display_error_message(get_lang('Impossible'));
  361.         }
  362.     }
  363.  
  364.     /*======================================
  365.             DELETE FILE OR DIRECTORY
  366.       ======================================*/
  367.  
  368.     if isset($_GET['delete']) )
  369.     {
  370.         include_once(api_get_path(LIBRARY_PATH'fileManage.lib.php');
  371.         if(DocumentManager::delete_document($_course,$_GET['delete'],$base_work_dir))
  372.         {
  373.             Display::display_confirmation_message(get_lang('DocDeleted'));
  374.         }
  375.         else
  376.         {
  377.             Display::display_error_message(get_lang('DocDeleteError'));
  378.         }
  379.     }
  380.  
  381.     ifisset($_POST['action']))
  382.     {
  383.         switch($_POST['action'])
  384.         {
  385.             case 'delete':
  386.                 foreach($_POST['path'as $index => $path)
  387.                 {
  388.                     DocumentManager::delete_document($_course,$path,$base_work_dir);
  389.                 }
  390.                 Display::display_confirmation_message(get_lang('DocDeleted'));
  391.                 break;
  392.         }
  393.     }
  394.  
  395.     /*======================================
  396.                CREATE DIRECTORY
  397.       ======================================*/
  398.  
  399.     //create directory with $_POST data
  400.     if(isset($_POST['create_dir']&& $_POST['dirname']!='')
  401.     {
  402.         //needed for directory creation
  403.         include_once(api_get_path(LIBRARY_PATH'fileUpload.lib.php');
  404.         $post_dir_name=$_POST['dirname'];
  405.         
  406.         if ($post_dir_name=='../' || $post_dir_name=='.' || $post_dir_name=='..'
  407.         {
  408.             Display::display_error_message(get_lang('CannotCreateDir'));
  409.         }
  410.         else
  411.         {
  412.             $added_slash ($curdirpath=='/')?'':'/';
  413.             $dir_name $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
  414.             $dir_check=$base_work_dir.''.$dir_name;
  415.             
  416.             if(!is_dir($dir_check))
  417.             {
  418.                 $created_dir create_unexisting_directory($_course,$_user['user_id'],$to_group_id,$to_user_id,$base_work_dir,$dir_name,$post_dir_name);
  419.                 
  420.                 if($created_dir)
  421.                 {
  422.                     Display::display_confirmation_message('<span title="'.$created_dir.'">'.get_lang('DirCr').'</span>',false);
  423.                     //uncomment if you want to enter the created dir
  424.                     //$curdirpath = $created_dir;
  425.                     //$curdirpathurl = urlencode($curdirpath);
  426.                 }
  427.                 else
  428.                 {
  429.                     Display::display_error_message(get_lang('CannotCreateDir'));
  430.                 }
  431.             }
  432.             else
  433.             {
  434.                 Display::display_error_message(get_lang('CannotCreateDir'));
  435.             }
  436.         }
  437.     }
  438.     
  439.     //show them the form for the directory name
  440.     if(isset($_GET['createdir']))
  441.     {
  442.         //create the form that asks for the directory name
  443.         $new_folder_text '<form action="'.api_get_self().'" method="post">';
  444.         $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  445.         $new_folder_text .= get_lang('NewDir'.' ';
  446.         $new_folder_text .= '<input type="text" name="dirname" />';
  447.         $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'" />';
  448.         $new_folder_text .= '</form>';
  449.         //show the form
  450.         Display::display_normal_message($new_folder_text,false);
  451.     }
  452.  
  453.  
  454.     /*======================================
  455.              VISIBILITY COMMANDS
  456.       ======================================*/
  457.  
  458.     if ((isset($_GET['set_invisible']&& !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']&& !empty($_GET['set_visible'])) AND $_GET['set_visible']<>'*' AND $_GET['set_invisible']<>'*')
  459.     {
  460.         //make visible or invisible?
  461.         if(isset($_GET['set_visible']))
  462.         {
  463.             $update_id $_GET['set_visible'];
  464.             $visibility_command 'visible';
  465.         }
  466.         else
  467.         {
  468.             $update_id $_GET['set_invisible'];
  469.             $visibility_command 'invisible';
  470.         }
  471.         //update item_property to change visibility
  472.         if(api_item_property_update($_courseTOOL_DOCUMENT$update_id$visibility_command$_user['user_id']))
  473.         {
  474.             Display::display_confirmation_message(get_lang("ViMod"));
  475.         }
  476.         else
  477.         {
  478.             Display::display_error_message(get_lang("ViModProb"));
  479.         }
  480.  
  481.     }
  482.     
  483.     
  484.     /*======================================
  485.              TEMPLATE ACTION
  486.       ======================================*/
  487.     
  488.     if(isset($_GET['add_as_template']&& !isset($_POST['create_template'])){
  489.         
  490.         $document_id_for_template intval($_GET['add_as_template']);
  491.         
  492.         //create the form that asks for the directory name
  493.         $new_folder_text '<form name="set_document_as_new_template" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
  494.         $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  495.         $new_folder_text .= '<table><tr><td>';
  496.         $new_folder_text .= get_lang('TemplateName').' : </td>';
  497.         $new_folder_text .= '<td><input type="text" name="template_title" /></td></tr>';
  498.         $new_folder_text .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
  499.         $new_folder_text .= '<td><textarea name="template_description"></textarea></td></tr></table>';
  500.         $new_folder_text .= '<input type="submit" name="create_template" value="'.get_lang('Ok').'" />';
  501.         $new_folder_text .= '</form>';
  502.         //show the form
  503.         Display::display_normal_message($new_folder_text,false);
  504.         
  505.     }
  506.     
  507.     elseif(isset($_GET['add_as_template']&& isset($_POST['create_template']))
  508.     {        
  509.         $document_id_for_template intval(Database::escape_string($_GET['add_as_template']));    
  510.             
  511.         $title=Security::remove_XSS($_POST['template_title']);                
  512.         $description Security::remove_XSS($_POST['template_description']);        
  513.         $course_code api_get_course_id();
  514.         $user_id api_get_user_id();
  515.         
  516.         if(!is_file(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/')){
  517.             mkdir(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/',0777);
  518.         }
  519.         
  520.         DocumentManager::set_document_as_template($title$description$document_id_for_template$course_code$user_id);
  521.         
  522.         Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
  523.         
  524.     }
  525.     
  526.     
  527.     if(isset($_GET['remove_as_template'])){
  528.         
  529.         $document_id_for_template intval($_GET['remove_as_template']);
  530.         $course_code api_get_course_id();
  531.         $user_id api_get_user_id();
  532.         
  533.         DocumentManager::unset_document_as_template($document_id_for_template$course_code$user_id);
  534.         
  535.         Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
  536.         
  537.     }
  538.     
  539.     
  540. // END is allowed to edit
  541.  
  542. /*
  543. -----------------------------------------------------------
  544.     GET ALL DOCUMENT DATA FOR CURDIRPATH
  545. -----------------------------------------------------------
  546. */
  547.  
  548. $docs_and_folders DocumentManager::get_all_document_data($_course,$curdirpath,$to_group_id,NULL,$is_allowed_to_edit || $group_member_with_upload_rights);
  549.  
  550. ?>
  551.  
  552. <div id="folderselector" style="float:left;margin-right:10px;margin-top:5px;">
  553. <?php
  554. $folders DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit || $group_member_with_upload_rights);
  555. if($folders===false)
  556. {
  557.     $folders array();
  558. }
  559. echo(build_directory_selector($folders,$curdirpath,(isset($group_properties['directory'])?$group_properties['directory']:array()),true));
  560. ?>
  561. </div>
  562.     <?php
  563.     echo '<div id="doc_links">';
  564.  
  565.  
  566.     /* GO TO PARENT DIRECTORY */
  567.  
  568.     if ($curdirpath!= '/'&& $curdirpath!=$group_properties['directory'])
  569.     {
  570.     ?>
  571.          <a href="<?php echo api_get_self()?>?<?php echo api_get_cidreq();?>&curdirpath=<?php echo urlencode((dirname($curdirpath)=='\\')?'/':dirname($curdirpath)).$req_gid ?>">
  572.                 <img src="../img/folder_up.gif" border="0" align="absbottom" hspace="5" alt="" />
  573.                 <?php echo get_lang('Up')?></a>&nbsp;
  574.     <?php
  575.     }
  576.  
  577.     if ($is_allowed_to_edit || $group_member_with_upload_rights)
  578.     {
  579.         /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  580.         ?>
  581.             <!-- create new document or directory -->
  582.             <a href="create_document.php?<?php echo api_get_cidreq();?>&dir=<?php echo $curdirpathurl.$req_gid?>"><img src="../img/filenew.gif" border="0" alt="" title="<?php echo get_lang('CreateDoc')?>" /></a>
  583.             <a href="create_document.php?<?php echo api_get_cidreq();?>&dir=<?php echo $curdirpathurl.$req_gid?>"><?php echo get_lang("CreateDoc")?></a>&nbsp;&nbsp;
  584.             <!-- file upload link -->
  585.             <a href="upload.php?<?php echo api_get_cidreq();?>&path=<?php echo $curdirpathurl.$req_gid?>"><img src="../img/submit_file.gif" border="0" title="<?php echo get_lang('UplUploadDocument')?>" alt="" /></a>
  586.             <a href="upload.php?<?php echo api_get_cidreq();?>&path=<?php echo $curdirpathurl.$req_gid?>"><?php echo get_lang('UplUploadDocument')?></a>&nbsp;
  587.             <!-- create directory -->
  588.             <a href="<?php echo api_get_self()?>?<?php echo api_get_cidreq();?>&curdirpath=<?php echo $curdirpathurl.$req_gid?>&amp;createdir=1"><img src="../img/folder_new.gif" border="0" alt ="" /></a>
  589.             <a href="<?php echo api_get_self()?>?<?php echo api_get_cidreq();?>&curdirpath=<?php echo $curdirpathurl.$req_gid?>&amp;createdir=1"><?php echo get_lang("CreateDir")?></a>&nbsp;
  590.         <?php
  591.     }
  592.     ?>
  593.     <!-- download zipped folder -->
  594.     <a href="<?php echo api_get_self()?>?<?php echo api_get_cidreq();?>&action=downloadfolder&amp;path=<?php echo $curdirpathurl.$req_gid?>"><img src="../img/zip_save.gif" border="0" title="<?php echo get_lang("Save")?> (ZIP)" alt="" /></a>
  595.     <a href="<?php echo api_get_self()?>?<?php echo api_get_cidreq();?>&action=downloadfolder&amp;path=<?php echo $curdirpathurl.$req_gid?>"><?php echo get_lang("Save")?> (ZIP)</a>&nbsp;
  596.     <?php
  597.     // Slideshow by Patrick Cool, May 2004
  598.     include("document_slideshow.inc.php");
  599.     if ($image_present)
  600.     {
  601.         echo "<a href=\"slideshow.php?".api_get_cidreq()."&curdirpath=".$curdirpathurl."\"><img src=\"../img/images_gallery.gif\" border=\"0\" title=\"".get_lang('ViewSlideshow')."\"/>&nbsp;"get_lang('ViewSlideshow'"</a>";
  602.     }
  603.     echo "</div>";
  604.  
  605. //==============================================================================
  606.  
  607. if(isset($docs_and_folders&& is_array($docs_and_folders))
  608. {
  609.     //echo('<pre>');
  610.     //print_r($docs_and_folders);
  611.     //echo('</pre>');
  612.     //*************************************************************************************************
  613.     //do we need the title field for the document name or not?
  614.     //we get the setting here, so we only have to do it once
  615.     $use_document_title get_setting('use_document_title');
  616.     //create a sortable table with our data
  617.     $sortable_data array();
  618.     
  619.     while (list ($key$ideach($docs_and_folders))
  620.     {
  621.         $row array ();
  622.  
  623.         //if the item is invisible, wrap it in a span with class invisible
  624.         $invisibility_span_open ($id['visibility']==0)?'<span class="invisible">':'';
  625.         $invisibility_span_close ($id['visibility']==0)?'</span>':'';
  626.         //size (or total size of a directory)
  627.         $size $id['filetype']=='folder' get_total_folder_size($id['path'],$is_allowed_to_edit$id['size'];
  628.         //get the title or the basename depending on what we're using
  629.         if ($use_document_title=='true' AND $id['title']<>'')
  630.         {
  631.             $document_name=$id['title'];
  632.         }
  633.         else
  634.         {
  635.             $document_name=basename($id['path']);
  636.         }
  637.         //data for checkbox
  638.         if (($is_allowed_to_edit || $group_member_with_upload_rightsAND count($docs_and_folders)>1)
  639.         {
  640.             $row[$id['path'];            
  641.         }
  642.         //icons
  643.         $row[]build_document_icon_tag($id['filetype'],$id['path'])
  644.         //document title with hyperlink
  645.         $row[create_document_link($http_www,$document_name,$id['path'],$id['filetype'],$size,$id['visibility']).'<br />'.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close;
  646.         //comments => display comment under the document name
  647.         //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  648.         $display_size format_file_size($size);
  649.         $row['<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  650.  
  651.         //last edit date
  652.         $last_edit_date=$id['lastedit_date'];        
  653.         $display_date date_to_str_ago($last_edit_date).'<br><span class="dropbox_date">'.$last_edit_date.'</span>';        
  654.         $row[$invisibility_span_open.$display_date.$invisibility_span_close;
  655.  
  656.         //admins get an edit column
  657.         if ($is_allowed_to_edit || $group_member_with_upload_rights)
  658.         {
  659.             $is_template (isset($id['is_template'])?$id['is_template']:false);
  660.             // if readonly, check if it the owner of the file or if the user is an admin
  661.             if ($id['insert_user_id'== $_user['user_id'|| api_is_platform_admin())
  662.             {
  663.                 $edit_icons build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key$is_template,0);
  664.             }
  665.             else
  666.             {
  667.                 $edit_icons build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key$is_template,$id['readonly']);            
  668.             }            
  669.             $row[$edit_icons;
  670.         }
  671.         $row[]=$last_edit_date;
  672.         $sortable_data[$row;
  673.     }
  674.     //*******************************************************************************************
  675. }
  676. else
  677. {
  678.     $sortable_data='';
  679.     $table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
  680. }
  681.  
  682. $column_show=array();
  683.  
  684. if (($is_allowed_to_edit || $group_member_with_upload_rightsAND count($docs_and_folders)>1)
  685. {
  686.     $column_show[]=1;
  687. }
  688.  
  689. $column_show[]=1;
  690. $column_show[]=1;
  691. $column_show[]=1;
  692. $column_show[]=1;
  693.  
  694. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  695. {
  696.     $column_show[]=1;
  697. }
  698. $column_show[]=0;
  699.  
  700.  
  701. $column_order=array();
  702.  
  703. if (count($row)==7)
  704. {
  705.     $column_order[]=1;
  706.     $column_order[]=2;
  707.     $column_order[]=3;
  708.     $column_order[]=6;
  709.     $column_order[]=5;
  710. }
  711.  
  712. if (count($row)==5)
  713. {
  714.     $column_order[]=1;
  715.     $column_order[]=2;
  716.     $column_order[]=4;
  717.     $column_order[]=4;            
  718. }
  719.  
  720. $table new SortableTableFromArrayConfig($sortable_data,2,20,'tablename',$column_show,$column_order,'ASC');
  721.  
  722. $query_vars['curdirpath'$curdirpath;
  723.  
  724. if(isset($_SESSION['_gid']))
  725. {
  726.     $query_vars['gidReq'$_SESSION['_gid'];
  727. }
  728. $query_vars['cidReq'api_get_course_id();
  729. $table->set_additional_parameters($query_vars);
  730. $column 0;
  731.  
  732. if (($is_allowed_to_edit || $group_member_with_upload_rightsAND count($docs_and_folders)>1)
  733. {
  734.     $table->set_header($column++,'',false);
  735. }
  736. $table->set_header($column++,get_lang('Type'));
  737. $table->set_header($column++,get_lang('Name'));
  738.  
  739. //$column_header[] = array(get_lang('Comment'),true);  => display comment under the document name
  740. $table->set_header($column++,get_lang('Size'));
  741. $table->set_header($column++,get_lang('Date'));
  742. //admins get an edit column
  743. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  744. {
  745.     $table->set_header($column++,'',false);
  746. }
  747.  
  748. //actions on multiple selected documents
  749. //currently only delete action -> take only DELETE right into account
  750. if (count($docs_and_folders)>1)
  751. {
  752.     if ($is_allowed_to_edit || $group_member_with_upload_rights)
  753.     {
  754.         $form_actions array();        
  755.         $form_action['delete'get_lang('Delete');
  756.         $table->set_form_actions($form_action,'path');
  757.     }
  758. }
  759.  
  760. $table->display();
  761. if(!empty($table_footer))
  762. {
  763.     echo $table_footer;
  764. }
  765.  
  766. /*
  767. ==============================================================================
  768.         Quota section
  769.  
  770.         Proposal: perhaps move/add the quota display to another section, e.g. course info
  771. ==============================================================================
  772. */
  773. if ($is_allowed_to_editdisplay_document_options();
  774.  
  775. /*
  776. ==============================================================================
  777.         Footer
  778. ==============================================================================
  779. */
  780. ?>

Documentation generated on Thu, 12 Jun 2008 13:20:11 -0500 by phpDocumentor 1.4.1