fck_course_document.inc.php 8.2 KB

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