document.php 54 KB

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