document.php 75 KB

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