2004-06-12 11:48:20 +02:00
|
|
|
<?php
|
2006-08-22 18:50:19 +02:00
|
|
|
/**
|
|
|
|
* API - accounts selection
|
2009-03-13 13:55:40 +01:00
|
|
|
*
|
2006-08-22 18:50:19 +02:00
|
|
|
* @link http://www.egroupware.org
|
2009-03-13 13:55:40 +01:00
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
*
|
2006-08-22 18:50:19 +02:00
|
|
|
* The original version of the acount-selection popup was written and
|
|
|
|
* (c) 2003 by Bettina Gille [ceb@phpgroupware.org]
|
2009-03-13 13:55:40 +01:00
|
|
|
*
|
2006-08-22 18:50:19 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @subpackage html
|
|
|
|
* @access public
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User Interface for account and/or group selection
|
|
|
|
*/
|
2009-03-13 13:55:40 +01:00
|
|
|
class uiaccountsel
|
2006-08-22 18:50:19 +02:00
|
|
|
{
|
|
|
|
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;
|
2004-06-12 11:48:20 +02:00
|
|
|
/**
|
2008-03-25 17:58:50 +01:00
|
|
|
* Reference to global accounts object
|
2006-08-22 18:50:19 +02:00
|
|
|
*
|
2008-03-25 17:58:50 +01:00
|
|
|
* @var accounts
|
2004-06-12 11:48:20 +02:00
|
|
|
*/
|
2008-03-25 17:58:50 +01:00
|
|
|
var $accounts;
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @return uiaccountsel
|
|
|
|
*/
|
2009-03-13 13:55:40 +01:00
|
|
|
function __construct()
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2008-03-25 17:58:50 +01:00
|
|
|
$this->accounts = $GLOBALS['egw']->accounts;
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$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
|
2009-03-13 13:55:40 +01:00
|
|
|
if (isset($GLOBALS['egw_info']['user']['apps']['admin']) &&
|
2006-08-22 18:50:19 +02:00
|
|
|
($this->account_selection == 'none' || $this->account_selection == 'groupmembers'))
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$this->account_selection = 'primary_group';
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
/**
|
|
|
|
* Create an account-selection for a certain range of users
|
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 13:55:40 +01:00
|
|
|
* @param int $lines > 1 number of lines for multiselection, 0 for a single selection,
|
2007-05-07 20:59:05 +02:00
|
|
|
* < 0 or 1(=-4) single selection which can be switched to a multiselection by js abs($lines) is size
|
2006-08-22 18:50:19 +02:00
|
|
|
* (in that case accounts should be an int or contain only 1 user-id)
|
|
|
|
* @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.
|
2007-05-07 17:01:48 +02:00
|
|
|
* Or a string which gets added as first Option with value='', eg. lang('all'), can also be specified in the array with key ''
|
2006-08-22 18:50:19 +02:00
|
|
|
* @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.
|
2012-01-09 23:15:28 +01:00
|
|
|
* @param callback $label_callback=null callback to fetch a label for non-accounts
|
2006-08-22 18:50:19 +02:00
|
|
|
* @return string/array string with html for !$nohtml, array('selected' => $selected,'participants' => $select)
|
|
|
|
*/
|
2012-01-09 23:15:28 +01:00
|
|
|
function selection($name,$element_id,$selected,$use='accounts',$lines=0,$not=False,$options='',$onchange='',$select=False,$nohtml=false,$label_callback=null)
|
2006-08-22 18:50:19 +02:00
|
|
|
{
|
2012-01-09 23:15:28 +01:00
|
|
|
//error_log(__METHOD__."('$name',".array2string($selected).",'$use',rows=$lines,$not,'$options','$onchange',".array2string($select).",$nohtml,$label_callback) account_selection=$this->account_selection");
|
2007-05-07 20:59:05 +02:00
|
|
|
$multi_size=4;
|
|
|
|
if ($lines < 0)
|
|
|
|
{
|
|
|
|
$multi_size = abs($lines);
|
|
|
|
$lines = 1;
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($this->account_selection == 'none') // dont show user-selection at all!
|
|
|
|
{
|
2008-03-25 17:58:50 +01:00
|
|
|
return html::input_hidden($name,$selected);
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
if (!is_array($selected))
|
|
|
|
{
|
|
|
|
$selected = $selected ? explode(',',$selected) : array();
|
|
|
|
}
|
|
|
|
$account_sel = $this->account_selection;
|
|
|
|
$app = False;
|
|
|
|
switch($use)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
if (substr($use,-1) == '+')
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$app = substr($use,0,-1);
|
|
|
|
$use = 'both';
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
else
|
2004-06-28 11:32:47 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$app = $use;
|
|
|
|
$use = 'accounts';
|
2004-06-28 11:32:47 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'accounts':
|
|
|
|
case 'both':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'groups':
|
|
|
|
if ($this->account_selection == 'groupmembers') $use = 'owngroups';
|
|
|
|
// fall-through
|
|
|
|
|
|
|
|
case 'owngroups':
|
2007-05-27 08:26:17 +02:00
|
|
|
$only_groups = true;
|
2006-08-22 18:50:19 +02:00
|
|
|
$account_sel = 'selectbox'; // groups always use only the selectbox
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$extra_label = is_string($select) && !empty($select) ? $select : False;
|
2006-09-25 10:48:19 +02:00
|
|
|
if (is_array($select) && isset($select['']))
|
|
|
|
{
|
|
|
|
$extra_label = $select[''];
|
|
|
|
unset($select['']);
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
switch($account_sel)
|
|
|
|
{
|
|
|
|
case 'popup':
|
|
|
|
$select = $selected;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'primary_group':
|
|
|
|
case 'groupmembers':
|
|
|
|
if ($account_sel == 'primary_group')
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2007-04-26 13:52:47 +02:00
|
|
|
$memberships = array($GLOBALS['egw_info']['user']['account_primary_group']);
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 11:03:11 +02:00
|
|
|
$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
$select = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected;
|
|
|
|
foreach($memberships as $gid)
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2012-08-09 11:03:11 +02:00
|
|
|
foreach((array)$this->accounts->members($gid,true) as $member)
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2013-01-25 14:35:30 +01:00
|
|
|
if (!in_array($member,$select) && $this->accounts->is_active($member)) $select[] = $member;
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($use == 'both') // show all memberships
|
2004-08-29 22:32:56 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($account_sel == 'primary_group')
|
|
|
|
{
|
2012-08-09 11:03:11 +02:00
|
|
|
$memberships = (array)$this->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true);
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
$select = array_merge($select,$memberships);
|
2004-08-29 22:32:56 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'selectbox':
|
|
|
|
default:
|
|
|
|
if (!is_array($select))
|
2004-08-29 22:32:56 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$select = $GLOBALS['egw']->accounts->search(array(
|
|
|
|
'type' => $use,
|
|
|
|
'app' => $app,
|
2013-01-25 14:35:30 +01:00
|
|
|
'active' => true, // return only active accounts
|
2006-08-22 18:50:19 +02:00
|
|
|
));
|
2012-08-09 11:03:11 +02:00
|
|
|
//error_log(__METHOD__."() account_selection='$this->account_selection', accounts->search(array('type'=>'$use', 'app' => '$app')) returns ".array2string($select));
|
2004-08-29 22:32:56 +02:00
|
|
|
}
|
2012-01-09 23:15:28 +01:00
|
|
|
// make sure everything in $selected is also in $select, as in the other account-selection methods
|
2012-03-21 10:24:30 +01:00
|
|
|
if ($selected && ($missing = array_diff_key($selected,$select)))
|
2012-01-09 23:15:28 +01:00
|
|
|
{
|
2012-03-21 10:24:30 +01:00
|
|
|
foreach($missing as $k => $v) // merge missing (cant use array_merge, because of nummeric keys!)
|
|
|
|
{
|
|
|
|
$select[$k] = $v;
|
|
|
|
}
|
2012-01-09 23:15:28 +01:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$already_selected = $users = $groups = array();
|
|
|
|
$use_keys = count($select) && !isset($select[0]); // id's are the keys
|
|
|
|
foreach($select as $key => $val)
|
|
|
|
{
|
|
|
|
$id = $use_keys ? $key : (is_array($val) ? $val['account_id'] : $val);
|
|
|
|
|
|
|
|
if ($not && ($id == $not || is_array($not) && in_array($id,$not)))
|
|
|
|
{
|
|
|
|
continue; // dont display that one
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2012-01-09 23:15:28 +01:00
|
|
|
$label = common::grab_owner_name($id);
|
|
|
|
if ($label[0] === '#' && $label_callback)
|
|
|
|
{
|
|
|
|
if (!($label = call_user_func($label_callback, $id))) continue;
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
if (in_array($id,$selected)) // show already selected accounts first
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2012-01-09 23:15:28 +01:00
|
|
|
$already_selected[$id] = $label;
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2008-03-25 17:58:50 +01:00
|
|
|
elseif ($this->accounts->get_type($id) == 'u')
|
2004-07-04 19:28:57 +02:00
|
|
|
{
|
2012-01-09 23:15:28 +01:00
|
|
|
$users[$id] = !is_array($val) ? $label :
|
2010-06-09 09:26:39 +02:00
|
|
|
common::display_fullname(
|
2013-01-25 14:35:30 +01:00
|
|
|
$val['account_lid'],$val['account_firstname'],$val['account_lastname'],$id);
|
2004-07-04 19:28:57 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
else
|
2004-11-26 14:14:19 +01:00
|
|
|
{
|
2012-01-09 23:15:28 +01:00
|
|
|
$groups[$id] = $label;
|
2004-11-26 14:14:19 +01:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
// sort users and groups alphabeticaly and put the groups behind the users
|
|
|
|
uasort($already_selected,strcasecmp);
|
|
|
|
uasort($users,strcasecmp);
|
|
|
|
uasort($groups,strcasecmp);
|
|
|
|
$select = $already_selected + $users + $groups;
|
|
|
|
if (count($selected) && !isset($selected[0])) // id's are the keys
|
|
|
|
{
|
|
|
|
foreach($selected as $id => $val)
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
if (is_string($val) && isset($users[$id])) // add string to option-label
|
|
|
|
{
|
|
|
|
$users[$id] .= " ($val)";
|
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
$selected = array_keys($selected);
|
|
|
|
}
|
|
|
|
// add necessary popup trigers
|
2010-06-09 09:26:39 +02:00
|
|
|
$link = egw::link('/index.php',array(
|
2006-08-22 18:50:19 +02:00
|
|
|
'menuaction' => 'phpgwapi.uiaccountsel.popup',
|
|
|
|
'app' => $app,
|
|
|
|
'use' => $use,
|
|
|
|
'element_id' => $element_id,
|
|
|
|
'multiple' => $lines, // single selection (multiple=0), closes after the first selection
|
2010-06-09 09:26:39 +02:00
|
|
|
),false);
|
|
|
|
$popup_options = 'width=600,height=420,toolbar=no,scrollbars=yes,resizable=yes';
|
2006-08-22 18:50:19 +02:00
|
|
|
$app = $GLOBALS['egw_info']['flags']['currentapp'];
|
2007-05-27 08:26:17 +02:00
|
|
|
if (!$only_groups && ($lines <= 1 && $this->account_selection == 'popup' || !$lines && $this->account_selection == 'primary_group'))
|
2006-08-22 18:50:19 +02:00
|
|
|
{
|
|
|
|
if (!$lines)
|
2004-08-29 22:32:56 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$options .= ' onchange="if (this.value==\'popup\') '."window.open('$link','uiaccountsel','$popup_options');".
|
|
|
|
($onchange ? " else { $onchange }" : '' ).'" onclick="if (this.value==\'popup\') '."window.open('$link','uiaccountsel','$popup_options');\"";
|
|
|
|
$select['popup'] = lang('Search').' ...';
|
2004-08-29 22:32:56 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
elseif ($onchange)
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$options .= ' onchange="if (this.value[0]!=\',\') { '.$onchange.' }"';
|
|
|
|
}
|
|
|
|
$need_js_popup = True;
|
|
|
|
}
|
|
|
|
elseif ($onchange)
|
|
|
|
{
|
|
|
|
$options .= ' onchange="'.$onchange.'"';
|
|
|
|
}
|
|
|
|
if ($extra_label)
|
|
|
|
{
|
|
|
|
//in php5 this put's the extra-label at the end: $select = array($extra_label) + $select;
|
2007-04-26 09:34:27 +02:00
|
|
|
$select2 = array('' => $extra_label);
|
2006-08-22 18:50:19 +02:00
|
|
|
$select2 += $select;
|
|
|
|
$select =& $select2; unset($select2);
|
|
|
|
}
|
2012-08-09 11:03:11 +02:00
|
|
|
//error_log(__METHOD__."(..., use='$use', ...) account_selection='$this->account_selection', select=".array2string($select));
|
2009-03-13 13:55:40 +01:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($nohtml)
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'selected' => $selected,
|
|
|
|
'participants' => $select
|
2009-03-13 13:55:40 +01:00
|
|
|
);
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
//echo "<p>html::select('$name',".print_r($selected,True).",".print_r($select,True).",True,'$options')</p>\n";
|
2008-03-25 17:58:50 +01:00
|
|
|
$html = html::select($name,$selected,$select,True,$options.' id="'.$element_id.'"',$lines > 1 ? $lines : 0);
|
2006-08-22 18:50:19 +02:00
|
|
|
|
2007-05-27 08:26:17 +02:00
|
|
|
if (!$only_groups && ($lines > 0 && $this->account_selection == 'popup' || $lines > 1 && $this->account_selection == 'primary_group'))
|
2006-08-22 18:50:19 +02:00
|
|
|
{
|
2007-05-07 20:59:05 +02:00
|
|
|
$js = "window.open('$link','uiaccountsel','$popup_options'); return false;";
|
2008-03-25 17:58:50 +01:00
|
|
|
$html .= html::submit_button('search','Search accounts',$js,false,
|
|
|
|
' title="'.html::htmlspecialchars(lang('Search accounts')).'"','search','phpgwapi');
|
2006-08-22 18:50:19 +02:00
|
|
|
$need_js_popup = True;
|
|
|
|
}
|
2007-05-27 08:26:17 +02:00
|
|
|
elseif (!$only_groups && ($lines == 1 || $lines > 0 && $this->account_selection == 'primary_group'))
|
2006-08-22 18:50:19 +02:00
|
|
|
{
|
2007-05-07 20:59:05 +02:00
|
|
|
$js = "if (selectBox = document.getElementById('$element_id')) if (!selectBox.multiple) {selectBox.size=$multi_size; selectBox.multiple=true; if (selectBox.options[0].value=='') selectBox.options[0] = null;";
|
|
|
|
if (!in_array($this->account_selection,array('groupmembers','selectbox'))) // no popup!
|
|
|
|
{
|
2010-06-09 09:26:39 +02:00
|
|
|
$js .= " this.src='".common::image('phpgwapi','search')."'; this.title='".
|
2008-03-25 17:58:50 +01:00
|
|
|
html::htmlspecialchars(lang('Search accounts'))."';} else {window.open('$link','uiaccountsel','$popup_options');";
|
2007-05-07 20:59:05 +02:00
|
|
|
$need_js_popup = True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$js .= " this.style.display='none'; selectBox.style.width='100%';";
|
|
|
|
}
|
|
|
|
$js .= "} return false;";
|
2008-03-25 17:58:50 +01:00
|
|
|
$html .= html::submit_button('search','Select multiple accounts',$js,false,
|
|
|
|
' title="'.html::htmlspecialchars(lang('Select multiple accounts')).'"','users','phpgwapi');
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
if($need_js_popup && !$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'])
|
|
|
|
{
|
|
|
|
$html .= '<script language="JavaScript">
|
|
|
|
function addOption(id,label,value,do_onchange)
|
|
|
|
{
|
|
|
|
selectBox = document.getElementById(id);
|
|
|
|
for (i=0; i < selectBox.length; i++) {
|
2004-06-13 22:17:54 +02:00
|
|
|
'.// check existing entries if they're already there and only select them in that case
|
2007-05-07 20:59:05 +02:00
|
|
|
' if (selectBox.options[i].value == value) {
|
2006-08-22 18:50:19 +02:00
|
|
|
selectBox.options[i].selected = true;
|
|
|
|
break;
|
2004-06-12 23:58:47 +02:00
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
if (i >= selectBox.length) {
|
2007-05-07 20:59:05 +02:00
|
|
|
if (!do_onchange) {
|
|
|
|
if (selectBox.length && selectBox.options[0].value=="") selectBox.options[0] = null;
|
|
|
|
selectBox.multiple=true;
|
|
|
|
selectBox.size='.$multi_size.';
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
selectBox.options[selectBox.length] = new Option(label,value,false,true);
|
|
|
|
}
|
|
|
|
if (selectBox.onchange && do_onchange) selectBox.onchange();
|
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
</script>';
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'] = True;
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
return $html;
|
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
function popup()
|
|
|
|
{
|
|
|
|
global $query; // nextmatch requires that !!!
|
2004-06-13 22:17:54 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$app = get_var('app',array('POST','GET'));
|
|
|
|
$use = get_var('use',array('POST','GET'));
|
2012-09-04 16:08:30 +02:00
|
|
|
$group_id = get_var('group_id',array('POST','GET'), $GLOBALS['egw_info']['user']['account_primary_group']);
|
2006-08-22 18:50:19 +02:00
|
|
|
$element_id = get_var('element_id',array('POST','GET'));
|
|
|
|
$multiple = get_var('multiple',array('POST','GET'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$query = get_var('query',array('POST','GET'));
|
|
|
|
$query_type = get_var('query_type',array('POST','GET'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$start = (int) get_var('start',array('POST'),0);
|
|
|
|
$order = get_var('order',array('POST','GET'),'account_lid');
|
|
|
|
$sort = get_var('sort',array('POST','GET'),'ASC');
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
//echo "<p>uiaccountsel::popup(): app='$app', use='$use', multiple='$multiple', group_id='$group_id', element_id='$element_id', start='$start', order='$order', sort='$sort'</p>\n";
|
2004-06-12 14:26:50 +02:00
|
|
|
|
2010-11-02 14:26:51 +01:00
|
|
|
$nextmatchs = new nextmatchs();
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2010-06-09 09:26:39 +02:00
|
|
|
$GLOBALS['egw']->template->set_root(common::get_tpl_dir('phpgwapi'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_file(array('accounts_list_t' => 'uiaccountsel.tpl'));
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','letter_search','letter_search_cells');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','group_cal','cal');
|
2010-07-31 10:07:21 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','group_selectAll','selectAllGroups');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','groups_multiple','multipleGroups');
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','group_other','other');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','group_all','all');
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','bla_intro','ibla');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','other_intro','iother');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','all_intro','iall');
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2010-07-31 10:07:21 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_selectAll','selectAllAccounts');
|
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_multiple','multipleAccounts');
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_block('accounts_list_t','accounts_list','list');
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('font',$GLOBALS['egw_info']['theme']['font']);
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_search',lang('search'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_groups',lang('user groups'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_accounts',lang('user accounts'));
|
2010-07-31 10:07:21 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_all',lang('all'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2010-06-09 09:26:39 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('img',common::image('phpgwapi','select'));
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_select_user',lang('Select user'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_select_group',lang('Select group'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($app) // split the groups in the ones with run-rights and without
|
|
|
|
{
|
|
|
|
if ($use == 'both') // groups with run-rights too, eg. calendar
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->fp('ibla','bla_intro',True);
|
2004-06-16 02:31:48 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
else
|
2004-06-16 02:31:48 +02:00
|
|
|
{
|
2005-10-24 12:30:29 +02:00
|
|
|
$GLOBALS['egw']->template->fp('iother','other_intro',True);
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->fp('iall','all_intro',True);
|
|
|
|
}
|
|
|
|
else // use all groups and account, eg. admin
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_perm',lang('group name'));
|
|
|
|
$GLOBALS['egw']->template->fp('iother','other_intro',True);
|
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($multiple >= 1)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->js->set_onload("copyOptions('$element_id');");
|
|
|
|
}
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('search or select accounts');
|
2010-06-09 09:26:39 +02:00
|
|
|
common::egw_header();
|
2006-08-22 18:50:19 +02:00
|
|
|
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_perm',lang('Groups with permission for %1',lang($app)));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_nonperm',lang('Groups without permission for %1',lang($app)));
|
|
|
|
|
|
|
|
$link_data = array
|
|
|
|
(
|
|
|
|
'menuaction' => 'phpgwapi.uiaccountsel.popup',
|
|
|
|
'app' => $app,
|
|
|
|
'use' => $use,
|
|
|
|
'group_id' => $group_id,
|
|
|
|
'element_id' => $element_id,
|
|
|
|
'multiple' => $multiple,
|
|
|
|
'query_type' => $query_type,
|
|
|
|
'query' => $query,
|
|
|
|
);
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
// -------------- list header variable template-declaration ------------------------
|
2010-11-02 14:26:51 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('sort_lid',$nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('LoginID'),$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('sort_firstname',$nextmatchs->show_sort_order($sort,'account_firstname',$order,'/index.php',lang('Firstname'),$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('sort_lastname',$nextmatchs->show_sort_order($sort,'account_lastname',$order,'/index.php',lang('Lastname'),$link_data));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2004-06-16 02:31:48 +02:00
|
|
|
// ------------------------- end header declaration --------------------------------
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$link_data['sort'] = $sort;
|
|
|
|
$link_data['order'] = $order;
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_list_members',lang('List members'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_firstname',lang('firstname'));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_lastname',lang('lastname'));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2010-07-31 10:07:21 +02:00
|
|
|
if ($multiple)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->template->fp('multipleGroups','groups_multiple',True);
|
|
|
|
}
|
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($app)
|
|
|
|
{
|
2008-03-25 17:58:50 +01:00
|
|
|
$app_groups = $this->accounts->split_accounts($app,'groups');
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
2008-03-25 17:58:50 +01:00
|
|
|
$all_groups = $this->accounts->search(array(
|
2010-11-02 14:03:01 +01:00
|
|
|
'type' => 'groups',
|
|
|
|
'order' => 'account_lid',
|
|
|
|
'sort' => 'ASC',
|
2006-08-22 18:50:19 +02:00
|
|
|
));
|
2010-11-02 14:26:51 +01:00
|
|
|
$tr_color_app_groups = $tr_color_all_groups = 'row_off';
|
2006-08-22 18:50:19 +02:00
|
|
|
foreach($all_groups as $group)
|
|
|
|
{
|
|
|
|
$link_data['group_id'] = $group['account_id'];
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('onclick',"addOption('$element_id','".
|
2011-03-09 19:45:08 +01:00
|
|
|
addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple==1).")".
|
2006-08-22 18:50:19 +02:00
|
|
|
(!$multiple ? '; window.close()' : ''));
|
2004-06-16 02:31:48 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if (!$app || in_array($group['account_id'],$app_groups))
|
|
|
|
{
|
2010-11-02 14:26:51 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('tr_color',$tr_color_app_groups=$nextmatchs->alternate_row_color($tr_color_app_groups,True));
|
2010-06-09 09:26:39 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('link_user_group',egw::link('/index.php',$link_data));
|
2012-09-04 16:08:30 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('name_user_group', ($group['account_id'] == $group_id ? '<b>' : '').
|
|
|
|
common::grab_owner_name($group['account_id']).($group['account_id'] == $group_id ? '</b>' : ''));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if($use == 'both') // allow selection of groups
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->template->fp('cal','group_cal',True);
|
2010-07-31 10:07:21 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('js_addAllGroups',"addOption('$element_id','".
|
2011-03-09 19:45:08 +01:00
|
|
|
addslashes(common::grab_owner_name($group['account_id']))."','$group[account_id]',".(int)($multiple==1).")".
|
2010-07-31 10:07:21 +02:00
|
|
|
(!$multiple ? '; window.close();' : ';'));
|
|
|
|
$GLOBALS['egw']->template->fp('selectAllGroups','group_selectAll',True);
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2004-06-16 02:31:48 +02:00
|
|
|
else
|
2004-06-12 11:48:20 +02:00
|
|
|
{
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->fp('other','group_other',True);
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
else
|
|
|
|
{
|
2010-11-02 14:26:51 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('tr_color',$tr_color_all_groups=$nextmatchs->alternate_row_color($tr_color_all_groups,True));
|
2010-06-09 09:26:39 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('link_all_group',egw::link('/index.php',$link_data));
|
|
|
|
$GLOBALS['egw']->template->set_var('name_all_group',common::grab_owner_name($group['account_id']));
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('accountid',$group['account_id']);
|
|
|
|
$GLOBALS['egw']->template->fp('all','group_all',True);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$link_data['group_id'] = $group_id; // reset it
|
2004-06-12 11:48:20 +02:00
|
|
|
|
|
|
|
// --------------------------------- nextmatch ---------------------------
|
2008-03-25 17:58:50 +01:00
|
|
|
$users = $this->accounts->search(array(
|
2006-08-22 18:50:19 +02:00
|
|
|
'type' => $group_id ? $group_id : $use,
|
|
|
|
'app' => $app,
|
|
|
|
'start' => $start,
|
|
|
|
'order' => $order,
|
|
|
|
'sort' => $sort,
|
|
|
|
'query' => $query,
|
|
|
|
'query_type' => $query_type,
|
|
|
|
));
|
|
|
|
|
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2010-11-02 14:26:51 +01:00
|
|
|
'left' => $nextmatchs->left('/index.php',$start,$this->accounts->total,$link_data+array('query'=>$query)),
|
|
|
|
'right' => $nextmatchs->right('/index.php',$start,$this->accounts->total,$link_data+array('query'=>$query)),
|
2010-06-09 09:26:39 +02:00
|
|
|
'lang_showing' => ($group_id ? common::grab_owner_name($group_id).': ' : '').
|
2008-03-25 17:58:50 +01:00
|
|
|
($query ? lang("Search %1 '%2'",lang($this->accounts->query_types[$query_type]),$query).': ' : '')
|
2010-11-02 14:26:51 +01:00
|
|
|
.$nextmatchs->show_hits($this->accounts->total,$start),
|
2006-08-22 18:50:19 +02:00
|
|
|
));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
|
|
|
// -------------------------- end nextmatch ------------------------------------
|
|
|
|
|
2010-06-09 09:26:39 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('search_action',egw::link('/index.php',$link_data));
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('prev_query', $query);
|
2010-11-02 14:26:51 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('search_list',$nextmatchs->search(array('query' => $query, 'search_obj' => 1)));
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('lang_firstname', lang("firstname"));
|
|
|
|
$GLOBALS['egw']->template->set_var('lang_lastname', lang("lastname"));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2010-07-31 10:07:21 +02:00
|
|
|
if ($multiple)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->template->fp('multipleAccounts','accounts_multiple',True);
|
|
|
|
}
|
|
|
|
|
2010-11-02 14:26:51 +01:00
|
|
|
$tr_color = 'row_off';
|
2006-08-22 18:50:19 +02:00
|
|
|
foreach($users as $user)
|
|
|
|
{
|
2010-11-02 14:26:51 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('tr_color',$tr_color=$nextmatchs->alternate_row_color($tr_color,True));
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2004-07-08 11:58:11 +02:00
|
|
|
// ---------------- template declaration for list records --------------------------
|
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
|
|
|
'lid' => $user['account_lid'],
|
|
|
|
'firstname' => $user['account_firstname'] ? $user['account_firstname'] : ' ',
|
|
|
|
'lastname' => $user['account_lastname'] ? $user['account_lastname'] : ' ',
|
|
|
|
'onclick' => "addOption('$element_id','".
|
2011-03-09 19:45:08 +01:00
|
|
|
addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple==1).")".
|
2006-08-22 18:50:19 +02:00
|
|
|
(!$multiple ? '; window.close()' : ''),
|
|
|
|
));
|
|
|
|
$GLOBALS['egw']->template->fp('list','accounts_list',True);
|
2010-07-31 10:07:21 +02:00
|
|
|
$GLOBALS['egw']->template->set_var('js_addAllAccounts',"addOption('$element_id','".
|
2011-03-09 19:45:08 +01:00
|
|
|
addslashes(common::grab_owner_name($user['account_id']))."','$user[account_id]',".(int)($multiple==1).")".
|
2010-07-31 10:07:21 +02:00
|
|
|
(!$multiple ? '; window.close()' : ';'));
|
|
|
|
$GLOBALS['egw']->template->fp('selectAllAccounts','accounts_selectAll',True);
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2008-03-25 17:58:50 +01:00
|
|
|
$GLOBALS['egw']->template->set_var('accountsel_icon',html::image('phpgwapi','users-big'));
|
|
|
|
$GLOBALS['egw']->template->set_var('query_type',is_array($this->accounts->query_types) ? html::select('query_type',$query_type,$this->accounts->query_types) : '');
|
2004-06-13 22:17:54 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
$link_data['query_type'] = 'start';
|
|
|
|
$letters = lang('alphabet');
|
|
|
|
$letters = explode(',',substr($letters,-1) != '*' ? $letters : 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
|
|
|
|
foreach($letters as $letter)
|
|
|
|
{
|
|
|
|
$link_data['query'] = $letter;
|
2005-10-24 12:30:29 +02:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2006-08-22 18:50:19 +02:00
|
|
|
'letter' => $letter,
|
2010-06-09 09:26:39 +02:00
|
|
|
'link' => egw::link('/index.php',$link_data),
|
2006-08-22 18:50:19 +02:00
|
|
|
'class' => $query == $letter && $query_type == 'start' ? 'letter_box_active' : 'letter_box',
|
2004-06-13 22:17:54 +02:00
|
|
|
));
|
2005-10-24 12:30:29 +02:00
|
|
|
$GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True);
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
|
|
|
unset($link_data['query']);
|
|
|
|
unset($link_data['query_type']);
|
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
|
|
|
'letter' => lang('all'),
|
2010-06-09 09:26:39 +02:00
|
|
|
'link' => egw::link('/index.php',$link_data),
|
2006-08-22 18:50:19 +02:00
|
|
|
'class' => $query_type != 'start' || !in_array($query,$letters) ? 'letter_box_active' : 'letter_box',
|
|
|
|
));
|
|
|
|
$GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True);
|
|
|
|
|
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
|
|
|
'lang_selection' => lang('selection'),
|
|
|
|
'lang_close' => lang('close'),
|
|
|
|
'close_action' => 'window.close();',
|
|
|
|
));
|
2009-03-13 13:55:40 +01:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($multiple >= 1)
|
|
|
|
{
|
2005-10-24 12:30:29 +02:00
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2006-08-22 18:50:19 +02:00
|
|
|
'lang_close' => lang('submit'),
|
|
|
|
'lang_multiple' => lang('multiple'),
|
|
|
|
'close_action' => "oneLineSubmit('$element_id');",
|
2004-06-13 22:17:54 +02:00
|
|
|
));
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|
2009-03-13 13:55:40 +01:00
|
|
|
|
2004-06-12 11:48:20 +02:00
|
|
|
|
2006-08-22 18:50:19 +02:00
|
|
|
if ($multiple)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->template->set_var(array(
|
2008-03-25 17:58:50 +01:00
|
|
|
'selection' => html::select('selected',False,array(),True,' id="uiaccountsel_popup_selection" style="width: 100%;"',13),
|
|
|
|
'remove' => html::submit_button('remove','remove',
|
2006-08-22 18:50:19 +02:00
|
|
|
"removeSelectedOptions('$element_id'); return false;",True,' title="'.lang('Remove selected accounts').'"','delete'),
|
|
|
|
));
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
$GLOBALS['egw']->template->pfp('out','accounts_list_t',True);
|
|
|
|
|
2010-06-09 09:26:39 +02:00
|
|
|
common::egw_footer();
|
2004-06-12 11:48:20 +02:00
|
|
|
}
|
2006-08-22 18:50:19 +02:00
|
|
|
}
|