123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * @package chamilo.calendar
- */
- // use anonymous mode when accessing this course tool
- $use_anonymous = true;
- $current_course_tool = TOOL_CALENDAR_EVENT;
- $course_info = api_get_course_info();
- if (!empty($course_info)) {
- api_protect_course_script(true);
- }
- $action = isset($_GET['action']) ? $_GET['action'] : null;
- $this_section = SECTION_COURSES;
- $url = null;
- if (empty($action)) {
- if (!empty($course_info)) {
- $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course'.'&'.api_get_cidreq();
- } else {
- $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?';
- }
- header("Location: $url");
- exit;
- }
- $group_id = api_get_group_id();
- $groupInfo = GroupManager::get_group_properties($group_id);
- /* Resource linker */
- $eventId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
- $type = $event_type = isset($_GET['type']) ? $_GET['type'] : null;
- $htmlHeadXtra[] = "<script>
- function plus_repeated_event() {
- if (document.getElementById('options2').style.display == 'none') {
- document.getElementById('options2').style.display = 'block';
- } else {
- document.getElementById('options2').style.display = 'none';
- }
- }
- $(function() {
- var checked = $('input[name=repeat]').attr('checked');
- if (checked) {
- $('#options2').show();
- }
- });
- </script>";
- $htmlHeadXtra[] = '<script>
- var counter_image = 1;
- function add_image_form() {
- // Multiple filepaths for image form
- var filepaths = document.getElementById("filepaths");
- if (document.getElementById("filepath_"+counter_image)) {
- counter_image = counter_image + 1;
- } else {
- counter_image = counter_image;
- }
- var elem1 = document.createElement("div");
- elem1.setAttribute("id","filepath_"+counter_image);
- filepaths.appendChild(elem1);
- id_elem1 = "filepath_"+counter_image;
- id_elem1 = "\'"+id_elem1+"\'";
- document.getElementById("filepath_"+counter_image).innerHTML = "<input type=\"file\" name=\"attach_"+counter_image+"\" /> <br />'.get_lang('Description').' <input type=\"text\" name=\"legend[]\" /><br /><br />";
- if (filepaths.childNodes.length == 6) {
- var link_attach = document.getElementById("link-more-attach");
- if (link_attach) {
- link_attach.innerHTML="";
- }
- }
- }
- </script>';
- // setting the name of the tool
- $nameTools = get_lang('Agenda');
- Event::event_access_tool(TOOL_CALENDAR_EVENT);
- // permission stuff - also used by loading from global in agenda.inc.php
- $is_allowed_to_edit = api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
- $agenda = new Agenda();
- $agenda->type = $type;
- $actions = $agenda->displayActions('calendar');
- if ($type === 'fromjs') {
- $id_list = explode('_', $eventId);
- $eventId = $id_list[1];
- $event_type = $id_list[0];
- }
- if (!api_is_allowed_to_edit(null, true) && $event_type === 'course') {
- api_not_allowed(true);
- }
- if ($event_type === 'course') {
- $agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().'&type=course';
- } else {
- $agendaUrl = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?&type='.$event_type;
- }
- $course_info = api_get_course_info();
- $agenda->type = $event_type;
- $content = null;
- if (api_is_allowed_to_edit(false, true) ||
- (api_get_course_setting('allow_user_edit_agenda') &&
- !api_is_anonymous() &&
- api_is_allowed_to_session_edit(false, true)) ||
- GroupManager::user_has_access(api_get_user_id(), $groupInfo['iid'], GroupManager::GROUP_TOOL_CALENDAR) &&
- GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])
- ) {
- switch ($action) {
- case 'add':
- $actionName = get_lang('Add');
- $form = $agenda->getForm(array('action' => 'add'));
- if ($form->validate()) {
- $values = $form->getSubmitValues();
- $sendEmail = isset($values['add_announcement']) ? true : false;
- $allDay = isset($values['all_day']) ? 'true' : 'false';
- $sendAttachment = isset($_FILES) && !empty($_FILES) ? true : false;
- $attachmentList = $sendAttachment ? $_FILES : null;
- $attachmentCommentList = isset($values['legend']) ? $values['legend'] : null;
- $comment = isset($values['comment']) ? $values['comment'] : null;
- $startDate = $values['date_range_start'];
- $endDate = $values['date_range_end'];
- $eventId = $agenda->addEvent(
- $startDate,
- $endDate,
- $allDay,
- $values['title'],
- $values['content'],
- $values['users_to_send'],
- $sendEmail,
- null,
- $attachmentList,
- $attachmentCommentList,
- $comment
- );
- if (!empty($values['repeat']) && !empty($eventId)) {
- // End date is always set as 23:59:59
- $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
- $agenda->addRepeatedItem(
- $eventId,
- $values['repeat_type'],
- $endDate,
- $values['users_to_send']
- );
- }
- $message = Display::return_message(get_lang('AddSuccess'), 'confirmation');
- if ($sendEmail) {
- $message .= Display::return_message(get_lang('AdditionalMailWasSentToSelectedUsers'), 'confirmation');
- }
- Display::addFlash($message);
- header("Location: $agendaUrl");
- exit;
- } else {
- $content = $form->return_form();
- }
- break;
- case 'edit':
- $actionName = get_lang('Edit');
- $event = $agenda->get_event($eventId);
- if (empty($event)) {
- api_not_allowed(true);
- }
- $event['action'] = 'edit';
- $event['id'] = $eventId;
- $form = $agenda->getForm($event);
- if ($form->validate()) {
- $values = $form->getSubmitValues();
- $allDay = isset($values['all_day']) ? 'true' : 'false';
- $sendEmail = isset($values['add_announcement']) ? true : false;
- $startDate = $values['date_range_start'];
- $endDate = $values['date_range_end'];
- $sendAttachment = isset($_FILES) && !empty($_FILES) ? true : false;
- $attachmentList = $sendAttachment ? $_FILES : null;
- $attachmentCommentList = isset($values['legend']) ? $values['legend'] : null;
- $comment = isset($values['comment']) ? $values['comment'] : null;
- // This is a sub event. Delete the current and create another BT#7803
- if (!empty($event['parent_event_id'])) {
- $agenda->deleteEvent($eventId);
- $eventId = $agenda->addEvent(
- $startDate,
- $endDate,
- $allDay,
- $values['title'],
- $values['content'],
- $values['users_to_send'],
- false,
- null,
- $attachmentList,
- $attachmentCommentList,
- $comment
- );
- $message = Display::return_message(get_lang('Updated'), 'confirmation');
- Display::addFlash($message);
- header("Location: $agendaUrl");
- exit;
- }
- $usersToSend = isset($values['users_to_send']) ? $values['users_to_send'] : '';
- // Editing normal event.
- $agenda->editEvent(
- $eventId,
- $startDate,
- $endDate,
- $allDay,
- $values['title'],
- $values['content'],
- $usersToSend,
- $attachmentList,
- $attachmentCommentList,
- $comment,
- '',
- $sendEmail
- );
- if (!empty($values['repeat']) && !empty($eventId)) {
- // End date is always set as 23:59:59
- $endDate = substr($values['repeat_end_day'], 0, 10).' 23:59:59';
- $agenda->addRepeatedItem(
- $eventId,
- $values['repeat_type'],
- $endDate,
- $values['users_to_send']
- );
- }
- $deleteAttachmentList = isset($values['delete_attachment']) ? $values['delete_attachment'] : array();
- if (!empty($deleteAttachmentList)) {
- foreach ($deleteAttachmentList as $deleteAttachmentId => $value) {
- $agenda->deleteAttachmentFile(
- $deleteAttachmentId,
- $agenda->course
- );
- }
- }
- $message = Display::return_message(get_lang('Updated'), 'confirmation');
- Display::addFlash($message);
- header("Location: $agendaUrl");
- exit;
- } else {
- $content = $form->returnForm();
- }
- break;
- case 'importical':
- $actionName = get_lang('Import');
- $form = $agenda->getImportCalendarForm();
- $content = $form->returnForm();
- if ($form->validate()) {
- $ical_name = $_FILES['ical_import']['name'];
- $ical_type = $_FILES['ical_import']['type'];
- $ext = substr($ical_name, (strrpos($ical_name, ".") + 1));
- if ($ext === 'ics' || $ext === 'ical' || $ext === 'icalendar' || $ext === 'ifb') {
- $result = $agenda->importEventFile($course_info, $_FILES['ical_import']);
- $is_ical = true;
- } else {
- $is_ical = false;
- }
- if (!$is_ical) {
- Display::return_message(get_lang('IsNotiCalFormatFile'), 'error');
- $form = $agenda->getImportCalendarForm();
- $content = $form->return_form();
- break;
- } else {
- Display::return_message(get_lang('AddSuccess'), 'error');
- $content = $result;
- }
- }
- break;
- case "delete":
- if (!(api_is_course_coach() &&
- !api_is_element_in_the_session(TOOL_AGENDA, $eventId))
- ) {
- // a coach can only delete an element belonging to his session
- $content = $agenda->deleteEvent($eventId);
- }
- break;
- }
- }
- if (!empty($group_id)) {
- $group_properties = GroupManager :: get_group_properties($group_id);
- $interbreadcrumb[] = array(
- "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
- "name" => get_lang('Groups')
- );
- $interbreadcrumb[] = array(
- "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
- "name" => get_lang('GroupSpace').' '.$group_properties['name']
- );
- }
- if (!empty($actionName)) {
- $interbreadcrumb[] = array(
- "url" => $url,
- "name" => get_lang('Agenda')
- );
- }
- // Tool introduction
- $introduction = Display::return_introduction_section(TOOL_CALENDAR_EVENT);
- echo $actions;
- echo $content;
|