document.php 24 KB

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