document.php 77 KB

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