index.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. $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($_user['user_id'], $is_courseAdmin, $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. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  275. // This is for the categories
  276. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  277. $view_dropbox_category_sent = $_GET['view_sent_category'];
  278. } else {
  279. $view_dropbox_category_sent = 0;
  280. }
  281. /* Menu Sent */
  282. if (api_get_session_id() == 0) {
  283. echo '<div class="actions">';
  284. if ($view_dropbox_category_sent != 0) {
  285. 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>";
  286. echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  287. } else {
  288. 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";
  289. }
  290. if (empty($_GET['view_sent_category'])) {
  291. 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>";
  292. }
  293. echo '</div>';
  294. } else {
  295. if (api_is_allowed_to_session_edit(false, true)) {
  296. echo '<div class="actions">';
  297. if ($view_dropbox_category_sent != 0) {
  298. echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
  299. 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>";
  300. } else {
  301. 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";
  302. }
  303. if (empty($_GET['view_sent_category'])) {
  304. 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>";
  305. }
  306. echo '</div>';
  307. }
  308. }
  309. }
  310. /* THE MENU TABS */
  311. if ($dropbox_cnf['sent_received_tabs']) {
  312. ?>
  313. <ul class="nav nav-tabs">
  314. <li <?php if (!$_GET['view'] OR $_GET['view'] == 'sent') { echo 'class="active"'; } ?> >
  315. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=sent" ><?php echo get_lang('SentFiles'); ?></a></li>
  316. <li <?php if ($_GET['view'] == 'received') { echo 'class="active"'; } ?> >
  317. <a href="index.php?<?php echo api_get_cidreq(); ?>&view=received" ><?php echo get_lang('ReceivedFiles'); ?></a></li>
  318. </ul>
  319. <?php
  320. }
  321. /* RECEIVED FILES */
  322. if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
  323. //echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
  324. // This is for the categories
  325. if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
  326. $view_dropbox_category_received = $_GET['view_received_category'];
  327. } else {
  328. $view_dropbox_category_received = 0;
  329. }
  330. // Object initialisation
  331. $dropbox_person = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor); // note: are the $is_courseAdmin and $is_courseTutor parameters needed????
  332. // Constructing the array that contains the total number of feedback messages per document.
  333. $number_feedback = get_total_number_feedback();
  334. // Sorting and paging options
  335. $sorting_options = array();
  336. $paging_options = array();
  337. // The headers of the sortable tables
  338. $column_header = array();
  339. $column_header[] = array('', false, '');
  340. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  341. $column_header[] = array(get_lang('ReceivedTitle'), true, '');
  342. $column_header[] = array(get_lang('Size'), true, '');
  343. $column_header[] = array(get_lang('Authors'), true, '');
  344. $column_header[] = array(get_lang('LastResent'), true);
  345. if (api_get_session_id() == 0) {
  346. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  347. } elseif (api_is_allowed_to_session_edit(false,true)) {
  348. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  349. }
  350. $column_header[] = array('RealDate', true);
  351. $column_header[] = array('RealSize', true);
  352. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  353. $column_show[] = 1;
  354. $column_show[] = 1;
  355. $column_show[] = 1;
  356. $column_show[] = 1;
  357. $column_show[] = 1;
  358. $column_show[] = 1;
  359. if (api_get_session_id() == 0) {
  360. $column_show[] = 1;
  361. } elseif (api_is_allowed_to_session_edit(false, true)) {
  362. $column_show[] = 1;
  363. }
  364. $column_show[] = 0;
  365. // Here we change the way how the colums are going to be sort
  366. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  367. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  368. $column_order[3] = 8;
  369. $column_order[5] = 7;
  370. // The content of the sortable table = the received files
  371. foreach ($dropbox_person -> receivedWork as $dropbox_file) {
  372. $dropbox_file_data = array();
  373. if ($view_dropbox_category_received == $dropbox_file->category) { // we only display the files that are in the category that we are in.
  374. $dropbox_file_data[] = $dropbox_file->id;
  375. if (!is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  376. $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array();
  377. }
  378. // New icon
  379. $new_icon = '';
  380. if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id, $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
  381. $new_icon = '&nbsp;'.Display::return_icon('new_dropbox_message.png', get_lang('New'),'',ICON_SIZE_SMALL);
  382. }
  383. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&amp;id='.$dropbox_file->id.'">';
  384. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  385. $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;
  386. $file_size = $dropbox_file->filesize;
  387. $dropbox_file_data[] = format_file_size($file_size);
  388. $dropbox_file_data[] = $dropbox_file->author;
  389. //$dropbox_file_data[] = $dropbox_file->description;
  390. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  391. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  392. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  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=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',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=movereceived&amp;move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a>
  395. <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'),'',ICON_SIZE_SMALL).'</a>';
  396. //$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>
  397. // <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>';
  398. // This is a hack to have an additional row in a sortable table
  399. if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
  400. $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
  401. $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>";
  402. }
  403. if (api_get_session_id() == 0) {
  404. $dropbox_file_data[] = $action_icons;
  405. } elseif (api_is_allowed_to_session_edit(false, true)) {
  406. $dropbox_file_data[] = $action_icons;
  407. }
  408. $action_icons = '';
  409. $dropbox_file_data[] = $last_upload_date;
  410. $dropbox_file_data[] = $file_size;
  411. $dropbox_data_recieved[] = $dropbox_file_data;
  412. }
  413. }
  414. // The content of the sortable table = the categories (if we are not in the root)
  415. if ($view_dropbox_category_received == 0) {
  416. 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;
  417. $dropbox_category_data = array();
  418. if ($category['received'] == '1') {
  419. $movelist[$category['cat_id']] = $category['cat_name'];
  420. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear
  421. // The icon of the category
  422. $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']).'">';
  423. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', $category['cat_name']).'</a>';
  424. $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>';
  425. $dropbox_category_data[] = '';
  426. $dropbox_category_data[] = '';
  427. $dropbox_category_data[] = '';
  428. $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>
  429. <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>';
  430. }
  431. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  432. $dropbox_data_recieved[] = $dropbox_category_data;
  433. }
  434. }
  435. }
  436. // Displaying the table
  437. $additional_get_parameters = array('view' => $_GET['view'], 'view_received_category' => $_GET['view_received_category'], 'view_sent_category' => $_GET['view_sent_category']);
  438. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  439. if (is_array($movelist)) {
  440. foreach ($movelist as $catid => $catname){
  441. $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname);
  442. }
  443. }
  444. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  445. $selectlist = array();
  446. }
  447. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  448. }
  449. /* SENT FILES */
  450. if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
  451. //echo '<h3>'.get_lang('SentFiles').'</h3>';
  452. // This is for the categories
  453. if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
  454. $view_dropbox_category_sent = $_GET['view_sent_category'];
  455. } else {
  456. $view_dropbox_category_sent = 0;
  457. }
  458. // Object initialisation
  459. $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
  460. // Constructing the array that contains the total number of feedback messages per document.
  461. $number_feedback = get_total_number_feedback();
  462. // Sorting and paging options
  463. $sorting_options = array();
  464. $paging_options = array();
  465. // The headers of the sortable tables
  466. $column_header = array();
  467. $column_header[] = array('', false, '');
  468. $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"');
  469. $column_header[] = array(get_lang('SentTitle'), true, '');
  470. $column_header[] = array(get_lang('Size'), true, '');
  471. $column_header[] = array(get_lang('SentTo'), true, '');
  472. $column_header[] = array(get_lang('LastResent'), true, '');
  473. if (api_get_session_id() == 0) {
  474. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  475. } elseif (api_is_allowed_to_session_edit(false, true)) {
  476. $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"');
  477. }
  478. $column_header[] = array('RealDate', true);
  479. $column_header[] = array('RealSize', true);
  480. $column_show = array();
  481. $column_order = array();
  482. // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
  483. $column_show[] = 1;
  484. $column_show[] = 1;
  485. $column_show[] = 1;
  486. $column_show[] = 1;
  487. $column_show[] = 1;
  488. $column_show[] = 1;
  489. if (api_get_session_id() == 0) {
  490. $column_show[] = 1;
  491. } elseif (api_is_allowed_to_session_edit(false, true)) {
  492. $column_show[] = 1;
  493. }
  494. $column_show[] = 0;
  495. // Here we change the way how the colums are going to be sort
  496. // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
  497. // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
  498. $column_order[3] = 8;
  499. $column_order[5] = 7;
  500. // The content of the sortable table = the received files
  501. foreach ($dropbox_person -> sentWork as $dropbox_file) {
  502. $dropbox_file_data = array();
  503. if ($view_dropbox_category_sent == $dropbox_file->category) {
  504. $dropbox_file_data[] = $dropbox_file->id;
  505. $link_open = '<a href="dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
  506. $dropbox_file_data[] = $link_open.build_document_icon_tag('file', $dropbox_file->title).'</a>';
  507. $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;
  508. $file_size = $dropbox_file->filesize;
  509. $dropbox_file_data[] = format_file_size($file_size);
  510. foreach ($dropbox_file->recipients as $recipient) {
  511. $receivers_celldata = display_user_link_work($recipient['user_id'], $recipient['name']).', '.$receivers_celldata;
  512. }
  513. $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
  514. $dropbox_file_data[] = $receivers_celldata;
  515. $last_upload_date = api_get_local_time($dropbox_file->last_upload_date);
  516. $dropbox_file_data[] = date_to_str_ago($last_upload_date).'<br /><span class="dropbox_date">'.api_format_date($last_upload_date).'</span>';
  517. //$dropbox_file_data[] = $dropbox_file->author;
  518. $receivers_celldata = '';
  519. $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
  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=viewfeedback&amp;id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a>
  521. <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>
  522. <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>';
  523. // This is a hack to have an additional row in a sortable table
  524. if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
  525. $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
  526. $action_icons .= "<tr><td colspan=\"2\">";
  527. $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>";
  528. $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>";
  529. }
  530. $dropbox_file_data[] = $action_icons;
  531. $dropbox_file_data[] = $last_upload_date;
  532. $dropbox_file_data[] = $file_size;
  533. $action_icons = '';
  534. $dropbox_data_sent[] = $dropbox_file_data;
  535. }
  536. }
  537. // The content of the sortable table = the categories (if we are not in the root)
  538. if ($view_dropbox_category_sent == 0) {
  539. foreach ($dropbox_categories as $category) {
  540. $dropbox_category_data = array();
  541. if ($category['sent'] == '1') {
  542. $dropbox_category_data[] = $category['cat_id']; // This is where the checkbox icon for the files appear.
  543. $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']).'">';
  544. $dropbox_category_data[] = $link_open.build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
  545. $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>';
  546. //$dropbox_category_data[] = '';
  547. $dropbox_category_data[] = '';
  548. //$dropbox_category_data[] = '';
  549. $dropbox_category_data[] = '';
  550. $dropbox_category_data[] = '';
  551. $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'].'">'.
  552. Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>
  553. <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']).'\');">'.
  554. Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  555. }
  556. if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
  557. $dropbox_data_sent[] = $dropbox_category_data;
  558. }
  559. }
  560. }
  561. // Displaying the table
  562. $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']));
  563. $selectlist = array('delete_received' => get_lang('Delete'), 'download_received' => get_lang('Download'));
  564. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  565. $selectlist = array('download_received' => get_lang('Download'));
  566. }
  567. Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
  568. }
  569. }
  570. Display::display_footer();