course_document.inc.php 8.3 KB

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