index.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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 ($_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::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. if ($action != 'add') {
  161. // Getting all the categories in the dropbox for the given user
  162. $dropbox_categories = get_dropbox_categories();
  163. // Greating the arrays with the categories for the received files and for the sent files
  164. foreach ($dropbox_categories as $category) {
  165. if ($category['received'] == '1') {
  166. $dropbox_received_category[] = $category;
  167. }
  168. if ($category['sent'] == '1') {
  169. $dropbox_sent_category[] = $category;
  170. }
  171. }
  172. // ACTIONS
  173. if ($view == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  174. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  175. // This is for the categories
  176. if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
  177. $view_dropbox_category_received = $viewReceivedCategory;
  178. } else {
  179. $view_dropbox_category_received = 0;
  180. }
  181. /* Menu Received */
  182. if (api_get_session_id() == 0) {
  183. echo '<div class="actions">';
  184. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  185. 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>";
  186. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  187. $movelist[0] = 'Root'; // move_received selectbox content
  188. } else {
  189. 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>';
  190. }
  191. echo '</div>';
  192. } else {
  193. if (api_is_allowed_to_session_edit(false, true)) {
  194. echo '<div class="actions">';
  195. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  196. 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>";
  197. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  198. $movelist[0] = 'Root'; // move_received selectbox content
  199. } else {
  200. 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>';
  201. }
  202. echo '</div>';
  203. }
  204. }
  205. }
  206. if (!$view OR $view == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  207. // This is for the categories
  208. if (isset($viewSentCategory) AND $viewSentCategory != '') {
  209. $view_dropbox_category_sent = $viewSentCategory;
  210. } else {
  211. $view_dropbox_category_sent = 0;
  212. }
  213. /* Menu Sent */
  214. if (api_get_session_id() == 0) {
  215. echo '<div class="actions">';
  216. if ($view_dropbox_category_sent != 0) {
  217. 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>";
  218. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  219. } else {
  220. 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";
  221. }
  222. if (empty($viewSentCategory)) {
  223. 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>";
  224. }
  225. echo '</div>';
  226. } else {
  227. if (api_is_allowed_to_session_edit(false, true)) {
  228. echo '<div class="actions">';
  229. if ($view_dropbox_category_sent != 0) {
  230. echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  231. 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>";
  232. } else {
  233. 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";
  234. }
  235. if (empty($viewSentCategory)) {
  236. 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>";
  237. }
  238. echo '</div>';
  239. }
  240. }
  241. }
  242. /* THE MENU TABS */
  243. if ($dropbox_cnf['sent_received_tabs']) {
  244. ?>
  245. <ul class="nav nav-tabs">
  246. <li <?php if (!$view OR $view == 'sent') { echo 'class="active"'; } ?> >
  247. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=sent" ><?php echo get_lang('SentFiles'); ?></a></li>
  248. <li <?php if ($view == 'received') { echo 'class="active"'; } ?> >
  249. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=received" ><?php echo get_lang('ReceivedFiles'); ?></a></li>
  250. </ul>
  251. <?php
  252. }
  253. /* RECEIVED FILES */
  254. if ($view == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  255. // This is for the categories
  256. if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
  257. $view_dropbox_category_received = $viewReceivedCategory;
  258. } else {
  259. $view_dropbox_category_received = 0;
  260. }
  261. // Object initialisation
  262. $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
  263. // Constructing the array that contains the total number of feedback messages per document.
  264. $number_feedback = get_total_number_feedback();
  265. // Sorting and paging options
  266. $sorting_options = array();
  267. $paging_options = array();
  268. // The headers of the sortable tables
  269. $column_header = array();
  270. $column_header[] = array('', false, '');
  271. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  272. $column_header[] = array(get_lang('ReceivedTitle'), true, '');
  273. $column_header[] = array(get_lang('Size'), true, '');
  274. $column_header[] = array(get_lang('Authors'), true, '');
  275. $column_header[] = array(get_lang('LastResent'), true);
  276. if (api_get_session_id() == 0) {
  277. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  278. } elseif (api_is_allowed_to_session_edit(false,true)) {
  279. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  280. }
  281. $column_header[] = array('RealDate', true);
  282. $column_header[] = array('RealSize', true);
  283. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  284. $column_show[] = 1;
  285. $column_show[] = 1;
  286. $column_show[] = 1;
  287. $column_show[] = 1;
  288. $column_show[] = 1;
  289. $column_show[] = 1;
  290. if (api_get_session_id() == 0) {
  291. $column_show[] = 1;
  292. } elseif (api_is_allowed_to_session_edit(false, true)) {
  293. $column_show[] = 1;
  294. }
  295. $column_show[] = 0;
  296. // Here we change the way how the colums are going to be sort
  297. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  298. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  299. $column_order[3] = 8;
  300. $column_order[5] = 7;
  301. // The content of the sortable table = the received files
  302. foreach ($dropbox_person -> receivedWork as $dropbox_file) {
  303. $dropbox_file_data = array();
  304. if ($view_dropbox_category_received == $dropbox_file->category) {
  305. // we only display the files that are in the category that we are in.
  306. $dropbox_file_data[] = $dropbox_file->id;
  307. if (!is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  308. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
  309. }
  310. // New icon
  311. $new_icon = '';
  312. if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id, $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  313. $new_icon = '&nbsp;'.Display::return_icon('new_dropbox_message.png', get_lang('New'),'',ICON_SIZE_SMALL);
  314. }
  315. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&amp;id='.$dropbox_file->id.'">';
  316. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  317. $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;
  318. $file_size = $dropbox_file->filesize;
  319. $dropbox_file_data[] = Text::format_file_size($file_size);
  320. $dropbox_file_data[] = $dropbox_file->author;
  321. //$dropbox_file_data[] = $dropbox_file->description;
  322. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  323. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  324. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  325. <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>
  326. <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>
  327. <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.'\');">'.
  328. Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  329. // This is a hack to have an additional row in a sortable table
  330. if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
  331. $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
  332. $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>";
  333. }
  334. if (api_get_session_id() == 0) {
  335. $dropbox_file_data[] = $action_icons;
  336. } elseif (api_is_allowed_to_session_edit(false, true)) {
  337. $dropbox_file_data[] = $action_icons;
  338. }
  339. $action_icons = '';
  340. $dropbox_file_data[] = $last_upload_date;
  341. $dropbox_file_data[] = $file_size;
  342. $dropbox_data_recieved[] = $dropbox_file_data;
  343. }
  344. }
  345. // The content of the sortable table = the categories (if we are not in the root)
  346. if ($view_dropbox_category_received == 0) {
  347. foreach ($dropbox_categories as $category) {
  348. /* Note: This can probably be shortened since the categories
  349. for the received files are already in the
  350. $dropbox_received_category array;*/
  351. $dropbox_category_data = array();
  352. if ($category['received'] == '1') {
  353. $movelist[$category['cat_id']] = $category['cat_name'];
  354. // This is where the checkbox icon for the files appear
  355. $dropbox_category_data[] = $category['cat_id'];
  356. // The icon of the category
  357. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&amp;view_sent_category='.$viewSentCategory.'&amp;view='.$view.'">';
  358. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  359. $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>';
  360. $dropbox_category_data[] = '';
  361. $dropbox_category_data[] = '';
  362. $dropbox_category_data[] = '';
  363. $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>
  364. <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>';
  365. }
  366. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  367. $dropbox_data_recieved[] = $dropbox_category_data;
  368. }
  369. }
  370. }
  371. // Displaying the table
  372. $additional_get_parameters = array('view' => $view, 'view_received_category' => $viewReceivedCategory, 'view_sent_category' => $viewSentCategory);
  373. $selectlist = array(
  374. 'delete_received' => get_lang('Delete'),
  375. 'download_received' => get_lang('Download')
  376. );
  377. if (is_array($movelist)) {
  378. foreach ($movelist as $catid => $catname){
  379. $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
  380. }
  381. }
  382. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  383. $selectlist = array();
  384. }
  385. Display::display_sortable_config_table(
  386. 'dropbox',
  387. $column_header,
  388. $dropbox_data_recieved,
  389. $sorting_options,
  390. $paging_options,
  391. $additional_get_parameters,
  392. $column_show,
  393. $column_order,
  394. $selectlist
  395. );
  396. }
  397. /* SENT FILES */
  398. if (!$view OR $view == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  399. // This is for the categories
  400. if (isset($viewSentCategory) AND $viewSentCategory != '') {
  401. $view_dropbox_category_sent = $viewSentCategory;
  402. } else {
  403. $view_dropbox_category_sent = 0;
  404. }
  405. // Object initialisation
  406. $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
  407. // Constructing the array that contains the total number of feedback messages per document.
  408. $number_feedback = get_total_number_feedback();
  409. // Sorting and paging options
  410. $sorting_options = array();
  411. $paging_options = array();
  412. // The headers of the sortable tables
  413. $column_header = array();
  414. $column_header[] = array('', false, '');
  415. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  416. $column_header[] = array(get_lang('SentTitle'), true, '');
  417. $column_header[] = array(get_lang('Size'), true, '');
  418. $column_header[] = array(get_lang('SentTo'), true, '');
  419. $column_header[] = array(get_lang('LastResent'), true, '');
  420. if (api_get_session_id() == 0) {
  421. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  422. } elseif (api_is_allowed_to_session_edit(false, true)) {
  423. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  424. }
  425. $column_header[] = array('RealDate', true);
  426. $column_header[] = array('RealSize', true);
  427. $column_show = array();
  428. $column_order = array();
  429. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  430. $column_show[] = 1;
  431. $column_show[] = 1;
  432. $column_show[] = 1;
  433. $column_show[] = 1;
  434. $column_show[] = 1;
  435. $column_show[] = 1;
  436. if (api_get_session_id() == 0) {
  437. $column_show[] = 1;
  438. } elseif (api_is_allowed_to_session_edit(false, true)) {
  439. $column_show[] = 1;
  440. }
  441. $column_show[] = 0;
  442. // Here we change the way how the colums are going to be sort
  443. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  444. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  445. $column_order[3] = 8;
  446. $column_order[5] = 7;
  447. // The content of the sortable table = the received files
  448. foreach ($dropbox_person->sentWork as $dropbox_file) {
  449. $dropbox_file_data = array();
  450. if ($view_dropbox_category_sent == $dropbox_file->category) {
  451. $dropbox_file_data[] = $dropbox_file->id;
  452. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  453. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  454. $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;
  455. $file_size = $dropbox_file->filesize;
  456. $dropbox_file_data[] = Text::format_file_size($file_size);
  457. $receivers_celldata = null;
  458. foreach ($dropbox_file->recipients as $recipient) {
  459. $receivers_celldata = display_user_link_work($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
  460. }
  461. $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
  462. $dropbox_file_data[] = $receivers_celldata;
  463. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  464. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  465. //$dropbox_file_data[] = $dropbox_file->author;
  466. $receivers_celldata = '';
  467. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  468. <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>
  469. <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>
  470. <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>';
  471. // This is a hack to have an additional row in a sortable table
  472. if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  473. $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
  474. $action_icons .= "<tr><td colspan=\"2\">";
  475. $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>";
  476. $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
  477. }
  478. $dropbox_file_data[] = $action_icons;
  479. $dropbox_file_data[] = $last_upload_date;
  480. $dropbox_file_data[] = $file_size;
  481. $action_icons = '';
  482. $dropbox_data_sent[] = $dropbox_file_data;
  483. }
  484. }
  485. $moveList = array();
  486. // The content of the sortable table = the categories (if we are not in the root)
  487. if ($view_dropbox_category_sent == 0) {
  488. foreach ($dropbox_categories as $category) {
  489. $dropbox_category_data = array();
  490. if ($category['sent'] == '1') {
  491. $moveList[$category['cat_id']] = $category['cat_name'];
  492. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear.
  493. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&amp;view_sent_category='.$category['cat_id'].'&amp;view='.$view.'">';
  494. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
  495. $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>';
  496. //$dropbox_category_data[] = '';
  497. $dropbox_category_data[] = '';
  498. //$dropbox_category_data[] = '';
  499. $dropbox_category_data[] = '';
  500. $dropbox_category_data[] = '';
  501. $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'].'">'.
  502. Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
  503. <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']).'\');">'.
  504. Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  505. }
  506. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  507. $dropbox_data_sent[] = $dropbox_category_data;
  508. }
  509. }
  510. }
  511. // Displaying the table
  512. $additional_get_parameters = array(
  513. 'view' => $view,
  514. 'view_received_category' => $viewReceivedCategory,
  515. 'view_sent_category' => $viewSentCategory
  516. );
  517. $selectlist = array(
  518. 'delete_received' => get_lang('Delete'),
  519. 'download_received' => get_lang('Download')
  520. );
  521. if (!empty($moveList)) {
  522. foreach ($moveList as $catid => $catname) {
  523. $selectlist['move_sent_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
  524. }
  525. }
  526. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  527. $selectlist = array('download_received' => get_lang('Download'));
  528. }
  529. Display::display_sortable_config_table(
  530. 'dropbox',
  531. $column_header,
  532. $dropbox_data_sent,
  533. $sorting_options,
  534. $paging_options,
  535. $additional_get_parameters,
  536. $column_show,
  537. $column_order,
  538. $selectlist
  539. );
  540. }
  541. }
  542. Display::display_footer();