2001-02-02 08:00:58 +01:00
|
|
|
<?php
|
2001-02-21 23:41:37 +01:00
|
|
|
/**************************************************************************\
|
2001-02-27 01:31:20 +01:00
|
|
|
* phpGroupWare API - Accounts manager for SQL *
|
2001-02-21 23:41:37 +01:00
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* View and manipulate contact records using SQL *
|
|
|
|
* Copyright (C) 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$ */
|
|
|
|
|
2001-03-18 19:49:19 +01:00
|
|
|
/*!
|
|
|
|
@class acl
|
|
|
|
@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>
|
|
|
|
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;
|
|
|
|
var $std_table="";
|
2001-02-21 23:41:37 +01:00
|
|
|
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-02-27 01:31:20 +01:00
|
|
|
var $stock_contact_fields; // This is an array of almost the fields in the phpgw_addressbook table, except id,owner,lid,tid
|
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
|
|
|
|
|
|
|
|
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-02-21 23:41:37 +01:00
|
|
|
$this->account_id = $phpgw_info["user"]["account_id"];
|
|
|
|
|
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-02-21 23:41:37 +01:00
|
|
|
$this->stock_contact_fields = array(
|
2001-03-21 09:23:33 +01:00
|
|
|
"id" => "uidnumber",
|
|
|
|
"lid" => "uid",
|
|
|
|
"tid" => "phpgwcontacttype",
|
|
|
|
"owner" => "phpgwowner",
|
|
|
|
"fn" => "cn", // 'prefix given middle family suffix'
|
|
|
|
"n_given" => "givenname", // firstname
|
|
|
|
"n_family" => "sn", // lastname
|
|
|
|
"n_middle" => "middlename",
|
|
|
|
"n_prefix" => "prefix",
|
|
|
|
"n_suffix" => "suffix",
|
|
|
|
"sound" => "audio",
|
|
|
|
"bday" => "birthday",
|
|
|
|
"note" => "description",
|
|
|
|
"tz" => "tz",
|
|
|
|
"geo" => "geo",
|
|
|
|
"url" => "url",
|
|
|
|
"pubkey" => "publickey",
|
|
|
|
|
|
|
|
"org_name" => "o", // company
|
|
|
|
"org_unit" => "ou", // division
|
|
|
|
"title" => "title",
|
|
|
|
|
|
|
|
"adr_one_street" => "street",
|
|
|
|
"adr_one_locality" => "locality",
|
|
|
|
"adr_one_region" => "st",
|
|
|
|
"adr_one_postalcode" => "postalcode",
|
|
|
|
"adr_one_countryname" => "countryname",
|
|
|
|
"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",
|
|
|
|
"tel_voice" => "voicetelephonenumber",
|
|
|
|
"tel_fax" => "facsimiletelephonenumber",
|
|
|
|
"tel_msg" => "msgtelephonenumber",
|
|
|
|
"tel_cell" => "cellphone",
|
|
|
|
"tel_pager" => "pagertelephonenumber",
|
|
|
|
"tel_bbs" => "bbstelephonenumber",
|
|
|
|
"tel_modem" => "modemtelephonenumber",
|
|
|
|
"tel_car" => "mobiletelephonenumber",
|
|
|
|
"tel_isdn" => "isdnphonenumber",
|
|
|
|
"tel_video" => "videophonenumber",
|
|
|
|
"tel_prefer" => "preferphone", // home, work, voice, etc
|
|
|
|
"email" => "mail",
|
|
|
|
"email_type" => "mailtype", //'INTERNET','CompuServe',etc...
|
|
|
|
"email_home" => "mailhome",
|
|
|
|
"email_home_type" => "mailhometype" //'INTERNET','CompuServe',etc...
|
2001-02-21 23:41:37 +01: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(
|
|
|
|
"dom" => lang("Domestic"),
|
|
|
|
"intl" => lang("International"),
|
|
|
|
"parcel" => lang("Parcel"),
|
|
|
|
"postal" => lang("Postal")
|
|
|
|
);
|
|
|
|
|
|
|
|
// Used to set preferphone field
|
|
|
|
$this->tel_types = array(
|
|
|
|
"work" => "work",
|
|
|
|
"home" => "home",
|
|
|
|
"voice" => "voice",
|
|
|
|
"fax" => "fax",
|
|
|
|
"msg" => "msg",
|
|
|
|
"cell" => "cell",
|
|
|
|
"pager" => "pager",
|
|
|
|
"bbs" => "bbs",
|
|
|
|
"modem" => "modem",
|
|
|
|
"car" => "car",
|
|
|
|
"isdn" => "isdn",
|
|
|
|
"video" => "video"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Used to set mail_type fields
|
2001-02-21 23:41:37 +01:00
|
|
|
$this->email_types = array(
|
|
|
|
"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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// send this the id and whatever fields you want to see
|
|
|
|
function read_single_entry($id,$fields="")
|
|
|
|
{
|
|
|
|
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
|
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) =
|
|
|
|
$this->split_stock_and_extras($fields);
|
|
|
|
|
|
|
|
if (count($stock_fieldnames)) {
|
|
|
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
|
|
|
if ($t_fields == ",") {
|
|
|
|
unset($t_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "uidnumber=".$id);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
2001-03-18 19:49:19 +01:00
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
if (gettype($stock_fieldnames) == "array") {
|
2001-03-18 19:49:19 +01:00
|
|
|
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
|
|
|
|
if ($return_fields[0]["adr_one_type"]) {
|
|
|
|
$one_type = $return_fields[0]["adr_one_type"];
|
|
|
|
reset($this->adr_types);
|
|
|
|
while (list($name,$val) = each($this->adr_types)) {
|
|
|
|
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($return_fields[0]["adr_two_type"]) {
|
2001-03-21 09:23:33 +01:00
|
|
|
$two_type = $return_fields[0]["adr_two_type"];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
|
|
|
while (list($name,$val) = each($this->adr_types)) {
|
|
|
|
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__);
|
|
|
|
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-03-18 19:49:19 +01:00
|
|
|
if ($extra_fields[$this->db->f("contact_name")]) {
|
|
|
|
$return_fields[0][$this->db->f("contact_name")] = $this->db2->f("contact_value");
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return_fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_last_entry($fields="")
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
if (count($stock_fieldnames)) {
|
|
|
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
|
|
|
if ($t_fields == ",") {
|
|
|
|
unset($t_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-18 19:49:19 +01:00
|
|
|
$id = $phpgw_info['server']['contact_nextid'] - 1;
|
|
|
|
if ($id == -1) { $id = 1; }
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "uidnumber=".$id);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
2001-03-18 19:49:19 +01:00
|
|
|
|
2001-02-21 23:41:37 +01:00
|
|
|
if (gettype($stock_fieldnames) == "array") {
|
2001-03-18 19:49:19 +01:00
|
|
|
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
|
|
|
|
if ($return_fields[0]["adr_one_type"]) {
|
|
|
|
$one_type = $return_fields[0]["adr_one_type"];
|
|
|
|
reset($this->adr_types);
|
|
|
|
while (list($name,$val) = each($this->adr_types)) {
|
|
|
|
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
2001-03-18 19:49:19 +01:00
|
|
|
if ($return_fields[0]["adr_two_type"]) {
|
2001-03-21 09:23:33 +01:00
|
|
|
$two_type = $return_fields[0]["adr_two_type"];
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($this->adr_types);
|
|
|
|
while (list($name,$val) = each($this->adr_types)) {
|
|
|
|
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__);
|
|
|
|
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-03-18 19:49:19 +01: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-18 19:49:19 +01:00
|
|
|
// 'rights' is unused at this time
|
|
|
|
function read($start=0,$offset=0,$fields="",$query="",$filter="",$sort="",$order="",$rights="")
|
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);
|
|
|
|
if (count($stock_fieldnames)) {
|
|
|
|
$t_fields = "," . implode(",",$stock_fieldnames);
|
|
|
|
if ($t_fields == ",") {
|
|
|
|
unset($t_fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-27 01:31:20 +01:00
|
|
|
// turn filter's a=b,c=d OR a=b into an array
|
2001-02-21 23:41:37 +01:00
|
|
|
if ($filter) {
|
|
|
|
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; }
|
|
|
|
$filterarray = split(',',$filter);
|
|
|
|
if ($filterarray[1]) {
|
|
|
|
$i=0;
|
2001-02-27 01:31:20 +01:00
|
|
|
for ($i=0;$i<count($filterarray);$i++) {
|
|
|
|
list($name,$value) = split("=",$filterarray[$i]);
|
|
|
|
if ($name) {
|
|
|
|
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; }
|
|
|
|
$filterfields[$name] = $value;
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list($name,$value) = split('=',$filter);
|
|
|
|
if ($DEBUG) {
|
|
|
|
echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#";
|
|
|
|
}
|
|
|
|
$filterfields = array($name => $value);
|
|
|
|
}
|
|
|
|
|
2001-02-27 01:31:20 +01:00
|
|
|
// now check each element of the array and convert into SQL for queries
|
|
|
|
// below
|
2001-02-21 23:41:37 +01:00
|
|
|
$i=0;
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($filterfields);
|
2001-02-21 23:41:37 +01:00
|
|
|
while (list($name,$value) = each($filterfields)) {
|
|
|
|
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; }
|
2001-02-27 01:31:20 +01:00
|
|
|
$isstd=0;
|
|
|
|
if ($name && empty($value)) {
|
2001-03-18 19:49:19 +01:00
|
|
|
if ($DEBUG) { echo "<br>DEBUG - filter field '".$name."' is empty (NULL)"; }
|
|
|
|
$check_stock = $this->stock_contact_fields + array('id' => 'id', 'tid' => 'tid', 'lid' => 'lid', 'owner' => 'owner');
|
|
|
|
while (list($fname,$fvalue)=each($check_stock)) {
|
2001-02-27 01:31:20 +01:00
|
|
|
if ($fvalue==$name) {
|
|
|
|
$filterlist .= $name.' is NULL,';
|
2001-03-18 19:49:19 +01:00
|
|
|
if ($DEBUG) { echo "<br>DEBUG - filter field '".$name."' is a stock field"; }
|
2001-02-27 01:31:20 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif($name && $value) {
|
|
|
|
reset($stock_fields);
|
|
|
|
while (list($fname,$fvalue)=each($stock_fields)) {
|
|
|
|
if ($fvalue==$name) {
|
|
|
|
$filterlist .= $name.'="'.$value.'",';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
$i++;
|
|
|
|
}
|
2001-02-27 01:31:20 +01:00
|
|
|
$filterlist = substr($filterlist,0,-1);
|
|
|
|
$filterlist = ereg_replace(","," AND ",$filterlist);
|
2001-02-21 23:41:37 +01:00
|
|
|
|
|
|
|
if ($DEBUG) {
|
2001-03-18 19:49:19 +01:00
|
|
|
echo "<br>DEBUG - Filter output string: #".$filterlist."#";
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-02-27 01:31:20 +01:00
|
|
|
if ($filterlist) {
|
2001-03-18 19:49:19 +01:00
|
|
|
$filtermethod = '('.$filterlist.') ';
|
|
|
|
$fwhere = ' WHERE '; $fand = ' AND ';
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
2001-02-27 01:31:20 +01:00
|
|
|
if ($DEBUG && $filtermethod) {
|
|
|
|
echo "<br>DEBUG - Filtering with: #" . $filtermethod . "#";
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$sort) { $sort = "ASC"; }
|
|
|
|
|
|
|
|
if ($order) {
|
2001-03-18 19:49:19 +01:00
|
|
|
$ordermethod = "order by $order $sort ";
|
2001-02-21 23:41:37 +01:00
|
|
|
} else {
|
2001-03-18 19:49:19 +01:00
|
|
|
$ordermethod = "order by n_family,n_given,email $sort";
|
2001-02-27 01:31:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($DEBUG && $ordermethod) {
|
|
|
|
echo "<br>DEBUG - $ordermethod";
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-03-18 19:49:19 +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.
|
2001-03-22 01:23:40 +01:00
|
|
|
/* if ($start && $offset) {
|
2001-03-18 19:49:19 +01:00
|
|
|
$limit = $this->db->limit($start,$offset);
|
|
|
|
} elseif ($start && !$offset) {
|
|
|
|
$limit = "";
|
|
|
|
} elseif(!$start && !$offset) {
|
|
|
|
$limit = "";
|
|
|
|
} else { #(!$start && $offset) {
|
|
|
|
$start = 0;
|
|
|
|
$limit = $this->db->limit($start,$offset);
|
2001-02-27 01:31:20 +01:00
|
|
|
}
|
2001-03-22 01:23:40 +01:00
|
|
|
*/
|
2001-03-18 19:49:19 +01:00
|
|
|
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
|
2001-03-19 02:02:07 +01:00
|
|
|
/*
|
2001-02-27 01:31:20 +01:00
|
|
|
if ($query) {
|
2001-03-18 19:49:19 +01:00
|
|
|
$this->db3->query("SELECT * FROM $this->std_table WHERE (n_family LIKE '"
|
|
|
|
. "%$query%' OR n_given LIKE '%$query%' OR email LIKE '%$query%' OR "
|
|
|
|
. "adr_one_street LIKE '%$query%' OR adr_one_locality LIKE '%$query%' OR adr_one_region LIKE '%$query%' OR "
|
|
|
|
. "adr_one_postalcode LIKE '%$query%' OR adr_one_countryname LIKE '%$query%' OR "
|
|
|
|
. "adr_two_street LIKE '%$query%' OR adr_two_locality LIKE '%$query%' OR adr_two_region LIKE '%$query%' OR "
|
|
|
|
. "adr_two_postalcode LIKE '%$query%' OR adr_two_countryname LIKE '%$query%' OR "
|
|
|
|
. "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod,__LINE__,__FILE__);
|
|
|
|
$this->total_records = $this->db3->num_rows();
|
|
|
|
|
|
|
|
$this->db->query("SELECT * FROM $this->std_table WHERE (n_family LIKE '"
|
|
|
|
. "%$query%' OR n_given LIKE '%$query%' OR email LIKE '%$query%' OR "
|
|
|
|
. "adr_one_street LIKE '%$query%' OR adr_one_locality LIKE '%$query%' OR adr_one_region LIKE '%$query%' OR "
|
|
|
|
. "adr_one_postalcode LIKE '%$query%' OR adr_one_countryname LIKE '%$query%' OR "
|
|
|
|
. "adr_two_street LIKE '%$query%' OR adr_two_locality LIKE '%$query%' OR adr_two_region LIKE '%$query%' OR "
|
|
|
|
. "adr_two_postalcode LIKE '%$query%' OR adr_two_countryname LIKE '%$query%' OR "
|
|
|
|
. "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod . " "
|
|
|
|
. $limit,__LINE__,__FILE__);
|
|
|
|
} else {
|
|
|
|
$this->db3->query("SELECT id,lid,tid,owner $t_fields FROM $this->std_table " . $fwhere
|
|
|
|
. $filtermethod,__LINE__,__FILE__);
|
|
|
|
$this->total_records = $this->db3->num_rows();
|
|
|
|
|
|
|
|
$this->db->query("SELECT id,lid,tid,owner $t_fields FROM $this->std_table " . $fwhere
|
|
|
|
. $filtermethod . " " . $ordermethod . " " . $limit,__LINE__,__FILE__);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-19 02:02:07 +01:00
|
|
|
*/
|
2001-03-22 01:23:40 +01:00
|
|
|
|
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*".$owner);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
$this->total_records = ldap_count_entries($this->ldap, $sri);
|
|
|
|
|
|
|
|
// $end = $offset - $start;
|
|
|
|
// 92 records minus 0 = 92.
|
|
|
|
// 92 records minus 15 = 77.
|
|
|
|
$end = $start + $offset;
|
|
|
|
echo $end;
|
|
|
|
reset($ldap_fields);
|
|
|
|
for ($i=$start;$i<$end;$i++) {
|
2001-02-21 23:41:37 +01:00
|
|
|
// unique id, lid for group/account records,
|
2001-03-18 19:49:19 +01:00
|
|
|
// type id (g/u) for groups/accounts, and
|
2001-02-21 23:41:37 +01:00
|
|
|
// id of owner/parent for the record
|
2001-03-22 01:23:40 +01:00
|
|
|
$return_fields[$i]["id"] = $ldap_fields[$i]["uidnumber"][0];
|
|
|
|
$return_fields[$i]["lid"] = $ldap_fields[$i]["uid"][0];
|
|
|
|
$return_fields[$i]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0];
|
|
|
|
$return_fields[$i]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
|
2001-02-21 23:41:37 +01:00
|
|
|
|
|
|
|
if (gettype($stock_fieldnames) == "array") {
|
2001-03-22 01:23:40 +01:00
|
|
|
while (list($f_name,$f_value) = each($stock_fieldnames)) {
|
|
|
|
$return_fields[$i][$f_name] = $ldap_fields[$i][$f_value][0];
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-18 19:49:19 +01:00
|
|
|
reset($stock_fieldnames);
|
|
|
|
}
|
|
|
|
$this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
|
2001-03-22 01:23:40 +01:00
|
|
|
. $ldap_fields[$i]["id"] . "'",__LINE__,__FILE__);
|
2001-03-18 19:49:19 +01:00
|
|
|
while ($this->db2->next_record()) {
|
|
|
|
// If its not in the list to be returned, don't return it.
|
|
|
|
// This is still quicker then 5(+) separate queries
|
|
|
|
if ($extra_fields[$this->db2->f("contact_name")]) {
|
|
|
|
$return_fields[$i][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return_fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add($owner,$fields)
|
|
|
|
{
|
2001-03-19 02:02:07 +01:00
|
|
|
global $phpgw_info;
|
2001-02-21 23:41:37 +01:00
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
$phpgw_info['server']['contact_nextid']++;
|
|
|
|
$id = $phpgw_info['server']['contact_nextid'];
|
2001-02-21 23:41:37 +01:00
|
|
|
//$this->db->lock(array("contacts"));
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "uidnumber=".$id);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
2001-03-21 09:23:33 +01:00
|
|
|
if (!$ldap_fields[0]['dn'][0]) {
|
2001-03-19 02:02:07 +01:00
|
|
|
if (gettype($stock_fieldnames) == "array") {
|
|
|
|
while(list($name,$value)=each($stock_fieldnames)) {
|
|
|
|
$ldap_fields[0][$value][0] = $stock_fields[0][$name];
|
2001-03-21 09:23:33 +01:00
|
|
|
echo '<br>'.$ldap_fields[0][$value][0];
|
2001-03-19 02:02:07 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-19 02:02:07 +01:00
|
|
|
|
2001-03-21 09:23:33 +01:00
|
|
|
$time = gettimeofday();
|
|
|
|
$ldap_fields[0]['uid'][0] = time().$time["usec"].":".$ldap_fields[0]['givenname'][0];
|
|
|
|
$ldap_fields[0]['dn'][0] = 'uid=' . $ldap_fields[0]['uid'][0].',' . $phpgw_info["server"]["ldap_contact_context"];
|
|
|
|
$ldap_fields[0]['phpgwowner'][0] = $owner;
|
|
|
|
$ldap_fields[0]['uidnumber'][0] = $id;
|
|
|
|
|
|
|
|
echo $ldap_fields[0]['dn'][0]; exit;
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
$err = ldap_add($this->ldap, $ldap_fields[0]["dn"], $ldap_fields[0]);
|
|
|
|
|
|
|
|
//$this->db->unlock();
|
|
|
|
if (count($extra_fields)) {
|
|
|
|
while (list($name,$value) = each($extra_fields)) {
|
|
|
|
$this->db->query("insert into $this->ext_table values ('$id','" . $this->account_id . "','"
|
|
|
|
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return False;
|
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__);
|
|
|
|
}
|
|
|
|
|
|
|
|
function update($id,$owner,$fields)
|
|
|
|
{
|
|
|
|
// First make sure that id number exists
|
2001-03-19 02:02:07 +01:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "uidnumber=".$id);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
|
|
|
if ($ldap_fields[0]['dn']) {
|
|
|
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
|
|
|
if (count($stock_fields)) {
|
|
|
|
$ldap_fields[0]['phpgwowner'] = $owner;
|
|
|
|
$err = ldap_modify($this->ldap,$ldap_fields[0]['dn'],$stock_fields);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-03-19 02:02:07 +01:00
|
|
|
while (list($x_name,$x_value) = each($extra_fields)) {
|
|
|
|
if ($this->field_exists($id,$x_name)) {
|
|
|
|
if (! $x_value) {
|
|
|
|
$this->delete_single_extra_field($id,$x_name);
|
|
|
|
} else {
|
|
|
|
$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-02-21 23:41:37 +01: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-19 02:02:07 +01:00
|
|
|
} else {
|
|
|
|
return False;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-19 02:02:07 +01:00
|
|
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "uidnumber=".$id);
|
|
|
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
|
|
|
|
|
|
|
if ($ldap_fields[0]['dn']) {
|
|
|
|
$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__);
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
|
|
|
|
?>
|