index.php 30 KB

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