document.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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. * @package chamilo.document
  27. */
  28. use \ChamiloSession as Session;
  29. // Language files that need to be included
  30. $language_file = array('document', 'slideshow', 'gradebook', 'create_course');
  31. require_once '../inc/global.inc.php';
  32. $current_course_tool = TOOL_DOCUMENT;
  33. $this_section = SECTION_COURSES;
  34. $to_user_id = null;
  35. $parent_id = null;
  36. $message = null;
  37. require_once 'document.inc.php';
  38. $lib_path = api_get_path(LIBRARY_PATH);
  39. /* Libraries */
  40. require_once $lib_path.'fileUpload.lib.php';
  41. require_once $lib_path.'fileDisplay.lib.php';
  42. require_once $lib_path.'fileManage.lib.php';
  43. api_protect_course_script(true);
  44. DocumentManager::removeGeneratedAudioTempFile();
  45. if (isset($_SESSION['temp_realpath_image'])
  46. && !empty($_SESSION['temp_realpath_image'])
  47. && is_file($_SESSION['temp_realpath_image'])) {
  48. unlink($_SESSION['temp_realpath_image']);
  49. }
  50. $courseInfo = api_get_course_info();
  51. $course_dir = $courseInfo['directory'].'/document';
  52. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  53. $base_work_dir = $sys_course_path.$course_dir;
  54. $http_www = api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/document';
  55. $document_path = $base_work_dir;
  56. //Removing sessions
  57. unset($_SESSION['draw_dir']);
  58. unset($_SESSION['paint_dir']);
  59. unset($_SESSION['temp_audio_nanogong']);
  60. $plugin = new AppPlugin();
  61. $pluginList = $plugin->get_installed_plugins();
  62. $capturePluginInstalled = in_array('jcapture', $pluginList);
  63. if ($capturePluginInstalled) {
  64. $jcapturePath = api_get_path(WEB_PLUGIN_PATH).'jcapture/plugin_applet.php';
  65. $htmlHeadXtra[] = '<script>
  66. $(function() {
  67. function insertAtCarret() {
  68. }
  69. $("#jcapture").click(function(){
  70. $("#appletplace").load("'.$jcapturePath.'");
  71. });
  72. });
  73. </script>';
  74. }
  75. // Create directory certificates.
  76. DocumentManager::create_directory_certificate_in_course(api_get_course_id());
  77. if (empty($courseInfo)) {
  78. api_not_allowed(true);
  79. }
  80. // Used for avoiding double-click.
  81. $dbl_click_id = 0;
  82. $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
  83. $moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null;
  84. /* Constants and variables */
  85. $userId = api_get_user_id();
  86. $userInfo = api_get_user_info();
  87. $sessionId = api_get_session_id();
  88. $course_code = api_get_course_id();
  89. $groupId = api_get_group_id();
  90. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  91. $group_member_with_upload_rights = false;
  92. // If the group id is set, we show them group documents
  93. $group_properties = array();
  94. $group_properties['directory'] = null;
  95. // For sessions we should check the parameters of visibility
  96. if (api_get_session_id() != 0) {
  97. $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true);
  98. }
  99. // Setting group variables.
  100. if (!empty($groupId)) {
  101. // Get group info
  102. $group_properties = GroupManager::get_group_properties($groupId);
  103. // Let's assume the user cannot upload files for the group
  104. $group_member_with_upload_rights = false;
  105. if ($group_properties['doc_state'] == 2) {
  106. // Documents are private
  107. if ($is_allowed_to_edit || GroupManager::is_user_in_group($userId, $groupId)) {
  108. // Only courseadmin or group members (members + tutors) allowed
  109. $interbreadcrumb[] = array(
  110. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  111. 'name' => get_lang('Groups')
  112. );
  113. $interbreadcrumb[] = array(
  114. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  115. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  116. );
  117. //they are allowed to upload
  118. $group_member_with_upload_rights = true;
  119. } else {
  120. $groupId = 0;
  121. }
  122. } elseif ($group_properties['doc_state'] == 1) {
  123. // Documents are public
  124. $interbreadcrumb[] = array(
  125. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  126. 'name' => get_lang('Groups')
  127. );
  128. $interbreadcrumb[] = array(
  129. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  130. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  131. );
  132. //allowed to upload?
  133. if ($is_allowed_to_edit || GroupManager::is_subscribed($userId, $groupId)) {
  134. // Only courseadmin or group members can upload
  135. $group_member_with_upload_rights = true;
  136. }
  137. }
  138. $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights;
  139. } else {
  140. $_SESSION['group_member_with_upload_rights'] = false;
  141. }
  142. // Actions.
  143. $document_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  144. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  145. $currentUrl = api_get_self().'?'.api_get_cidreq().'&id='.$document_id;
  146. if (Portfolio::controller()->accept()) {
  147. Portfolio::controller()->run();
  148. }
  149. switch ($action) {
  150. case 'delete_item':
  151. if ($is_allowed_to_edit ||
  152. $group_member_with_upload_rights ||
  153. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ||
  154. is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId)
  155. ) {
  156. if (isset($_GET['deleteid'])) {
  157. if (!$is_allowed_to_edit) {
  158. if (api_is_coach()) {
  159. if (!DocumentManager::is_visible_by_id(
  160. $_GET['deleteid'],
  161. $courseInfo,
  162. $sessionId,
  163. api_get_user_id())
  164. ) {
  165. api_not_allowed();
  166. }
  167. }
  168. if (DocumentManager::check_readonly(
  169. $courseInfo,
  170. api_get_user_id(),
  171. '',
  172. $_GET['deleteid'],
  173. true)
  174. ) {
  175. api_not_allowed();
  176. }
  177. }
  178. $documentInfo = DocumentManager::get_document_data_by_id(
  179. $_GET['deleteid'],
  180. $courseInfo['code'],
  181. false,
  182. $sessionId
  183. );
  184. // Check whether the document is in the database.
  185. if (!empty($documentInfo)) {
  186. $deleteDocument = DocumentManager::delete_document(
  187. $courseInfo,
  188. null,
  189. $base_work_dir,
  190. $sessionId,
  191. $_GET['deleteid'],
  192. $groupId
  193. );
  194. if ($deleteDocument) {
  195. $certificateId = isset($_GET['delete_certificate_id']) ? $_GET['delete_certificate_id'] : null;
  196. DocumentManager::remove_attach_certificate(api_get_course_id(), $certificateId);
  197. $message = Display::return_message(get_lang('DocDeleted').': '.$documentInfo['path'], 'success');
  198. } else {
  199. $message = Display::return_message(get_lang('DocDeleteError'), 'warning');
  200. }
  201. } else {
  202. $message = Display::return_message(get_lang('FileNotFound'), 'warning');
  203. }
  204. Session::write('message', $message);
  205. header("Location: $currentUrl");
  206. exit;
  207. }
  208. }
  209. break;
  210. case 'download':
  211. // Get the document data from the ID
  212. $document_data = DocumentManager::get_document_data_by_id(
  213. $document_id,
  214. api_get_course_id(),
  215. false,
  216. $sessionId
  217. );
  218. if ($sessionId != 0 && !$document_data) {
  219. // If there is a session defined and asking for the document *from
  220. // the session* didn't work, try it from the course (out of a
  221. // session context)
  222. $document_data = DocumentManager::get_document_data_by_id(
  223. $document_id,
  224. api_get_course_id(),
  225. false,
  226. 0
  227. );
  228. }
  229. // Check whether the document is in the database
  230. if (empty($document_data)) {
  231. api_not_allowed();
  232. }
  233. // Launch event
  234. event_download($document_data['url']);
  235. // Check visibility of document and paths
  236. if (!($is_allowed_to_edit || $group_member_with_upload_rights)
  237. && !DocumentManager::is_visible_by_id($document_id, $courseInfo, $sessionId, api_get_user_id())) {
  238. api_not_allowed(true);
  239. }
  240. $full_file_name = $base_work_dir.$document_data['path'];
  241. if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
  242. DocumentManager::file_send_for_download($full_file_name, true);
  243. }
  244. exit;
  245. break;
  246. case 'downloadfolder':
  247. if (api_get_setting('students_download_folders') == 'true'
  248. || api_is_allowed_to_edit()
  249. || api_is_platform_admin()) {
  250. // Get the document data from the ID
  251. $document_data = DocumentManager::get_document_data_by_id(
  252. $document_id,
  253. api_get_course_id(),
  254. false,
  255. $sessionId
  256. );
  257. if ($sessionId != 0 && !$document_data) {
  258. // If there is a session defined and asking for the
  259. // document * from the session* didn't work, try it from the
  260. // course (out of a session context)
  261. $document_data = DocumentManager::get_document_data_by_id(
  262. $document_id,
  263. api_get_course_id(),
  264. false,
  265. 0
  266. );
  267. }
  268. //filter when I am into shared folder, I can download only my shared folder
  269. if (is_any_user_shared_folder($document_data['path'], $sessionId)) {
  270. if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $sessionId)
  271. || api_is_allowed_to_edit()
  272. || api_is_platform_admin()) {
  273. require 'downloadfolder.inc.php';
  274. }
  275. } else {
  276. require 'downloadfolder.inc.php';
  277. }
  278. // Launch event
  279. event_download($document_data['url']);
  280. exit;
  281. }
  282. break;
  283. case 'export_to_pdf':
  284. if (api_get_setting('students_export2pdf') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) {
  285. DocumentManager::export_to_pdf($document_id, $course_code);
  286. }
  287. break;
  288. case 'copytomyfiles':
  289. // Copy a file to general my files user's
  290. if (api_get_setting('allow_social_tool') == 'true' &&
  291. api_get_setting('users_copy_files') == 'true'
  292. && api_get_user_id() != 0
  293. && !api_is_anonymous()
  294. ) {
  295. // Get the document data from the ID
  296. $document_info = DocumentManager::get_document_data_by_id(
  297. $document_id,
  298. api_get_course_id(),
  299. true,
  300. $sessionId
  301. );
  302. if ($sessionId != 0 && !$document_info) {
  303. /* If there is a session defined and asking for the document
  304. from the session didn't work, try it from the course
  305. (out of a session context)*/
  306. $document_info = DocumentManager::get_document_data_by_id(
  307. $document_id,
  308. api_get_course_id(),
  309. true,
  310. 0
  311. );
  312. }
  313. $parent_id = $document_info['parent_id'];
  314. $my_path = UserManager::get_user_picture_path_by_id(
  315. api_get_user_id(),
  316. 'system'
  317. );
  318. $user_folder = $my_path['dir'].'my_files/';
  319. $my_path = null;
  320. if (!file_exists($user_folder)) {
  321. $perm = api_get_permissions_for_new_directories();
  322. @mkdir($user_folder, $perm, true);
  323. }
  324. $file = $sys_course_path.$courseInfo['directory'].'/document'.$document_info['path'];
  325. $copyfile = $user_folder.basename($document_info['path']);
  326. $cidReq = Security::remove_XSS($_GET['cidReq']);
  327. $id_session = Security::remove_XSS($_GET['id_session']);
  328. $gidReq = Security::remove_XSS($_GET['gidReq']);
  329. $id = Security::remove_XSS($_GET['id']);
  330. if (empty($parent_id)) {
  331. $parent_id = 0;
  332. }
  333. $file_link = Display::url(
  334. get_lang('SeeFile'),
  335. api_get_path(WEB_CODE_PATH).'social/myfiles.php?'.
  336. 'cidReq='.$cidReq.'&amp;id_session='.$id_session.'&amp;'.
  337. 'gidReq='.$gidReq.'&amp;parent_id='.$parent_id
  338. );
  339. if (file_exists($copyfile)) {
  340. $message = get_lang('CopyAlreadyDone').'</p><p>';
  341. $message .= '<a class = "btn" '.
  342. 'href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$parent_id.'">'.
  343. get_lang("No").
  344. '</a>'.
  345. '&nbsp;&nbsp;|&nbsp;&nbsp;'.
  346. '<a class = "btn" href="'.api_get_self().'?'.
  347. api_get_cidreq().'&amp;action=copytomyfiles&amp;id='.$document_info['id'].
  348. '&amp;copy=yes">'.
  349. get_lang('Yes').
  350. '</a></p>';
  351. if (!isset($_GET['copy'])) {
  352. $message = Display::return_message($message, 'warning', false);
  353. }
  354. if (Security::remove_XSS($_GET['copy']) == 'yes') {
  355. if (!copy($file, $copyfile)) {
  356. $message = Display::return_message(get_lang('CopyFailed'), 'error');
  357. } else {
  358. $message = Display::return_message(
  359. get_lang('OverwritenFile').' '.$file_link,
  360. 'confirmation',
  361. false
  362. );
  363. }
  364. }
  365. } else {
  366. if (!copy($file, $copyfile)) {
  367. $message = Display::return_message(get_lang('CopyFailed'), 'error');
  368. } else {
  369. $message = Display::return_message(get_lang('CopyMade').' '.$file_link, 'confirmation', false);
  370. }
  371. }
  372. Session::write('message', $message);
  373. }
  374. break;
  375. }
  376. // I'm in the certification module?
  377. $is_certificate_mode = false;
  378. if (isset($_GET['curdirpath'])) {
  379. $is_certificate_mode = DocumentManager::is_certificate_mode($_GET['curdirpath']);
  380. }
  381. if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
  382. $is_certificate_mode = true;
  383. }
  384. // If no actions we proceed to show the document (Hack in order to use document.php?id=X)
  385. if (isset($document_id) && empty($action)) {
  386. // Get the document data from the ID
  387. $document_data = DocumentManager::get_document_data_by_id(
  388. $document_id,
  389. api_get_course_id(),
  390. true,
  391. $sessionId
  392. );
  393. if ($sessionId != 0 && !$document_data) {
  394. // If there is a session defined and asking for the
  395. // document * from the session* didn't work, try it from the course
  396. // (out of a session context)
  397. $document_data = DocumentManager::get_document_data_by_id(
  398. $document_id,
  399. api_get_course_id(),
  400. true,
  401. 0
  402. );
  403. }
  404. // If the document is not a folder we show the document.
  405. if ($document_data) {
  406. $parent_id = $document_data['parent_id'];
  407. $visibility = DocumentManager::check_visibility_tree(
  408. $document_id,
  409. api_get_course_id(),
  410. $sessionId,
  411. api_get_user_id(),
  412. $groupId
  413. );
  414. if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
  415. if ($visibility && api_is_allowed_to_session_edit()) {
  416. $url = api_get_path(WEB_COURSE_PATH).
  417. $courseInfo['path'].'/document'.$document_data['path'].'?'
  418. .api_get_cidreq();
  419. header("Location: $url");
  420. }
  421. exit;
  422. } else {
  423. if (!$visibility && !api_is_allowed_to_edit()) {
  424. api_not_allowed();
  425. }
  426. }
  427. $_GET['curdirpath'] = $document_data['path'];
  428. }
  429. // What's the current path?
  430. // We will verify this a bit further down
  431. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  432. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  433. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  434. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  435. } else {
  436. $curdirpath = '/';
  437. }
  438. $curdirpathurl = urlencode($curdirpath);
  439. } else {
  440. // What's the current path?
  441. // We will verify this a bit further down
  442. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  443. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  444. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  445. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  446. } else {
  447. $curdirpath = '/';
  448. }
  449. $curdirpathurl = urlencode($curdirpath);
  450. // Check the path
  451. // If the path is not found (no document id), set the path to /
  452. $document_id = DocumentManager::get_document_id($courseInfo, $curdirpath);
  453. if (!$document_id) {
  454. $document_id = DocumentManager::get_document_id($courseInfo, $curdirpath);
  455. }
  456. $document_data = DocumentManager::get_document_data_by_id(
  457. $document_id,
  458. api_get_course_id(),
  459. true
  460. );
  461. $parent_id = $document_data['parent_id'];
  462. }
  463. if (isset($document_data) && $document_data['path'] == '/certificates') {
  464. $is_certificate_mode = true;
  465. }
  466. if (!$parent_id) {
  467. $parent_id = 0;
  468. }
  469. $current_folder_id = $document_id;
  470. // Show preview
  471. if (isset($_GET['curdirpath']) &&
  472. $_GET['curdirpath'] == '/certificates' &&
  473. isset($_GET['set_preview']) &&
  474. $_GET['set_preview'] == strval(intval($_GET['set_preview']))
  475. ) {
  476. if (isset($_GET['set_preview'])) {
  477. // Generate document HTML
  478. $content_html = DocumentManager::replace_user_info_into_html(
  479. api_get_user_id(),
  480. api_get_course_id(),
  481. true
  482. );
  483. $filename = 'certificate_preview/'.api_get_unique_id().'.png';
  484. $qr_code_filename = api_get_path(SYS_ARCHIVE_PATH).$filename;
  485. $temp_folder = api_get_path(SYS_ARCHIVE_PATH).'certificate_preview';
  486. if (!is_dir($temp_folder)) {
  487. mkdir($temp_folder, api_get_permissions_for_new_directories());
  488. }
  489. $qr_code_web_filename = api_get_path(WEB_ARCHIVE_PATH).$filename;
  490. $certificate = new Certificate();
  491. $text = $certificate->parse_certificate_variables($content_html['variables']);
  492. $result = $certificate->generate_qr($text, $qr_code_filename);
  493. $new_content_html = $content_html['content'];
  494. $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
  495. $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
  496. $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document';
  497. $new_content_html = str_replace(
  498. '/main/default_course_document',
  499. $path_image_in_default_course,
  500. $new_content_html
  501. );
  502. $new_content_html = str_replace(
  503. '/main/img/',
  504. api_get_path(WEB_IMG_PATH),
  505. $new_content_html
  506. );
  507. Display::display_reduced_header();
  508. echo '<style>body {background:none;}</style>
  509. <style media="print" type="text/css"> #print_div { visibility:hidden; } </style>';
  510. echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div">
  511. <img src="../img/printmgr.gif" alt="'.get_lang('Print').'"/>'.get_lang('Print').'</a>';
  512. if (is_file($qr_code_filename) && is_readable($qr_code_filename)) {
  513. $new_content_html = str_replace(
  514. '((certificate_barcode))',
  515. Display::img($qr_code_web_filename),
  516. $new_content_html
  517. );
  518. }
  519. print_r($new_content_html);
  520. exit;
  521. }
  522. }
  523. // Is the document tool visible?
  524. // Check whether the tool is actually visible
  525. $table_course_tool = Database::get_course_table(TABLE_TOOL_LIST);
  526. $course_id = api_get_course_int_id();
  527. $tool_sql = 'SELECT visibility FROM '.$table_course_tool.
  528. ' WHERE c_id = '.$course_id.' AND name = "'.TOOL_DOCUMENT.'" LIMIT 1';
  529. $tool_result = Database::query($tool_sql);
  530. $tool_row = Database::fetch_array($tool_result);
  531. $tool_visibility = $tool_row['visibility'];
  532. if ($tool_visibility == '0' && $groupId == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights)) {
  533. api_not_allowed(true);
  534. }
  535. $htmlHeadXtra[] = "<script>
  536. function confirmation (name) {
  537. if (confirm(\" ".get_lang("AreYouSureToDelete")." \"+ name + \" ?\")) {
  538. return true;
  539. } else {
  540. return false;
  541. }
  542. }
  543. </script>";
  544. // If they are looking at group documents they can't see the root
  545. if ($groupId != 0 && $curdirpath == '/') {
  546. $curdirpath = $group_properties['directory'];
  547. $curdirpathurl = urlencode($group_properties['directory']);
  548. }
  549. // Check visibility of the current dir path. Don't show anything if not allowed
  550. //@todo check this validation for coaches
  551. //if (!$is_allowed_to_edit || api_is_coach()) { before
  552. if (!$is_allowed_to_edit && api_is_coach()) {
  553. if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $courseInfo, $sessionId, 'folder'))) {
  554. api_not_allowed(true);
  555. }
  556. }
  557. /* Create shared folders */
  558. if ($sessionId == 0) {
  559. //Create shared folder. Necessary for recycled courses.
  560. // session_id should always be zero and should always be created from a
  561. // base course, never from a session.
  562. if (!file_exists($base_work_dir.'/shared_folder')) {
  563. $usf_dir_title = get_lang('UserFolders');
  564. $usf_dir_name = '/shared_folder';
  565. $groupId = 0;
  566. $visibility = 0;
  567. create_unexisting_directory(
  568. $courseInfo,
  569. api_get_user_id(),
  570. $sessionId,
  571. $groupId,
  572. $to_user_id,
  573. $base_work_dir,
  574. $usf_dir_name,
  575. $usf_dir_title,
  576. $visibility
  577. );
  578. }
  579. // Create dynamic user shared folder
  580. if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.$userId)) {
  581. $usf_dir_title = $userInfo['complete_name'];
  582. $usf_dir_name = '/shared_folder/sf_user_'.$userId;
  583. $groupId = 0;
  584. $visibility = 1;
  585. create_unexisting_directory(
  586. $courseInfo,
  587. api_get_user_id(),
  588. $sessionId,
  589. $groupId,
  590. $to_user_id,
  591. $base_work_dir,
  592. $usf_dir_name,
  593. $usf_dir_title,
  594. $visibility
  595. );
  596. }
  597. } else {
  598. // Create shared folder session.
  599. if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId)) {
  600. $usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($sessionId).')';
  601. $usf_dir_name = '/shared_folder_session_'.$sessionId;
  602. $groupId = 0;
  603. $visibility = 0;
  604. create_unexisting_directory(
  605. $courseInfo,
  606. api_get_user_id(),
  607. $sessionId,
  608. $groupId,
  609. $to_user_id,
  610. $base_work_dir,
  611. $usf_dir_name,
  612. $usf_dir_title,
  613. $visibility
  614. );
  615. }
  616. //Create dynamic user shared folder into a shared folder session
  617. if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId.'/sf_user_'.$userId)) {
  618. $usf_dir_title = $userInfo['complete_name'].'('.api_get_session_name($sessionId).')';
  619. $usf_dir_name = '/shared_folder_session_'.$sessionId.'/sf_user_'.$userId;
  620. $groupId = 0;
  621. $visibility = 1;
  622. create_unexisting_directory(
  623. $courseInfo,
  624. $userId,
  625. $sessionId,
  626. $groupId,
  627. $to_user_id,
  628. $base_work_dir,
  629. $usf_dir_name,
  630. $usf_dir_title,
  631. $visibility
  632. );
  633. }
  634. }
  635. /* MAIN SECTION */
  636. // Slideshow inititalisation
  637. $_SESSION['image_files_only'] = '';
  638. $image_files_only = '';
  639. if ($is_certificate_mode) {
  640. $interbreadcrumb[] = array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook'));
  641. } else {
  642. if ((isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath']) || isset($_GET['createdir'])) {
  643. $interbreadcrumb[] = array('url' => 'document.php', 'name' => get_lang('Documents'));
  644. } else {
  645. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Documents'));
  646. }
  647. }
  648. // Interbreadcrumb for the current directory root path
  649. if (empty($document_data['parents'])) {
  650. if (isset($_GET['createdir'])) {
  651. $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
  652. } else {
  653. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  654. }
  655. } else {
  656. $counter = 0;
  657. foreach ($document_data['parents'] as $document_sub_data) {
  658. //fixing double group folder in breadcrumb
  659. if ($groupId) {
  660. if ($counter == 0) {
  661. $counter++;
  662. continue;
  663. }
  664. }
  665. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  666. $document_sub_data['document_url'] = '#';
  667. }
  668. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  669. $counter++;
  670. }
  671. }
  672. if (isset($_GET['createdir'])) {
  673. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateDir'));
  674. }
  675. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  676. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
  677. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  678. $mediaplayer_path = api_get_path(WEB_LIBRARY_PATH).'mediaplayer/player.swf';
  679. $documentAndFolders = DocumentManager::get_all_document_data(
  680. $courseInfo,
  681. $curdirpath,
  682. $groupId,
  683. null,
  684. $is_allowed_to_edit || $group_member_with_upload_rights,
  685. false
  686. );
  687. $count = 1;
  688. $jquery = null;
  689. if (!empty($documentAndFolders)) {
  690. foreach ($documentAndFolders as $file) {
  691. if ($file['filetype'] == 'file') {
  692. $path_info = pathinfo($file['path']);
  693. $extension = strtolower($path_info['extension']);
  694. //@todo use a js loop to auto generate this code
  695. if (in_array($extension, array('ogg', 'mp3', 'wav'))) {
  696. // Get the document data from the ID
  697. $document_data = DocumentManager::get_document_data_by_id(
  698. $file['id'],
  699. api_get_course_id(),
  700. false,
  701. $sessionId
  702. );
  703. if ($sessionId != 0 && !$document_data) {
  704. /* If there is a session defined and asking for the document
  705. * from the session* didn't work, try it from the
  706. course (out of a session context) */
  707. $document_data = DocumentManager::get_document_data_by_id(
  708. $file['id'],
  709. api_get_course_id(),
  710. false,
  711. 0
  712. );
  713. }
  714. if ($extension == 'ogg') {
  715. $extension = 'oga';
  716. }
  717. $params = array('url' => $document_data['direct_url'],
  718. 'extension' => $extension,
  719. 'count' => $count
  720. );
  721. $jquery .= DocumentManager::generate_jplayer_jquery($params);
  722. $count++;
  723. }
  724. }
  725. }
  726. }
  727. $htmlHeadXtra[] = '<script>
  728. $(document).ready( function() {
  729. //Experimental changes to preview mp3, ogg files
  730. '.$jquery.'
  731. });
  732. </script>';
  733. // Lib for event log, stats & tracking & record of the access
  734. event_access_tool(TOOL_DOCUMENT);
  735. /* DISPLAY */
  736. if ($groupId != 0) { // Add group name after for group documents
  737. $add_group_to_title = ' ('.$group_properties['name'].')';
  738. }
  739. $moveForm = null;
  740. /* MOVE FILE OR DIRECTORY */
  741. //Only teacher and all users into their group and each user into his/her shared folder
  742. if ($is_allowed_to_edit ||
  743. $group_member_with_upload_rights ||
  744. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ||
  745. is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId)
  746. ) {
  747. if (isset($_GET['move']) && $_GET['move'] != '') {
  748. $my_get_move = intval($_REQUEST['move']);
  749. if (api_is_coach()) {
  750. if (!DocumentManager::is_visible_by_id($my_get_move, $courseInfo, $sessionId, api_get_user_id())) {
  751. api_not_allowed(true);
  752. }
  753. }
  754. if (!$is_allowed_to_edit) {
  755. if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $my_get_move)) {
  756. api_not_allowed(true);
  757. }
  758. }
  759. // Get the document data from the ID
  760. $document_to_move = DocumentManager::get_document_data_by_id(
  761. $my_get_move,
  762. api_get_course_id(),
  763. false,
  764. $sessionId
  765. );
  766. $move_path = $document_to_move['path'];
  767. if (!empty($document_to_move)) {
  768. $folders = DocumentManager::get_all_document_folders(
  769. $courseInfo,
  770. $groupId,
  771. $is_allowed_to_edit || $group_member_with_upload_rights
  772. );
  773. // filter if is my shared folder. TODO: move this code to build_move_to_selector function
  774. if (is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) && !$is_allowed_to_edit) {
  775. //only main user shared folder
  776. $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();
  777. $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//'; //all subfolders
  778. $user_shared_folders = array();
  779. foreach ($folders as $fold) {
  780. if ($main_user_shared_folder_main == $fold || preg_match($main_user_shared_folder_sub, $fold)) {
  781. $user_shared_folders[] = $fold;
  782. }
  783. }
  784. $moveForm .= '<legend>'.get_lang('Move').'</legend>';
  785. $moveForm .= build_move_to_selector(
  786. $user_shared_folders,
  787. $move_path,
  788. $my_get_move,
  789. $group_properties['directory']
  790. );
  791. } else {
  792. $moveForm .= '<legend>'.get_lang('Move').'</legend>';
  793. $moveForm .= build_move_to_selector($folders, $move_path, $my_get_move, $group_properties['directory']);
  794. }
  795. }
  796. }
  797. if (!empty($moveTo) && isset($_POST['move_file'])) {
  798. if (!$is_allowed_to_edit) {
  799. if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), $_POST['move_file'])) {
  800. api_not_allowed(true);
  801. }
  802. }
  803. if (api_is_coach()) {
  804. if (!DocumentManager::is_visible_by_id($_POST['move_file'], $courseInfo, $sessionId, api_get_user_id())) {
  805. api_not_allowed(true);
  806. }
  807. }
  808. // Get the document data from the ID
  809. $document_to_move = DocumentManager::get_document_data_by_id(
  810. $_POST['move_file'],
  811. api_get_course_id(),
  812. false,
  813. $sessionId
  814. );
  815. // Security fix: make sure they can't move files that are not in the document table
  816. if (!empty($document_to_move)) {
  817. $real_path_target = $base_work_dir.$moveTo.'/'.basename($document_to_move['path']);
  818. $fileExist = false;
  819. if (file_exists($real_path_target)) {
  820. $fileExist = true;
  821. }
  822. if (move($base_work_dir.$document_to_move['path'], $base_work_dir.$moveTo)) {
  823. update_db_info('update', $document_to_move['path'], $moveTo.'/'.basename($document_to_move['path']));
  824. //update database item property
  825. $doc_id = $_POST['move_file'];
  826. if (is_dir($real_path_target)) {
  827. api_item_property_update(
  828. $courseInfo,
  829. TOOL_DOCUMENT,
  830. $doc_id,
  831. 'FolderMoved',
  832. api_get_user_id(),
  833. $groupId,
  834. null,
  835. null,
  836. null,
  837. $sessionId
  838. );
  839. $message = Display::return_message(get_lang('DirMv'), 'confirmation');
  840. } elseif (is_file($real_path_target)) {
  841. api_item_property_update(
  842. $courseInfo,
  843. TOOL_DOCUMENT,
  844. $doc_id,
  845. 'DocumentMoved',
  846. api_get_user_id(),
  847. $groupId,
  848. null,
  849. null,
  850. null,
  851. $sessionId
  852. );
  853. $message = Display::return_message(get_lang('DocMv'), 'confirmation');
  854. }
  855. // Set the current path
  856. $curdirpath = $_POST['move_to'];
  857. $curdirpathurl = urlencode($_POST['move_to']);
  858. } else {
  859. if ($fileExist) {
  860. if (is_dir($real_path_target)) {
  861. $message = Display::return_message(get_lang('DirExists'), 'error');
  862. } elseif (is_file($real_path_target)) {
  863. $message = Display::return_message(get_lang('FileExists'), 'v');
  864. }
  865. } else {
  866. $message = Display::return_message(get_lang('Impossible'), 'error');
  867. }
  868. }
  869. } else {
  870. $message = Display::return_message(get_lang('Impossible'), 'error');
  871. }
  872. Session::write('message', $message);
  873. }
  874. }
  875. /* DELETE FILE OR DIRECTORY */
  876. //Only teacher and all users into their group
  877. if ($is_allowed_to_edit ||
  878. $group_member_with_upload_rights ||
  879. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  880. ) {
  881. if (isset($_POST['action']) && isset($_POST['ids'])) {
  882. $files = $_POST['ids'];
  883. $readonlyAlreadyChecked = false;
  884. $messages = null;
  885. foreach ($files as $documentId) {
  886. $items = array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates');
  887. $data = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
  888. if (in_array($data['path'], $items)) {
  889. // exclude system directories (do not allow deletion)
  890. continue;
  891. } else {
  892. switch ($_POST['action']) {
  893. case 'set_invisible':
  894. $visibilityCommand = 'invisible';
  895. if (api_item_property_update(
  896. $courseInfo,
  897. TOOL_DOCUMENT,
  898. $documentId,
  899. $visibilityCommand,
  900. api_get_user_id(),
  901. null,
  902. null,
  903. null,
  904. null,
  905. $sessionId
  906. )) {
  907. $messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['path'], 'confirmation');
  908. } else {
  909. $messages .= Display::return_message(get_lang('ViModProb'), 'error');
  910. }
  911. break;
  912. case 'set_visible':
  913. $visibilityCommand = 'visible';
  914. if (api_item_property_update(
  915. $courseInfo,
  916. TOOL_DOCUMENT,
  917. $documentId,
  918. $visibilityCommand,
  919. api_get_user_id(),
  920. null,
  921. null,
  922. null,
  923. null,
  924. $sessionId
  925. )) {
  926. $messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['path'], 'confirmation');
  927. } else {
  928. $messages .= Display::return_message(get_lang('ViModProb'), 'error');
  929. }
  930. break;
  931. case 'delete':
  932. // Check all documents scheduled for deletion
  933. // If one of them is read-only, abandon deletion
  934. // Note: this is only executed once
  935. if (!$readonlyAlreadyChecked) {
  936. foreach ($files as $id) {
  937. if (!$is_allowed_to_edit) {
  938. if (DocumentManager::check_readonly(
  939. $courseInfo,
  940. api_get_user_id(),
  941. null,
  942. $id,
  943. false,
  944. $sessionId
  945. )
  946. ) {
  947. $messages .= Display::return_message(get_lang('CantDeleteReadonlyFiles'), 'error');
  948. break 2;
  949. }
  950. }
  951. }
  952. $readonlyAlreadyChecked = true;
  953. }
  954. $deleteDocument = DocumentManager::delete_document(
  955. $courseInfo,
  956. null,
  957. $base_work_dir,
  958. $sessionId,
  959. $documentId,
  960. $groupId
  961. );
  962. if (!empty($deleteDocument)) {
  963. $messages .= Display::return_message(get_lang('DocDeleted').': '.$data['path'], 'confirmation');
  964. }
  965. break;
  966. }
  967. }
  968. } // endforeach
  969. Session::write('message', $messages);
  970. }
  971. }
  972. $dirForm = null;
  973. /* CREATE DIRECTORY */
  974. //Only teacher and all users into their group and any user into his/her shared folder
  975. if ($is_allowed_to_edit ||
  976. $group_member_with_upload_rights ||
  977. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  978. ) {
  979. // Create directory with $_POST data
  980. if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
  981. // Needed for directory creation
  982. $post_dir_name = $_POST['dirname'];
  983. if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
  984. $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
  985. } else {
  986. if (!empty($_POST['dir_id'])) {
  987. // Get the document data from the ID
  988. $document_data = DocumentManager::get_document_data_by_id(
  989. $_POST['dir_id'],
  990. api_get_course_id(),
  991. false,
  992. $sessionId
  993. );
  994. if ($sessionId != 0 && !$document_data) {
  995. // If there is a session defined and asking for the
  996. // document * from the session* didn't work, try it from
  997. // the course (out of a session context)
  998. $document_data = DocumentManager::get_document_data_by_id(
  999. $_POST['dir_id'],
  1000. api_get_course_id(),
  1001. false,
  1002. 0
  1003. );
  1004. }
  1005. $curdirpath = $document_data['path'];
  1006. }
  1007. $added_slash = ($curdirpath == '/') ? '' : '/';
  1008. $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
  1009. $dir_name = disable_dangerous_file($dir_name);
  1010. $dir_check = $base_work_dir.$dir_name;
  1011. if (!is_dir($dir_check)) {
  1012. $visibility = empty($groupId) ? null : 1;
  1013. $created_dir = create_unexisting_directory(
  1014. $courseInfo,
  1015. api_get_user_id(),
  1016. $sessionId,
  1017. $groupId,
  1018. $to_user_id,
  1019. $base_work_dir,
  1020. $dir_name,
  1021. $post_dir_name,
  1022. $visibility
  1023. );
  1024. if ($created_dir) {
  1025. $message = Display::return_message(get_lang('DirCr').' '.$created_dir, 'confirmation');
  1026. } else {
  1027. $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
  1028. }
  1029. } else {
  1030. $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
  1031. }
  1032. }
  1033. Session::write('message', $message);
  1034. }
  1035. // Show them the form for the directory name
  1036. if (isset($_GET['createdir'])) {
  1037. $dirForm = create_dir_form($document_id);
  1038. }
  1039. }
  1040. /* VISIBILITY COMMANDS */
  1041. if ($is_allowed_to_edit) {
  1042. if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) ||
  1043. (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) &&
  1044. $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*'
  1045. ) {
  1046. // Make visible or invisible?
  1047. if (isset($_GET['set_visible'])) {
  1048. $update_id = intval($_GET['set_visible']);
  1049. $visibility_command = 'visible';
  1050. } else {
  1051. $update_id = intval($_GET['set_invisible']);
  1052. $visibility_command = 'invisible';
  1053. }
  1054. if (!$is_allowed_to_edit) {
  1055. if (api_is_coach()) {
  1056. if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $sessionId, api_get_user_id())) {
  1057. api_not_allowed(true);
  1058. }
  1059. }
  1060. if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $update_id)) {
  1061. api_not_allowed(true);
  1062. }
  1063. }
  1064. // Update item_property to change visibility
  1065. if (api_item_property_update(
  1066. $courseInfo,
  1067. TOOL_DOCUMENT,
  1068. $update_id,
  1069. $visibility_command,
  1070. api_get_user_id(),
  1071. null,
  1072. null,
  1073. null,
  1074. null,
  1075. $sessionId)
  1076. ) {
  1077. //don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all)
  1078. $message = Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
  1079. } else {
  1080. $message = Display::return_message(get_lang('ViModProb'), 'error');
  1081. }
  1082. Session::write('message', $message);
  1083. }
  1084. }
  1085. $templateForm = null;
  1086. /* TEMPLATE ACTION */
  1087. //Only teacher and all users into their group
  1088. if ($is_allowed_to_edit ||
  1089. $group_member_with_upload_rights ||
  1090. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1091. ) {
  1092. if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
  1093. $document_id_for_template = intval($_GET['add_as_template']);
  1094. // Create the form that asks for the directory name
  1095. $templateForm .= '<form name="set_document_as_new_template" enctype="multipart/form-data" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
  1096. $templateForm .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  1097. $templateForm .= '<table><tr><td>';
  1098. $templateForm .= get_lang('TemplateName').' : </td>';
  1099. $templateForm .= '<td><input type="text" name="template_title" /></td></tr>';
  1100. //$templateForm .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
  1101. //$templateForm .= '<td><textarea name="template_description"></textarea></td></tr>';
  1102. $templateForm .= '<tr><td>'.get_lang('TemplateImage').' : </td>';
  1103. $templateForm .= '<td><input type="file" name="template_image" id="template_image" /></td></tr>';
  1104. $templateForm .= '</table>';
  1105. $templateForm .= '<button type="submit" class="add" name="create_template">'.get_lang('CreateTemplate').'</button>';
  1106. $templateForm .= '</form>';
  1107. } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
  1108. $document_id_for_template = intval(Database::escape_string($_GET['add_as_template']));
  1109. $title = Security::remove_XSS($_POST['template_title']);
  1110. //$description = Security::remove_XSS($_POST['template_description']);
  1111. $user_id = api_get_user_id();
  1112. // Create the template_thumbnails folder in the upload folder (if needed)
  1113. if (!is_dir(api_get_path(SYS_PATH).'courses/'.$courseInfo['directory'].'/upload/template_thumbnails/')) {
  1114. @mkdir(
  1115. api_get_path(SYS_PATH).'courses/'.$courseInfo['directory'].'/upload/template_thumbnails/',
  1116. api_get_permissions_for_new_directories()
  1117. );
  1118. }
  1119. // Upload the file
  1120. if (!empty($_FILES['template_image']['name'])) {
  1121. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  1122. $upload_ok = process_uploaded_file($_FILES['template_image']);
  1123. if ($upload_ok) {
  1124. // Try to add an extension to the file if it hasn't one
  1125. $new_file_name = $courseInfo['code'].'-'.add_ext_on_mime(
  1126. stripslashes($_FILES['template_image']['name']),
  1127. $_FILES['template_image']['type']
  1128. );
  1129. // Upload dir
  1130. $upload_dir = api_get_path(SYS_PATH).'courses/'.$courseInfo['directory'].'/upload/template_thumbnails/';
  1131. // Resize image to max default and end upload
  1132. $temp = new Image($_FILES['template_image']['tmp_name']);
  1133. $picture_info = $temp->get_image_info();
  1134. $max_width_for_picture = 100;
  1135. if ($picture_info['width'] > $max_width_for_picture) {
  1136. $thumbwidth = $max_width_for_picture;
  1137. if (empty($thumbwidth) || $thumbwidth == 0) {
  1138. $thumbwidth = $max_width_for_picture;
  1139. }
  1140. $new_height = round(($thumbwidth / $picture_info['width']) * $picture_info['height']);
  1141. $temp->resize($thumbwidth, $new_height, 0);
  1142. }
  1143. $temp->send_image($upload_dir.$new_file_name);
  1144. }
  1145. }
  1146. DocumentManager::set_document_as_template(
  1147. $title,
  1148. $description,
  1149. $document_id_for_template,
  1150. $course_code,
  1151. $user_id,
  1152. $new_file_name
  1153. );
  1154. $message = Display::return_message(get_lang('DocumentSetAsTemplate'), 'confirmation');
  1155. Session::write('message', $message);
  1156. }
  1157. if (isset($_GET['remove_as_template'])) {
  1158. $document_id_for_template = intval($_GET['remove_as_template']);
  1159. $user_id = api_get_user_id();
  1160. DocumentManager::unset_document_as_template(
  1161. $document_id_for_template,
  1162. $course_code,
  1163. $user_id
  1164. );
  1165. $message = Display::return_message(get_lang('DocumentUnsetAsTemplate'), 'confirmation');
  1166. Session::write('message', $message);
  1167. }
  1168. }
  1169. // END ACTION MENU
  1170. // Attach certificate in the gradebook
  1171. if (isset($_GET['curdirpath']) &&
  1172. $_GET['curdirpath'] == '/certificates' &&
  1173. isset($_GET['set_certificate']) &&
  1174. $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))
  1175. ) {
  1176. if (isset($_GET['cidReq'])) {
  1177. $course_id = Security::remove_XSS($_GET['cidReq']); // course id
  1178. $document_id = Security::remove_XSS($_GET['set_certificate']); // document id
  1179. DocumentManager::attach_gradebook_certificate($course_id, $document_id);
  1180. $message = Display::return_message(get_lang('IsDefaultCertificate'), 'normal');
  1181. Session::write('message', $message);
  1182. }
  1183. }
  1184. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  1185. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  1186. $documentAndFolders = DocumentManager::get_all_document_data(
  1187. $courseInfo,
  1188. $curdirpath,
  1189. $groupId,
  1190. null,
  1191. $is_allowed_to_edit || $group_member_with_upload_rights,
  1192. true
  1193. );
  1194. } else {
  1195. $documentAndFolders = DocumentManager::get_all_document_data(
  1196. $courseInfo,
  1197. $curdirpath,
  1198. $groupId,
  1199. null,
  1200. $is_allowed_to_edit || $group_member_with_upload_rights,
  1201. false
  1202. );
  1203. }
  1204. if ($groupId != 0) {
  1205. $userAccess = GroupManager::user_has_access(
  1206. api_get_user_id(),
  1207. $groupId,
  1208. GroupManager::GROUP_TOOL_DOCUMENTS
  1209. );
  1210. if ($userAccess) {
  1211. $folders = DocumentManager::get_all_document_folders(
  1212. $courseInfo,
  1213. $groupId,
  1214. $is_allowed_to_edit || $group_member_with_upload_rights
  1215. );
  1216. }
  1217. } else {
  1218. $folders = DocumentManager::get_all_document_folders(
  1219. $courseInfo,
  1220. $groupId,
  1221. $is_allowed_to_edit || $group_member_with_upload_rights
  1222. );
  1223. }
  1224. if (!isset($folders) || $folders === false) {
  1225. $folders = array();
  1226. }
  1227. $actions = '<div class="actions">';
  1228. if (!$is_certificate_mode) {
  1229. /* BUILD SEARCH FORM */
  1230. $actions .= '<span style="display:inline-block;">';
  1231. $form = new FormValidator('search_document', 'get', api_get_self().'?'.api_get_cidreq());
  1232. $renderer = & $form->defaultRenderer();
  1233. $renderer->setElementTemplate('<span>{element}</span> ');
  1234. $form->add_textfield('keyword', '', false, array('class' => 'span2'));
  1235. $form->addElement('hidden', 'cidReq', api_get_course_id());
  1236. $form->addElement('hidden', 'id_session', api_get_session_id());
  1237. $form->addElement('hidden', 'gidReq', $groupId);
  1238. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  1239. $actions .= $form->return_form();
  1240. $actions .= '</span>';
  1241. }
  1242. /* GO TO PARENT DIRECTORY */
  1243. if ($curdirpath != '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
  1244. $actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
  1245. $actions .= Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM);
  1246. $actions .= '</a>';
  1247. }
  1248. if ($is_certificate_mode && $curdirpath != '/certificates') {
  1249. $actions .= Display::url(
  1250. Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM),
  1251. api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath
  1252. );
  1253. }
  1254. $column_show = array();
  1255. if ($is_allowed_to_edit ||
  1256. $group_member_with_upload_rights ||
  1257. is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1258. ) {
  1259. // TODO:check enable more options for shared folders
  1260. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  1261. // Create new document
  1262. if (!$is_certificate_mode) {
  1263. $actions .= Display::url(
  1264. Display::return_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM),
  1265. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id
  1266. );
  1267. // Create new draw
  1268. if (api_get_setting('enabled_support_svg') == 'true') {
  1269. if (api_browser_support('svg')) {
  1270. $actions .= Display::url(
  1271. Display::return_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM),
  1272. api_get_path(WEB_CODE_PATH).'document/create_draw.php?'.api_get_cidreq().'&id='.$document_id
  1273. );
  1274. } else {
  1275. $actions .= Display::return_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
  1276. }
  1277. }
  1278. // Create new paint
  1279. if (api_get_setting('enabled_support_pixlr') == 'true') {
  1280. $actions .= Display::url(
  1281. Display::return_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM),
  1282. api_get_path(WEB_CODE_PATH).'document/create_paint.php?'.api_get_cidreq().'&id='.$document_id
  1283. );
  1284. }
  1285. // Record an image clip from my webcam
  1286. if (api_get_setting('enable_webcam_clip') == 'true') {
  1287. $actions .= Display::url(
  1288. Display::return_icon('webcam.png', get_lang('WebCamClip'), '', ICON_SIZE_MEDIUM),
  1289. api_get_path(WEB_CODE_PATH).'document/webcam_clip.php?'.api_get_cidreq().'&id='.$document_id
  1290. );
  1291. }
  1292. // Record audio (nanogong)
  1293. if (api_get_setting('enable_nanogong') == 'true') {
  1294. $actions .= Display::url(
  1295. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1296. api_get_path(WEB_CODE_PATH).'document/record_audio.php?'.api_get_cidreq().'&id='.$document_id
  1297. );
  1298. }
  1299. // Record audio (wami record)
  1300. if (api_get_setting('enable_wami_record') == 'true') {
  1301. $actions .= Display::url(
  1302. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1303. api_get_path(WEB_CODE_PATH).'document/record_audio_wami.php?'.api_get_cidreq().'&id='.$document_id
  1304. );
  1305. }
  1306. // Create new audio from text
  1307. if (api_get_setting('enabled_text2audio') == 'true') {
  1308. $dt2a = 'google';
  1309. $req_dt2a = '&amp;dt2a='.$dt2a;
  1310. $actions .= Display::url(
  1311. Display::return_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM),
  1312. api_get_path(WEB_CODE_PATH).'document/create_audio.php?'.api_get_cidreq().'&id='.$document_id.$req_dt2a
  1313. );
  1314. }
  1315. }
  1316. // Create new certificate
  1317. if ($is_certificate_mode) {
  1318. $actions .= Display::url(
  1319. Display::return_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM),
  1320. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id.'&certificate=true&selectcat='.$selectcat
  1321. );
  1322. }
  1323. // File upload link
  1324. if ($is_certificate_mode) {
  1325. $actions .= Display::url(
  1326. Display::return_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM),
  1327. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
  1328. );
  1329. } else {
  1330. $actions .= Display::url(
  1331. Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM),
  1332. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
  1333. );
  1334. }
  1335. /*echo '<a href="#" id="jcapture">';
  1336. echo Display::display_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM).'</a>';*/
  1337. if ($capturePluginInstalled) {
  1338. $actions .= '<span id="appletplace"></span>';
  1339. $actions .= Display::url(
  1340. Display::return_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM),
  1341. '#',
  1342. array('id' => 'jcapture')
  1343. );
  1344. }
  1345. // Create directory
  1346. if (!$is_certificate_mode) {
  1347. $actions .= Display::url(
  1348. Display::return_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM),
  1349. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$document_id.'&createdir=1'
  1350. );
  1351. }
  1352. }
  1353. $table_footer = '';
  1354. $total_size = 0;
  1355. $sortable_data = array();
  1356. if (isset($documentAndFolders) && is_array($documentAndFolders)) {
  1357. if ($groupId == 0 || GroupManager::user_has_access($userId, $groupId, GroupManager::GROUP_TOOL_DOCUMENTS)) {
  1358. $count = 1;
  1359. $countedPaths = array();
  1360. $countedPaths = array();
  1361. foreach ($documentAndFolders as $key => $document_data) {
  1362. $row = array();
  1363. $row['id'] = $document_data['id'];
  1364. $row['type'] = $document_data['filetype'];
  1365. // If the item is invisible, wrap it in a span with class invisible.
  1366. $is_visible = DocumentManager::is_visible_by_id(
  1367. $document_data['id'],
  1368. $courseInfo,
  1369. $sessionId,
  1370. api_get_user_id(),
  1371. false
  1372. );
  1373. $invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
  1374. $invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
  1375. // Size (or total size of a directory)
  1376. $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
  1377. // Get the title or the basename depending on what we're using
  1378. if ($document_data['title'] != '') {
  1379. $document_name = $document_data['title'];
  1380. } else {
  1381. $document_name = basename($document_data['path']);
  1382. }
  1383. $row['name'] = $document_name;
  1384. // Data for checkbox
  1385. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1386. $row[] = $document_data['id'];
  1387. }
  1388. if (DocumentManager::is_folder_to_avoid($document_data['path'], $is_certificate_mode)) {
  1389. continue;
  1390. }
  1391. // Show the owner of the file only in groups
  1392. $user_link = '';
  1393. if (!empty($groupId)) {
  1394. if (!empty($document_data['insert_user_id'])) {
  1395. $user_info = UserManager::get_user_info_by_id($document_data['insert_user_id']);
  1396. $user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
  1397. $user_link = '<div class="document_owner">'.
  1398. get_lang('Owner').': '.display_user_link_document($document_data['insert_user_id'], $user_name).'</div>';
  1399. }
  1400. }
  1401. // Icons (clickable)
  1402. $row[] = create_document_link($document_data, true, $count, $is_visible);
  1403. $path_info = pathinfo($document_data['path']);
  1404. if (isset($path_info['extension']) && in_array($path_info['extension'], array('ogg', 'mp3', 'wav'))) {
  1405. $count++;
  1406. }
  1407. // Validacion when belongs to a session
  1408. $session_img = api_get_session_image($document_data['session_id'], $_user['status']);
  1409. // Document title with link
  1410. $row[] = create_document_link($document_data, false, null, $is_visible).
  1411. $session_img.'<br />'.$invisibility_span_open.
  1412. '<i>'.nl2br(htmlspecialchars($document_data['comment'], ENT_QUOTES, $charset)).'</i>'.
  1413. $invisibility_span_close.
  1414. $user_link;
  1415. // Comments => display comment under the document name
  1416. $display_size = format_file_size($size);
  1417. $row[] = '<span style="display:none;">'.$size.'</span>'.
  1418. $invisibility_span_open.
  1419. $display_size.
  1420. $invisibility_span_close;
  1421. // Last edit date
  1422. $last_edit_date = api_get_local_time($document_data['lastedit_date']);
  1423. $display_date = date_to_str_ago($last_edit_date).
  1424. ' <div class="muted"><small>'.$last_edit_date."</small></div>";
  1425. $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
  1426. // Admins get an edit column
  1427. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
  1428. $is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
  1429. // If readonly, check if it the owner of the file or if the user is an admin
  1430. if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
  1431. $edit_icons = build_edit_icons($document_data, $key, $is_template, 0, $is_visible);
  1432. } else {
  1433. $edit_icons = build_edit_icons($document_data, $key, $is_template, $document_data['readonly'], $is_visible);
  1434. }
  1435. $row[] = $edit_icons;
  1436. }
  1437. $row[] = $last_edit_date;
  1438. $row[] = $size;
  1439. $row[] = $document_name;
  1440. $total_size = $total_size + $size;
  1441. if (!isset($countedPaths[$document_data['path']])) {
  1442. $total_size = $total_size + $size;
  1443. $countedPaths[$document_data['path']] = true;
  1444. }
  1445. if ((isset($_GET['keyword']) &&
  1446. search_keyword($document_name, $_GET['keyword'])) ||
  1447. !isset($_GET['keyword']) || empty($_GET['keyword'])
  1448. ) {
  1449. $sortable_data[] = $row;
  1450. }
  1451. }
  1452. }
  1453. } else {
  1454. $sortable_data = '';
  1455. $table_footer = get_lang('NoDocsInFolder');
  1456. }
  1457. if (!is_null($documentAndFolders)) {
  1458. // Show download zipped folder icon
  1459. global $total_size;
  1460. if (!$is_certificate_mode && $total_size != 0
  1461. && (api_get_setting('students_download_folders') == 'true'
  1462. || api_is_allowed_to_edit()
  1463. || api_is_platform_admin()
  1464. )
  1465. ) {
  1466. //for student does not show icon into other shared folder, and does not show into main path (root)
  1467. if (is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1468. && $curdirpath != '/'
  1469. || api_is_allowed_to_edit()
  1470. || api_is_platform_admin()
  1471. ) {
  1472. $actions .= Display::url(
  1473. Display::return_icon('save_pack.png', get_lang('Save').' (ZIP)', '', ICON_SIZE_MEDIUM),
  1474. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&action=downloadfolder&id='.$document_id
  1475. );
  1476. }
  1477. }
  1478. }
  1479. require 'document_slideshow.inc.php';
  1480. if ($image_present && !isset($_GET['keyword'])) {
  1481. $actions .= Display::url(
  1482. Display::return_icon('slideshow.png', get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM),
  1483. api_get_path(WEB_CODE_PATH).'document/slideshow.php?'.api_get_cidreq().'&curdirpath='.$curdirpathurl
  1484. );
  1485. }
  1486. if (api_is_allowed_to_edit(null, true)) {
  1487. $actions .= Display::url(
  1488. Display::return_icon('percentage.png', get_lang('DocumentQuota'), '', ICON_SIZE_MEDIUM),
  1489. api_get_path(WEB_CODE_PATH).'document/document_quota.php?'.api_get_cidreq()
  1490. );
  1491. }
  1492. $actions .= '</div>';
  1493. if (!empty($moveTo)) {
  1494. $document_id = DocumentManager::get_document_id($courseInfo, $moveTo);
  1495. }
  1496. if (isset($_GET['createdir']) && isset($_POST['dirname']) && $_POST['dirname'] != '') {
  1497. $post_dir_name = $_POST['dirname'];
  1498. $document_id = DocumentManager::get_document_id($courseInfo, $_POST['dirname']);
  1499. }
  1500. $selector = null;
  1501. if (!$is_certificate_mode) {
  1502. $selector = build_directory_selector(
  1503. $folders,
  1504. $document_id,
  1505. (isset($group_properties['directory']) ? $group_properties['directory'] : array()),
  1506. true
  1507. );
  1508. }
  1509. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1510. $column_show[] = 1;
  1511. }
  1512. $column_show[] = 1;
  1513. $column_show[] = 1;
  1514. $column_show[] = 1;
  1515. $column_show[] = 1;
  1516. if ($is_allowed_to_edit
  1517. || $group_member_with_upload_rights
  1518. || is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1519. ) {
  1520. $column_show[] = 1;
  1521. }
  1522. $column_show[] = 0;
  1523. $column_show[] = 0;
  1524. $column_order = array();
  1525. if (count($row) == 12) {
  1526. //teacher
  1527. $column_order[2] = 8; //name
  1528. $column_order[3] = 7;
  1529. $column_order[4] = 6;
  1530. } elseif (count($row) == 10) {
  1531. //student
  1532. $column_order[1] = 6;
  1533. $column_order[2] = 5;
  1534. $column_order[3] = 4;
  1535. }
  1536. $default_column = $is_allowed_to_edit ? 2 : 1;
  1537. $tableName = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
  1538. $table = new SortableTableFromArrayConfig(
  1539. $sortable_data,
  1540. $default_column,
  1541. 20,
  1542. $tableName,
  1543. $column_show,
  1544. $column_order,
  1545. 'ASC',
  1546. true
  1547. );
  1548. $query_vars = array();
  1549. if (isset($_GET['keyword'])) {
  1550. $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
  1551. } else {
  1552. $query_vars['curdirpath'] = $curdirpath;
  1553. }
  1554. if ($groupId) {
  1555. $query_vars['gidReq'] = $groupId;
  1556. }
  1557. $query_vars['cidReq'] = api_get_course_id();
  1558. $table->set_additional_parameters($query_vars);
  1559. $column = 0;
  1560. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1561. $table->set_header($column++, '', false, array('style' => 'width:12px;'));
  1562. }
  1563. $table->set_header($column++, get_lang('Type'), true, array('style' => 'width:30px;'));
  1564. $table->set_header($column++, get_lang('Name'));
  1565. $table->set_header($column++, get_lang('Size'), true, array('style' => 'width:50px;'));
  1566. $table->set_header($column++, get_lang('Date'), true, array('style' => 'width:150px;'));
  1567. // Admins get an edit column
  1568. if ($is_allowed_to_edit
  1569. || $group_member_with_upload_rights
  1570. || is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
  1571. $table->set_header($column++, get_lang('Actions'), false, array('class' => 'td_actions'));
  1572. }
  1573. // Actions on multiple selected documents
  1574. // TODO: Currently only delete action -> take only DELETE permission into account
  1575. if (count($documentAndFolders) > 1) {
  1576. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1577. $form_actions = array();
  1578. $form_action['set_invisible'] = get_lang('SetInvisible');
  1579. $form_action['set_visible'] = get_lang('SetVisible');
  1580. $form_action['delete'] = get_lang('Delete');
  1581. $portfolio_actions = Portfolio::actions();
  1582. foreach ($portfolio_actions as $action) {
  1583. $form_action[$action->get_name()] = $action->get_title();
  1584. }
  1585. $table->set_form_actions($form_action, 'ids');
  1586. }
  1587. }
  1588. Display::display_header('', 'Doc');
  1589. /* Introduction section (editable by course admins) */
  1590. if (!empty($groupId)) {
  1591. Display::display_introduction_section(TOOL_DOCUMENT.$groupId);
  1592. } else {
  1593. Display::display_introduction_section(TOOL_DOCUMENT);
  1594. }
  1595. $message = Session::read('message');
  1596. if (!empty($message)) {
  1597. echo $message;
  1598. }
  1599. Session::erase('message');
  1600. echo $actions;
  1601. echo $templateForm;
  1602. echo $moveForm;
  1603. echo $dirForm;
  1604. echo $selector;
  1605. $table->display();
  1606. if (count($documentAndFolders) > 1) {
  1607. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1608. // Getting the course quota
  1609. $course_quota = DocumentManager::get_course_quota();
  1610. // Calculating the total space
  1611. $already_consumed_space_course = DocumentManager::documents_total_space(api_get_course_int_id());
  1612. // Displaying the quota
  1613. DocumentManager::display_simple_quota($course_quota, $already_consumed_space_course);
  1614. }
  1615. }
  1616. if (!empty($table_footer)) {
  1617. Display::display_warning_message($table_footer);
  1618. }
  1619. // Footer
  1620. Display::display_footer();