document.php 55 KB

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