2001-02-06 21:13:06 +01:00
|
|
|
<?php
|
2001-03-10 00:21:52 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Accounts manager shared functions *
|
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* shared functions for other account repository managers *
|
|
|
|
* Copyright (C) 2000, 2001 Joseph Engo *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class accounts extends accounts_
|
|
|
|
{
|
2001-03-19 21:25:04 +01:00
|
|
|
var $memberships = Array();
|
|
|
|
var $members = Array();
|
|
|
|
|
2001-03-10 00:21:52 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* Standard constructor for setting $this->account_id *
|
|
|
|
* This constructor sets the account id, if string is sent, converts to id *
|
|
|
|
* I might move this to the accounts_shared if it stays around *
|
|
|
|
\**************************************************************************/
|
2001-03-19 21:25:04 +01:00
|
|
|
function accounts($account_id = '')
|
2001-03-10 00:21:52 +01:00
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$this->db = $GLOBALS['phpgw']->db;
|
2001-03-10 00:21:52 +01:00
|
|
|
|
2001-03-21 07:05:44 +01:00
|
|
|
if($account_id != '')
|
|
|
|
{
|
|
|
|
$this->account_id = get_account_id($account_id);
|
|
|
|
}
|
2001-09-02 15:08:50 +02:00
|
|
|
$this->user_context = $GLOBALS['phpgw_info']['server']['ldap_context'];
|
|
|
|
$this->group_context = $GLOBALS['phpgw_info']['server']['ldap_group_context'];
|
2001-03-10 00:21:52 +01:00
|
|
|
}
|
|
|
|
|
2001-06-10 11:43:11 +02:00
|
|
|
function is_expired()
|
|
|
|
{
|
|
|
|
if ($this->data['expires'] != -1 && $this->data['expires'] < time())
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-10 00:21:52 +01:00
|
|
|
function read()
|
|
|
|
{
|
|
|
|
if (count($this->data) == 0)
|
|
|
|
{
|
|
|
|
$this->read_repository();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_data($data)
|
|
|
|
{
|
|
|
|
reset($data);
|
|
|
|
$this->data = Array();
|
|
|
|
$this->data = $data;
|
|
|
|
|
|
|
|
reset($this->data);
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
2001-08-04 16:26:10 +02:00
|
|
|
function membership($accountid = '')
|
2001-03-10 00:21:52 +01:00
|
|
|
{
|
2001-03-19 21:25:04 +01:00
|
|
|
$account_id = get_account_id($accountid);
|
2001-03-10 00:21:52 +01:00
|
|
|
|
|
|
|
$security_equals = Array();
|
2001-09-02 01:42:16 +02:00
|
|
|
$security_equals = $GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1, $account_id);
|
2001-03-10 00:21:52 +01:00
|
|
|
|
|
|
|
if ($security_equals == False)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-03-18 17:29:05 +01:00
|
|
|
$this->memberships = Array();
|
|
|
|
|
2001-03-10 00:21:52 +01:00
|
|
|
for ($idx=0; $idx<count($security_equals); $idx++)
|
|
|
|
{
|
2001-03-19 21:55:48 +01:00
|
|
|
$groups = intval($security_equals[$idx]);
|
|
|
|
$this->memberships[] = Array('account_id' => $groups, 'account_name' => $this->id2name($groups));
|
2001-03-10 00:21:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->memberships;
|
|
|
|
}
|
|
|
|
|
2001-03-19 21:25:04 +01:00
|
|
|
function members ($accountid = '')
|
2001-03-10 00:21:52 +01:00
|
|
|
{
|
2001-03-19 21:25:04 +01:00
|
|
|
$account_id = get_account_id($accountid);
|
2001-03-10 00:21:52 +01:00
|
|
|
|
|
|
|
$security_equals = Array();
|
|
|
|
$acl = CreateObject('phpgwapi.acl');
|
2001-03-19 21:25:04 +01:00
|
|
|
$security_equals = $acl->get_ids_for_location($account_id, 1, 'phpgw_group');
|
2001-03-10 00:21:52 +01:00
|
|
|
unset($acl);
|
|
|
|
|
|
|
|
if ($security_equals == False)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($idx=0; $idx<count($security_equals); $idx++)
|
|
|
|
{
|
|
|
|
$name = $this->id2name(intval($security_equals[$idx]));
|
2001-06-03 19:19:02 +02:00
|
|
|
$this->members[] = Array('account_id' => intval($security_equals[$idx]), 'account_name' => $name);
|
2001-03-10 00:21:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->members;
|
|
|
|
}
|
2001-06-26 12:22:25 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@function get_nextid
|
|
|
|
@@abstract Using the common functions next_id and last_id, find the next available account_id
|
|
|
|
@@param $account_type (optional, default to 'u'
|
|
|
|
*/
|
|
|
|
function get_nextid($account_type='u')
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
if ($GLOBALS['phpgw_info']['server']['account_min_id']) { $min = $GLOBALS['phpgw_info']['server']['account_min_id']; }
|
|
|
|
if ($GLOBALS['phpgw_info']['server']['account_max_id']) { $max = $GLOBALS['phpgw_info']['server']['account_max_id']; }
|
2001-06-26 12:22:25 +02:00
|
|
|
|
|
|
|
if ($account_type == 'g')
|
|
|
|
{
|
2001-06-26 12:25:10 +02:00
|
|
|
$type = 'groups';
|
2001-06-26 12:22:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-06-26 12:25:10 +02:00
|
|
|
$type = 'accounts';
|
2001-06-26 12:22:25 +02:00
|
|
|
}
|
2001-09-02 01:42:16 +02:00
|
|
|
$nextid = $GLOBALS['phpgw']->common->last_id($type,$min,$max);
|
2001-06-26 12:22:25 +02:00
|
|
|
|
|
|
|
/* Loop until we find a free id */
|
|
|
|
$free = 0;
|
|
|
|
while (!$free)
|
|
|
|
{
|
|
|
|
//echo '<br>calling search for id: '.$nextid;
|
|
|
|
if ($this->exists($nextid))
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$nextid = $GLOBALS['phpgw']->common->next_id($type,$min,$max);
|
2001-06-26 12:22:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* echo '<br>calling search for lid: '.$account_lid; */
|
|
|
|
if ($this->exists($account_lid))
|
|
|
|
{
|
2001-09-02 01:42:16 +02:00
|
|
|
$nextid = $GLOBALS['phpgw']->common->next_id($type,$min,$max);
|
2001-06-26 12:22:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$free = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-09-02 01:42:16 +02:00
|
|
|
if ($GLOBALS['phpgw_info']['server']['account_max_id'] &&
|
|
|
|
($nextid > $GLOBALS['phpgw_info']['server']['account_max_id']))
|
2001-06-26 12:22:25 +02:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
/* echo '<br>using'.$nextid;exit; */
|
|
|
|
return $nextid;
|
|
|
|
}
|
2001-03-10 00:21:52 +01:00
|
|
|
}
|
2001-03-10 01:17:32 +01:00
|
|
|
?>
|