index.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @desc The dropbox is a personal (peer to peer) file exchange module that allows
  5. * you to send documents to a certain (group of) users.
  6. *
  7. * @version 1.3
  8. *
  9. * @author Jan Bols <jan@ivpv.UGent.be>, main programmer, initial version
  10. * @author René Haentjens <rene.haentjens@UGent.be>, several contributions
  11. * @author Roan Embrechts, virtual course support
  12. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University (see history version 1.3)
  13. *
  14. * @package chamilo.dropbox
  15. *
  16. * @todo complete refactoring. Currently there are about at least 3 sql queries needed for every individual dropbox document.
  17. * first we find all the documents that were sent (resp. received) by the user
  18. * then for every individual document the user(s)information who received (resp. sent) the document is searched
  19. * then for every individual document the feedback is retrieved
  20. * @todo the implementation of the dropbox categories could (on the database level) have been done more elegantly by storing the category
  21. * in the dropbox_person table because this table stores the relationship between the files (sent OR received) and the users
  22. */
  23. /**
  24. HISTORY
  25. Version 1.1
  26. ------------
  27. - dropbox_init1.inc.php: changed include statements to require statements. This way if a file is not found, it stops the execution of a script instead of continuing with warnings.
  28. - dropbox_init1.inc.php: the include files "claro_init_global.inc.php" & "debug.lib.inc.php" are first checked for their existence before including them. If they don't exist, in the .../include dir, they get loaded from the .../inc dir. This change is necessary because the UCL changed the include dir to inc.
  29. - dropbox_init1.inc.php: the databasetable name in the variable $dropbox_cnf["introTbl"] is chnged from "introduction" to "tool_intro"
  30. - install.php: after submit, checks if the database uses accueil or tool_list as a tablename
  31. - index.php: removed the behaviour of only the teachers that are allowed to delete entries
  32. - index.php: added field "lastUploadDate" in table dropbox_file to store information about last update when resubmiting a file
  33. - dropbox.inc.php: added $lang["lastUpdated"]
  34. - index.php: entries in received list show when file was last updated if it is updated
  35. - index.php: entries in sent list show when file was last resent if it was resent
  36. - dropbox_submit.php: add a unique id to every uploaded file
  37. - index.php: add POST-variable to the upload form with overwrite data when user decides to overwrite the previous sent file with new file
  38. - dropbox_submit.php: add sanity checks on POST['overwrite'] data
  39. - index.php: remove title field in upload form
  40. - dropbox_submit.php: remove use of POST['title'] variable
  41. - dropbox_init1.inc.php: added $dropbox_cnf["version"] variable
  42. - dropbox_class.inc.php: add $this->lastUploadDate to Dropbox_work class
  43. - dropbox.inc.php: added $lang['emptyTable']
  44. - index.php: if the received or sent list is empty, a message is displayed
  45. - dropbox_download.php: the $file var is set equal to the title-field of the filetable. So not constructed anymore by substracting the username from the filename
  46. - index.php: add check to see if column lastUploadDate exists in filetable
  47. - index.php: moved javascripts from dropbox_init2.inc.php to index.php
  48. - index.php: when specifying an uploadfile in the form, a checkbox allowing the user to overwrite a previously sent file is shown when the specified file has the same name as a previously uploaded file of that user.
  49. - index.php: assign all the metadata (author, description, date, recipient, sender) of an entry in a list to the class="dropbox_detail" and add css to html-header
  50. - index.php: assign all dates of entries in list to the class="dropbox_date" and add CSS
  51. - index.php: assign all persons in entries of list to the class="dropbox_person" and add CSS
  52. - dropbox.inc.php: added $lang['dropbox_version'] to indicate the lates version. This must be equal to the $dropbox_cnf['version'] variable.
  53. - dropbox_init1.inc.php: if the newest lang file isn't loaded by claro_init_global.inc.php from the .../lang dir it will be loaded locally from the .../plugin/dropbox/ dir. This way an administrator must not install the dropbox.inc.php in the .../lang/english dir, but he can leave it in the local .../plugin/dropbox/ dir. However if you want to present multiple language translations of the file you must still put the file in the /lang/ dir, because there is no language management system inside the .../plugin/dropbox dir.
  54. - mime.inc.php: created this file. It contains an array $mimetype with all the mimetypes that are used by dropbox_download.php to give hinst to the browser during download about content
  55. - dropbox_download.php: remove https specific headers because they're not necessary
  56. - dropbox_download.php: use application/octet-stream as the default mime and inline as the default Content-Disposition
  57. - dropbox.inc.php: add lang vars for "order by" action
  58. - dropbox_class.inc.php: add methods orderSentWork, orderReceivedWork en _cmpWork and propery _orderBy to class Dropbox_person to take care of sorting
  59. - index.php: add selectionlist to headers of sent/received lists to select "order by" and add code to keep selected value in sessionvar.
  60. - index.php: moved part of a <a> hyperlink to previous line to remove the underlined space between symbol and title of a work entry in the sent/received list
  61. - index.php: add filesize info in sent/received lists
  62. - dropbox_submit.php: resubmit prevention only for GET action, because it gives some annoying behaviour in POST situation: white screen in IE6
  63. Version 1.2
  64. -----------
  65. - adapted entire dropbox tool so it can be used as a default tool in Dokeos 1.5
  66. - index.php: add event registration to log use of tool in stats tables
  67. - index.php: upload form checks for correct user selection and file specification before uploading the script
  68. - dropbox_init1.inc.php: added dropbox_cnf["allowOverwrite"] to allow or disallow overwriting of files
  69. - index.php: author name textbox is automatically filled in
  70. - mailing functionality (René Haentjens)
  71. - allowStudentToStudent and allowJustUpload options (id.)
  72. - help in separate window (id.)
  73. Version 1.3 (Patrick Cool)
  74. --------------------------
  75. - sortable table
  76. - categories
  77. - fixing a security hole
  78. - tabs (which can be disabled: see $dropbox_cnf['sent_received_tabs'])
  79. - same action on multiple documents ([zip]download, move, delete)
  80. - consistency with the docuements tool (open/download file, icons of documents, ...)
  81. - zip download of complete folder
  82. Version 1.4 (Yannick Warnier)
  83. -----------------------------
  84. - removed all self-built database tables names
  85. */
  86. /* INIT SECTION */
  87. // The file that contains all the initialisation stuff (and includes all the configuration stuff)
  88. require_once 'dropbox_init.inc.php';
  89. // get the last time the user accessed the tool
  90. if ($_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == '') {
  91. $last_access = get_last_tool_access(TOOL_DROPBOX, $_course['code'], $_user['user_id']);
  92. $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access;
  93. } else {
  94. $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX];
  95. }
  96. // Do the tracking
  97. event_access_tool(TOOL_DROPBOX);
  98. // This var is used to give a unique value to every page request. This is to prevent resubmiting data
  99. $dropbox_unid = md5(uniqid(rand(), true));
  100. /* DISPLAY SECTION */
  101. Display::display_introduction_section(TOOL_DROPBOX);
  102. // Build URL-parameters for table-sorting
  103. $sort_params = array();
  104. if (isset($_GET['dropbox_column'])) {
  105. $sort_params[] = 'dropbox_column='.$_GET['dropbox_column'];
  106. }
  107. if (isset($_GET['dropbox_page_nr'])) {
  108. $sort_params[] = 'page_nr='.intval($_GET['page_nr']);
  109. }
  110. if (isset($_GET['dropbox_per_page'])) {
  111. $sort_params[] = 'dropbox_per_page='.intval($_GET['dropbox_per_page']);
  112. }
  113. if (isset($_GET['dropbox_direction'])) {
  114. $sort_params[] = 'dropbox_direction='.$_GET['dropbox_direction'];
  115. }
  116. $sort_params = Security::remove_XSS(implode('&', $sort_params));
  117. /* ACTIONS: add a dropbox file, add a dropbox category. */
  118. // Display the form for adding a new dropbox item.
  119. if ($_GET['action'] == 'add') {
  120. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  121. api_not_allowed();
  122. }
  123. display_add_form();
  124. }
  125. if (isset($_POST['submitWork'])) {
  126. $check = Security::check_token();
  127. if ($check) {
  128. Display :: display_confirmation_message(store_add_dropbox());
  129. //require_once 'dropbox_submit.php';
  130. }
  131. }
  132. // Display the form for adding a category
  133. if ($_GET['action'] == 'addreceivedcategory' or $_GET['action'] == 'addsentcategory') {
  134. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  135. api_not_allowed();
  136. }
  137. display_addcategory_form($_POST['category_name'],'',$_GET['action']);
  138. }
  139. // Editing a category: displaying the form
  140. if ($_GET['action'] == 'editcategory' and isset($_GET['id'])) {
  141. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  142. api_not_allowed();
  143. }
  144. if (!$_POST) {
  145. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  146. api_not_allowed();
  147. }
  148. display_addcategory_form('', $_GET['id'], 'editcategory');
  149. }
  150. }
  151. // Storing a new or edited category
  152. if (isset($_POST['StoreCategory'])) {
  153. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  154. api_not_allowed();
  155. }
  156. $return_information = store_addcategory();
  157. if ($return_information['type'] == 'confirmation') {
  158. Display :: display_confirmation_message($return_information['message']);
  159. }
  160. if ($return_information['type'] == 'error') {
  161. Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']);
  162. display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $_POST['action']);
  163. }
  164. }
  165. // Move a File
  166. if (($_GET['action'] == 'movesent' OR $_GET['action'] == 'movereceived') AND isset($_GET['move_id'])) {
  167. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  168. api_not_allowed();
  169. }
  170. display_move_form(str_replace('move', '', $_GET['action']), $_GET['move_id'], get_dropbox_categories(str_replace('move', '', $_GET['action'])), $sort_params);
  171. }
  172. if ($_POST['do_move']) {
  173. Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part']));
  174. }
  175. // Delete a file
  176. if (($_GET['action'] == 'deletereceivedfile' OR $_GET['action'] == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  177. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  178. api_not_allowed();
  179. }
  180. $dropboxfile = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
  181. if ($_GET['action'] == 'deletereceivedfile') {
  182. $dropboxfile->deleteReceivedWork($_GET['id']);
  183. $message = get_lang('ReceivedFileDeleted');
  184. }
  185. if ($_GET['action'] == 'deletesentfile') {
  186. $dropboxfile->deleteSentWork($_GET['id']);
  187. $message = get_lang('SentFileDeleted');
  188. }
  189. Display :: display_confirmation_message($message);
  190. }
  191. // Delete a category
  192. if (($_GET['action'] == 'deletereceivedcategory' OR $_GET['action'] == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  193. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  194. api_not_allowed();
  195. }
  196. $message = delete_category($_GET['action'], $_GET['id']);
  197. Display :: display_confirmation_message($message);
  198. }
  199. // Do an action on multiple files
  200. // only the download has is handled separately in dropbox_init_inc.php because this has to be done before the headers are sent
  201. // (which also happens in dropbox_init.inc.php
  202. if (!isset($_POST['feedback']) && (strstr($_POST['action'], 'move_received') OR
  203. $_POST['action'] == 'delete_received' OR $_POST['action'] == 'download_received' OR
  204. $_POST['action'] == 'delete_sent' OR $_POST['action'] == 'download_sent')) {
  205. $display_message = handle_multiple_actions();
  206. Display :: display_normal_message($display_message);
  207. }
  208. // Store Feedback
  209. if (isset($_POST['feedback'])) {
  210. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  211. api_not_allowed();
  212. }
  213. $check = Security::check_token();
  214. if ($check) {
  215. $display_message = store_feedback();
  216. Display :: display_normal_message($display_message);
  217. Security::check_token();
  218. }
  219. }
  220. // Error Message
  221. if (isset($_GET['error']) AND !empty($_GET['error'])) {
  222. Display :: display_normal_message(get_lang($_GET['error']));
  223. }
  224. if ($_GET['action'] != 'add') {
  225. // Getting all the categories in the dropbox for the given user
  226. $dropbox_categories = get_dropbox_categories();
  227. // Greating the arrays with the categories for the received files and for the sent files
  228. foreach ($dropbox_categories as $category) {
  229. if ($category['received'] == '1') {
  230. $dropbox_received_category[] = $category;
  231. }
  232. if ($category['sent'] == '1') {
  233. $dropbox_sent_category[] = $category;
  234. }
  235. }
  236. // ACTIONS
  237. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  238. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  239. // This is for the categories
  240. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  241. $view_dropbox_category_received = Security::remove_XSS($_GET['view_received_category']);
  242. } else {
  243. $view_dropbox_category_received = 0;
  244. }
  245. /* Menu Received */
  246. if (api_get_session_id() == 0) {
  247. echo '<div class="actions">';
  248. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  249. echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
  250. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
  251. $movelist[0] = 'Root'; // move_received selectbox content
  252. } else {
  253. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').'</a>';
  254. }
  255. echo '</div>';
  256. } else {
  257. if (api_is_allowed_to_session_edit(false, true)) {
  258. echo '<div class="actions">';
  259. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  260. echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
  261. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
  262. $movelist[0] = 'Root'; // move_received selectbox content
  263. } else {
  264. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32').'</a>';
  265. }
  266. echo '</div>';
  267. }
  268. }
  269. }
  270. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  271. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  272. // This is for the categories
  273. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  274. $view_dropbox_category_sent = $_GET['view_sent_category'];
  275. } else {
  276. $view_dropbox_category_sent = 0;
  277. }
  278. /* Menu Sent */
  279. if (api_get_session_id() == 0) {
  280. echo '<div class="actions">';
  281. if ($view_dropbox_category_sent != 0) {
  282. echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
  283. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category=0&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
  284. } else {
  285. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&amp;action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32')."</a>\n";
  286. }
  287. if (empty($_GET['view_sent_category'])) {
  288. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&amp;action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'','32')."</a>";
  289. }
  290. echo '</div>';
  291. } else {
  292. if (api_is_allowed_to_session_edit(false, true)) {
  293. echo '<div class="actions">';
  294. if ($view_dropbox_category_sent != 0) {
  295. echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
  296. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category=0&amp;view='.Security::remove_XSS($_GET['view']).'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'','32')."</a>";
  297. } else {
  298. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&amp;action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'','32')."</a>\n";
  299. }
  300. if (empty($_GET['view_sent_category'])) {
  301. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&amp;action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'','32')."</a>";
  302. }
  303. echo '</div>';
  304. }
  305. }
  306. }
  307. /* THE MENU TABS */
  308. if ($dropbox_cnf['sent_received_tabs']) {
  309. ?>
  310. <div id="tabbed_menu">
  311. <ul id="tabbed_menu_tabs">
  312. <li><a href="index.php?<?php echo api_get_cidreq(); ?>&view=sent" <?php if (!$_GET['view'] OR $_GET['view'] == 'sent') { echo 'class="active"'; } ?>><?php echo get_lang('SentFiles'); ?></a></li>
  313. <li><a href="index.php?<?php echo api_get_cidreq(); ?>&view=received" <?php if ($_GET['view'] == 'received') { echo 'class="active"'; } ?> ><?php echo get_lang('ReceivedFiles'); ?></a></li>
  314. </ul>
  315. </div>
  316. <?php
  317. }
  318. /* RECEIVED FILES */
  319. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  320. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  321. // This is for the categories
  322. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  323. $view_dropbox_category_received = $_GET['view_received_category'];
  324. } else {
  325. $view_dropbox_category_received = 0;
  326. }
  327. // Object initialisation
  328. $dropbox_person = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor); // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
  329. // Constructing the array that contains the total number of feedback messages per document.
  330. $number_feedback = get_total_number_feedback();
  331. // Sorting and paging options
  332. $sorting_options = array();
  333. $paging_options = array();
  334. // The headers of the sortable tables
  335. $column_header = array();
  336. $column_header[] = array('', false, '');
  337. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  338. $column_header[] = array(get_lang('ReceivedTitle'), true, '');
  339. $column_header[] = array(get_lang('Size'), true, '');
  340. $column_header[] = array(get_lang('Authors'), true, '');
  341. $column_header[] = array(get_lang('LastResent'), true);
  342. if (api_get_session_id() == 0) {
  343. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  344. } elseif (api_is_allowed_to_session_edit(false,true)) {
  345. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  346. }
  347. $column_header[] = array('RealDate', true);
  348. $column_header[] = array('RealSize', true);
  349. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  350. $column_show[] = 1;
  351. $column_show[] = 1;
  352. $column_show[] = 1;
  353. $column_show[] = 1;
  354. $column_show[] = 1;
  355. $column_show[] = 1;
  356. if (api_get_session_id() == 0) {
  357. $column_show[] = 1;
  358. } elseif (api_is_allowed_to_session_edit(false, true)) {
  359. $column_show[] = 1;
  360. }
  361. $column_show[] = 0;
  362. // Here we change the way how the colums are going to be sort
  363. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  364. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  365. $column_order[3] = 8;
  366. $column_order[5] = 7;
  367. // The content of the sortable table = the received files
  368. foreach ($dropbox_person -> receivedWork as $dropbox_file) {
  369. $dropbox_file_data = array();
  370. if ($view_dropbox_category_received == $dropbox_file->category) { // we only display the files that are in the category that we are in.
  371. $dropbox_file_data[] = $dropbox_file->id;
  372. if (!is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  373. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
  374. }
  375. // New icon
  376. $new_icon = '';
  377. if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id, $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  378. $new_icon = '&nbsp;'.Display::return_icon('new_dropbox_message.png', get_lang('New'),'',22);
  379. }
  380. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&amp;id='.$dropbox_file->id.'">';
  381. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  382. $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;'),22).'</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description;
  383. $file_size = $dropbox_file->filesize;
  384. $dropbox_file_data[] = format_file_size($file_size);
  385. $dropbox_file_data[] = $dropbox_file->author;
  386. //$dropbox_file_data[] = $dropbox_file->description;
  387. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  388. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  389. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  390. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',22).'</a>
  391. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=movereceived&amp;move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',22).'</a>
  392. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=deletereceivedfile&amp;id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  393. //$action_icons=' <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$_GET['view_received_category'].'&amp;view_sent_category='.$_GET['view_sent_category'].'&amp;action=movereceived&amp;move_id='.$dropbox_file->id.'">'.Display::return_icon('deplacer.gif',get_lang('Move')).'</a>
  394. // <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$_GET['view_received_category'].'&amp;view_sent_category='.$_GET['view_sent_category'].'&amp;action=deletereceivedfile&amp;id='.$dropbox_file->id.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  395. // This is a hack to have an additional row in a sortable table
  396. if ($_GET['action'] == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
  397. $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
  398. $action_icons .= '<tr><td colspan="2"><a href="index.php?"'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category'])."&amp;view_sent_category=".Security::remove_XSS($_GET['view_sent_category'])."&amp;view=".Security::remove_XSS($_GET['view']).'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
  399. }
  400. if (api_get_session_id() == 0) {
  401. $dropbox_file_data[] = $action_icons;
  402. } elseif (api_is_allowed_to_session_edit(false, true)) {
  403. $dropbox_file_data[] = $action_icons;
  404. }
  405. $action_icons = '';
  406. $dropbox_file_data[] = $last_upload_date;
  407. $dropbox_file_data[] = $file_size;
  408. $dropbox_data_recieved[] = $dropbox_file_data;
  409. }
  410. }
  411. // The content of the sortable table = the categories (if we are not in the root)
  412. if ($view_dropbox_category_received == 0) {
  413. foreach ($dropbox_categories as $category) { // Note: This can probably be shortened since the categories for the received files are already in the $dropbox_received_category array;
  414. $dropbox_category_data = array();
  415. if ($category['received'] == '1') {
  416. $movelist[$category['cat_id']] = $category['cat_name'];
  417. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear
  418. // The icon of the category
  419. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'">';
  420. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  421. $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;'),22).'</a>'.$link_open.$category['cat_name'].'</a>';
  422. $dropbox_category_data[] = '';
  423. $dropbox_category_data[] = '';
  424. $dropbox_category_data[] = '';
  425. $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=editcategory&amp;id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>
  426. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=deletereceivedcategory&amp;id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.$category['cat_name'].'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  427. }
  428. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  429. $dropbox_data_recieved[] = $dropbox_category_data;
  430. }
  431. }
  432. }
  433. // Displaying the table
  434. $additional_get_parameters = array('view' => $_GET['view'], 'view_received_category' => $_GET['view_received_category'], 'view_sent_category' => $_GET['view_sent_category']);
  435. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  436. if (is_array($movelist)) {
  437. foreach ($movelist as $catid => $catname){
  438. $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. $catname;
  439. }
  440. }
  441. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  442. $selectlist = array();
  443. }
  444. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  445. }
  446. /* SENT FILES */
  447. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  448. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  449. // This is for the categories
  450. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  451. $view_dropbox_category_sent = $_GET['view_sent_category'];
  452. } else {
  453. $view_dropbox_category_sent = 0;
  454. }
  455. // Object initialisation
  456. $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
  457. // Constructing the array that contains the total number of feedback messages per document.
  458. $number_feedback = get_total_number_feedback();
  459. // Sorting and paging options
  460. $sorting_options = array();
  461. $paging_options = array();
  462. // The headers of the sortable tables
  463. $column_header = array();
  464. $column_header[] = array('', false, '');
  465. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  466. $column_header[] = array(get_lang('SentTitle'), true, '');
  467. $column_header[] = array(get_lang('Size'), true, '');
  468. $column_header[] = array(get_lang('SentTo'), true, '');
  469. $column_header[] = array(get_lang('LastResent'), true, '');
  470. if (api_get_session_id() == 0) {
  471. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  472. } elseif (api_is_allowed_to_session_edit(false, true)) {
  473. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  474. }
  475. $column_header[] = array('RealDate', true);
  476. $column_header[] = array('RealSize', true);
  477. $column_show = array();
  478. $column_order = array();
  479. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  480. $column_show[] = 1;
  481. $column_show[] = 1;
  482. $column_show[] = 1;
  483. $column_show[] = 1;
  484. $column_show[] = 1;
  485. $column_show[] = 1;
  486. if (api_get_session_id() == 0) {
  487. $column_show[] = 1;
  488. } elseif (api_is_allowed_to_session_edit(false, true)) {
  489. $column_show[] = 1;
  490. }
  491. $column_show[] = 0;
  492. // Here we change the way how the colums are going to be sort
  493. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  494. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  495. $column_order[3] = 8;
  496. $column_order[5] = 7;
  497. // The content of the sortable table = the received files
  498. foreach ($dropbox_person -> sentWork as $dropbox_file) {
  499. $dropbox_file_data = array();
  500. if ($view_dropbox_category_sent == $dropbox_file->category) {
  501. $dropbox_file_data[] = $dropbox_file->id;
  502. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  503. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  504. $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;'),22).'</a>'.$link_open.$dropbox_file->title.'</a><br />'.$dropbox_file->description;
  505. $file_size = $dropbox_file->filesize;
  506. $dropbox_file_data[] = format_file_size($file_size);
  507. foreach ($dropbox_file->recipients as $recipient) {
  508. $receivers_celldata = display_user_link_work($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
  509. }
  510. $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
  511. $dropbox_file_data[] = $receivers_celldata;
  512. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  513. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  514. //$dropbox_file_data[] = $dropbox_file->author;
  515. $receivers_celldata = '';
  516. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  517. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',22).'</a>
  518. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=movesent&amp;move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',22).'</a>
  519. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['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'),'',22).'</a>';
  520. // This is a hack to have an additional row in a sortable table
  521. if ($_GET['action'] == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  522. $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
  523. $action_icons .= "<tr><td colspan=\"2\">";
  524. $action_icons .= "<a href=\"index.php?".api_get_cidreq()."&view_received_category=".Security::remove_XSS($_GET['view_received_category'])."&view_sent_category=".Security::remove_XSS($_GET['view_sent_category'])."&view=".Security::remove_XSS($_GET['view']).'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>";
  525. $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
  526. }
  527. $dropbox_file_data[] = $action_icons;
  528. $dropbox_file_data[] = $last_upload_date;
  529. $dropbox_file_data[] = $file_size;
  530. $action_icons = '';
  531. $dropbox_data_sent[] = $dropbox_file_data;
  532. }
  533. }
  534. // The content of the sortable table = the categories (if we are not in the root)
  535. if ($view_dropbox_category_sent == 0) {
  536. foreach ($dropbox_categories as $category) {
  537. $dropbox_category_data = array();
  538. if ($category['sent'] == '1') {
  539. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear.
  540. $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.$category['cat_id'].'&amp;view='.Security::remove_XSS($_GET['view']).'">';
  541. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  542. $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;'),22).'</a>'.$link_open.$category['cat_name'].'</a>';
  543. //$dropbox_category_data[] = '';
  544. $dropbox_category_data[] = '';
  545. //$dropbox_category_data[] = '';
  546. $dropbox_category_data[] = '';
  547. $dropbox_category_data[] = '';
  548. $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'),'',22).'</a>
  549. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=deletesentcategory&amp;id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.$category['cat_name'].'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  550. }
  551. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  552. $dropbox_data_sent[] = $dropbox_category_data;
  553. }
  554. }
  555. }
  556. // Displaying the table
  557. $additional_get_parameters = array('view' => Security::remove_XSS($_GET['view']), 'view_received_category' => Security::remove_XSS($_GET['view_received_category']), 'view_sent_category' => Security::remove_XSS($_GET['view_sent_category']));
  558. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  559. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  560. $selectlist = array('download_received' => get_lang('Download'));
  561. }
  562. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  563. }
  564. }
  565. Display::display_footer();