document.php 58 KB

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