index.php 37 KB

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