document.php 79 KB

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