fck_course_document.inc.php 8.3 KB

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