document.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Homepage script for the documents tool
  5. *
  6. * This script allows the user to manage files and directories on a remote http
  7. * server.
  8. * The user can : - navigate through files and directories.
  9. * - upload a file
  10. * - delete, copy a file or a directory
  11. * - edit properties & content (name, comments, html content)
  12. * The script is organised in four sections.
  13. *
  14. * 1) Execute the command called by the user
  15. * Note: somme commands of this section are organised in two steps.
  16. * The script always begins with the second step,
  17. * so it allows to return more easily to the first step.
  18. *
  19. * Note (March 2004) some editing functions (renaming, commenting)
  20. * are moved to a separate page, edit_document.php. This is also
  21. * where xml and other stuff should be added.
  22. * 2) Define the directory to display
  23. * 3) Read files and directories from the directory defined in part 2
  24. * 4) Display all of that on an HTML page
  25. *
  26. * @todo eliminate code duplication with document/document.php, scormdocument.php
  27. *
  28. * @package chamilo.document
  29. */
  30. /**
  31. * Code
  32. */
  33. // Language files that need to be included
  34. $language_file = array('document', 'slideshow', 'gradebook', 'create_course');
  35. require_once '../inc/global.inc.php';
  36. $this_section = SECTION_COURSES;
  37. require_once 'document.inc.php';
  38. $lib_path = api_get_path(LIBRARY_PATH);
  39. /* Libraries */
  40. require_once $lib_path.'document.lib.php';
  41. require_once $lib_path.'fileUpload.lib.php';
  42. require_once $lib_path.'formvalidator/FormValidator.class.php';
  43. require_once $lib_path.'fileDisplay.lib.php';
  44. require_once $lib_path.'tablesort.lib.php';
  45. api_protect_course_script(true);
  46. //Removing sessions
  47. unset($_SESSION['draw_dir']);
  48. unset($_SESSION['paint_dir']);
  49. // Create directory certificates
  50. DocumentManager::create_directory_certificate_in_course(api_get_course_id());
  51. $course_info = api_get_course_info();
  52. $course_dir = $course_info['path'].'/document';
  53. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  54. $base_work_dir = $sys_course_path.$course_dir;
  55. $http_www = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document';
  56. $dbl_click_id = 0; // Used for avoiding double-click
  57. /* Constants and variables */
  58. $session_id = api_get_session_id();
  59. $course_code = api_get_course_id();
  60. $to_group_id = api_get_group_id();
  61. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  62. $group_member_with_upload_rights = false;
  63. // If the group id is set, we show them group documents
  64. $group_properties = array();
  65. $group_properties['directory'] = null;
  66. // For sessions we should check the parameters of visibility
  67. if (api_get_session_id() != 0) {
  68. $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true);
  69. }
  70. //Setting group variables
  71. if (api_get_group_id()) {
  72. // Needed for group related stuff
  73. require_once $lib_path.'groupmanager.lib.php';
  74. // Get group info
  75. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  76. $noPHP_SELF = true;
  77. // Let's assume the user cannot upload files for the group
  78. $group_member_with_upload_rights = false;
  79. if ($group_properties['doc_state'] == 2) {
  80. // Documents are private
  81. if ($is_allowed_to_edit || GroupManager :: is_user_in_group(api_get_user_id(), api_get_group_id())) {
  82. // Only courseadmin or group members (members + tutors) allowed
  83. $req_gid = '&amp;gidReq='.api_get_group_id();
  84. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  85. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.api_get_group_id(), 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  86. //they are allowed to upload
  87. $group_member_with_upload_rights = true;
  88. } else {
  89. $to_group_id = 0;
  90. $req_gid = '';
  91. }
  92. } elseif ($group_properties['doc_state'] == 1) {
  93. // Documents are public
  94. $to_group_id = api_get_group_id();
  95. $req_gid = '&amp;gidReq='.api_get_group_id();
  96. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  97. $interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.api_get_group_id(), 'name' => get_lang('GroupSpace').' '.$group_properties['name']);
  98. //allowed to upload?
  99. if ($is_allowed_to_edit || GroupManager::is_subscribed(api_get_user_id(), api_get_group_id())) {
  100. // Only courseadmin or group members can upload
  101. $group_member_with_upload_rights = true;
  102. }
  103. } else { // Documents not active for this group
  104. $to_group_id = 0;
  105. $req_gid = '';
  106. }
  107. $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights;
  108. } else {
  109. $_SESSION['group_member_with_upload_rights'] = false;
  110. $to_group_id = 0;
  111. $req_gid = '';
  112. }
  113. //Actions
  114. $document_id = intval($_REQUEST['id']);
  115. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  116. switch ($action) {
  117. case 'download':
  118. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  119. // Check whether the document is in the database
  120. if (empty($document_data)) {
  121. // File not found!
  122. header('HTTP/1.0 404 Not Found');
  123. $error404 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
  124. $error404 .= '<html><head>';
  125. $error404 .= '<title>404 Not Found</title>';
  126. $error404 .= '</head><body>';
  127. $error404 .= '<h1>Not Found</h1>';
  128. $error404 .= '<p>The requested URL was not found on this server.</p>';
  129. $error404 .= '<hr>';
  130. $error404 .= '</body></html>';
  131. echo $error404;
  132. exit;
  133. }
  134. // Launch event
  135. event_download($document_data['url']);
  136. // Check visibility of document and paths
  137. if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id())) {
  138. api_not_allowed(true);
  139. }
  140. $full_file_name = $base_work_dir.$document_data['path'];
  141. if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
  142. DocumentManager::file_send_for_download($full_file_name, true);
  143. }
  144. exit;
  145. break;
  146. case 'downloadfolder' :
  147. if (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) {
  148. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  149. //filter when I am into shared folder, I can donwload only my shared folder
  150. if (is_any_user_shared_folder($document_data['path'], $session_id)) {
  151. if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $session_id) || api_is_allowed_to_edit() || api_is_platform_admin()){
  152. require 'downloadfolder.inc.php';
  153. }
  154. } else {
  155. require 'downloadfolder.inc.php';
  156. }
  157. exit;
  158. }
  159. break;
  160. case 'export_to_pdf' :
  161. if (api_get_setting('students_export2pdf') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) {
  162. DocumentManager::export_to_pdf($document_id, $course_code);
  163. }
  164. break;
  165. }
  166. // I'm in the certification module?
  167. $is_certificate_mode = DocumentManager::is_certificate_mode($_GET['curdirpath']);
  168. //If no actions we proceed to show the document (Hack in order to use document.php?id=X)
  169. if (isset($document_id)) {
  170. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  171. //If the document is not a folder we show the document
  172. if ($document_data) {
  173. $parent_id = $document_data['parent_id'];
  174. //$visibility = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  175. $visibility = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id());
  176. if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
  177. if ($visibility && api_is_allowed_to_session_edit()) {
  178. $url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();
  179. header("Location: $url");
  180. }
  181. exit;
  182. } else {
  183. if (!$visibility && !api_is_allowed_to_edit()) {
  184. api_not_allowed();
  185. }
  186. }
  187. $_GET['curdirpath'] = $document_data['path'];
  188. }
  189. // What's the current path?
  190. // We will verify this a bit further down
  191. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  192. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  193. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  194. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  195. } else {
  196. $curdirpath = '/';
  197. }
  198. $curdirpathurl = urlencode($curdirpath);
  199. } else {
  200. // What's the current path?
  201. // We will verify this a bit further down
  202. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  203. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  204. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  205. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  206. } else {
  207. $curdirpath = '/';
  208. }
  209. $curdirpathurl = urlencode($curdirpath);
  210. // Check the path
  211. // If the path is not found (no document id), set the path to /
  212. $document_id = DocumentManager::get_document_id($course_info, $curdirpath);
  213. if (!$document_id) {
  214. $document_id = DocumentManager::get_document_id($course_info, $curdirpath);
  215. }
  216. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  217. $parent_id = $document_data['parent_id'];
  218. }
  219. if (!$parent_id) {
  220. $parent_id = 0;
  221. }
  222. $current_folder_id = $document_id;
  223. // Show preview
  224. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) {
  225. if (isset($_GET['set_preview'])) {
  226. // Generate document HTML
  227. $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), true);
  228. $new_content_html = $content_html;
  229. $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
  230. $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
  231. $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document';
  232. $new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
  233. $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
  234. echo '<style media="print" type="text/css"> #print_div { visibility:hidden; } </style>';
  235. echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="../img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
  236. print_r($new_content_html);
  237. exit;
  238. }
  239. }
  240. // Is the document tool visible?
  241. // Check whether the tool is actually visible
  242. $table_course_tool = Database::get_course_table(TABLE_TOOL_LIST, $_course['dbName']);
  243. $tool_sql = 'SELECT visibility FROM ' . $table_course_tool . ' WHERE name = "'. TOOL_DOCUMENT .'" LIMIT 1';
  244. $tool_result = Database::query($tool_sql);
  245. $tool_row = Database::fetch_array($tool_result);
  246. $tool_visibility = $tool_row['visibility'];
  247. if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights)) {
  248. api_not_allowed(true);
  249. }
  250. $htmlHeadXtra[] =
  251. "<script type=\"text/javascript\">
  252. function confirmation (name) {
  253. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  254. {return true;}
  255. else
  256. {return false;}
  257. }
  258. </script>";
  259. // If they are looking at group documents they can't see the root
  260. if ($to_group_id != 0 && $curdirpath == '/') {
  261. $curdirpath = $group_properties['directory'];
  262. $curdirpathurl = urlencode($group_properties['directory']);
  263. }
  264. // Check visibility of the current dir path. Don't show anything if not allowed
  265. //@todo check this validation for coaches
  266. //if (!$is_allowed_to_edit || api_is_coach()) { before
  267. if (!$is_allowed_to_edit && api_is_coach()) {
  268. if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $_course, api_get_session_id(),'folder'))) {
  269. api_not_allowed(true);
  270. }
  271. }
  272. /* Create shared folders */
  273. if ($session_id == 0) {
  274. //Create shared folder. Necessary for courses recycled. Allways session_id should be zero. Allway should be created from a base course, never from a session.
  275. if (!file_exists($base_work_dir.'/shared_folder')) {
  276. $usf_dir_title = get_lang('UserFolders');
  277. $usf_dir_name = '/shared_folder';
  278. $to_group_id = 0;
  279. $visibility = 0;
  280. create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
  281. }
  282. // Create dynamic user shared folder
  283. if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) {
  284. $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']);
  285. $usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id();
  286. $to_group_id = 0;
  287. $visibility = 1;
  288. create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
  289. }
  290. } else {
  291. //Create shared folder session
  292. if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id)) {
  293. $usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($session_id).')';
  294. $usf_dir_name = '/shared_folder_session_'.$session_id;
  295. $to_group_id = 0;
  296. $visibility = 0;
  297. create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
  298. }
  299. //Create dynamic user shared folder into a shared folder session
  300. if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id())) {
  301. $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']).' ('.api_get_session_name($session_id).')';
  302. $usf_dir_name = '/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id();
  303. $to_group_id = 0;
  304. $visibility = 1;
  305. create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
  306. }
  307. }
  308. /* MAIN SECTION */
  309. // Slideshow inititalisation
  310. $_SESSION['image_files_only'] = '';
  311. $image_files_only = '';
  312. /* Header */
  313. if ($is_certificate_mode) {
  314. $interbreadcrumb[]= array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook'));
  315. } else {
  316. if ((isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath']) || isset($_GET['createdir'])) {
  317. $interbreadcrumb[]= array('url' => 'document.php', 'name' => get_lang('Documents'));
  318. } else {
  319. $interbreadcrumb[]= array('url' => '#', 'name' => get_lang('Documents'));
  320. }
  321. }
  322. // Interbreadcrumb for the current directory root path
  323. if (empty($document_data['parents'])) {
  324. if (isset($_GET['createdir'])) {
  325. $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
  326. } else {
  327. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  328. }
  329. } else {
  330. foreach($document_data['parents'] as $document_sub_data) {
  331. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  332. $document_sub_data['document_url'] = '#';
  333. }
  334. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  335. }
  336. }
  337. if (isset($_GET['createdir'])) {
  338. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateDir'));
  339. }
  340. $htmlHeadXtra[] = api_get_jquery_ui_js();
  341. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  342. /*
  343. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'yoxview/yox.js"></script>';
  344. $htmlHeadXtra[] = api_get_js('yoxview/yoxview-init.js');
  345. */
  346. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
  347. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  348. $mediaplayer_path = api_get_path(WEB_LIBRARY_PATH).'mediaplayer/player.swf';
  349. //automatic loading the course language for yoxview
  350. /*$yoxview_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  351. $lang_yoxview = api_get_language_isocode();
  352. $lang_yoxview = isset($yoxview_code_translation_table[$lang_yoxview]) ? $yoxview_code_translation_table[$lang_yoxview] : $lang_yoxview;
  353. */
  354. $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, false);
  355. $file_list = $format_list = '';
  356. $count = 1;
  357. if (!empty($docs_and_folders))
  358. foreach ($docs_and_folders as $file) {
  359. if ($file['filetype'] == 'file') {
  360. $path_info = pathinfo($file['path']);
  361. $extension = strtolower($path_info['extension']);
  362. //@todo use a js loop to autogenerate this code
  363. if (in_array($extension, array('ogg', 'mp3', 'wav'))) {
  364. $document_data = DocumentManager::get_document_data_by_id($file['id'], api_get_course_id());
  365. if ($extension == 'ogg') {
  366. $extension = 'oga';
  367. }
  368. $jquery .= ' $("#jquery_jplayer_'.$count.'").jPlayer({
  369. ready: function() {
  370. $(this).jPlayer("setMedia", {
  371. '.$extension.' : "'.$document_data['direct_url'].'"
  372. });
  373. },
  374. swfPath: "'.$js_path.'jquery-jplayer",
  375. supplied: "mp3, m4a, oga, ogv, wav",
  376. solution: "flash, html", // Do not change this setting otherwise
  377. cssSelectorAncestor: "#jp_interface_'.$count.'",
  378. });'."\n\n";
  379. $count++;
  380. }
  381. }
  382. }
  383. $htmlHeadXtra[] = '<script type="text/javascript">
  384. $(document).ready( function() {
  385. /*
  386. $(".yoxview").yoxview({
  387. lang: "'.$lang_yoxview.'",
  388. flashVideoPlayerPath: "'.$mediaplayer_path.'",
  389. allowInternalLinks:true,
  390. defaultDimensions: { iframe: { width: 800}},
  391. });*/
  392. //Experimental changes to preview mp3, ogg files
  393. '.$jquery.'
  394. //Keep this down otherwise the jquery player will not work
  395. for (i=0;i<$(".actions").length;i++) {
  396. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  397. $(".actions:eq("+i+")").hide();
  398. }
  399. }
  400. });
  401. </script>';
  402. Display::display_header('','Doc');
  403. // Lib for event log, stats & tracking & record of the access
  404. event_access_tool(TOOL_DOCUMENT);
  405. /* DISPLAY */
  406. if ($to_group_id != 0) { // Add group name after for group documents
  407. $add_group_to_title = ' ('.$group_properties['name'].')';
  408. }
  409. /* Introduction section (editable by course admins) */
  410. if (!empty($_SESSION['_gid'])) {
  411. Display::display_introduction_section(TOOL_DOCUMENT.$_SESSION['_gid']);
  412. } else {
  413. Display::display_introduction_section(TOOL_DOCUMENT);
  414. }
  415. // ACTION MENU
  416. // Copy a file to general my files user's
  417. if (isset($_GET['action']) && $_GET['action'] == 'copytomyfiles' && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0) {
  418. $clean_get_id = Security::remove_XSS($_GET['id']);
  419. $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'system');
  420. $user_folder = $my_path['dir'].'my_files/';
  421. $my_path = null;
  422. if (!file_exists($user_folder)) {
  423. $perm = api_get_permissions_for_new_directories();
  424. @mkdir($user_folder, $perm, true);
  425. }
  426. $file = $sys_course_path.$_course['path'].'/document'.$clean_get_id;
  427. $copyfile = $user_folder.basename($clean_get_id);
  428. if (file_exists($copyfile)) {
  429. $message = get_lang('CopyAlreadyDone').'</p><p>'.'<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'">'.get_lang("No").'</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$curdirpath.'&amp;action=copytomyfiles&amp;id='.$clean_get_id.'&amp;copy=yes">'.get_lang('Yes').'</a></p>';
  430. if (!isset($_GET['copy'])){
  431. Display::display_warning_message($message,false);
  432. }
  433. if (Security::remove_XSS($_GET['copy']) == 'yes'){
  434. if (!copy($file, $copyfile)) {
  435. Display::display_error_message(get_lang('CopyFailed'));
  436. } else {
  437. Display::display_confirmation_message(get_lang('OverwritenFile'));
  438. }
  439. }
  440. } else {
  441. if (!copy($file, $copyfile)) {
  442. Display::display_error_message(get_lang('CopyFailed'));
  443. } else {
  444. Display::display_confirmation_message(get_lang('CopyMade'));
  445. }
  446. }
  447. }
  448. /* MOVE FILE OR DIRECTORY */
  449. //Only teacher and all users into their group and each user into his/her shared folder
  450. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($_POST['move_to']), $session_id)) {
  451. if (isset($_GET['move']) && $_GET['move'] != '') {
  452. $my_get_move = intval($_REQUEST['move']);
  453. if (api_is_coach()) {
  454. if (!DocumentManager::is_visible_by_id($my_get_move, $course_info, api_get_session_id(), api_get_user_id())) {
  455. api_not_allowed();
  456. }
  457. }
  458. if (!$is_allowed_to_edit) {
  459. if (DocumentManager::check_readonly($_course, api_get_user_id(), $my_get_move)) {
  460. api_not_allowed();
  461. }
  462. }
  463. $document_to_move = DocumentManager::get_document_data_by_id($my_get_move, api_get_course_id());
  464. $move_path = $document_to_move['path'];
  465. if (!empty($document_to_move)) {
  466. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
  467. //filter if is my shared folder. TODO: move this code to build_move_to_selector function
  468. if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) && !$is_allowed_to_edit){
  469. $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();//only main user shared folder
  470. $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//';//all subfolders
  471. $user_shared_folders=array();
  472. foreach($folders as $fold){
  473. if($main_user_shared_folder_main==$fold || preg_match($main_user_shared_folder_sub, $fold)){
  474. $user_shared_folders[]=$fold;
  475. }
  476. }
  477. echo '<div class="row"><div class="form_header">'.get_lang('Move').'</div></div>';
  478. echo build_move_to_selector($user_shared_folders, $move_path, $my_get_move, $group_properties['directory']);
  479. } else {
  480. echo '<div class="row"><div class="form_header">'.get_lang('Move').'</div></div>';
  481. echo build_move_to_selector($folders, $move_path, $my_get_move, $group_properties['directory']);
  482. }
  483. }
  484. }
  485. if (isset($_POST['move_to']) && isset($_POST['move_file'])) {
  486. if (!$is_allowed_to_edit) {
  487. if (DocumentManager::check_readonly($_course, api_get_user_id(), $_POST['move_file'])) {
  488. api_not_allowed();
  489. }
  490. }
  491. if (api_is_coach()) {
  492. if (!DocumentManager::is_visible_by_id($_POST['move_file'], $_course, api_get_session_id(), api_get_user_id())) {
  493. api_not_allowed();
  494. }
  495. }
  496. $document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id());
  497. require_once $lib_path.'fileManage.lib.php';
  498. // This is needed for the update_db_info function
  499. //$dbTable = $_course['dbNameGlu'].'document';
  500. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  501. // Security fix: make sure they can't move files that are not in the document table
  502. if (!empty($document_to_move)) {
  503. $real_path_target = $base_work_dir.$_POST['move_to'].'/'.basename($document_to_move['path']);
  504. $fileExist=false;
  505. if(file_exists($real_path_target)){
  506. $fileExist=true;
  507. }
  508. if (move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) {
  509. //if (1) {
  510. //$contents = DocumentManager::replace_urls_inside_content_html_when_moving_file(basename($document_to_move['path']), $base_work_dir.dirname($document_to_move['path']), $base_work_dir.$_POST['move_to']);
  511. //exit;
  512. update_db_info('update', $document_to_move['path'], $_POST['move_to'].'/'.basename($document_to_move['path']));
  513. //update database item property
  514. $doc_id=$_POST['move_file'];
  515. if(is_dir($real_path_target)){
  516. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderMoved', api_get_user_id(),$to_group_id,null,null,null,$session_id);
  517. Display::display_confirmation_message(get_lang('DirMv'));
  518. }
  519. elseif(is_file($real_path_target)){
  520. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentMoved', api_get_user_id(),$to_group_id,null,null,null,$session_id);
  521. Display::display_confirmation_message(get_lang('DocMv'));
  522. }
  523. // Set the current path
  524. $curdirpath = $_POST['move_to'];
  525. $curdirpathurl = urlencode($_POST['move_to']);
  526. } else {
  527. if($fileExist){
  528. if(is_dir($real_path_target)){
  529. Display::display_error_message(get_lang('DirExists'));
  530. }
  531. elseif(is_file($real_path_target)){
  532. Display::display_error_message(get_lang('FileExists'));
  533. }
  534. }
  535. else{
  536. Display::display_error_message(get_lang('Impossible'));
  537. }
  538. }
  539. } else {
  540. Display::display_error_message(get_lang('Impossible'));
  541. }
  542. }
  543. }
  544. /* DELETE FILE OR DIRECTORY */
  545. //Only teacher and all users into their group
  546. if($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)){
  547. if (isset($_GET['delete'])) {
  548. if (!$is_allowed_to_edit) {
  549. if (api_is_coach()) {
  550. if (!DocumentManager::is_visible($_GET['delete'], $_course, api_get_session_id())) {
  551. api_not_allowed();
  552. }
  553. }
  554. if (DocumentManager::check_readonly($_course, api_get_user_id(), $_GET['delete'], '', true)) {
  555. api_not_allowed();
  556. }
  557. }
  558. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  559. if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
  560. if ( isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(intval($_GET['delete_certificate_id']))) {
  561. $default_certificate_id = $_GET['delete_certificate_id'];
  562. DocumentManager::remove_attach_certificate(api_get_course_id(), $default_certificate_id);
  563. }
  564. Display::display_confirmation_message(get_lang('DocDeleted'));
  565. } else {
  566. Display::display_error_message(get_lang('DocDeleteError'));
  567. }
  568. }
  569. if (isset($_POST['action'])) {
  570. switch ($_POST['action']) {
  571. case 'delete':
  572. foreach ($_POST['path'] as $index => & $path) {
  573. if (!$is_allowed_to_edit) {
  574. if (DocumentManager::check_readonly($_course, api_get_user_id(), $path)) {
  575. Display::display_error_message(get_lang('CantDeleteReadonlyFiles'));
  576. break 2;
  577. }
  578. }
  579. }
  580. foreach ($_POST['path'] as $index => & $path) {
  581. if (in_array($path, array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates'))) {
  582. continue;
  583. } else {
  584. $delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir);
  585. }
  586. }
  587. if (!empty($delete_document)) {
  588. Display::display_confirmation_message(get_lang('DocDeleted'));
  589. }
  590. break;
  591. }
  592. }
  593. }
  594. /* CREATE DIRECTORY */
  595. //Only teacher and all users into their group and any user into his/her shared folder
  596. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
  597. // Create directory with $_POST data
  598. if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
  599. // Needed for directory creation
  600. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  601. $post_dir_name = $_POST['dirname'];
  602. if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
  603. Display::display_error_message(get_lang('CannotCreateDir'));
  604. } else {
  605. if (!empty($_POST['dir_id'])) {
  606. $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
  607. $curdirpath = $document_data['path'];
  608. }
  609. $added_slash = ($curdirpath == '/') ? '' : '/';
  610. $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
  611. $dir_name = disable_dangerous_file($dir_name);
  612. $dir_name = str_replace('.', '_', $dir_name);
  613. //@todo why the folder name can't have a dot. It's just the folder name
  614. $post_dir_name = str_replace('.', '_', $post_dir_name);
  615. $dir_check = $base_work_dir.$dir_name;
  616. if (!is_dir($dir_check)) {
  617. $created_dir = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
  618. if ($created_dir) {
  619. Display::display_confirmation_message('<span title="'.$created_dir.'">'.get_lang('DirCr').'</span>', false);
  620. // Uncomment if you want to enter the created dir
  621. //$curdirpath = $created_dir;
  622. //$curdirpathurl = urlencode($curdirpath);
  623. } else {
  624. Display::display_error_message(get_lang('CannotCreateDir'));
  625. }
  626. } else {
  627. Display::display_error_message(get_lang('CannotCreateDir'));
  628. }
  629. }
  630. }
  631. // Show them the form for the directory name
  632. if (isset($_GET['createdir'])) {
  633. echo create_dir_form($document_id);
  634. }
  635. }
  636. /* VISIBILITY COMMANDS */
  637. //Only teacher
  638. if ($is_allowed_to_edit) {
  639. if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) && $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*') {
  640. // Make visible or invisible?
  641. if (isset($_GET['set_visible'])) {
  642. $update_id = intval($_GET['set_visible']);
  643. $visibility_command = 'visible';
  644. } else {
  645. $update_id = intval($_GET['set_invisible']);
  646. $visibility_command = 'invisible';
  647. }
  648. if (!$is_allowed_to_edit) {
  649. if (api_is_coach()) {
  650. if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id(), api_get_user_id())) {
  651. api_not_allowed();
  652. }
  653. }
  654. if (DocumentManager::check_readonly($_course, api_get_user_id(), '', $update_id)) {
  655. api_not_allowed();
  656. }
  657. }
  658. // Update item_property to change visibility
  659. if (api_item_property_update($_course, TOOL_DOCUMENT, $update_id, $visibility_command, api_get_user_id(), null, null, null, null, $session_id)) {
  660. Display::display_confirmation_message(get_lang('VisibilityChanged'));//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all)
  661. } else {
  662. Display::display_error_message(get_lang('ViModProb'));
  663. }
  664. }
  665. }
  666. /* TEMPLATE ACTION */
  667. //Only teacher and all users into their group
  668. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)){
  669. if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
  670. $document_id_for_template = intval($_GET['add_as_template']);
  671. // Create the form that asks for the directory name
  672. $template_text = '<form name="set_document_as_new_template" enctype="multipart/form-data" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
  673. $template_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  674. $template_text .= '<table><tr><td>';
  675. $template_text .= get_lang('TemplateName').' : </td>';
  676. $template_text .= '<td><input type="text" name="template_title" /></td></tr>';
  677. //$template_text .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
  678. //$template_text .= '<td><textarea name="template_description"></textarea></td></tr>';
  679. $template_text .= '<tr><td>'.get_lang('TemplateImage').' : </td>';
  680. $template_text .= '<td><input type="file" name="template_image" id="template_image" /></td></tr>';
  681. $template_text .= '</table>';
  682. $template_text .= '<button type="submit" class="add" name="create_template">'.get_lang('CreateTemplate').'</button>';
  683. $template_text .= '</form>';
  684. // Show the form
  685. Display::display_normal_message($template_text, false);
  686. } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
  687. $document_id_for_template = intval(Database::escape_string($_GET['add_as_template']));
  688. $title = Security::remove_XSS($_POST['template_title']);
  689. //$description = Security::remove_XSS($_POST['template_description']);
  690. $user_id = api_get_user_id();
  691. // Create the template_thumbnails folder in the upload folder (if needed)
  692. if (!is_dir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/')) {
  693. @mkdir(api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/', api_get_permissions_for_new_directories());
  694. }
  695. // Upload the file
  696. if (!empty($_FILES['template_image']['name'])) {
  697. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  698. $upload_ok = process_uploaded_file($_FILES['template_image']);
  699. if ($upload_ok) {
  700. // Try to add an extension to the file if it hasn't one
  701. $new_file_name = $_course['sysCode'].'-'.add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
  702. // Upload dir
  703. $upload_dir = api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/';
  704. // Resize image to max default and end upload
  705. $temp = new Image($_FILES['template_image']['tmp_name']);
  706. $picture_info = $temp->get_image_info();
  707. $max_width_for_picture = 100;
  708. if ($picture_info['width'] > $max_width_for_picture) {
  709. $thumbwidth = $max_width_for_picture;
  710. if (empty($thumbwidth) || $thumbwidth == 0) {
  711. $thumbwidth = $max_width_for_picture;
  712. }
  713. $new_height = round(($thumbwidth/$picture_info['width'])*$picture_info['height']);
  714. $temp->resize($thumbwidth, $new_height, 0);
  715. }
  716. $temp->send_image($upload_dir.$new_file_name);
  717. }
  718. }
  719. DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $new_file_name);
  720. Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
  721. }
  722. if (isset($_GET['remove_as_template'])) {
  723. $document_id_for_template = intval($_GET['remove_as_template']);
  724. $user_id = api_get_user_id();
  725. DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
  726. Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
  727. }
  728. }
  729. // END ACTION MENU
  730. // Attach certificate in the gradebook
  731. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_certificate']) && $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))) {
  732. if (isset($_GET['cidReq'])) {
  733. $course_id = Security::remove_XSS($_GET['cidReq']); // course id
  734. $document_id = Security::remove_XSS($_GET['set_certificate']); // document id
  735. DocumentManager::attach_gradebook_certificate ($course_id,$document_id);
  736. Display::display_normal_message(get_lang('IsDefaultCertificate'));
  737. }
  738. }
  739. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  740. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  741. $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, true);
  742. } else {
  743. $docs_and_folders = DocumentManager::get_all_document_data($_course, $curdirpath, $to_group_id, null, $is_allowed_to_edit || $group_member_with_upload_rights, false);
  744. }
  745. $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
  746. if ($folders === false) {
  747. $folders = array();
  748. }
  749. echo '<div class="actions">';
  750. //if ($is_allowed_to_edit || $group_member_with_upload_rights){
  751. /* BUILD SEARCH FORM */
  752. echo '<span style="display:inline-block;">';
  753. $form = new FormValidator('search_document', 'get', '', '', null, false);
  754. $renderer = & $form->defaultRenderer();
  755. $renderer->setElementTemplate('<span>{element}</span> ');
  756. $form->add_textfield('keyword', '', false);
  757. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  758. $form->display();
  759. echo '</span>';
  760. //}
  761. /* GO TO PARENT DIRECTORY */
  762. if ($curdirpath!= '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
  763. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
  764. echo Display::display_icon('folder_up.png', get_lang('Up'),'','32');
  765. echo '</a>';
  766. }
  767. if ($is_certificate_mode && $curdirpath != '/certificates') {
  768. ?>
  769. <a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq();?>&amp;curdirpath=<?php echo urlencode((dirname($curdirpath) == '\\') ? '/' : dirname($curdirpath)).$req_gid; ?>">
  770. <?php Display::display_icon('folder_up.png', get_lang('Up'),'','32'); ?></a>
  771. <?php
  772. }
  773. $table_footer = '';
  774. $total_size = 0;
  775. if (isset($docs_and_folders) && is_array($docs_and_folders)) {
  776. // Do we need the title field for the document name or not?
  777. // We get the setting here, so we only have to do it once
  778. $use_document_title = api_get_setting('use_document_title');
  779. // Create a sortable table with our data
  780. $sortable_data = array();
  781. $count = 1;
  782. foreach ($docs_and_folders as $key => $document_data) {
  783. $row = array();
  784. $row['id'] = $document_data['id'];
  785. $row['type'] = $document_data['filetype'];
  786. // If the item is invisible, wrap it in a span with class invisible
  787. $is_visible = DocumentManager::is_visible_by_id($document_data['id'], $course_info, api_get_session_id(), api_get_user_id(), false);
  788. $invisibility_span_open = ($is_visible == 0) ? '<span class="invisible">' : '';
  789. $invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
  790. // Size (or total size of a directory)
  791. $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
  792. // Get the title or the basename depending on what we're using
  793. if ($use_document_title == 'true' && $document_data['title'] != '') {
  794. $document_name = $document_data['title'];
  795. } else {
  796. $document_name = basename($document_data['path']);
  797. }
  798. $row['name'] = $document_name;
  799. // Data for checkbox
  800. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  801. $row[] = $document_data['path'];
  802. }
  803. // Hide HotPotatoes Certificates and all css folders
  804. if ($document_data['path']=='/HotPotatoes_files' || $document_data['path']=='/certificates' || basename($document_data['path'])=='css'){
  805. continue;
  806. }
  807. //Admin setting for Hide/Show the folders of all users
  808. if (api_get_setting('show_users_folders') == 'false' && ($document_data['path']=='/shared_folder' || strstr($document_data['path'], 'shared_folder_session_'))){
  809. continue;
  810. }
  811. //Admin setting for Hide/Show Default folders to all users
  812. if (api_get_setting('show_default_folders') == 'false' && ($document_data['path']=='/images' || $document_data['path']=='/flash' || $document_data['path']=='/audio' || $document_data['path']=='/video')){
  813. continue;
  814. }
  815. //Admin setting for Hide/Show chat history folder
  816. if (api_get_setting('show_chat_folder') == 'false' && $document_data['path']=='/chat_files'){
  817. continue;
  818. }
  819. // Show the owner of the file only in groups
  820. $user_link = '';
  821. if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
  822. if (!empty($document_data['insert_user_id'])) {
  823. $user_info = UserManager::get_user_info_by_id($document_data['insert_user_id']);
  824. $user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
  825. $user_link = '<div class="document_owner">'.get_lang('Owner').': '.display_user_link_document($document_data['insert_user_id'], $user_name).'</div>';
  826. }
  827. }
  828. // Icons (clickable)
  829. $row[] = create_document_link($document_data, true, $count, $is_visible);
  830. $path_info = pathinfo($document_data['path']);
  831. if (isset($path_info['extension']) && in_array($path_info['extension'], array('ogg', 'mp3','wav'))) {
  832. $count ++;
  833. }
  834. // Validacion when belongs to a session
  835. $session_img = api_get_session_image($document_data['session_id'], $_user['status']);
  836. // Document title with link
  837. $row[] = create_document_link($document_data, false, null, $is_visible).$session_img.'<br />'.$invisibility_span_open.'<i>'.nl2br(htmlspecialchars($document_data['comment'],ENT_QUOTES,$charset)).'</i>'.$invisibility_span_close.$user_link;
  838. // Comments => display comment under the document name
  839. $display_size = format_file_size($size);
  840. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  841. // Last edit date
  842. $last_edit_date = $document_data['lastedit_date'];
  843. $last_edit_date = api_get_local_time($last_edit_date, null, date_default_timezone_get());
  844. //$display_date = date_to_str_ago($last_edit_date).'<br /><span class="dropbox_date">'.api_format_date($last_edit_date).'</span>';
  845. $display_date = date_to_str_ago($last_edit_date);
  846. $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
  847. // Admins get an edit column
  848. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
  849. $is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
  850. // If readonly, check if it the owner of the file or if the user is an admin
  851. if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
  852. $edit_icons = build_edit_icons($document_data, $key, $is_template, 0, $is_visible);
  853. } else {
  854. $edit_icons = build_edit_icons($document_data, $key, $is_template, $document_data['readonly'], $is_visible);
  855. }
  856. $row[] = $edit_icons;
  857. }
  858. $row[] = $last_edit_date;
  859. $row[] = $size;
  860. $row[] = $document_name;
  861. $total_size = $total_size + $size;
  862. if ((isset($_GET['keyword']) && search_keyword($document_name, $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
  863. $sortable_data[] = $row;
  864. }
  865. }
  866. } else {
  867. $sortable_data = '';
  868. $table_footer = get_lang('NoDocsInFolder');
  869. }
  870. $column_show = array();
  871. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
  872. // TODO:check enable more options for shared folders
  873. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  874. // Create new document
  875. if (!$is_certificate_mode) {
  876. ?>
  877. <a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
  878. <?php Display::display_icon('new_document.png', get_lang('CreateDoc'),'','32'); ?></a>
  879. <?php
  880. // Create new draw
  881. if (api_get_setting('enabled_support_svg') == 'true') {
  882. if (api_browser_support('svg')) {
  883. ?>
  884. <a href="create_draw.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
  885. <?php Display::display_icon('new_draw.png', get_lang('Draw'),'','32'); ?></a>&nbsp;
  886. <?php
  887. } else {
  888. Display::display_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'),'','32');
  889. }
  890. }
  891. // Create new paint
  892. if (api_get_setting('enabled_support_pixlr') == 'true'){
  893. ?>
  894. <a href="create_paint.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
  895. <?php Display::display_icon('new_paint.png', get_lang('PhotoRetouching'),'','32'); ?></a>
  896. <?php
  897. }
  898. // Record new audio
  899. if (api_get_setting('enable_nanogong') == 'true') {
  900. ?>
  901. <a href="record_audio.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
  902. <?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'),'',32); ?></a>
  903. <?php
  904. }
  905. // Create new audio
  906. if (api_get_setting('enabled_text2audio') == 'true'){
  907. ?>
  908. <a href="create_audio.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
  909. <?php Display::display_icon('new_sound.png', get_lang('CreateAudio'),'','32'); ?></a>
  910. <?php
  911. }
  912. }
  913. // Create new certificate
  914. if ($is_certificate_mode) {
  915. ?>
  916. <a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>&certificate=true&<?php echo 'selectcat='.Security::remove_XSS($_GET['selectcat']); ?>">
  917. <?php Display::display_icon('new_certificate.png', get_lang('CreateCertificate'),'','32'); ?></a>
  918. <?php
  919. }
  920. // File upload link
  921. if ($is_certificate_mode) {
  922. echo '<a href="upload.php?'.api_get_cidreq().'&id='.$current_folder_id.$req_gid.'">';
  923. echo Display::display_icon('upload_certificate.png', get_lang('UploadCertificate'),'','32').'</a>';
  924. } else {
  925. echo '<a href="upload.php?'.api_get_cidreq().'&id='.$current_folder_id.$req_gid.'">';
  926. echo Display::display_icon('upload_file.png', get_lang('UplUploadDocument'),'','32').'</a>';
  927. }
  928. // Create directory
  929. if (!$is_certificate_mode) {
  930. ?>
  931. <a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>&createdir=1">
  932. <?php Display::display_icon('new_folder.png', get_lang('CreateDir'),'','32'); ?></a>
  933. <?php
  934. }
  935. }
  936. if (!is_null($docs_and_folders)) {
  937. // Show download zipped folder icon
  938. global $total_size;
  939. if (!$is_certificate_mode && $total_size != 0 && (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())) {
  940. //for student does not show icon into other shared folder, and does not show into main path (root)
  941. if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) && $curdirpath!='/' || api_is_allowed_to_edit() || api_is_platform_admin()) {
  942. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=downloadfolder&amp;id='.$document_id.'">'.Display::return_icon('save_pack.png', get_lang('Save').' (ZIP)','','32').'</a>';
  943. }
  944. }
  945. }
  946. // Slideshow by Patrick Cool, May 2004
  947. require 'document_slideshow.inc.php';
  948. if ($image_present && !isset($_GET['keyword']) ) {
  949. echo '<a href="slideshow.php?'.api_get_cidreq().'&amp;curdirpath='.$curdirpathurl.'">'.Display::return_icon('slideshow.png', get_lang('ViewSlideshow'),'','32').'</a>';
  950. }
  951. echo '</div>';
  952. if (!$is_certificate_mode) {
  953. echo build_directory_selector($folders, $curdirpath, (isset($group_properties['directory']) ? $group_properties['directory'] : array()), true);
  954. }
  955. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  956. $column_show[] = 1;
  957. }
  958. $column_show[] = 1;
  959. $column_show[] = 1;
  960. $column_show[] = 1;
  961. $column_show[] = 1;
  962. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
  963. $column_show[] = 1;
  964. }
  965. $column_show[] = 0;
  966. $column_show[] = 0;
  967. $column_order = array();
  968. if (count($row) == 12) {
  969. //teacher
  970. $column_order[2] = 8; //name
  971. $column_order[3] = 7;
  972. $column_order[4] = 6;
  973. } elseif (count($row) == 10) {
  974. //student
  975. $column_order[1] = 6;
  976. $column_order[2] = 5;
  977. $column_order[3] = 4;
  978. }
  979. $default_column = $is_allowed_to_edit ? 2 : 1;
  980. $tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
  981. //var_dump($column_show,$column_order);
  982. $table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC', true);
  983. if(isset($_GET['keyword'])) {
  984. $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
  985. }else{
  986. $query_vars['curdirpath'] = $curdirpath;
  987. }
  988. if (api_get_group_id()) {
  989. $query_vars['gidReq'] = api_get_group_id();
  990. }
  991. $query_vars['cidReq'] = api_get_course_id();
  992. $table->set_additional_parameters($query_vars);
  993. $column = 0;
  994. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  995. $table->set_header($column++, '', false, array('style' => 'width:12px;'));
  996. }
  997. $table->set_header($column++, get_lang('Type'),true, array('style' => 'width:30px;'));
  998. $table->set_header($column++, get_lang('Name'));
  999. $table->set_header($column++, get_lang('Size'),true, array('style' => 'width:50px;'));
  1000. $table->set_header($column++, get_lang('Date'),true, array('style' => 'width:105px;'));
  1001. // Admins get an edit column
  1002. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
  1003. $table->set_header($column++, get_lang('Actions'), false, array ('style' => 'width:160px;'));
  1004. }
  1005. // Actions on multiple selected documents
  1006. // TODO: Currently only delete action -> take only DELETE right into account
  1007. if (count($docs_and_folders) > 1) {
  1008. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1009. $form_actions = array();
  1010. $form_action['delete'] = get_lang('Delete');
  1011. $table->set_form_actions($form_action, 'path');
  1012. }
  1013. }
  1014. $table->display();
  1015. if (count($docs_and_folders) > 1) {
  1016. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1017. // Getting the course quota
  1018. $course_quota = DocumentManager::get_course_quota();
  1019. // Calculating the total space
  1020. $already_consumed_space = DocumentManager::documents_total_space($_course);
  1021. // Displaying the quota
  1022. DocumentManager::display_simple_quota($course_quota, $already_consumed_space);
  1023. }
  1024. }
  1025. if (!empty($table_footer)) {
  1026. Display::display_warning_message($table_footer);
  1027. }
  1028. // Footer
  1029. Display::display_footer();