dropbox_init.inc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  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
  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 chamilo.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
  22. * the implementation of the dropbox categories could (on the database level) have been done more elegantly by storing the category
  23. * in the dropbox_person table because this table stores the relationship between the files (sent OR received) and the users
  24. */
  25. /**
  26. HISTORY
  27. Version 1.1
  28. ------------
  29. - dropbox_init1.inc.php: changed include statements to require statements.
  30. This way if a file is not found, it stops the execution of a script instead of continuing with warnings.
  31. - dropbox_init1.inc.php: the include files "claro_init_global.inc.php" & "debug.lib.inc.php" are first checked for
  32. their existence before including them. If they don't exist, in the .../include dir,
  33. they get loaded from the .../inc dir. This change is necessary because the UCL changed the include dir to inc.
  34. - dropbox_init1.inc.php: the databasetable name in the variable $dropbox_cnf["introTbl"]
  35. is changed from "introduction" to "tool_intro"
  36. - install.php: after submit, checks if the database uses accueil or tool_list as a tablename
  37. - index.php: removed the behaviour of only the teachers that are allowed to delete entries
  38. - index.php: added field "lastUploadDate" in table dropbox_file to store information
  39. about last update when resubmiting a file
  40. - dropbox.inc.php: added $lang["lastUpdated"]
  41. - index.php: entries in received list show when file was last updated if it is updated
  42. - index.php: entries in sent list show when file was last resent if it was resent
  43. - index.php: add POST-variable to the upload form with overwrite data when
  44. user decides to overwrite the previous sent file with new file
  45. - dropbox_submit.php: add sanity checks on POST['overwrite'] data
  46. - index.php: remove title field in upload form
  47. - dropbox_init1.inc.php: added $dropbox_cnf["version"] variable
  48. - dropbox_class.inc.php: add $this->lastUploadDate to Dropbox_work class
  49. - dropbox.inc.php: added $lang['emptyTable']
  50. - index.php: if the received or sent list is empty, a message is displayed
  51. - dropbox_download.php: the $file var is set equal to the title-field of the filetable.
  52. So not constructed anymore by substracting the username from the filename
  53. - index.php: add check to see if column lastUploadDate exists in filetable
  54. - index.php: moved javascripts from dropbox_init2.inc.php to index.php
  55. - index.php: when specifying an uploadfile in the form, a checkbox allowing the user to overwrite a
  56. previously sent file is shown when the specified file has the same name as a previously uploaded file of that user.
  57. - index.php: assign all the metadata (author, description, date, recipient, sender) of an
  58. entry in a list to the class="dropbox_detail" and add css to html-header
  59. - index.php: assign all dates of entries in list to the class="dropbox_date" and add CSS
  60. - index.php: assign all persons in entries of list to the class="dropbox_person" and add CSS
  61. - dropbox.inc.php: added $lang['dropbox_version'] to indicate the lates version.
  62. This must be equal to the $dropbox_cnf['version'] variable.
  63. - dropbox_init1.inc.php: if the newest lang file isn't loaded by claro_init_global.inc.php
  64. from the .../lang dir it will be loaded locally from the .../plugin/dropbox/ dir.
  65. This way an administrator must not install the dropbox.inc.php in the .../lang/english dir,
  66. but he can leave it in the local .../plugin/dropbox/ dir.
  67. However if you want to present multiple language translations of the file you must still
  68. put the file in the /lang/ dir, because there is no language management system inside the .../plugin/dropbox dir.
  69. - mime.inc.php: created this file. It contains an array $mimetype with all the mimetypes
  70. that are used by dropbox_download.php to give hinst to the browser during download about content
  71. - dropbox_download.php: remove https specific headers because they're not necessary
  72. - dropbox_download.php: use application/octet-stream as the default mime and inline as the default Content-Disposition
  73. - dropbox.inc.php: add lang vars for "order by" action
  74. - dropbox_class.inc.php: add methods orderSentWork, orderReceivedWork en _cmpWork and
  75. propery _orderBy to class Dropbox_person to take care of sorting
  76. - index.php: add selectionlist to headers of sent/received lists to select "order by"
  77. and add code to keep selected value in sessionvar.
  78. - index.php: moved part of a <a> hyperlink to previous line to remove the underlined space between
  79. symbol and title of a work entry in the sent/received list
  80. - index.php: add filesize info in sent/received lists
  81. - dropbox_submit.php: resubmit prevention only for GET action, because it gives some annoying behaviour in POST
  82. * situation: white screen in IE6.
  83. Version 1.2
  84. -----------
  85. - adapted entire dropbox tool so it can be used as a default tool in Dokeos 1.5
  86. - index.php: add event registration to log use of tool in stats tables
  87. - index.php: upload form checks for correct user selection and file specification before uploading the script
  88. - dropbox_init1.inc.php: added dropbox_cnf["allowOverwrite"] to allow or disallow overwriting of files
  89. - index.php: author name textbox is automatically filled in
  90. - mailing functionality (René Haentjens)
  91. - allowStudentToStudent and allowJustUpload options (id.)
  92. - help in separate window (id.)
  93. Version 1.3 (Patrick Cool)
  94. --------------------------
  95. - sortable table
  96. - categories
  97. - fixing a security hole
  98. - tabs (which can be disabled: see $dropbox_cnf['sent_received_tabs'])
  99. - same action on multiple documents ([zip]download, move, delete)
  100. - consistency with the docuements tool (open/download file, icons of documents, ...)
  101. - zip download of complete folder
  102. Version 1.4 (Yannick Warnier)
  103. -----------------------------
  104. - removed all self-built database tables names
  105. */
  106. /**
  107. * First initialisation file with initialisation of variables and
  108. * without outputting anything to browser.
  109. * 1. Calls global.inc.php and lang file
  110. * 2. Initialises $dropbox_cnf array with all relevant vars
  111. * 3. Often used functions.
  112. *
  113. * @version 1.31
  114. *
  115. * @copyright 2004-2005
  116. * @author Jan Bols <jan@ivpv.UGent.be>, main programmer
  117. * @author René Haentjens, severalcontributions <rene.haentjens@UGent.be>
  118. * @author Roan Embrechts, virtual course support
  119. * @author Patrick Cool <patrick.cool@UGent.be>
  120. * Chamilo Config Settings (AWACS)
  121. * Refactoring
  122. * tool introduction
  123. * folders
  124. * download file / folder (download icon)
  125. * same action on multiple documents
  126. * extended feedback
  127. *
  128. * @package chamilo.dropbox
  129. */
  130. require_once __DIR__.'/../inc/global.inc.php';
  131. $is_allowed_in_course = api_is_allowed_in_course();
  132. $is_courseTutor = api_is_course_tutor();
  133. $is_courseAdmin = api_is_course_admin();
  134. $current_course_tool = TOOL_DROPBOX;
  135. // the dropbox file that contains additional functions
  136. require_once 'dropbox_functions.inc.php';
  137. // protecting the script
  138. api_protect_course_script();
  139. $user_id = api_get_user_id();
  140. $course_code = api_get_course_id();
  141. $course_info = api_get_course_info($course_code);
  142. $session_id = api_get_session_id();
  143. $action = isset($_GET['action']) ? $_GET['action'] : null;
  144. $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
  145. $postAction = isset($_POST['action']) ? $_POST['action'] : null;
  146. if (api_is_excluded_user_type()) {
  147. api_not_allowed(true);
  148. }
  149. if (empty($session_id)) {
  150. $is_course_member = CourseManager::is_user_subscribed_in_course(
  151. $user_id,
  152. $course_code,
  153. false
  154. );
  155. } else {
  156. $is_course_member = CourseManager::is_user_subscribed_in_course(
  157. $user_id,
  158. $course_code,
  159. true,
  160. $session_id
  161. );
  162. }
  163. // we need this here because the javascript to re-upload the file needs an array
  164. // off all the documents that have already been sent.
  165. // @todo consider moving the javascripts in a function that displays the javascripts
  166. // only when it is needed.
  167. if ($action == 'add') {
  168. $dropbox_person = new Dropbox_Person(
  169. $user_id,
  170. $is_courseAdmin,
  171. $is_courseTutor
  172. );
  173. }
  174. /* Create javascript and htmlHeaders */
  175. $javascript = "<script>
  176. function confirmsend()
  177. {
  178. if (confirm(\"".get_lang('MailingConfirmSend')."\")){
  179. return true;
  180. } else {
  181. return false;
  182. }
  183. return true;
  184. }
  185. function confirmation (name)
  186. {
  187. if (confirm(\"".get_lang('ConfirmDelete')." : \"+ name )){
  188. return true;
  189. } else {
  190. return false;
  191. }
  192. return true;
  193. }
  194. function checkForm (frm)
  195. {
  196. if (frm.elements['recipients[]'].selectedIndex < 0){
  197. alert(\"".get_lang('NoUserSelected')."\");
  198. return false;
  199. } else if (frm.file.value == '') {
  200. alert(\"".get_lang('NoFileSpecified')."\");
  201. return false;
  202. } else {
  203. return true;
  204. }
  205. }
  206. ";
  207. $allowOverwrite = api_get_setting('dropbox_allow_overwrite');
  208. if ($allowOverwrite == 'true') {
  209. //sentArray keeps list of all files still available in the sent files list
  210. //of the user.
  211. //This is used to show or hide the overwrite file-radio button of the upload form
  212. $javascript .= " var sentArray = new Array(";
  213. if (isset($dropbox_person)) {
  214. for ($i = 0; $i < count($dropbox_person->sentWork); $i++) {
  215. if ($i > 0) {
  216. $javascript .= ", ";
  217. }
  218. $javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
  219. }
  220. }
  221. $javascript .= ");
  222. function checkfile(str)
  223. {
  224. ind = str.lastIndexOf('/'); //unix separator
  225. if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
  226. filename = str.substring(ind+1, str.length);
  227. found = 0;
  228. for (i=0; i<sentArray.length; i++) {
  229. if (sentArray[i] == filename) found=1;
  230. }
  231. //always start with unchecked box
  232. el = getElement('cb_overwrite');
  233. el.checked = false;
  234. //show/hide checkbox
  235. if (found == 1) {
  236. displayEl('overwrite');
  237. } else {
  238. undisplayEl('overwrite');
  239. }
  240. }
  241. function getElement(id)
  242. {
  243. return document.getElementById ? document.getElementById(id) :
  244. document.all ? document.all(id) : null;
  245. }
  246. function displayEl(id)
  247. {
  248. var el = getElement(id);
  249. if (el && el.style) el.style.display = '';
  250. }
  251. function undisplayEl(id)
  252. {
  253. var el = getElement(id);
  254. if (el && el.style) el.style.display = 'none';
  255. }";
  256. }
  257. $javascript .= "
  258. </script>";
  259. $htmlHeadXtra[] = $javascript;
  260. $htmlHeadXtra[] = "<script>
  261. function confirmation (name)
  262. {
  263. if (confirm(\" ".get_lang("Are you sure to delete")." \"+ name + \" ?\"))
  264. {return true;}
  265. else
  266. {return false;}
  267. }
  268. </script>";
  269. Session::write('javascript', $javascript);
  270. $htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
  271. <meta http-equiv="pragma" content="no-cache">
  272. <meta http-equiv="expires" content="-1">';
  273. $htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
  274. $htmlHeadXtra[] = "<script>
  275. $(function () {
  276. $('#recipient_form').on('change', function() {
  277. $('#multiple_form').show();
  278. });
  279. });
  280. </script>";
  281. $checked_files = false;
  282. if (!$view || $view == 'received') {
  283. $part = 'received';
  284. } elseif ($view = 'sent') {
  285. $part = 'sent';
  286. } else {
  287. header('location: index.php?'.api_get_cidreq().'&view='.$view.'&error=Error');
  288. exit;
  289. }
  290. if (($postAction == 'download_received' || $postAction == 'download_sent') and !$_POST['store_feedback']) {
  291. $checked_file_ids = $_POST['id'];
  292. if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
  293. header('Location: index.php?'.api_get_cidreq().'&view='.$view.'&error=CheckAtLeastOneFile');
  294. } else {
  295. handle_multiple_actions();
  296. }
  297. exit;
  298. }
  299. /*
  300. * AUTHORISATION SECTION
  301. * Prevents access of all users that are not course members
  302. */
  303. if ((!$is_allowed_in_course || !$is_course_member) &&
  304. !api_is_allowed_to_edit(null, true)
  305. ) {
  306. if ($origin != 'learnpath') {
  307. api_not_allowed(true); //print headers/footers
  308. } else {
  309. api_not_allowed();
  310. }
  311. exit();
  312. }
  313. /* BREADCRUMBS */
  314. if ($view == 'received') {
  315. $interbreadcrumb[] = [
  316. 'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq(),
  317. 'name' => get_lang('Dropbox'),
  318. ];
  319. $nameTools = get_lang('Received Files');
  320. if ($action == 'addreceivedcategory') {
  321. $interbreadcrumb[] = [
  322. 'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=received&'.api_get_cidreq(),
  323. 'name' => get_lang('Received Files'),
  324. ];
  325. $nameTools = get_lang('Add a new folder');
  326. }
  327. }
  328. if ($view == 'sent' || empty($view)) {
  329. $interbreadcrumb[] = [
  330. 'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq(),
  331. 'name' => get_lang('Dropbox'),
  332. ];
  333. $nameTools = get_lang('Sent Files');
  334. if ($action == 'addsentcategory') {
  335. $interbreadcrumb[] = [
  336. 'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=sent&'.api_get_cidreq(),
  337. 'name' => get_lang('Sent Files'),
  338. ];
  339. $nameTools = get_lang('Add a new folder');
  340. }
  341. if ($action == 'add') {
  342. $nameTools = get_lang('Share a new file');
  343. }
  344. if ($action == 'update') {
  345. $interbreadcrumb[] = [
  346. 'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=sent&'.api_get_cidreq(),
  347. 'name' => get_lang('Sent Files'),
  348. ];
  349. $nameTools = get_lang('Update file');
  350. }
  351. }
  352. /* HEADER & TITLE */
  353. if (isset($origin) && $origin == 'learnpath') {
  354. $htmlHeadXtra[] = $javascript;
  355. Display::display_reduced_header($nameTools, 'Dropbox');
  356. } else {
  357. Display::display_header($nameTools, 'Dropbox');
  358. }