True, ); function uiaccountsel($account_id = '', $account_type='') { $this->accounts($account_id,$account_type); // call constructor of extended class $this->account_selection = $GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection']; if (!is_object($GLOBALS['phpgw']->html)) { $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); } $this->html = $GLOBALS['phpgw']->html; } /** * 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/array 'accounts', 'groups', 'both' or app-name for all accounts with run-rights or an * 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 * @param $lines int 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 * @return the necessary html */ function selection($name,$element_id,$selected,$use='accounts',$lines=1,$not=False,$options='',$onchange='') { //echo "
uiaccountsel::selection('$name',".print_r($selected,True).",'$use',$lines,$not,'$options')
\n"; if (!is_array($selected)) { $selected = $selected ? array($selected) : array(); } $enumerate_groups = False; switch($this->account_selection) { case 'popup': $use = $selected; break; case 'primary_group': $use = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected; $members = $this->member($GLOBALS['phpgw']->accounts->data['account_primary_group']); if (is_array($members)) { foreach($members as $member) { if (!in_array($member['account_id'],$use)) { $use[] = $member['account_id']; } } } break; case 'selectbox': default: if ($use == 'accounts' || $use == 'groups' || $use == 'both') { $use = $GLOBALS['phpgw']->accounts->get_list($use); } elseif (!is_array($use)) // app-name { $use = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,$use); $enumerate_groups = True; } } $users = $groups = array(); $use_keys = count($use) && !isset($use[0]); // id's are the keys foreach($use 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 } if ($this->get_type($id) == 'u') { $users[$id] = !is_array($val) ? $GLOBALS['phpgw']->common->grab_owner_name($id) : $GLOBALS['phpgw']->common->display_fullname( $val['account_lid'],$val['account_firstname'],$val['account_lastname']); } else { if ($enumerate_groups && ($members = $this->member($id))) { foreach($members as $member) { if ($not && $member['account_id'] == $not) continue; // dont display that one $users[$member['account_id']] = $GLOBALS['phpgw']->common->grab_owner_name($member['account_id']); } } $groups[$id] = lang('group').' '.$this->id2name($id); } } // sort users and groups alphabeticaly and put the groups behind the users uasort($users,strcasecmp); uasort($groups,strcasecmp); $select = $users + $groups; if (count($selected) && !isset($selected[0])) // id's are the keys { foreach($selected as $id => $val) { if (is_string($val) && isset($users[$id])) // add string to option-label { $users[$id] .= " ($val)"; } } $selected = array_keys($selected); } // add necessary popup trigers $link = $GLOBALS['phpgw']->link('/index.php',array( 'menuaction' => 'phpgwapi.uiaccountsel.popup', 'app' => $GLOBALS['phpgw_info']['flags']['currentapp'], 'element_id' => $element_id, 'single' => !$lines, // single selection, closes after the first selection )); $popup_options = 'width=600,height=400,toolbar=no,scrollbars=auto,resizable=yes'; $app = $GLOBALS['phpgw_info']['flags']['currentapp']; $single = (int) !$lines; if (!$lines) { $options .= ' onchange="if (this.value==\'popup\') '."window.open('$link','uiaccountsel','$popup_options');". ($onchange ? " else { $onchange }" : '' ).'"'; $select['popup'] = lang('Search').' ...'; $need_js_popup = True; } elseif ($onchange) { $options .= ' onchange="'.$onchange.'"'; } //echo "html::select('$name',".print_r($selected,True).",".print_r($select,True).",True,'$options')
\n"; $html = $this->html->select($name,$selected,$select,True,$options.' id="'.$element_id.'"',$lines); if ($lines > 1 && ($this->account_selection == 'popup' || $this->account_selection == 'primary_group')) { $html .= ''. $this->html->image('phpgwapi','users',lang('search or select accounts')).''; $need_js_popup = True; } if($need_js_popup && !$GLOBALS['phpgw_info']['flags']['uiaccountsel']['addOption_installed']) { $html .= ''; $GLOBALS['phpgw_info']['flags']['uiaccountsel']['addOption_installed'] = True; } return $html; } function popup($app='') { global $query; // nextmatch requires that !!! if (!$app) $app = get_var('app',array('POST','GET')); $group_id = get_var('group_id',array('POST','GET'),$GLOBALS['phpgw']->accounts->data['account_primary_group']); $element_id = get_var('element_id',array('POST','GET')); $single = get_var('single',array('POST','GET')); $query = get_var('query',array('POST','GET')); $query_type = get_var('query_type',array('POST','GET')); $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'); //echo "uiaccountsel::popup(): app='$app', group_id='$group_id', element_id='$element_id', start='$start', order='$order', sort='$sort'
\n"; $this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); $GLOBALS['phpgw']->template->set_root($GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi')); $GLOBALS['phpgw']->template->set_file(array('accounts_list_t' => 'uiaccountsel.tpl')); $GLOBALS['phpgw']->template->set_block('accounts_list_t','letter_search','letter_search_cells'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','group_cal','cal'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','group_other','other'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','group_all','all'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','bla_intro','ibla'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','other_intro','iother'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','all_intro','iall'); $GLOBALS['phpgw']->template->set_block('accounts_list_t','accounts_list','list'); $GLOBALS['phpgw']->template->set_var('font',$GLOBALS['phpgw_info']['theme']['font']); $GLOBALS['phpgw']->template->set_var('lang_search',lang('search')); $GLOBALS['phpgw']->template->set_var('lang_groups',lang('user groups')); $GLOBALS['phpgw']->template->set_var('lang_accounts',lang('user accounts')); $GLOBALS['phpgw']->template->set_var('img',$GLOBALS['phpgw']->common->image('phpgwapi','select')); $GLOBALS['phpgw']->template->set_var('lang_select_user',lang('Select user')); $GLOBALS['phpgw']->template->set_var('lang_select_group',lang('Select group')); $GLOBALS['phpgw']->template->set_var('css_file',$GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/idots/css/idots.css'); switch($app) { case 'calendar': $GLOBALS['phpgw']->template->fp('ibla','bla_intro',True); $GLOBALS['phpgw']->template->fp('iall','all_intro',True); break; case 'admin': $GLOBALS['phpgw']->template->set_var('lang_perm',lang('group name')); $GLOBALS['phpgw']->template->fp('iother','other_intro',True); break; default: $GLOBALS['phpgw']->template->fp('iother','other_intro',True); $GLOBALS['phpgw']->template->fp('iall','all_intro',True); break; } if (!$single) { if (!is_object($GLOBALS['phpgw']->js)) { $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); } $GLOBALS['phpgw']->js->set_onload("copyOptions('$element_id');"); } $GLOBALS['phpgw_info']['flags']['app_header'] = lang('search or select accounts'); $GLOBALS['phpgw']->common->phpgw_header(); $GLOBALS['phpgw']->template->set_var('lang_perm',lang('Groups with permission for %1',lang($app))); $GLOBALS['phpgw']->template->set_var('lang_nonperm',lang('Groups without permission for %1',lang($app))); $link_data = array ( 'menuaction' => 'phpgwapi.uiaccountsel.popup', 'app' => $app, 'group_id' => $group_id, 'element_id' => $element_id, 'single' => $single, 'query_type' => $query_type, ); $app_groups = array(); if ($app != 'admin') { $user_groups = $this->membership($this->account); $app_user = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,$app); for ($i = 0;$i