document.php 49 KB

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