dropbox_init.inc.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. /* INIT SECTION */
  26. $language_file = 'dropbox';
  27. // This var disables the link in the breadcrumbs on top of the page
  28. //$noPHP_SELF = true;
  29. // including the basic Chamilo initialisation file
  30. require '../inc/global.inc.php';
  31. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  32. // the dropbox configuration parameters
  33. require_once 'dropbox_config.inc.php';
  34. // the dropbox sanity files (adds a new table and some new fields)
  35. //require_once 'dropbox_sanity.inc.php';
  36. // the dropbox file that contains additional functions
  37. require_once 'dropbox_functions.inc.php';
  38. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  39. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  40. // protecting the script
  41. api_protect_course_script();
  42. /* Libraries */
  43. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  44. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  45. // including the library for the sortable table
  46. require_once api_get_path(LIBRARY_PATH).'tablesort.lib.php';
  47. // including the library for the dropbox
  48. require_once 'dropbox_class.inc.php';
  49. // including some libraries that are also used in the documents tool
  50. require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php'; // we use a function build_document_icon_tag
  51. require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; // the function choose_image is used
  52. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  53. /* Virtual course support */
  54. $user_id = api_get_user_id();
  55. $course_code = $_course['sysCode'];
  56. $course_info = Database::get_course_info($course_code);
  57. $session_id = api_get_session_id();
  58. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code,$session_id);
  59. /* Object Initialisation */
  60. // we need this here because the javascript to re-upload the file needs an array
  61. // off all the documents that have already been sent.
  62. // @todo consider moving the javascripts in a function that displays the javascripts
  63. // only when it is needed.
  64. if ($_GET['action'] == 'add') {
  65. $dropbox_person = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
  66. }
  67. /* Create javascript and htmlHeaders */
  68. $javascript = "<script type=\"text/javascript\">
  69. function confirmsend ()
  70. {
  71. if (confirm(\"".get_lang('MailingConfirmSend', '')."\")){
  72. return true;
  73. } else {
  74. return false;
  75. }
  76. return true;
  77. }
  78. function confirmation (name)
  79. {
  80. if (confirm(\"".get_lang('ConfirmDelete', '')." : \"+ name )){
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. return true;
  86. }
  87. function checkForm (frm)
  88. {
  89. if (frm.elements['recipients[]'].selectedIndex < 0){
  90. alert(\"".get_lang('NoUserSelected', '')."\");
  91. return false;
  92. } else if (frm.file.value == '') {
  93. alert(\"".get_lang('NoFileSpecified', '')."\");
  94. return false;
  95. } else {
  96. return true;
  97. }
  98. }
  99. ";
  100. if (dropbox_cnf('allowOverwrite')) {
  101. $javascript .= "
  102. var sentArray = new Array("; //sentArray keeps list of all files still available in the sent files list
  103. //of the user.
  104. //This is used to show or hide the overwrite file-radio button of the upload form
  105. for ($i = 0; $i < count($dropbox_person->sentWork); $i++) {
  106. if ($i > 0) {
  107. $javascript .= ", ";
  108. }
  109. $javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
  110. //echo '***'.$dropbox_person->sentWork[$i]->title;
  111. }
  112. $javascript .= ");
  113. function checkfile(str)
  114. {
  115. ind = str.lastIndexOf('/'); //unix separator
  116. if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
  117. filename = str.substring(ind+1, str.length);
  118. found = 0;
  119. for (i=0; i<sentArray.length; i++) {
  120. if (sentArray[i] == filename) found=1;
  121. }
  122. //always start with unchecked box
  123. el = getElement('cb_overwrite');
  124. el.checked = false;
  125. //show/hide checkbox
  126. if (found == 1) {
  127. displayEl('overwrite');
  128. } else {
  129. undisplayEl('overwrite');
  130. }
  131. }
  132. function getElement(id)
  133. {
  134. return document.getElementById ? document.getElementById(id) :
  135. document.all ? document.all(id) : null;
  136. }
  137. function displayEl(id)
  138. {
  139. var el = getElement(id);
  140. if (el && el.style) el.style.display = '';
  141. }
  142. function undisplayEl(id)
  143. {
  144. var el = getElement(id);
  145. if (el && el.style) el.style.display = 'none';
  146. }";
  147. }
  148. $javascript .= "
  149. </script>";
  150. $htmlHeadXtra[] = $javascript;
  151. $htmlHeadXtra[] =
  152. "<script type=\"text/javascript\">
  153. function confirmation (name)
  154. {
  155. if (confirm(\" ". get_lang("AreYouSureToDelete") ." \"+ name + \" ?\"))
  156. {return true;}
  157. else
  158. {return false;}
  159. }
  160. </script>";
  161. api_session_register('javascript');
  162. $htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
  163. <meta http-equiv="pragma" content="no-cache">
  164. <meta http-equiv="expires" content="-1">';
  165. $checked_files = false;
  166. if (!$_GET['view'] OR $_GET['view'] == 'received') {
  167. $part = 'received';
  168. } elseif ($_GET['view'] = 'sent') {
  169. $part = 'sent';
  170. } else {
  171. header ('location: index.php?view='.$_GET['view'].'&error=Error');
  172. }
  173. if (($_POST['action'] == 'download_received' || $_POST['action'] == 'download_sent') and !$_POST['store_feedback']) {
  174. $checked_file_ids = $_POST['id'];
  175. if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
  176. header ('location: index.php?view='.$_GET['view'].'&error=CheckAtLeastOneFile');
  177. } else {
  178. handle_multiple_actions();
  179. }
  180. exit;
  181. }
  182. /*
  183. * AUTHORISATION SECTION
  184. * Prevents access of all users that are not course members
  185. */
  186. if ((!$is_allowed_in_course || !$is_course_member) && !api_is_allowed_to_edit(null, true)) {
  187. if ($origin != 'learnpath') {
  188. api_not_allowed(true);//print headers/footers
  189. } else {
  190. api_not_allowed();
  191. }
  192. exit();
  193. }
  194. /* BREADCRUMBS */
  195. if ($_GET['view'] == 'received') {
  196. $interbreadcrumb[] = array('url' => '../dropbox/index.php', 'name' => get_lang('Dropbox', ''));
  197. $nameTools = get_lang('ReceivedFiles');
  198. if ($_GET['action'] == 'addreceivedcategory') {
  199. $interbreadcrumb[] = array('url' => '../dropbox/index.php?view=received', 'name' => get_lang('ReceivedFiles'));
  200. $nameTools = get_lang('AddNewCategory');
  201. }
  202. }
  203. if ($_GET['view'] == 'sent' OR empty($_GET['view'])) {
  204. $interbreadcrumb[] = array('url' => '../dropbox/index.php', 'name' => get_lang('Dropbox', ''));
  205. $nameTools = get_lang('SentFiles');
  206. if ($_GET['action'] == 'addsentcategory') {
  207. $interbreadcrumb[] = array('url' => '../dropbox/index.php?view=sent', 'name' => get_lang('SentFiles'));
  208. $nameTools = get_lang('AddNewCategory');
  209. }
  210. if ($_GET['action'] == 'add') {
  211. $interbreadcrumb[] = array ('url' => '../dropbox/index.php?view=sent', 'name' => get_lang('SentFiles'));
  212. $nameTools = get_lang('UploadNewFile');
  213. }
  214. }
  215. /* HEADER & TITLE */
  216. if ($origin != 'learnpath') {
  217. Display::display_header($nameTools, 'Dropbox');
  218. } else { // if we come from the learning path we have to include the stylesheet and the required javascripts manually.
  219. echo '<link rel="stylesheet" type="text/css" href="', api_get_path(WEB_CODE_PATH), 'css/default.css">';
  220. echo $javascript;
  221. }
  222. // api_display_tool_title($nameTools);