dropbox_init.inc.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php // $Id: dropbox_init1.inc.php,v 1.29 2005/09/12 08:16:16 renehaentjens Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2006 Dokeos S.A.
  6. Copyright (c) 2006 Ghent University (UGent)
  7. Copyright (c) various contributors
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * First initialisation file with initialisation of variables and
  22. * without outputting anything to browser.
  23. * 1. Calls global.inc.php and lang file
  24. * 2. Initialises $dropbox_cnf array with all relevant vars
  25. * 3. Often used functions
  26. *
  27. * @version 1.31
  28. * @copyright 2004-2005
  29. * @author Jan Bols <jan@ivpv.UGent.be>, main programmer
  30. * @author Rene Haentjens, severalcontributions <rene.haentjens@UGent.be> (see RH)
  31. * @author Roan Embrechts, virtual course support
  32. * @author Patrick Cool <patrick.cool@UGent.be>
  33. Dokeos Config Settings (AWACS)
  34. Refactoring
  35. tool introduction
  36. folders
  37. download file / folder (download icon)
  38. same action on multiple documents
  39. extended feedback
  40. * @package dokeos.dropbox
  41. ==============================================================================
  42. */
  43. /*
  44. ==============================================================================
  45. INIT SECTION
  46. ==============================================================================
  47. */
  48. // name of the language file that needs to be included
  49. $language_file = "dropbox";
  50. //this var disables the link in the breadcrumbs on top of the page
  51. //$noPHP_SELF = TRUE;
  52. // including the basic Dokeos initialisation file
  53. require("../inc/global.inc.php");
  54. require_once(api_get_path(LIBRARY_PATH) . "security.lib.php");
  55. // the dropbox configuration parameters
  56. require_once('dropbox_config.inc.php');
  57. // the dropbox sanity files (adds a new table and some new fields)
  58. //require_once('dropbox_sanity.inc.php');
  59. // the dropbox file that contains additional functions
  60. require_once('dropbox_functions.inc.php');
  61. require(api_get_path(INCLUDE_PATH).'/conf/mail.conf.php');
  62. include_once(api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php');
  63. include_once(api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php');
  64. // protecting the script
  65. api_protect_course_script();
  66. /*
  67. -----------------------------------------------------------
  68. Libraries
  69. -----------------------------------------------------------
  70. */
  71. require_once(api_get_path(LIBRARY_PATH)."/debug.lib.inc.php");
  72. require_once(api_get_path(LIBRARY_PATH) . "/course.lib.php");
  73. require_once(api_get_path(LIBRARY_PATH) . "/groupmanager.lib.php");
  74. // including the library for the sortable table
  75. require_once(api_get_path(LIBRARY_PATH).'/tablesort.lib.php');
  76. // including the library for the dropbox
  77. require_once( "dropbox_class.inc.php");
  78. // including the library to do the tracking
  79. require_once(api_get_path(LIBRARY_PATH).'/events.lib.inc.php');
  80. // including some libraries that are also used in the documents tool
  81. require_once('../document/document.inc.php'); // we use a function build_document_icon_tag
  82. require_once(api_get_path(LIBRARY_PATH).'/fileDisplay.lib.php'); // the function choose_image is used
  83. require_once(api_get_path(LIBRARY_PATH).'/document.lib.php');
  84. /*
  85. -----------------------------------------------------------
  86. Virtual course support
  87. -----------------------------------------------------------
  88. */
  89. $user_id = api_get_user_id();
  90. $course_code = $_course['sysCode'];
  91. $course_info = Database::get_course_info($course_code);
  92. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_info);
  93. /*
  94. -----------------------------------------------------------
  95. Object Initialisation
  96. -----------------------------------------------------------
  97. */
  98. // we need this here because the javascript to re-upload the file needs an array
  99. // off all the documents that have already been sent.
  100. // @todo consider moving the javascripts in a function that displays the javascripts
  101. // only when it is needed.
  102. if ($_GET['action']=='add')
  103. {
  104. $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
  105. }
  106. /*
  107. -----------------------------------------------------------
  108. create javascript and htmlHeaders
  109. // RH: Mailing: new function confirmsend
  110. -----------------------------------------------------------
  111. */
  112. $javascript = "<script>
  113. function confirmsend ()
  114. {
  115. if (confirm(\"".dropbox_lang("mailingConfirmSend", "noDLTT")."\")){
  116. return true;
  117. } else {
  118. return false;
  119. }
  120. return true;
  121. }
  122. function confirmation (name)
  123. {
  124. if (confirm(\"".dropbox_lang("confirmDelete", "noDLTT")." : \"+ name )){
  125. return true;
  126. } else {
  127. return false;
  128. }
  129. return true;
  130. }
  131. function checkForm (frm)
  132. {
  133. if (frm.elements['recipients[]'].selectedIndex < 0){
  134. alert(\"".dropbox_lang("noUserSelected", "noDLTT")."\");
  135. return false;
  136. } else if (frm.file.value == '') {
  137. alert(\"".dropbox_lang("noFileSpecified", "noDLTT")."\");
  138. return false;
  139. } else {
  140. return true;
  141. }
  142. }
  143. ";
  144. if (dropbox_cnf("allowOverwrite"))
  145. {
  146. $javascript .= "
  147. var sentArray = new Array("; //sentArray keeps list of all files still available in the sent files list
  148. //of the user.
  149. //This is used to show or hide the overwrite file-radio button of the upload form
  150. for($i=0; $i<count($dropbox_person->sentWork); $i++)
  151. {
  152. if ($i > 0)
  153. {
  154. $javascript .= ", ";
  155. }
  156. $javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
  157. //echo '***'.$dropbox_person->sentWork[$i]->title;
  158. }
  159. $javascript .=");
  160. function checkfile(str)
  161. {
  162. ind = str.lastIndexOf('/'); //unix separator
  163. if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
  164. filename = str.substring(ind+1, str.length);
  165. found = 0;
  166. for (i=0; i<sentArray.length; i++) {
  167. if (sentArray[i] == filename) found=1;
  168. }
  169. //always start with unchecked box
  170. el = getElement('cb_overwrite');
  171. el.checked = false;
  172. //show/hide checkbox
  173. if (found == 1) {
  174. displayEl('overwrite');
  175. } else {
  176. undisplayEl('overwrite');
  177. }
  178. }
  179. function getElement(id)
  180. {
  181. return document.getElementById ? document.getElementById(id) :
  182. document.all ? document.all(id) : null;
  183. }
  184. function displayEl(id)
  185. {
  186. var el = getElement(id);
  187. if (el && el.style) el.style.display = '';
  188. }
  189. function undisplayEl(id)
  190. {
  191. var el = getElement(id);
  192. if (el && el.style) el.style.display = 'none';
  193. }";
  194. }
  195. $javascript .="
  196. </script>";
  197. $htmlHeadXtra[] = $javascript;
  198. $htmlHeadXtra[] =
  199. "<script>
  200. function confirmation (name)
  201. {
  202. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  203. {return true;}
  204. else
  205. {return false;}
  206. }
  207. </script>";
  208. api_session_register('javascript');
  209. $htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
  210. <meta http-equiv="pragma" content="no-cache">
  211. <meta http-equiv="expires" content="-1">';
  212. $checked_files=false;
  213. if (!$_GET['view'] OR $_GET['view']=='received')
  214. {
  215. $part='received';
  216. }
  217. elseif ($_GET['view']='sent')
  218. {
  219. $part='sent';
  220. }
  221. else
  222. {
  223. header ('location: index.php?view='.$_GET['view'].'&error=Error');
  224. }
  225. if (($_POST['action']=='download_received' || $_POST['action']=='download_sent') and !$_POST['store_feedback'])
  226. {
  227. {
  228. $checked_file_ids = $_POST['id'];
  229. if (!is_array($checked_file_ids) || count($checked_file_ids)==0)
  230. {
  231. header ('location: index.php?view='.$_GET['view'].'&error=CheckAtLeastOneFile');
  232. exit;
  233. }
  234. else
  235. handle_multiple_actions();
  236. exit;
  237. }
  238. }
  239. /*
  240. * ========================================
  241. * AUTHORISATION SECTION
  242. * ========================================
  243. * Prevents access of all users that are not course members
  244. */
  245. if((!$is_allowed_in_course || !$is_courseMember) && !api_is_allowed_to_edit())
  246. {
  247. if ($origin != 'learnpath')
  248. {
  249. api_not_allowed(true);//print headers/footers
  250. }else{
  251. api_not_allowed();
  252. }
  253. exit();
  254. }
  255. /*
  256. ==============================================================================
  257. HEADER & TITLE
  258. ==============================================================================
  259. */
  260. $nameTools = dropbox_lang("dropbox", "noDLTT");
  261. if ($origin != 'learnpath')
  262. {
  263. Display::display_header($nameTools,"Dropbox");
  264. }
  265. else // if we come from the learning path we have to include the stylesheet and the required javascripts manually.
  266. {
  267. echo '<link rel="stylesheet" type="text/css" href="',api_get_path(WEB_CODE_PATH), 'css/default.css">';
  268. echo $javascript;
  269. }
  270. api_display_tool_title($nameTools);
  271. ?>