2001-02-02 08:00:58 +01:00
|
|
|
<?php
|
2001-05-23 22:57:10 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Accounts manager for LDAP *
|
|
|
|
* This file written by Miles Lott <milosch@phpgroupware.org> *
|
|
|
|
* View and manipulate contact records using LDAP *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* 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 *
|
|
|
|
\**************************************************************************/
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-05-23 22:57:10 +02:00
|
|
|
/* $Id$ */
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-05-01 11:32:52 +02:00
|
|
|
/*!
|
2001-03-27 23:57:26 +02:00
|
|
|
@class contacts
|
2001-03-18 19:49:19 +01:00
|
|
|
@abstract Contact List System
|
|
|
|
@discussion Author: jengo/Milosch <br>
|
|
|
|
This class provides a contact database scheme. <br>
|
|
|
|
It attempts to be based on the vcard 2.1 standard, with mods as needed to make for more reasonable sql storage. <br>
|
2001-05-23 22:57:10 +02:00
|
|
|
The LDAP schema used here may require installation of schema files available in the phpgwapi/doc/ldap dir.
|
|
|
|
Please see the README file there.
|
2001-03-18 19:49:19 +01:00
|
|
|
Syntax: CreateObject('phpgwapi.contacts'); <br>
|
|
|
|
Example1: $contacts = CreateObject('phpgwapi.contacts');
|
2001-02-27 01:31:20 +01:00
|
|
|
*/
|
2001-02-21 23:41:37 +01:00
|
|
|
class contacts_
|
|
|
|
{
|
|
|
|
var $db;
|
2001-03-19 02:02:07 +01:00
|
|
|
var $ldap;
|
2001-03-22 08:57:38 +01:00
|
|
|
var $nextid;
|
2001-05-07 06:49:00 +02:00
|
|
|
var $std_table='';
|
|
|
|
var $ext_table='phpgw_addressbook_extra';
|
2001-02-27 01:31:20 +01:00
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
var $account_id;
|
2001-03-27 23:57:26 +02:00
|
|
|
var $stock_contact_fields; // This is an array of almost the fields in the phpgw_addressbook table
|
|
|
|
var $non_contact_fields; // Here are the rest: d,owner,access,lid,tid,cat_id
|
2001-02-21 23:41:37 +01:00
|
|
|
var $email_types; // VCard email type array
|
|
|
|
var $total_records; // This will contain numrows for data retrieved
|
2001-03-24 16:04:35 +01:00
|
|
|
var $grants; // This holds all of the users that have granted access to there entrys
|
2001-02-21 23:41:37 +01:00
|
|
|
|
|
|
|
function contacts_()
|
|
|
|
{
|
|
|
|
global $phpgw, $phpgw_info;
|
|
|
|
|
|
|
|
$this->db = $phpgw->db;
|
2001-03-21 09:23:33 +01:00
|
|
|
$this->ldap = $phpgw->common->ldapConnect(
|
|
|
|
$phpgw_info['server']['ldap_contact_host'],
|
|
|
|
$phpgw_info['server']['ldap_contact_dn'],
|
|
|
|
$phpgw_info['server']['ldap_contact_pw']
|
|
|
|
);
|
2001-05-07 06:49:00 +02:00
|
|
|
$this->account_id = $phpgw_info['user']['account_id'];
|
2001-03-24 16:04:35 +01:00
|
|
|
$this->grants = $phpgw->acl->get_grants('addressbook');
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-03-21 09:23:33 +01:00
|
|
|
// The left side are the array elements used throughout phpgw, right side are the ldap attributes
|
2001-05-07 06:49:00 +02:00
|
|
|
$this->stock_contact_fields = array(
|
|
|
|
'fn' => 'cn', // 'prefix given middle family suffix'
|
|
|
|
'n_given' => 'givenname', // firstname
|
|
|
|
'n_family' => 'sn', // lastname
|
2001-05-23 22:50:35 +02:00
|
|
|
'n_middle' => 'phpgwmiddlename',
|
|
|
|
'n_prefix' => 'phpgwprefix',
|
|
|
|
'n_suffix' => 'phpgwsuffix',
|
|
|
|
'sound' => 'phpgwaudio',
|
|
|
|
'bday' => 'phpgwbirthday',
|
2001-05-07 06:49:00 +02:00
|
|
|
'note' => 'description',
|
2001-05-23 22:50:35 +02:00
|
|
|
'tz' => 'phpgwtz',
|
|
|
|
'geo' => 'phpgwgeo',
|
|
|
|
'url' => 'phpgwurl',
|
|
|
|
'pubkey' => 'phpgwpublickey',
|
2001-05-07 06:49:00 +02:00
|
|
|
|
|
|
|
'org_name' => 'o', // company
|
|
|
|
'org_unit' => 'ou', // division
|
|
|
|
'title' => 'title',
|
|
|
|
|
2001-05-23 22:50:35 +02:00
|
|
|
'adr_one_street' => 'street',
|
|
|
|
'adr_one_locality' => 'l',
|
2001-05-07 06:49:00 +02:00
|
|
|
'adr_one_region' => 'st',
|
|
|
|
'adr_one_postalcode' => 'postalcode',
|
2001-05-23 22:50:35 +02:00
|
|
|
'adr_one_countryname' => 'co',
|
2001-05-07 06:49:00 +02:00
|
|
|
'adr_one_type' => 'phpgwadronetype', // address is domestic/intl/postal/parcel/work/home
|
|
|
|
'label' => 'phpgwaddresslabel', // address label
|
|
|
|
|
|
|
|
'adr_two_street' => 'phpgwadrtwostreet',
|
|
|
|
'adr_two_locality' => 'phpgwadrtwolocality',
|
|
|
|
'adr_two_region' => 'phpgwadrtworegion',
|
|
|
|
'adr_two_postalcode' => 'phpgwadrtwopostalcode',
|
|
|
|
'adr_two_countryname' => 'phpgwadrtwocountryname',
|
|
|
|
'adr_two_type' => 'phpgwadrtwotype', // address is domestic/intl/postal/parcel/work/home
|
|
|
|
|
|
|
|
'tel_work' => 'telephonenumber',
|
|
|
|
'tel_home' => 'homephone',
|
2001-05-23 22:50:35 +02:00
|
|
|
'tel_voice' => 'phpgwvoicetelephonenumber',
|
2001-05-07 06:49:00 +02:00
|
|
|
'tel_fax' => 'facsimiletelephonenumber',
|
2001-05-23 22:50:35 +02:00
|
|
|
'tel_msg' => 'phpgwmsgtelephonenumber',
|
|
|
|
'tel_cell' => 'phpgwcelltelephonenumber',
|
|
|
|
'tel_pager' => 'phpgwpagertelephonenumber',
|
|
|
|
'tel_bbs' => 'phpgwbbstelephonenumber',
|
|
|
|
'tel_modem' => 'phpgwmodemtelephonenumber',
|
|
|
|
'tel_car' => 'phpgwmobiletelephonenumber',
|
|
|
|
'tel_isdn' => 'phpgwisdnphonenumber',
|
|
|
|
'tel_video' => 'phpgwvideophonenumber',
|
|
|
|
'tel_prefer' => 'phpgwpreferphone', // home, work, voice, etc
|
2001-05-07 06:49:00 +02:00
|
|
|
'email' => 'mail',
|
2001-05-23 22:50:35 +02:00
|
|
|
'email_type' => 'phpgwmailtype', //'INTERNET','CompuServe',etc...
|
|
|
|
'email_home' => 'phpgwmailhome',
|
|
|
|
'email_home_type' => 'phpgwmailhometype' //'INTERNET','CompuServe',etc...
|
2001-02-21 23:41:37 +01:00
|
|
|
);
|
|
|
|
|
2001-03-27 16:33:16 +02:00
|
|
|
$this->non_contact_fields = array(
|
2001-05-07 06:49:00 +02:00
|
|
|
'id' => 'uidnumber',
|
|
|
|
'lid' => 'uid',
|
2001-05-23 22:50:35 +02:00
|
|
|
'tid' => 'phpgwcontacttypeid',
|
|
|
|
'cat_id' => 'phpgwcontactcatid',
|
|
|
|
'access' => 'phpgwcontactaccess',
|
|
|
|
'owner' => 'phpgwcontactowner'
|
2001-03-27 16:33:16 +02:00
|
|
|
);
|
|
|
|
|
2001-03-18 19:49:19 +01:00
|
|
|
/* Used to flag an address as being:
|
|
|
|
domestic OR international(default)
|
|
|
|
parcel(default)
|
|
|
|
postal(default)
|
|
|
|
work(default) OR home
|
|
|
|
*/
|
|
|
|
$this->adr_types = array(
|
2001-05-07 06:49:00 +02:00
|
|
|
'dom' => lang('Domestic'),
|
|
|
|
'intl' => lang('International'),
|
|
|
|
'parcel' => lang('Parcel'),
|
|
|
|
'postal' => lang('Postal')
|
2001-03-18 19:49:19 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Used to set preferphone field
|
|
|
|
$this->tel_types = array(
|
2001-05-07 06:49:00 +02:00
|
|
|
'work' => 'work',
|
|
|
|
'home' => 'home',
|
|
|
|
'voice' => 'voice',
|
|
|
|
'fax' => 'fax',
|
|
|
|
'msg' => 'msg',
|
|
|
|
'cell' => 'cell',
|
|
|
|
'pager' => 'pager',
|
|
|
|
'bbs' => 'bbs',
|
|
|
|
'modem' => 'modem',
|
|
|
|
'car' => 'car',
|
|
|
|
'isdn' => 'isdn',
|
|
|
|
'video' => 'video'
|
2001-03-18 19:49:19 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Used to set mail_type fields
|
2001-05-01 11:32:52 +02:00
|
|
|
$this->email_types = array(
|
2001-05-07 06:49:00 +02:00
|
|
|
'INTERNET' => 'INTERNET',
|
|
|
|
'CompuServe' => 'CompuServe',
|
|
|
|
'AOL' => 'AOL',
|
|
|
|
'Prodigy' => 'Prodigy',
|
|
|
|
'eWorld' => 'eWorld',
|
|
|
|
'AppleLink' => 'AppleLink',
|
|
|
|
'AppleTalk' => 'AppleTalk',
|
|
|
|
'PowerShare' => 'PowerShare',
|
|
|
|
'IBMMail' => 'IBMMail',
|
|
|
|
'ATTMail' => 'ATTMail',
|
|
|
|
'MCIMail' => 'MCIMail',
|
|
|
|
'X.400' => 'X.400',
|
|
|
|
'TLX' => 'TLX'
|
2001-02-21 23:41:37 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// send this the id and whatever fields you want to see
|
2001-05-07 06:49:00 +02:00
|
|
|
function read_single_entry($id,$fields = '')
|
2001-02-21 23:41:37 +01:00
|
|
|
{
|
2001-03-22 03:50:14 +01:00
|
|
|
global $phpgw_info;
|
2001-02-21 23:41:37 +01:00
|
|
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) =
|
|
|
|
$this->split_stock_and_extras($fields);
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (count($stock_fieldnames))
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($t_fields == ",")
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
unset($t_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'uidnumber='.$id);
|
2001-03-19 02:02:07 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
2001-03-18 19:49:19 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0];
|
|
|
|
$return_fields[0]['lid'] = $ldap_fields[0]['uid'][0];
|
2001-05-23 22:50:35 +02:00
|
|
|
$return_fields[0]['tid'] = $ldap_fields[0]['phpgwcontacttypeid'][0];
|
|
|
|
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
|
|
|
|
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
|
|
|
|
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
|
2001-05-07 06:49:00 +02:00
|
|
|
if (gettype($stock_fieldnames) == 'array')
|
|
|
|
{
|
|
|
|
while(list($name,$value)=each($stock_fieldnames))
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$return_fields[0][$name] = $ldap_fields[0][$value][0];
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-18 19:49:19 +01:00
|
|
|
|
|
|
|
// Setup address type fields
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($return_fields[0]['adr_one_type'])
|
|
|
|
{
|
|
|
|
$one_type = $return_fields[0]['adr_one_type'];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($name,$val) = each($this->adr_types))
|
|
|
|
{
|
2001-03-18 19:49:19 +01:00
|
|
|
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
|
|
|
|
}
|
|
|
|
}
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($return_fields[0]["adr_two_type"])
|
|
|
|
{
|
|
|
|
$two_type = $return_fields[0]['adr_two_type'];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($name,$val) = each($this->adr_types))
|
|
|
|
{
|
2001-03-18 19:49:19 +01:00
|
|
|
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->query("select contact_name,contact_value from $this->ext_table where contact_id='" . $id . "'",__LINE__,__FILE__);
|
2001-05-07 06:49:00 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
// If its not in the list to be returned, don't return it.
|
|
|
|
// This is still quicker then 5(+) separate queries
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($extra_fields[$this->db->f('contact_name')])
|
|
|
|
{
|
|
|
|
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return_fields;
|
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
function read_last_entry($fields = '')
|
2001-02-21 23:41:37 +01:00
|
|
|
{
|
2001-03-18 19:49:19 +01:00
|
|
|
global $phpgw_info;
|
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) =
|
|
|
|
$this->split_stock_and_extras($fields);
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (count($stock_fieldnames))
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($t_fields == ",")
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
unset($t_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
$id = $this->nextid;
|
2001-03-18 19:49:19 +01:00
|
|
|
if ($id == -1) { $id = 1; }
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'uidnumber='.$id);
|
2001-03-19 02:02:07 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
2001-03-18 19:49:19 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$return_fields[0]['id'] = $ldap_fields[0]['uidnumber'][0];
|
|
|
|
$return_fields[0]['lid'] = $ldap_fields[0]['uid'][0];
|
2001-05-23 22:50:35 +02:00
|
|
|
$return_fields[0]['tid'] = $ldap_fields[0]['phpgwcontacttypeid'][0];
|
|
|
|
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
|
|
|
|
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
|
|
|
|
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
|
2001-03-24 09:45:52 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (gettype($stock_fieldnames) == 'array')
|
|
|
|
{
|
|
|
|
while(list($name,$value)=each($stock_fieldnames))
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$return_fields[0][$name] = $ldap_fields[0][$value][0];
|
2001-03-18 19:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup address type fields
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($return_fields[0]['adr_one_type'])
|
|
|
|
{
|
|
|
|
$one_type = $return_fields[0]['adr_one_type'];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($name,$val) = each($this->adr_types))
|
|
|
|
{
|
2001-03-18 19:49:19 +01:00
|
|
|
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($return_fields[0]['adr_two_type'])
|
|
|
|
{
|
|
|
|
$two_type = $return_fields[0]['adr_two_type'];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($name,$val) = each($this->adr_types))
|
|
|
|
{
|
2001-03-18 19:49:19 +01:00
|
|
|
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->query("select contact_name,contact_value from $this->ext_table where contact_id='" . $id . "'",__LINE__,__FILE__);
|
2001-05-07 06:49:00 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
// If its not in the list to be returned, don't return it.
|
|
|
|
// This is still quicker then 5(+) separate queries
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($extra_fields[$this->db->f('contact_name')])
|
|
|
|
{
|
|
|
|
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return_fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send this the range, query, sort, order and whatever fields you want to see
|
2001-03-24 09:45:52 +01:00
|
|
|
// 'rights' and 'access' are unused at this time
|
2001-03-29 19:53:26 +02:00
|
|
|
function read($start=0,$offset=0,$fields="",$query="",$filter="",$sort="",$order="")
|
2001-02-21 23:41:37 +01:00
|
|
|
{
|
|
|
|
global $phpgw,$phpgw_info;
|
2001-02-27 01:31:20 +01:00
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
2001-02-27 01:31:20 +01:00
|
|
|
$DEBUG = 0;
|
2001-02-21 23:41:37 +01:00
|
|
|
|
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
|
|
|
|
2001-03-29 19:53:26 +02:00
|
|
|
$filterfields = array();
|
2001-02-27 01:31:20 +01:00
|
|
|
// turn filter's a=b,c=d OR a=b into an array
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($filter)
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; }
|
|
|
|
$filterarray = split(',',$filter);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($filterarray[1])
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
$i=0;
|
2001-05-07 06:49:00 +02:00
|
|
|
for ($i=0;$i<count($filterarray);$i++)
|
|
|
|
{
|
2001-02-27 01:31:20 +01:00
|
|
|
list($name,$value) = split("=",$filterarray[$i]);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($name)
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #".$this->non_contact_fields[$name]."# => #".$value."#"; }
|
|
|
|
$filterfields[$this->non_contact_fields[$name]] = $value;
|
2001-02-27 01:31:20 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-21 23:41:37 +01:00
|
|
|
list($name,$value) = split('=',$filter);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($DEBUG)
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
echo "<br>DEBUG - Filter strings: #".$this->non_contact_fields[$name]."# => #".$value."#";
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-27 16:33:16 +02:00
|
|
|
$filterfields = array($this->non_contact_fields[$name] => $value);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$filterfields += array('phpgwcontacttypeid' => 'n');
|
2001-03-27 16:33:16 +02:00
|
|
|
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwtypeid=n#"; }
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-03-29 19:53:26 +02:00
|
|
|
if (is_array($this->grants))
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$filterfields += array('phpgwcontactaccess' => 'public');
|
2001-03-29 19:53:26 +02:00
|
|
|
$grants = $this->grants;
|
|
|
|
while (list($user) = each($grants))
|
|
|
|
{
|
|
|
|
if ($DEBUG) { echo "<br>DEBUG - Grant from owner: ".$user; }
|
2001-05-23 22:50:35 +02:00
|
|
|
$filterfields += array('phpgwcontactowner' => $user);
|
2001-03-29 19:53:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//if ($DEBUG) {
|
|
|
|
// while(list($name,$value) = each($filterfields)) {
|
|
|
|
// echo "<br>DEBUG - Filter strings: #".$name.",".$value."#";
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
if (!$sort) { $sort = "ASC"; }
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (!$order)
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
$order = "n_family";
|
2001-02-27 01:31:20 +01:00
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($DEBUG && $order)
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
echo "<br>DEBUG - ORDER by $order";
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($query)
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
$ldap_fields = array();
|
|
|
|
$total = 0;
|
2001-03-23 05:44:55 +01:00
|
|
|
// Query each field seperately instead of using ldap OR search.
|
|
|
|
// It seems PHP cannot do this correctly.
|
|
|
|
reset($stock_fieldnames);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($name,$value) = each($stock_fieldnames) )
|
|
|
|
{
|
2001-03-22 21:36:26 +01:00
|
|
|
$lquery = $value.'=*'.$query.'*';
|
2001-03-22 21:19:40 +01:00
|
|
|
//echo $lquery; exit;
|
2001-05-07 06:49:00 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], $lquery);
|
2001-03-23 05:44:55 +01:00
|
|
|
// append the results
|
2001-03-22 21:19:40 +01:00
|
|
|
$ldap_fields += ldap_get_entries($this->ldap, $sri);
|
2001-03-23 05:44:55 +01:00
|
|
|
// add the # rows to our total
|
2001-03-22 21:19:40 +01:00
|
|
|
$total = $total + ldap_count_entries($this->ldap, $sri);
|
|
|
|
}
|
2001-03-23 05:44:55 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($filterfields)
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
|
|
|
|
}
|
2001-03-23 05:44:55 +01:00
|
|
|
|
2001-03-27 16:33:16 +02:00
|
|
|
//echo '<br>first total="'.$total.'"';
|
2001-03-23 05:44:55 +01:00
|
|
|
// Now, remove duplicate rows
|
2001-03-29 13:12:03 +02:00
|
|
|
//if (floor(phpversion()) == 4) {
|
|
|
|
// $tmp = array_unique($ldap_fields);
|
|
|
|
// $ldap_fields = $tmp;
|
|
|
|
// } else {
|
2001-03-27 16:33:16 +02:00
|
|
|
$ldap_fields = $this->asortbyindex($ldap_fields,'uidnumber');
|
|
|
|
reset($ldap_fields);
|
2001-05-07 06:49:00 +02:00
|
|
|
if (count($ldap_fields) > 0)
|
|
|
|
{
|
|
|
|
for ($a = 0; $a < count($ldap_fields); $a++)
|
|
|
|
{
|
|
|
|
if ($ldap_fields[$a])
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
//echo '<br>comparing "'.$ldap_fields[$a]['uidnumber'][0]
|
|
|
|
// .'" to "'.$ldap_fields[$a - 1]['uidnumber'][0].'"';
|
2001-05-07 06:49:00 +02:00
|
|
|
if (($ldap_fields[$a]['uidnumber'][0] <> $ldap_fields[$a - 1]['uidnumber'][0]))
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
$uniquearray[$a] = $ldap_fields[$a];
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
//echo '<br>deleting "'.$ldap_fields[$a -1 ]['uidnumber'][0];
|
|
|
|
}
|
2001-03-23 05:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-27 16:33:16 +02:00
|
|
|
$ldap_fields = $uniquearray;
|
2001-03-23 05:44:55 +01:00
|
|
|
}
|
2001-03-29 13:12:03 +02:00
|
|
|
// } // end version check
|
2001-03-24 09:45:52 +01:00
|
|
|
|
2001-03-23 05:44:55 +01:00
|
|
|
$this->total_records = count($ldap_fields);
|
2001-03-26 15:33:50 +02:00
|
|
|
//echo '<br>total="'.$this->total_records.'"';
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner=*');
|
2001-03-22 21:19:40 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
$this->total_records = ldap_count_entries($this->ldap, $sri);
|
2001-03-27 16:33:16 +02:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($filterfields)
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-22 01:23:40 +01:00
|
|
|
|
2001-03-22 21:19:40 +01:00
|
|
|
// Use shared sorting routines, based on sort and order
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($sort == 'ASC')
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
$ldap_fields = $this->asortbyindex($ldap_fields, $this->stock_contact_fields[$order]);
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
$ldap_fields = $this->arsortbyindex($ldap_fields, $this->stock_contact_fields[$order]);
|
|
|
|
}
|
2001-03-22 01:23:40 +01:00
|
|
|
|
2001-03-22 03:39:38 +01:00
|
|
|
// This logic allows you to limit rows, or not.
|
|
|
|
// The export feature, for example, does not limit rows.
|
|
|
|
// This way, it can retrieve all rows at once.
|
|
|
|
if ($start && $offset) {
|
|
|
|
$limit = $start + $offset;;
|
|
|
|
} elseif ($start && !$offset) {
|
|
|
|
$limit = $start;
|
|
|
|
} elseif(!$start && !$offset) {
|
|
|
|
$limit = $this->total_records;
|
|
|
|
} else { #(!$start && $offset) {
|
|
|
|
$start = 0;
|
|
|
|
$limit = $offset;
|
|
|
|
}
|
|
|
|
//echo '('.$start.','.$limit.')';
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-03-24 16:31:59 +01:00
|
|
|
@reset($ldap_fields);
|
2001-03-22 03:39:38 +01:00
|
|
|
$j=0;
|
2001-05-07 06:49:00 +02:00
|
|
|
for ($i=$start;$i<$limit;$i++)
|
|
|
|
{
|
|
|
|
if ($i<$this->total_records && $ldap_fields[$i]['uid'][0])
|
|
|
|
{
|
2001-03-22 03:39:38 +01:00
|
|
|
//echo '<br>j:'.$j;
|
2001-05-23 22:50:35 +02:00
|
|
|
//echo '<br>i:'.$i;
|
2001-03-22 03:39:38 +01:00
|
|
|
// unique id, lid for group/account records,
|
|
|
|
// type id (g/u) for groups/accounts, and
|
|
|
|
// id of owner/parent for the record
|
2001-05-07 06:49:00 +02:00
|
|
|
$return_fields[$j]['id'] = $ldap_fields[$i]['uidnumber'][0];
|
|
|
|
$return_fields[$j]['lid'] = $ldap_fields[$i]['uid'][0];
|
2001-05-23 22:50:35 +02:00
|
|
|
$return_fields[$j]['tid'] = $ldap_fields[$i]['phpgwcontacttypeid'][0];
|
|
|
|
$return_fields[$j]['owner'] = $ldap_fields[$i]['phpgwcontactowner'][0];
|
|
|
|
$return_fields[$j]['access'] = $ldap_fields[$i]['phpgwcontactaccess'][0];
|
|
|
|
$return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcontactcatId'][0];
|
|
|
|
//echo '<br>uidnumber: "'.$ldap_fields[$i]['uidnumber'][0].'"';
|
|
|
|
//echo '<br>tid: "'.$ldap_fields[$i]['phpgwcontacttypeid'][0].'"';
|
|
|
|
//echo '<br>owner: "'.$ldap_fields[$i]['phpgwcontactowner'][0].'"';
|
|
|
|
//echo '<br>access: "'.$ldap_fields[$i]['phpgwcontactaccess'][0].'"';
|
|
|
|
//echo '<br>catid: "'.$ldap_fields[$i]['phpgwcontactcatid'][0].'"';
|
2001-05-07 06:49:00 +02:00
|
|
|
|
|
|
|
if (gettype($stock_fieldnames) == 'array')
|
|
|
|
{
|
2001-03-22 21:19:40 +01:00
|
|
|
reset($stock_fieldnames);
|
2001-05-07 06:49:00 +02:00
|
|
|
while (list($f_name,$f_value) = each($stock_fieldnames))
|
|
|
|
{
|
2001-03-22 03:39:38 +01:00
|
|
|
$return_fields[$j][$f_name] = $ldap_fields[$i][$f_value][0];
|
|
|
|
}
|
|
|
|
reset($stock_fieldnames);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-22 21:19:40 +01:00
|
|
|
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
|
2001-05-07 06:49:00 +02:00
|
|
|
. $ldap_fields[$i]['id'] . "'",__LINE__,__FILE__);
|
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
2001-03-22 03:39:38 +01:00
|
|
|
// If its not in the list to be returned, don't return it.
|
|
|
|
// This is still quicker then 5(+) separate queries
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($extra_fields[$this->db->f('contact_name')])
|
|
|
|
{
|
|
|
|
$return_fields[$j][$this->db->f('contact_name')] = $this->db->f('contact_value');
|
2001-03-22 03:39:38 +01:00
|
|
|
}
|
2001-03-18 19:49:19 +01:00
|
|
|
}
|
2001-03-22 03:39:38 +01:00
|
|
|
$j++;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return_fields;
|
|
|
|
}
|
|
|
|
|
2001-03-27 23:57:26 +02:00
|
|
|
function add($owner,$fields,$access='private',$cat_id='0',$tid='n')
|
2001-02-21 23:41:37 +01:00
|
|
|
{
|
2001-03-22 08:57:38 +01:00
|
|
|
global $phpgw,$phpgw_info;
|
2001-03-24 08:58:03 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (!$phpgw_info['server']['ldap_contact_context'])
|
|
|
|
{
|
2001-03-24 08:58:03 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
$free = 0;
|
2001-05-07 06:49:00 +02:00
|
|
|
$this->nextid = $phpgw->common->last_id('contacts');
|
2001-03-22 08:57:38 +01:00
|
|
|
// Loop until we find a free id
|
2001-05-07 06:49:00 +02:00
|
|
|
while (!$free)
|
|
|
|
{
|
|
|
|
$ldap_fields = '';
|
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'uidnumber='.$this->nextid);
|
2001-03-22 08:57:38 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($ldap_fields[0]['dn'][0])
|
|
|
|
{
|
|
|
|
$this->nextid = $phpgw->common->next_id('contacts');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 08:57:38 +01:00
|
|
|
$free = True;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
2001-03-19 02:02:07 +01:00
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
$ldap_fields = '';
|
2001-05-07 06:49:00 +02:00
|
|
|
if (gettype($stock_fieldnames) == 'array')
|
|
|
|
{
|
|
|
|
while(list($name,$value)=each($stock_fieldnames))
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
if ($stock_fields[$name] != '')
|
|
|
|
{
|
|
|
|
$ldap_fields[$value] = $stock_fields[$name];
|
|
|
|
}
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-21 09:23:33 +01:00
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
$time = gettimeofday();
|
2001-05-07 06:49:00 +02:00
|
|
|
$ldap_fields['uid'] = time().$time['usec'].':'.$ldap_fields['givenname'];
|
2001-05-23 22:50:35 +02:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$dn = 'uid=' . $ldap_fields['uid'].',' . $phpgw_info['server']['ldap_contact_context'];
|
2001-05-23 22:50:35 +02:00
|
|
|
$ldap_fields['phpgwcontacttypeid'] = $tid;
|
|
|
|
$ldap_fields['phpgwcontactowner'] = $owner;
|
|
|
|
$ldap_fields['phpgwcontactaccess'] = $access;
|
|
|
|
$ldap_fields['phpgwcontactcatid'] = $cat_id;
|
2001-03-26 15:33:50 +02:00
|
|
|
$ldap_fields['uidnumber'] = $this->nextid;
|
2001-05-23 22:50:35 +02:00
|
|
|
//$ldap_fields['objectclass'][0] = 'person';
|
|
|
|
$ldap_fields['objectclass'][0] = 'organizationalPerson';
|
|
|
|
$ldap_fields['objectclass'][1] = 'inetOrgPerson';
|
|
|
|
$ldap_fields['objectclass'][2] = 'phpgwContact';
|
|
|
|
/*
|
|
|
|
@reset($ldap_fields);
|
2001-03-22 08:57:38 +01:00
|
|
|
while (list($name,$value) = each($ldap_fields) ) {
|
2001-05-23 22:50:35 +02:00
|
|
|
if ($value)
|
|
|
|
{
|
|
|
|
echo '<br>fieldname ="'.$name.'", value ="'.$value.'"';
|
|
|
|
}
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
|
|
|
exit;
|
2001-05-23 22:50:35 +02:00
|
|
|
*/
|
2001-03-22 08:57:38 +01:00
|
|
|
$err = ldap_add($this->ldap, $dn, $ldap_fields);
|
2001-03-19 02:02:07 +01:00
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
//$this->db->unlock();
|
2001-05-07 06:49:00 +02:00
|
|
|
if (count($extra_fields))
|
|
|
|
{
|
|
|
|
while (list($name,$value) = each($extra_fields))
|
|
|
|
{
|
2001-03-22 08:57:38 +01:00
|
|
|
$this->db->query("insert into $this->ext_table values ('".$this->nextid."','" . $this->account_id . "','"
|
|
|
|
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
2001-03-19 02:02:07 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function field_exists($id,$field_name)
|
|
|
|
{
|
|
|
|
$this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='"
|
|
|
|
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
|
|
|
$this->db->next_record();
|
|
|
|
return $this->db->f(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_single_extra_field($id,$owner,$field_name,$field_value)
|
|
|
|
{
|
|
|
|
$this->db->query("insert into $this->ext_table values ($id,'$owner','" . addslashes($field_name)
|
|
|
|
. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_single_extra_field($id,$field_name)
|
|
|
|
{
|
|
|
|
$this->db->query("delete from $this->ext_table where contact_id='$id' and contact_name='"
|
|
|
|
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
|
2001-03-27 23:57:26 +02:00
|
|
|
function update($id,$owner,$fields,$access='private',$cat_id='0',$tid='n')
|
2001-02-21 23:41:37 +01:00
|
|
|
{
|
2001-03-22 03:52:10 +01:00
|
|
|
global $phpgw_info;
|
2001-03-27 23:57:26 +02:00
|
|
|
$nonfields = $this->non_contact_fields;
|
2001-03-24 08:58:03 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (!$phpgw_info['server']['ldap_contact_context'])
|
|
|
|
{
|
2001-03-24 08:58:03 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
// First make sure that id number exists
|
2001-05-07 06:49:00 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'uidnumber='.$id);
|
2001-03-19 02:02:07 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
2001-03-27 23:57:26 +02:00
|
|
|
if ($ldap_fields[0]['dn'])
|
|
|
|
{
|
2001-03-22 08:57:38 +01:00
|
|
|
$dn = $ldap_fields[0]['dn'];
|
2001-03-19 02:02:07 +01:00
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
2001-05-07 06:49:00 +02:00
|
|
|
if (gettype($stock_fieldnames) == 'array')
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-03-22 08:57:38 +01:00
|
|
|
// Check each value, add our extra attributes if they are missing, and
|
2001-03-22 21:19:40 +01:00
|
|
|
// otherwise fix the entry while we can.
|
|
|
|
//
|
2001-03-22 08:57:38 +01:00
|
|
|
// Verify uidnumber
|
2001-03-27 23:57:26 +02:00
|
|
|
$stock_fields['id'] = $id;
|
|
|
|
if (empty($ldap_fields[0]['uidnumber']))
|
|
|
|
{
|
2001-03-26 15:33:50 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
2001-03-27 23:57:26 +02:00
|
|
|
elseif (!$ldap_fields[0]['uidnumber'])
|
|
|
|
{
|
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
|
2001-03-27 16:33:16 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
// Verify uid
|
2001-03-27 23:57:26 +02:00
|
|
|
$uids = split(',',$dn);
|
|
|
|
$stock_fields['lid'] = $uids[0];
|
|
|
|
if (empty($ldap_fields[0]['uid']))
|
|
|
|
{
|
|
|
|
$err = ldap_modify($this->ldap,$dn,array('uid' => $stock_fields['lid']));
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
2001-03-27 23:57:26 +02:00
|
|
|
elseif (!$ldap_fields[0]['uid'])
|
|
|
|
{
|
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('uid' => $stock_fields['lid']));
|
2001-03-26 15:33:50 +02:00
|
|
|
}
|
|
|
|
|
2001-03-22 08:57:38 +01:00
|
|
|
// Verify objectclasses are there
|
2001-03-27 23:57:26 +02:00
|
|
|
if (empty($ldap_fields[0]['objectclass']))
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
//$stock_fields['objectclass'][0] = 'person';
|
|
|
|
$stock_fields['objectclass'][0] = 'organizationalPerson';
|
|
|
|
$stock_fields['objectclass'][1] = 'inetOrgPerson';
|
|
|
|
$stock_fields['objectclass'][2] = 'phpgwContact';
|
2001-03-22 08:57:38 +01:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
elseif (!$ldap_fields[0]['objectclass'])
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
//$stock_fields['objectclass'][0] = 'person';
|
|
|
|
$stock_fields['objectclass'][0] = 'organizationalPerson';
|
|
|
|
$stock_fields['objectclass'][1] = 'inetOrgPerson';
|
|
|
|
$stock_fields['objectclass'][2] = 'phpgwContact';
|
2001-03-22 08:57:38 +01:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass']));
|
|
|
|
}
|
|
|
|
|
2001-03-27 23:57:26 +02:00
|
|
|
// Verify owner
|
|
|
|
$stock_fields['owner'] = $owner;
|
2001-05-23 22:50:35 +02:00
|
|
|
if (empty($ldap_fields[0]['phpgwcontactowner']))
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
elseif (!$ldap_fields[0]['phpgwcontactowner'])
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify access
|
|
|
|
$stock_fields['access'] = $access;
|
2001-05-23 22:50:35 +02:00
|
|
|
if (empty($ldap_fields[0]['phpgwcontactaccess']))
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
elseif (!$ldap_fields[0]['phpgwcontactaccess'])
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify cat_id
|
|
|
|
$stock_fields['cat_id'] = $cat_id;
|
2001-05-23 22:50:35 +02:00
|
|
|
if (empty($ldap_fields[0]['phpgwcontactcatid']))
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
elseif (!$ldap_fields[0]['phpgwcontactcatid'])
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify tid
|
|
|
|
$stock_fields['tid'] = $tid;
|
2001-05-23 22:50:35 +02:00
|
|
|
if (empty($ldap_fields[0]['phpgwcontacttypeid']))
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
elseif (!$ldap_fields[0]['phpgwcontacttypeid'])
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// OK, just mod the data already
|
|
|
|
$allfields = $stock_fieldnames + $nonfields;
|
|
|
|
while ( list($fname,$fvalue) = each($allfields) )
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
//if ($ldap_fields[0][$fvalue])
|
|
|
|
if ($ldap_fields[0][$fvalue] && $stock_fields[$fname] && $ldap_fields[0][$fvalue][0] != $stock_fields[$fname] )
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-03-24 16:51:28 +01:00
|
|
|
//echo "<br>".$fname." => ".$fvalue." was there";
|
2001-03-22 08:57:38 +01:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
//elseif (!$ldap_fields[0][$fvalue])
|
|
|
|
elseif (!$ldap_fields[0][$fvalue] && $stock_fields[$fname])
|
2001-03-27 23:57:26 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
//echo "<br>".$fname." not there - '".$fvalue."'";
|
2001-03-22 08:57:38 +01:00
|
|
|
$err = ldap_mod_add($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
|
|
|
|
}
|
2001-05-23 22:50:35 +02:00
|
|
|
elseif ($ldap_fields[0][$fvalue] && !$stock_fields[$fname])
|
|
|
|
{
|
|
|
|
//echo "<br>".$fname." gone... deleting - '".$fvalue."'";
|
|
|
|
// NOTE: we use the ldap_fields because we need to send the
|
|
|
|
// _ORIGINAL_ contents as the value. see:
|
|
|
|
// http://www.php.net/manual/en/function.ldap-mod-del.php
|
|
|
|
$err = ldap_mod_del($this->ldap,$dn,array($fvalue => $ldap_fields[0][$fvalue][0]));
|
|
|
|
}
|
|
|
|
// Else we have nothing to do.
|
2001-03-22 08:57:38 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-03-27 23:57:26 +02:00
|
|
|
while (list($x_name,$x_value) = each($extra_fields))
|
|
|
|
{
|
|
|
|
if ($this->field_exists($id,$x_name))
|
|
|
|
{
|
|
|
|
if (! $x_value)
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$this->delete_single_extra_field($id,$x_name);
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$this->db->query("update $this->ext_table set contact_value='" . addslashes($x_value)
|
|
|
|
. "',contact_owner='$owner' where contact_name='" . addslashes($x_name)
|
|
|
|
. "' and contact_id='$id'",__LINE__,__FILE__);
|
|
|
|
}
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$this->add_single_extra_field($id,$owner,$x_name,$x_value);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-27 23:57:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
return False;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-30 06:18:22 +02:00
|
|
|
// Used by admin to change ownership on account delete
|
|
|
|
function change_owner($old_owner='',$new_owner='')
|
|
|
|
{
|
|
|
|
if (!($new_owner && $old_owner))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-05-23 22:50:35 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner='.$old_owner);
|
2001-03-30 06:18:22 +02:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
|
|
|
$entry = "";
|
2001-05-23 22:50:35 +02:00
|
|
|
while (list($null,$entry) = each($ldap_fields))
|
2001-05-07 06:49:00 +02:00
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $new_owner));
|
2001-03-30 06:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->query("update $this->ext_table set contact_owner='$new_owner' WHERE contact_owner=$owner",__LINE__,__FILE__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-18 19:49:19 +01:00
|
|
|
// This is where the real work of delete() is done, shared class file contains calling function
|
2001-02-21 23:41:37 +01:00
|
|
|
function delete_($id)
|
|
|
|
{
|
2001-03-22 03:52:10 +01:00
|
|
|
global $phpgw_info;
|
2001-03-24 08:58:03 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (!$phpgw_info['server']['ldap_contact_context']) {
|
2001-03-24 08:58:03 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'uidnumber='.$id);
|
2001-03-19 02:02:07 +01:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($ldap_fields[0]['dn'])
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
$err = ldap_delete($this->ldap,$ldap_fields[0]['dn']);
|
|
|
|
|
|
|
|
$this->db->query("delete from $this->ext_table where contact_id='$id' and contact_owner='"
|
|
|
|
. $this->account_id . "'",__LINE__,__FILE__);
|
2001-05-07 06:49:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
return False;
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-03-28 14:39:42 +02:00
|
|
|
// This is for the admin script deleteaccount.php
|
|
|
|
function delete_all($owner=0)
|
2001-03-24 08:46:31 +01:00
|
|
|
{
|
|
|
|
global $phpgw_info;
|
2001-03-24 08:58:03 +01:00
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if (!$phpgw_info['server']['ldap_contact_context'])
|
|
|
|
{
|
2001-03-24 08:58:03 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
if ($owner)
|
|
|
|
{
|
2001-05-23 22:50:35 +02:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info['server']['ldap_contact_context'], 'phpgwcontactowner='.$owner);
|
2001-03-28 14:39:42 +02:00
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
2001-05-07 06:49:00 +02:00
|
|
|
$entry = '';
|
|
|
|
while (list($null,$entry) = each($ldap_fields))
|
|
|
|
{
|
2001-03-28 14:39:42 +02:00
|
|
|
$err = ldap_delete($this->ldap,$entry['dn']);
|
|
|
|
}
|
2001-03-24 08:46:31 +01:00
|
|
|
|
2001-03-30 05:57:38 +02:00
|
|
|
$this->db->query("DELETE FROM $this->ext_table WHERE contact_owner=$owner",__LINE__,__FILE__);
|
2001-03-24 08:46:31 +01:00
|
|
|
}
|
2001-03-24 08:58:03 +01:00
|
|
|
return;
|
2001-03-24 08:46:31 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
?>
|