document.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. <?php // $Id: document.php 9757 2006-10-25 11:35:34Z elixir_inter $
  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. $langFile = "document";
  59. include("../inc/global.inc.php");
  60. $this_section=SECTION_COURSES;
  61. include('document.inc.php');
  62. include(api_get_path(LIBRARY_PATH).'/xajax/xajax.inc.php');
  63. $xajax = new Xajax();
  64. //$xajax -> debugOn();
  65. $xajax -> registerFunction('launch_ppt2lp');
  66. api_protect_course_script();
  67. //session
  68. if(isset($_GET['id_session']))
  69. $_SESSION['id_session'] = $_GET['id_session'];
  70. $htmlHeadXtra[] =
  71. "<script type=\"text/javascript\">
  72. function confirmation (name)
  73. {
  74. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  75. {return true;}
  76. else
  77. {return false;}
  78. }
  79. </script>";
  80. /*
  81. -----------------------------------------------------------
  82. Variables
  83. - some need defining before inclusion of libraries
  84. -----------------------------------------------------------
  85. */
  86. //what's the current path?
  87. //we will verify this a bit further down
  88. if(isset($_GET['curdirpath']) && $_GET['curdirpath']!='')
  89. {
  90. $curdirpath = $_GET['curdirpath'];
  91. }
  92. elseif (isset($_POST['curdirpath']) && $_POST['curdirpath']!='')
  93. {
  94. $curdirpath = $_POST['curdirpath'];
  95. }
  96. else
  97. {
  98. $curdirpath = '/';
  99. }
  100. $curdirpathurl = urlencode($curdirpath);
  101. $course_dir = $_course['path']."/document";
  102. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  103. $base_work_dir = $sys_course_path.$course_dir;
  104. $http_www = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document';
  105. $dbl_click_id = 0; // used to avoid double-click
  106. $is_allowed_to_edit = api_is_allowed_to_edit();
  107. $group_member_with_upload_rights = false;
  108. //if the group id is set, we show them group documents
  109. if(isset($_SESSION['_gid']) && $_SESSION['_gid']!='')
  110. {
  111. //needed for group related stuff
  112. include_once(api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php');
  113. //get group info
  114. $group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
  115. $noPHP_SELF=true;
  116. //let's assume the user cannot upload files for the group
  117. $group_member_with_upload_rights = false;
  118. if($group_properties['doc_state']==2) //documents are private
  119. {
  120. if($is_allowed_to_edit || GroupManager :: is_user_in_group($_uid,$_SESSION['_gid'])) //only courseadmin or group members (members + tutors) allowed
  121. {
  122. $to_group_id = $_SESSION['_gid'];
  123. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  124. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('Groups'));
  125. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
  126. //they are allowed to upload
  127. $group_member_with_upload_rights = true;
  128. }
  129. else
  130. {
  131. $to_group_id = 0;
  132. $req_gid = '';
  133. }
  134. }
  135. elseif($group_properties['doc_state']==1) //documents are public
  136. {
  137. $to_group_id = $_SESSION['_gid'];
  138. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  139. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace'));
  140. //allowed to upload?
  141. if($is_allowed_to_edit || GroupManager::is_subscribed($_uid,$_SESSION['_gid'])) //only courseadmin or group members can upload
  142. {
  143. $group_member_with_upload_rights = true;
  144. }
  145. }
  146. else //documents not active for this group
  147. {
  148. $to_group_id = 0;
  149. $req_gid = '';
  150. }
  151. $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights;
  152. }
  153. else
  154. {
  155. $to_group_id = 0;
  156. $req_gid = '';
  157. }
  158. /*
  159. -----------------------------------------------------------
  160. Libraries
  161. -----------------------------------------------------------
  162. */
  163. //the main_api.lib.php, database.lib.php and display.lib.php
  164. //libraries are included by default
  165. include_once(api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  166. include_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php');
  167. include_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  168. include_once(api_get_path(LIBRARY_PATH) . 'tablesort.lib.php');
  169. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  170. //-----------------------------------------------------------
  171. //check the path
  172. //if the path is not found (no document id), set the path to /
  173. if(!DocumentManager::get_document_id($_course,$curdirpath)){
  174. $curdirpath = '/';
  175. //urlencoded version
  176. $curdirpathurl = '%2F';
  177. }
  178. //if they are looking at group documents they can't see the root
  179. if($to_group_id!=0 && $curdirpath=='/')
  180. {
  181. $curdirpath = $group_properties['directory'];
  182. $curdirpathurl = urlencode($group_properties['directory']);
  183. }
  184. //-----------------------------------------------------------
  185. /*
  186. -----------------------------------------------------------
  187. Constants and variables
  188. -----------------------------------------------------------
  189. */
  190. $course_quota = DocumentManager::get_course_quota();
  191. /*
  192. ==============================================================================
  193. MAIN SECTION
  194. ==============================================================================
  195. */
  196. /**
  197. * Function called with xajax.
  198. * It create a directory named like the powerpoint file and generate slides from it.
  199. * @param $file the path of the powerpoint document
  200. * @return XajaxResponse object
  201. */
  202. function launch_ppt2lp($file){
  203. global $_course,$_uid, $openoffice_conf, $base_work_dir;
  204. $response = new XajaxResponse();
  205. // lp tables
  206. $tbl_learnpath_item = Database::get_course_table(LEARNPATH_ITEM_TABLE);
  207. $tbl_learnpath_chapter = Database::get_course_table(LEARNPATH_CHAPTER_TABLE);
  208. $tbl_learnpath_main = Database::get_course_table(LEARNPATH_MAIN_TABLE);
  209. $tbl_tool = Database::get_course_table(TOOL_LIST_TABLE);
  210. $file = urldecode($file);
  211. // get properties of ppt file
  212. $document_datas = DocumentManager::get_all_document_data($_course, $file);
  213. $to_group_id = (empty($document_datas['to_group_id'])) ? 0 : $document_datas['to_group_id'];
  214. $to_user_id = (empty($document_datas['to_user_id'])) ? null : $document_datas['to_user_id'];
  215. //create the directory
  216. $added_slash = '/';
  217. $dir_name = $added_slash.substr($file, 1, strrpos($file,'.')-1);
  218. $created_dir = create_unexisting_directory($_course,$_uid,$to_group_id,$to_user_id,$base_work_dir,$dir_name);
  219. chmod ($base_work_dir.$created_dir,0777);
  220. /*
  221. * exec java application
  222. * the parameters of the program are :
  223. * - javacommand on this server ;
  224. * - host where openoffice is running;
  225. * - port with which openoffice is listening
  226. * - file to convert
  227. * - folder where put the slides
  228. * - ftppassword if required
  229. * The program fills $files with the list of slides created
  230. */
  231. $cmd = 'cd '.api_get_path(LIBRARY_PATH).'/ppt2png && ./launch_ppt2png.sh '.$openoffice_conf['javacommand'].' '.$openoffice_conf['host'].' '.$openoffice_conf['port'].' "'.$base_work_dir.$file.'" "'.$base_work_dir.$created_dir.'" '.$openoffice_conf['ftppasswd'];
  232. $files = array();
  233. $shell = exec($cmd, $files, $return);
  234. chmod ($base_work_dir.$created_dir,0744);
  235. if($return != 0) { //if the java application returns an error code
  236. DocumentManager::delete_document($_course, $dir_name, $base_work_dir);
  237. $response -> addAssign('ajax_response', 'innerHTML', '<div class="error-message">'.get_lang('nookppt2lp').' : '.$return.$cmd.'</div>');
  238. $response -> addScript('document.getElementById("documents_content").style.display="block"');
  239. }
  240. else {
  241. // create lp
  242. $learnpath_name = 'lp_';
  243. $learnpath_name .= substr($_GET['file'], strrpos($_GET['file'],'/')+1);
  244. $learnpath_name = substr($learnpath_name,0, strrpos($learnpath_name,'.'));
  245. $learnpath_description = '';
  246. $sql ="INSERT INTO $tbl_learnpath_main (learnpath_name, learnpath_description) VALUES ('".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
  247. api_sql_query($sql,__FILE__,__LINE__);
  248. $my_lp_id = Database::get_last_insert_id();
  249. $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','squaregrey.gif',0)";
  250. api_sql_query($sql,__FILE__,__LINE__);
  251. // insert a new module
  252. $title = 'slides';
  253. $omschrijving = '';
  254. $order = 1;
  255. $sql ="INSERT INTO $tbl_learnpath_chapter (learnpath_id, chapter_name, chapter_description, display_order) VALUES ('".domesticate($my_lp_id)."', '".domesticate(htmlspecialchars($title))."','".domesticate(htmlspecialchars($omschrijving))."', '".domesticate($order)."')";
  256. $result=api_sql_query($sql,__FILE__,__LINE__);
  257. $chapter_id = Database::get_last_insert_id();
  258. $order = 1;
  259. foreach($files as $file){
  260. $document_id = add_document($_course,$created_dir.'/'.$file,'file',filesize($base_work_dir.$created_dir.'/'.$file),$file);
  261. if ($document_id){
  262. //put the document in item_property update
  263. api_item_property_update($_course,TOOL_DOCUMENT,$document_id,'DocumentAdded',$_SESSION['_uid'],$to_group_id,$to_user_id);
  264. $sql = "INSERT INTO $tbl_learnpath_item (chapter_id, item_type, item_id, display_order) VALUES ('$chapter_id', 'Document','".$document_id."','".$order."')";
  265. $result = api_sql_query($sql, __FILE__, __LINE__);
  266. $order++;
  267. }
  268. }
  269. // redirect on the lp view
  270. $response -> addScript('document.location="../learnpath/showinframes.php?source_id=5&action=&learnpath_id='.$my_lp_id.'&chapter_id=&originalresource=no";');
  271. }
  272. return $response;
  273. }
  274. $xajax -> processRequests();
  275. //-------------------------------------------------------------------//
  276. if ($_GET['action']=="download")
  277. {
  278. //check if the document is in the database
  279. if(!DocumentManager::get_document_id($_course,$_GET['id']))
  280. {
  281. //file not found!
  282. header("HTTP/1.0 404 Not Found");
  283. $error404 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
  284. $error404 .= '<html><head>';
  285. $error404 .= '<title>404 Not Found</title>';
  286. $error404 .= '</head><body>';
  287. $error404 .= '<h1>Not Found</h1>';
  288. $error404 .= '<p>The requested URL was not found on this server.</p>';
  289. $error404 .= '<hr>';
  290. $error404 .= '</body></html>';
  291. echo($error404);
  292. exit;
  293. }
  294. // launch event
  295. event_download($_GET['id']);
  296. $doc_url=$_GET['id'];
  297. $full_file_name = $base_work_dir.$doc_url;
  298. DocumentManager::file_send_for_download($full_file_name,true);
  299. exit;
  300. }
  301. //-------------------------------------------------------------------//
  302. //download of an completed folder
  303. if($_GET['action']=="downloadfolder")
  304. {
  305. include('downloadfolder.inc.php');
  306. }
  307. //-------------------------------------------------------------------//
  308. // slideshow inititalisation
  309. $_SESSION["image_files_only"]="";
  310. $image_files_only="";
  311. /*
  312. -----------------------------------------------------------
  313. Header
  314. -----------------------------------------------------------
  315. */
  316. $tool_name = get_lang("Doc"); // title of the page (should come from the language file)
  317. Display::display_header($tool_name,"Doc");
  318. $is_allowed_to_edit = api_is_allowed_to_edit();
  319. /*
  320. * Lib for event log, stats & tracking
  321. * plus record of the access
  322. */
  323. event_access_tool(TOOL_DOCUMENT);
  324. /*
  325. ==============================================================================
  326. DISPLAY
  327. ==============================================================================
  328. */
  329. if($to_group_id !=0) //add group name after for group documents
  330. {
  331. $add_group_to_title = ' ('.$group_properties['name'].')';
  332. }
  333. //api_display_tool_title($tool_name.$add_group_to_title);
  334. /*======================================
  335. PPT2LP SECTION
  336. ======================================*/
  337. $xajax -> printJavascript('../inc/lib/xajax/');
  338. echo '<script type="text/javascript">
  339. function prepare_ppt2lp(file){
  340. document.getElementById("ajax_response").style.display = "block";
  341. document.getElementById("documents_content").style.display="none";
  342. xajax_launch_ppt2lp(file);
  343. }
  344. </script>';
  345. echo '<div id="ajax_response" align="center" width="100%" style="display:none">
  346. '.get_lang('Wait').'<br /><br />
  347. <img src="../img/anim-loader.gif" />
  348. </div>';
  349. echo '<div id="documents_content">';
  350. /*
  351. -----------------------------------------------------------
  352. Introduction section
  353. (editable by course admins)
  354. -----------------------------------------------------------
  355. */
  356. Display::display_introduction_section(TOOL_DOCUMENT);
  357. /*============================================================================*/
  358. if($is_allowed_to_edit || $group_member_with_upload_rights) // TEACHER ONLY
  359. {
  360. /*======================================
  361. MOVE FILE OR DIRECTORY
  362. ======================================*/
  363. if (isset($_GET['move']) && $_GET['move']!='')
  364. {
  365. if(DocumentManager::get_document_id($_course,$_GET['move']))
  366. {
  367. $folders = DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit || $group_member_with_upload_rights);
  368. Display::display_normal_message(build_move_to_selector($folders,$_GET['curdirpath'],$_GET['move'],$group_properties['directory']));
  369. }
  370. }
  371. if (isset($_POST['move_to']) && isset($_POST['move_file']))
  372. {
  373. include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  374. //this is needed for the update_db_info function
  375. //$dbTable = $_course['dbNameGlu']."document";
  376. $dbTable = Database::get_course_table(DOCUMENT_TABLE);
  377. //security fix: make sure they can't move files that are not in the document table
  378. if(DocumentManager::get_document_id($_course,$_POST['move_file'])) {
  379. //Display::display_normal_message('We want to move '.$_POST['move_file'].' to '.$_POST['move_to']);
  380. if ( move($base_work_dir.$_POST['move_file'],$base_work_dir.$_POST['move_to']) )
  381. {
  382. update_db_info("update", $_POST['move_file'], $_POST['move_to']."/".basename($_POST['move_file']));
  383. //set the current path
  384. $curdirpath = $_POST['move_to'];
  385. $curdirpathurl = urlencode($_POST['move_to']);
  386. Display::display_normal_message(get_lang('DirMv'));
  387. }
  388. else
  389. {
  390. Display::display_error_message(get_lang('Impossible'));
  391. }
  392. }
  393. else
  394. {
  395. Display::display_error_message(get_lang('Impossible'));
  396. }
  397. }
  398. /*======================================
  399. DELETE FILE OR DIRECTORY
  400. ======================================*/
  401. if ( isset($_GET['delete']) )
  402. {
  403. include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  404. if(DocumentManager::delete_document($_course,$_GET['delete'],$base_work_dir))
  405. {
  406. Display::display_normal_message(get_lang('DocDeleted'));
  407. }
  408. else
  409. {
  410. Display::display_normal_message(get_lang('DocDeleteError'));
  411. }
  412. }
  413. if( isset($_POST['action']))
  414. {
  415. switch($_POST['action'])
  416. {
  417. case 'delete':
  418. foreach($_POST['path'] as $index => $path)
  419. {
  420. DocumentManager::delete_document($_course,$path,$base_work_dir);
  421. }
  422. Display::display_normal_message(get_lang('DocDeleted'));
  423. break;
  424. }
  425. }
  426. /*======================================
  427. CREATE DIRECTORY
  428. ======================================*/
  429. //create directory with $_POST data
  430. if(isset($_POST['create_dir']) && $_POST['dirname']!='')
  431. {
  432. //needed for directory creation
  433. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  434. $added_slash = ($curdirpath=='/')?'':'/';
  435. $dir_name = $curdirpath.$added_slash.replace_dangerous_char($_POST['dirname']);
  436. $created_dir = create_unexisting_directory($_course,$_uid,$to_group_id,$to_user_id,$base_work_dir,$dir_name,$_POST['dirname']);
  437. if($created_dir)
  438. {
  439. //Display::display_normal_message("<strong>".$created_dir."</strong> was created!");
  440. Display::display_normal_message('<span title="'.$created_dir.'">'.get_lang('DirCr').'</span>');
  441. //uncomment if you want to enter the created dir
  442. //$curdirpath = $created_dir;
  443. //$curdirpathurl = urlencode($curdirpath);
  444. }
  445. else
  446. {
  447. Display::display_error_message(get_lang('CannotCreateDir'));
  448. }
  449. }
  450. //show them the form for the directory name
  451. if(isset($_GET['createdir']))
  452. {
  453. //create the form that asks for the directory name
  454. $new_folder_text = '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
  455. $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  456. $new_folder_text .= get_lang('NewDir') .' ';
  457. $new_folder_text .= '<input type="text" name="dirname" />';
  458. $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'" />';
  459. $new_folder_text .= '</form>';
  460. //show the form
  461. Display::display_normal_message($new_folder_text);
  462. }
  463. /*======================================
  464. VISIBILITY COMMANDS
  465. ======================================*/
  466. 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']<>'*')
  467. {
  468. //make visible or invisible?
  469. if(isset($_GET['set_visible']))
  470. {
  471. $update_id = $_GET['set_visible'];
  472. $visibility_command = 'visible';
  473. }
  474. else
  475. {
  476. $update_id = $_GET['set_invisible'];
  477. $visibility_command = 'invisible';
  478. }
  479. //update item_property to change visibility
  480. if(api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, $_uid))
  481. {
  482. Display::display_normal_message(get_lang("ViMod"));
  483. }
  484. else
  485. {
  486. Display::display_error_message(get_lang("ViModProb"));
  487. }
  488. }
  489. } // END is allowed to edit
  490. /*
  491. -----------------------------------------------------------
  492. GET ALL DOCUMENT DATA FOR CURDIRPATH
  493. -----------------------------------------------------------
  494. */
  495. $docs_and_folders = DocumentManager::get_all_document_data($_course,$curdirpath,$to_group_id,NULL,$is_allowed_to_edit || $group_member_with_upload_rights);
  496. ?>
  497. <div id="folderselector" style="float:left;margin-right:10px;margin-top:5px;">
  498. <?php
  499. $folders = DocumentManager::get_all_document_folders($_course,$to_group_id,$is_allowed_to_edit || $group_member_with_upload_rights);
  500. echo(build_directory_selector($folders,$curdirpath,$group_properties['directory']));
  501. ?>
  502. </div>
  503. <?php
  504. echo "<div id=\"doc_links\">";
  505. /* GO TO PARENT DIRECTORY */
  506. if ($curdirpath!= '/'&& $curdirpath!=$group_properties['directory'])
  507. {
  508. ?>
  509. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?curdirpath=<?php echo urlencode((dirname($curdirpath)=='\\')?'/':dirname($curdirpath)) ?>">
  510. <img src="../img/parent.gif" border="0" align="absbottom" hspace="5" alt="" />
  511. <?php echo get_lang("Up"); ?></a>&nbsp;
  512. <?php
  513. }
  514. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  515. {
  516. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  517. ?>
  518. <!-- create new document or directory -->
  519. <a href="create_document.php?dir=<?php echo $curdirpathurl; ?>"><img src="../img/new_doc.gif" border="0" alt="" title="<?php echo get_lang('CreateDoc'); ?>" /></a>
  520. <a href="create_document.php?dir=<?php echo $curdirpathurl; ?>"><?php echo get_lang("CreateDoc"); ?></a>&nbsp;&nbsp;
  521. <!-- file upload link -->
  522. <a href="upload.php?path=<?php echo $curdirpathurl.$req_gid; ?>"><img src="../img/upload.gif" border="0" title="<?php echo get_lang('UplUploadDocument'); ?>" alt="" /></a>
  523. <a href="upload.php?path=<?php echo $curdirpathurl.$req_gid; ?>"><?php echo get_lang('UplUploadDocument'); ?></a>&nbsp;
  524. <!-- create directory -->
  525. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?curdirpath=<?php echo $curdirpathurl; ?>&amp;createdir=1"><img src="../img/new_folder.gif" border="0" alt ="" /></a>
  526. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?curdirpath=<?php echo $curdirpathurl; ?>&amp;createdir=1"><?php echo get_lang("CreateDir"); ?></a>&nbsp;
  527. <?php
  528. }
  529. ?>
  530. <!-- download zipped folder -->
  531. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=downloadfolder&amp;path=<?php echo $curdirpathurl; ?>"><img src="../img/save_zip.gif" border="0" title="<?php echo get_lang("Save"); ?> (ZIP)" alt="" /></a>
  532. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=downloadfolder&amp;path=<?php echo $curdirpathurl; ?>"><?php echo get_lang("Save"); ?> (ZIP)</a>&nbsp;
  533. <?php
  534. // Slideshow by Patrick Cool, May 2004
  535. include("document_slideshow.inc.php");
  536. // including the language file for the slideshow
  537. include(api_get_path(SYS_LANG_PATH).$languageInterface."/"."slideshow.inc.php");
  538. if ($image_present)
  539. {
  540. echo "<a href=\"slideshow.php?curdirpath=".$curdirpathurl."\"><img src=\"../img/gif.gif\" border=\"0\" align=\"absmiddle\" title=\"".get_lang('ViewSlideshow')."\"/>". get_lang('ViewSlideshow') . "</a>";
  541. }
  542. echo "</div>";
  543. //==============================================================================
  544. if($docs_and_folders)
  545. {
  546. //echo('<pre>');
  547. //print_r($docs_and_folders);
  548. //echo('</pre>');
  549. //*************************************************************************************************
  550. //do we need the title field for the document name or not?
  551. //we get the setting here, so we only have to do it once
  552. $use_document_title = get_setting('use_document_title');
  553. //create a sortable table with our data
  554. $sortable_data = array();
  555. while (list ($key, $id) = each($docs_and_folders))
  556. {
  557. $row = array ();
  558. //if the item is invisible, wrap it in a span with class invisible
  559. $invisibility_span_open = ($id['visibility']==0)?'<span class="invisible">':'';
  560. $invisibility_span_close = ($id['visibility']==0)?'</span>':'';
  561. //size (or total size of a directory)
  562. $size = $id['filetype']=='folder' ? get_total_folder_size($id['path'],$is_allowed_to_edit) : $id[size];
  563. //get the title or the basename depending on what we're using
  564. if ($use_document_title=='true' AND $id['title']<>'')
  565. {
  566. $document_name=$id['title'];
  567. }
  568. else
  569. {
  570. $document_name=basename($id['path']);
  571. }
  572. //$row[] = $key; //testing
  573. //data for checkbox
  574. if (($is_allowed_to_edit || $group_member_with_upload_rights) AND count($docs_and_folders)>1)
  575. {
  576. $row[] = $id['path'];
  577. }
  578. //icons
  579. $row[]= build_document_icon_tag($id['filetype'],$id['path']);
  580. //document title with hyperlink
  581. $row[] = create_document_link($http_www,$document_name,$id['path'],$id['filetype'],$size,$id['visibility']).'<br />'.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  582. //comments => display comment under the document name
  583. //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  584. $display_size = format_file_size($size);
  585. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  586. //last edit date
  587. $display_date = format_date(strtotime($id['lastedit_date']));
  588. $row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
  589. //admins get an edit column
  590. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  591. {
  592. $edit_icons = build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key);
  593. // if ppt2lp is actived and it's a ppt-like document, we display a link on which an ajax event is linked : prepare_ppt2lp (see upper)
  594. if(api_service_is_active('ppt2lp') && in_array(substr($id['path'],strrpos($id['path'],'.')+1),array("ppt","odp"))){
  595. $edit_icons .= '<a href="#" onclick="prepare_ppt2lp(\''.urlencode($id['path']).'\')" title="'.get_lang('Ppt2lp').'" alt="'.get_lang('Ppt2lp').'"><img src="../img/recycle.gif" border="0" /></a>';
  596. }
  597. $row[] = $edit_icons;
  598. }
  599. $sortable_data[] = $row;
  600. }
  601. //*******************************************************************************************
  602. }
  603. else
  604. {
  605. $sortable_data='';
  606. $table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
  607. //echo('<p><strong>'.get_lang('NoDocsInFolder').'</strong></p>');
  608. }
  609. $table = new SortableTableFromArray($sortable_data,2,100);
  610. $query_vars['curdirpath'] = $curdirpath;
  611. if(isset($_SESSION['_gid']))
  612. {
  613. $query_vars['gidReq'] = $_SESSION['_gid'];
  614. }
  615. $table->set_additional_parameters($query_vars);
  616. $column = 0;
  617. if (($is_allowed_to_edit || $group_member_with_upload_rights) AND count($docs_and_folders)>1)
  618. {
  619. $table->set_header($column++,'',false);
  620. }
  621. $table->set_header($column++,get_lang('Type'));
  622. $table->set_header($column++,get_lang('Name'));
  623. //$column_header[] = array(get_lang('Comment'),true); => display comment under the document name
  624. $table->set_header($column++,get_lang('Size'));
  625. $table->set_header($column++,get_lang('Date'));
  626. //admins get an edit column
  627. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  628. {
  629. $table->set_header($column++,'',false);
  630. }
  631. //actions on multiple selected documents
  632. //currently only delete action -> take only DELETE right into account
  633. if (count($docs_and_folders)>1)
  634. {
  635. if ($is_allowed_to_edit || $group_member_with_upload_rights)
  636. {
  637. $form_actions = array();
  638. $form_action['delete'] = get_lang('Delete');
  639. $table->set_form_actions($form_action,'path');
  640. }
  641. }
  642. $table->display();
  643. echo $table_footer;
  644. /*
  645. ==============================================================================
  646. Quota section
  647. Proposal: perhaps move/add the quota display to another section, e.g. course info
  648. ==============================================================================
  649. */
  650. if ($is_allowed_to_edit) display_document_options();
  651. /*
  652. ==============================================================================
  653. Footer
  654. ==============================================================================
  655. */
  656. echo '</div>';
  657. Display::display_footer();
  658. ?>