index.php 30 KB

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