document.php 59 KB

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