course_document.inc.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. $language_file = array('create_course', 'document');
  3. include_once('global.inc.php');
  4. require_once(api_get_path(SYS_CODE_PATH).'inc/lib/course_document.lib.php');
  5. /*
  6. ==============================================================================
  7. INIT SECTION
  8. ==============================================================================
  9. */
  10. // name of the language file that needs to be included
  11. require_once api_get_path(INCLUDE_PATH).'lib/fckeditor/repository.php';
  12. include(api_get_path(SYS_CODE_PATH).'document/document.inc.php');
  13. //if(!$is_in_admin){
  14. if(!api_is_platform_admin()){
  15. api_protect_course_script();
  16. }
  17. //session
  18. if(isset($_GET['id_session']))
  19. $_SESSION['id_session'] = intval($_GET['id_session']);
  20. $htmlHeadXtra[] =
  21. "<script type=\"text/javascript\">
  22. function confirmation (name)
  23. {
  24. if (confirm(\" ". api_convert_encoding(get_lang('AreYouSureToDelete'), 'UTF-8', $charset) ." \"+ name + \" ?\"))
  25. {return true;}
  26. else
  27. {return false;}
  28. }
  29. </script>";
  30. /*
  31. -----------------------------------------------------------
  32. Variables
  33. - some need defining before inclusion of libraries
  34. -----------------------------------------------------------
  35. */
  36. $sType = isset($sType) ? $sType : '';
  37. if($sType=="MP3") $sType="audio";
  38. // Resource type
  39. $sType = strtolower($sType);
  40. // Choosing the repository to be used.
  41. if (api_is_in_course())
  42. {
  43. if (!api_is_in_group())
  44. {
  45. // 1. We are inside a course and not in a group.
  46. if (api_is_allowed_to_edit())
  47. {
  48. // 1.1. Teacher
  49. $base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/';
  50. $http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/';
  51. }
  52. else
  53. {
  54. // 1.2. Student
  55. $base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
  56. $http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/shared_folder/'.api_get_user_id().'/';
  57. }
  58. }
  59. else
  60. {
  61. // 2. Inside a course and inside a group.
  62. $base_work_dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
  63. $http_www = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/';
  64. }
  65. }
  66. else
  67. {
  68. if (api_is_platform_admin() && $_SESSION['this_section'] == 'platform_admin')
  69. {
  70. // 3. Platform administration activities.
  71. $base_work_dir = $_configuration['root_sys'].'home/default_platform_document/';
  72. $http_www = $_configuration['root_web'].'home/default_platform_document/';
  73. }
  74. else
  75. {
  76. // 4. The user is outside courses.
  77. $base_work_dir = $_configuration['root_sys'].'main/upload/users/'.api_get_user_id().'/my_files/';
  78. $http_www = $_configuration['root_web'].'main/upload/users/'.api_get_user_id().'/my_files/';
  79. }
  80. }
  81. // Set the upload path according to the resource type.
  82. if ($sType == 'audio')
  83. {
  84. check_and_create_resource_directory($base_work_dir, '/audio', get_lang('Audio'));
  85. $base_work_dir = $base_work_dir.'audio/';
  86. $http_www = $http_www.'audio/';
  87. $path = "/audio/";
  88. }
  89. elseif ($sType == 'flash')
  90. {
  91. check_and_create_resource_directory($base_work_dir, '/flash', get_lang('Flash'));
  92. $base_work_dir = $base_work_dir.'flash/';
  93. $http_www = $http_www.'flash/';
  94. $path = "/flash/";
  95. }
  96. elseif ($sType == 'images')
  97. {
  98. check_and_create_resource_directory($base_work_dir, '/images', get_lang('Images'));
  99. $base_work_dir = $base_work_dir.'images/';
  100. $http_www = $http_www.'images/';
  101. $path = "/images/";
  102. }
  103. elseif ($sType == 'video')
  104. {
  105. check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
  106. $base_work_dir = $base_work_dir.'video/';
  107. $http_www = $http_www.'video/';
  108. $path = "/video/";
  109. }
  110. elseif ($sType == 'video/flv')
  111. {
  112. check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
  113. check_and_create_resource_directory($base_work_dir, '/video/flv', 'flv');
  114. $base_work_dir = $base_work_dir.'video/flv/';
  115. $http_www = $http_www.'video/flv/';
  116. $path = "/video/flv/";
  117. }
  118. $course_dir = $_course['path']."/document/".$sType;
  119. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  120. $dbl_click_id = 0; // used to avoid double-click
  121. $is_allowed_to_edit = api_is_allowed_to_edit();
  122. $req_gid = '';
  123. /*
  124. -----------------------------------------------------------
  125. Libraries
  126. -----------------------------------------------------------
  127. */
  128. //libraries are included by default
  129. include_once(api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php');
  130. include_once(api_get_path(LIBRARY_PATH) . 'document.lib.php');
  131. include_once(api_get_path(LIBRARY_PATH) . 'tablesort.lib.php');
  132. /*
  133. -----------------------------------------------------------
  134. Constants and variables
  135. -----------------------------------------------------------
  136. */
  137. $course_quota = DocumentManager::get_course_quota();
  138. /*
  139. ==============================================================================
  140. MAIN SECTION
  141. ==============================================================================
  142. */
  143. /*
  144. -----------------------------------------------------------
  145. Header
  146. -----------------------------------------------------------
  147. */
  148. $tool_name = get_lang("Doc"); // title of the page (should come from the language file)
  149. ?>
  150. <style type="text/css" media="screen, projection">
  151. /*<![CDATA[*/
  152. @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/public_admin/default.css";
  153. /*]]>*/
  154. </style>
  155. <?php
  156. if(api_get_setting('stylesheets')<>'')
  157. {
  158. ?>
  159. <style type="text/css" media="screen, projection">
  160. /*<![CDATA[*/
  161. @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets');?>/default.css";
  162. /*]]>*/
  163. </style>
  164. <?php
  165. }
  166. $is_allowed_to_edit = api_is_allowed_to_edit();
  167. if($is_allowed_to_edit) // TEACHER ONLY
  168. {
  169. /*======================================
  170. DELETE FILE OR DIRECTORY
  171. ======================================*/
  172. if ( isset($_GET['delete']) )
  173. {
  174. include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  175. if(DocumentManager::delete_document($_course,$_GET['delete'],$base_work_dir))
  176. {
  177. Display::display_normal_message(api_convert_encoding(get_lang('DocDeleted'), 'UTF-8', $charset));
  178. }
  179. else
  180. {
  181. Display::display_normal_message(api_convert_encoding(get_lang('DocDeleteError'), 'UTF-8', $charset));
  182. }
  183. }
  184. if( isset($_POST['action']))
  185. {
  186. switch($_POST['action'])
  187. {
  188. case 'delete':
  189. foreach($_POST['path'] as $index => $path)
  190. {
  191. DocumentManager::delete_document($_course,$path,$base_work_dir);
  192. }
  193. Display::display_normal_message(api_convert_encoding(get_lang('DocDeleted'), 'UTF-8', $charset));
  194. break;
  195. }
  196. }
  197. }
  198. /*
  199. -----------------------------------------------------------
  200. GET ALL DOCUMENT DATA FOR CURDIRPATH
  201. -----------------------------------------------------------
  202. */
  203. $docs_and_folders = getlist ($base_work_dir.'/');
  204. ?>
  205. <?php
  206. if($docs_and_folders)
  207. {
  208. //echo('<pre>');
  209. //print_r($docs_and_folders);
  210. //echo('</pre>');
  211. //*************************************************************************************************
  212. //do we need the title field for the document name or not?
  213. //we get the setting here, so we only have to do it once
  214. $use_document_title = api_get_setting('use_document_title');
  215. //create a sortable table with our data
  216. $sortable_data = array();
  217. while (list ($key, $id) = each($docs_and_folders))
  218. {
  219. // Skip directories.
  220. if ($id['filetype'] != 'file')
  221. {
  222. continue;
  223. }
  224. $row = array ();
  225. //if the item is invisible, wrap it in a span with class invisible
  226. $invisibility_span_open = ($id['visibility']==0)?'<span class="invisible">':'';
  227. $invisibility_span_close = ($id['visibility']==0)?'</span>':'';
  228. //size (or total size of a directory)
  229. $size = $id['filetype']=='folder' ? get_total_folder_size($id['path'],$is_allowed_to_edit) : $id[size];
  230. //get the title or the basename depending on what we're using
  231. if ($use_document_title=='true' AND $id['title']<>'')
  232. {
  233. $document_name=$id['title'];
  234. }
  235. else
  236. {
  237. $document_name=basename($id['path']);
  238. }
  239. //$row[] = $key; //testing
  240. //data for checkbox
  241. /*
  242. if ($is_allowed_to_edit AND count($docs_and_folders)>1)
  243. {
  244. $row[] = $id['path'];
  245. }
  246. */
  247. // icons with hyperlinks
  248. $row[]= '<a href="#" onclick="javascript:OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.build_document_icon_tag($id['filetype'],$id['path']).'</a>';
  249. //document title with hyperlink
  250. $row[] = '<a href="#" onclick="javascript:OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.$id['title'].'</a>';
  251. //comments => display comment under the document name
  252. //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  253. $display_size = format_file_size($size);
  254. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  255. //last edit date
  256. $display_date = format_date(strtotime($id['lastedit_date']));
  257. $row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
  258. $sortable_data[] = $row;
  259. }
  260. //*******************************************************************************************
  261. }
  262. else
  263. {
  264. $sortable_data=array();
  265. //$table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
  266. }
  267. $table = new SortableTableFromArray($sortable_data,4,10);
  268. $query_vars['curdirpath'] = $curdirpath;
  269. if(isset($_SESSION['_gid']))
  270. {
  271. $query_vars['gidReq'] = $_SESSION['_gid'];
  272. }
  273. $table->set_additional_parameters($query_vars);
  274. $column = 0;
  275. /*
  276. if ($is_allowed_to_edit AND count($docs_and_folders)>1)
  277. {
  278. $table->set_header($column++,'',false);
  279. }
  280. */
  281. $table->set_header($column++, api_htmlentities(get_lang('Type'), ENT_QUOTES, $charset));
  282. $table->set_header($column++, api_htmlentities(get_lang('Title'), ENT_QUOTES, $charset));
  283. //$column_header[] = array(get_lang('Comment'),true); => display comment under the document name
  284. $table->set_header($column++, api_htmlentities(get_lang('Size'), ENT_QUOTES, $charset));
  285. $table->set_header($column++, api_htmlentities(get_lang('Date'), ENT_QUOTES, $charset));
  286. //currently only delete action -> take only DELETE right into account
  287. /*
  288. if (count($docs_and_folders)>1)
  289. {
  290. if ($is_allowed_to_edit)
  291. {
  292. $form_actions = array();
  293. $form_action['delete'] = get_lang('Delete');
  294. $table->set_form_actions($form_action,'path');
  295. }
  296. }
  297. */
  298. echo api_convert_encoding($table->get_table_html(), 'UTF-8', $charset);
  299. echo api_convert_encoding($table_footer, 'UTF-8', $charset);
  300. ////////// functions ////////////
  301. ?>
  302. <script type="text/javascript">
  303. <!--
  304. function OpenFile( fileUrl, type )
  305. {
  306. if(type=="audio")
  307. {
  308. ret = confirm('<?php echo api_convert_encoding(get_lang('AutostartMp3'), 'UTF-8', $charset); ?>');
  309. if(ret==true)
  310. {
  311. GetE('autostart').checked = true;
  312. }
  313. else
  314. {
  315. GetE('autostart').checked = false;
  316. }
  317. }
  318. SetUrl( fileUrl ) ;
  319. //window.close() ;
  320. }
  321. //-->
  322. </script>