index.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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, api_get_course_int_id(), $_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. $action = isset($_GET['action']) ? $_GET['action'] : null;
  118. /* ACTIONS: add a dropbox file, add a dropbox category. */
  119. // Display the form for adding a new dropbox item.
  120. if ($action == 'add') {
  121. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  122. api_not_allowed();
  123. }
  124. display_add_form();
  125. }
  126. if (isset($_POST['submitWork'])) {
  127. $check = Security::check_token();
  128. if ($check) {
  129. $message = store_add_dropbox();
  130. if (!empty($message)) {
  131. Display :: display_confirmation_message($message);
  132. }
  133. }
  134. }
  135. // Display the form for adding a category
  136. if ($action == 'addreceivedcategory' or $action == 'addsentcategory') {
  137. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  138. api_not_allowed();
  139. }
  140. display_addcategory_form($_POST['category_name'],'',$_GET['action']);
  141. }
  142. // Editing a category: displaying the form
  143. if ($action == 'editcategory' and isset($_GET['id'])) {
  144. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  145. api_not_allowed();
  146. }
  147. if (!$_POST) {
  148. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  149. api_not_allowed();
  150. }
  151. display_addcategory_form('', $_GET['id'], 'editcategory');
  152. }
  153. }
  154. // Storing a new or edited category
  155. if (isset($_POST['StoreCategory'])) {
  156. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  157. api_not_allowed();
  158. }
  159. $return_information = store_addcategory();
  160. if ($return_information['type'] == 'confirmation') {
  161. Display :: display_confirmation_message($return_information['message']);
  162. }
  163. if ($return_information['type'] == 'error') {
  164. Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']);
  165. display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $_POST['action']);
  166. }
  167. }
  168. // Move a File
  169. if (($action == 'movesent' OR $action == 'movereceived') AND isset($_GET['move_id'])) {
  170. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  171. api_not_allowed();
  172. }
  173. display_move_form(str_replace('move', '', $action), $_GET['move_id'], get_dropbox_categories(str_replace('move', '', $action)), $sort_params);
  174. }
  175. if (isset($_POST['do_move'])) {
  176. Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part']));
  177. }
  178. // Delete a file
  179. if (($action == 'deletereceivedfile' OR $action == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  180. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  181. api_not_allowed();
  182. }
  183. $dropboxfile = new Dropbox_Person(api_get_user_id(), api_is_course_admin(), $is_courseTutor);
  184. if ($action == 'deletereceivedfile') {
  185. $dropboxfile->deleteReceivedWork($_GET['id']);
  186. $message = get_lang('ReceivedFileDeleted');
  187. }
  188. if ($action == 'deletesentfile') {
  189. $dropboxfile->deleteSentWork($_GET['id']);
  190. $message = get_lang('SentFileDeleted');
  191. }
  192. Display :: display_confirmation_message($message);
  193. }
  194. // Delete a category
  195. if (($action == 'deletereceivedcategory' OR $action == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  196. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  197. api_not_allowed();
  198. }
  199. $message = delete_category($action, $_GET['id']);
  200. Display :: display_confirmation_message($message);
  201. }
  202. // Do an action on multiple files
  203. // only the download has is handled separately in dropbox_init_inc.php because this has to be done before the headers are sent
  204. // (which also happens in dropbox_init.inc.php
  205. if (!isset($_POST['feedback']) && (strstr($_POST['action'], 'move_received') OR
  206. $_POST['action'] == 'delete_received' OR $_POST['action'] == 'download_received' OR
  207. $_POST['action'] == 'delete_sent' OR $_POST['action'] == 'download_sent')) {
  208. $display_message = handle_multiple_actions();
  209. Display :: display_normal_message($display_message);
  210. }
  211. // Store Feedback
  212. if (isset($_POST['feedback'])) {
  213. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  214. api_not_allowed();
  215. }
  216. $check = Security::check_token();
  217. if ($check) {
  218. $display_message = store_feedback();
  219. Display :: display_normal_message($display_message);
  220. Security::check_token();
  221. }
  222. }
  223. // Error Message
  224. if (isset($_GET['error']) AND !empty($_GET['error'])) {
  225. Display :: display_normal_message(get_lang($_GET['error']));
  226. }
  227. if ($action != 'add') {
  228. // Getting all the categories in the dropbox for the given user
  229. $dropbox_categories = get_dropbox_categories();
  230. // Greating the arrays with the categories for the received files and for the sent files
  231. foreach ($dropbox_categories as $category) {
  232. if ($category['received'] == '1') {
  233. $dropbox_received_category[] = $category;
  234. }
  235. if ($category['sent'] == '1') {
  236. $dropbox_sent_category[] = $category;
  237. }
  238. }
  239. // ACTIONS
  240. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  241. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  242. // This is for the categories
  243. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  244. $view_dropbox_category_received = Security::remove_XSS($_GET['view_received_category']);
  245. } else {
  246. $view_dropbox_category_received = 0;
  247. }
  248. /* Menu Received */
  249. if (api_get_session_id() == 0) {
  250. echo '<div class="actions">';
  251. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  252. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  253. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  254. $movelist[0] = 'Root'; // move_received selectbox content
  255. } else {
  256. 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'),'',ICON_SIZE_MEDIUM).'</a>';
  257. }
  258. echo '</div>';
  259. } else {
  260. if (api_is_allowed_to_session_edit(false, true)) {
  261. echo '<div class="actions">';
  262. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  263. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  264. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
  265. $movelist[0] = 'Root'; // move_received selectbox content
  266. } else {
  267. 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'),'',ICON_SIZE_MEDIUM).'</a>';
  268. }
  269. echo '</div>';
  270. }
  271. }
  272. }
  273. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  274. // This is for the categories
  275. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  276. $view_dropbox_category_sent = $_GET['view_sent_category'];
  277. } else {
  278. $view_dropbox_category_sent = 0;
  279. }
  280. /* Menu Sent */
  281. if (api_get_session_id() == 0) {
  282. echo '<div class="actions">';
  283. if ($view_dropbox_category_sent != 0) {
  284. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  285. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  286. } else {
  287. 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'),'',ICON_SIZE_MEDIUM)."</a>\n";
  288. }
  289. if (empty($_GET['view_sent_category'])) {
  290. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  291. }
  292. echo '</div>';
  293. } else {
  294. if (api_is_allowed_to_session_edit(false, true)) {
  295. echo '<div class="actions">';
  296. if ($view_dropbox_category_sent != 0) {
  297. echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  298. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  299. } else {
  300. 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'),'',ICON_SIZE_MEDIUM)."</a>\n";
  301. }
  302. if (empty($_GET['view_sent_category'])) {
  303. 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'),'',ICON_SIZE_MEDIUM)."</a>";
  304. }
  305. echo '</div>';
  306. }
  307. }
  308. }
  309. /* THE MENU TABS */
  310. if ($dropbox_cnf['sent_received_tabs']) {
  311. ?>
  312. <ul class="nav nav-tabs">
  313. <li <?php if (!$_GET['view'] OR $_GET['view'] == 'sent') { echo 'class="active"'; } ?> >
  314. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=sent" ><?php echo get_lang('SentFiles'); ?></a></li>
  315. <li <?php if ($_GET['view'] == 'received') { echo 'class="active"'; } ?> >
  316. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=received" ><?php echo get_lang('ReceivedFiles'); ?></a></li>
  317. </ul>
  318. <?php
  319. }
  320. /* RECEIVED FILES */
  321. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  322. // This is for the categories
  323. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  324. $view_dropbox_category_received = $_GET['view_received_category'];
  325. } else {
  326. $view_dropbox_category_received = 0;
  327. }
  328. // Object initialisation
  329. $dropbox_person = new Dropbox_Person(api_get_user_id(), api_is_course_admin(), $is_courseTutor); // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
  330. // Constructing the array that contains the total number of feedback messages per document.
  331. $number_feedback = get_total_number_feedback();
  332. // Sorting and paging options
  333. $sorting_options = array();
  334. $paging_options = array();
  335. // The headers of the sortable tables
  336. $column_header = array();
  337. $column_header[] = array('', false, '');
  338. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  339. $column_header[] = array(get_lang('ReceivedTitle'), true, '');
  340. $column_header[] = array(get_lang('Size'), true, '');
  341. $column_header[] = array(get_lang('Authors'), true, '');
  342. $column_header[] = array(get_lang('LastResent'), true);
  343. if (api_get_session_id() == 0) {
  344. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  345. } elseif (api_is_allowed_to_session_edit(false,true)) {
  346. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  347. }
  348. $column_header[] = array('RealDate', true);
  349. $column_header[] = array('RealSize', true);
  350. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  351. $column_show[] = 1;
  352. $column_show[] = 1;
  353. $column_show[] = 1;
  354. $column_show[] = 1;
  355. $column_show[] = 1;
  356. $column_show[] = 1;
  357. if (api_get_session_id() == 0) {
  358. $column_show[] = 1;
  359. } elseif (api_is_allowed_to_session_edit(false, true)) {
  360. $column_show[] = 1;
  361. }
  362. $column_show[] = 0;
  363. // Here we change the way how the colums are going to be sort
  364. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  365. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  366. $column_order[3] = 8;
  367. $column_order[5] = 7;
  368. // The content of the sortable table = the received files
  369. foreach ($dropbox_person -> receivedWork as $dropbox_file) {
  370. $dropbox_file_data = array();
  371. if ($view_dropbox_category_received == $dropbox_file->category) {
  372. // we only display the files that are in the category that we are in.
  373. $dropbox_file_data[] = $dropbox_file->id;
  374. if (!is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  375. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
  376. }
  377. // New icon
  378. $new_icon = '';
  379. if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id, $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  380. $new_icon = '&nbsp;'.Display::return_icon('new_dropbox_message.png', get_lang('New'),'',ICON_SIZE_SMALL);
  381. }
  382. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&amp;id='.$dropbox_file->id.'">';
  383. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  384. $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;
  385. $file_size = $dropbox_file->filesize;
  386. $dropbox_file_data[] = Text::format_file_size($file_size);
  387. $dropbox_file_data[] = $dropbox_file->author;
  388. //$dropbox_file_data[] = $dropbox_file->description;
  389. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  390. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  391. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  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=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a>
  393. <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'),'',ICON_SIZE_SMALL).'</a>
  394. <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.'\');">'.
  395. Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  396. // This is a hack to have an additional row in a sortable table
  397. if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
  398. $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
  399. $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>";
  400. }
  401. if (api_get_session_id() == 0) {
  402. $dropbox_file_data[] = $action_icons;
  403. } elseif (api_is_allowed_to_session_edit(false, true)) {
  404. $dropbox_file_data[] = $action_icons;
  405. }
  406. $action_icons = '';
  407. $dropbox_file_data[] = $last_upload_date;
  408. $dropbox_file_data[] = $file_size;
  409. $dropbox_data_recieved[] = $dropbox_file_data;
  410. }
  411. }
  412. // The content of the sortable table = the categories (if we are not in the root)
  413. if ($view_dropbox_category_received == 0) {
  414. 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;
  415. $dropbox_category_data = array();
  416. if ($category['received'] == '1') {
  417. $movelist[$category['cat_id']] = $category['cat_name'];
  418. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear
  419. // The icon of the category
  420. $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']).'">';
  421. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  422. $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>';
  423. $dropbox_category_data[] = '';
  424. $dropbox_category_data[] = '';
  425. $dropbox_category_data[] = '';
  426. $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'),'',ICON_SIZE_SMALL).'</a>
  427. <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(\''.Security::remove_XSS($category['cat_name']).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  428. }
  429. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  430. $dropbox_data_recieved[] = $dropbox_category_data;
  431. }
  432. }
  433. }
  434. // Displaying the table
  435. $additional_get_parameters = array('view' => $_GET['view'], 'view_received_category' => $_GET['view_received_category'], 'view_sent_category' => $_GET['view_sent_category']);
  436. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  437. if (is_array($movelist)) {
  438. foreach ($movelist as $catid => $catname){
  439. $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
  440. }
  441. }
  442. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  443. $selectlist = array();
  444. }
  445. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  446. }
  447. /* SENT FILES */
  448. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  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(api_get_user_id(), api_is_course_admin(), $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;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a><br />'.$dropbox_file->description;
  505. $file_size = $dropbox_file->filesize;
  506. $dropbox_file_data[] = Text::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'),'',ICON_SIZE_SMALL).'</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'),'',ICON_SIZE_SMALL).'</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'),'',ICON_SIZE_SMALL).'</a>';
  520. // This is a hack to have an additional row in a sortable table
  521. if ($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', Security::remove_XSS($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;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($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'].'">'.
  549. Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
  550. <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(\''.Security::remove_XSS($category['cat_name']).'\');">'.
  551. Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  552. }
  553. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  554. $dropbox_data_sent[] = $dropbox_category_data;
  555. }
  556. }
  557. }
  558. // Displaying the table
  559. $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']));
  560. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  561. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  562. $selectlist = array('download_received' => get_lang('Download'));
  563. }
  564. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  565. }
  566. }
  567. Display::display_footer();