agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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['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 = $id_list[1];
  61. $event_type = $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. $message = null;
  74. $content = null;
  75. if (api_is_allowed_to_edit(false, true) ||
  76. (api_get_course_setting('allow_user_edit_agenda') &&
  77. !api_is_anonymous() &&
  78. api_is_allowed_to_session_edit(false, true)) ||
  79. GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) &&
  80. GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
  81. ) {
  82. switch ($action) {
  83. case 'add':
  84. $actionName = get_lang('Add');
  85. $form = $agenda->getForm(array('action' => 'add'));
  86. if ($form->validate()) {
  87. $values = $form->getSubmitValues();
  88. $sendEmail = isset($values['add_announcement']) ? true : false;
  89. $allDay = isset($values['all_day']) ? 'true' : 'false';
  90. $sendAttachment = isset($_FILES['user_upload']) ? true : false;
  91. $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
  92. $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
  93. $comment = isset($values['comment']) ? $values['comment'] : null;
  94. $startDate = $values['date_range_start'];
  95. $endDate = $values['date_range_end'];
  96. $eventId = $agenda->addEvent(
  97. $startDate,
  98. $endDate,
  99. $allDay,
  100. $values['title'],
  101. $values['content'],
  102. $values['users_to_send'],
  103. $sendEmail,
  104. null,
  105. $attachment,
  106. $attachmentComment,
  107. $comment
  108. );
  109. if (!empty($values['repeat']) && !empty($eventId)) {
  110. // End date is always set as 23:59:59
  111. $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
  112. $agenda->addRepeatedItem(
  113. $eventId,
  114. $values['repeat_type'],
  115. $endDate,
  116. $values['users_to_send']
  117. );
  118. }
  119. $message = Display::return_message(get_lang('AddSuccess'), 'confirmation');
  120. if ($sendEmail) {
  121. $message .= Display::return_message(get_lang('AdditionalMailWasSentToSelectedUsers'), 'confirmation');
  122. }
  123. Session::write('message', $message);
  124. header("Location: $agendaUrl");
  125. exit;
  126. } else {
  127. $content = $form->return_form();
  128. }
  129. break;
  130. case 'edit':
  131. $actionName = get_lang('Edit');
  132. $event = $agenda->get_event($eventId);
  133. if (empty($event)) {
  134. api_not_allowed(true);
  135. }
  136. $event['action'] = 'edit';
  137. $event['id'] = $eventId;
  138. $form = $agenda->getForm($event);
  139. if ($form->validate()) {
  140. $values = $form->getSubmitValues();
  141. $allDay = isset($values['all_day']) ? 'true' : 'false';
  142. $startDate = $values['date_range_start'];
  143. $endDate = $values['date_range_end'];
  144. $sendAttachment = isset($_FILES['user_upload']) ? true : false;
  145. $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
  146. $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
  147. $comment = isset($values['comment']) ? $values['comment'] : null;
  148. // This is a sub event. Delete the current and create another BT#7803
  149. if (!empty($event['parent_event_id'])) {
  150. $agenda->delete_event($eventId);
  151. $eventId = $agenda->addEvent(
  152. $startDate,
  153. $endDate,
  154. $allDay,
  155. $values['title'],
  156. $values['content'],
  157. $values['users_to_send'],
  158. false,
  159. null,
  160. $attachment,
  161. $attachmentComment,
  162. $comment
  163. );
  164. $message = Display::return_message(get_lang('Updated'), 'confirmation');
  165. Session::write('message', $message);
  166. header("Location: $agendaUrl");
  167. exit;
  168. }
  169. // Editing normal event.
  170. $agenda->editEvent(
  171. $eventId,
  172. $startDate,
  173. $endDate,
  174. $allDay,
  175. $values['title'],
  176. $values['content'],
  177. $values['users_to_send'],
  178. $attachment,
  179. $attachmentComment,
  180. $comment
  181. );
  182. if (!empty($values['repeat']) && !empty($eventId)) {
  183. // End date is always set as 23:59:59
  184. $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
  185. $agenda->addRepeatedItem(
  186. $eventId,
  187. $values['repeat_type'],
  188. $endDate,
  189. $values['users_to_send']
  190. );
  191. }
  192. $deleteAttachment = isset($values['delete_attachment']) ? true : false;
  193. if ($deleteAttachment && isset($event['attachment']) && !empty($event['attachment'])) {
  194. $agenda->deleteAttachmentFile(
  195. $event['attachment']['id'],
  196. $agenda->course
  197. );
  198. }
  199. $message = Display::return_message(get_lang('Updated'), 'confirmation');
  200. Session::write('message', $message);
  201. header("Location: $agendaUrl");
  202. exit;
  203. } else {
  204. $content = $form->returnForm();
  205. }
  206. break;
  207. case 'importical':
  208. $actionName = get_lang('Import');
  209. $form = $agenda->getImportCalendarForm();
  210. $content = $form->return_form();
  211. if ($form->validate()) {
  212. $ical_name = $_FILES['ical_import']['name'];
  213. $ical_type = $_FILES['ical_import']['type'];
  214. $ext = substr($ical_name, (strrpos($ical_name, ".") + 1));
  215. if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
  216. $result = $agenda->importEventFile($course_info, $_FILES['ical_import']);
  217. $is_ical = true;
  218. } else {
  219. $is_ical = false;
  220. }
  221. if (!$is_ical) {
  222. $message = Display::return_message(get_lang('IsNotiCalFormatFile'), 'error');
  223. $form = $agenda->getImportCalendarForm();
  224. $content = $form->return_form();
  225. break;
  226. } else {
  227. $message = Display::return_message(get_lang('AddSuccess'), 'error');
  228. $content = $result;
  229. }
  230. Session::write('message', $message);
  231. }
  232. break;
  233. case "delete":
  234. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $eventId) )) {
  235. // a coach can only delete an element belonging to his session
  236. $content = $agenda->delete_event($eventId);
  237. }
  238. break;
  239. }
  240. }
  241. if (!empty($group_id)) {
  242. $group_properties = GroupManager :: get_group_properties($group_id);
  243. $interbreadcrumb[] = array(
  244. "url" => api_get_path(WEB_CODE_PATH)."group/group.php",
  245. "name" => get_lang('Groups')
  246. );
  247. $interbreadcrumb[] = array(
  248. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?gidReq=".$group_id,
  249. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  250. );
  251. }
  252. if (!empty($actionName)) {
  253. $interbreadcrumb[] = array(
  254. "url" => $url,
  255. "name" => get_lang('Agenda')
  256. );
  257. }
  258. // Tool introduction
  259. $introduction = Display::return_introduction_section(TOOL_CALENDAR_EVENT);
  260. $message = Session::read('message');
  261. Session::erase('message');
  262. $tpl = new Template($actionName);
  263. $tpl->assign('content', $content);
  264. $tpl->assign('actions', $actions);
  265. // Loading main Chamilo 1 col template
  266. $tpl->display_one_col_template();