document.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Homepage script for the documents tool
  5. *
  6. * This script allows the user to manage files and directories on a remote http
  7. * server.
  8. * The user can : - navigate through files and directories.
  9. * - upload a file
  10. * - delete, copy a file or a directory
  11. * - edit properties & content (name, comments, html content)
  12. * The script is organised in four sections.
  13. *
  14. * 1) Execute the command called by the user
  15. * Note: somme commands of this section are organised in two steps.
  16. * The script always begins with the second step,
  17. * so it allows to return more easily to the first step.
  18. *
  19. * Note (March 2004) some editing functions (renaming, commenting)
  20. * are moved to a separate page, edit_document.php. This is also
  21. * where xml and other stuff should be added.
  22. * 2) Define the directory to display
  23. * 3) Read files and directories from the directory defined in part 2
  24. * 4) Display all of that on an HTML page
  25. *
  26. * @package chamilo.document
  27. */
  28. use ChamiloSession as Session;
  29. require_once '../inc/global.inc.php';
  30. $current_course_tool = TOOL_DOCUMENT;
  31. $this_section = SECTION_COURSES;
  32. $to_user_id = null;
  33. $parent_id = null;
  34. $lib_path = api_get_path(LIBRARY_PATH);
  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());
  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('ErrorSameFormat'),
  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('FormatNotSupported'),
  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('AreYouSureToDelete').' "+ 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 .= '<form name="set_document_as_new_template" enctype="multipart/form-data" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
  1248. $templateForm .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  1249. $templateForm .= '<table><tr><td>';
  1250. $templateForm .= get_lang('TemplateName').' : </td>';
  1251. $templateForm .= '<td><input type="text" name="template_title" /></td></tr>';
  1252. //$templateForm .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
  1253. //$templateForm .= '<td><textarea name="template_description"></textarea></td></tr>';
  1254. $templateForm .= '<tr><td>'.get_lang('TemplateImage').' : </td>';
  1255. $templateForm .= '<td><input type="file" name="template_image" id="template_image" /></td></tr>';
  1256. $templateForm .= '</table>';
  1257. $templateForm .= '<button type="submit" class="btn-default" name="create_template">'.get_lang('CreateTemplate').'</button>';
  1258. $templateForm .= '</form>';
  1259. } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
  1260. $document_id_for_template = intval($_GET['add_as_template']);
  1261. $title = Security::remove_XSS($_POST['template_title']);
  1262. $user_id = api_get_user_id();
  1263. // Create the template_thumbnails folder in the upload folder (if needed)
  1264. if (!is_dir(api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/')) {
  1265. @mkdir(
  1266. api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/',
  1267. api_get_permissions_for_new_directories()
  1268. );
  1269. }
  1270. // Upload the file
  1271. if (!empty($_FILES['template_image']['name'])) {
  1272. $upload_ok = process_uploaded_file($_FILES['template_image']);
  1273. if ($upload_ok) {
  1274. // Try to add an extension to the file if it hasn't one
  1275. $new_file_name = $courseInfo['code'].'-'.add_ext_on_mime(
  1276. stripslashes($_FILES['template_image']['name']),
  1277. $_FILES['template_image']['type']
  1278. );
  1279. // Upload dir
  1280. $upload_dir = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/';
  1281. // Resize image to max default and end upload
  1282. $temp = new Image($_FILES['template_image']['tmp_name']);
  1283. $picture_info = $temp->get_image_info();
  1284. $max_width_for_picture = 100;
  1285. if ($picture_info['width'] > $max_width_for_picture) {
  1286. $thumbwidth = $max_width_for_picture;
  1287. if (empty($thumbwidth) || $thumbwidth == 0) {
  1288. $thumbwidth = $max_width_for_picture;
  1289. }
  1290. $new_height = round(($thumbwidth / $picture_info['width']) * $picture_info['height']);
  1291. $temp->resize($thumbwidth, $new_height, 0);
  1292. }
  1293. $temp->send_image($upload_dir.$new_file_name);
  1294. }
  1295. }
  1296. DocumentManager::set_document_as_template(
  1297. $title,
  1298. $description,
  1299. $document_id_for_template,
  1300. $course_code,
  1301. $user_id,
  1302. $new_file_name
  1303. );
  1304. Display::addFlash(
  1305. Display::return_message(get_lang('DocumentSetAsTemplate'), 'confirmation')
  1306. );
  1307. }
  1308. if (isset($_GET['remove_as_template'])) {
  1309. $document_id_for_template = intval($_GET['remove_as_template']);
  1310. $user_id = api_get_user_id();
  1311. DocumentManager::unset_document_as_template(
  1312. $document_id_for_template,
  1313. $course_code,
  1314. $user_id
  1315. );
  1316. Display::addFlash(
  1317. Display::return_message(get_lang('DocumentUnsetAsTemplate'), 'confirmation')
  1318. );
  1319. }
  1320. }
  1321. // END ACTION MENU
  1322. // Attach certificate in the gradebook
  1323. if (isset($_GET['curdirpath']) &&
  1324. $_GET['curdirpath'] == '/certificates' &&
  1325. isset($_GET['set_certificate']) &&
  1326. $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))
  1327. ) {
  1328. if (isset($_GET['cidReq'])) {
  1329. $course_id = Security::remove_XSS($_GET['cidReq']); // course id
  1330. $document_id = Security::remove_XSS($_GET['set_certificate']); // document id
  1331. DocumentManager::attach_gradebook_certificate($course_id, $document_id);
  1332. $message = Display::return_message(get_lang('IsDefaultCertificate'), 'normal');
  1333. Display::addFlash(
  1334. $message
  1335. );
  1336. }
  1337. }
  1338. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  1339. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  1340. $documentAndFolders = DocumentManager::get_all_document_data(
  1341. $courseInfo,
  1342. $curdirpath,
  1343. $groupId,
  1344. null,
  1345. $is_allowed_to_edit || $group_member_with_upload_rights,
  1346. true
  1347. );
  1348. } else {
  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. false
  1356. );
  1357. }
  1358. if ($groupId != 0) {
  1359. $userAccess = GroupManager::user_has_access(
  1360. api_get_user_id(),
  1361. $groupId,
  1362. GroupManager::GROUP_TOOL_DOCUMENTS
  1363. );
  1364. if ($userAccess) {
  1365. $folders = DocumentManager::get_all_document_folders(
  1366. $courseInfo,
  1367. $groupId,
  1368. $is_allowed_to_edit || $group_member_with_upload_rights
  1369. );
  1370. }
  1371. } else {
  1372. $folders = DocumentManager::get_all_document_folders(
  1373. $courseInfo,
  1374. $groupId,
  1375. $is_allowed_to_edit || $group_member_with_upload_rights
  1376. );
  1377. }
  1378. if (!isset($folders) || $folders === false) {
  1379. $folders = array();
  1380. }
  1381. $btngroup = array('class' => 'btn btn-default');
  1382. /* GO TO PARENT DIRECTORY */
  1383. $actionsLeft = '';
  1384. if ($curdirpath != '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
  1385. $actionsLeft = '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
  1386. $actionsLeft .= Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM);
  1387. $actionsLeft .= '</a>';
  1388. }
  1389. if ($is_certificate_mode && $curdirpath != '/certificates') {
  1390. $actionsLeft .= Display::url(
  1391. Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM),
  1392. api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath
  1393. );
  1394. }
  1395. $column_show = array();
  1396. if ($is_allowed_to_edit ||
  1397. $group_member_with_upload_rights ||
  1398. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1399. ) {
  1400. // TODO:check enable more options for shared folders
  1401. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  1402. // Create new document
  1403. if (!$is_certificate_mode) {
  1404. $actionsLeft .= Display::url(
  1405. Display::return_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM),
  1406. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id
  1407. );
  1408. // Create new draw
  1409. if (api_get_setting('enabled_support_svg') == 'true') {
  1410. if (api_browser_support('svg')) {
  1411. $actionsLeft .= Display::url(
  1412. Display::return_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM),
  1413. api_get_path(WEB_CODE_PATH).'document/create_draw.php?'.api_get_cidreq().'&id='.$document_id
  1414. );
  1415. } else {
  1416. $actionsLeft .= Display::return_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
  1417. }
  1418. }
  1419. // Create new paint
  1420. if (api_get_setting('enabled_support_pixlr') == 'true') {
  1421. $actionsLeft .= Display::url(
  1422. Display::return_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM),
  1423. api_get_path(WEB_CODE_PATH).'document/create_paint.php?'.api_get_cidreq().'&id='.$document_id
  1424. );
  1425. }
  1426. // Record an image clip from my webcam
  1427. if (api_get_setting('enable_webcam_clip') == 'true') {
  1428. $actionsLeft .= Display::url(
  1429. Display::return_icon('webcam.png', get_lang('WebCamClip'), '', ICON_SIZE_MEDIUM),
  1430. api_get_path(WEB_CODE_PATH).'document/webcam_clip.php?'.api_get_cidreq().'&id='.$document_id
  1431. );
  1432. }
  1433. // Record audio (nanogong)
  1434. if (api_get_setting('enable_nanogong') == 'true') {
  1435. $actionsLeft .= Display::url(
  1436. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1437. api_get_path(WEB_CODE_PATH).'document/record_audio.php?'.api_get_cidreq().'&id='.$document_id
  1438. );
  1439. }
  1440. // Record audio (wami record)
  1441. if (api_get_setting('enable_wami_record') == 'true') {
  1442. $actionsLeft .= Display::url(
  1443. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1444. api_get_path(WEB_CODE_PATH).'document/record_audio_wami.php?'.api_get_cidreq().'&id='.$document_id
  1445. );
  1446. }
  1447. // Create new audio from text
  1448. if (api_get_setting('enabled_text2audio') == 'true') {
  1449. $dt2a = 'google';
  1450. $req_dt2a = '&amp;dt2a='.$dt2a;
  1451. $actionsLeft .= Display::url(
  1452. Display::return_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM),
  1453. api_get_path(WEB_CODE_PATH).'document/create_audio.php?'.api_get_cidreq().'&id='.$document_id.$req_dt2a
  1454. );
  1455. }
  1456. }
  1457. // Create new certificate
  1458. if ($is_certificate_mode) {
  1459. $actionsLeft .= Display::url(
  1460. Display::return_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM),
  1461. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id.'&certificate=true&selectcat='.$selectcat
  1462. );
  1463. }
  1464. // File upload link
  1465. if ($is_certificate_mode) {
  1466. $actionsLeft .= Display::url(
  1467. Display::return_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM),
  1468. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id.'&certificate=true'
  1469. );
  1470. } else {
  1471. $actionsLeft .= Display::url(
  1472. Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM),
  1473. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
  1474. );
  1475. }
  1476. /*echo '<a href="#" id="jcapture">';
  1477. echo Display::display_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM).'</a>';*/
  1478. if ($capturePluginInstalled) {
  1479. $actionsLeft .= '<span id="appletplace"></span>';
  1480. $actionsLeft .= Display::url(
  1481. Display::return_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM),
  1482. '#',
  1483. array('id' => 'jcapture')
  1484. );
  1485. }
  1486. // Create directory
  1487. if (!$is_certificate_mode) {
  1488. $actionsLeft .= Display::url(
  1489. Display::return_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM),
  1490. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$document_id.'&createdir=1'
  1491. );
  1492. }
  1493. }
  1494. require 'document_slideshow.inc.php';
  1495. if ($image_present && !isset($_GET['keyword'])) {
  1496. $actionsLeft .= Display::url(
  1497. Display::return_icon('slideshow.png', get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM),
  1498. api_get_path(WEB_CODE_PATH).'document/slideshow.php?'.api_get_cidreq().'&curdirpath='.$curdirpathurl
  1499. );
  1500. }
  1501. if (api_is_allowed_to_edit(null, true)) {
  1502. $actionsLeft .= Display::url(
  1503. Display::return_icon('percentage.png', get_lang('DocumentQuota'), '', ICON_SIZE_MEDIUM),
  1504. api_get_path(WEB_CODE_PATH).'document/document_quota.php?'.api_get_cidreq()
  1505. );
  1506. }
  1507. $actionsRight = '';
  1508. if (!$is_certificate_mode) {
  1509. /* BUILD SEARCH FORM */
  1510. $form = new FormValidator(
  1511. 'search_document',
  1512. 'get',
  1513. api_get_self().'?'.api_get_cidreq(),
  1514. '',
  1515. array(),
  1516. FormValidator::LAYOUT_INLINE
  1517. );
  1518. $form->addText('keyword', '', false, array('class' => 'col-md-2'));
  1519. $form->addElement('hidden', 'cidReq', api_get_course_id());
  1520. $form->addElement('hidden', 'id_session', api_get_session_id());
  1521. $form->addElement('hidden', 'gidReq', $groupId);
  1522. $form->addButtonSearch(get_lang('Search'));
  1523. $actionsRight = $form->returnForm();
  1524. }
  1525. $table_footer = '';
  1526. $total_size = 0;
  1527. $sortable_data = array();
  1528. if (isset($documentAndFolders) && is_array($documentAndFolders)) {
  1529. if ($groupId == 0 ||
  1530. GroupManager::user_has_access(
  1531. $userId,
  1532. $groupId,
  1533. GroupManager::GROUP_TOOL_DOCUMENTS
  1534. )
  1535. ) {
  1536. $count = 1;
  1537. $countedPaths = array();
  1538. $countedPaths = array();
  1539. foreach ($documentAndFolders as $key => $document_data) {
  1540. $row = array();
  1541. $row['id'] = $document_data['id'];
  1542. $row['type'] = $document_data['filetype'];
  1543. // If the item is invisible, wrap it in a span with class invisible.
  1544. $is_visible = DocumentManager::is_visible_by_id(
  1545. $document_data['id'],
  1546. $courseInfo,
  1547. $sessionId,
  1548. api_get_user_id(),
  1549. false
  1550. );
  1551. $invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
  1552. $invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
  1553. // Size (or total size of a directory)
  1554. $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
  1555. // Get the title or the basename depending on what we're using
  1556. if ($document_data['title'] != '') {
  1557. $document_name = $document_data['title'];
  1558. } else {
  1559. $document_name = basename($document_data['path']);
  1560. }
  1561. $row['name'] = $document_name;
  1562. // Data for checkbox
  1563. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1564. $row[] = $document_data['id'];
  1565. }
  1566. if (DocumentManager::is_folder_to_avoid($document_data['path'], $is_certificate_mode)) {
  1567. continue;
  1568. }
  1569. // Show the owner of the file only in groups
  1570. $user_link = '';
  1571. if (!empty($groupId)) {
  1572. if (!empty($document_data['insert_user_id'])) {
  1573. $user_info = api_get_user_info($document_data['insert_user_id']);
  1574. $user_link = '<div class="document_owner">'.
  1575. get_lang('Owner').': '.UserManager::getUserProfileLink($user_info).'</div>';
  1576. }
  1577. }
  1578. // Icons (clickable)
  1579. $row[] = DocumentManager::create_document_link($document_data, true, $count, $is_visible);
  1580. $path_info = pathinfo($document_data['path']);
  1581. if (isset($path_info['extension']) && in_array($path_info['extension'], array('ogg', 'mp3', 'wav'))) {
  1582. $count++;
  1583. }
  1584. // Validation when belongs to a session
  1585. $session_img = api_get_session_image($document_data['session_id'], $_user['status']);
  1586. // Document title with link
  1587. $row[] = DocumentManager::create_document_link($document_data, false, null, $is_visible).
  1588. $session_img.'<br />'.$invisibility_span_open.
  1589. '<i>'.nl2br(htmlspecialchars($document_data['comment'], ENT_QUOTES, $charset)).'</i>'.
  1590. $invisibility_span_close.
  1591. $user_link;
  1592. // Comments => display comment under the document name
  1593. $display_size = format_file_size($size);
  1594. $row[] = '<span style="display:none;">'.$size.'</span>'.
  1595. $invisibility_span_open.
  1596. $display_size.
  1597. $invisibility_span_close;
  1598. // Last edit date
  1599. $last_edit_date = api_get_local_time($document_data['lastedit_date']);
  1600. $display_date = date_to_str_ago($last_edit_date).
  1601. ' <div class="muted"><small>'.$last_edit_date."</small></div>";
  1602. $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
  1603. // Admins get an edit column
  1604. if ($is_allowed_to_edit || $group_member_with_upload_rights ||
  1605. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1606. ) {
  1607. $is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
  1608. // If readonly, check if it the owner of the file or if the user is an admin
  1609. if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
  1610. $edit_icons = DocumentManager::build_edit_icons(
  1611. $document_data,
  1612. $key,
  1613. $is_template,
  1614. 0,
  1615. $is_visible
  1616. );
  1617. } else {
  1618. $edit_icons = DocumentManager::build_edit_icons(
  1619. $document_data,
  1620. $key,
  1621. $is_template,
  1622. $document_data['readonly'],
  1623. $is_visible
  1624. );
  1625. }
  1626. $row[] = $edit_icons;
  1627. }
  1628. $row[] = $last_edit_date;
  1629. $row[] = $size;
  1630. $row[] = $document_name;
  1631. $total_size = $total_size + $size;
  1632. if (!isset($countedPaths[$document_data['path']])) {
  1633. $total_size = $total_size + $size;
  1634. $countedPaths[$document_data['path']] = true;
  1635. }
  1636. if ((isset($_GET['keyword']) &&
  1637. DocumentManager::search_keyword($document_name, $_GET['keyword'])) ||
  1638. !isset($_GET['keyword']) || empty($_GET['keyword'])
  1639. ) {
  1640. $sortable_data[] = $row;
  1641. }
  1642. }
  1643. }
  1644. } else {
  1645. $sortable_data = '';
  1646. $table_footer = get_lang('NoDocsInFolder');
  1647. }
  1648. if (!is_null($documentAndFolders)) {
  1649. // Show download zipped folder icon
  1650. global $total_size;
  1651. if (!$is_certificate_mode && $total_size != 0
  1652. && (api_get_setting('students_download_folders') == 'true'
  1653. || api_is_allowed_to_edit()
  1654. || api_is_platform_admin()
  1655. )
  1656. ) {
  1657. //for student does not show icon into other shared folder, and does not show into main path (root)
  1658. if (DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1659. && $curdirpath != '/'
  1660. || api_is_allowed_to_edit()
  1661. || api_is_platform_admin()
  1662. ) {
  1663. $actionsLeft .= Display::url(
  1664. Display::return_icon(
  1665. 'save_pack.png',
  1666. get_lang('Save').' (ZIP)',
  1667. '',
  1668. ICON_SIZE_MEDIUM
  1669. ),
  1670. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&action=downloadfolder&id='.$document_id
  1671. );
  1672. }
  1673. }
  1674. }
  1675. if (!empty($moveTo)) {
  1676. $document_id = DocumentManager::get_document_id($courseInfo, $moveTo);
  1677. }
  1678. if (isset($_GET['createdir']) && isset($_POST['dirname']) && $_POST['dirname'] != '') {
  1679. $post_dir_name = $_POST['dirname'];
  1680. $document_id = DocumentManager::get_document_id($courseInfo, $_POST['dirname']);
  1681. }
  1682. $selector = null;
  1683. if (!$is_certificate_mode) {
  1684. $selector = DocumentManager::build_directory_selector(
  1685. $folders,
  1686. $document_id,
  1687. (isset($group_properties['directory']) ? $group_properties['directory'] : array()),
  1688. true
  1689. );
  1690. }
  1691. if (($is_allowed_to_edit || $group_member_with_upload_rights) &&
  1692. count($documentAndFolders) > 1
  1693. ) {
  1694. $column_show[] = 1;
  1695. }
  1696. $column_show[] = 1;
  1697. $column_show[] = 1;
  1698. $column_show[] = 1;
  1699. $column_show[] = 1;
  1700. if ($is_allowed_to_edit
  1701. || $group_member_with_upload_rights
  1702. || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1703. ) {
  1704. $column_show[] = 1;
  1705. }
  1706. $column_show[] = 0;
  1707. $column_show[] = 0;
  1708. $column_order = array();
  1709. if (count($row) == 12) {
  1710. //teacher
  1711. $column_order[2] = 8; //name
  1712. $column_order[3] = 7;
  1713. $column_order[4] = 6;
  1714. } elseif (count($row) == 10) {
  1715. //student
  1716. $column_order[1] = 6;
  1717. $column_order[2] = 5;
  1718. $column_order[3] = 4;
  1719. }
  1720. $default_column = $is_allowed_to_edit ? 2 : 1;
  1721. $tableName = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
  1722. $table = new SortableTableFromArrayConfig(
  1723. $sortable_data,
  1724. $default_column,
  1725. 20,
  1726. $tableName,
  1727. $column_show,
  1728. $column_order,
  1729. 'ASC',
  1730. true
  1731. );
  1732. $query_vars = array();
  1733. if (isset($_GET['keyword'])) {
  1734. $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
  1735. } else {
  1736. $query_vars['curdirpath'] = $curdirpath;
  1737. }
  1738. if ($groupId) {
  1739. $query_vars['gidReq'] = $groupId;
  1740. }
  1741. $query_vars['cidReq'] = api_get_course_id();
  1742. $table->set_additional_parameters($query_vars);
  1743. $column = 0;
  1744. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1745. $table->set_header($column++, '', false, array('style' => 'width:12px;'));
  1746. }
  1747. $table->set_header($column++, get_lang('Type'), true, array('style' => 'width:30px;'));
  1748. $table->set_header($column++, get_lang('Name'));
  1749. $table->set_header($column++, get_lang('Size'), true, array('style' => 'width:50px;'));
  1750. $table->set_header($column++, get_lang('Date'), true, array('style' => 'width:150px;'));
  1751. // Admins get an edit column
  1752. if ($is_allowed_to_edit
  1753. || $group_member_with_upload_rights
  1754. || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
  1755. $table->set_header($column++, get_lang('Actions'), false, array('class' => 'td_actions'));
  1756. }
  1757. // Actions on multiple selected documents
  1758. // TODO: Currently only delete action -> take only DELETE permission into account
  1759. if (count($documentAndFolders) > 1) {
  1760. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1761. $form_actions = array();
  1762. $form_action['set_invisible'] = get_lang('SetInvisible');
  1763. $form_action['set_visible'] = get_lang('SetVisible');
  1764. $form_action['delete'] = get_lang('Delete');
  1765. $portfolio_actions = Portfolio::actions();
  1766. foreach ($portfolio_actions as $action) {
  1767. $form_action[$action->get_name()] = $action->get_title();
  1768. }
  1769. $table->set_form_actions($form_action, 'ids');
  1770. }
  1771. }
  1772. Display::display_header('', 'Doc');
  1773. /* Introduction section (editable by course admins) */
  1774. if (!empty($groupId)) {
  1775. Display::display_introduction_section(TOOL_DOCUMENT.$groupId);
  1776. } else {
  1777. Display::display_introduction_section(TOOL_DOCUMENT);
  1778. }
  1779. $toolbar = Display::toolbarAction(
  1780. 'toolbar-document',
  1781. array(0 => $actionsLeft, 1 => $actionsRight)
  1782. );
  1783. echo $toolbar;
  1784. echo $templateForm;
  1785. echo $moveForm;
  1786. echo $dirForm;
  1787. echo $selector;
  1788. $table->display();
  1789. if (count($documentAndFolders) > 1) {
  1790. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1791. // Getting the course quota
  1792. $course_quota = DocumentManager::get_course_quota();
  1793. // Calculating the total space
  1794. $already_consumed_space_course = DocumentManager::documents_total_space(
  1795. api_get_course_int_id()
  1796. );
  1797. // Displaying the quota
  1798. DocumentManager::display_simple_quota(
  1799. $course_quota,
  1800. $already_consumed_space_course
  1801. );
  1802. }
  1803. }
  1804. if (!empty($table_footer)) {
  1805. Display::display_warning_message($table_footer);
  1806. }
  1807. echo '
  1808. <div id="convertModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
  1809. <div class="modal-dialog">
  1810. <div class="modal-content">
  1811. <div class="modal-header" style="text-align: center;">
  1812. <button type="button" class="close" data-dismiss="modal">
  1813. <span aria-hidden="true">&times;</span>
  1814. <span class="sr-only">' . get_lang('Close') . '</span>
  1815. </button>
  1816. <h4 class="modal-title">' . get_lang('PleaseSelectConvertFormat') . '</h4>
  1817. </div>
  1818. <div class="modal-body" style="text-align: center;">
  1819. <p>' . get_lang('ConvertFormats') . '&hellip;</p>
  1820. <select id="convertSelect" class="input-lg text-center">
  1821. <option value="">
  1822. ' . get_lang('SelectConvertFormat') . '
  1823. </option>
  1824. <option value="pdf">
  1825. PDF - Portable Document File
  1826. </option>
  1827. <option value="odt" style="display:none;" class="textFormatType">
  1828. ODT - Open Document Text
  1829. </option>
  1830. <option value="odp" style="display:none;" class="presentationFormatType">
  1831. ODP - Open Document Portable
  1832. </option>
  1833. <option value="ods" style="display:none;" class="spreadsheetFormatType">
  1834. ODS - Open Document Spreadsheet
  1835. </option>
  1836. </select>
  1837. </div>
  1838. <div class="modal-footer">
  1839. <button type="button" class="btn btn-default" data-dismiss="modal">' . get_lang('Close') . '</button>
  1840. </div>
  1841. </div>
  1842. </div>
  1843. </div>';
  1844. // Footer
  1845. Display::display_footer();