document.php 58 KB

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