document.php 77 KB

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