dropbox_init.inc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. /**
  87. * First initialisation file with initialisation of variables and
  88. * without outputting anything to browser.
  89. * 1. Calls global.inc.php and lang file
  90. * 2. Initialises $dropbox_cnf array with all relevant vars
  91. * 3. Often used functions
  92. *
  93. * @version 1.31
  94. * @copyright 2004-2005
  95. * @author Jan Bols <jan@ivpv.UGent.be>, main programmer
  96. * @author René Haentjens, severalcontributions <rene.haentjens@UGent.be>
  97. * @author Roan Embrechts, virtual course support
  98. * @author Patrick Cool <patrick.cool@UGent.be>
  99. Chamilo Config Settings (AWACS)
  100. Refactoring
  101. tool introduction
  102. folders
  103. download file / folder (download icon)
  104. same action on multiple documents
  105. extended feedback
  106. * @package chamilo.dropbox
  107. */
  108. /**
  109. * Code
  110. */
  111. /* INIT SECTION */
  112. use \ChamiloSession as Session;
  113. $language_file = array('dropbox', 'document');
  114. // including the basic Chamilo initialisation file
  115. require_once '../inc/global.inc.php';
  116. $is_allowed_in_course = api_is_allowed_in_course();
  117. $is_courseTutor = api_is_course_tutor();
  118. $is_courseAdmin = api_is_course_admin();
  119. $current_course_tool = TOOL_DROPBOX;
  120. // the dropbox configuration parameters
  121. $dropbox_cnf = require_once 'dropbox_config.inc.php';
  122. Session::write('dropbox_conf', $dropbox_cnf);
  123. // the dropbox file that contains additional functions
  124. require_once 'dropbox_functions.inc.php';
  125. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  126. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  127. // protecting the script
  128. api_protect_course_script();
  129. /* Libraries */
  130. // including the library for the dropbox
  131. require_once 'dropbox_class.inc.php';
  132. // including some libraries that are also used in the documents tool
  133. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; // we use a function build_document_icon_tag
  134. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function choose_image is used
  135. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  136. /* Virtual course support */
  137. $user_id = api_get_user_id();
  138. $course_code = api_get_course_id();
  139. $course_info = api_get_course_info($course_code);
  140. $session_id = api_get_session_id();
  141. $action = isset($_GET['action']) ? $_GET['action'] : null;
  142. $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
  143. $postAction = isset($_POST['action']) ? $_POST['action'] : null;
  144. if (empty($session_id)) {
  145. $is_course_member = CourseManager::is_user_subscribed_in_course($user_id, $course_code, false);
  146. } else {
  147. $is_course_member = CourseManager::is_user_subscribed_in_course($user_id, $course_code, true, $session_id);
  148. }
  149. /* Object Initialisation */
  150. // we need this here because the javascript to re-upload the file needs an array
  151. // off all the documents that have already been sent.
  152. // @todo consider moving the javascripts in a function that displays the javascripts
  153. // only when it is needed.
  154. if ($action == 'add') {
  155. $dropbox_person = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
  156. }
  157. /* Create javascript and htmlHeaders */
  158. $javascript = "<script type=\"text/javascript\">
  159. function confirmsend ()
  160. {
  161. if (confirm(\"".get_lang('MailingConfirmSend', '')."\")){
  162. return true;
  163. } else {
  164. return false;
  165. }
  166. return true;
  167. }
  168. function confirmation (name)
  169. {
  170. if (confirm(\"".get_lang('ConfirmDelete', '')." : \"+ name )){
  171. return true;
  172. } else {
  173. return false;
  174. }
  175. return true;
  176. }
  177. function checkForm (frm)
  178. {
  179. if (frm.elements['recipients[]'].selectedIndex < 0){
  180. alert(\"".get_lang('NoUserSelected', '')."\");
  181. return false;
  182. } else if (frm.file.value == '') {
  183. alert(\"".get_lang('NoFileSpecified', '')."\");
  184. return false;
  185. } else {
  186. return true;
  187. }
  188. }
  189. ";
  190. if (dropbox_cnf('allowOverwrite')) {
  191. //sentArray keeps list of all files still available in the sent files list
  192. //of the user.
  193. //This is used to show or hide the overwrite file-radio button of the upload form
  194. $javascript .= "
  195. var sentArray = new Array(";
  196. if (isset($dropbox_person)) {
  197. for ($i = 0; $i < count($dropbox_person->sentWork); $i++) {
  198. if ($i > 0) {
  199. $javascript .= ", ";
  200. }
  201. $javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
  202. }
  203. }
  204. $javascript .= ");
  205. function checkfile(str)
  206. {
  207. ind = str.lastIndexOf('/'); //unix separator
  208. if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
  209. filename = str.substring(ind+1, str.length);
  210. found = 0;
  211. for (i=0; i<sentArray.length; i++) {
  212. if (sentArray[i] == filename) found=1;
  213. }
  214. //always start with unchecked box
  215. el = getElement('cb_overwrite');
  216. el.checked = false;
  217. //show/hide checkbox
  218. if (found == 1) {
  219. displayEl('overwrite');
  220. } else {
  221. undisplayEl('overwrite');
  222. }
  223. }
  224. function getElement(id)
  225. {
  226. return document.getElementById ? document.getElementById(id) :
  227. document.all ? document.all(id) : null;
  228. }
  229. function displayEl(id)
  230. {
  231. var el = getElement(id);
  232. if (el && el.style) el.style.display = '';
  233. }
  234. function undisplayEl(id)
  235. {
  236. var el = getElement(id);
  237. if (el && el.style) el.style.display = 'none';
  238. }";
  239. }
  240. $javascript .= "
  241. </script>";
  242. $htmlHeadXtra[] = $javascript;
  243. $htmlHeadXtra[] =
  244. "<script type=\"text/javascript\">
  245. function confirmation (name)
  246. {
  247. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  248. {return true;}
  249. else
  250. {return false;}
  251. }
  252. </script>";
  253. Session::write('javascript',$javascript);
  254. $htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
  255. <meta http-equiv="pragma" content="no-cache">
  256. <meta http-equiv="expires" content="-1">';
  257. $checked_files = false;
  258. if (!$view OR $view == 'received') {
  259. $part = 'received';
  260. } elseif ($view = 'sent') {
  261. $part = 'sent';
  262. } else {
  263. header ('location: index.php?view='.$view.'&error=Error');
  264. }
  265. if (($postAction == 'download_received' || $postAction == 'download_sent') and !$_POST['store_feedback']) {
  266. $checked_file_ids = $_POST['id'];
  267. if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
  268. header ('location: index.php?view='.$view.'&error=CheckAtLeastOneFile');
  269. } else {
  270. handle_multiple_actions();
  271. }
  272. exit;
  273. }
  274. /*
  275. * AUTHORISATION SECTION
  276. * Prevents access of all users that are not course members
  277. */
  278. if ((!$is_allowed_in_course || !$is_course_member) && !api_is_allowed_to_edit(null, true)) {
  279. if ($origin != 'learnpath') {
  280. api_not_allowed(true);//print headers/footers
  281. } else {
  282. api_not_allowed();
  283. }
  284. exit();
  285. }
  286. /* BREADCRUMBS */
  287. if ($view == 'received') {
  288. $interbreadcrumb[] = array('url' => '../dropbox/index.php', 'name' => get_lang('Dropbox', ''));
  289. $nameTools = get_lang('ReceivedFiles');
  290. if ($action == 'addreceivedcategory') {
  291. $interbreadcrumb[] = array('url' => '../dropbox/index.php?view=received', 'name' => get_lang('ReceivedFiles'));
  292. $nameTools = get_lang('AddNewCategory');
  293. }
  294. }
  295. if ($view == 'sent' OR empty($view)) {
  296. $interbreadcrumb[] = array('url' => '../dropbox/index.php', 'name' => get_lang('Dropbox', ''));
  297. $nameTools = get_lang('SentFiles');
  298. if ($action == 'addsentcategory') {
  299. $interbreadcrumb[] = array('url' => '../dropbox/index.php?view=sent', 'name' => get_lang('SentFiles'));
  300. $nameTools = get_lang('AddNewCategory');
  301. }
  302. if ($action == 'add') {
  303. $interbreadcrumb[] = array ('url' => '../dropbox/index.php?view=sent', 'name' => get_lang('SentFiles'));
  304. $nameTools = get_lang('UploadNewFile');
  305. }
  306. }
  307. /* HEADER & TITLE */
  308. if (isset($origin) && $origin == 'learnpath') {
  309. // if we come from the learning path we have to include the stylesheet and the required javascripts manually.
  310. echo '<link rel="stylesheet" type="text/css" href="', api_get_path(WEB_CODE_PATH), 'css/default.css">';
  311. echo $javascript;
  312. } else {
  313. Display::display_header($nameTools, 'Dropbox');
  314. }