document.php 76 KB

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