From 0bfaad22caba2ab7f85b0c5e4ba9784537a12e2f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 21 Jan 2013 18:04:12 +0100 Subject: [PATCH] Adding calendar user filter sent by ycastillo see #2238 --- main/calendar/agenda.inc.php | 73 +++++++++++++++++++++++++++++------ main/calendar/agenda.lib.php | 23 +++++++---- main/calendar/agenda_js.php | 14 +++++-- main/inc/ajax/agenda.ajax.php | 7 +++- 4 files changed, 95 insertions(+), 22 deletions(-) diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index c734996ff2..fb42a64221 100644 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -26,6 +26,16 @@ $(document).ready(function () { setFocus(); }); '; +$htmlHeadXtra[] = ''; require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; @@ -958,7 +968,7 @@ function show_to_form($to_already_selected) { * @return html code */ function construct_not_selected_select_form($group_list=null, $user_list=null, $to_already_selected=array()) { - echo ''; // adding the groups to the select form echo ''; @@ -996,6 +1006,42 @@ function construct_not_selected_select_form($group_list=null, $user_list=null, $ echo ""; } +function show_to($filter=0) { + /*$user_list = get_course_users(); + $group_list = get_course_groups();*/ + $order = 'lastname'; + if (api_is_western_name_order()) { + $order = 'firstname'; + } + + $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order); + $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id()); + + return construct_to_select_form($group_list, $user_list, $filter); +} + +function construct_to_select_form($group_list=null, $user_list=null, $filter=0) { + $result = '
"; + return $result; +} + + /** * This function shows the form with the user that were selected * @author: Patrick Cool , Ghent University @@ -1533,15 +1579,20 @@ function change_visibility($tool,$id,$visibility) * The links that allows the course administrator to add a new agenda item, to filter on groups or users * @author Patrick Cool , Ghent University */ -function display_courseadmin_links() { - if (!isset($_GET['action'])) { - $actions = "".Display::return_icon('calendar_na.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM).""; - } else { - $actions = "".Display::return_icon('calendar.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM).""; - } - $actions .= "".Display::return_icon('new_event.png', get_lang('AgendaAdd'),'',ICON_SIZE_MEDIUM).""; - $actions .= "".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'),'',ICON_SIZE_MEDIUM).""; - return $actions; +function display_courseadmin_links($filter = 0) { + if (!isset($_GET['action'])) { + $to = show_to($filter); + $actions = "".Display::return_icon('calendar_na.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM).""; + } else { + $actions = "".Display::return_icon('calendar.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM).""; + } + $actions .= "".Display::return_icon('new_event.png', get_lang('AgendaAdd'),'',ICON_SIZE_MEDIUM).""; + $actions .= "".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'),'',ICON_SIZE_MEDIUM).""; + $actions .= '
'; + $actions .= Display::return_icon('group.png', get_lang('To'), array ('align' => 'absmiddle'),ICON_SIZE_SMALL).' '.get_lang('To'); + $actions .= $to; + $actions .= '
'; + return $actions; } @@ -2135,7 +2186,7 @@ function display_one_agenda_item($agenda_id) { // Content $content = $myrow['content']; $content = make_clickable($content); - + echo ''; echo ''; echo $content; diff --git a/main/calendar/agenda.lib.php b/main/calendar/agenda.lib.php index 7711bf754b..94c34a5eeb 100644 --- a/main/calendar/agenda.lib.php +++ b/main/calendar/agenda.lib.php @@ -228,7 +228,7 @@ class Agenda { * @param int course id *integer* not the course code * */ - function get_events($start, $end, $course_id = null, $group_id = null) { + function get_events($start, $end, $course_id = null, $group_id = null,$sel_user = 0) { switch ($this->type) { case 'admin': @@ -237,7 +237,7 @@ class Agenda { case 'course': $session_id = api_get_session_id(); $course_info = api_get_course_info_by_id($course_id); - $this->get_course_events($start, $end, $course_info, $group_id, $session_id); + $this->get_course_events($start, $end, $course_info, $group_id, $session_id,$sel_user); break; case 'personal': default: @@ -436,7 +436,7 @@ class Agenda { return $my_events; } - function get_course_events($start, $end, $course_info, $group_id = 0, $session_id = 0) { + function get_course_events($start, $end, $course_info, $group_id = 0, $session_id = 0, $sel_user = 0) { $course_id = $course_info['real_id']; $group_list = GroupManager::get_group_list(null, $course_info['code']); @@ -455,8 +455,11 @@ class Agenda { $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); - - $user_id = api_get_user_id(); + if (api_is_allowed_to_edit()) { + $user_id = $sel_user; + } else { + $user_id = api_get_user_id(); + } if (!empty($group_id)) { $group_memberships = array($group_id); @@ -466,7 +469,12 @@ class Agenda { if (is_array($group_memberships) && count($group_memberships) > 0) { if (api_is_allowed_to_edit()) { - $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; + if($user_id !=0) { + $where_condition = "( ip.to_user_id = $user_id AND ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; + } else { + $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).") ) "; } @@ -479,6 +487,7 @@ class Agenda { ip.visibility = '1' AND agenda.c_id = $course_id AND ip.c_id = $course_id + GROUP BY id"; } else { @@ -633,7 +642,7 @@ class Agenda { $this->events[] = $event; } } - return $events; + //return $events; } function get_platform_events($start, $end) { diff --git a/main/calendar/agenda_js.php b/main/calendar/agenda_js.php index c33ae1329c..e13443b63c 100644 --- a/main/calendar/agenda_js.php +++ b/main/calendar/agenda_js.php @@ -134,9 +134,13 @@ $export_icon_high = '../img/export_high_fade.png'; $tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))); $actions = null; + if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true) OR $is_group_tutor) { if ($type == 'course') { - $actions = display_courseadmin_links(); + if (isset($_GET['user_id'])) { + $filter = $_GET['user_id']; + } + $actions = display_courseadmin_links($filter); } $tpl->assign('actions', $actions); } @@ -163,9 +167,13 @@ $tpl->assign('type_event_class', $type_event_class); $tpl->assign('can_add_events', $can_add_events); //Setting AJAX caller -$agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type; +if (isset($_GET['user_id'])) { + $user_id = $_GET['user_id']; + $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?user_id='.$user_id.'&type='.$type; +} else { + $agenda_ajax_url = api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?type='.$type; +} $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url); - $course_code = api_get_course_id(); if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') { diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index c7c936984c..37d784688e 100644 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -79,7 +79,12 @@ switch ($action) { case 'get_events': $start = $_REQUEST['start']; $end = $_REQUEST['end']; - $events = $agenda->get_events($start, $end, api_get_course_int_id(), $group_id); + if (isset($_REQUEST['user_id'])) { + $sel_user = $_REQUEST['user_id']; + } else { + $sel_user = 0; + } + $events = $agenda->get_events($start, $end, api_get_course_int_id(), $group_id,$_REQUEST['user_id']); echo $events; break; case 'get_user_agenda':