document.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Homepage script for the documents tool
  5. *
  6. * This script allows the user to manage files and directories on a remote http
  7. * server.
  8. * The user can : - navigate through files and directories.
  9. * - upload a file
  10. * - delete, copy a file or a directory
  11. * - edit properties & content (name, comments, html content)
  12. * The script is organised in four sections.
  13. *
  14. * 1) Execute the command called by the user
  15. * Note: somme commands of this section are organised in two steps.
  16. * The script always begins with the second step,
  17. * so it allows to return more easily to the first step.
  18. *
  19. * Note (March 2004) some editing functions (renaming, commenting)
  20. * are moved to a separate page, edit_document.php. This is also
  21. * where xml and other stuff should be added.
  22. * 2) Define the directory to display
  23. * 3) Read files and directories from the directory defined in part 2
  24. * 4) Display all of that on an HTML page
  25. *
  26. *
  27. * @package chamilo.document
  28. */
  29. /**
  30. * Code
  31. */
  32. // Language files that need to be included
  33. $language_file = array('document', 'slideshow', 'gradebook', 'create_course');
  34. require_once '../inc/global.inc.php';
  35. $current_course_tool = TOOL_DOCUMENT;
  36. $this_section = SECTION_COURSES;
  37. require_once 'document.inc.php';
  38. $lib_path = api_get_path(LIBRARY_PATH);
  39. api_protect_course_script(true);
  40. $to_user_id = api_get_user_id();
  41. //erase temp nanogons' audio, image edit
  42. if (isset($_SESSION['temp_audio_nanogong']) && !empty($_SESSION['temp_audio_nanogong'])) {
  43. unlink($_SESSION['temp_audio_nanogong']);
  44. }
  45. if (isset($_SESSION['temp_realpath_image']) && !empty($_SESSION['temp_realpath_image'])) {
  46. unlink($_SESSION['temp_realpath_image']);
  47. }
  48. //Removing sessions
  49. unset($_SESSION['draw_dir']);
  50. unset($_SESSION['paint_dir']);
  51. unset($_SESSION['temp_audio_nanogong']);
  52. // Create directory certificates
  53. DocumentManager::create_directory_certificate_in_course(api_get_course_id());
  54. $course_info = api_get_course_info();
  55. if (empty($course_info)) {
  56. api_not_allowed(true);
  57. }
  58. $course_dir = $course_info['path'].'/document';
  59. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  60. $base_work_dir = $sys_course_path.$course_dir;
  61. $http_www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
  62. $dbl_click_id = 0; // Used for avoiding double-click
  63. $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
  64. /* Constants and variables */
  65. $session_id = api_get_session_id();
  66. $course_code = api_get_course_id();
  67. $to_group_id = api_get_group_id();
  68. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  69. $group_member_with_upload_rights = false;
  70. // If the group id is set, we show them group documents
  71. $group_properties = array();
  72. $group_properties['directory'] = null;
  73. // For sessions we should check the parameters of visibility
  74. if (api_get_session_id() != 0) {
  75. $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true);
  76. }
  77. //Setting group variables
  78. if (api_get_group_id()) {
  79. // Get group info
  80. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  81. $noPHP_SELF = true;
  82. // Let's assume the user cannot upload files for the group
  83. $group_member_with_upload_rights = false;
  84. if ($group_properties['doc_state'] == 2) {
  85. // Documents are private
  86. if ($is_allowed_to_edit || GroupManager :: is_user_in_group(api_get_user_id(), api_get_group_id())) {
  87. // Only courseadmin or group members (members + tutors) allowed
  88. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  89. $interbreadcrumb[] = array(
  90. 'url' => '../group/group_space.php?gidReq='.api_get_group_id(),
  91. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  92. );
  93. //they are allowed to upload
  94. $group_member_with_upload_rights = true;
  95. } else {
  96. $to_group_id = 0;
  97. }
  98. } elseif ($group_properties['doc_state'] == 1) {
  99. // Documents are public
  100. $to_group_id = api_get_group_id();
  101. $interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
  102. $interbreadcrumb[] = array(
  103. 'url' => '../group/group_space.php?gidReq='.api_get_group_id(),
  104. 'name' => get_lang('GroupSpace').' '.$group_properties['name']
  105. );
  106. //allowed to upload?
  107. if ($is_allowed_to_edit || GroupManager::is_subscribed(api_get_user_id(), api_get_group_id())) {
  108. // Only courseadmin or group members can upload
  109. $group_member_with_upload_rights = true;
  110. }
  111. } else { // Documents not active for this group
  112. $to_group_id = 0;
  113. }
  114. $_SESSION['group_member_with_upload_rights'] = $group_member_with_upload_rights;
  115. } else {
  116. $_SESSION['group_member_with_upload_rights'] = false;
  117. $to_group_id = 0;
  118. }
  119. //Actions
  120. $document_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  121. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  122. $message = '';
  123. if (Portfolio::controller()->accept()) {
  124. Portfolio::controller()->run();
  125. }
  126. switch ($action) {
  127. case 'download':
  128. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  129. // Check whether the document is in the database
  130. if (empty($document_data)) {
  131. api_not_allowed();
  132. }
  133. // Launch event
  134. event_download($document_data['url']);
  135. // Check visibility of document and paths
  136. if (!($is_allowed_to_edit || $group_member_with_upload_rights) && !DocumentManager::is_visible_by_id(
  137. $document_id,
  138. $course_info,
  139. api_get_session_id(),
  140. api_get_user_id()
  141. )
  142. ) {
  143. api_not_allowed(true);
  144. }
  145. $full_file_name = $base_work_dir.$document_data['path'];
  146. if (Security::check_abs_path($full_file_name, $base_work_dir.'/')) {
  147. DocumentManager::file_send_for_download($full_file_name, true);
  148. }
  149. exit;
  150. break;
  151. case 'downloadfolder' :
  152. if (api_get_setting('students_download_folders') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin(
  153. )
  154. ) {
  155. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  156. //filter when I am into shared folder, I can donwload only my shared folder
  157. if (is_any_user_shared_folder($document_data['path'], $session_id)) {
  158. if (is_my_shared_folder(
  159. api_get_user_id(),
  160. $document_data['path'],
  161. $session_id
  162. ) || api_is_allowed_to_edit() || api_is_platform_admin()
  163. ) {
  164. require 'downloadfolder.inc.php';
  165. }
  166. } else {
  167. require 'downloadfolder.inc.php';
  168. }
  169. exit;
  170. }
  171. break;
  172. case 'export_to_pdf' :
  173. if (api_get_setting('students_export2pdf') == 'true' || api_is_allowed_to_edit() || api_is_platform_admin()) {
  174. DocumentManager::export_to_pdf($document_id, $course_code);
  175. }
  176. break;
  177. case 'copytomyfiles':
  178. // Copy a file to general my files user's
  179. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0 && !api_is_anonymous()
  180. ) {
  181. $document_info = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
  182. $parent_id = $document_info['parent_id'];
  183. $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', true);
  184. $user_folder = $my_path['dir'].'my_files/';
  185. $my_path = null;
  186. if (!file_exists($user_folder)) {
  187. $perm = api_get_permissions_for_new_directories();
  188. @mkdir($user_folder, $perm, true);
  189. }
  190. $file = $sys_course_path.$course_info['path'].'/document'.$document_info['path'];
  191. $copyfile = $user_folder.basename($document_info['path']);
  192. $cidReq = Security::remove_XSS($_GET['cidReq']);
  193. $id_session = Security::remove_XSS($_GET['id_session']);
  194. $gidReq = Security::remove_XSS($_GET['gidReq']);
  195. $id = Security::remove_XSS($_GET['id']);
  196. if (empty($parent_id)) {
  197. $parent_id = 0;
  198. }
  199. $file_link = Display::url(
  200. get_lang('SeeFile'),
  201. api_get_path(
  202. WEB_CODE_PATH
  203. ).'social/myfiles.php?cidReq='.$cidReq.'&amp;id_session='.$id_session.'&amp;gidReq='.$gidReq.'&amp;parent_id='.$parent_id
  204. );
  205. if (file_exists($copyfile)) {
  206. $message = get_lang('CopyAlreadyDone').'</p><p>';
  207. $message .= '<a class = "btn" href="'.api_get_self().'?'.api_get_cidreq(
  208. ).'&amp;id='.$parent_id.'">'.get_lang("No").'</a>&nbsp;&nbsp;|&nbsp;&nbsp;
  209. <a class = "btn" href="'.api_get_self().'?'.api_get_cidreq(
  210. ).'&amp;action=copytomyfiles&amp;id='.$document_info['id'].'&amp;copy=yes">'.get_lang('Yes').'</a></p>';
  211. if (!isset($_GET['copy'])) {
  212. $message = Display::return_message($message, 'warning', false);
  213. } var_dump($file, $copyfile);exit;
  214. if (Security::remove_XSS($_GET['copy']) == 'yes') {
  215. if (!copy($file, $copyfile)) {
  216. $message = Display::return_message(get_lang('CopyFailed'), 'error');
  217. } else {
  218. $message = Display::return_message(
  219. get_lang('OverwritenFile').' '.$file_link,
  220. 'confirmation',
  221. false
  222. );
  223. }
  224. }
  225. } else {
  226. if (!copy($file, $copyfile)) {
  227. $message = Display::return_message(get_lang('CopyFailed'), 'error');
  228. } else {
  229. $message = Display::return_message(get_lang('CopyMade').' '.$file_link, 'confirmation', false);
  230. }
  231. }
  232. }
  233. break;
  234. }
  235. // I'm in the certification module?
  236. $is_certificate_mode = false;
  237. if (isset($_GET['curdirpath'])) {
  238. $is_certificate_mode = DocumentManager::is_certificate_mode($_GET['curdirpath']);
  239. }
  240. if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
  241. $is_certificate_mode = true;
  242. }
  243. //If no actions we proceed to show the document (Hack in order to use document.php?id=X)
  244. if (isset($document_id) && empty($action)) {
  245. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  246. //If the document is not a folder we show the document
  247. if ($document_data) {
  248. $parent_id = $document_data['parent_id'];
  249. //$visibility = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
  250. $visibility = DocumentManager::check_visibility_tree(
  251. $document_id,
  252. api_get_course_id(),
  253. api_get_session_id(),
  254. api_get_user_id()
  255. );
  256. if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
  257. if ($visibility && api_is_allowed_to_session_edit()) {
  258. $url = api_get_path(
  259. WEB_COURSE_PATH
  260. ).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();
  261. header("Location: $url");
  262. }
  263. exit;
  264. } else {
  265. if (!$visibility && !api_is_allowed_to_edit()) {
  266. api_not_allowed();
  267. }
  268. }
  269. $_GET['curdirpath'] = $document_data['path'];
  270. }
  271. // What's the current path?
  272. // We will verify this a bit further down
  273. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  274. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  275. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  276. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  277. } else {
  278. $curdirpath = '/';
  279. }
  280. $curdirpathurl = urlencode($curdirpath);
  281. } else {
  282. // What's the current path?
  283. // We will verify this a bit further down
  284. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
  285. $curdirpath = Security::remove_XSS($_GET['curdirpath']);
  286. } elseif (isset($_POST['curdirpath']) && $_POST['curdirpath'] != '') {
  287. $curdirpath = Security::remove_XSS($_POST['curdirpath']);
  288. } else {
  289. $curdirpath = '/';
  290. }
  291. $curdirpathurl = urlencode($curdirpath);
  292. // Check the path
  293. // If the path is not found (no document id), set the path to /
  294. $document_id = DocumentManager::get_document_id($course_info, $curdirpath);
  295. if (!$document_id) {
  296. $document_id = DocumentManager::get_document_id($course_info, $curdirpath);
  297. }
  298. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
  299. $parent_id = $document_data['parent_id'];
  300. }
  301. if (isset($document_data) && $document_data['path'] == '/certificates') {
  302. $is_certificate_mode = true;
  303. }
  304. if (!$parent_id) {
  305. $parent_id = 0;
  306. }
  307. $current_folder_id = $document_id;
  308. // Show preview
  309. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(
  310. intval($_GET['set_preview'])
  311. )
  312. ) {
  313. if (isset($_GET['set_preview'])) {
  314. // Generate document HTML
  315. $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), api_get_course_id(), true);
  316. $filename = 'certificate_preview/'.api_get_unique_id().'.png';
  317. $qr_code_filename = api_get_path(SYS_ARCHIVE_PATH).$filename;
  318. $temp_folder = api_get_path(SYS_ARCHIVE_PATH).'certificate_preview';
  319. if (!is_dir($temp_folder)) {
  320. mkdir($temp_folder, api_get_permissions_for_new_directories());
  321. }
  322. $qr_code_web_filename = api_get_path(WEB_ARCHIVE_PATH).$filename;
  323. $certificate = new Certificate();
  324. $text = $certificate->parse_certificate_variables($content_html['variables']);
  325. $result = $certificate->generate_qr($text, $qr_code_filename);
  326. $new_content_html = $content_html['content'];
  327. $path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
  328. $new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
  329. $path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document';
  330. $new_content_html = str_replace(
  331. '/main/default_course_document',
  332. $path_image_in_default_course,
  333. $new_content_html
  334. );
  335. $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
  336. Display::display_reduced_header();
  337. echo '<style>body {background:none;}</style><style media="print" type="text/css"> #print_div { visibility:hidden; } </style>';
  338. echo '<a href="javascript:window.print();" style="float:right; padding:4px;" id="print_div"><img src="../img/printmgr.gif" alt="'.get_lang(
  339. 'Print'
  340. ).'"/>'.get_lang('Print').'</a>';
  341. if (is_file($qr_code_filename) && is_readable($qr_code_filename)) {
  342. $new_content_html = str_replace(
  343. '((certificate_barcode))',
  344. Display::img($qr_code_web_filename),
  345. $new_content_html
  346. );
  347. }
  348. print_r($new_content_html);
  349. exit;
  350. }
  351. }
  352. // Is the document tool visible?
  353. // Check whether the tool is actually visible
  354. $table_course_tool = Database::get_course_table(TABLE_TOOL_LIST);
  355. $course_id = api_get_course_int_id();
  356. $tool_sql = 'SELECT visibility FROM '.$table_course_tool.' WHERE c_id = '.$course_id.' AND name = "'.TOOL_DOCUMENT.'" LIMIT 1';
  357. $tool_result = Database::query($tool_sql);
  358. $tool_row = Database::fetch_array($tool_result);
  359. $tool_visibility = $tool_row['visibility'];
  360. if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights)) {
  361. api_not_allowed(true);
  362. }
  363. $htmlHeadXtra[] = "<script>
  364. function confirmation (name) {
  365. if (confirm(\" ".get_lang("AreYouSureToDelete")." \"+ name + \" ?\"))
  366. {return true;}
  367. else
  368. {return false;}
  369. }
  370. </script>";
  371. // If they are looking at group documents they can't see the root
  372. if ($to_group_id != 0 && $curdirpath == '/') {
  373. $curdirpath = $group_properties['directory'];
  374. $curdirpathurl = urlencode($group_properties['directory']);
  375. }
  376. // Check visibility of the current dir path. Don't show anything if not allowed
  377. //@todo check this validation for coaches
  378. //if (!$is_allowed_to_edit || api_is_coach()) { before
  379. if (!$is_allowed_to_edit && api_is_coach()) {
  380. if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $course_info, api_get_session_id(), 'folder'))) {
  381. api_not_allowed(true);
  382. }
  383. }
  384. /* Create shared folders */
  385. if ($session_id == 0) {
  386. //Create shared folder. Necessary for courses recycled. Allways session_id should be zero. Allway should be created from a base course, never from a session.
  387. if (!file_exists($base_work_dir.'/shared_folder')) {
  388. $usf_dir_title = get_lang('UserFolders');
  389. $usf_dir_name = '/shared_folder';
  390. $to_group_id = 0;
  391. $visibility = 0;
  392. FileManager::create_unexisting_directory(
  393. $course_info,
  394. api_get_user_id(),
  395. api_get_session_id(),
  396. $to_group_id,
  397. $to_user_id,
  398. $base_work_dir,
  399. $usf_dir_name,
  400. $usf_dir_title,
  401. $visibility
  402. );
  403. }
  404. // Create dynamic user shared folder
  405. if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) {
  406. $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']);
  407. $usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id();
  408. $to_group_id = 0;
  409. $visibility = 1;
  410. FileManager::create_unexisting_directory(
  411. $course_info,
  412. api_get_user_id(),
  413. api_get_session_id(),
  414. $to_group_id,
  415. $to_user_id,
  416. $base_work_dir,
  417. $usf_dir_name,
  418. $usf_dir_title,
  419. $visibility
  420. );
  421. }
  422. } else {
  423. //Create shared folder session
  424. if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id)) {
  425. $usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($session_id).')';
  426. $usf_dir_name = '/shared_folder_session_'.$session_id;
  427. $to_group_id = 0;
  428. $visibility = 0;
  429. FileManager::create_unexisting_directory(
  430. $course_info,
  431. api_get_user_id(),
  432. api_get_session_id(),
  433. $to_group_id,
  434. $to_user_id,
  435. $base_work_dir,
  436. $usf_dir_name,
  437. $usf_dir_title,
  438. $visibility
  439. );
  440. }
  441. //Create dynamic user shared folder into a shared folder session
  442. if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id())) {
  443. $usf_dir_title = api_get_person_name($_user['firstName'], $_user['lastName']).'('.api_get_session_name(
  444. $session_id
  445. ).')';
  446. $usf_dir_name = '/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id();
  447. $to_group_id = 0;
  448. $visibility = 1;
  449. FileManager::create_unexisting_directory(
  450. $course_info,
  451. api_get_user_id(),
  452. api_get_session_id(),
  453. $to_group_id,
  454. $to_user_id,
  455. $base_work_dir,
  456. $usf_dir_name,
  457. $usf_dir_title,
  458. $visibility
  459. );
  460. }
  461. }
  462. /* MAIN SECTION */
  463. // Slideshow inititalisation
  464. $_SESSION['image_files_only'] = '';
  465. $image_files_only = '';
  466. if ($is_certificate_mode) {
  467. $interbreadcrumb[] = array('url' => '../gradebook/index.php', 'name' => get_lang('Gradebook'));
  468. } else {
  469. if ((isset($_GET['id']) && $_GET['id'] != 0) || isset($_GET['curdirpath']) || isset($_GET['createdir'])) {
  470. $interbreadcrumb[] = array('url' => 'document.php', 'name' => get_lang('Documents'));
  471. } else {
  472. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Documents'));
  473. }
  474. }
  475. // Interbreadcrumb for the current directory root path
  476. if (empty($document_data['parents'])) {
  477. if (isset($_GET['createdir'])) {
  478. $interbreadcrumb[] = array('url' => $document_data['document_url'], 'name' => $document_data['title']);
  479. } else {
  480. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  481. }
  482. } else {
  483. $counter = 0;
  484. foreach ($document_data['parents'] as $document_sub_data) {
  485. //fixing double group folder in breadcrumb
  486. if (api_get_group_id()) {
  487. if ($counter == 0) {
  488. $counter++;
  489. continue;
  490. }
  491. }
  492. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  493. $document_sub_data['document_url'] = '#';
  494. }
  495. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  496. $counter++;
  497. }
  498. }
  499. if (isset($_GET['createdir'])) {
  500. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateDir'));
  501. }
  502. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  503. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
  504. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  505. //$htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.inspector.js"></script>';
  506. $mediaplayer_path = api_get_path(WEB_LIBRARY_PATH).'mediaplayer/player.swf';
  507. $docs_and_folders = DocumentManager::get_all_document_data(
  508. $course_info,
  509. $curdirpath,
  510. $to_group_id,
  511. null,
  512. $is_allowed_to_edit || $group_member_with_upload_rights,
  513. false
  514. );
  515. $count = 1;
  516. $jquery = null;
  517. if (!empty($docs_and_folders)) {
  518. foreach ($docs_and_folders as $file) {
  519. if ($file['filetype'] == 'file') {
  520. $path_info = pathinfo($file['path']);
  521. $extension = strtolower($path_info['extension']);
  522. //@todo use a js loop to autogenerate this code
  523. if (in_array($extension, array('ogg', 'mp3', 'wav'))) {
  524. $document_data = DocumentManager::get_document_data_by_id($file['id'], api_get_course_id());
  525. if ($extension == 'ogg') {
  526. $extension = 'oga';
  527. }
  528. //$("#jplayer_inspector_'.$count.'").jPlayerInspector({jPlayer:$("#jquery_jplayer_'.$count.'")});
  529. $params = array(
  530. 'url' => $document_data['direct_url'],
  531. 'extension' => $extension,
  532. 'count' => $count
  533. );
  534. $jquery .= DocumentManager::generate_jplayer_jquery($params);
  535. $count++;
  536. }
  537. }
  538. }
  539. }
  540. $htmlHeadXtra[] = '<script>
  541. $(document).ready( function() {
  542. //Experimental changes to preview mp3, ogg files
  543. '.$jquery.'
  544. });
  545. </script>';
  546. Display::display_header('', 'Doc');
  547. // Lib for event log, stats & tracking & record of the access
  548. event_access_tool(TOOL_DOCUMENT);
  549. /* DISPLAY */
  550. if ($to_group_id != 0) { // Add group name after for group documents
  551. $add_group_to_title = ' ('.$group_properties['name'].')';
  552. }
  553. /* Introduction section (editable by course admins) */
  554. if (!empty($to_group_id)) {
  555. Display::display_introduction_section(TOOL_DOCUMENT.$to_group_id);
  556. } else {
  557. Display::display_introduction_section(TOOL_DOCUMENT);
  558. }
  559. // ACTION MENU
  560. $moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null;
  561. /* MOVE FILE OR DIRECTORY */
  562. //Only teacher and all users into their group and each user into his/her shared folder
  563. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  564. api_get_user_id(),
  565. $curdirpath,
  566. $session_id
  567. ) || is_my_shared_folder(api_get_user_id(), $moveTo, $session_id)
  568. ) {
  569. if (isset($_GET['move']) && $_GET['move'] != '') {
  570. $my_get_move = intval($_REQUEST['move']);
  571. if (api_is_coach()) {
  572. if (!DocumentManager::is_visible_by_id(
  573. $my_get_move,
  574. $course_info,
  575. api_get_session_id(),
  576. api_get_user_id()
  577. )
  578. ) {
  579. api_not_allowed();
  580. }
  581. }
  582. if (!$is_allowed_to_edit) {
  583. if (DocumentManager::check_readonly($course_info, api_get_user_id(), $my_get_move)) {
  584. api_not_allowed();
  585. }
  586. }
  587. $document_to_move = DocumentManager::get_document_data_by_id($my_get_move, api_get_course_id());
  588. $move_path = $document_to_move['path'];
  589. if (!empty($document_to_move)) {
  590. $folders = DocumentManager::get_all_document_folders(
  591. $course_info,
  592. $to_group_id,
  593. $is_allowed_to_edit || $group_member_with_upload_rights
  594. );
  595. //filter if is my shared folder. TODO: move this code to build_move_to_selector function
  596. if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) && !$is_allowed_to_edit) {
  597. $main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id(
  598. ); //only main user shared folder
  599. $main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//'; //all subfolders
  600. $user_shared_folders = array();
  601. foreach ($folders as $fold) {
  602. if ($main_user_shared_folder_main == $fold || preg_match($main_user_shared_folder_sub, $fold)) {
  603. $user_shared_folders[] = $fold;
  604. }
  605. }
  606. echo '<legend>'.get_lang('Move').'</legend>';
  607. echo build_move_to_selector(
  608. $user_shared_folders,
  609. $move_path,
  610. $my_get_move,
  611. $group_properties['directory']
  612. );
  613. } else {
  614. echo '<legend>'.get_lang('Move').'</legend>';
  615. echo build_move_to_selector($folders, $move_path, $my_get_move, $group_properties['directory']);
  616. }
  617. }
  618. }
  619. if (isset($_POST['move_to']) && isset($_POST['move_file'])) {
  620. if (!$is_allowed_to_edit) {
  621. if (DocumentManager::check_readonly($course_info, api_get_user_id(), $_POST['move_file'])) {
  622. api_not_allowed();
  623. }
  624. }
  625. if (api_is_coach()) {
  626. if (!DocumentManager::is_visible_by_id(
  627. $_POST['move_file'],
  628. $_course,
  629. api_get_session_id(),
  630. api_get_user_id()
  631. )
  632. ) {
  633. api_not_allowed();
  634. }
  635. }
  636. $document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id());
  637. // Security fix: make sure they can't move files that are not in the document table
  638. if (!empty($document_to_move)) {
  639. $real_path_target = $base_work_dir.$_POST['move_to'].'/'.basename($document_to_move['path']);
  640. $fileExist = false;
  641. if (file_exists($real_path_target)) {
  642. $fileExist = true;
  643. }
  644. if (FileManager::move($base_work_dir.$document_to_move['path'], $base_work_dir.$_POST['move_to'])) {
  645. FileManager::update_db_info(
  646. 'update',
  647. $document_to_move['path'],
  648. $_POST['move_to'].'/'.basename($document_to_move['path'])
  649. );
  650. //update database item property
  651. $doc_id = $_POST['move_file'];
  652. if (is_dir($real_path_target)) {
  653. api_item_property_update(
  654. $_course,
  655. TOOL_DOCUMENT,
  656. $doc_id,
  657. 'FolderMoved',
  658. api_get_user_id(),
  659. $to_group_id,
  660. null,
  661. null,
  662. null,
  663. $session_id
  664. );
  665. Display::display_confirmation_message(get_lang('DirMv'));
  666. } elseif (is_file($real_path_target)) {
  667. api_item_property_update(
  668. $_course,
  669. TOOL_DOCUMENT,
  670. $doc_id,
  671. 'DocumentMoved',
  672. api_get_user_id(),
  673. $to_group_id,
  674. null,
  675. null,
  676. null,
  677. $session_id
  678. );
  679. Display::display_confirmation_message(get_lang('DocMv'));
  680. }
  681. // Set the current path
  682. $curdirpath = $_POST['move_to'];
  683. $curdirpathurl = urlencode($_POST['move_to']);
  684. } else {
  685. if ($fileExist) {
  686. if (is_dir($real_path_target)) {
  687. Display::display_error_message(get_lang('DirExists'));
  688. } elseif (is_file($real_path_target)) {
  689. Display::display_error_message(get_lang('FileExists'));
  690. }
  691. } else {
  692. Display::display_error_message(get_lang('Impossible'));
  693. }
  694. }
  695. } else {
  696. Display::display_error_message(get_lang('Impossible'));
  697. }
  698. }
  699. }
  700. /* DELETE FILE OR DIRECTORY */
  701. //Only teacher and all users into their group
  702. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  703. api_get_user_id(),
  704. $curdirpath,
  705. $session_id
  706. )
  707. ) {
  708. if (isset($_GET['delete'])) {
  709. if (!$is_allowed_to_edit) {
  710. if (api_is_coach()) {
  711. if (!DocumentManager::is_visible($_GET['delete'], $_course, api_get_session_id())) {
  712. api_not_allowed();
  713. }
  714. }
  715. if (DocumentManager::check_readonly($_course, api_get_user_id(), $_GET['delete'], '', true)) {
  716. api_not_allowed();
  717. }
  718. }
  719. $document_data = DocumentManager::get_document_id($_course, $_GET['delete']);
  720. // Check whether the document is in the database
  721. if (!empty($document_data)) {
  722. if (DocumentManager::delete_document($_course, $_GET['delete'], $base_work_dir)) {
  723. if (isset($_GET['delete_certificate_id']) && $_GET['delete_certificate_id'] == strval(
  724. intval($_GET['delete_certificate_id'])
  725. )
  726. ) {
  727. $default_certificate_id = $_GET['delete_certificate_id'];
  728. DocumentManager::remove_attach_certificate(api_get_course_id(), $default_certificate_id);
  729. }
  730. Display::display_confirmation_message(get_lang('DocDeleted'));
  731. } else {
  732. Display::display_error_message(get_lang('DocDeleteError'));
  733. }
  734. } else {
  735. Display::display_warning_message(get_lang('FileNotFound'));
  736. }
  737. }
  738. if (isset($_POST['action'])) {
  739. switch ($_POST['action']) {
  740. case 'delete':
  741. foreach ($_POST['path'] as $index => & $path) {
  742. if (!$is_allowed_to_edit) {
  743. if (DocumentManager::check_readonly($_course, api_get_user_id(), $path)) {
  744. Display::display_error_message(get_lang('CantDeleteReadonlyFiles'));
  745. break 2;
  746. }
  747. }
  748. }
  749. foreach ($_POST['path'] as $index => & $path) {
  750. if (in_array(
  751. $path,
  752. array('/audio', '/flash', '/images', '/shared_folder', '/video', '/chat_files', '/certificates')
  753. )
  754. ) {
  755. continue;
  756. } else {
  757. $delete_document = DocumentManager::delete_document($_course, $path, $base_work_dir);
  758. }
  759. }
  760. if (!empty($delete_document)) {
  761. Display::display_confirmation_message(get_lang('DocDeleted'));
  762. }
  763. break;
  764. }
  765. }
  766. }
  767. /* CREATE DIRECTORY */
  768. //Only teacher and all users into their group and any user into his/her shared folder
  769. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  770. api_get_user_id(),
  771. $curdirpath,
  772. $session_id
  773. )
  774. ) {
  775. // Create directory with $_POST data
  776. if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
  777. // Needed for directory creation
  778. $post_dir_name = $_POST['dirname'];
  779. if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
  780. Display::display_error_message(get_lang('CannotCreateDir'));
  781. } else {
  782. if (!empty($_POST['dir_id'])) {
  783. $document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
  784. $curdirpath = $document_data['path'];
  785. }
  786. $added_slash = ($curdirpath == '/') ? '' : '/';
  787. $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
  788. $dir_name = FileManager::disable_dangerous_file($dir_name);
  789. $dir_check = $base_work_dir.$dir_name;
  790. if (!is_dir($dir_check)) {
  791. $created_dir = FileManager::create_unexisting_directory(
  792. $_course,
  793. api_get_user_id(),
  794. api_get_session_id(),
  795. $to_group_id,
  796. $to_user_id,
  797. $base_work_dir,
  798. $dir_name,
  799. $post_dir_name
  800. );
  801. if ($created_dir) {
  802. Display::display_confirmation_message(
  803. '<span title="'.$created_dir.'">'.get_lang('DirCr').'</span>',
  804. false
  805. );
  806. // Uncomment if you want to enter the created dir
  807. //$curdirpath = $created_dir;
  808. //$curdirpathurl = urlencode($curdirpath);
  809. } else {
  810. Display::display_error_message(get_lang('CannotCreateDir'));
  811. }
  812. } else {
  813. Display::display_error_message(get_lang('CannotCreateDir'));
  814. }
  815. }
  816. }
  817. // Show them the form for the directory name
  818. if (isset($_GET['createdir'])) {
  819. echo create_dir_form($document_id);
  820. }
  821. }
  822. /* VISIBILITY COMMANDS */
  823. //Only teacher
  824. if ($is_allowed_to_edit) {
  825. if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) || (isset($_GET['set_visible']) && !empty($_GET['set_visible'])) && $_GET['set_visible'] != '*' && $_GET['set_invisible'] != '*') {
  826. // Make visible or invisible?
  827. if (isset($_GET['set_visible'])) {
  828. $update_id = intval($_GET['set_visible']);
  829. $visibility_command = 'visible';
  830. } else {
  831. $update_id = intval($_GET['set_invisible']);
  832. $visibility_command = 'invisible';
  833. }
  834. if (!$is_allowed_to_edit) {
  835. if (api_is_coach()) {
  836. if (!DocumentManager::is_visible_by_id($update_id, $_course, api_get_session_id(), api_get_user_id())) {
  837. api_not_allowed();
  838. }
  839. }
  840. if (DocumentManager::check_readonly($_course, api_get_user_id(), '', $update_id)) {
  841. api_not_allowed();
  842. }
  843. }
  844. // Update item_property to change visibility
  845. if (api_item_property_update(
  846. $_course,
  847. TOOL_DOCUMENT,
  848. $update_id,
  849. $visibility_command,
  850. api_get_user_id(),
  851. null,
  852. null,
  853. null,
  854. null,
  855. $session_id
  856. )
  857. ) {
  858. Display::display_confirmation_message(
  859. get_lang('VisibilityChanged')
  860. ); //don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all)
  861. } else {
  862. Display::display_error_message(get_lang('ViModProb'));
  863. }
  864. }
  865. }
  866. /* TEMPLATE ACTION */
  867. //Only teacher and all users into their group
  868. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  869. api_get_user_id(),
  870. $curdirpath,
  871. $session_id
  872. )
  873. ) {
  874. if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
  875. $document_id_for_template = intval($_GET['add_as_template']);
  876. // Create the form that asks for the directory name
  877. $template_text = '<form name="set_document_as_new_template" enctype="multipart/form-data" action="'.api_get_self(
  878. ).'?add_as_template='.$document_id_for_template.'" method="post">';
  879. $template_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
  880. $template_text .= '<table><tr><td>';
  881. $template_text .= get_lang('TemplateName').' : </td>';
  882. $template_text .= '<td><input type="text" name="template_title" /></td></tr>';
  883. //$template_text .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
  884. //$template_text .= '<td><textarea name="template_description"></textarea></td></tr>';
  885. $template_text .= '<tr><td>'.get_lang('TemplateImage').' : </td>';
  886. $template_text .= '<td><input type="file" name="template_image" id="template_image" /></td></tr>';
  887. $template_text .= '</table>';
  888. $template_text .= '<button type="submit" class="add" name="create_template">'.get_lang(
  889. 'CreateTemplate'
  890. ).'</button>';
  891. $template_text .= '</form>';
  892. // Show the form
  893. Display::display_normal_message($template_text, false);
  894. } elseif (isset($_GET['add_as_template']) && isset($_POST['create_template'])) {
  895. $document_id_for_template = intval(Database::escape_string($_GET['add_as_template']));
  896. $title = Security::remove_XSS($_POST['template_title']);
  897. //$description = Security::remove_XSS($_POST['template_description']);
  898. $user_id = api_get_user_id();
  899. // Create the template_thumbnails folder in the upload folder (if needed)
  900. if (!is_dir(api_get_path(SYS_DATA_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/')) {
  901. @mkdir(api_get_path(SYS_DATA_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/',
  902. api_get_permissions_for_new_directories()
  903. );
  904. }
  905. // Upload the file
  906. if (!empty($_FILES['template_image']['name'])) {
  907. $upload_ok = FileManager::process_uploaded_file($_FILES['template_image']);
  908. if ($upload_ok) {
  909. // Try to add an extension to the file if it hasn't one
  910. $new_file_name = $_course['sysCode'].'-'.FileManager::add_ext_on_mime(
  911. stripslashes($_FILES['template_image']['name']),
  912. $_FILES['template_image']['type']
  913. );
  914. // Upload dir
  915. $upload_dir = api_get_path(SYS_DATA_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/';
  916. // Resize image to max default and end upload
  917. $temp = new Image($_FILES['template_image']['tmp_name']);
  918. $picture_info = $temp->get_image_info();
  919. $max_width_for_picture = 100;
  920. if ($picture_info['width'] > $max_width_for_picture) {
  921. $thumbwidth = $max_width_for_picture;
  922. if (empty($thumbwidth) || $thumbwidth == 0) {
  923. $thumbwidth = $max_width_for_picture;
  924. }
  925. $new_height = round(($thumbwidth / $picture_info['width']) * $picture_info['height']);
  926. $temp->resize($thumbwidth, $new_height, 0);
  927. }
  928. $temp->send_image($upload_dir.$new_file_name);
  929. }
  930. }
  931. DocumentManager::set_document_as_template(
  932. $title,
  933. $description,
  934. $document_id_for_template,
  935. $course_code,
  936. $user_id,
  937. $new_file_name
  938. );
  939. Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
  940. }
  941. if (isset($_GET['remove_as_template'])) {
  942. $document_id_for_template = intval($_GET['remove_as_template']);
  943. $user_id = api_get_user_id();
  944. DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
  945. Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
  946. }
  947. }
  948. // END ACTION MENU
  949. // Attach certificate in the gradebook
  950. if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_certificate']) && $_GET['set_certificate'] == strval(
  951. intval($_GET['set_certificate'])
  952. )
  953. ) {
  954. if (isset($_GET['cidReq'])) {
  955. $course_id = Security::remove_XSS($_GET['cidReq']); // course id
  956. $document_id = Security::remove_XSS($_GET['set_certificate']); // document id
  957. DocumentManager::attach_gradebook_certificate($course_id, $document_id);
  958. Display::display_normal_message(get_lang('IsDefaultCertificate'));
  959. }
  960. }
  961. /* GET ALL DOCUMENT DATA FOR CURDIRPATH */
  962. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  963. $docs_and_folders = DocumentManager::get_all_document_data(
  964. $_course,
  965. $curdirpath,
  966. $to_group_id,
  967. null,
  968. $is_allowed_to_edit || $group_member_with_upload_rights,
  969. true
  970. );
  971. } else {
  972. $docs_and_folders = DocumentManager::get_all_document_data(
  973. $_course,
  974. $curdirpath,
  975. $to_group_id,
  976. null,
  977. $is_allowed_to_edit || $group_member_with_upload_rights,
  978. false
  979. );
  980. }
  981. if (api_get_group_id() != 0) {
  982. if (api_is_allowed_to_edit() || GroupManager::is_subscribed(api_get_user_id(), api_get_group_id()) || GroupManager :: is_tutor_of_group(
  983. api_get_user_id(),
  984. api_get_group_id()
  985. ) || UserManager::is_admin(api_get_user_id())
  986. ) {
  987. $folders = DocumentManager::get_all_document_folders(
  988. $_course,
  989. api_get_group_id(),
  990. $is_allowed_to_edit || $group_member_with_upload_rights
  991. );
  992. }
  993. } else {
  994. $folders = DocumentManager::get_all_document_folders(
  995. $_course,
  996. api_get_group_id(),
  997. $is_allowed_to_edit || $group_member_with_upload_rights
  998. );
  999. }
  1000. //$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit || $group_member_with_upload_rights);
  1001. if ($folders === false) {
  1002. $folders = array();
  1003. }
  1004. echo '<div class="actions">';
  1005. if (!$is_certificate_mode) {
  1006. /* BUILD SEARCH FORM */
  1007. echo '<span style="display:inline-block;">';
  1008. $form = new FormValidator('search_document', 'get', '', '', null, false);
  1009. $renderer = & $form->defaultRenderer();
  1010. $renderer->setElementTemplate('<span>{element}</span> ');
  1011. $form->add_textfield('keyword', '', false, array('class' => 'span2'));
  1012. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  1013. $form->display();
  1014. echo '</span>';
  1015. }
  1016. /* GO TO PARENT DIRECTORY */
  1017. if ($curdirpath != '/' && $curdirpath != $group_properties['directory'] && !$is_certificate_mode) {
  1018. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
  1019. echo Display::display_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM);
  1020. echo '</a>';
  1021. }
  1022. if ($is_certificate_mode && $curdirpath != '/certificates') {
  1023. ?>
  1024. <a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&amp;curdirpath=<?php echo urlencode(
  1025. (dirname($curdirpath) == '\\') ? '/' : dirname($curdirpath)
  1026. ); ?>">
  1027. <?php Display::display_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM); ?></a>
  1028. <?php
  1029. }
  1030. $column_show = array();
  1031. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  1032. api_get_user_id(),
  1033. $curdirpath,
  1034. $session_id
  1035. )
  1036. ) {
  1037. // TODO:check enable more options for shared folders
  1038. /* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
  1039. // Create new document
  1040. if (!$is_certificate_mode) {
  1041. ?>
  1042. <a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1043. <?php Display::display_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM); ?></a>
  1044. <?php
  1045. // Create new draw
  1046. if (api_get_setting('enabled_support_svg') == 'true') {
  1047. if (api_browser_support('svg')) {
  1048. ?>
  1049. <a href="create_draw.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1050. <?php Display::display_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM); ?></a>&nbsp;
  1051. <?php
  1052. } else {
  1053. Display::display_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
  1054. }
  1055. }
  1056. // Create new paint
  1057. if (api_get_setting('enabled_support_pixlr') == 'true') {
  1058. ?>
  1059. <a href="create_paint.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1060. <?php Display::display_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM); ?></a>
  1061. <?php
  1062. }
  1063. // Record an image clip from my webcam
  1064. if (api_get_setting('enable_webcam_clip') == 'true') {
  1065. ?>
  1066. <a href="webcam_clip.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1067. <?php Display::display_icon('webcam.png', get_lang('WebCamClip'), '', ICON_SIZE_MEDIUM); ?></a>
  1068. <?php
  1069. }
  1070. // Record audio (nanogong)
  1071. if (api_get_setting('enable_nanogong') == 'true') {
  1072. ?>
  1073. <a href="record_audio.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1074. <?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
  1075. <?php
  1076. }
  1077. // Record audio (wami record)
  1078. if (api_get_setting('enable_wami_record') == 'true') {
  1079. ?>
  1080. <a href="record_audio_wami.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>">
  1081. <?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
  1082. <?php
  1083. }
  1084. // Create new audio from text
  1085. if (api_get_setting('enabled_text2audio') == 'true') {
  1086. $dt2a = 'google';
  1087. $req_dt2a = '&amp;dt2a='.$dt2a;
  1088. ?>
  1089. <a href="create_audio.php?<?php echo api_get_cidreq(); ?>&amp;id=<?php echo $document_id.$req_dt2a; ?>">
  1090. <?php Display::display_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM); ?></a>
  1091. <?php
  1092. }
  1093. }
  1094. // Create new certificate
  1095. if ($is_certificate_mode) {
  1096. ?>
  1097. <a href="create_document.php?<?php echo api_get_cidreq(
  1098. ); ?>&id=<?php echo $document_id; ?>&certificate=true&selectcat=<?php echo $selectcat; ?>">
  1099. <?php Display::display_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM); ?></a>
  1100. <?php
  1101. }
  1102. // File upload link
  1103. if ($is_certificate_mode) {
  1104. echo '<a href="upload.php?'.api_get_cidreq().'&id='.$current_folder_id.'">';
  1105. echo Display::display_icon(
  1106. 'upload_certificate.png',
  1107. get_lang('UploadCertificate'),
  1108. '',
  1109. ICON_SIZE_MEDIUM
  1110. ).'</a>';
  1111. } else {
  1112. echo '<a href="upload.php?'.api_get_cidreq().'&id='.$current_folder_id.'">';
  1113. echo Display::display_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM).'</a>';
  1114. }
  1115. // Create directory
  1116. if (!$is_certificate_mode) {
  1117. ?>
  1118. <a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id; ?>&createdir=1">
  1119. <?php Display::display_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM); ?></a>
  1120. <?php
  1121. }
  1122. }
  1123. $table_footer = '';
  1124. $total_size = 0;
  1125. if (isset($docs_and_folders) && is_array($docs_and_folders)) {
  1126. if (api_get_group_id() == 0 || (api_is_allowed_to_edit() || GroupManager::is_subscribed(
  1127. api_get_user_id(),
  1128. api_get_group_id()
  1129. ) || GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id()) || UserManager::is_admin(
  1130. api_get_user_id()
  1131. ))
  1132. ) {
  1133. // Create a sortable table with our data
  1134. $sortable_data = array();
  1135. $count = 1;
  1136. foreach ($docs_and_folders as $key => $document_data) {
  1137. $row = array();
  1138. $row['id'] = $document_data['id'];
  1139. $row['type'] = $document_data['filetype'];
  1140. // If the item is invisible, wrap it in a span with class invisible
  1141. $is_visible = DocumentManager::is_visible_by_id(
  1142. $document_data['id'],
  1143. $course_info,
  1144. api_get_session_id(),
  1145. api_get_user_id(),
  1146. false
  1147. );
  1148. $invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
  1149. $invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
  1150. // Size (or total size of a directory)
  1151. $size = $document_data['filetype'] == 'folder' ? FileManager::get_total_folder_size(
  1152. $document_data['path'],
  1153. $is_allowed_to_edit
  1154. ) : $document_data['size'];
  1155. // Get the title or the basename depending on what we're using
  1156. if ($document_data['title'] != '') {
  1157. $document_name = $document_data['title'];
  1158. } else {
  1159. $document_name = basename($document_data['path']);
  1160. }
  1161. $row['name'] = $document_name;
  1162. // Data for checkbox
  1163. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  1164. $row[] = $document_data['path'];
  1165. }
  1166. if (DocumentManager::is_folder_to_avoid($document_data['path'], $is_certificate_mode)) {
  1167. continue;
  1168. }
  1169. // Show the owner of the file only in groups
  1170. $user_link = '';
  1171. if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
  1172. if (!empty($document_data['insert_user_id'])) {
  1173. $user_info = UserManager::get_user_info_by_id($document_data['insert_user_id']);
  1174. $user_name = api_get_person_name($user_info['firstname'], $user_info['lastname']);
  1175. $user_link = '<div class="document_owner">'.get_lang('Owner').': '.display_user_link_document(
  1176. $document_data['insert_user_id'],
  1177. $user_name
  1178. ).'</div>';
  1179. }
  1180. }
  1181. // Icons (clickable)
  1182. $row[] = create_document_link($document_data, true, $count, $is_visible);
  1183. $path_info = pathinfo($document_data['path']);
  1184. if (isset($path_info['extension']) && in_array($path_info['extension'], array('ogg', 'mp3', 'wav'))) {
  1185. $count++;
  1186. }
  1187. // Validacion when belongs to a session
  1188. $session_img = api_get_session_image($document_data['session_id'], $_user['status']);
  1189. // Document title with link
  1190. $row[] = create_document_link(
  1191. $document_data,
  1192. false,
  1193. null,
  1194. $is_visible
  1195. ).$session_img.'<br />'.$invisibility_span_open.'<i>'.nl2br(
  1196. htmlspecialchars($document_data['comment'], ENT_QUOTES, $charset)
  1197. ).'</i>'.$invisibility_span_close.$user_link;
  1198. // Comments => display comment under the document name
  1199. $display_size = Text::format_file_size($size);
  1200. $row[] = '<span style="display:none;">'.$size.'</span>'.$invisibility_span_open.$display_size.$invisibility_span_close;
  1201. // Last edit date
  1202. $last_edit_date = api_get_local_time($document_data['lastedit_date']);
  1203. $display_date = date_to_str_ago(
  1204. $last_edit_date
  1205. ).' <div class="muted"><small>'.$last_edit_date."</small></div>";
  1206. $row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
  1207. // Admins get an edit column
  1208. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  1209. api_get_user_id(),
  1210. $curdirpath,
  1211. $session_id
  1212. )
  1213. ) {
  1214. $is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
  1215. // If readonly, check if it the owner of the file or if the user is an admin
  1216. if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
  1217. $edit_icons = build_edit_icons($document_data, $key, $is_template, 0, $is_visible);
  1218. } else {
  1219. $edit_icons = build_edit_icons(
  1220. $document_data,
  1221. $key,
  1222. $is_template,
  1223. $document_data['readonly'],
  1224. $is_visible
  1225. );
  1226. }
  1227. $row[] = $edit_icons;
  1228. }
  1229. $row[] = $last_edit_date;
  1230. $row[] = $size;
  1231. $row[] = $document_name;
  1232. $total_size = $total_size + $size;
  1233. if ((isset($_GET['keyword']) && search_keyword(
  1234. $document_name,
  1235. $_GET['keyword']
  1236. )) || !isset($_GET['keyword']) || empty($_GET['keyword'])
  1237. ) {
  1238. $sortable_data[] = $row;
  1239. }
  1240. }
  1241. }
  1242. } else {
  1243. $sortable_data = '';
  1244. $table_footer = get_lang('NoDocsInFolder');
  1245. }
  1246. if (!is_null($docs_and_folders)) {
  1247. // Show download zipped folder icon
  1248. global $total_size;
  1249. if (!$is_certificate_mode && $total_size != 0 && (api_get_setting(
  1250. 'students_download_folders'
  1251. ) == 'true' || api_is_allowed_to_edit() || api_is_platform_admin())
  1252. ) {
  1253. //for student does not show icon into other shared folder, and does not show into main path (root)
  1254. if (is_my_shared_folder(
  1255. api_get_user_id(),
  1256. $curdirpath,
  1257. $session_id
  1258. ) && $curdirpath != '/' || api_is_allowed_to_edit() || api_is_platform_admin()
  1259. ) {
  1260. echo '<a href="'.api_get_self().'?'.api_get_cidreq(
  1261. ).'&amp;action=downloadfolder&amp;id='.$document_id.'">'.Display::return_icon(
  1262. 'save_pack.png',
  1263. get_lang('Save').' (ZIP)',
  1264. '',
  1265. ICON_SIZE_MEDIUM
  1266. ).'</a>';
  1267. }
  1268. }
  1269. }
  1270. // Slideshow by Patrick Cool, May 2004
  1271. require 'document_slideshow.inc.php';
  1272. if ($image_present && !isset($_GET['keyword'])) {
  1273. echo '<a href="slideshow.php?'.api_get_cidreq().'&amp;curdirpath='.$curdirpathurl.'">'.Display::return_icon(
  1274. 'slideshow.png',
  1275. get_lang('ViewSlideshow'),
  1276. '',
  1277. ICON_SIZE_MEDIUM
  1278. ).'</a>';
  1279. }
  1280. if (api_is_allowed_to_edit(null, true)) {
  1281. echo '<a href="document_quota.php?'.api_get_cidreq().'">'.Display::return_icon(
  1282. 'percentage.png',
  1283. get_lang('DocumentQuota'),
  1284. '',
  1285. ICON_SIZE_MEDIUM
  1286. ).'</a>';
  1287. }
  1288. echo '</div>'; //end actions
  1289. if (isset($message)) {
  1290. echo $message;
  1291. }
  1292. if (isset($_POST['move_to'])) {
  1293. $document_id = DocumentManager::get_document_id($course_info, $_POST['move_to']);
  1294. }
  1295. if (isset($_GET['createdir']) && isset($_POST['dirname']) && $_POST['dirname'] != '') {
  1296. $post_dir_name = $_POST['dirname'];
  1297. $document_id = DocumentManager::get_document_id($course_info, $_POST['dirname']);
  1298. }
  1299. if (!$is_certificate_mode) {
  1300. echo build_directory_selector(
  1301. $folders,
  1302. $document_id,
  1303. (isset($group_properties['directory']) ? $group_properties['directory'] : array()),
  1304. true
  1305. );
  1306. }
  1307. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  1308. $column_show[] = 1;
  1309. }
  1310. $column_show[] = 1;
  1311. $column_show[] = 1;
  1312. $column_show[] = 1;
  1313. $column_show[] = 1;
  1314. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  1315. api_get_user_id(),
  1316. $curdirpath,
  1317. $session_id
  1318. )
  1319. ) {
  1320. $column_show[] = 1;
  1321. }
  1322. $column_show[] = 0;
  1323. $column_show[] = 0;
  1324. $column_order = array();
  1325. if (isset($row)) {
  1326. if (count($row) == 12) {
  1327. //teacher
  1328. $column_order[2] = 8; //name
  1329. $column_order[3] = 7;
  1330. $column_order[4] = 6;
  1331. } elseif (count($row) == 10) {
  1332. //student
  1333. $column_order[1] = 6;
  1334. $column_order[2] = 5;
  1335. $column_order[3] = 4;
  1336. }
  1337. }
  1338. $default_column = $is_allowed_to_edit ? 2 : 1;
  1339. $tablename = $is_allowed_to_edit ? 'teacher_table' : 'student_table';
  1340. $table = new SortableTableFromArrayConfig($sortable_data, $default_column, 20, $tablename, $column_show, $column_order, 'ASC', true);
  1341. if (isset($_GET['keyword'])) {
  1342. $query_vars['keyword'] = Security::remove_XSS($_GET['keyword']);
  1343. } else {
  1344. $query_vars['curdirpath'] = $curdirpath;
  1345. }
  1346. if (api_get_group_id()) {
  1347. $query_vars['gidReq'] = api_get_group_id();
  1348. }
  1349. $query_vars['cidReq'] = api_get_course_id();
  1350. $table->set_additional_parameters($query_vars);
  1351. $column = 0;
  1352. if (($is_allowed_to_edit || $group_member_with_upload_rights) && count($docs_and_folders) > 1) {
  1353. $table->set_header($column++, '', false, array('style' => 'width:12px;'));
  1354. }
  1355. $table->set_header($column++, get_lang('Type'), true, array('style' => 'width:30px;'));
  1356. $table->set_header($column++, get_lang('Name'));
  1357. $table->set_header($column++, get_lang('Size'), true, array('style' => 'width:50px;'));
  1358. $table->set_header($column++, get_lang('Date'), true, array('style' => 'width:150px;'));
  1359. // Admins get an edit column
  1360. if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(
  1361. api_get_user_id(),
  1362. $curdirpath,
  1363. $session_id
  1364. )
  1365. ) {
  1366. $table->set_header($column++, get_lang('Actions'), false, array('class' => 'td_actions'));
  1367. }
  1368. // Actions on multiple selected documents
  1369. // TODO: Currently only delete action -> take only DELETE right into account
  1370. if (count($docs_and_folders) > 1) {
  1371. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1372. $form_actions = array();
  1373. $form_action['delete'] = get_lang('Delete');
  1374. $portfolio_actions = Portfolio::actions();
  1375. foreach ($portfolio_actions as $action) {
  1376. $form_action[$action->get_name()] = $action->get_title();
  1377. }
  1378. $table->set_form_actions($form_action, 'path');
  1379. }
  1380. }
  1381. $table->display();
  1382. if (count($docs_and_folders) > 1) {
  1383. if ($is_allowed_to_edit || $group_member_with_upload_rights) {
  1384. // Getting the course quota
  1385. $course_quota = DocumentManager::get_course_quota();
  1386. // Calculating the total space
  1387. $already_consumed_space_course = DocumentManager::documents_total_space(api_get_course_int_id());
  1388. // Displaying the quota
  1389. DocumentManager::display_simple_quota($course_quota, $already_consumed_space_course);
  1390. }
  1391. }
  1392. if (!empty($table_footer)) {
  1393. Display::display_warning_message($table_footer);
  1394. }
  1395. // Footer
  1396. Display::display_footer();