index.php 30 KB

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