index.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. $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. Display :: display_confirmation_message(store_add_dropbox());
  130. //require_once 'dropbox_submit.php';
  131. }
  132. }
  133. // Display the form for adding a category
  134. if ($action == 'addreceivedcategory' or $action == 'addsentcategory') {
  135. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  136. api_not_allowed();
  137. }
  138. display_addcategory_form($_POST['category_name'],'',$_GET['action']);
  139. }
  140. // Editing a category: displaying the form
  141. if ($action == 'editcategory' and isset($_GET['id'])) {
  142. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  143. api_not_allowed();
  144. }
  145. if (!$_POST) {
  146. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  147. api_not_allowed();
  148. }
  149. display_addcategory_form('', $_GET['id'], 'editcategory');
  150. }
  151. }
  152. // Storing a new or edited category
  153. if (isset($_POST['StoreCategory'])) {
  154. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  155. api_not_allowed();
  156. }
  157. $return_information = store_addcategory();
  158. if ($return_information['type'] == 'confirmation') {
  159. Display :: display_confirmation_message($return_information['message']);
  160. }
  161. if ($return_information['type'] == 'error') {
  162. Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']);
  163. display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $_POST['action']);
  164. }
  165. }
  166. // Move a File
  167. if (($action == 'movesent' OR $action == 'movereceived') AND isset($_GET['move_id'])) {
  168. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  169. api_not_allowed();
  170. }
  171. display_move_form(str_replace('move', '', $action), $_GET['move_id'], get_dropbox_categories(str_replace('move', '', $action)), $sort_params);
  172. }
  173. if (isset($_POST['do_move']) && $_POST['do_move']) {
  174. Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part']));
  175. }
  176. // Delete a file
  177. if (($action == 'deletereceivedfile' OR $action == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  178. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  179. api_not_allowed();
  180. }
  181. $dropboxfile = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
  182. if ($action == 'deletereceivedfile') {
  183. $dropboxfile->deleteReceivedWork($_GET['id']);
  184. $message = get_lang('ReceivedFileDeleted');
  185. }
  186. if ($action == 'deletesentfile') {
  187. $dropboxfile->deleteSentWork($_GET['id']);
  188. $message = get_lang('SentFileDeleted');
  189. }
  190. Display :: display_confirmation_message($message);
  191. }
  192. // Delete a category
  193. if (($action == 'deletereceivedcategory' OR $action == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) {
  194. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  195. api_not_allowed();
  196. }
  197. $message = delete_category($action, $_GET['id']);
  198. Display :: display_confirmation_message($message);
  199. }
  200. // Do an action on multiple files
  201. // only the download has is handled separately in dropbox_init_inc.php because this has to be done before the headers are sent
  202. // (which also happens in dropbox_init.inc.php
  203. if (!isset($_POST['feedback']) && (strstr($_POST['action'], 'move_received') OR
  204. $_POST['action'] == 'delete_received' OR $_POST['action'] == 'download_received' OR
  205. $_POST['action'] == 'delete_sent' OR $_POST['action'] == 'download_sent')) {
  206. $display_message = handle_multiple_actions();
  207. Display :: display_normal_message($display_message);
  208. }
  209. // Store Feedback
  210. if (isset($_POST['feedback'])) {
  211. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  212. api_not_allowed();
  213. }
  214. $check = Security::check_token();
  215. if ($check) {
  216. $display_message = store_feedback();
  217. Display :: display_normal_message($display_message);
  218. Security::check_token();
  219. }
  220. }
  221. // Error Message
  222. if (isset($_GET['error']) AND !empty($_GET['error'])) {
  223. Display :: display_normal_message(get_lang($_GET['error']));
  224. }
  225. if ($action != 'add') {
  226. // Getting all the categories in the dropbox for the given user
  227. $dropbox_categories = get_dropbox_categories();
  228. // Greating the arrays with the categories for the received files and for the sent files
  229. foreach ($dropbox_categories as $category) {
  230. if ($category['received'] == '1') {
  231. $dropbox_received_category[] = $category;
  232. }
  233. if ($category['sent'] == '1') {
  234. $dropbox_sent_category[] = $category;
  235. }
  236. }
  237. // ACTIONS
  238. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  239. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  240. // This is for the categories
  241. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  242. $view_dropbox_category_received = Security::remove_XSS($_GET['view_received_category']);
  243. } else {
  244. $view_dropbox_category_received = 0;
  245. }
  246. /* Menu Received */
  247. if (api_get_session_id() == 0) {
  248. echo '<div class="actions">';
  249. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  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. echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
  252. $movelist[0] = 'Root'; // move_received selectbox content
  253. } else {
  254. 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>';
  255. }
  256. echo '</div>';
  257. } else {
  258. if (api_is_allowed_to_session_edit(false, true)) {
  259. echo '<div class="actions">';
  260. if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
  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. echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'</strong> ';
  263. $movelist[0] = 'Root'; // move_received selectbox content
  264. } else {
  265. 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>';
  266. }
  267. echo '</div>';
  268. }
  269. }
  270. }
  271. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  272. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  273. // This is for the categories
  274. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  275. $view_dropbox_category_sent = $_GET['view_sent_category'];
  276. } else {
  277. $view_dropbox_category_sent = 0;
  278. }
  279. /* Menu Sent */
  280. if (api_get_session_id() == 0) {
  281. echo '<div class="actions">';
  282. if ($view_dropbox_category_sent != 0) {
  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. echo get_lang('Category').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
  285. } else {
  286. 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";
  287. }
  288. if (empty($_GET['view_sent_category'])) {
  289. 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>";
  290. }
  291. echo '</div>';
  292. } else {
  293. if (api_is_allowed_to_session_edit(false, true)) {
  294. echo '<div class="actions">';
  295. if ($view_dropbox_category_sent != 0) {
  296. echo get_lang('CurrentlySeeing').': <strong>'.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'</strong> ';
  297. 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>";
  298. } else {
  299. 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";
  300. }
  301. if (empty($_GET['view_sent_category'])) {
  302. 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>";
  303. }
  304. echo '</div>';
  305. }
  306. }
  307. }
  308. /* THE MENU TABS */
  309. if ($dropbox_cnf['sent_received_tabs']) {
  310. ?>
  311. <div id="tabbed_menu">
  312. <ul id="tabbed_menu_tabs">
  313. <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>
  314. <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>
  315. </ul>
  316. </div>
  317. <?php
  318. }
  319. /* RECEIVED FILES */
  320. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  321. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  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($_user['user_id'], $is_courseAdmin, $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) { // we only display the files that are in the category that we are in.
  372. $dropbox_file_data[] = $dropbox_file->id;
  373. if (!is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  374. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
  375. }
  376. // New icon
  377. $new_icon = '';
  378. if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id, $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  379. $new_icon = '&nbsp;'.Display::return_icon('new_dropbox_message.png', get_lang('New'),'',22);
  380. }
  381. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&amp;id='.$dropbox_file->id.'">';
  382. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  383. $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;
  384. $file_size = $dropbox_file->filesize;
  385. $dropbox_file_data[] = format_file_size($file_size);
  386. $dropbox_file_data[] = $dropbox_file->author;
  387. //$dropbox_file_data[] = $dropbox_file->description;
  388. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  389. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  390. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  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=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',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=movereceived&amp;move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',22).'</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=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>';
  394. //$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>
  395. // <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>';
  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;'),22).'</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'),'',22).'</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(\''.$category['cat_name'].'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</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') . '->'. $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. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  450. // This is for the categories
  451. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  452. $view_dropbox_category_sent = $_GET['view_sent_category'];
  453. } else {
  454. $view_dropbox_category_sent = 0;
  455. }
  456. // Object initialisation
  457. $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
  458. // Constructing the array that contains the total number of feedback messages per document.
  459. $number_feedback = get_total_number_feedback();
  460. // Sorting and paging options
  461. $sorting_options = array();
  462. $paging_options = array();
  463. // The headers of the sortable tables
  464. $column_header = array();
  465. $column_header[] = array('', false, '');
  466. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  467. $column_header[] = array(get_lang('SentTitle'), true, '');
  468. $column_header[] = array(get_lang('Size'), true, '');
  469. $column_header[] = array(get_lang('SentTo'), true, '');
  470. $column_header[] = array(get_lang('LastResent'), true, '');
  471. if (api_get_session_id() == 0) {
  472. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  473. } elseif (api_is_allowed_to_session_edit(false, true)) {
  474. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  475. }
  476. $column_header[] = array('RealDate', true);
  477. $column_header[] = array('RealSize', true);
  478. $column_show = array();
  479. $column_order = array();
  480. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  481. $column_show[] = 1;
  482. $column_show[] = 1;
  483. $column_show[] = 1;
  484. $column_show[] = 1;
  485. $column_show[] = 1;
  486. $column_show[] = 1;
  487. if (api_get_session_id() == 0) {
  488. $column_show[] = 1;
  489. } elseif (api_is_allowed_to_session_edit(false, true)) {
  490. $column_show[] = 1;
  491. }
  492. $column_show[] = 0;
  493. // Here we change the way how the colums are going to be sort
  494. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  495. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  496. $column_order[3] = 8;
  497. $column_order[5] = 7;
  498. // The content of the sortable table = the received files
  499. foreach ($dropbox_person -> sentWork as $dropbox_file) {
  500. $dropbox_file_data = array();
  501. if ($view_dropbox_category_sent == $dropbox_file->category) {
  502. $dropbox_file_data[] = $dropbox_file->id;
  503. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  504. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  505. $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;
  506. $file_size = $dropbox_file->filesize;
  507. $dropbox_file_data[] = format_file_size($file_size);
  508. foreach ($dropbox_file->recipients as $recipient) {
  509. $receivers_celldata = display_user_link_work($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
  510. }
  511. $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
  512. $dropbox_file_data[] = $receivers_celldata;
  513. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  514. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  515. //$dropbox_file_data[] = $dropbox_file->author;
  516. $receivers_celldata = '';
  517. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  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=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',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=movesent&amp;move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',22).'</a>
  520. <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>';
  521. // This is a hack to have an additional row in a sortable table
  522. if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  523. $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
  524. $action_icons .= "<tr><td colspan=\"2\">";
  525. $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>";
  526. $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
  527. }
  528. $dropbox_file_data[] = $action_icons;
  529. $dropbox_file_data[] = $last_upload_date;
  530. $dropbox_file_data[] = $file_size;
  531. $action_icons = '';
  532. $dropbox_data_sent[] = $dropbox_file_data;
  533. }
  534. }
  535. // The content of the sortable table = the categories (if we are not in the root)
  536. if ($view_dropbox_category_sent == 0) {
  537. foreach ($dropbox_categories as $category) {
  538. $dropbox_category_data = array();
  539. if ($category['sent'] == '1') {
  540. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear.
  541. $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']).'">';
  542. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  543. $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>';
  544. //$dropbox_category_data[] = '';
  545. $dropbox_category_data[] = '';
  546. //$dropbox_category_data[] = '';
  547. $dropbox_category_data[] = '';
  548. $dropbox_category_data[] = '';
  549. $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>
  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(\''.$category['cat_name'].'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  551. }
  552. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  553. $dropbox_data_sent[] = $dropbox_category_data;
  554. }
  555. }
  556. }
  557. // Displaying the table
  558. $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']));
  559. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  560. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  561. $selectlist = array('download_received' => get_lang('Download'));
  562. }
  563. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  564. }
  565. }
  566. Display::display_footer();