dropbox_init.inc.php 14 KB

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