dropbox_init.inc.php 7.6 KB

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