Two new options for the account-selection:

- Selectbox with groupmembers (only)
- No user-selection at all
These two options limit the visibility of other users. There for they should be forced and apply NOT to administrators.
This commit is contained in:
Ralf Becker 2006-08-22 16:50:19 +00:00
parent cb2a42be22
commit 8fd0640039

View File

@ -1,45 +1,65 @@
<?php
/**************************************************************************\
* eGroupWare API - Accounts manager - User Interface functions *
* Written or modified by RalfBecker@outdoor-training.de *
* The original version of the acount-selection popup was written and *
* (c) 2003 by Bettina Gille [ceb@phpgroupware.org] *
* -------------------------------------------------------------------------*
* This library is part of the eGroupWare API *
* http://www.egroupware.org *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
include_once(EGW_API_INC . '/class.accounts.inc.php');
/**
* User Interface for account and/or group selection
/**
* API - accounts selection
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
*
* The original version of the acount-selection popup was written and
* (c) 2003 by Bettina Gille [ceb@phpgroupware.org]
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package api
* @subpackage html
* @access public
* @version $Id$
*/
class uiaccountsel extends accounts
{
include_once(EGW_API_INC . '/class.accounts.inc.php');
/**
* User Interface for account and/or group selection
*
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package api
* @subpackage html
* @access public
*/
class uiaccountsel extends accounts
{
var $public_functions = array(
'popup' => True,
);
/**
* value of the commen pref. 'account_selection' for non admins, 'primary_group' for admins
*
* @var string
*/
var $account_selection;
/**
* Reference to the html-class
*
* @var html
*/
var $html;
function uiaccountsel($account_id = '', $account_type='')
/**
* Constructor
*
* @return uiaccountsel
*/
function uiaccountsel()
{
$this->accounts($account_id,$account_type); // call constructor of extended class
$this->accounts(); // call constructor of extended class
$this->account_selection = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'];
// admin group should NOT get limited by none or groupmembers, we use primary_group instead
if (isset($GLOBALS['egw_info']['user']['apps']['admin']) &&
($this->account_selection == 'none' || $this->account_selection == 'groupmembers'))
{
$this->account_selection = 'primary_group';
}
if (!is_object($GLOBALS['egw']->html))
{
$GLOBALS['egw']->html =& CreateObject('phpgwapi.html');
@ -50,26 +70,38 @@
/**
* Create an account-selection for a certain range of users
*
* @param $name string name of the form-element
* @param $element_id string id of the form-element, this need to be unique for the whole window !!!
* @param $selected array/int user-id or array of user-id's which are already selected
* @param $use string 'accounts', 'groups', 'owngroups', 'both' or app-name for all accounts with run-rights.
* The function respects the 'account_selection' general preference:
* - 'selectbox' => Selectbox with all accounts and groups
* - 'primary_group' => Selectbox with primary group and search
* - 'popup' => Popup with search
* - 'groupmembers' => Non admins can only select groupmembers
* - 'none' => Non admins can NOT select any other user
*
* @param string $name name of the form-element
* @param string $element_id id of the form-element, this need to be unique for the whole window !!!
* @param array/int $selected user-id or array of user-id's which are already selected
* @param string $use 'accounts', 'groups', 'owngroups', 'both' or app-name for all accounts with run-rights.
* If an '+' is appended to the app-name, one can also select groups with run-rights for that app.
* @param $lines int number of lines for multiselection or 0 for a single selection
* @param int $lines number of lines for multiselection or 0 for a single selection
* (in that case accounts should be an int or contain only 1 user-id)
* @param $not int/array user-id or array of user-id's not to display in selection, default False = display all
* @param $options additional options (e.g. style)
* @param $onchange javascript to execute if the selection changes, eg. to reload the page
* @param $select array/bool/string array with id's as keys or values. If the id is in the key and the value is a string,
* @param int/array $not user-id or array of user-id's not to display in selection, default False = display all
* @param string $options additional options (e.g. style)
* @param string $onchange javascript to execute if the selection changes, eg. to reload the page
* @param array/bool/string $select array with id's as keys or values. If the id is in the key and the value is a string,
* it gets appended to the user-name. Or false if the selectable values for the selectbox are determined by use.
* Or a string which gets added as first Option with value=0, eg. lang('all')
* @param $nohtml boolean if true, returns an array with the key 'selected' as the selected participants,
* @param boolean $nohtml if true, returns an array with the key 'selected' as the selected participants,
* and with the key 'participants' as the participants data as would fit in a select.
* @return the necessary html
* @return string/array string with html for !$nohtml, array('selected' => $selected,'participants' => $select)
*/
function selection($name,$element_id,$selected,$use='accounts',$lines=0,$not=False,$options='',$onchange='',$select=False,$nohtml=false)
{
//echo "<p>uiaccountsel::selection('$name',".print_r($selected,True).",'$use',$lines,$not,'$options','$onchange',".print_r($select,True).")</p>\n";
//echo "<p align=right>uiaccountsel::selection('$name',".print_r($selected,True).",'$use',$lines,$not,'$options','$onchange',".print_r($select,True).") account_selection=$this->account_selection</p>\n";
if ($this->account_selection == 'none') // dont show user-selection at all!
{
return $this->html->input_hidden($name,$selected);
}
if (!is_array($selected))
{
$selected = $selected ? explode(',',$selected) : array();
@ -90,10 +122,15 @@
$use = 'accounts';
}
break;
case 'accounts':
case 'both':
break;
case 'groups':
if ($this->account_selection == 'groupmembers') $use = 'owngroups';
// fall-through
case 'owngroups':
$account_sel = 'selectbox'; // groups always use only the selectbox
break;
@ -104,20 +141,35 @@
case 'popup':
$select = $selected;
break;
case 'primary_group':
case 'groupmembers':
if ($account_sel == 'primary_group')
{
$memberships = array($GLOBALS['egw']->accounts->data['account_primary_group']);
}
else
{
$memberships = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
}
$select = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected;
$members = $this->member($GLOBALS['egw']->accounts->data['account_primary_group']);
if (is_array($members))
foreach($memberships as $gid)
{
foreach($members as $member)
foreach($this->members($gid,true) as $member)
{
if (!in_array($member['account_id'],$select))
{
$select[] = $member['account_id'];
if (!in_array($member,$select)) $select[] = $member;
}
}
if ($use == 'both') // show all memberships
{
if ($account_sel == 'primary_group')
{
$memberships = $this->memberships($GLOBALS['egw_info']['user']['account_id'],true);
}
$select = array_merge($select,$memberships);
}
break;
case 'selectbox':
default:
if (!is_array($select))
@ -180,7 +232,7 @@
));
$popup_options = 'width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes';
$app = $GLOBALS['egw_info']['flags']['currentapp'];
if ($lines <= 1 && $use != 'groups' && $use != 'owngroups')
if ($lines <= 1 && $use != 'groups' && $use != 'owngroups' && $account_sel != 'groupmembers' && $account_sel != 'selectbox')
{
if (!$lines)
{
@ -231,8 +283,8 @@
if($need_js_popup && !$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'])
{
$html .= '<script language="JavaScript">
function addOption(id,label,value,do_onchange)
{
function addOption(id,label,value,do_onchange)
{
selectBox = document.getElementById(id);
for (i=0; i < selectBox.length; i++) {
'.// check existing entries if they're already there and only select them in that case
@ -253,7 +305,7 @@
selectBox.options[selectBox.length] = new Option(label,value,false,true);
}
if (selectBox.onchange && do_onchange) selectBox.onchange();
}
}
</script>';
$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'] = True;
}
@ -499,4 +551,4 @@
$GLOBALS['egw']->common->egw_footer();
}
}
}