document.php 75 KB

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