course_document.inc.php 9.1 KB

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