index.php 35 KB

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