index.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // The file that contains all the initialisation stuff (and includes all the configuration stuff)
  4. require_once 'dropbox_init.inc.php';
  5. $_course = api_get_course_info();
  6. $last_access = '';
  7. // get the last time the user accessed the tool
  8. if (isset($_SESSION[$_course['id']]) &&
  9. $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == ''
  10. ) {
  11. $last_access = get_last_tool_access(TOOL_DROPBOX);
  12. $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access;
  13. } else {
  14. if (isset($_SESSION[$_course['id']])) {
  15. $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX];
  16. }
  17. }
  18. $postAction = isset($_POST['action']) ? $_POST['action'] : null;
  19. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  20. $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
  21. $viewReceivedCategory = isset($_GET['view_received_category']) ? Security::remove_XSS($_GET['view_received_category']) : null;
  22. $viewSentCategory = isset($_GET['view_sent_category']) ? Security::remove_XSS($_GET['view_sent_category']) : null;
  23. $showSentReceivedTabs = true;
  24. // Do the tracking
  25. Event::event_access_tool(TOOL_DROPBOX);
  26. $logInfo = [
  27. 'tool' => TOOL_DROPBOX,
  28. 'tool_id' => 0,
  29. 'tool_id_detail' => 0,
  30. 'action' => $action,
  31. ];
  32. Event::registerLog($logInfo);
  33. /* DISPLAY SECTION */
  34. Display::display_introduction_section(TOOL_DROPBOX);
  35. // Build URL-parameters for table-sorting
  36. $sort_params = [];
  37. if (isset($_GET['dropbox_column'])) {
  38. $sort_params[] = 'dropbox_column='.intval($_GET['dropbox_column']);
  39. }
  40. if (isset($_GET['dropbox_page_nr'])) {
  41. $sort_params[] = 'page_nr='.intval($_GET['dropbox_page_nr']);
  42. }
  43. if (isset($_GET['dropbox_per_page'])) {
  44. $sort_params[] = 'dropbox_per_page='.intval($_GET['dropbox_per_page']);
  45. }
  46. if (isset($_GET['dropbox_direction']) && in_array($_GET['dropbox_direction'], ['ASC', 'DESC'])) {
  47. $sort_params[] = 'dropbox_direction='.$_GET['dropbox_direction'];
  48. }
  49. $sort_params = Security::remove_XSS(implode('&', $sort_params));
  50. // Display the form for adding a new dropbox item.
  51. if ($action == 'add') {
  52. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  53. api_not_allowed();
  54. }
  55. display_add_form(
  56. $viewReceivedCategory,
  57. $viewSentCategory,
  58. $view
  59. );
  60. }
  61. if (isset($_POST['submitWork'])) {
  62. $check = Security::check_token();
  63. if ($check) {
  64. store_add_dropbox();
  65. }
  66. }
  67. // Display the form for adding a category
  68. if ($action == 'addreceivedcategory' || $action == 'addsentcategory') {
  69. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  70. api_not_allowed();
  71. }
  72. $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : '';
  73. display_addcategory_form($categoryName, '', $_GET['action']);
  74. }
  75. // Editing a category: displaying the form
  76. if ($action == 'editcategory' && isset($_GET['id'])) {
  77. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  78. api_not_allowed();
  79. }
  80. if (!$_POST) {
  81. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  82. api_not_allowed();
  83. }
  84. display_addcategory_form('', $_GET['id'], 'editcategory');
  85. }
  86. }
  87. // Storing a new or edited category
  88. if (isset($_POST['StoreCategory'])) {
  89. if (api_get_session_id() != 0 &&
  90. !api_is_allowed_to_session_edit(false, true)
  91. ) {
  92. api_not_allowed();
  93. }
  94. $return_information = store_addcategory();
  95. if ($return_information['type'] == 'confirmation') {
  96. echo Display::return_message($return_information['message'], 'confirmation');
  97. }
  98. if ($return_information['type'] == 'error') {
  99. echo Display::return_message(
  100. get_lang('The form contains incorrect or incomplete data. Please check your input.').'<br />'.$return_information['message'],
  101. 'error'
  102. );
  103. display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction);
  104. }
  105. }
  106. // Move a File
  107. if (($action == 'movesent' || $action == 'movereceived') && isset($_GET['move_id'])) {
  108. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  109. api_not_allowed();
  110. }
  111. display_move_form(
  112. str_replace('move', '', $action),
  113. $_GET['move_id'],
  114. get_dropbox_categories(str_replace('move', '', $action)),
  115. $sort_params,
  116. $viewReceivedCategory,
  117. $viewSentCategory,
  118. $view
  119. );
  120. }
  121. if (isset($_POST['do_move'])) {
  122. $result = store_move(
  123. $_POST['id'],
  124. $_POST['move_target'],
  125. $_POST['part']
  126. );
  127. echo Display::return_message(
  128. $result,
  129. 'confirm'
  130. );
  131. }
  132. // Delete a file
  133. if (($action == 'deletereceivedfile' || $action == 'deletesentfile') && isset($_GET['id']) && is_numeric($_GET['id'])) {
  134. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  135. api_not_allowed();
  136. }
  137. $dropboxfile = new Dropbox_Person(
  138. api_get_user_id(),
  139. $is_courseAdmin,
  140. $is_courseTutor
  141. );
  142. if ($action == 'deletereceivedfile') {
  143. $dropboxfile->deleteReceivedWork($_GET['id']);
  144. $message = get_lang('The received file has been deleted.');
  145. }
  146. if ($action == 'deletesentfile') {
  147. $dropboxfile->deleteSentWork($_GET['id']);
  148. $message = get_lang('The sent file has been deleted.');
  149. }
  150. echo Display::return_message($message, 'confirmation');
  151. }
  152. // Delete a category
  153. if (($action == 'deletereceivedcategory' || $action == 'deletesentcategory') &&
  154. isset($_GET['id']) && is_numeric($_GET['id'])
  155. ) {
  156. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  157. api_not_allowed();
  158. }
  159. $message = delete_category($action, $_GET['id']);
  160. echo Display::return_message($message, 'confirmation');
  161. }
  162. // Do an action on multiple files
  163. // only the download has is handled separately in
  164. // dropbox_init_inc.php because this has to be done before the headers are sent
  165. // (which also happens in dropbox_init.inc.php
  166. if (!isset($_POST['feedback']) && (
  167. strstr($postAction, 'move_received') ||
  168. strstr($postAction, 'move_sent') ||
  169. $postAction == 'delete_received' ||
  170. $postAction == 'download_received' ||
  171. $postAction == 'delete_sent' ||
  172. $postAction == 'download_sent'
  173. )
  174. ) {
  175. $display_message = handle_multiple_actions();
  176. echo Display::return_message($display_message, 'normal');
  177. }
  178. // Store Feedback
  179. if (isset($_POST['feedback'])) {
  180. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  181. api_not_allowed();
  182. }
  183. $check = Security::check_token();
  184. if ($check) {
  185. $display_message = store_feedback();
  186. echo Display::return_message($display_message, 'normal');
  187. Security::check_token();
  188. }
  189. }
  190. // Error Message
  191. if (isset($_GET['error']) && !empty($_GET['error'])) {
  192. echo Display::return_message(get_lang($_GET['error']), 'normal');
  193. }
  194. $dropbox_data_sent = [];
  195. $movelist = [];
  196. $dropbox_data_recieved = [];
  197. if ($action != 'add') {
  198. // Getting all the categories in the dropbox for the given user
  199. $dropbox_categories = get_dropbox_categories();
  200. // Greating the arrays with the categories for the received files and for the sent files
  201. foreach ($dropbox_categories as $category) {
  202. if ($category['received'] == '1') {
  203. $dropbox_received_category[] = $category;
  204. }
  205. if ($category['sent'] == '1') {
  206. $dropbox_sent_category[] = $category;
  207. }
  208. }
  209. // ACTIONS
  210. if ($view == 'received' || !$showSentReceivedTabs) {
  211. // This is for the categories
  212. if (isset($viewReceivedCategory) && $viewReceivedCategory != '') {
  213. $view_dropbox_category_received = $viewReceivedCategory;
  214. } else {
  215. $view_dropbox_category_received = 0;
  216. }
  217. /* Menu Received */
  218. if (api_get_session_id() == 0) {
  219. echo '<div class="actions">';
  220. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  221. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.
  222. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM).
  223. "</a>";
  224. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  225. $movelist[0] = 'Root'; // move_received selectbox content
  226. } else {
  227. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.
  228. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM).'</a>';
  229. }
  230. echo '</div>';
  231. } else {
  232. if (api_is_allowed_to_session_edit(false, true)) {
  233. echo '<div class="actions">';
  234. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  235. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.
  236. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM)."</a>";
  237. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  238. $movelist[0] = 'Root'; // move_received selectbox content
  239. } else {
  240. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.
  241. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM).
  242. '</a>';
  243. }
  244. echo '</div>';
  245. }
  246. }
  247. }
  248. if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
  249. // This is for the categories
  250. if (isset($viewSentCategory) && $viewSentCategory != '') {
  251. $view_dropbox_category_sent = $viewSentCategory;
  252. } else {
  253. $view_dropbox_category_sent = 0;
  254. }
  255. /* Menu Sent */
  256. if (api_get_session_id() == 0) {
  257. echo '<div class="actions">';
  258. if (empty($viewSentCategory)) {
  259. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".
  260. Display::return_icon('upload_file.png', get_lang('Share a new file'), '', ICON_SIZE_MEDIUM).
  261. "</a>";
  262. }
  263. if ($view_dropbox_category_sent != 0) {
  264. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.
  265. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM).
  266. "</a>";
  267. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  268. } else {
  269. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".
  270. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM)."</a>\n";
  271. }
  272. echo '</div>';
  273. } else {
  274. if (api_is_allowed_to_session_edit(false, true)) {
  275. echo '<div class="actions">';
  276. if (empty($viewSentCategory)) {
  277. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".
  278. Display::return_icon('upload_file.png', get_lang('Share a new file'), '', ICON_SIZE_MEDIUM).
  279. "</a>";
  280. }
  281. if ($view_dropbox_category_sent != 0) {
  282. echo get_lang('You are in folder').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  283. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.
  284. Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('root'), '', ICON_SIZE_MEDIUM).
  285. "</a>";
  286. } else {
  287. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".
  288. Display::return_icon('new_folder.png', get_lang('Add a new folder'), '', ICON_SIZE_MEDIUM)."</a>\n";
  289. }
  290. echo '</div>';
  291. }
  292. }
  293. }
  294. /* THE MENU TABS */
  295. if ($showSentReceivedTabs) {
  296. ?>
  297. <ul class="nav nav-tabs">
  298. <li <?php if (!$view || $view == 'sent') {
  299. echo 'class="active"';
  300. } ?> >
  301. <a href="<?php echo api_get_path(WEB_CODE_PATH).'dropbox/'; ?>index.php?<?php echo api_get_cidreq(); ?>&view=sent" >
  302. <?php echo get_lang('Sent Files'); ?>
  303. </a>
  304. </li>
  305. <li <?php if ($view == 'received') {
  306. echo 'class="active"';
  307. } ?> >
  308. <a href="<?php echo api_get_path(WEB_CODE_PATH).'dropbox/'; ?>index.php?<?php echo api_get_cidreq(); ?>&view=received" >
  309. <?php echo get_lang('Received Files'); ?></a>
  310. </li>
  311. </ul>
  312. <?php
  313. }
  314. /* RECEIVED FILES */
  315. if ($view == 'received' || !$showSentReceivedTabs) {
  316. // This is for the categories
  317. if (isset($viewReceivedCategory) && $viewReceivedCategory != '') {
  318. $view_dropbox_category_received = $viewReceivedCategory;
  319. } else {
  320. $view_dropbox_category_received = 0;
  321. }
  322. // Object initialisation
  323. $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
  324. // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
  325. // Constructing the array that contains the total number of feedback messages per document.
  326. $number_feedback = get_total_number_feedback();
  327. // Sorting and paging options
  328. $sorting_options = [];
  329. $paging_options = [];
  330. // The headers of the sortable tables
  331. $column_header = [];
  332. $column_header[] = ['', false, ''];
  333. $column_header[] = [get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'];
  334. $column_header[] = [get_lang('Title'), true, ''];
  335. $column_header[] = [get_lang('Size'), true, ''];
  336. $column_header[] = [get_lang('Authors'), true, ''];
  337. $column_header[] = [get_lang('Latest sent on'), true];
  338. if (api_get_session_id() == 0) {
  339. $column_header[] = [get_lang('Edit'), false, '', 'nowrap style="text-align: right"'];
  340. } elseif (api_is_allowed_to_session_edit(false, true)) {
  341. $column_header[] = [get_lang('Edit'), false, '', 'nowrap style="text-align: right"'];
  342. }
  343. $column_header[] = ['RealDate', true];
  344. $column_header[] = ['RealSize', true];
  345. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  346. $column_show[] = 1;
  347. $column_show[] = 1;
  348. $column_show[] = 1;
  349. $column_show[] = 1;
  350. $column_show[] = 1;
  351. $column_show[] = 1;
  352. if (api_get_session_id() == 0) {
  353. $column_show[] = 1;
  354. } elseif (api_is_allowed_to_session_edit(false, true)) {
  355. $column_show[] = 1;
  356. }
  357. $column_show[] = 0;
  358. // Here we change the way how the columns are going to be sort
  359. // in this case the the column of Latest sent on ( 4th element in $column_header) we will be order like the column RealDate
  360. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  361. $column_order[3] = 8;
  362. $column_order[5] = 7;
  363. // The content of the sortable table = the received files
  364. foreach ($dropbox_person->receivedWork as $dropbox_file) {
  365. $dropbox_file_data = [];
  366. if ($view_dropbox_category_received == $dropbox_file->category) {
  367. // we only display the files that are in the category that we are in.
  368. $dropbox_file_data[] = $dropbox_file->id;
  369. if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  370. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = [];
  371. }
  372. // New icon
  373. $new_icon = '';
  374. if (isset($_SESSION['_seen'])) {
  375. if ($dropbox_file->last_upload_date > $last_access &&
  376. !in_array(
  377. $dropbox_file->id,
  378. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX]
  379. )
  380. ) {
  381. $new_icon = '&nbsp;'.Display::return_icon(
  382. 'new_dropbox_message.png',
  383. get_lang('New'),
  384. '',
  385. ICON_SIZE_SMALL
  386. );
  387. }
  388. }
  389. $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  390. $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
  391. $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
  392. Display::return_icon('save.png', get_lang('Download'), ['style' => 'float:right;'], ICON_SIZE_SMALL).
  393. '</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description;
  394. $file_size = $dropbox_file->filesize;
  395. $dropbox_file_data[] = format_file_size($file_size);
  396. $authorInfo = api_get_user_info($dropbox_file->uploader_id);
  397. if ($authorInfo) {
  398. $dropbox_file_data[] = $authorInfo['complete_name'];
  399. } else {
  400. $dropbox_file_data[] = '';
  401. }
  402. $lastUploadDate = Display::dateToStringAgoAndLongDate($dropbox_file->last_upload_date);
  403. $dropbox_file_data[] = $lastUploadDate;
  404. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  405. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.
  406. Display::return_icon('discuss.png', get_lang('Comment'), '', ICON_SIZE_SMALL).'</a>
  407. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movereceived&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.
  408. Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).'</a>
  409. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.
  410. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  411. '</a>';
  412. // This is a hack to have an additional row in a sortable table
  413. if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  414. $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
  415. $url = api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params;
  416. $action_icons .= "
  417. <tr>
  418. <td colspan=\"9\">".
  419. feedback($dropbox_file->feedback2, $url).
  420. "</td></tr>";
  421. }
  422. if (api_get_session_id() == 0) {
  423. $dropbox_file_data[] = $action_icons;
  424. } elseif (api_is_allowed_to_session_edit(false, true)) {
  425. $dropbox_file_data[] = $action_icons;
  426. }
  427. $action_icons = '';
  428. $dropbox_file_data[] = $lastUploadDate;
  429. $dropbox_file_data[] = $file_size;
  430. $dropbox_data_recieved[] = $dropbox_file_data;
  431. }
  432. }
  433. // The content of the sortable table = the categories (if we are not in the root)
  434. if ($view_dropbox_category_received == 0) {
  435. foreach ($dropbox_categories as $category) {
  436. /* Note: This can probably be shortened since the categories
  437. for the received files are already in the
  438. $dropbox_received_category array;*/
  439. $dropbox_category_data = [];
  440. if ($category['received'] == '1') {
  441. $movelist[$category['cat_id']] = $category['cat_name'];
  442. // This is where the checkbox icon for the files appear
  443. $dropbox_category_data[] = $category['cat_id'];
  444. // The icon of the category
  445. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">';
  446. $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>';
  447. $dropbox_category_data[] =
  448. '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.
  449. Display::return_icon('save_pack.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>';
  450. $dropbox_category_data[] = '';
  451. $dropbox_category_data[] = '';
  452. $dropbox_category_data[] = '';
  453. $dropbox_category_data[] =
  454. '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
  455. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  456. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.
  457. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  458. }
  459. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  460. $dropbox_data_recieved[] = $dropbox_category_data;
  461. }
  462. }
  463. }
  464. // Displaying the table
  465. $additional_get_parameters = [
  466. 'view' => $view,
  467. 'view_received_category' => $viewReceivedCategory,
  468. 'view_sent_category' => $viewSentCategory,
  469. ];
  470. $selectlist = [
  471. 'delete_received' => get_lang('Delete'),
  472. 'download_received' => get_lang('Download'),
  473. ];
  474. if (is_array($movelist)) {
  475. foreach ($movelist as $catid => $catname) {
  476. $selectlist['move_received_'.$catid] = get_lang('Move').'->'.Security::remove_XSS($catname);
  477. }
  478. }
  479. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  480. $selectlist = [];
  481. }
  482. echo '<div class="files-table">';
  483. Display::display_sortable_config_table(
  484. 'dropbox',
  485. $column_header,
  486. $dropbox_data_recieved,
  487. $sorting_options,
  488. $paging_options,
  489. $additional_get_parameters,
  490. $column_show,
  491. $column_order,
  492. $selectlist
  493. );
  494. echo '</div>';
  495. }
  496. /* SENT FILES */
  497. if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
  498. // This is for the categories
  499. if (isset($viewSentCategory) && $viewSentCategory != '') {
  500. $view_dropbox_category_sent = $viewSentCategory;
  501. } else {
  502. $view_dropbox_category_sent = 0;
  503. }
  504. // Object initialisation
  505. $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
  506. // Constructing the array that contains the total number of feedback messages per document.
  507. $number_feedback = get_total_number_feedback();
  508. // Sorting and paging options
  509. $sorting_options = [];
  510. $paging_options = [];
  511. // The headers of the sortable tables
  512. $column_header = [];
  513. $column_header[] = ['', false, ''];
  514. $column_header[] = [get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'];
  515. $column_header[] = [get_lang('Sent Files'), true, ''];
  516. $column_header[] = [get_lang('Size'), true, ''];
  517. $column_header[] = [get_lang('Visible to'), true, ''];
  518. $column_header[] = [get_lang('Latest sent on'), true, ''];
  519. if (api_get_session_id() == 0) {
  520. $column_header[] = [get_lang('Edit'), false, '', 'nowrap style="text-align: right"'];
  521. } elseif (api_is_allowed_to_session_edit(false, true)) {
  522. $column_header[] = [get_lang('Edit'), false, '', 'nowrap style="text-align: right"'];
  523. }
  524. $column_header[] = ['RealDate', true];
  525. $column_header[] = ['RealSize', true];
  526. $column_show = [];
  527. $column_order = [];
  528. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  529. $column_show[] = 1;
  530. $column_show[] = 1;
  531. $column_show[] = 1;
  532. $column_show[] = 1;
  533. $column_show[] = 1;
  534. $column_show[] = 1;
  535. if (api_get_session_id() == 0) {
  536. $column_show[] = 1;
  537. } elseif (api_is_allowed_to_session_edit(false, true)) {
  538. $column_show[] = 1;
  539. }
  540. $column_show[] = 0;
  541. // Here we change the way how the colums are going to be sort
  542. // in this case the the column of Latest sent on ( 4th element in $column_header) we will be order like the column RealDate
  543. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  544. $column_order[3] = 8;
  545. $column_order[5] = 7;
  546. // The content of the sortable table = the received files
  547. foreach ($dropbox_person->sentWork as $dropbox_file) {
  548. $dropbox_file_data = [];
  549. if ($view_dropbox_category_sent == $dropbox_file->category) {
  550. $dropbox_file_data[] = $dropbox_file->id;
  551. $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  552. $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
  553. $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
  554. Display::return_icon('save.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).
  555. '</a>'.
  556. $link_open.
  557. $dropbox_file->title.
  558. '</a><br />'.$dropbox_file->description;
  559. $file_size = $dropbox_file->filesize;
  560. $dropbox_file_data[] = format_file_size($file_size);
  561. $receivers_celldata = '';
  562. foreach ($dropbox_file->recipients as $recipient) {
  563. if (isset($recipient['user_id'])) {
  564. $userInfo = api_get_user_info($recipient['user_id']);
  565. $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata;
  566. }
  567. }
  568. $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
  569. $dropbox_file_data[] = $receivers_celldata;
  570. $lastUploadDate = Display::dateToStringAgoAndLongDate($dropbox_file->last_upload_date);
  571. $dropbox_file_data[] = $lastUploadDate;
  572. $receivers_celldata = '';
  573. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  574. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.
  575. Display::return_icon('discuss.png', get_lang('Comment'), '', ICON_SIZE_SMALL).
  576. '</a>
  577. <a href="'.api_get_path(WEB_CODE_PATH).'dropbox/update.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=update&id='.$dropbox_file->id.'&'.$sort_params.'">'.
  578. Display::return_icon('upload_file.png', get_lang('Update'), '', ICON_SIZE_SMALL).
  579. '</a>
  580. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.
  581. Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).'
  582. </a>
  583. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.
  584. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  585. '</a>';
  586. // This is a hack to have an additional row in a sortable table
  587. if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  588. $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
  589. $action_icons .= "<tr><td colspan=\"9\">";
  590. $url = api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params;
  591. $action_icons .= feedback($dropbox_file->feedback2, $url);
  592. //$action_icons .= "<a class=\"btn btn-default\" href=\""><i class=\"fa fa-times\" aria-hidden=\"true\"></i></a>";
  593. $action_icons .= "</tr>";
  594. }
  595. $dropbox_file_data[] = $action_icons;
  596. $dropbox_file_data[] = $lastUploadDate;
  597. $dropbox_file_data[] = $file_size;
  598. $action_icons = '';
  599. $dropbox_data_sent[] = $dropbox_file_data;
  600. }
  601. }
  602. $moveList = [];
  603. // The content of the sortable table = the categories (if we are not in the root)
  604. if ($view_dropbox_category_sent == 0) {
  605. foreach ($dropbox_categories as $category) {
  606. $dropbox_category_data = [];
  607. if ($category['sent'] == '1') {
  608. $moveList[$category['cat_id']] = $category['cat_name'];
  609. $dropbox_category_data[] = $category['cat_id'];
  610. // This is where the checkbox icon for the files appear.
  611. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">';
  612. $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
  613. $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.
  614. Display::return_icon('save_pack.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>';
  615. $dropbox_category_data[] = '';
  616. $dropbox_category_data[] = '';
  617. $dropbox_category_data[] = '';
  618. $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
  619. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  620. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.
  621. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
  622. }
  623. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  624. $dropbox_data_sent[] = $dropbox_category_data;
  625. }
  626. }
  627. }
  628. // Displaying the table
  629. $additional_get_parameters = [
  630. 'view' => $view,
  631. 'view_received_category' => $viewReceivedCategory,
  632. 'view_sent_category' => $viewSentCategory,
  633. ];
  634. $selectlist = [
  635. 'delete_received' => get_lang('Delete'),
  636. 'download_received' => get_lang('Download'),
  637. ];
  638. if (!empty($moveList)) {
  639. foreach ($moveList as $catid => $catname) {
  640. $selectlist['move_sent_'.$catid] = get_lang('Move').'->'.Security::remove_XSS($catname);
  641. }
  642. }
  643. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  644. $selectlist = ['download_received' => get_lang('Download')];
  645. }
  646. echo '<div class="files-table">';
  647. Display::display_sortable_config_table(
  648. 'dropbox',
  649. $column_header,
  650. $dropbox_data_sent,
  651. $sorting_options,
  652. $paging_options,
  653. $additional_get_parameters,
  654. $column_show,
  655. $column_order,
  656. $selectlist
  657. );
  658. echo '</div>';
  659. }
  660. }
  661. Display::display_footer();