From 56376e9e2e75bec0313844c236aef73ef96dd390 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 30 Jan 2012 17:01:26 +0100 Subject: [PATCH] Adding new filter: users in any group see BT#3614 --- main/admin/add_users_to_usergroup.php | 40 +++++++++++++++++++++++++-- main/inc/lib/usergroup.lib.php | 9 ++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/main/admin/add_users_to_usergroup.php b/main/admin/add_users_to_usergroup.php index 330558009e..5ad6f69b1e 100644 --- a/main/admin/add_users_to_usergroup.php +++ b/main/admin/add_users_to_usergroup.php @@ -68,6 +68,21 @@ function validate_filter() { document.formulaire.form_sent.value=0; document.formulaire.submit(); } + +function checked_in_no_group(checked) { + $("#first_letter_user") + .find("option") + .attr("selected", false); + document.formulaire.form_sent.value="2"; + document.formulaire.submit(); +} + +function change_select(val) { + $("#user_with_any_group_id").attr("checked", false); + document.formulaire.form_sent.value="2"; + document.formulaire.submit(); +} + '; @@ -88,6 +103,7 @@ if (is_array($extra_field_list)) { $usergroup = new UserGroup(); $id = intval($_GET['id']); $first_letter_user = ''; + if ($_POST['form_sent']) { $form_sent = $_POST['form_sent']; $elements_posted = $_POST['elements_in_name']; @@ -137,6 +153,8 @@ if ($use_extra_fields) { $data = $usergroup->get($id); $list_in = $usergroup->get_users_by_usergroup($id); +$list_all = $usergroup->get_users_by_usergroup(); + $order = array('lastname'); if (api_is_western_name_order()) { $order = array('firstname'); @@ -144,6 +162,7 @@ if (api_is_western_name_order()) { $elements_not_in = $elements_in = array(); $complete_user_list = UserManager::get_user_list(array(), $order); + if (!empty($complete_user_list)) { foreach($complete_user_list as $item) { if ($use_extra_fields) { @@ -159,10 +178,21 @@ if (!empty($complete_user_list)) { } } } + +$user_with_any_group = isset($_REQUEST['user_with_any_group']) && !empty($_REQUEST['user_with_any_group']) ? true : false; -//if (!empty($first_letter_user)) { +if ($user_with_any_group) { $user_list = UserManager::get_user_list_like(array('lastname' => $first_letter_user), $order, true); -//} + $new_user_list = array(); + foreach($user_list as $item) { + if (!in_array($item['user_id'], $list_all)) { + $new_user_list[] = $item; + } + } + $user_list = $new_user_list; +} else { + $user_list = UserManager::get_user_list_like(array('lastname' => $first_letter_user), $order, true); +} if (!empty($user_list)) { foreach($user_list as $item) { @@ -246,7 +276,7 @@ if(!empty($errorMsg)) { : -
'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> +
+ onchange="checked_in_no_group(this.checked);" name="user_with_any_group" id="user_with_any_group_id"> + +
diff --git a/main/inc/lib/usergroup.lib.php b/main/inc/lib/usergroup.lib.php index 6e6c19ac01..91d4a54584 100644 --- a/main/inc/lib/usergroup.lib.php +++ b/main/inc/lib/usergroup.lib.php @@ -74,8 +74,13 @@ class UserGroup extends Model { * @param int user group id * @return array with a list of user ids */ - public function get_users_by_usergroup($id) { - $results = Database::select('user_id',$this->usergroup_rel_user_table, array('where'=>array('usergroup_id = ?'=>$id))); + public function get_users_by_usergroup($id = null) { + if (empty($id)) { + $conditions = array(); + } else { + $conditions = array('where'=>array('usergroup_id = ?'=>$id)); + } + $results = Database::select('user_id', $this->usergroup_rel_user_table, $conditions, true); $array = array(); if (!empty($results)) { foreach($results as $row) {