document.php 58 KB

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