dropbox_init.inc.php 7.5 KB

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