course_document.inc.php 9.0 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'; moved to autoload
  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. $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'system');
  64. $base_work_dir = $my_path['dir'].'my_files/';
  65. $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web');
  66. $http_www = $my_path['dir'].'my_files/';
  67. }
  68. }
  69. // Set the upload path according to the resource type.
  70. if ($sType == 'audio') {
  71. check_and_create_resource_directory($base_work_dir, '/audio', get_lang('Audio'));
  72. $base_work_dir = $base_work_dir.'audio/';
  73. $http_www = $http_www.'audio/';
  74. $path = "/audio/";
  75. } elseif ($sType == 'flash') {
  76. check_and_create_resource_directory($base_work_dir, '/flash', get_lang('Flash'));
  77. $base_work_dir = $base_work_dir.'flash/';
  78. $http_www = $http_www.'flash/';
  79. $path = "/flash/";
  80. } elseif ($sType == 'images') {
  81. check_and_create_resource_directory($base_work_dir, '/images', get_lang('Images'));
  82. $base_work_dir = $base_work_dir.'images/';
  83. $http_www = $http_www.'images/';
  84. $path = "/images/";
  85. } elseif ($sType == 'video') {
  86. check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
  87. $base_work_dir = $base_work_dir.'video/';
  88. $http_www = $http_www.'video/';
  89. $path = "/video/";
  90. } elseif ($sType == 'video/flv') {
  91. check_and_create_resource_directory($base_work_dir, '/video', get_lang('Video'));
  92. check_and_create_resource_directory($base_work_dir, '/video/flv', 'flv');
  93. $base_work_dir = $base_work_dir.'video/flv/';
  94. $http_www = $http_www.'video/flv/';
  95. $path = "/video/flv/";
  96. }
  97. $course_dir = $_course['path'].'/document/'.$sType;
  98. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  99. $dbl_click_id = 0; // used to avoid double-click
  100. $is_allowed_to_edit = api_is_allowed_to_edit();
  101. $req_gid = '';
  102. /* Constants and variables */
  103. $course_quota = DocumentManager::get_course_quota();
  104. /* MAIN SECTION */
  105. /* Header */
  106. $tool_name = get_lang('Doc'); // Title of the page (should come from the language file)
  107. ?>
  108. <style type="text/css" media="screen, projection">
  109. /*<![CDATA[*/
  110. @import "<?php echo api_get_path(WEB_CSS_PATH); ?>public_admin/default.css";
  111. /*]]>*/
  112. </style>
  113. <?php
  114. if(api_get_setting('stylesheets')<>'')
  115. {
  116. ?>
  117. <style type="text/css" media="screen, projection">
  118. /*<![CDATA[*/
  119. @import "<?php echo api_get_path(WEB_CSS_PATH), api_get_setting('stylesheets'); ?>/default.css";
  120. /*]]>*/
  121. </style>
  122. <?php
  123. }
  124. $is_allowed_to_edit = api_is_allowed_to_edit();
  125. if ($is_allowed_to_edit) { // TEACHER ONLY
  126. /* DELETE FILE OR DIRECTORY */
  127. if (isset($_GET['delete'])) {
  128. if (DocumentManager::delete_document($_course,$_GET['delete'], $base_work_dir)) {
  129. Display::display_normal_message(api_utf8_encode(get_lang('DocDeleted')));
  130. } else {
  131. Display::display_normal_message(api_utf8_encode(get_lang('DocDeleteError')));
  132. }
  133. }
  134. if (isset($_POST['action'])) {
  135. switch ($_POST['action']) {
  136. case 'delete':
  137. foreach ($_POST['path'] as $index => $path) {
  138. DocumentManager::delete_document($_course, $path, $base_work_dir);
  139. }
  140. Display::display_normal_message(api_utf8_encode(get_lang('DocDeleted')));
  141. break;
  142. }
  143. }
  144. }
  145. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  146. $docs_and_folders = getlist ($base_work_dir.'/');
  147. if ($docs_and_folders) {
  148. //create a sortable table with our data
  149. $sortable_data = array();
  150. while (list ($key, $id) = each($docs_and_folders)) {
  151. // Skip directories.
  152. if ($id['filetype'] != 'file') {
  153. continue;
  154. }
  155. $row = array ();
  156. //if the item is invisible, wrap it in a span with class invisible
  157. $invisibility_span_open = ($id['visibility'] == 0) ? '<span class="invisible">' : '';
  158. $invisibility_span_close = ($id['visibility'] == 0) ? '</span>' : '';
  159. //size (or total size of a directory)
  160. $size = $id['filetype'] == 'folder' ? get_total_folder_size($id['path'], $is_allowed_to_edit) : $id[size];
  161. //get the title or the basename depending on what we're using
  162. if ($id['title'] != '') {
  163. $document_name = $id['title'];
  164. } else {
  165. $document_name = basename($id['path']);
  166. }
  167. //$row[] = $key; //testing
  168. //data for checkbox
  169. /*
  170. if ($is_allowed_to_edit AND count($docs_and_folders) > 1) {
  171. $row[] = $id['path'];
  172. }
  173. */
  174. // icons with hyperlinks
  175. $row[]= '<a href="#" onclick="javascript: OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.build_document_icon_tag($id['filetype'],$id['path']).'</a>';
  176. //document title with hyperlink
  177. $row[] = '<a href="#" onclick="javascript: OpenFile(\''.$http_www.'/'.$id['title'].'\', \''.$sType.'\');return false;">'.$id['title'].'</a>';
  178. //comments => display comment under the document name
  179. //$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
  180. $display_size = format_file_size($size);
  181. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  182. //last edit date
  183. $display_date = format_date(strtotime($id['lastedit_date']));
  184. $row[] = '<span style="display:none;">'.$id['lastedit_date'].'</span>'.$invisibility_span_open.$display_date.$invisibility_span_close;
  185. $sortable_data[] = $row;
  186. }
  187. } else {
  188. $sortable_data = array();
  189. //$table_footer='<div style="text-align:center;"><strong>'.get_lang('NoDocsInFolder').'</strong></div>';
  190. }
  191. $table = new SortableTableFromArray($sortable_data, 4, 10);
  192. $query_vars['curdirpath'] = $curdirpath;
  193. if (isset($_SESSION['_gid'])) {
  194. $query_vars['gidReq'] = $_SESSION['_gid'];
  195. }
  196. $table->set_additional_parameters($query_vars);
  197. $column = 0;
  198. /*
  199. if ($is_allowed_to_edit AND count($docs_and_folders) > 1) {
  200. $table->set_header($column++, '', false);
  201. }
  202. */
  203. $table->set_header($column++, api_htmlentities(get_lang('Type'), ENT_QUOTES));
  204. $table->set_header($column++, api_htmlentities(get_lang('Title'), ENT_QUOTES));
  205. //$column_header[] = array(get_lang('Comment'),true); => display comment under the document name
  206. $table->set_header($column++, api_htmlentities(get_lang('Size'), ENT_QUOTES));
  207. $table->set_header($column++, api_htmlentities(get_lang('Date'), ENT_QUOTES));
  208. //currently only delete action -> take only DELETE right into account
  209. /*
  210. if (count($docs_and_folders) > 1) {
  211. if ($is_allowed_to_edit) {
  212. $form_actions = array();
  213. $form_action['delete'] = get_lang('Delete');
  214. $table->set_form_actions($form_action, 'path');
  215. }
  216. }
  217. */
  218. echo api_utf8_encode($table->get_table_html());
  219. echo api_utf8_encode($table_footer);
  220. // Functions
  221. ?>
  222. <script type="text/javascript">
  223. <!--
  224. function OpenFile( fileUrl, type )
  225. {
  226. if (type=="audio")
  227. {
  228. ret = confirm('<?php echo api_utf8_encode(get_lang('AutostartMp3')); ?>');
  229. if (ret)
  230. {
  231. GetE('autostart').checked = true;
  232. }
  233. else
  234. {
  235. GetE('autostart').checked = false;
  236. }
  237. }
  238. SetUrl( fileUrl ) ;
  239. //window.close() ;
  240. }
  241. //-->
  242. </script>