document.php 59 KB

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