document.php 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  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 = null;
  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. Display::addFlash(Display::return_message(get_lang('VisibilityChanged').': '.$data['title'], 'confirmation'));
  1058. } else {
  1059. Display::addFlash(Display::return_message(get_lang('ViModProb'), 'error'));
  1060. }
  1061. header('Location: '.$currentUrl);
  1062. exit;
  1063. break;
  1064. case 'set_visible':
  1065. $visibilityCommand = 'visible';
  1066. if (api_item_property_update(
  1067. $courseInfo,
  1068. TOOL_DOCUMENT,
  1069. $documentId,
  1070. $visibilityCommand,
  1071. api_get_user_id(),
  1072. null,
  1073. null,
  1074. null,
  1075. null,
  1076. $sessionId
  1077. )) {
  1078. Display::addFlash(Display::return_message(get_lang('VisibilityChanged').': '.$data['title'], 'confirmation'));
  1079. } else {
  1080. Display::addFlash(Display::return_message(get_lang('ViModProb'), 'error'));
  1081. }
  1082. header('Location: '.$currentUrl);
  1083. exit;
  1084. break;
  1085. case 'delete':
  1086. // Check all documents scheduled for deletion
  1087. // If one of them is read-only, abandon deletion
  1088. // Note: this is only executed once
  1089. if (!$readonlyAlreadyChecked) {
  1090. foreach ($files as $id) {
  1091. if (!$is_allowed_to_edit) {
  1092. if (DocumentManager::check_readonly(
  1093. $courseInfo,
  1094. api_get_user_id(),
  1095. null,
  1096. $id,
  1097. false,
  1098. $sessionId
  1099. )
  1100. ) {
  1101. $messages .= Display::return_message(
  1102. get_lang('CantDeleteReadonlyFiles'),
  1103. 'error'
  1104. );
  1105. break 2;
  1106. }
  1107. }
  1108. }
  1109. $readonlyAlreadyChecked = true;
  1110. }
  1111. $deleteDocument = DocumentManager::delete_document(
  1112. $courseInfo,
  1113. null,
  1114. $base_work_dir,
  1115. $sessionId,
  1116. $documentId,
  1117. $groupId
  1118. );
  1119. if (!empty($deleteDocument)) {
  1120. $messages .= Display::return_message(
  1121. get_lang('DocDeleted').': '.$data['title'],
  1122. 'confirmation'
  1123. );
  1124. }
  1125. break;
  1126. }
  1127. }
  1128. } // endforeach
  1129. Display::addFlash($messages);
  1130. }
  1131. }
  1132. $dirForm = null;
  1133. /* CREATE DIRECTORY */
  1134. //Only teacher and all users into their group and any user into his/her shared folder
  1135. if ($is_allowed_to_edit ||
  1136. $group_member_with_upload_rights ||
  1137. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1138. ) {
  1139. // Create directory with $_POST data
  1140. if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
  1141. // Needed for directory creation
  1142. $post_dir_name = $_POST['dirname'];
  1143. if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
  1144. $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
  1145. } else {
  1146. // dir_id is the parent folder id.
  1147. if (!empty($_POST['dir_id'])) {
  1148. // Get the document data from the ID
  1149. $document_data = DocumentManager::get_document_data_by_id(
  1150. $_POST['dir_id'],
  1151. api_get_course_id(),
  1152. false,
  1153. $sessionId
  1154. );
  1155. if ($sessionId != 0 && !$document_data) {
  1156. // If there is a session defined and asking for the
  1157. // document * from the session* didn't work, try it from
  1158. // the course (out of a session context)
  1159. $document_data = DocumentManager::get_document_data_by_id(
  1160. $_POST['dir_id'],
  1161. api_get_course_id(),
  1162. false,
  1163. 0
  1164. );
  1165. }
  1166. $curdirpath = $document_data['path'];
  1167. }
  1168. $added_slash = ($curdirpath == '/') ? '' : '/';
  1169. $dir_name = $curdirpath.$added_slash.api_replace_dangerous_char($post_dir_name);
  1170. $dir_name = disable_dangerous_file($dir_name);
  1171. $dir_check = $base_work_dir.$dir_name;
  1172. $visibility = empty($groupId) ? null : 1;
  1173. $newFolderData = create_unexisting_directory(
  1174. $courseInfo,
  1175. api_get_user_id(),
  1176. $sessionId,
  1177. $groupId,
  1178. $to_user_id,
  1179. $base_work_dir,
  1180. $dir_name,
  1181. $post_dir_name,
  1182. $visibility
  1183. );
  1184. if (!empty($newFolderData)) {
  1185. $message = Display::return_message(
  1186. get_lang('DirCr') . ' ' . $newFolderData['title'],
  1187. 'confirmation'
  1188. );
  1189. } else {
  1190. $message = Display::return_message(
  1191. get_lang('CannotCreateDir'),
  1192. 'error'
  1193. );
  1194. }
  1195. }
  1196. Display::addFlash($message);
  1197. }
  1198. // Show them the form for the directory name
  1199. if (isset($_GET['createdir'])) {
  1200. $dirForm = DocumentManager::create_dir_form($document_id);
  1201. }
  1202. }
  1203. /* VISIBILITY COMMANDS */
  1204. if ($is_allowed_to_edit) {
  1205. if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) ||
  1206. (isset($_GET['set_visible']) && !empty($_GET['set_visible']))
  1207. ) {
  1208. // Make visible or invisible?
  1209. if (isset($_GET['set_visible'])) {
  1210. $update_id = intval($_GET['set_visible']);
  1211. $visibility_command = 'visible';
  1212. } else {
  1213. $update_id = intval($_GET['set_invisible']);
  1214. $visibility_command = 'invisible';
  1215. }
  1216. if (!$is_allowed_to_edit) {
  1217. if (api_is_coach()) {
  1218. if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $sessionId, api_get_user_id())) {
  1219. api_not_allowed(true);
  1220. }
  1221. }
  1222. if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $update_id)) {
  1223. api_not_allowed(true);
  1224. }
  1225. }
  1226. // Update item_property to change visibility
  1227. if (api_item_property_update(
  1228. $courseInfo,
  1229. TOOL_DOCUMENT,
  1230. $update_id,
  1231. $visibility_command,
  1232. api_get_user_id(),
  1233. null,
  1234. null,
  1235. null,
  1236. null,
  1237. $sessionId)
  1238. ) {
  1239. Display::addFlash(
  1240. Display::return_message(get_lang('VisibilityChanged'), 'confirmation')
  1241. );
  1242. } else {
  1243. Display::addFlash(
  1244. Display::return_message(get_lang('ViModProb'), 'error')
  1245. );
  1246. }
  1247. header('Location: '.$currentUrl);
  1248. exit;
  1249. }
  1250. }
  1251. $templateForm = null;
  1252. /* TEMPLATE ACTION */
  1253. //Only teacher and all users into their group
  1254. if ($is_allowed_to_edit ||
  1255. $group_member_with_upload_rights ||
  1256. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1257. ) {
  1258. if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
  1259. $document_id_for_template = intval($_GET['add_as_template']);
  1260. // Create the form that asks for the directory name
  1261. $templateForm .= '
  1262. <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">
  1263. <fieldset>
  1264. <legend>' . get_lang('AddAsTemplate') . '</legend>
  1265. <div class="form-group">
  1266. <label for="template_title" class="col-sm-2 control-label">' . get_lang('TemplateName') . '</label>
  1267. <div class="col-sm-10">
  1268. <input type="text" class="form-control" id="template_title" name="template_title">
  1269. </div>
  1270. </div>
  1271. <div class="form-group">
  1272. <label for="template_image" class="col-sm-2 control-label">' . get_lang('TemplateImage') . '</label>
  1273. <div class="col-sm-10">
  1274. <input type="file" name="template_image" id="template_image">
  1275. </div>
  1276. </div>
  1277. <div class="form-group">
  1278. <div class="col-sm-offset-2 col-sm-10">
  1279. <button type="submit" name="create_template" class="btn btn-primary">' . get_lang('CreateTemplate') . '</button>
  1280. </div>
  1281. </div>
  1282. <input type="hidden" name="curdirpath" value="' . $curdirpath . '" />
  1283. </fieldset>
  1284. </form>
  1285. <hr>
  1286. ';
  1287. } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
  1288. $document_id_for_template = intval($_GET['add_as_template']);
  1289. $title = Security::remove_XSS($_POST['template_title']);
  1290. $user_id = api_get_user_id();
  1291. // Create the template_thumbnails folder in the upload folder (if needed)
  1292. if (!is_dir(api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/')) {
  1293. @mkdir(
  1294. api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/',
  1295. api_get_permissions_for_new_directories()
  1296. );
  1297. }
  1298. // Upload the file
  1299. if (!empty($_FILES['template_image']['name'])) {
  1300. $upload_ok = process_uploaded_file($_FILES['template_image']);
  1301. if ($upload_ok) {
  1302. // Try to add an extension to the file if it hasn't one
  1303. $new_file_name = $courseInfo['code'].'-'.add_ext_on_mime(
  1304. stripslashes($_FILES['template_image']['name']),
  1305. $_FILES['template_image']['type']
  1306. );
  1307. // Upload dir
  1308. $upload_dir = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/upload/template_thumbnails/';
  1309. // Resize image to max default and end upload
  1310. $temp = new Image($_FILES['template_image']['tmp_name']);
  1311. $picture_info = $temp->get_image_info();
  1312. $max_width_for_picture = 100;
  1313. if ($picture_info['width'] > $max_width_for_picture) {
  1314. $temp->resize($max_width_for_picture);
  1315. }
  1316. $temp->send_image($upload_dir.$new_file_name);
  1317. }
  1318. }
  1319. DocumentManager::set_document_as_template(
  1320. $title,
  1321. '',
  1322. $document_id_for_template,
  1323. $course_code,
  1324. $user_id,
  1325. $new_file_name
  1326. );
  1327. Display::addFlash(
  1328. Display::return_message(get_lang('DocumentSetAsTemplate'), 'confirmation')
  1329. );
  1330. }
  1331. if (isset($_GET['remove_as_template'])) {
  1332. $document_id_for_template = intval($_GET['remove_as_template']);
  1333. $user_id = api_get_user_id();
  1334. DocumentManager::unset_document_as_template(
  1335. $document_id_for_template,
  1336. $course_code,
  1337. $user_id
  1338. );
  1339. Display::addFlash(
  1340. Display::return_message(get_lang('DocumentUnsetAsTemplate'), 'confirmation')
  1341. );
  1342. }
  1343. }
  1344. // END ACTION MENU
  1345. // Attach certificate in the gradebook
  1346. if (isset($_GET['curdirpath']) &&
  1347. $_GET['curdirpath'] == '/certificates' &&
  1348. isset($_GET['set_certificate']) &&
  1349. $_GET['set_certificate'] == strval(intval($_GET['set_certificate']))
  1350. ) {
  1351. if (isset($_GET['cidReq'])) {
  1352. $course_id = Security::remove_XSS($_GET['cidReq']); // course id
  1353. $document_id = Security::remove_XSS($_GET['set_certificate']); // document id
  1354. DocumentManager::attach_gradebook_certificate($course_id, $document_id);
  1355. $message = Display::return_message(get_lang('IsDefaultCertificate'), 'normal');
  1356. Display::addFlash(
  1357. $message
  1358. );
  1359. }
  1360. }
  1361. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  1362. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  1363. $documentAndFolders = DocumentManager::get_all_document_data(
  1364. $courseInfo,
  1365. $curdirpath,
  1366. $groupId,
  1367. null,
  1368. $is_allowed_to_edit || $group_member_with_upload_rights,
  1369. true
  1370. );
  1371. } else {
  1372. $documentAndFolders = DocumentManager::get_all_document_data(
  1373. $courseInfo,
  1374. $curdirpath,
  1375. $groupId,
  1376. null,
  1377. $is_allowed_to_edit || $group_member_with_upload_rights,
  1378. false
  1379. );
  1380. }
  1381. if ($groupId != 0) {
  1382. $userAccess = GroupManager::user_has_access(
  1383. api_get_user_id(),
  1384. $groupId,
  1385. GroupManager::GROUP_TOOL_DOCUMENTS
  1386. );
  1387. if ($userAccess) {
  1388. $folders = DocumentManager::get_all_document_folders(
  1389. $courseInfo,
  1390. $groupId,
  1391. $is_allowed_to_edit || $group_member_with_upload_rights
  1392. );
  1393. }
  1394. } else {
  1395. $folders = DocumentManager::get_all_document_folders(
  1396. $courseInfo,
  1397. $groupId,
  1398. $is_allowed_to_edit || $group_member_with_upload_rights
  1399. );
  1400. }
  1401. if (!isset($folders) || $folders === false) {
  1402. $folders = array();
  1403. }
  1404. $btngroup = array('class' => 'btn btn-default');
  1405. /* GO TO PARENT DIRECTORY */
  1406. $actionsLeft = '';
  1407. if ($curdirpath != '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
  1408. $actionsLeft = '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
  1409. $actionsLeft .= Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM);
  1410. $actionsLeft .= '</a>';
  1411. }
  1412. if ($is_certificate_mode && $curdirpath != '/certificates') {
  1413. $actionsLeft .= Display::url(
  1414. Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM),
  1415. api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath
  1416. );
  1417. }
  1418. $column_show = array();
  1419. if ($is_allowed_to_edit ||
  1420. $group_member_with_upload_rights ||
  1421. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1422. ) {
  1423. // TODO:check enable more options for shared folders
  1424. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  1425. // Create new document
  1426. if (!$is_certificate_mode) {
  1427. $actionsLeft .= Display::url(
  1428. Display::return_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM),
  1429. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id
  1430. );
  1431. // Create new draw
  1432. if (api_get_setting('enabled_support_svg') == 'true') {
  1433. if (api_browser_support('svg')) {
  1434. $actionsLeft .= Display::url(
  1435. Display::return_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM),
  1436. api_get_path(WEB_CODE_PATH).'document/create_draw.php?'.api_get_cidreq().'&id='.$document_id
  1437. );
  1438. } else {
  1439. $actionsLeft .= Display::return_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
  1440. }
  1441. }
  1442. // Create new paint
  1443. if (api_get_setting('enabled_support_pixlr') == 'true') {
  1444. $actionsLeft .= Display::url(
  1445. Display::return_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM),
  1446. api_get_path(WEB_CODE_PATH).'document/create_paint.php?'.api_get_cidreq().'&id='.$document_id
  1447. );
  1448. }
  1449. // Record an image clip from my webcam
  1450. if (api_get_setting('enable_webcam_clip') == 'true') {
  1451. $actionsLeft .= Display::url(
  1452. Display::return_icon('webcam.png', get_lang('WebCamClip'), '', ICON_SIZE_MEDIUM),
  1453. api_get_path(WEB_CODE_PATH).'document/webcam_clip.php?'.api_get_cidreq().'&id='.$document_id
  1454. );
  1455. }
  1456. // Record audio (nanogong)
  1457. if (api_get_setting('enable_nanogong') == 'true') {
  1458. $actionsLeft .= Display::url(
  1459. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1460. api_get_path(WEB_CODE_PATH).'document/record_audio.php?'.api_get_cidreq().'&id='.$document_id
  1461. );
  1462. }
  1463. // Record audio (wami record)
  1464. if (api_get_setting('enable_wami_record') == 'true') {
  1465. $actionsLeft .= Display::url(
  1466. Display::return_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM),
  1467. api_get_path(WEB_CODE_PATH).'document/record_audio_wami.php?'.api_get_cidreq().'&id='.$document_id
  1468. );
  1469. }
  1470. // Create new audio from text
  1471. if (api_get_setting('enabled_text2audio') == 'true') {
  1472. $dt2a = 'google';
  1473. $req_dt2a = '&amp;dt2a='.$dt2a;
  1474. $actionsLeft .= Display::url(
  1475. Display::return_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM),
  1476. api_get_path(WEB_CODE_PATH).'document/create_audio.php?'.api_get_cidreq().'&id='.$document_id.$req_dt2a
  1477. );
  1478. }
  1479. }
  1480. // Create new certificate
  1481. if ($is_certificate_mode) {
  1482. $actionsLeft .= Display::url(
  1483. Display::return_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM),
  1484. api_get_path(WEB_CODE_PATH).'document/create_document.php?'.api_get_cidreq().'&id='.$document_id.'&certificate=true&selectcat='.$selectcat
  1485. );
  1486. }
  1487. // File upload link
  1488. if ($is_certificate_mode) {
  1489. $actionsLeft .= Display::url(
  1490. Display::return_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM),
  1491. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id.'&certificate=true'
  1492. );
  1493. } else {
  1494. $actionsLeft .= Display::url(
  1495. Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM),
  1496. api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
  1497. );
  1498. }
  1499. /*echo '<a href="#" id="jcapture">';
  1500. echo Display::display_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM).'</a>';*/
  1501. if ($capturePluginInstalled) {
  1502. $actionsLeft .= '<span id="appletplace"></span>';
  1503. $actionsLeft .= Display::url(
  1504. Display::return_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM),
  1505. '#',
  1506. array('id' => 'jcapture')
  1507. );
  1508. }
  1509. // Create directory
  1510. if (!$is_certificate_mode) {
  1511. $actionsLeft .= Display::url(
  1512. Display::return_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM),
  1513. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$document_id.'&createdir=1'
  1514. );
  1515. }
  1516. }
  1517. require 'document_slideshow.inc.php';
  1518. if ($image_present && !isset($_GET['keyword'])) {
  1519. $actionsLeft .= Display::url(
  1520. Display::return_icon('slideshow.png', get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM),
  1521. api_get_path(WEB_CODE_PATH).'document/slideshow.php?'.api_get_cidreq().'&curdirpath='.$curdirpathurl
  1522. );
  1523. }
  1524. if (api_is_allowed_to_edit(null, true)) {
  1525. $actionsLeft .= Display::url(
  1526. Display::return_icon('percentage.png', get_lang('DocumentQuota'), '', ICON_SIZE_MEDIUM),
  1527. api_get_path(WEB_CODE_PATH).'document/document_quota.php?'.api_get_cidreq()
  1528. );
  1529. }
  1530. if (!$is_certificate_mode) {
  1531. /* BUILD SEARCH FORM */
  1532. $form = new FormValidator(
  1533. 'search_document',
  1534. 'get',
  1535. api_get_self().'?'.api_get_cidreq(),
  1536. '',
  1537. array(),
  1538. FormValidator::LAYOUT_INLINE
  1539. );
  1540. $form->addText('keyword', '', false, array('class' => 'col-md-2'));
  1541. $form->addElement('hidden', 'cidReq', api_get_course_id());
  1542. $form->addElement('hidden', 'id_session', api_get_session_id());
  1543. $form->addElement('hidden', 'gidReq', $groupId);
  1544. $form->addButtonSearch(get_lang('Search'));
  1545. $actionsRight = $form->returnForm();
  1546. }
  1547. $table_footer = '';
  1548. $total_size = 0;
  1549. $sortable_data = array();
  1550. if (isset($documentAndFolders) && is_array($documentAndFolders)) {
  1551. if ($groupId == 0 ||
  1552. GroupManager::user_has_access(
  1553. $userId,
  1554. $groupId,
  1555. GroupManager::GROUP_TOOL_DOCUMENTS
  1556. )
  1557. ) {
  1558. $count = 1;
  1559. $countedPaths = array();
  1560. $countedPaths = array();
  1561. foreach ($documentAndFolders as $key => $document_data) {
  1562. $row = array();
  1563. $row['id'] = $document_data['id'];
  1564. $row['type'] = $document_data['filetype'];
  1565. // If the item is invisible, wrap it in a span with class invisible.
  1566. $is_visible = DocumentManager::is_visible_by_id(
  1567. $document_data['id'],
  1568. $courseInfo,
  1569. $sessionId,
  1570. api_get_user_id(),
  1571. false
  1572. );
  1573. $invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
  1574. $invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
  1575. // Size (or total size of a directory)
  1576. $size = $document_data['filetype'] == 'folder' ? get_total_folder_size($document_data['path'], $is_allowed_to_edit) : $document_data['size'];
  1577. // Get the title or the basename depending on what we're using
  1578. if ($document_data['title'] != '') {
  1579. $document_name = $document_data['title'];
  1580. } else {
  1581. $document_name = basename($document_data['path']);
  1582. }
  1583. $row['name'] = $document_name;
  1584. // Data for checkbox
  1585. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1586. $row[] = $document_data['id'];
  1587. }
  1588. if (DocumentManager::is_folder_to_avoid($document_data['path'], $is_certificate_mode)) {
  1589. continue;
  1590. }
  1591. // Show the owner of the file only in groups
  1592. $user_link = '';
  1593. if (!empty($groupId)) {
  1594. if (!empty($document_data['insert_user_id'])) {
  1595. $user_info = api_get_user_info($document_data['insert_user_id']);
  1596. $user_link = '<div class="document_owner">'.
  1597. get_lang('Owner').': '.UserManager::getUserProfileLink($user_info).'</div>';
  1598. }
  1599. }
  1600. // Icons (clickable)
  1601. $row[] = DocumentManager::create_document_link($document_data, true, $count, $is_visible);
  1602. $path_info = pathinfo($document_data['path']);
  1603. if (isset($path_info['extension']) &&
  1604. in_array($path_info['extension'], array('ogg', 'mp3', 'wav'))
  1605. ) {
  1606. $count++;
  1607. }
  1608. // Validation when belongs to a session
  1609. $session_img = api_get_session_image($document_data['session_id'], $_user['status']);
  1610. // Document title with link
  1611. $row[] = DocumentManager::create_document_link($document_data, false, null, $is_visible).
  1612. $session_img.'<br />'.$invisibility_span_open.
  1613. '<i>'.nl2br(htmlspecialchars($document_data['comment'], ENT_QUOTES, $charset)).'</i>'.
  1614. $invisibility_span_close.
  1615. $user_link;
  1616. // Comments => display comment under the document name
  1617. $display_size = format_file_size($size);
  1618. $row[] = '<span style="display:none;">'.$size.'</span>'.
  1619. $invisibility_span_open.
  1620. $display_size.
  1621. $invisibility_span_close;
  1622. // Last edit date
  1623. $last_edit_date = api_get_local_time($document_data['lastedit_date']);
  1624. $display_date = date_to_str_ago($document_data['lastedit_date']).
  1625. ' <div class="muted"><small>'.$last_edit_date."</small></div>";
  1626. $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
  1627. // Admins get an edit column
  1628. if ($is_allowed_to_edit ||
  1629. $groupMemberWithEditRights ||
  1630. DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1631. ) {
  1632. $is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
  1633. // If readonly, check if it the owner of the file or if the user is an admin
  1634. if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
  1635. $edit_icons = DocumentManager::build_edit_icons(
  1636. $document_data,
  1637. $key,
  1638. $is_template,
  1639. 0,
  1640. $is_visible
  1641. );
  1642. } else {
  1643. $edit_icons = DocumentManager::build_edit_icons(
  1644. $document_data,
  1645. $key,
  1646. $is_template,
  1647. $document_data['readonly'],
  1648. $is_visible
  1649. );
  1650. }
  1651. $row[] = $edit_icons;
  1652. } else {
  1653. $row[] = '';
  1654. }
  1655. $row[] = $last_edit_date;
  1656. $row[] = $size;
  1657. $row[] = $document_name;
  1658. $total_size = $total_size + $size;
  1659. if (!isset($countedPaths[$document_data['path']])) {
  1660. $total_size = $total_size + $size;
  1661. $countedPaths[$document_data['path']] = true;
  1662. }
  1663. if ((isset($_GET['keyword']) &&
  1664. DocumentManager::search_keyword($document_name, $_GET['keyword'])) ||
  1665. !isset($_GET['keyword']) || empty($_GET['keyword'])
  1666. ) {
  1667. $sortable_data[] = $row;
  1668. }
  1669. }
  1670. }
  1671. } else {
  1672. $sortable_data = '';
  1673. $table_footer = get_lang('NoDocsInFolder');
  1674. }
  1675. if (!is_null($documentAndFolders)) {
  1676. // Show download zipped folder icon
  1677. global $total_size;
  1678. if (!$is_certificate_mode && $total_size != 0
  1679. && (api_get_setting('students_download_folders') == 'true'
  1680. || api_is_allowed_to_edit()
  1681. || api_is_platform_admin()
  1682. )
  1683. ) {
  1684. //for student does not show icon into other shared folder, and does not show into main path (root)
  1685. if (DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1686. && $curdirpath != '/'
  1687. || api_is_allowed_to_edit()
  1688. || api_is_platform_admin()
  1689. ) {
  1690. $actionsLeft .= Display::url(
  1691. Display::return_icon(
  1692. 'save_pack.png',
  1693. get_lang('Save').' (ZIP)',
  1694. '',
  1695. ICON_SIZE_MEDIUM
  1696. ),
  1697. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&action=downloadfolder&id='.$document_id
  1698. );
  1699. }
  1700. }
  1701. }
  1702. if (api_is_platform_admin()) {
  1703. if (api_get_configuration_value('document_manage_deleted_files')) {
  1704. $actionsLeft .= Display::url(
  1705. get_lang('Recycle'),
  1706. api_get_path(WEB_CODE_PATH).'document/recycle.php?'.api_get_cidreq(),
  1707. array('class' => 'btn btn-default')
  1708. );
  1709. }
  1710. }
  1711. if (!empty($moveTo)) {
  1712. $document_id = DocumentManager::get_document_id($courseInfo, $moveTo);
  1713. }
  1714. if (isset($_GET['createdir']) && isset($_POST['dirname']) && $_POST['dirname'] != '') {
  1715. $post_dir_name = $_POST['dirname'];
  1716. $document_id = DocumentManager::get_document_id($courseInfo, $_POST['dirname']);
  1717. }
  1718. $selector = null;
  1719. if (!$is_certificate_mode) {
  1720. $selector = DocumentManager::build_directory_selector(
  1721. $folders,
  1722. $document_id,
  1723. (isset($group_properties['directory']) ? $group_properties['directory'] : array()),
  1724. true
  1725. );
  1726. }
  1727. if (($is_allowed_to_edit || $group_member_with_upload_rights) &&
  1728. count($documentAndFolders) > 1
  1729. ) {
  1730. $column_show[] = 1;
  1731. }
  1732. $column_show[] = 1;
  1733. $column_show[] = 1;
  1734. $column_show[] = 1;
  1735. $column_show[] = 1;
  1736. if ($is_allowed_to_edit
  1737. || $group_member_with_upload_rights
  1738. || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
  1739. ) {
  1740. $column_show[] = 1;
  1741. }
  1742. $column_show[] = 0;
  1743. $column_show[] = 0;
  1744. $column_order = array();
  1745. if (count($row) == 12) {
  1746. //teacher
  1747. $column_order[2] = 8; //name
  1748. $column_order[3] = 7;
  1749. $column_order[4] = 6;
  1750. } elseif (count($row) == 10) {
  1751. //student
  1752. $column_order[1] = 6;
  1753. $column_order[2] = 5;
  1754. $column_order[3] = 4;
  1755. }
  1756. $default_column = $is_allowed_to_edit ? 2 : 1;
  1757. $tableName = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
  1758. $table = new SortableTableFromArrayConfig(
  1759. $sortable_data,
  1760. $default_column,
  1761. 20,
  1762. $tableName,
  1763. $column_show,
  1764. $column_order,
  1765. 'ASC',
  1766. true
  1767. );
  1768. $query_vars = array();
  1769. if (isset($_GET['keyword'])) {
  1770. $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
  1771. } else {
  1772. $query_vars['curdirpath'] = $curdirpath;
  1773. }
  1774. if ($groupId) {
  1775. $query_vars['gidReq'] = $groupId;
  1776. }
  1777. $query_vars['cidReq'] = api_get_course_id();
  1778. $table->set_additional_parameters($query_vars);
  1779. $column = 0;
  1780. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
  1781. $table->set_header($column++, '', false, array('style' => 'width:12px;'));
  1782. }
  1783. $table->set_header($column++, get_lang('Type'), true, array('style' => 'width:30px;'));
  1784. $table->set_header($column++, get_lang('Name'));
  1785. $table->set_header($column++, get_lang('Size'), true, array('style' => 'width:50px;'));
  1786. $table->set_header($column++, get_lang('Date'), true, array('style' => 'width:150px;'));
  1787. // Admins get an edit column
  1788. if ($is_allowed_to_edit
  1789. || $group_member_with_upload_rights
  1790. || DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
  1791. $table->set_header($column++, get_lang('Actions'), false, array('class' => 'td_actions'));
  1792. }
  1793. // Actions on multiple selected documents
  1794. // TODO: Currently only delete action -> take only DELETE permission into account
  1795. if (count($documentAndFolders) > 1) {
  1796. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1797. $form_actions = array();
  1798. $form_action['set_invisible'] = get_lang('SetInvisible');
  1799. $form_action['set_visible'] = get_lang('SetVisible');
  1800. $form_action['delete'] = get_lang('Delete');
  1801. $portfolio_actions = Portfolio::actions();
  1802. foreach ($portfolio_actions as $action) {
  1803. $form_action[$action->get_name()] = $action->get_title();
  1804. }
  1805. $table->set_form_actions($form_action, 'ids');
  1806. }
  1807. }
  1808. Display::display_header('', 'Doc');
  1809. /* Introduction section (editable by course admins) */
  1810. if (!empty($groupId)) {
  1811. Display::display_introduction_section(TOOL_DOCUMENT.$groupId);
  1812. } else {
  1813. Display::display_introduction_section(TOOL_DOCUMENT);
  1814. }
  1815. $toolbar = Display::toolbarAction(
  1816. 'toolbar-document',
  1817. array(0 => $actionsLeft, 1 => $actionsRight)
  1818. );
  1819. echo $toolbar;
  1820. echo $templateForm;
  1821. echo $moveForm;
  1822. echo $dirForm;
  1823. echo $selector;
  1824. $table->display();
  1825. if (count($documentAndFolders) > 1) {
  1826. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1827. // Getting the course quota
  1828. $course_quota = DocumentManager::get_course_quota();
  1829. // Calculating the total space
  1830. $already_consumed_space_course = DocumentManager::documents_total_space(
  1831. api_get_course_int_id()
  1832. );
  1833. // Displaying the quota
  1834. DocumentManager::display_simple_quota(
  1835. $course_quota,
  1836. $already_consumed_space_course
  1837. );
  1838. }
  1839. }
  1840. if (!empty($table_footer)) {
  1841. Display::display_warning_message($table_footer);
  1842. }
  1843. echo '
  1844. <div id="convertModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
  1845. <div class="modal-dialog">
  1846. <div class="modal-content">
  1847. <div class="modal-header" style="text-align: center;">
  1848. <button type="button" class="close" data-dismiss="modal" aria-label="' . get_lang('Close') . '">
  1849. <span aria-hidden="true">&times;</span>
  1850. </button>
  1851. <h4 class="modal-title">' . get_lang('Convert') . '</h4>
  1852. </div>
  1853. <div class="modal-body">
  1854. <form action="#" class="form-horizontal">
  1855. <div class="form-group">
  1856. <label class="col-sm-4 control-label" for="convertSelect">' . get_lang('ConvertFormats') . '</label>
  1857. <div class="col-sm-8">
  1858. <select id="convertSelect">
  1859. <option value="">' . get_lang('Select') . '</option>
  1860. <option value="pdf">
  1861. PDF - Portable Document File
  1862. </option>
  1863. <option value="odt" style="display:none;" class="textFormatType">
  1864. ODT - Open Document Text
  1865. </option>
  1866. <option value="odp" style="display:none;" class="presentationFormatType">
  1867. ODP - Open Document Portable
  1868. </option>
  1869. <option value="ods" style="display:none;" class="spreadsheetFormatType">
  1870. ODS - Open Document Spreadsheet
  1871. </option>
  1872. </select>
  1873. </div>
  1874. </div>
  1875. </form>
  1876. </div>
  1877. <div class="modal-footer">
  1878. <button type="button" class="btn btn-default" data-dismiss="modal">' . get_lang('Close') . '</button>
  1879. </div>
  1880. </div>
  1881. </div>';
  1882. // Footer
  1883. Display::display_footer();