2001-02-02 08:00:58 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Accounts manager for SQL *
|
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* View and manipulate contact records *
|
|
|
|
* 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-02-11 05:16:18 +01:00
|
|
|
class contacts extends contacts_
|
|
|
|
{
|
2001-03-24 10:58:09 +01:00
|
|
|
function check_perms($has, $needed)
|
|
|
|
{
|
|
|
|
return (!!($has & $needed) == True);
|
|
|
|
}
|
|
|
|
|
2001-02-11 05:16:18 +01:00
|
|
|
function split_stock_and_extras($fields)
|
|
|
|
{
|
|
|
|
while (list($field,$value) = each($fields)) {
|
|
|
|
// Depending on how the array was build, this is needed.
|
|
|
|
// Yet, I can't figure out why ....
|
2001-02-21 23:41:37 +01:00
|
|
|
if (gettype($value) == "integer") {
|
2001-02-11 05:16:18 +01:00
|
|
|
$field = $value;
|
|
|
|
}
|
|
|
|
if ($this->stock_contact_fields[$field]) {
|
|
|
|
$stock_fields[$field] = $value;
|
2001-03-19 04:45:46 +01:00
|
|
|
$stock_fieldnames[$field] = $this->stock_contact_fields[$field];
|
2001-02-11 05:16:18 +01:00
|
|
|
} else {
|
|
|
|
$extra_fields[$field] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array($stock_fields,$stock_fieldnames,$extra_fields);
|
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
|
2001-02-11 05:16:18 +01:00
|
|
|
function loop_addslashes($fields)
|
|
|
|
{
|
|
|
|
$absf = $this->stock_contact_fields;
|
|
|
|
while ($t = each($absf)) {
|
|
|
|
$ta[] = addslashes($fields[$t[0]]);
|
|
|
|
}
|
|
|
|
reset($absf); // Is this needed ?
|
|
|
|
return $ta;
|
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
|
2001-02-11 05:16:18 +01:00
|
|
|
// This will take an array or integer
|
|
|
|
function delete($id)
|
|
|
|
{
|
|
|
|
if (gettype($id) == "array") {
|
|
|
|
while (list($null,$t_id) = each($id)) {
|
|
|
|
$this->delete_($t_id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->delete_($id);
|
|
|
|
}
|
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
function asc_sort($a,$b)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
echo "<br>A:'".$a."' B:'".$b;
|
2001-04-09 14:54:43 +02:00
|
|
|
if($a[1]==$b[1]) return 0;
|
|
|
|
return ($a[1]>$b[1])?1:-1;
|
2001-03-22 20:48:14 +01:00
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
function desc_sort($a,$b)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
echo "<br>A:'".$a."' B:'".$b;
|
2001-04-09 14:54:43 +02:00
|
|
|
if($a[1]==$b[1]) return 0;
|
|
|
|
return ($a[1]<$b[1])?1:-1;
|
2001-03-22 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
/**
|
|
|
|
** comesafter ($s1, $s2)
|
|
|
|
**
|
|
|
|
** Returns 1 if $s1 comes after $s2 alphabetically, 0 if not.
|
|
|
|
**/
|
|
|
|
function comesafter ($s1, $s2)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
** We don't want to overstep the bounds of one of the strings and segfault,
|
|
|
|
** so let's see which one is shorter.
|
|
|
|
**/
|
2001-03-22 20:48:14 +01:00
|
|
|
$order = 1;
|
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
if ( (strlen($s1) == 0) )
|
|
|
|
{
|
2001-03-22 21:05:32 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2001-04-09 14:54:43 +02:00
|
|
|
|
|
|
|
if ( (strlen($s2) == 0) )
|
|
|
|
{
|
2001-03-22 21:05:32 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
if (strlen ($s1) > strlen ($s2))
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$temp = $s1;
|
|
|
|
$s1 = $s2;
|
|
|
|
$s2 = $temp;
|
|
|
|
$order = 0;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
for ($index = 0; $index < strlen ($s1); $index++)
|
|
|
|
{
|
|
|
|
/* $s1 comes after $s2 */
|
2001-03-22 20:48:14 +01:00
|
|
|
if (strtolower($s1[$index]) > strtolower($s2[$index])) { return ($order); }
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-03-22 20:48:14 +01:00
|
|
|
/* $s1 comes before $s2 */
|
|
|
|
if (strtolower($s1[$index]) < strtolower($s2[$index])) { return (1 - $order); }
|
|
|
|
}
|
|
|
|
/* Special case in which $s1 is a substring of $s2 */
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
return ($order);
|
2001-03-22 20:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* asortbyindex ($sortarray, $index)
|
|
|
|
*
|
|
|
|
* Sort a multi-dimensional array by a second-degree index. For instance, the 0th index
|
|
|
|
* of the Ith member of both the group and user arrays is a string identifier. In the
|
|
|
|
* case of a user array this is the username; with the group array it is the group name.
|
|
|
|
* asortby
|
|
|
|
*/
|
2001-03-27 19:15:47 +02:00
|
|
|
function asortbyindex ($sortarray, $index)
|
|
|
|
{
|
2001-03-22 21:05:32 +01:00
|
|
|
$lastindex = count($sortarray) - 2;
|
2001-03-27 19:15:47 +02:00
|
|
|
for ($subindex = 0; $subindex < $lastindex; $subindex++)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$lastiteration = $lastindex - $subindex;
|
2001-03-27 19:15:47 +02:00
|
|
|
for ($iteration = 0; $iteration < $lastiteration; $iteration++)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$nextchar = 0;
|
2001-03-27 19:15:47 +02:00
|
|
|
if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index]))
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$temp = $sortarray[$iteration];
|
|
|
|
$sortarray[$iteration] = $sortarray[$iteration + 1];
|
|
|
|
$sortarray[$iteration + 1] = $temp;
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-22 20:48:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ($sortarray);
|
|
|
|
}
|
2001-02-21 23:41:37 +01:00
|
|
|
|
2001-03-27 19:15:47 +02:00
|
|
|
function arsortbyindex ($sortarray, $index)
|
|
|
|
{
|
2001-03-22 21:05:32 +01:00
|
|
|
$lastindex = count($sortarray) - 1;
|
2001-03-27 19:15:47 +02:00
|
|
|
for ($subindex = $lastindex; $subindex > 0; $subindex--)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$lastiteration = $lastindex - $subindex;
|
2001-03-27 19:15:47 +02:00
|
|
|
for ($iteration = $lastiteration; $iteration > 0; $iteration--)
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$nextchar = 0;
|
2001-03-27 19:15:47 +02:00
|
|
|
if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index]))
|
|
|
|
{
|
2001-03-22 20:48:14 +01:00
|
|
|
$temp = $sortarray[$iteration];
|
|
|
|
$sortarray[$iteration] = $sortarray[$iteration - 1];
|
|
|
|
$sortarray[$iteration - 1] = $temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ($sortarray);
|
2001-02-21 23:41:37 +01:00
|
|
|
}
|
2001-03-27 16:33:16 +02:00
|
|
|
|
2001-03-27 19:15:47 +02:00
|
|
|
function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0)
|
|
|
|
{
|
2001-03-27 16:33:16 +02:00
|
|
|
$match = 0;
|
2001-03-27 19:15:47 +02:00
|
|
|
if($DEBUG) { echo "<br>"; }
|
2001-03-27 16:33:16 +02:00
|
|
|
for($i=0;$i<count($ldap_fields);$i++) {
|
2001-03-29 18:07:34 +02:00
|
|
|
$yes = True;
|
2001-03-27 19:15:47 +02:00
|
|
|
|
2001-04-09 14:54:43 +02:00
|
|
|
if ($ldap_fields[$i]["uidnumber"][0])
|
2001-03-27 19:15:47 +02:00
|
|
|
{
|
2001-04-09 14:54:43 +02:00
|
|
|
reset($filterfields);
|
|
|
|
while (list($col,$filt) = each($filterfields))
|
|
|
|
{
|
2001-05-26 14:37:24 +02:00
|
|
|
if ($col == 'phpgwcontactcatid')
|
2001-04-09 14:54:43 +02:00
|
|
|
{
|
2001-05-26 14:37:24 +02:00
|
|
|
$colarray = explode(',',$ldap_fields[$i][$col][0]);
|
|
|
|
if ($colarray[1])
|
|
|
|
{
|
|
|
|
while(list($key,$val) = each ($colarray))
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' Testing "'.$col.'" for "'.$val.'"'; }
|
|
|
|
if ($val == $filt)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched.'." "; }
|
|
|
|
$yes &= True;
|
|
|
|
$match++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' Testing "'.$col.'" for "'.$filt.'"'; }
|
|
|
|
if ($ldap_fields[$i][$col][0] == $filt)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched.'." "; }
|
|
|
|
$yes &= True;
|
|
|
|
$match++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ', but number '.$ldap_fields[$i]["uidnumber"][0].' did not match.'." "; }
|
|
|
|
$yes &= False;
|
|
|
|
$match--;
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 14:54:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-26 14:37:24 +02:00
|
|
|
if($DEBUG) { echo ' Testing "'.$col.'" for "'.$filt.'"'; }
|
|
|
|
if ($ldap_fields[$i][$col][0] == $filt)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched.'." "; }
|
|
|
|
$yes &= True;
|
|
|
|
$match++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ', but number '.$ldap_fields[$i]["uidnumber"][0].' did not match.'." "; }
|
|
|
|
$yes &= False;
|
|
|
|
$match--;
|
|
|
|
}
|
2001-04-09 14:54:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($yes)
|
2001-03-27 19:15:47 +02:00
|
|
|
{
|
2001-04-09 14:54:43 +02:00
|
|
|
if($DEBUG) { echo $ldap_fields[$i]["uidnumber"][0].' matched all!'."<br>"; }
|
|
|
|
$new_ldap[] = $ldap_fields[$i];
|
2001-03-27 19:15:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-04-09 14:54:43 +02:00
|
|
|
if($DEBUG) { echo $ldap_fields[$i]["uidnumber"][0].' did not match all.'."<br>"; }
|
2001-03-27 16:33:16 +02:00
|
|
|
}
|
|
|
|
}
|
2001-04-09 14:54:43 +02:00
|
|
|
}
|
|
|
|
if($DEBUG)
|
|
|
|
{
|
|
|
|
if($match)
|
2001-03-27 19:15:47 +02:00
|
|
|
{
|
2001-04-09 14:54:43 +02:00
|
|
|
echo '<br>'.$match.' total matches.'."\n";
|
2001-03-27 16:33:16 +02:00
|
|
|
}
|
2001-03-27 19:15:47 +02:00
|
|
|
else
|
|
|
|
{
|
2001-04-09 14:54:43 +02:00
|
|
|
echo '<br>No matches :('."\n";
|
2001-03-27 19:15:47 +02:00
|
|
|
}
|
2001-03-27 16:33:16 +02:00
|
|
|
}
|
|
|
|
$this->total_records = count($new_ldap);
|
|
|
|
|
|
|
|
return $new_ldap;
|
|
|
|
}
|
2001-06-22 07:29:43 +02:00
|
|
|
|
|
|
|
function formatted_address($id = '',$fields = '',$business = True)
|
|
|
|
{
|
|
|
|
global $phpgw,$phpgw_info;
|
|
|
|
|
|
|
|
$font = $phpgw_info['theme']['font'];
|
|
|
|
|
|
|
|
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
|
|
|
|
|
|
|
|
$address = $this->read_single_entry($id,$fields);
|
|
|
|
|
|
|
|
if ($address[0]['title'])
|
|
|
|
{
|
|
|
|
$title = $address[0]['title'] . ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($business)
|
|
|
|
{
|
|
|
|
$street = $address[0]['adr_one_street'];
|
|
|
|
$city = $address[0]['adr_one_locality'];
|
|
|
|
$zip = $address[0]['adr_one_postalcode'];
|
|
|
|
$state = $address[0]['adr_one_region'];
|
|
|
|
$country = $address[0]['adr_one_countryname'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$street = $address[0]['adr_two_street'];
|
|
|
|
$city = $address[0]['adr_two_locality'];
|
|
|
|
$zip = $address[0]['adr_two_postalcode'];
|
|
|
|
$state = $address[0]['adr_two_region'];
|
|
|
|
$country = $address[0]['adr_two_countryname'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $country)
|
|
|
|
{
|
|
|
|
$country = $phpgw_info['user']['preferences']['common']['country'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($country == 'DE')
|
|
|
|
{
|
2001-06-22 07:55:15 +02:00
|
|
|
$a = $t->set_file(array('address_format' => 'format_de.tpl'));
|
2001-06-22 07:29:43 +02:00
|
|
|
}
|
|
|
|
elseif ($country == 'US')
|
|
|
|
{
|
2001-06-22 07:55:15 +02:00
|
|
|
$a = $t->set_file(array('address_format' => 'format_us.tpl'));
|
2001-06-22 07:29:43 +02:00
|
|
|
}
|
|
|
|
|
2001-06-22 07:55:15 +02:00
|
|
|
$a .= $t->set_var('font',$font);
|
|
|
|
$a .= $t->set_var('title',$title);
|
|
|
|
$a .= $t->set_var('firstname',$address[0]['n_given']);
|
|
|
|
$a .= $t->set_var('lastname',$address[0]['n_family']);
|
|
|
|
$a .= $t->set_var('company',$address[0]['org_name']);
|
|
|
|
$a .= $t->set_var('department',$address[0]['org_unit']);
|
|
|
|
$a .= $t->set_var('street',$street);
|
|
|
|
$a .= $t->set_var('city',$city);
|
|
|
|
$a .= $t->set_var('zip',$zip);
|
|
|
|
$a .= $t->set_var('state',$state);
|
|
|
|
$a .= $t->set_var('country',lang($country));
|
2001-06-22 07:29:43 +02:00
|
|
|
|
2001-06-22 07:55:15 +02:00
|
|
|
$a .= $t->fp('out','address_format');
|
|
|
|
return $a;
|
2001-06-22 07:29:43 +02:00
|
|
|
}
|
2001-02-11 05:16:18 +01:00
|
|
|
}
|
2001-02-02 08:00:58 +01:00
|
|
|
?>
|