course_document.inc.php 9.1 KB

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