agenda.php 12 KB

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