course_document.inc.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. include_once('global.inc.php');
  3. /*
  4. ==============================================================================
  5. INIT SECTION
  6. ==============================================================================
  7. */
  8. $langFile = 'document';
  9. include(api_get_path(SYS_CODE_PATH).'document/document.inc.php');
  10. api_protect_course_script();
  11. //session
  12. if(isset($_GET['id_session']))
  13. $_SESSION['id_session'] = $_GET['id_session'];
  14. $htmlHeadXtra[] =
  15. "<script type=\"text/javascript\">
  16. function confirmation (name)
  17. {
  18. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  19. {return true;}
  20. else
  21. {return false;}
  22. }
  23. </script>";
  24. /*
  25. -----------------------------------------------------------
  26. Variables
  27. - some need defining before inclusion of libraries
  28. -----------------------------------------------------------
  29. */
  30. //what's the current path?
  31. $sType = isset($sType)?$sType:"Image";
  32. $course_dir = $_course['path']."/document/".$sType;
  33. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  34. $base_work_dir = $sys_course_path.$course_dir;
  35. $http_www = api_get_path('WEB_COURSE_PATH').$_course['path'].'/document/'.$sType;
  36. $dbl_click_id = 0; // used to avoid double-click
  37. $is_allowed_to_edit = api_is_allowed_to_edit();
  38. $to_group_id = 0;
  39. $req_gid = '';
  40. /*
  41. -----------------------------------------------------------
  42. Libraries
  43. -----------------------------------------------------------
  44. */
  45. //libraries are included by default
  46. include_once(api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  47. include_once(api_get_path(LIBRARY_PATH) . 'events.lib.inc.php');
  48. include_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  49. include_once(api_get_path(LIBRARY_PATH) . 'tablesort.lib.php');
  50. /*
  51. -----------------------------------------------------------
  52. Constants and variables
  53. -----------------------------------------------------------
  54. */
  55. $course_quota = DocumentManager::get_course_quota();
  56. /*
  57. ==============================================================================
  58. MAIN SECTION
  59. ==============================================================================
  60. */
  61. /*
  62. -----------------------------------------------------------
  63. Header
  64. -----------------------------------------------------------
  65. */
  66. $tool_name = get_lang("Doc"); // title of the page (should come from the language file)
  67. ?>
  68. <style type="text/css" media="screen, projection">
  69. /*<![CDATA[*/
  70. @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/default/default.css";
  71. /*]]>*/
  72. </style>
  73. <?php
  74. if(api_get_setting('stylesheets')<>'')
  75. {
  76. ?>
  77. <style type="text/css" media="screen, projection">
  78. /*<![CDATA[*/
  79. @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets');?>/default.css";
  80. /*]]>*/
  81. </style>
  82. <?php
  83. }
  84. $is_allowed_to_edit = api_is_allowed_to_edit();
  85. if($is_allowed_to_edit) // TEACHER ONLY
  86. {
  87. /*======================================
  88. DELETE FILE OR DIRECTORY
  89. ======================================*/
  90. if ( isset($_GET['delete']) )
  91. {
  92. include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  93. if(DocumentManager::delete_document($_course,$_GET['delete'],$base_work_dir))
  94. {
  95. Display::display_normal_message(get_lang('DocDeleted'));
  96. }
  97. else
  98. {
  99. Display::display_normal_message(get_lang('DocDeleteError'));
  100. }
  101. }
  102. if( isset($_POST['action']))
  103. {
  104. switch($_POST['action'])
  105. {
  106. case 'delete':
  107. foreach($_POST['path'] as $index => $path)
  108. {
  109. DocumentManager::delete_document($_course,$path,$base_work_dir);
  110. }
  111. Display::display_normal_message(get_lang('DocDeleted'));
  112. break;
  113. }
  114. }
  115. } // END is allowed to edit
  116. /*
  117. -----------------------------------------------------------
  118. GET ALL DOCUMENT DATA FOR CURDIRPATH
  119. -----------------------------------------------------------
  120. */
  121. $docs_and_folders = getlist ($base_work_dir.'/');
  122. ?>
  123. <?php
  124. if($docs_and_folders)
  125. {
  126. //echo('<pre>');
  127. //print_r($docs_and_folders);
  128. //echo('</pre>');
  129. //*************************************************************************************************
  130. //do we need the title field for the document name or not?
  131. //we get the setting here, so we only have to do it once
  132. $use_document_title = get_setting('use_document_title');
  133. //create a sortable table with our data
  134. $sortable_data = array();
  135. while (list ($key, $id) = each($docs_and_folders))
  136. {
  137. $row = array ();
  138. //if the item is invisible, wrap it in a span with class invisible
  139. $invisibility_span_open = ($id['visibility']==0)?'<span class="invisible">':'';
  140. $invisibility_span_close = ($id['visibility']==0)?'</span>':'';
  141. //size (or total size of a directory)
  142. $size = $id['filetype']=='folder' ? get_total_folder_size($id['path'],$is_allowed_to_edit) : $id[size];
  143. //get the title or the basename depending on what we're using
  144. if ($use_document_title=='true' AND $id['title']<>'')
  145. {
  146. $document_name=$id['title'];
  147. }
  148. else
  149. {
  150. $document_name=basename($id['path']);
  151. }
  152. //$row[] = $key; //testing
  153. //data for checkbox
  154. /*
  155. if ($is_allowed_to_edit AND count($docs_and_folders)>1)
  156. {
  157. $row[] = $id['path'];
  158. }
  159. */
  160. //icons
  161. $row[]= build_document_icon_tag($id['filetype'],$id['path']);
  162. //document title with hyperlink
  163. $row[] = '<a href="#" onclick="OpenFile(\''.$http_www.'/'.$id['title'].'\');return false;">'.$id['title'].'</a>';
  164. //comments => display comment under the document name
  165. //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  166. $display_size = format_file_size($size);
  167. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  168. //last edit date
  169. $display_date = format_date(strtotime($id['lastedit_date']));
  170. $row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
  171. $sortable_data[] = $row;
  172. }
  173. //*******************************************************************************************
  174. }
  175. else
  176. {
  177. $sortable_data='';
  178. $table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
  179. }
  180. $table = new SortableTableFromArray($sortable_data,4,10);
  181. $query_vars['curdirpath'] = $curdirpath;
  182. if(isset($_SESSION['_gid']))
  183. {
  184. $query_vars['gidReq'] = $_SESSION['_gid'];
  185. }
  186. $table->set_additional_parameters($query_vars);
  187. $column = 0;
  188. /*
  189. if ($is_allowed_to_edit AND count($docs_and_folders)>1)
  190. {
  191. $table->set_header($column++,'',false);
  192. }
  193. */
  194. $table->set_header($column++,get_lang('Type'));
  195. $table->set_header($column++,get_lang('Name'));
  196. //$column_header[] = array(get_lang('Comment'),true); => display comment under the document name
  197. $table->set_header($column++,get_lang('Size'));
  198. $table->set_header($column++,get_lang('Date'));
  199. //currently only delete action -> take only DELETE right into account
  200. /*
  201. if (count($docs_and_folders)>1)
  202. {
  203. if ($is_allowed_to_edit)
  204. {
  205. $form_actions = array();
  206. $form_action['delete'] = get_lang('Delete');
  207. $table->set_form_actions($form_action,'path');
  208. }
  209. }
  210. */
  211. $table->display();
  212. echo $table_footer;
  213. ////////// functions ////////////
  214. function getlist ($directory) {
  215. //global $delim, $win;
  216. if ($d = @opendir($directory)) {
  217. while (($filename = @readdir($d)) !== false) {
  218. $path = $directory . $filename;
  219. if ($filename != '..')
  220. if ($filename != '.')
  221. {
  222. $file = array(
  223. "lastedit_date" =>date ("Y-m-d H:i:s", filemtime($path)),
  224. "visibility" => 1,
  225. "path" => $path,
  226. "title" => basename($path),
  227. "filetype" => filetype($path),
  228. "size" => filesize ($path)
  229. );
  230. $files[] = $file;
  231. }
  232. }
  233. return $files;
  234. } else {
  235. return false;
  236. }
  237. }
  238. ?>
  239. <SCRIPT LANGUAGE="JavaScript">
  240. <!--
  241. function OpenFile( fileUrl )
  242. {
  243. SetUrl( fileUrl ) ;
  244. window.close() ;
  245. }
  246. //-->
  247. </SCRIPT>