document.php 58 KB

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