index.php 31 KB

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