index.php 37 KB

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