document.php 79 KB

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