| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API - Accounts manager - User Interface functions * 4 * Written or modified by RalfBecker@outdoor-training.de * 5 * The original version of the acount-selection popup was written and * 6 * (c) 2003 by Bettina Gille [ceb@phpgroupware.org] * 7 * -------------------------------------------------------------------------* 8 * This library is part of the eGroupWare API * 9 * http://www.egroupware.org * 10 * ------------------------------------------------------------------------ * 11 * This library is free software; you can redistribute it and/or modify it * 12 * under the terms of the GNU Lesser General Public License as published by * 13 * the Free Software Foundation; either version 2.1 of the License, * 14 * or any later version. * 15 * This library is distributed in the hope that it will be useful, but * 16 * WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 18 * See the GNU Lesser General Public License for more details. * 19 * You should have received a copy of the GNU Lesser General Public License * 20 * along with this library; if not, write to the Free Software Foundation, * 21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 22 \**************************************************************************/ 23 /* $Id: class.uiaccountsel.inc.php 20514 2006-03-09 18:00:45Z ralfbecker $ */ 24 25 include_once (EGW_API_INC . '/class.accounts.inc.php'); 26 27 /** 28 * User Interface for account and/or group selection 29 */ 30 31 class uiaccountsel extends accounts 32 { 33 var $public_functions = array( 34 'popup' => True, 35 ); 36 37 function uiaccountsel($account_id = '', $account_type='') 38 { 39 $this->accounts($account_id,$account_type); // call constructor of extended class 40 41 $this->account_selection = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection']; 42 43 if (!is_object($GLOBALS['egw']->html)) 44 { 45 $GLOBALS['egw']->html =& CreateObject('phpgwapi.html'); 46 } 47 $this->html = $GLOBALS['egw']->html; 48 } 49 50 /** 51 * Create an account-selection for a certain range of users 52 * 53 * @param $name string name of the form-element 54 * @param $element_id string id of the form-element, this need to be unique for the whole window !!! 55 * @param $selected array/int user-id or array of user-id's which are already selected 56 * @param $use string 'accounts', 'groups', 'owngroups', 'both' or app-name for all accounts with run-rights. 57 * If an '+' is appended to the app-name, one can also select groups with run-rights for that app. 58 * @param $lines int number of lines for multiselection or 0 for a single selection 59 * (in that case accounts should be an int or contain only 1 user-id) 60 * @param $not int/array user-id or array of user-id's not to display in selection, default False = display all 61 * @param $options additional options (e.g. style) 62 * @param $onchange javascript to execute if the selection changes, eg. to reload the page 63 * @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, 64 * it gets appended to the user-name. Or false if the selectable values for the selectbox are determined by use. 65 * Or a string which gets added as first Option with value=0, eg. lang('all') 66 * @param $nohtml boolean if true, returns an array with the key 'selected' as the selected participants, 67 * and with the key 'participants' as the participants data as would fit in a select. 68 * @return the necessary html 69 */ 70 function selection($name,$element_id,$selected,$use='accounts',$lines=0,$not=False,$options='',$onchange='',$select=False,$nohtml=false) 71 { 72 //echo "<p>uiaccountsel::selection('$name',".print_r($selected,True).",'$use',$lines,$not,'$options','$onchange',".print_r($select,True).")</p>\n"; 73 if (!is_array($selected)) 74 { 75 $selected = $selected ? explode(',',$selected) : array(); 76 } 77 $account_sel = $this->account_selection; 78 $app = False; 79 switch($use) 80 { 81 default: 82 if (substr($use,-1) == '+') 83 { 84 $app = substr($use,0,-1); 85 $use = 'both'; 86 } 87 else 88 { 89 $app = $use; 90 $use = 'accounts'; 91 } 92 break; 93 case 'accounts': 94 case 'both': 95 break; 96 case 'groups': 97 case 'owngroups': 98 $account_sel = 'selectbox'; // groups always use only the selectbox 99 break; 100 } 101 $extra_label = is_string($select) && !empty($select) ? $select : False; 102 switch($account_sel) 103 { 104 case 'popup': 105 $select = $selected; 106 break; 107 case 'primary_group': 108 $select = count($selected) && !isset($selected[0]) ? array_keys($selected) : $selected; 109 $members = $this->member($GLOBALS['egw']->accounts->data['account_primary_group']); 110 if (is_array($members)) 111 { 112 foreach($members as $member) 113 { 114 if (!in_array($member['account_id'],$select)) 115 { 116 $select[] = $member['account_id']; 117 } 118 } 119 } 120 break; 121 case 'selectbox': 122 default: 123 if (!is_array($select)) 124 { 125 $select = $GLOBALS['egw']->accounts->search(array( 126 'type' => $use, 127 'app' => $app, 128 )); 129 } 130 break; 131 } 132 $already_selected = $users = $groups = array(); 133 $use_keys = count($select) && !isset($select[0]); // id's are the keys 134 foreach($select as $key => $val) 135 { 136 $id = $use_keys ? $key : (is_array($val) ? $val['account_id'] : $val); 137 138 if ($not && ($id == $not || is_array($not) && in_array($id,$not))) 139 { 140 continue; // dont display that one 141 } 142 if (in_array($id,$selected)) // show already selected accounts first 143 { 144 $already_selected[$id] = $GLOBALS['egw']->common->grab_owner_name($id); 145 } 146 elseif ($this->get_type($id) == 'u') 147 { 148 $users[$id] = !is_array($val) ? $GLOBALS['egw']->common->grab_owner_name($id) : 149 $GLOBALS['egw']->common->display_fullname( 150 $val['account_lid'],$val['account_firstname'],$val['account_lastname']); 151 } 152 else 153 { 154 $groups[$id] = $GLOBALS['egw']->common->grab_owner_name($id); 155 } 156 } 157 // sort users and groups alphabeticaly and put the groups behind the users 158 uasort($already_selected,strcasecmp); 159 uasort($users,strcasecmp); 160 uasort($groups,strcasecmp); 161 $select = $already_selected + $users + $groups; 162 if (count($selected) && !isset($selected[0])) // id's are the keys 163 { 164 foreach($selected as $id => $val) 165 { 166 if (is_string($val) && isset($users[$id])) // add string to option-label 167 { 168 $users[$id] .= " ($val)"; 169 } 170 } 171 $selected = array_keys($selected); 172 } 173 // add necessary popup trigers 174 $link = $GLOBALS['egw']->link('/index.php',array( 175 'menuaction' => 'phpgwapi.uiaccountsel.popup', 176 'app' => $app, 177 'use' => $use, 178 'element_id' => $element_id, 179 'multiple' => $lines, // single selection (multiple=0), closes after the first selection 180 )); 181 $popup_options = 'width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes'; 182 $app = $GLOBALS['egw_info']['flags']['currentapp']; 183 if ($lines <= 1 && $use != 'groups' && $use != 'owngroups') 184 { 185 if (!$lines) 186 { 187 $options .= ' onchange="if (this.value==\'popup\') '."window.open('$link','uiaccountsel','$popup_options');". 188 ($onchange ? " else { $onchange }" : '' ).'" onclick="if (this.value==\'popup\') '."window.open('$link','uiaccountsel','$popup_options');\""; 189 $select['popup'] = lang('Search').' ...'; 190 } 191 elseif ($onchange) 192 { 193 $options .= ' onchange="if (this.value[0]!=\',\') { '.$onchange.' }"'; 194 } 195 $need_js_popup = True; 196 } 197 elseif ($onchange) 198 { 199 $options .= ' onchange="'.$onchange.'"'; 200 } 201 if ($extra_label) 202 { 203 //in php5 this put's the extra-label at the end: $select = array($extra_label) + $select; 204 $select2 = array($extra_label); 205 $select2 += $select; 206 $select =& $select2; unset($select2); 207 } 208 209 if ($nohtml) 210 { 211 return array( 212 'selected' => $selected, 213 'participants' => $select 214 ); 215 } 216 //echo "<p>html::select('$name',".print_r($selected,True).",".print_r($select,True).",True,'$options')</p>\n"; 217 $html = $this->html->select($name,$selected,$select,True,$options.' id="'.$element_id.'"',$lines > 1 ? $lines : 0); 218 219 if ($lines > 0 && ($this->account_selection == 'popup' || $this->account_selection == 'primary_group')) 220 { 221 $html .= $this->html->submit_button('search','Search',"window.open('$link','uiaccountsel','$popup_options'); return false;",false, 222 ' title="'.$this->html->htmlspecialchars($lines > 1 ? lang('search or select accounts') : lang('search or select multiple accounts')).'"', 223 'users','phpgwapi'); 224 $need_js_popup = True; 225 } 226 if ($lines == 1 && $this->account_selection == 'selectbox') 227 { 228 $html .= '<a href="#" onclick="'."if (selectBox = document.getElementById('$element_id')) { selectBox.size=4; selectBox.multiple=true; } return false;".'">'. 229 $this->html->image('phpgwapi','users',lang('select multiple accounts')).'</a>'; 230 } 231 if($need_js_popup && !$GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed']) 232 { 233 $html .= '<script language="JavaScript"> 234 function addOption(id,label,value,do_onchange) 235 { 236 selectBox = document.getElementById(id); 237 for (i=0; i < selectBox.length; i++) { 238 '.// check existing entries if they're already there and only select them in that case 239 ' if (selectBox.options[i].value == value) { 240 selectBox.options[i].selected = true; 241 break; 242 } 243 '.// check existing entries for an entry starting with a comma, marking a not yet finished multiple selection 244 ' else if (value.slice(0,1) == "," && selectBox.options[i].value.slice(0,1) == ",") { 245 selectBox.options[i].value = value; 246 selectBox.options[i].text = "'.lang('multiple').'"; 247 selectBox.options[i].title = label; 248 selectBox.options[i].selected = true; 249 break; 250 } 251 } 252 if (i >= selectBox.length) { 253 selectBox.options[selectBox.length] = new Option(label,value,false,true); 254 } 255 if (selectBox.onchange && do_onchange) selectBox.onchange(); 256 } 257 </script>'; 258 $GLOBALS['egw_info']['flags']['uiaccountsel']['addOption_installed'] = True; 259 } 260 return $html; 261 } 262 263 function popup() 264 { 265 global $query; // nextmatch requires that !!! 266 267 $app = get_var('app',array('POST','GET')); 268 $use = get_var('use',array('POST','GET')); 269 $group_id = get_var('group_id',array('POST','GET'),$GLOBALS['egw']->accounts->data['account_primary_group']); 270 $element_id = get_var('element_id',array('POST','GET')); 271 $multiple = get_var('multiple',array('POST','GET')); 272 273 $query = get_var('query',array('POST','GET')); 274 $query_type = get_var('query_type',array('POST','GET')); 275 276 $start = (int) get_var('start',array('POST'),0); 277 $order = get_var('order',array('POST','GET'),'account_lid'); 278 $sort = get_var('sort',array('POST','GET'),'ASC'); 279 280 //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"; 281 282 $this->nextmatchs =& CreateObject('phpgwapi.nextmatchs'); 283 284 $GLOBALS['egw']->template->set_root($GLOBALS['egw']->common->get_tpl_dir('phpgwapi')); 285 286 $GLOBALS['egw']->template->set_file(array('accounts_list_t' => 'uiaccountsel.tpl')); 287 $GLOBALS['egw']->template->set_block('accounts_list_t','letter_search','letter_search_cells'); 288 $GLOBALS['egw']->template->set_block('accounts_list_t','group_cal','cal'); 289 $GLOBALS['egw']->template->set_block('accounts_list_t','group_other','other'); 290 $GLOBALS['egw']->template->set_block('accounts_list_t','group_all','all'); 291 292 $GLOBALS['egw']->template->set_block('accounts_list_t','bla_intro','ibla'); 293 $GLOBALS['egw']->template->set_block('accounts_list_t','other_intro','iother'); 294 $GLOBALS['egw']->template->set_block('accounts_list_t','all_intro','iall'); 295 296 $GLOBALS['egw']->template->set_block('accounts_list_t','accounts_list','list'); 297 298 $GLOBALS['egw']->template->set_var('font',$GLOBALS['egw_info']['theme']['font']); 299 $GLOBALS['egw']->template->set_var('lang_search',lang('search')); 300 $GLOBALS['egw']->template->set_var('lang_groups',lang('user groups')); 301 $GLOBALS['egw']->template->set_var('lang_accounts',lang('user accounts')); 302 303 $GLOBALS['egw']->template->set_var('img',$GLOBALS['egw']->common->image('phpgwapi','select')); 304 $GLOBALS['egw']->template->set_var('lang_select_user',lang('Select user')); 305 $GLOBALS['egw']->template->set_var('lang_select_group',lang('Select group')); 306 307 if ($app) // split the groups in the ones with run-rights and without 308 { 309 if ($use == 'both') // groups with run-rights too, eg. calendar 310 { 311 $GLOBALS['egw']->template->fp('ibla','bla_intro',True); 312 } 313 else 314 { 315 $GLOBALS['egw']->template->fp('iother','other_intro',True); 316 } 317 $GLOBALS['egw']->template->fp('iall','all_intro',True); 318 } 319 else // use all groups and account, eg. admin 320 { 321 $GLOBALS['egw']->template->set_var('lang_perm',lang('group name')); 322 $GLOBALS['egw']->template->fp('iother','other_intro',True); 323 } 324 325 if ($multiple >= 1) 326 { 327 if (!is_object($GLOBALS['egw']->js)) 328 { 329 $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript'); 330 } 331 $GLOBALS['egw']->js->set_onload("copyOptions('$element_id');"); 332 } 333 $GLOBALS['egw_info']['flags']['app_header'] = lang('search or select accounts'); 334 $GLOBALS['egw']->common->egw_header(); 335 336 $GLOBALS['egw']->template->set_var('lang_perm',lang('Groups with permission for %1',lang($app))); 337 $GLOBALS['egw']->template->set_var('lang_nonperm',lang('Groups without permission for %1',lang($app))); 338 339 $link_data = array 340 ( 341 'menuaction' => 'phpgwapi.uiaccountsel.popup', 342 'app' => $app, 343 'use' => $use, 344 'group_id' => $group_id, 345 'element_id' => $element_id, 346 'multiple' => $multiple, 347 'query_type' => $query_type, 348 'query' => $query, 349 ); 350 351 // -------------- list header variable template-declaration ------------------------ 352 $GLOBALS['egw']->template->set_var('sort_lid',$this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('LoginID'),$link_data)); 353 $GLOBALS['egw']->template->set_var('sort_firstname',$this->nextmatchs->show_sort_order($sort,'account_firstname',$order,'/index.php',lang('Firstname'),$link_data)); 354 $GLOBALS['egw']->template->set_var('sort_lastname',$this->nextmatchs->show_sort_order($sort,'account_lastname',$order,'/index.php',lang('Lastname'),$link_data)); 355 356 // ------------------------- end header declaration -------------------------------- 357 358 $link_data['sort'] = $sort; 359 $link_data['order'] = $order; 360 361 $GLOBALS['egw']->template->set_var('lang_list_members',lang('List members')); 362 $GLOBALS['egw']->template->set_var('lang_firstname',lang('firstname')); 363 $GLOBALS['egw']->template->set_var('lang_lastname',lang('lastname')); 364 365 if ($app) 366 { 367 $app_groups = $this->split_accounts($app,'groups'); 368 } 369 $all_groups = $this->search(array( 370 'type' => 'groups', 371 )); 372 foreach($all_groups as $group) 373 { 374 $link_data['group_id'] = $group['account_id']; 375 376 $GLOBALS['egw']->template->set_var('onclick',"addOption('$element_id','". 377 $GLOBALS['egw']->common->grab_owner_name($group['account_id'])."','$group[account_id]',".(int)($multiple==1).")". 378 (!$multiple ? '; window.close()' : '')); 379 380 if (!$app || in_array($group['account_id'],$app_groups)) 381 { 382 $GLOBALS['egw']->template->set_var('tr_color',$this->nextmatchs->alternate_row_color($tr_color,True)); 383 $GLOBALS['egw']->template->set_var('link_user_group',$GLOBALS['egw']->link('/index.php',$link_data)); 384 $GLOBALS['egw']->template->set_var('name_user_group',$GLOBALS['egw']->common->grab_owner_name($group['account_id'])); 385 386 if($use == 'both') // allow selection of groups 387 { 388 $GLOBALS['egw']->template->fp('cal','group_cal',True); 389 } 390 else 391 { 392 $GLOBALS['egw']->template->fp('other','group_other',True); 393 } 394 } 395 else 396 { 397 $GLOBALS['egw']->template->set_var('link_all_group',$GLOBALS['egw']->link('/index.php',$link_data)); 398 $GLOBALS['egw']->template->set_var('name_all_group',$GLOBALS['egw']->common->grab_owner_name($group['account_id'])); 399 $GLOBALS['egw']->template->set_var('accountid',$group['account_id']); 400 $GLOBALS['egw']->template->fp('all','group_all',True); 401 } 402 } 403 $link_data['group_id'] = $group_id; // reset it 404 405 // --------------------------------- nextmatch --------------------------- 406 $users = $this->search(array( 407 'type' => $group_id ? $group_id : $use, 408 'app' => $app, 409 'start' => $start, 410 'order' => $order, 411 'sort' => $sort, 412 'query' => $query, 413 'query_type' => $query_type, 414 )); 415 416 $GLOBALS['egw']->template->set_var(array( 417 'left' => $this->nextmatchs->left('/index.php',$start,$this->total,$link_data+array('query'=>$query)), 418 'right' => $this->nextmatchs->right('/index.php',$start,$this->total,$link_data+array('query'=>$query)), 419 'lang_showing' => ($group_id ? $GLOBALS['egw']->common->grab_owner_name($group_id).': ' : ''). 420 ($query ? lang("Search %1 '%2'",lang($this->query_types[$query_type]),$query).': ' : '') 421 .$this->nextmatchs->show_hits($this->total,$start), 422 )); 423 424 // -------------------------- end nextmatch ------------------------------------ 425 426 $GLOBALS['egw']->template->set_var('search_action',$GLOBALS['egw']->link('/index.php',$link_data)); 427 $GLOBALS['egw']->template->set_var('prev_query', $query); 428 $GLOBALS['egw']->template->set_var('search_list',$this->nextmatchs->search(array('query' => $query, 'search_obj' => 1))); 429 $GLOBALS['egw']->template->set_var('lang_firstname', lang("firstname")); 430 $GLOBALS['egw']->template->set_var('lang_lastname', lang("lastname")); 431 432 foreach($users as $user) 433 { 434 $GLOBALS['egw']->template->set_var('tr_color',$this->nextmatchs->alternate_row_color($tr_color,True)); 435 436 // ---------------- template declaration for list records -------------------------- 437 438 $GLOBALS['egw']->template->set_var(array( 439 'lid' => $user['account_lid'], 440 'firstname' => $user['account_firstname'] ? $user['account_firstname'] : ' ', 441 'lastname' => $user['account_lastname'] ? $user['account_lastname'] : ' ', 442 'onclick' => "addOption('$element_id','". 443 $GLOBALS['egw']->common->grab_owner_name($user['account_id'])."','$user[account_id]',".(int)($multiple==1).")". 444 (!$multiple ? '; window.close()' : ''), 445 )); 446 $GLOBALS['egw']->template->fp('list','accounts_list',True); 447 } 448 449 $GLOBALS['egw']->template->set_var('accountsel_icon',$this->html->image('phpgwapi','users-big')); 450 $GLOBALS['egw']->template->set_var('query_type',is_array($this->query_types) ? $this->html->select('query_type',$query_type,$this->query_types) : ''); 451 452 $link_data['query_type'] = 'start'; 453 $letters = lang('alphabet'); 454 $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'); 455 foreach($letters as $letter) 456 { 457 $link_data['query'] = $letter; 458 $GLOBALS['egw']->template->set_var(array( 459 'letter' => $letter, 460 'link' => $GLOBALS['egw']->link('/index.php',$link_data), 461 'class' => $query == $letter && $query_type == 'start' ? 'letter_box_active' : 'letter_box', 462 )); 463 $GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True); 464 } 465 unset($link_data['query']); 466 unset($link_data['query_type']); 467 $GLOBALS['egw']->template->set_var(array( 468 'letter' => lang('all'), 469 'link' => $GLOBALS['egw']->link('/index.php',$link_data), 470 'class' => $query_type != 'start' || !in_array($query,$letters) ? 'letter_box_active' : 'letter_box', 471 )); 472 $GLOBALS['egw']->template->fp('letter_search_cells','letter_search',True); 473 474 $GLOBALS['egw']->template->set_var(array( 475 'lang_selection' => lang('selection'), 476 'lang_close' => lang('close'), 477 'close_action' => 'window.close();', 478 )); 479 480 if ($multiple >= 1) 481 { 482 $GLOBALS['egw']->template->set_var(array( 483 'lang_close' => lang('submit'), 484 'lang_multiple' => lang('multiple'), 485 'close_action' => "oneLineSubmit('$element_id');", 486 )); 487 } 488 489 490 if ($multiple) 491 { 492 $GLOBALS['egw']->template->set_var(array( 493 'selection' => $this->html->select('selected',False,array(),True,' id="uiaccountsel_popup_selection" style="width: 100%;"',13), 494 'remove' => $this->html->submit_button('remove','remove', 495 "removeSelectedOptions('$element_id'); return false;",True,' title="'.lang('Remove selected accounts').'"','delete'), 496 )); 497 } 498 $GLOBALS['egw']->template->pfp('out','accounts_list_t',True); 499 500 $GLOBALS['egw']->common->egw_footer(); 501 } 502 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |