agenda.php 11 KB

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