dropbox_init.inc.php 9.4 KB

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