diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index d9a14437ce..fa8dfb1ad3 100644 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -34,7 +34,7 @@ class Agenda { * @param string agendaDay, agendaWeek, month * @param string personal, course or global (only works for personal by now) */ - function add_event($start, $end, $all_day, $view, $type, $title, $content) { + function add_event($start, $end, $all_day, $view, $title, $content) { $start = date('Y-m-d H:i:s', $start); $end = date('Y-m-d H:i:s', $end); @@ -44,7 +44,7 @@ class Agenda { $attributes = array(); $id = null; - switch($type) { + switch($this->type) { case 'personal': $attributes['user'] = api_get_user_id(); $attributes['title'] = $title; @@ -81,7 +81,7 @@ class Agenda { return $id; } - function edit_event($id, $start, $end, $all_day, $view, $type, $title, $content) { + function edit_event($id, $start, $end, $all_day, $view, $title, $content) { $start = date('Y-m-d H:i:s', $start); $start = api_get_utc_datetime($start); @@ -94,7 +94,7 @@ class Agenda { $attributes = array(); - switch($type) { + switch($this->type) { case 'personal': $attributes['title'] = $title; $attributes['text'] = $content; @@ -120,8 +120,8 @@ class Agenda { } } - function delete_event($id, $type) { - switch($type) { + function delete_event($id) { + switch($this->type) { case 'personal': Database::delete($this->tbl_personal_agenda, array('id = ?' =>$id)); break; @@ -144,8 +144,8 @@ class Agenda { * @param int course id *integer* not the course code * */ - function get_events($start, $end, $type, $user_id, $course_id = null) { - switch($type) { + function get_events($start, $end, $user_id, $course_id = null) { + switch($this->type) { case 'admin': $this->get_platform_events($start, $end); break; @@ -180,15 +180,15 @@ class Agenda { return ''; } - function move_event($id, $type, $day_delta, $minute_delta) { + function move_event($id, $day_delta, $minute_delta) { // we convert the hour delta into minutes and add the minute delta $delta = ($day_delta * 60 * 24) + $minute_delta; $delta = intval($delta); - $event = $this->get_event($id, $type); + $event = $this->get_event($id, $this->type); if (!empty($event)){ - switch($type) { + switch($this->type) { case 'personal': $sql = "UPDATE $this->tbl_personal_agenda SET date = DATE_ADD(date, INTERVAL $delta MINUTE), enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE) WHERE id=".intval($id); @@ -213,11 +213,11 @@ class Agenda { * Gets a single personal event * @param int event id */ - function get_event($id, $type) { + function get_event($id) { // make sure events of the personal agenda can only be seen by the user himself $id = intval($id); $event = null; - switch($type) { + switch ($this->type) { case 'personal': $user = api_get_user_id(); $sql = " SELECT * FROM ".$this->tbl_personal_agenda." WHERE id=".$id." AND user = ".$user; @@ -346,7 +346,7 @@ class Agenda { } $event['editable'] = false; - if (api_is_allowed_to_edit()) { + if (api_is_allowed_to_edit() && $this->type == 'course') { $event['editable'] = true; } @@ -355,14 +355,12 @@ class Agenda { } if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') { $event['end'] = $this->format_event_date($row['end_date']); - } - + } $event['description'] = $row['content']; - $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; - - - $my_events[] = $event; + + $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; + $my_events[] = $event; $this->events[] = $event; } @@ -380,7 +378,7 @@ class Agenda { $access_url_id = api_get_current_access_url_id(); $sql = "SELECT * FROM ".$this->tbl_global_agenda." - WHERE start_date>='".$start."' AND end_date<='".$end."' AND access_url_id = $access_url_id "; + WHERE start_date >= '".$start."' AND end_date <= '".$end."' AND access_url_id = $access_url_id "; $result = Database::query($sql); $my_events = array(); @@ -393,7 +391,8 @@ class Agenda { $event['allDay'] = 'false'; $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color; $event['editable'] = false; - if (api_is_platform_admin()) { + + if (api_is_platform_admin() && $this->type == 'admin') { $event['editable'] = true; } diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index 3b47225eda..2fa8d927d2 100644 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -31,16 +31,15 @@ if (api_is_platform_admin() && $type == 'admin') { if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) { $type = 'course'; } -$can_add_events = 0; -if (api_is_platform_admin()) { +$can_add_events = 0; +if (api_is_platform_admin() && $type == 'admin') { $can_add_events = 1; } -if (api_is_allowed_to_edit()) { +if (api_is_allowed_to_edit() && $type == 'course') { $can_add_events = 1; } - -if ($type == 'personal' && !api_is_anonymous()) { +if (!api_is_anonymous() && $type == 'personal') { $can_add_events = 1; } diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index 67fee99dbc..bf69394cda 100644 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -12,24 +12,26 @@ require_once api_get_path(SYS_CODE_PATH).'calendar/agenda.lib.php'; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; + $agenda = new Agenda(); +$agenda->type = $type; -switch ($action) { +switch ($action) { case 'add_event': //For now we only save personal events - echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $type, $_REQUEST['title'], $_REQUEST['content']); + echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']); break; case 'edit_event': $id_list = explode('_', $_REQUEST['id']); //$type = $id_list[0]; $id = $id_list[1]; - $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $type ,$_REQUEST['title'], $_REQUEST['content']); + $agenda->edit_event($id, $_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], $_REQUEST['title'], $_REQUEST['content']); break; case 'delete_event': $id_list = explode('_', $_REQUEST['id']); //$type = $id_list[0]; $id = $id_list[1]; - $agenda->delete_event($id, $type); + $agenda->delete_event($id); break; case 'move_event': $day_delta = $_REQUEST['day_delta']; @@ -37,12 +39,12 @@ switch ($action) { //$type = $_REQUEST['type'][0]; $id = explode('_', $_REQUEST['id']); $id = $id[1]; - $agenda->move_event($id, $type, $day_delta, $minute_delta); + $agenda->move_event($id, $day_delta, $minute_delta); break; case 'get_events': $start = $_REQUEST['start']; $end = $_REQUEST['end']; - $events = $agenda->get_events($start, $end, $type, api_get_user_id(), api_get_course_int_id()); + $events = $agenda->get_events($start, $end, api_get_user_id(), api_get_course_int_id()); echo $events; break; case 'get_user_agenda':