index.php 35 KB

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