agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.calendar
  5. */
  6. use ChamiloSession as Session;
  7. // use anonymous mode when accessing this course tool
  8. $use_anonymous = true;
  9. ////require_once '../inc/global.inc.php';
  10. $current_course_tool = TOOL_CALENDAR_EVENT;
  11. $course_info = api_get_course_info();
  12. if (!empty($course_info)) {
  13. api_protect_course_script(true);
  14. }
  15. $action = isset($_GET['action']) ? $_GET['action'] : null;
  16. $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
  17. $this_section = SECTION_COURSES;
  18. $url = null;
  19. if (empty($action)) {
  20. if (!empty($course_info)) {
  21. $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course'.'&'.api_get_cidreq();
  22. } else {
  23. $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?';
  24. }
  25. header("Location: $url");
  26. exit;
  27. }
  28. /* Resource linker */
  29. Session::write('source_type', 'Agenda');
  30. //require_once '../resourcelinker/resourcelinker.inc.php';
  31. $group_id = api_get_group_id();
  32. $eventId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  33. $type = $event_type = isset($_GET['type']) ? $_GET['type'] : null;
  34. $htmlHeadXtra[] = "<script>
  35. function plus_repeated_event() {
  36. if (document.getElementById('options2').style.display == 'none') {
  37. document.getElementById('options2').style.display = 'block';
  38. } else {
  39. document.getElementById('options2').style.display = 'none';
  40. }
  41. }
  42. $(function() {
  43. var checked = $('input[name=repeat]').attr('checked');
  44. if (checked) {
  45. $('#options2').show();
  46. }
  47. });
  48. </script>
  49. ";
  50. // setting the name of the tool
  51. $nameTools = get_lang('Agenda');
  52. Event::event_access_tool(TOOL_CALENDAR_EVENT);
  53. // permission stuff - also used by loading from global in agenda.inc.php
  54. $is_allowed_to_edit = api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
  55. $agenda = new Agenda();
  56. $agenda->type = $type;
  57. $actions = $agenda->displayActions('calendar');
  58. if ($type == 'fromjs') {
  59. $id_list = explode('_', $eventId);
  60. $eventId = isset($id_list[1]) ? $id_list[1] : '';
  61. $event_type = isset($id_list[0]) ? $id_list[0] : '';
  62. }
  63. if (!api_is_allowed_to_edit(null, true) && $event_type == 'course') {
  64. api_not_allowed(true);
  65. }
  66. if ($event_type == 'course') {
  67. $agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().'&type=course';
  68. } else {
  69. $agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?&type='.$event_type;
  70. }
  71. $course_info = api_get_course_info();
  72. $agenda->type = $event_type;
  73. $content = null;
  74. if (api_is_allowed_to_edit(false, true) ||
  75. (api_get_course_setting('allow_user_edit_agenda') &&
  76. !api_is_anonymous() &&
  77. api_is_allowed_to_session_edit(false, true)) ||
  78. GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) &&
  79. GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
  80. ) {
  81. switch ($action) {
  82. case 'add':
  83. $actionName = get_lang('Add');
  84. $form = $agenda->getForm(array('action' => 'add'));
  85. if ($form->validate()) {
  86. $values = $form->getSubmitValues();
  87. $sendEmail = isset($values['add_announcement']) ? true : false;
  88. $allDay = isset($values['all_day']) ? 'true' : 'false';
  89. $sendAttachment = isset($_FILES['user_upload']) ? true : false;
  90. $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
  91. $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
  92. $comment = isset($values['comment']) ? $values['comment'] : null;
  93. $startDate = $values['date_range_start'];
  94. $endDate = $values['date_range_end'];
  95. $eventId = $agenda->addEvent(
  96. $startDate,
  97. $endDate,
  98. $allDay,
  99. $values['title'],
  100. $values['content'],
  101. $values['users_to_send'],
  102. $sendEmail,
  103. null,
  104. $attachment,
  105. $attachmentComment,
  106. $comment
  107. );
  108. if (!empty($values['repeat']) && !empty($eventId)) {
  109. // End date is always set as 23:59:59
  110. $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
  111. $agenda->addRepeatedItem(
  112. $eventId,
  113. $values['repeat_type'],
  114. $endDate,
  115. $values['users_to_send']
  116. );
  117. }
  118. Display::return_message(get_lang('AddSuccess'), 'confirmation');
  119. if ($sendEmail) {
  120. Display::return_message(get_lang('AdditionalMailWasSentToSelectedUsers'), 'confirmation');
  121. }
  122. header("Location: $agendaUrl");
  123. exit;
  124. } else {
  125. $content = $form->return_form();
  126. }
  127. break;
  128. case 'edit':
  129. $actionName = get_lang('Edit');
  130. $event = $agenda->get_event($eventId);
  131. if (empty($event)) {
  132. api_not_allowed(true);
  133. }
  134. $event['action'] = 'edit';
  135. $event['id'] = $eventId;
  136. $form = $agenda->getForm($event);
  137. if ($form->validate()) {
  138. $values = $form->getSubmitValues();
  139. $allDay = isset($values['all_day']) ? 'true' : 'false';
  140. $startDate = $values['date_range_start'];
  141. $endDate = $values['date_range_end'];
  142. $sendAttachment = isset($_FILES['user_upload']) ? true : false;
  143. $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
  144. $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
  145. $comment = isset($values['comment']) ? $values['comment'] : null;
  146. // This is a sub event. Delete the current and create another BT#7803
  147. if (!empty($event['parent_event_id'])) {
  148. $agenda->delete_event($eventId);
  149. $eventId = $agenda->addEvent(
  150. $startDate,
  151. $endDate,
  152. $allDay,
  153. $values['title'],
  154. $values['content'],
  155. $values['users_to_send'],
  156. false,
  157. null,
  158. $attachment,
  159. $attachmentComment,
  160. $comment
  161. );
  162. Display::return_message(get_lang('Updated'), 'confirmation');
  163. header("Location: $agendaUrl");
  164. exit;
  165. }
  166. $usersToSend = isset($values['users_to_send']) ? $values['users_to_send'] : '';
  167. // Editing normal event.
  168. $agenda->editEvent(
  169. $eventId,
  170. $startDate,
  171. $endDate,
  172. $allDay,
  173. $values['title'],
  174. $values['content'],
  175. $usersToSend,
  176. $attachment,
  177. $attachmentComment,
  178. $comment
  179. );
  180. if (!empty($values['repeat']) && !empty($eventId)) {
  181. // End date is always set as 23:59:59
  182. $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
  183. $agenda->addRepeatedItem(
  184. $eventId,
  185. $values['repeat_type'],
  186. $endDate,
  187. $values['users_to_send']
  188. );
  189. }
  190. $deleteAttachment = isset($values['delete_attachment']) ? true : false;
  191. if ($deleteAttachment && isset($event['attachment']) && !empty($event['attachment'])) {
  192. $agenda->deleteAttachmentFile(
  193. $event['attachment']['id'],
  194. $agenda->course
  195. );
  196. }
  197. Display::return_message(get_lang('Updated'), 'confirmation');
  198. header("Location: $agendaUrl");
  199. exit;
  200. } else {
  201. $content = $form->returnForm();
  202. }
  203. break;
  204. case 'importical':
  205. $actionName = get_lang('Import');
  206. $form = $agenda->getImportCalendarForm();
  207. $content = $form->return_form();
  208. if ($form->validate()) {
  209. $ical_name = $_FILES['ical_import']['name'];
  210. $ical_type = $_FILES['ical_import']['type'];
  211. $ext = substr($ical_name, (strrpos($ical_name, ".") + 1));
  212. if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
  213. $result = $agenda->importEventFile($course_info, $_FILES['ical_import']);
  214. $is_ical = true;
  215. } else {
  216. $is_ical = false;
  217. }
  218. if (!$is_ical) {
  219. Display::return_message(get_lang('IsNotiCalFormatFile'), 'error');
  220. $form = $agenda->getImportCalendarForm();
  221. $content = $form->return_form();
  222. break;
  223. } else {
  224. Display::return_message(get_lang('AddSuccess'), 'error');
  225. $content = $result;
  226. }
  227. }
  228. break;
  229. case "delete":
  230. if (!(api_is_course_coach() &&
  231. !api_is_element_in_the_session(TOOL_AGENDA, $eventId))
  232. ) {
  233. // a coach can only delete an element belonging to his session
  234. $content = $agenda->delete_event($eventId);
  235. }
  236. break;
  237. }
  238. }
  239. if (!empty($group_id)) {
  240. $group_properties = GroupManager :: get_group_properties($group_id);
  241. $interbreadcrumb[] = array(
  242. "url" => api_get_path(WEB_CODE_PATH)."group/group.php",
  243. "name" => get_lang('Groups')
  244. );
  245. $interbreadcrumb[] = array(
  246. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?gidReq=".$group_id,
  247. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  248. );
  249. }
  250. if (!empty($actionName)) {
  251. $interbreadcrumb[] = array(
  252. "url" => $url,
  253. "name" => get_lang('Agenda')
  254. );
  255. }
  256. // Tool introduction
  257. $introduction = Display::return_introduction_section(TOOL_CALENDAR_EVENT);
  258. echo $actions;
  259. echo $content;