From 8811a617aee6fc8ce7a03303d811ddddaf99cb4e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 23 Dec 2011 15:19:34 +0100 Subject: [PATCH] Some fixes in the calendar layout + minor code style fixes in the session category list --- main/admin/session_category_list.php | 9 +- main/calendar/agenda.lib.php | 122 +++++++++++++++++-------- main/css/base.css | 7 ++ main/inc/ajax/agenda.ajax.php | 5 + main/template/default/agenda/month.tpl | 36 ++++++-- 5 files changed, 131 insertions(+), 48 deletions(-) mode change 100755 => 100644 main/admin/session_category_list.php diff --git a/main/admin/session_category_list.php b/main/admin/session_category_list.php old mode 100755 new mode 100644 index b5af86add8..a87a48b535 --- a/main/admin/session_category_list.php +++ b/main/admin/session_category_list.php @@ -5,12 +5,11 @@ $language_file='admin'; $cidReset=true; require_once '../inc/global.inc.php'; -require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; -require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php'; api_protect_admin_script(true); + // setting the section (for the tabs) -$this_section=SECTION_PLATFORM_ADMIN; +$this_section = SECTION_PLATFORM_ADMIN; $htmlHeadXtra[] = ''; -$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); -$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); +$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); +$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $page=intval($_GET['page']); $action= Security::remove_XSS($_REQUEST['action']); diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index 2e359ef254..87b3c6d8cb 100644 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -57,7 +57,7 @@ class Agenda { $attributes['title'] = $title; $attributes['text'] = $content; $attributes['date'] = $start; - $attributes['enddate'] = $end; + $attributes['enddate'] = $end; $attributes['all_day'] = $all_day; $id = Database::insert($this->tbl_personal_agenda, $attributes); break; @@ -67,7 +67,7 @@ class Agenda { $attributes['content'] = $content; $attributes['start_date'] = $start; $attributes['end_date'] = $end; - $attributes['all_day'] = $all_day; + $attributes['all_day'] = $all_day; $attributes['session_id'] = api_get_session_id(); $attributes['c_id'] = $this->course['real_id']; @@ -103,8 +103,7 @@ class Agenda { if (isset($add_as_announcement) && !empty($add_as_announcement)) { self::store_agenda_item_as_announcement($id); } - } - + } break; case 'admin': @@ -264,12 +263,18 @@ class Agenda { break; case 'personal': default: + //Getting personal events $this->get_personal_events($start, $end); + + //Getting platform/admin events $this->get_platform_events($start, $end); + + //Getting course events $my_course_list = array(); + if (!api_is_anonymous()) { $my_course_list = CourseManager::get_courses_list_by_user_id(api_get_user_id(), true); - } + } if (!empty($my_course_list)) { foreach($my_course_list as $course_info_item) { if (isset($course_id) && !empty($course_id)) { @@ -364,6 +369,7 @@ class Agenda { $start = api_get_utc_datetime($start); $end = api_get_utc_datetime($end); $user_id = api_get_user_id(); + $sql = "SELECT * FROM ".$this->tbl_personal_agenda." WHERE date >= '".$start."' AND (enddate <='".$end."' OR enddate IS NULL) AND user = $user_id"; @@ -376,6 +382,9 @@ class Agenda { $event['className'] = 'personal'; $event['borderColor'] = $event['backgroundColor'] = $this->event_personal_color; $event['editable'] = true; + + $event['sent_to'] = get_lang('Me'); + $event['type'] = 'personal'; if (!empty($row['date']) && $row['date'] != '0000-00-00 00:00:00') { $event['start'] = $this->format_event_date($row['date']); @@ -384,7 +393,7 @@ class Agenda { if (!empty($row['enddate']) && $row['enddate'] != '0000-00-00 00:00:00') { $event['end'] = $this->format_event_date($row['enddate']); } - $event['description'] = $row['text']; + $event['description'] = $row['text']; $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; $my_events[] = $event; $this->events[]= $event; @@ -397,7 +406,21 @@ class Agenda { $course_id = $course_info['real_id']; - $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); + $group_list = GroupManager::get_group_list(null, $course_info['code']); + $group_name_list = array(); + + if (!empty($group_list)) { + foreach($group_list as $group) { + $group_name_list[$group['id']]= $group['name']; + } + } + + if (!api_is_allowed_to_edit()) { + $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); + } else { + $group_memberships = array_keys($group_name_list); + } + $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); @@ -408,36 +431,38 @@ class Agenda { } if (is_array($group_memberships) && count($group_memberships) >0 ) { - $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip - WHERE agenda.id = ip.ref AND - ip.tool ='".TOOL_CALENDAR_EVENT."' AND - ( ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) AND - ip.visibility = '1' AND - agenda.c_id = $course_id AND - ip.c_id = $course_id"; + if (api_is_allowed_to_edit()) { + $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; + } else { + $where_condition = "( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; + } + + $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref + FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip + WHERE agenda.id = ip.ref AND + ip.tool ='".TOOL_CALENDAR_EVENT."' AND + $where_condition AND + ip.visibility = '1' AND + agenda.c_id = $course_id AND + ip.c_id = $course_id"; + + + } else { - if (api_is_allowed_to_edit()) { - $sql="SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip - WHERE agenda.id = ip.ref - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ip.visibility='1' AND - agenda.c_id = $course_id AND - ip.c_id = $course_id - "; - } else { - $sql="SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref - FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip - WHERE agenda.id = ip.ref - AND ip.tool='".TOOL_CALENDAR_EVENT."' - AND ( ip.to_user_id=$user_id OR ip.to_group_id='0') - AND ip.visibility='1' AND - agenda.c_id = $course_id AND - ip.c_id = $course_id "; - - - } + if (api_is_allowed_to_edit()) { + $where_condition = ""; + } else { + $where_condition = "( ip.to_user_id=$user_id OR ip.to_group_id='0')"; + } + $sql="SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref + FROM ".$tlb_course_agenda." agenda, ".$tbl_property." ip + WHERE agenda.id = ip.ref AND + ip.tool='".TOOL_CALENDAR_EVENT."' AND + $where_condition AND + ip.visibility='1' AND + agenda.c_id = $course_id AND + ip.c_id = $course_id"; + } $result = Database::query($sql); @@ -467,6 +492,7 @@ class Agenda { } $event['editable'] = false; + if (api_is_allowed_to_edit() && $this->type == 'course') { $event['editable'] = true; } @@ -477,6 +503,28 @@ 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['sent_to'] = ''; + $event['type'] = $this->type; + + + //Event Sent to a group? + if (isset($row['to_group_id']) && !empty($row['to_group_id'])) { + $event['sent_to'] = $group_name_list[$row['to_group_id']]; + $event['type'] = 'group'; + } + + //Event sent to a user? + if (isset($row['to_user_id'])) { + $event['sent_to'] = $row['to_user_id']; + } + + //Event sent to everyone! + if (empty($event['sent_to'])) { + $event['sent_to'] = get_lang('Everyone'); + } + + $event['description'] = $row['content']; $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0; @@ -512,6 +560,8 @@ class Agenda { $event['allDay'] = 'false'; $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color; $event['editable'] = false; + + $event['type'] = 'admin'; if (api_is_platform_admin() && $this->type == 'admin') { $event['editable'] = true; diff --git a/main/css/base.css b/main/css/base.css index 642ddd1328..300d336f79 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -3790,10 +3790,17 @@ form div.error input, form div.error textarea { .label_tag.admin_event { background:red; } + .label_tag.course_event { background:#458B00; } +.label_tag.group_event { + background:#A0522D; +} + + + .label_tag.important { background-color: #c43c35; diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index acca4f6662..a75bc2a427 100644 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -13,6 +13,11 @@ 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'; +if ($type =='course') { + // Access control + api_protect_course_script(true); +} + $agenda = new Agenda(); $agenda->type = $type; //course,admin or personal diff --git a/main/template/default/agenda/month.tpl b/main/template/default/agenda/month.tpl index 9bfe4722e4..4ff9ac5398 100644 --- a/main/template/default/agenda/month.tpl +++ b/main/template/default/agenda/month.tpl @@ -82,6 +82,7 @@ $(document).ready(function() { dayNamesShort: {$day_names_short}, selectable : true, selectHelper: true, + //add event select: function(start, end, allDay, jsEvent, view) { /* When selecting one day or several days */ @@ -89,7 +90,9 @@ $(document).ready(function() { var end_date = Math.round(end.getTime() / 1000); $('#visible_to_input').show(); - $('#add_as_announcement_div').show(); + $('#add_as_announcement_div').show(); + + $('#visible_to_read_only').hide(); //Cleans the selected attr clean_user_select(); @@ -116,7 +119,8 @@ $(document).ready(function() { $('#end_date').html(' - ' + end.toDateString()); } $('#color_calendar').html('{$type_label}'); - $('#color_calendar').addClass('label_tag'); + $('#color_calendar').removeClass('group_event'); + $('#color_calendar').addClass('label_tag'); $('#color_calendar').addClass('{$type}_event'); allFields.removeClass( "ui-state-error" ); @@ -160,7 +164,7 @@ $(document).ready(function() { }, eventClick: function(calEvent, jsEvent, view) { - + //edit event if (calEvent.editable) { var start_date = Math.round(calEvent.start.getTime() / 1000); if (calEvent.allDay == 1) { @@ -170,12 +174,19 @@ $(document).ready(function() { } $('#visible_to_input').hide(); + $('#visible_to_read_only').show(); $('#add_as_announcement_div').hide(); + $("#visible_to_read_only_users").html(calEvent.sent_to); $('#color_calendar').html('{$type_label}'); $('#color_calendar').addClass('label_tag'); - $('#color_calendar').addClass('{$type}_event'); + + $('#color_calendar').removeClass('course_event'); + $('#color_calendar').removeClass('personal_event'); + $('#color_calendar').removeClass('group_event'); + + $('#color_calendar').addClass(calEvent.type+'_event'); $('#start_date').html(calEvent.start.getDate() +"/"+ calEvent.start.getMonth() +"/"+calEvent.start.getFullYear()); @@ -206,9 +217,10 @@ $(document).ready(function() { success:function() { calEvent.title = $("#title").val(); calEvent.start = calEvent.start; - calEvent.end = calEvent.end; + calEvent.end = calEvent.end; calEvent.allDay = calEvent.allDay; - calEvent.description = $("#content").val(); + calEvent.description = $("#content").val(); + calendar.fullCalendar('updateEvent', calEvent, true // make the event "stick" @@ -269,10 +281,20 @@ $(document).ready(function() {
- {$visible_to} + {$visible_to}
{/if} + + +