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