document.php 52 KB

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