2001-07-08 15:54:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - addressbook *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Written by Joseph Engo <jengo@mail.com> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class soaddressbook
|
|
|
|
{
|
|
|
|
var $contacts;
|
|
|
|
var $rights;
|
2001-08-04 16:12:32 +02:00
|
|
|
var $grants;
|
|
|
|
var $owner;
|
2001-07-08 15:54:40 +02:00
|
|
|
|
|
|
|
function soaddressbook()
|
|
|
|
{
|
2001-08-23 06:29:20 +02:00
|
|
|
if(!isset($GLOBALS['owner']))
|
|
|
|
{
|
|
|
|
$GLOBALS['owner'] = 0;
|
|
|
|
}
|
|
|
|
$owner = $GLOBALS['owner'];
|
2001-07-08 15:54:40 +02:00
|
|
|
|
2001-08-23 06:29:20 +02:00
|
|
|
$this->contacts = CreateObject('phpgwapi.contacts');
|
|
|
|
$grants = $this->contacts->grants;
|
|
|
|
/* _debug_array($GLOBALS['phpgw_info']); */
|
|
|
|
/* _debug_array($grants); */
|
2001-08-04 16:12:32 +02:00
|
|
|
|
|
|
|
if(!isset($owner) || !$owner)
|
|
|
|
{
|
2001-08-23 06:29:20 +02:00
|
|
|
$owner = $GLOBALS['phpgw_info']['user']['account_id'];
|
|
|
|
/* echo $owner; */
|
2001-08-04 16:12:32 +02:00
|
|
|
$rights = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
|
2001-08-23 06:29:20 +02:00
|
|
|
/* echo $rights; */
|
2001-08-04 16:12:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($grants[$owner])
|
|
|
|
{
|
|
|
|
$rights = $grants[$owner];
|
|
|
|
if (!($rights & PHPGW_ACL_READ))
|
|
|
|
{
|
2001-08-23 06:29:20 +02:00
|
|
|
$owner = $GLOBALS['phpgw_info']['user']['account_id'];
|
2001-08-04 16:12:32 +02:00
|
|
|
$rights = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-23 06:29:20 +02:00
|
|
|
$this->rights = $rights;
|
|
|
|
$this->grants = $grants;
|
|
|
|
$this->owner = $owner;
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2001-08-23 08:57:37 +02:00
|
|
|
function read_entries($data)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2001-08-23 08:57:37 +02:00
|
|
|
return $this->contacts->read(
|
|
|
|
$data['start'],
|
|
|
|
$data['limit'],
|
|
|
|
$data['fields'],
|
|
|
|
$data['query'],
|
|
|
|
$data['filter'],
|
|
|
|
$data['sort'],
|
|
|
|
$data['order']
|
|
|
|
);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function read_entry($id,$fields)
|
|
|
|
{
|
|
|
|
if ($this->rights & PHPGW_ACL_READ)
|
|
|
|
{
|
|
|
|
return $this->contacts->read_single_entry($id,$fields);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-04 16:12:32 +02:00
|
|
|
$rtrn = array(0 => array('No access' => 'No access'));
|
2001-07-08 15:54:40 +02:00
|
|
|
return $rtrn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_last_entry($fields)
|
|
|
|
{
|
|
|
|
if ($this->rights & PHPGW_ACL_READ)
|
|
|
|
{
|
|
|
|
return $this->contacts->read_last_entry($fields);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-20 18:30:02 +02:00
|
|
|
$rtrn = array(0 => array('No access' => 'No access'));
|
2001-07-08 15:54:40 +02:00
|
|
|
return $rtrn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-09 02:19:28 +02:00
|
|
|
function add_entry($fields)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
2001-07-18 22:30:53 +02:00
|
|
|
$fields['tid'] = trim($fields['tid']);
|
|
|
|
if(empty($fields['tid']))
|
|
|
|
{
|
|
|
|
$fields['tid'] = 'n';
|
|
|
|
}
|
2001-07-08 15:54:40 +02:00
|
|
|
if ($this->rights & PHPGW_ACL_ADD)
|
|
|
|
{
|
2001-08-09 02:32:59 +02:00
|
|
|
$id = $this->contacts->add($fields['owner'],$fields,$fields['access'],$fields['cat_id'],$fields['tid']);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
2001-08-09 02:32:59 +02:00
|
|
|
return $id;
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_lastid()
|
|
|
|
{
|
|
|
|
$entry = $this->contacts->read_last_entry();
|
2001-08-20 18:30:02 +02:00
|
|
|
$id = $entry[0]['id'];
|
|
|
|
return $id;
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
|
2001-08-09 02:19:28 +02:00
|
|
|
function update_entry($fields)
|
2001-07-08 15:54:40 +02:00
|
|
|
{
|
|
|
|
if ($this->rights & PHPGW_ACL_EDIT)
|
|
|
|
{
|
2001-08-09 02:19:28 +02:00
|
|
|
$this->contacts->update($fields['ab_id'],$fields['owner'],$fields,$fields['access'],$fields['cat_id']);
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 06:09:12 +02:00
|
|
|
|
2001-08-09 02:19:28 +02:00
|
|
|
function delete_entry($data)
|
2001-07-12 06:09:12 +02:00
|
|
|
{
|
|
|
|
if ($this->rights & PHPGW_ACL_DELETE)
|
|
|
|
{
|
2001-08-09 02:19:28 +02:00
|
|
|
$this->contacts->delete($data['id']);
|
2001-07-12 06:09:12 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2001-07-08 15:54:40 +02:00
|
|
|
}
|
|
|
|
?>
|