Adding calendar user filter sent by ycastillo see #2238

skala
Julio Montoya 13 years ago
parent 337dba18a5
commit 0bfaad22ca
  1. 73
      main/calendar/agenda.inc.php
  2. 23
      main/calendar/agenda.lib.php
  3. 14
      main/calendar/agenda_js.php
  4. 7
      main/inc/ajax/agenda.ajax.php

@ -26,6 +26,16 @@ $(document).ready(function () {
setFocus();
});
</script>';
$htmlHeadXtra[] = '<script>
$(function() {
$("#selected_form_id").change(function() {
var temp ="&user_id="+$("#selected_form_id").val();
url = window.location+temp;
window.location.replace(url);
});
});
</script>';
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 '<select data-placeholder="'.get_lang('Select').'" style="width:350px;" class="chzn-select" id="selected_form_id" name="selected_form[]" multiple="multiple">';
echo '<select data-placeholder="'.get_lang('Select').'" style="width:150px;" class="chzn-select" id="selected_form_id" name="selected_form[]" multiple="multiple">';
// adding the groups to the select form
echo '<option value="everyone">'.get_lang('Everyone').'</option>';
@ -996,6 +1006,42 @@ function construct_not_selected_select_form($group_list=null, $user_list=null, $
echo "</select>";
}
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 = '<form style="float:right;"><select data-placeholder="'.get_lang('Select').'name="sel_to" class="chzn-select" id="selected_form_id"></form>';
// adding the groups to the select form
$result .= '<option value=0>'.get_lang('Everyone').'</option>';
// adding the individual users to the select form
if (!empty($user_list)) {
$result .= '<optgroup label="'.get_lang('Users').'">';
foreach($user_list as $this_user) {
$username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
$user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
$selected = $this_user['user_id'] == $filter ? "selected" : null;
$result .= "<option title='$username' value=".$this_user['user_id']." ". $selected.">$user_info.</option>";
}
$result .= "</optgroup>";
}
$result .= "</select>";
return $result;
}
/**
* This function shows the form with the user that were selected
* @author: Patrick Cool <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, Ghent University
*/
function display_courseadmin_links() {
if (!isset($_GET['action'])) {
$actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar_na.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
} else {
$actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
}
$actions .= "<a href='agenda.php?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&action=add'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'),'',ICON_SIZE_MEDIUM)."</a>";
$actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'),'',ICON_SIZE_MEDIUM)."</a>";
return $actions;
function display_courseadmin_links($filter = 0) {
if (!isset($_GET['action'])) {
$to = show_to($filter);
$actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar_na.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
} else {
$actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'),'',ICON_SIZE_MEDIUM)."</a>";
}
$actions .= "<a href='agenda.php?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&action=add'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'),'',ICON_SIZE_MEDIUM)."</a>";
$actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'),'',ICON_SIZE_MEDIUM)."</a>";
$actions .= '<div style="width:380px;">';
$actions .= Display::return_icon('group.png', get_lang('To'), array ('align' => 'absmiddle'),ICON_SIZE_SMALL).' '.get_lang('To');
$actions .= $to;
$actions .= '</div>';
return $actions;
}
@ -2135,7 +2186,7 @@ function display_one_agenda_item($agenda_id) {
// Content
$content = $myrow['content'];
$content = make_clickable($content);
echo '<tr class="row_even">';
echo '<td '.(api_is_allowed_to_edit()?'colspan="3"':'colspan="2"'). '>';
echo $content;

@ -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) {

@ -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') {

@ -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':

Loading…
Cancel
Save