dropbox_init.inc.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 claro_init_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 langfile
  49. // name of the language file that needs to be included
  50. $language_file = "dropbox";
  51. //this var disables the link in the breadcrumps on top of the page
  52. //$noPHP_SELF = TRUE;
  53. // including the basic Dokeos initialisation file
  54. require("../inc/global.inc.php");
  55. // the dropbox configuration parameters
  56. include_once('dropbox_config.inc.php');
  57. // the dropbox sanity files (adds a new table and some new fields)
  58. include_once('dropbox_sanity.inc.php');
  59. // the dropbox file that contains additional functions
  60. include_once('dropbox_functions.inc.php');
  61. // protecting the script
  62. api_protect_course_script();
  63. /*
  64. -----------------------------------------------------------
  65. Libraries
  66. -----------------------------------------------------------
  67. */
  68. require_once(api_get_path(LIBRARY_PATH)."/debug.lib.inc.php");
  69. require_once(api_get_path(LIBRARY_PATH) . "/course.lib.php");
  70. require_once(api_get_path(LIBRARY_PATH) . "/groupmanager.lib.php");
  71. // including the library for the sortable table
  72. require_once(api_get_path(LIBRARY_PATH).'/tablesort.lib.php');
  73. // including the library for the dropbox
  74. require_once( "dropbox_class.inc.php");
  75. // including the library to do the tracking
  76. require_once(api_get_path(LIBRARY_PATH).'/events.lib.inc.php');
  77. // including some libraries that are also used in the documents tool
  78. require_once('../document/document.inc.php'); // we use a function build_document_icon_tag
  79. require_once(api_get_path(LIBRARY_PATH).'/fileDisplay.lib.php'); // the function choose_image is used
  80. require_once(api_get_path(LIBRARY_PATH).'/document.lib.php');
  81. /*
  82. -----------------------------------------------------------
  83. Virtual course support
  84. -----------------------------------------------------------
  85. */
  86. $user_id = api_get_user_id();
  87. $course_code = $_course['sysCode'];
  88. $course_info = Database::get_course_info($course_code);
  89. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_info);
  90. /*
  91. -----------------------------------------------------------
  92. Object Initialisation
  93. -----------------------------------------------------------
  94. */
  95. // we need this here because the javascript to re-upload the file needs an array
  96. // off all the documents that have already been sent.
  97. // @todo consider moving the javascripts in a function that displays the javascripts
  98. // only when it is needed.
  99. if ($_GET['action']=='add')
  100. {
  101. $dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
  102. }
  103. /*
  104. -----------------------------------------------------------
  105. create javascript and htmlHeaders
  106. // RH: Mailing: new function confirmsend
  107. -----------------------------------------------------------
  108. */
  109. $javascript = "<script>
  110. function confirmsend ()
  111. {
  112. if (confirm(\"".dropbox_lang("mailingConfirmSend", "noDLTT")."\")){
  113. return true;
  114. } else {
  115. return false;
  116. }
  117. return true;
  118. }
  119. function confirmation (name)
  120. {
  121. if (confirm(\"".dropbox_lang("confirmDelete", "noDLTT")." : \"+ name )){
  122. return true;
  123. } else {
  124. return false;
  125. }
  126. return true;
  127. }
  128. function checkForm (frm)
  129. {
  130. if (frm.elements['recipients[]'].selectedIndex < 0){
  131. alert(\"".dropbox_lang("noUserSelected", "noDLTT")."\");
  132. return false;
  133. } else if (frm.file.value == '') {
  134. alert(\"".dropbox_lang("noFileSpecified", "noDLTT")."\");
  135. return false;
  136. } else {
  137. return true;
  138. }
  139. }
  140. ";
  141. if (dropbox_cnf("allowOverwrite"))
  142. {
  143. $javascript .= "
  144. var sentArray = new Array("; //sentArray keeps list of all files still available in the sent files list
  145. //of the user.
  146. //This is used to show or hide the overwrite file-radio button of the upload form
  147. for($i=0; $i<count($dropbox_person->sentWork); $i++)
  148. {
  149. if ($i > 0)
  150. {
  151. $javascript .= ", ";
  152. }
  153. $javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
  154. //echo '***'.$dropbox_person->sentWork[$i]->title;
  155. }
  156. $javascript .=");
  157. function checkfile(str)
  158. {
  159. ind = str.lastIndexOf('/'); //unix separator
  160. if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
  161. filename = str.substring(ind+1, str.length);
  162. found = 0;
  163. for (i=0; i<sentArray.length; i++) {
  164. if (sentArray[i] == filename) found=1;
  165. }
  166. //always start with unchecked box
  167. el = getElement('cb_overwrite');
  168. el.checked = false;
  169. //show/hide checkbox
  170. if (found == 1) {
  171. displayEl('overwrite');
  172. } else {
  173. undisplayEl('overwrite');
  174. }
  175. }
  176. function getElement(id)
  177. {
  178. return document.getElementById ? document.getElementById(id) :
  179. document.all ? document.all(id) : null;
  180. }
  181. function displayEl(id)
  182. {
  183. var el = getElement(id);
  184. if (el && el.style) el.style.display = '';
  185. }
  186. function undisplayEl(id)
  187. {
  188. var el = getElement(id);
  189. if (el && el.style) el.style.display = 'none';
  190. }";
  191. }
  192. $javascript .="
  193. </script>";
  194. $htmlHeadXtra[] = $javascript;
  195. $htmlHeadXtra[] =
  196. "<script>
  197. function confirmation (name)
  198. {
  199. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  200. {return true;}
  201. else
  202. {return false;}
  203. }
  204. </script>";
  205. api_session_register('javascript');
  206. $htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
  207. <meta http-equiv="pragma" content="no-cache">
  208. <meta http-equiv="expires" content="-1">';
  209. $checked_files=false;
  210. if (!$_GET['view'] OR $_GET['view']=='received')
  211. {
  212. $part='received';
  213. }
  214. elseif ($_GET['view']='sent')
  215. {
  216. $part='sent';
  217. }
  218. else
  219. {
  220. header ('location: index.php?view='.$_GET['view'].'&error=Error');
  221. }
  222. if ($_POST['actions']=='download' and !$_POST['store_feedback'])
  223. {
  224. foreach ($_POST as $key=>$value)
  225. {
  226. if (strstr($key,$part.'_'))
  227. {
  228. $checked_files=true;
  229. $checked_file_ids[]=$value;
  230. }
  231. }
  232. if ($checked_files==false)
  233. {
  234. header ('location: index.php?view='.$_GET['view'].'&error=CheckAtLeastOneFile');
  235. exit;
  236. }
  237. else
  238. {
  239. handle_multiple_actions();
  240. exit;
  241. }
  242. }
  243. /*
  244. ==============================================================================
  245. HEADER & TITLE
  246. ==============================================================================
  247. */
  248. $nameTools = dropbox_lang("dropbox", "noDLTT");
  249. if ($origin != 'learnpath')
  250. {
  251. Display::display_header($nameTools,"Dropbox");
  252. }
  253. else // if we come from the learning path we have to include the stylesheet and the required javascripts manually.
  254. {
  255. echo '<link rel="stylesheet" type="text/css" href="',api_get_path(WEB_CODE_PATH), 'css/default.css">';
  256. echo $javascript;
  257. }
  258. api_display_tool_title();
  259. /*
  260. * ========================================
  261. * AUTHORISATION SECTION
  262. * ========================================
  263. * Prevents access of all users that are not course members
  264. */
  265. if(! $is_allowed_in_course || ! $is_courseMember)
  266. {
  267. debug ($_SESSION);
  268. api_not_allowed();
  269. if ($origin != 'learnpath')
  270. {
  271. Display::display_footer();
  272. }
  273. exit();
  274. }
  275. /**
  276. * ========================================
  277. *       SANITY CHECK
  278. * ========================================
  279. * @todo This has to be moved to the install / update script
  280. */
  281. if (mysql_query("SELECT * FROM `".$dropbox_cnf['tbl_category']."`")==false)
  282. {
  283. $sql="CREATE TABLE `".$dropbox_cnf['tbl_category']."` (
  284. `cat_id` int(11) NOT NULL auto_increment,
  285. `cat_name` text NOT NULL,
  286. `received` enum('0','1') NOT NULL default '0',
  287. `sent` enum('0','1') NOT NULL default '0',
  288. `user_id` int(11) NOT NULL default '0',
  289. PRIMARY KEY (`cat_id`)
  290. );";
  291. api_sql_query($sql);
  292. }
  293. if (mysql_query("SELECT cat_id FROM `".$dropbox_cnf["fileTbl"]."`")==false)
  294. {
  295. $sql="ALTER TABLE `".$dropbox_cnf["fileTbl"]."`
  296. ADD `cat_id` int(11) NOT NULL default '0'";
  297. api_sql_query($sql);
  298. }
  299. ?>