document.php 53 KB

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