document.php 76 KB

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