[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Accounts manager shared functions * |
---|
| 4 | * Written by Joseph Engo <jengo@phpgroupware.org> * |
---|
| 5 | * and Bettina Gille [ceb@phpgroupware.org] * |
---|
| 6 | * shared functions for other account repository managers * |
---|
| 7 | * Copyright (C) 2000 - 2002 Joseph Engo * |
---|
| 8 | * Copyright (C) 2003 Joseph Engo, Bettina Gille * |
---|
| 9 | * -------------------------------------------------------------------------* |
---|
| 10 | * This library is part of the eGroupWare API * |
---|
| 11 | * http://www.egroupware.org * |
---|
| 12 | * ------------------------------------------------------------------------ * |
---|
| 13 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 14 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 15 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 16 | * or any later version. * |
---|
| 17 | * This library is distributed in the hope that it will be useful, but * |
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 20 | * See the GNU Lesser General Public License for more details. * |
---|
| 21 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 22 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 23 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 24 | \**************************************************************************/ |
---|
| 25 | |
---|
| 26 | if (empty($GLOBALS['phpgw_info']['server']['account_repository'])) |
---|
| 27 | { |
---|
| 28 | if (!empty($GLOBALS['phpgw_info']['server']['auth_type'])) |
---|
| 29 | { |
---|
| 30 | $GLOBALS['phpgw_info']['server']['account_repository'] = $GLOBALS['phpgw_info']['server']['auth_type']; |
---|
| 31 | } |
---|
| 32 | else |
---|
| 33 | { |
---|
| 34 | $GLOBALS['phpgw_info']['server']['account_repository'] = 'sql'; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | include_once(PHPGW_API_INC . '/class.accounts_' . $GLOBALS['phpgw_info']['server']['account_repository'] . '.inc.php'); |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | Dont know where to put this (seek3r) |
---|
| 41 | This is where it belongs (jengo) |
---|
| 42 | This is where it ended up (milosch) |
---|
| 43 | Moved again at least temporarily since sql and ldap use it. |
---|
| 44 | */ |
---|
| 45 | $GLOBALS['phpgw_info']['server']['global_denied_users'] = array( |
---|
| 46 | 'root' => True, 'bin' => True, 'daemon' => True, |
---|
| 47 | 'adm' => True, 'lp' => True, 'sync' => True, |
---|
| 48 | 'shutdown' => True, 'halt' => True, 'ldap' => True, |
---|
| 49 | 'mail' => True, 'news' => True, 'uucp' => True, |
---|
| 50 | 'operator' => True, 'games' => True, 'gopher' => True, |
---|
| 51 | 'nobody' => True, 'xfs' => True, 'pgsql' => True, |
---|
| 52 | 'mysql' => True, 'postgres' => True, 'oracle' => True, |
---|
| 53 | 'ftp' => True, 'gdm' => True, 'named' => True, |
---|
| 54 | 'alias' => True, 'web' => True, 'sweep' => True, |
---|
| 55 | 'cvs' => True, 'qmaild' => True, 'qmaill' => True, |
---|
| 56 | 'qmaillog' => True, 'qmailp' => True, 'qmailq' => True, |
---|
| 57 | 'qmailr' => True, 'qmails' => True, 'rpc' => True, |
---|
| 58 | 'rpcuser' => True, 'amanda' => True, 'apache' => True, |
---|
| 59 | 'pvm' => True, 'squid' => True, 'ident' => True, |
---|
| 60 | 'nscd' => True, 'mailnull' => True, 'cyrus' => True, |
---|
| 61 | 'backup' => True |
---|
| 62 | ); |
---|
| 63 | |
---|
| 64 | $GLOBALS['phpgw_info']['server']['global_denied_groups'] = array( |
---|
| 65 | 'root' => True, 'bin' => True, 'daemon' => True, |
---|
| 66 | 'sys' => True, 'adm' => True, 'tty' => True, |
---|
| 67 | 'disk' => True, 'lp' => True, 'mem' => True, |
---|
| 68 | 'kmem' => True, 'wheel' => True, 'mail' => True, |
---|
| 69 | 'uucp' => True, 'man' => True, 'games' => True, |
---|
| 70 | 'dip' => True, 'ftp' => True, 'nobody' => True, |
---|
| 71 | 'floppy' => True, 'xfs' => True, 'console' => True, |
---|
| 72 | 'utmp' => True, 'pppusers' => True, 'popusers' => True, |
---|
| 73 | 'slipusers' => True, 'slocate' => True, 'mysql' => True, |
---|
| 74 | 'dnstools' => True, 'web' => True, 'named' => True, |
---|
| 75 | 'dba' => True, 'oinstall' => True, 'oracle' => True, |
---|
| 76 | 'gdm' => True, 'sweep' => True, 'cvs' => True, |
---|
| 77 | 'postgres' => True, 'qmail' => True, 'nofiles' => True, |
---|
| 78 | 'ldap' => True, 'backup' => True |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | /*! |
---|
| 82 | @class_start accounts |
---|
| 83 | @abstract Class for handling user and group accounts |
---|
| 84 | */ |
---|
| 85 | |
---|
| 86 | class accounts extends accounts_ |
---|
| 87 | { |
---|
| 88 | var $memberships = array(); |
---|
| 89 | var $members = array(); |
---|
| 90 | var $xmlrpc_methods = array(); |
---|
| 91 | // enables the session-cache |
---|
| 92 | var $use_session_cache = True; |
---|
| 93 | |
---|
| 94 | /**************************************************************************\ |
---|
| 95 | * Standard constructor for setting $this->account_id * |
---|
| 96 | * This constructor sets the account id, if string is sent, converts to id * |
---|
| 97 | * I might move this to the accounts_shared if it stays around * |
---|
| 98 | \**************************************************************************/ |
---|
| 99 | function accounts($account_id = '', $account_type='') |
---|
| 100 | { |
---|
| 101 | // enable the caching in the session onyl for ldap |
---|
| 102 | $this->use_session_cache = $GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap'; |
---|
| 103 | |
---|
| 104 | $this->db = $GLOBALS['phpgw']->db; |
---|
| 105 | |
---|
| 106 | if($account_id != '') |
---|
| 107 | { |
---|
| 108 | $this->account_id = get_account_id($account_id); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if($account_type != '') |
---|
| 112 | { |
---|
| 113 | $this->account_type = $account_type; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | $this->query_types = array( |
---|
| 117 | 'all' => 'all fields', |
---|
| 118 | 'firstname' => 'firstname', |
---|
| 119 | 'lastname' => 'lastname', |
---|
| 120 | 'lid' => 'LoginID', |
---|
| 121 | 'email' => 'email', |
---|
| 122 | 'start' => 'start with', |
---|
| 123 | 'exact' => 'exact', |
---|
| 124 | ); |
---|
| 125 | $this->accounts_(); // call constructor of extended class |
---|
| 126 | |
---|
| 127 | $this->xmlrpc_methods[] = array( |
---|
| 128 | 'name' => 'get_list', |
---|
| 129 | 'description' => 'Returns a list of accounts and/or groups' |
---|
| 130 | ); |
---|
| 131 | $this->xmlrpc_methods[] = array( |
---|
| 132 | 'name' => 'name2id', |
---|
| 133 | 'description' => 'Cross reference account_lid with account_id' |
---|
| 134 | ); |
---|
| 135 | $this->xmlrpc_methods[] = array( |
---|
| 136 | 'name' => 'id2name', |
---|
| 137 | 'description' => 'Cross reference account_id with account_lid' |
---|
| 138 | ); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | * Sets up the account-data cache |
---|
| 143 | * |
---|
| 144 | * The cache is shared between all instances of the account-class and it can be save in the session, |
---|
| 145 | * if use_session_cache is set to True |
---|
| 146 | */ |
---|
| 147 | function setup_cache() |
---|
| 148 | { |
---|
| 149 | if ($this->use_session_cache && // are we supposed to use a session-cache |
---|
| 150 | !@$GLOBALS['phpgw_info']['accounts']['session_cache_setup'] && // is it already setup |
---|
| 151 | // is the account-class ready (startup !) |
---|
| 152 | is_object($GLOBALS['phpgw']->session) && $GLOBALS['phpgw']->session->account_id) |
---|
| 153 | { |
---|
| 154 | // setting up the session-cache |
---|
| 155 | $GLOBALS['phpgw_info']['accounts']['cache'] = $GLOBALS['phpgw']->session->appsession('accounts_cache','phpgwapi'); |
---|
| 156 | $GLOBALS['phpgw_info']['accounts']['session_cache_setup'] = True; |
---|
| 157 | //echo "accounts::setup_cache() cache=<pre>".print_r($GLOBALS['phpgw_info']['accounts']['cache'],True)."</pre>\n"; |
---|
| 158 | } |
---|
| 159 | if (!isset($this->cache)) |
---|
| 160 | { |
---|
| 161 | $this->cache = &$GLOBALS['phpgw_info']['accounts']['cache']; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | * Saves the account-data cache in the session |
---|
| 167 | * |
---|
| 168 | * Gets called from common::phpgw_final() |
---|
| 169 | */ |
---|
| 170 | function save_session_cache() |
---|
| 171 | { |
---|
| 172 | if ($this->use_session_cache && // are we supposed to use a session-cache |
---|
| 173 | $GLOBALS['phpgw_info']['accounts']['session_cache_setup'] && // is it already setup |
---|
| 174 | // is the account-class ready (startup !) |
---|
| 175 | is_object($GLOBALS['phpgw']->session)) |
---|
| 176 | { |
---|
| 177 | $GLOBALS['phpgw']->session->appsession('accounts_cache','phpgwapi',$GLOBALS['phpgw_info']['accounts']['cache']); |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | * Searches / lists accounts: users and/or groups |
---|
| 183 | * |
---|
| 184 | * @param $param['type'] string/int 'accounts', 'groups', 'owngroups' (groups the user is a member of), 'both' |
---|
| 185 | * or integer group-id for a list of members of that group |
---|
| 186 | * @param $param['start'] int first account to return (returns offset or max_matches entries) or all if not set |
---|
| 187 | * @param $param['sort'] string column to sort after, default account_lid if unset |
---|
| 188 | * @param $param['order'] string 'ASC' or 'DESC', default 'DESC' if not set |
---|
| 189 | * @param $param['query'] string to search for, no search if unset or empty |
---|
| 190 | * @param $param['query_type'] string: |
---|
| 191 | * 'all' - query all fields for containing $param[query] |
---|
| 192 | * 'start' - query all fields starting with $param[query] |
---|
| 193 | * 'exact' - query all fields for exact $param[query] |
---|
| 194 | * 'lid','firstname','lastname','email' - query only the given field for containing $param[query] |
---|
| 195 | * @param $param['app'] string with an app-name, to limit result on accounts with run-right for that app |
---|
| 196 | * @param $param['offset'] int - number of matches to return if start given, default use the value in the prefs |
---|
| 197 | * @return array with uid / data pairs, data is an array with account_id, account_lid, account_firstname, |
---|
| 198 | * account_lastname, person_id (id of the linked addressbook entry), account_status, account_expires, account_primary_group |
---|
| 199 | */ |
---|
| 200 | function search($param) |
---|
| 201 | { |
---|
| 202 | //echo "<p>accounts::search(".print_r($param,True).")</p>\n"; |
---|
| 203 | $this->setup_cache(); |
---|
| 204 | $account_search = &$this->cache['account_search']; |
---|
| 205 | |
---|
| 206 | $serial = serialize($param); |
---|
| 207 | |
---|
| 208 | if (isset($account_search[$serial])) |
---|
| 209 | { |
---|
| 210 | $this->total = $account_search[$serial]['total']; |
---|
| 211 | } |
---|
| 212 | elseif (function_exists('accounts_::search')) // implements its on search function ==> use it |
---|
| 213 | { |
---|
| 214 | $account_search[$serial]['data'] = accounts_::search($param); |
---|
| 215 | $account_search[$serial]['total'] = $this->total; |
---|
| 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
| 219 | $serial2 = $serial; |
---|
| 220 | if (is_numeric($param['type']) || $param['app'] || $param['type'] == 'owngroups') // do we need to limit the search on a group or app? |
---|
| 221 | { |
---|
| 222 | $app = $param['app']; |
---|
| 223 | unset($param['app']); |
---|
| 224 | if (is_numeric($param['type'])) |
---|
| 225 | { |
---|
| 226 | $group = (int) $param['type']; |
---|
| 227 | $param['type'] = 'accounts'; |
---|
| 228 | } |
---|
| 229 | elseif ($param['type'] == 'owngroups') |
---|
| 230 | { |
---|
| 231 | $group = -1; |
---|
| 232 | $param['type'] = 'groups'; |
---|
| 233 | } |
---|
| 234 | $start = $param['start']; |
---|
| 235 | unset($param['start']); |
---|
| 236 | $serial2 = serialize($param); |
---|
| 237 | } |
---|
| 238 | if (!isset($account_search[$serial2])) // check if we already did this general search |
---|
| 239 | { |
---|
| 240 | $account_search[$serial2]['data'] = array(); |
---|
| 241 | $accounts = accounts_::get_list($param['type'],$param['start'],$param['sort'],$param['order'],$param['query'],$param['offset'],$param['query_type']); |
---|
| 242 | if (!$accounts) $accounts = array(); |
---|
| 243 | foreach($accounts as $data) |
---|
| 244 | { |
---|
| 245 | $account_search[$serial2]['data'][$data['account_id']] = $data; |
---|
| 246 | } |
---|
| 247 | $account_search[$serial2]['total'] = $this->total; |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | $this->total = $account_search[$serial2]['total']; |
---|
| 252 | } |
---|
| 253 | //echo "accounts_::get_list($param[type],$param[start],$param[sort],$param[order],$param[query],$param[offset],$param[query_type]) returned<pre>".print_r($account_search[$serial2],True)."</pre>\n"; |
---|
| 254 | if ($app || $group) // limit the search on accounts with run-rights for app or a group |
---|
| 255 | { |
---|
| 256 | $valid = array(); |
---|
| 257 | if ($app) |
---|
| 258 | { |
---|
| 259 | $valid = $this->split_accounts($app,$param['type'] == 'both' ? 'merge' : $param['type']); |
---|
| 260 | } |
---|
| 261 | if ($group) |
---|
| 262 | { |
---|
| 263 | $members = $group > 0 ? $GLOBALS['phpgw']->acl->get_ids_for_location($group, 1, 'phpgw_group') : |
---|
| 264 | $GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1,$GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 265 | if (!$members) $members = array(); |
---|
| 266 | $valid = !$app ? $members : array_intersect($valid,$members); // use the intersection |
---|
| 267 | } |
---|
| 268 | //echo "<p>limiting result to app='app' and/or group=$group valid-ids=".print_r($valid,true)."</p>\n"; |
---|
| 269 | $offset = $param['offset'] ? $param['offset'] : $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; |
---|
| 270 | $stop = $start + $offset; |
---|
| 271 | $n = 0; |
---|
| 272 | $account_search[$serial]['data'] = array(); |
---|
| 273 | foreach ($account_search[$serial2]['data'] as $id => $data) |
---|
| 274 | { |
---|
| 275 | if (!in_array($id,$valid)) |
---|
| 276 | { |
---|
| 277 | $this->total--; |
---|
| 278 | continue; |
---|
| 279 | } |
---|
| 280 | // now we have a valid entry |
---|
| 281 | if (!is_int($start) || $start <= $n && $n < $stop) |
---|
| 282 | { |
---|
| 283 | $account_search[$serial]['data'][$id] = $data; |
---|
| 284 | } |
---|
| 285 | $n++; |
---|
| 286 | } |
---|
| 287 | $account_search[$serial]['total'] = $this->total; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | //echo "<p>accounts::search('$serial')=<pre>".print_r($account_search[$serial]['data'],True).")</pre>\n"; |
---|
| 291 | return $account_search[$serial]['data']; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='') |
---|
| 296 | { |
---|
| 297 | //echo "<p>accounts::get_list(".print_r($_type,True).",start='$start',sort='$sort',order='$order',query='$query',offset='$offset')</p>\n"; |
---|
| 298 | $this->setup_cache(); |
---|
| 299 | $account_list = &$this->cache['account_list']; |
---|
| 300 | |
---|
| 301 | // For XML-RPC |
---|
| 302 | if (is_array($_type)) |
---|
| 303 | { |
---|
| 304 | $p = $_type; |
---|
| 305 | $_type = $p['type']; |
---|
| 306 | $start = $p['start']; |
---|
| 307 | $order = $p['order']; |
---|
| 308 | $query = $p['query']; |
---|
| 309 | $offset = $p['offset']; |
---|
| 310 | $query_type = $p['query_type']; |
---|
| 311 | } |
---|
| 312 | else |
---|
| 313 | { |
---|
| 314 | $p = array( |
---|
| 315 | 'type' => $_type, |
---|
| 316 | 'start' => $start, |
---|
| 317 | 'order' => $order, |
---|
| 318 | 'query' => $query, |
---|
| 319 | 'offset' => $offset, |
---|
| 320 | 'query_type' => $query_type , |
---|
| 321 | ); |
---|
| 322 | } |
---|
| 323 | $serial = serialize($p); |
---|
| 324 | |
---|
| 325 | if (isset($account_list[$serial])) |
---|
| 326 | { |
---|
| 327 | $this->total = $account_list[$serial]['total']; |
---|
| 328 | } |
---|
| 329 | else |
---|
| 330 | { |
---|
| 331 | $account_list[$serial]['data'] = accounts_::get_list($_type,$start,$sort,$order,$query,$offset,$query_type); |
---|
| 332 | $account_list[$serial]['total'] = $this->total; |
---|
| 333 | } |
---|
| 334 | return $account_list[$serial]['data']; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | function is_expired() |
---|
| 338 | { |
---|
| 339 | if ($this->data['expires'] != -1 && $this->data['expires'] < time()) |
---|
| 340 | { |
---|
| 341 | return True; |
---|
| 342 | } |
---|
| 343 | else |
---|
| 344 | { |
---|
| 345 | return False; |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | /** |
---|
| 350 | * Invalidate the cache (or parts of it) after change in $account_id |
---|
| 351 | * |
---|
| 352 | * Atm simplest approach - delete it all ;-) |
---|
| 353 | */ |
---|
| 354 | function cache_invalidate($account_id) |
---|
| 355 | { |
---|
| 356 | //echo "<p>accounts::cache_invalidate($account_id)</p>\n"; |
---|
| 357 | $GLOBALS['phpgw_info']['accounts']['cache'] = array(); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | function save_repository() |
---|
| 361 | { |
---|
| 362 | $this->cache_invalidate($this->account_id); |
---|
| 363 | accounts_::save_repository(); |
---|
| 364 | } |
---|
| 365 | |
---|
[5141] | 366 | function delete($accountid = '') |
---|
[2] | 367 | { |
---|
| 368 | $this->cache_invalidate($accountid); |
---|
[5141] | 369 | parent::delete($accountid); |
---|
[2] | 370 | |
---|
| 371 | // delete all acl_entries belonging to that user or group |
---|
| 372 | $GLOBALS['phpgw']->acl->delete_account($accountid); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | function create($account_info,$default_prefs=True) |
---|
| 376 | { |
---|
| 377 | $account_id = accounts_::create($account_info,$default_prefs); |
---|
| 378 | $this->cache_invalidate($account_id); |
---|
| 379 | |
---|
| 380 | return $account_id; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | function read_repository() |
---|
| 384 | { |
---|
| 385 | $this->setup_cache(); |
---|
| 386 | $account_data = &$this->cache['account_data']; |
---|
| 387 | |
---|
| 388 | if (isset($account_data[$this->account_id])) |
---|
| 389 | { |
---|
| 390 | return $this->data = $account_data[$this->account_id]; |
---|
| 391 | } |
---|
| 392 | return $account_data[$this->account_id] = accounts_::read_repository(); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | function read() |
---|
| 396 | { |
---|
| 397 | if (count($this->data) == 0) |
---|
| 398 | { |
---|
| 399 | $this->read_repository(); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | reset($this->data); |
---|
| 403 | return $this->data; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | function update_data($data) |
---|
| 407 | { |
---|
| 408 | reset($data); |
---|
| 409 | $this->data = Array(); |
---|
| 410 | $this->data = $data; |
---|
| 411 | |
---|
| 412 | reset($this->data); |
---|
| 413 | return $this->data; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | function membership($accountid = '') |
---|
| 417 | { |
---|
| 418 | $this->setup_cache(); |
---|
| 419 | $membership_list = &$this->cache['membership_list']; |
---|
| 420 | |
---|
| 421 | $account_id = get_account_id($accountid); |
---|
| 422 | |
---|
| 423 | if (isset($membership_list[$account_id])) |
---|
| 424 | { |
---|
| 425 | return $membership_list[$account_id]; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | $security_equals = Array(); |
---|
| 429 | $security_equals = $GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id); |
---|
| 430 | |
---|
| 431 | if ($security_equals == False) |
---|
| 432 | { |
---|
| 433 | return $membership_list[$account_id] = False; |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | $this->memberships = Array(); |
---|
| 437 | |
---|
| 438 | for ($idx=0; $idx<count($security_equals); $idx++) |
---|
| 439 | { |
---|
| 440 | $groups = (int)$security_equals[$idx]; |
---|
[394] | 441 | |
---|
| 442 | /* jakjr: expressoLivre does not need the cn of each group */ |
---|
| 443 | //$this->memberships[] = Array('account_id' => $groups, 'account_name' => $this->id2name($groups)); |
---|
| 444 | |
---|
| 445 | $this->memberships[] = Array('account_id' => $groups, 'account_name' => $groups); |
---|
[2] | 446 | } |
---|
| 447 | |
---|
| 448 | return $membership_list[$account_id] = $this->memberships; |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | function member($accountid = '') |
---|
| 452 | { |
---|
| 453 | $account_id = get_account_id($accountid); |
---|
| 454 | |
---|
| 455 | $security_equals = Array(); |
---|
| 456 | $acl = CreateObject('phpgwapi.acl'); |
---|
| 457 | $security_equals = $acl->get_ids_for_location($account_id, 1, 'phpgw_group'); |
---|
| 458 | unset($acl); |
---|
| 459 | |
---|
| 460 | if ($security_equals == False) |
---|
| 461 | { |
---|
| 462 | return False; |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | for ($idx=0; $idx<count($security_equals); $idx++) |
---|
| 466 | { |
---|
| 467 | $name = $this->id2name((int)$security_equals[$idx]); |
---|
| 468 | $this->members[] = Array('account_id' => (int)$security_equals[$idx], 'account_name' => $name); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | return $this->members; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /*! |
---|
| 475 | @function get_nextid |
---|
| 476 | @abstract Using the common functions next_id and last_id, find the next available account_id |
---|
| 477 | @param $account_type (optional, default to 'u') |
---|
| 478 | */ |
---|
| 479 | // NOTE: to my knowledge this is not used any more RalfBecker 2004/06/15 |
---|
| 480 | function get_nextid($account_type='u') |
---|
| 481 | { |
---|
| 482 | $min = $GLOBALS['phpgw_info']['server']['account_min_id'] ? $GLOBALS['phpgw_info']['server']['account_min_id'] : 0; |
---|
| 483 | $max = $GLOBALS['phpgw_info']['server']['account_max_id'] ? $GLOBALS['phpgw_info']['server']['account_max_id'] : 0; |
---|
| 484 | |
---|
| 485 | if ($account_type == 'g') |
---|
| 486 | { |
---|
| 487 | $type = 'groups'; |
---|
| 488 | } |
---|
| 489 | else |
---|
| 490 | { |
---|
| 491 | $type = 'accounts'; |
---|
| 492 | } |
---|
| 493 | $nextid = (int)$GLOBALS['phpgw']->common->last_id($type,$min,$max); |
---|
| 494 | |
---|
| 495 | /* Loop until we find a free id */ |
---|
| 496 | $free = 0; |
---|
| 497 | while (!$free) |
---|
| 498 | { |
---|
| 499 | $account_lid = ''; |
---|
| 500 | //echo '<br>calling search for id: '.$nextid; |
---|
| 501 | if ($this->exists($nextid)) |
---|
| 502 | { |
---|
| 503 | $nextid = (int)$GLOBALS['phpgw']->common->next_id($type,$min,$max); |
---|
| 504 | } |
---|
| 505 | else |
---|
| 506 | { |
---|
| 507 | $account_lid = $this->id2name($nextid); |
---|
| 508 | /* echo '<br>calling search for lid: '.$account_lid . '(from account_id=' . $nextid . ')'; */ |
---|
| 509 | if ($this->exists($account_lid)) |
---|
| 510 | { |
---|
| 511 | $nextid = (int)$GLOBALS['phpgw']->common->next_id($type,$min,$max); |
---|
| 512 | } |
---|
| 513 | else |
---|
| 514 | { |
---|
| 515 | $free = True; |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | if ($GLOBALS['phpgw_info']['server']['account_max_id'] && |
---|
| 520 | ($nextid > $GLOBALS['phpgw_info']['server']['account_max_id'])) |
---|
| 521 | { |
---|
| 522 | return False; |
---|
| 523 | } |
---|
| 524 | /* echo '<br>using'.$nextid;exit; */ |
---|
| 525 | return $nextid; |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | |
---|
| 529 | /** |
---|
| 530 | * splits users and groups from a array of id's or the accounts with run-rights for a given app-name |
---|
| 531 | * |
---|
| 532 | * @param $app_users array of user-id's or app-name (if you use app-name the result gets cached!) |
---|
| 533 | * @param $use string what should be returned only an array with id's of either 'accounts' or 'groups'. |
---|
| 534 | * Or an array with arrays for 'both' under the keys 'groups' and 'accounts' or 'merge' for accounts |
---|
| 535 | * and groups merged into one array |
---|
| 536 | * @return see $use |
---|
| 537 | */ |
---|
| 538 | function split_accounts($app_users,$use='both') |
---|
| 539 | { |
---|
| 540 | if (!is_array($app_users)) |
---|
| 541 | { |
---|
| 542 | $this->setup_cache(); |
---|
| 543 | $cache = &$this->cache['account_split'][$app_user]; |
---|
| 544 | |
---|
| 545 | if (is_array($cache)) |
---|
| 546 | { |
---|
| 547 | return $cache; |
---|
| 548 | } |
---|
| 549 | $app_users = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,$app_users); |
---|
| 550 | } |
---|
| 551 | $accounts = array( |
---|
| 552 | 'accounts' => array(), |
---|
| 553 | 'groups' => array(), |
---|
| 554 | ); |
---|
| 555 | foreach($app_users as $id) |
---|
| 556 | { |
---|
| 557 | $type = $GLOBALS['phpgw']->accounts->get_type($id); |
---|
| 558 | if($type == 'g') |
---|
| 559 | { |
---|
| 560 | $accounts['groups'][$id] = $id; |
---|
| 561 | foreach((array)$GLOBALS['phpgw']->acl->get_ids_for_location($id,1,'phpgw_group') as $id) |
---|
| 562 | { |
---|
| 563 | $accounts['accounts'][$id] = $id; |
---|
| 564 | } |
---|
| 565 | } |
---|
| 566 | else |
---|
| 567 | { |
---|
| 568 | $accounts['accounts'][$id] = $id; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | // not sure why they need to be sorted, but we need to remove the keys anyway |
---|
| 573 | sort($accounts['groups']); |
---|
| 574 | sort($accounts['accounts']); |
---|
| 575 | |
---|
| 576 | if (isset($cache)) |
---|
| 577 | { |
---|
| 578 | $cache = $accounts; |
---|
| 579 | } |
---|
| 580 | //echo "<p>accounts::split_accounts(".print_r($app_users,True).",'$use') = <pre>".print_r($accounts,True)."</pre>\n"; |
---|
| 581 | |
---|
| 582 | switch($use) |
---|
| 583 | { |
---|
| 584 | case 'both': |
---|
| 585 | return $accounts; |
---|
| 586 | case 'groups': |
---|
| 587 | return $accounts['groups']; |
---|
| 588 | case 'accounts': |
---|
| 589 | return $accounts['accounts']; |
---|
| 590 | case 'merge': |
---|
| 591 | return array_merge($accounts['accounts'],$accounts['groups']); |
---|
| 592 | } |
---|
| 593 | return False; |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | /** |
---|
| 597 | * phpgw compatibility function, better use split_accounts |
---|
| 598 | */ |
---|
| 599 | function return_members($accounts) |
---|
| 600 | { |
---|
| 601 | $arr = $this->split_accounts($accounts); |
---|
| 602 | |
---|
| 603 | return array( |
---|
| 604 | 'users' => $arr['accounts'], |
---|
| 605 | 'groups' => $arr['groups'], |
---|
| 606 | ); |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | function name2id($name,$which='account_lid') |
---|
| 610 | { |
---|
| 611 | $this->setup_cache(); |
---|
| 612 | $name_list = &$this->cache['name_list']; |
---|
| 613 | |
---|
| 614 | if(@isset($name_list[$which][$name]) && $name_list[$which][$name]) |
---|
| 615 | { |
---|
| 616 | return $name_list[$which][$name]; |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | /* Don't bother searching for empty account_lid */ |
---|
| 620 | if(empty($name)) |
---|
| 621 | { |
---|
| 622 | return False; |
---|
| 623 | } |
---|
| 624 | return $name_list[$which][$name] = accounts_::name2id($name,$which); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | function id2name($account_id,$which='account_lid') |
---|
| 628 | { |
---|
| 629 | $this->setup_cache(); |
---|
| 630 | $id_list = &$this->cache['id_list']; |
---|
| 631 | |
---|
| 632 | if (! $account_id) |
---|
| 633 | { |
---|
| 634 | return False; |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | if($id_list[$account_id][$which]) |
---|
| 638 | { |
---|
| 639 | return $id_list[$account_id][$which]; |
---|
| 640 | } |
---|
| 641 | return $id_list[$account_id][$which] = accounts_::id2name($account_id,$which); |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | function get_type($accountid) |
---|
| 645 | { |
---|
| 646 | $this->setup_cache(); |
---|
| 647 | $account_type = &$this->cache['account_type']; |
---|
| 648 | |
---|
| 649 | $account_id = get_account_id($accountid); |
---|
| 650 | |
---|
| 651 | if (isset($this->account_type) && $account_id == $this->account_id) |
---|
| 652 | { |
---|
| 653 | return $this->account_type; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | if(@isset($account_type[$account_id]) && @$account_type[$account_id]) |
---|
| 657 | { |
---|
| 658 | return $account_type[$account_id]; |
---|
| 659 | } |
---|
| 660 | elseif($account_id == '') |
---|
| 661 | { |
---|
| 662 | return False; |
---|
| 663 | } |
---|
| 664 | return $account_type[$account_id] = accounts_::get_type($account_id); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | function get_account_name($accountid,&$lid,&$fname,&$lname) |
---|
| 668 | { |
---|
| 669 | $this->setup_cache(); |
---|
| 670 | $account_name = &$this->cache['account_name']; |
---|
| 671 | |
---|
| 672 | $account_id = get_account_id($accountid); |
---|
| 673 | if(isset($account_name[$account_id])) |
---|
| 674 | { |
---|
| 675 | $lid = $account_name[$account_id]['lid']; |
---|
| 676 | $fname = $account_name[$account_id]['fname']; |
---|
| 677 | $lname = $account_name[$account_id]['lname']; |
---|
| 678 | return $account_name[$account_id] !== False; |
---|
| 679 | } |
---|
| 680 | $Ok = accounts_::get_account_name($accountid,$lid,$fname,$lname); |
---|
| 681 | |
---|
| 682 | $account_name[$account_id] = array( |
---|
| 683 | 'lid' => $lid, |
---|
| 684 | 'fname' => $fname, |
---|
| 685 | 'lname' => $lname, |
---|
| 686 | ); |
---|
| 687 | return $Ok; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | function get_account_data($account_id) |
---|
| 691 | { |
---|
| 692 | $this->account_id = $account_id; |
---|
| 693 | $this->read_repository(); |
---|
| 694 | |
---|
| 695 | $data[$this->data['account_id']]['lid'] = $this->data['account_lid']; |
---|
| 696 | $data[$this->data['account_id']]['firstname'] = $this->data['firstname']; |
---|
| 697 | $data[$this->data['account_id']]['lastname'] = $this->data['lastname']; |
---|
| 698 | $data[$this->data['account_id']]['fullname'] = $this->data['fullname']; |
---|
| 699 | $data[$this->data['account_id']]['type'] = $this->data['account_type']; |
---|
| 700 | |
---|
| 701 | return $data; |
---|
| 702 | } |
---|
| 703 | } |
---|