2001-01-25 04:03:45 +01:00
|
|
|
|
<?php
|
2003-10-25 12:14:25 +02:00
|
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
|
* eGroupWare API - Contact Management Shared Routines *
|
2003-10-25 12:14:25 +02:00
|
|
|
|
* Written by Joseph Engo <jengo@phpgroupware.org> *
|
2004-05-05 14:06:13 +02:00
|
|
|
|
* and Miles Lott <milosch@groupwhere.org> *
|
2003-10-25 12:14:25 +02:00
|
|
|
|
* and Bettina Gille <ceb@phpgroupware.org> *
|
|
|
|
|
* View and manipulate contact records *
|
|
|
|
|
* Copyright (C) 2001, 2002 Joseph Engo, Miles Lott, Bettina Gille *
|
2005-08-27 14:24:56 +02:00
|
|
|
|
* ------------------------------------------------------------------------ *
|
2004-05-05 14:06:13 +02:00
|
|
|
|
* This library is part of the eGroupWare API *
|
2005-08-27 14:24:56 +02:00
|
|
|
|
* http://www.egroupware.org *
|
2003-10-25 12:14:25 +02:00
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
|
* 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$ */
|
|
|
|
|
|
2005-08-27 14:24:56 +02:00
|
|
|
|
if (!isset($GLOBALS['egw_info']['server']['contact_repository']))
|
2001-05-21 11:12:10 +02:00
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$GLOBALS['egw_info']['server']['contact_repository'] = 'sql';
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
2005-08-27 14:24:56 +02:00
|
|
|
|
require_once(EGW_API_INC . '/class.contacts_'.$GLOBALS['egw_info']['server']['contact_repository'] . '.inc.php');
|
2003-10-25 12:14:25 +02:00
|
|
|
|
|
|
|
|
|
class contacts extends contacts_
|
|
|
|
|
{
|
|
|
|
|
function contacts()
|
|
|
|
|
{
|
|
|
|
|
$this->contacts_(); // call constructor of extended class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@function check_perms
|
|
|
|
|
@abstract checks if user has the necessary permissions on a contact
|
|
|
|
|
@syntax check_perms($rights,$needed,$addr=False)
|
|
|
|
|
@param $rights integer the rights the user has / grants from the owner of the contact, only used if $addr not given
|
|
|
|
|
@param $needed integer PHPGW_ACL_{READ|EDIT|DELETE}
|
|
|
|
|
@param $addr mixed contact-array or contact-id, if False rights have to be supplyed in $rights
|
|
|
|
|
*/
|
|
|
|
|
function check_perms($rights,$needed,$addr=False)
|
|
|
|
|
{
|
|
|
|
|
//echo "<p>contacts::check_perms($rights,$needed,".print_r($addr,True).")";
|
|
|
|
|
if ($addr !== False) // addr-record or id given
|
|
|
|
|
{
|
2003-12-10 12:36:54 +01:00
|
|
|
|
if(@is_array($addr))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (isset($addr['rights']))
|
|
|
|
|
{
|
|
|
|
|
$rights = $addr['rights'];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($addr['owner']))
|
|
|
|
|
{
|
|
|
|
|
$rights = $this->grants[$addr['owner']];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-12-10 12:36:54 +01:00
|
|
|
|
$id = (int)(isset($addr['id']) ? $addr['id'] : $addr['ab_id']);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-12-10 12:36:54 +01:00
|
|
|
|
$id = (int)$addr;
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
if (isset($id))
|
|
|
|
|
{
|
|
|
|
|
$addr = $this->read_single_entry($id,array('owner' => 'owner'));
|
|
|
|
|
$rights = @$addr[0]['rights'];
|
|
|
|
|
//echo "addr($id)=<pre>".print_r($addr[0],True)."</pre>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-10 12:36:54 +01:00
|
|
|
|
$ret = !!((int)$rights & $needed);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
//echo " rights=$rights, id=$id => ".($ret?'True':'False')."</p>\n";
|
|
|
|
|
//echo "grants=<pre>".print_r($this->grants,True)."</pre>\n";
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-22 16:34:32 +01:00
|
|
|
|
/**
|
2004-05-05 14:06:13 +02:00
|
|
|
|
* Get the the person data what you want. Wrapper function to stay compatible with egroupware.
|
2004-03-22 16:34:32 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Lars Kneschke <lars@kneschke.de>
|
|
|
|
|
* @param array $fields The fields that you can see from person
|
|
|
|
|
* @param integer $limit Limit of records that you want
|
|
|
|
|
* @param integer $ofset Ofset of record that you want start
|
|
|
|
|
* @param string $orderby The field which you want order
|
|
|
|
|
* @param string $sort ASC | DESC depending what you want
|
|
|
|
|
* @param mixed $criteria All criterias what you want
|
|
|
|
|
* @param mixed $criteria_token same like $criteria but builded<br>with sql_criteria class, more powerfull
|
|
|
|
|
* @return array with records
|
|
|
|
|
*/
|
|
|
|
|
function get_persons($_fields, $start='', $limit='', $orderby='', $sort='', $_criteria='', $token_criteria='')
|
|
|
|
|
{
|
|
|
|
|
// transform fields from phpgw to egw structure
|
|
|
|
|
foreach($_fields as $fieldValue)
|
|
|
|
|
{
|
|
|
|
|
switch($fieldValue)
|
|
|
|
|
{
|
|
|
|
|
case 'per_first_name':
|
|
|
|
|
$fields['n_given']='n_given';
|
|
|
|
|
case 'per_last_name':
|
|
|
|
|
$fields['n_family']='n_family';
|
|
|
|
|
default:
|
|
|
|
|
$fields[$fieldValue]=$fieldValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-08-27 14:24:56 +02:00
|
|
|
|
|
2004-03-22 16:34:32 +01:00
|
|
|
|
// transform criteria from phpgw to egw structure
|
|
|
|
|
if(is_array($_criteria))
|
|
|
|
|
{
|
|
|
|
|
foreach($_criteria as $criteriaKey => $criteriaValue)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
if($GLOBALS['egw_info']['server']['contact_repository'] == 'ldap')
|
2004-03-22 16:34:32 +01:00
|
|
|
|
{
|
|
|
|
|
switch($criteriaKey)
|
|
|
|
|
{
|
|
|
|
|
case 'contact_id':
|
|
|
|
|
$criteria['uid']=$criteriaValue;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$criteria[$criteriaKey] = $criteria[$criteriaValue];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch($criteriaKey)
|
|
|
|
|
{
|
|
|
|
|
case 'contact_id':
|
|
|
|
|
$criteria['id']=$criteriaValue;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$criteria[$criteriaKey] = $criteria[$criteriaValue];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$entries = $this->read($start,$limit,$fields,$criteria,'',$sort,$orderby);
|
2005-08-27 14:24:56 +02:00
|
|
|
|
|
2004-03-22 16:34:32 +01:00
|
|
|
|
// transform entries from egw to phpgw structure
|
|
|
|
|
if(is_array($entries))
|
|
|
|
|
{
|
|
|
|
|
foreach($entries as $entryKey => $entryValue)
|
|
|
|
|
{
|
|
|
|
|
$entryValue['per_first_name'] = $entryValue['n_given'];
|
|
|
|
|
$entryValue['per_last_name'] = $entryValue['n_family'];
|
|
|
|
|
$entryValue['contact_id'] = $entryValue['id'];
|
|
|
|
|
$entries[$entryKey] = $entryValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $entries;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-25 12:14:25 +02:00
|
|
|
|
function split_stock_and_extras($fields)
|
|
|
|
|
{
|
2004-01-17 04:21:21 +01:00
|
|
|
|
settype($fields, 'array');
|
|
|
|
|
foreach($fields as $field => $value)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
/* Depending on how the array was built, this is needed. */
|
2004-03-07 10:54:37 +01:00
|
|
|
|
if (is_int($field))
|
|
|
|
|
{
|
|
|
|
|
$field = $value;
|
|
|
|
|
}
|
2003-12-10 12:36:54 +01:00
|
|
|
|
if(@is_int($value))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$value = $field;
|
|
|
|
|
}
|
|
|
|
|
if ($this->stock_contact_fields[$field])
|
|
|
|
|
{
|
|
|
|
|
$stock_fields[$field] = $value;
|
|
|
|
|
$stock_fieldnames[$field] = $this->stock_contact_fields[$field];
|
|
|
|
|
}
|
2003-11-14 22:20:55 +01:00
|
|
|
|
elseif (!isset($this->non_contact_fields[$field]))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$extra_fields[$field] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return array($stock_fields,$stock_fieldnames,$extra_fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loop_addslashes($fields)
|
|
|
|
|
{
|
|
|
|
|
$absf = $this->stock_contact_fields;
|
2004-01-17 04:21:21 +01:00
|
|
|
|
foreach($absf as $t => $nul)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2004-01-17 04:21:21 +01:00
|
|
|
|
$ta[] = $this->db->db_addslashes($fields[$t]);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
return $ta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This will take an array or integer */
|
|
|
|
|
function delete($id)
|
|
|
|
|
{
|
2003-12-10 12:36:54 +01:00
|
|
|
|
if(@is_array($id))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2004-01-17 04:21:21 +01:00
|
|
|
|
foreach($id as $nul => $t_id)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$this->delete_($t_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$this->delete_($id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function asc_sort($a,$b)
|
|
|
|
|
{
|
|
|
|
|
echo "<br>A:'".$a."' B:'".$b;
|
2004-01-17 04:21:21 +01:00
|
|
|
|
if($a[1] == $b[1])
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-10-25 12:14:25 +02:00
|
|
|
|
return ($a[1]>$b[1])?1:-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function desc_sort($a,$b)
|
|
|
|
|
{
|
|
|
|
|
echo "<br>A:'".$a."' B:'".$b;
|
2004-01-17 04:21:21 +01:00
|
|
|
|
if($a[1]==$b[1])
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-10-25 12:14:25 +02:00
|
|
|
|
return ($a[1]<$b[1])?1:-1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-28 15:10:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* To be used in usort()
|
|
|
|
|
*
|
|
|
|
|
* compares two 2-dimensional arrays a and b.
|
|
|
|
|
* The first dimension holds the key, the array is sorted by.
|
|
|
|
|
* The second dimension holds the data, that's actually string-compared.
|
2003-10-25 12:14:25 +02:00
|
|
|
|
*
|
2005-09-28 15:10:22 +02:00
|
|
|
|
* @author Carsten Wolff <wolffc@egroupware.org>
|
|
|
|
|
* @param array $fields The fields, the array is to be sorted by. Use of multiple keys is for subsorting.
|
|
|
|
|
* @param string $order ASC | DESC ascending or descending order
|
|
|
|
|
* @param array $a one item
|
|
|
|
|
* @param array $b the other item
|
|
|
|
|
* @return integer -1 | 0 | 1 equals: a is smaller | the same | larger than b.
|
2003-10-25 12:14:25 +02:00
|
|
|
|
*/
|
2005-09-28 15:10:22 +02:00
|
|
|
|
function _cmp($fields, $order, $a, $b)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-09-28 15:10:22 +02:00
|
|
|
|
foreach ($fields as $field)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-09-28 15:10:22 +02:00
|
|
|
|
$result = strcasecmp($a[$field][0], $b[$field][0]);
|
|
|
|
|
if ($result == 0)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-09-28 15:10:22 +02:00
|
|
|
|
continue;
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
2005-09-28 15:10:22 +02:00
|
|
|
|
if ($order == "DESC")
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-09-28 15:10:22 +02:00
|
|
|
|
return -$result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return $result;
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-09-28 15:10:22 +02:00
|
|
|
|
return 0;
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatted_address($id, $business = True, $afont = '', $asize = '2')
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
|
2003-10-25 12:14:25 +02:00
|
|
|
|
$s = CreateObject('phpgwapi.sbox');
|
|
|
|
|
|
2003-12-10 12:36:54 +01:00
|
|
|
|
$fields = array(
|
|
|
|
|
'n_given' => 'n_given',
|
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
|
'title' => 'title',
|
|
|
|
|
'org_name' => 'org_name',
|
|
|
|
|
'org_unit' => 'org_unit',
|
|
|
|
|
'adr_one_street' => 'adr_one_street',
|
|
|
|
|
'adr_one_locality' => 'adr_one_locality',
|
|
|
|
|
'adr_one_postalcode' => 'adr_one_postalcode',
|
|
|
|
|
'adr_one_region' => 'adr_one_region',
|
|
|
|
|
'adr_one_countryname' => 'adr_one_countryname',
|
|
|
|
|
'adr_two_street' => 'adr_two_street',
|
|
|
|
|
'adr_two_locality' => 'adr_two_locality',
|
|
|
|
|
'adr_two_postalcode' => 'adr_two_postalcode',
|
|
|
|
|
'adr_two_region' => 'adr_two_region',
|
|
|
|
|
'adr_two_countryname' => 'adr_two_countryname'
|
2003-10-25 12:14:25 +02:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
list($address) = $this->read_single_entry($id,$fields);
|
|
|
|
|
foreach($address as $k => $val)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$address[$k] = $GLOBALS['egw']->strip_html($val);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($address['title'])
|
|
|
|
|
{
|
|
|
|
|
$title = $address['title'] . ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($business)
|
|
|
|
|
{
|
|
|
|
|
if ($address['org_name'])
|
|
|
|
|
{
|
|
|
|
|
$company = $address['org_name'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$street = $address['adr_one_street'];
|
|
|
|
|
$city = $address['adr_one_locality'];
|
|
|
|
|
$zip = $address['adr_one_postalcode'];
|
|
|
|
|
$state = $address['adr_one_region'];
|
|
|
|
|
$country = $address['adr_one_countryname'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
$street = $address['adr_two_street'];
|
|
|
|
|
$city = $address['adr_two_locality'];
|
|
|
|
|
$zip = $address['adr_two_postalcode'];
|
|
|
|
|
$state = $address['adr_two_region'];
|
|
|
|
|
$country = $address['adr_two_countryname'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $country)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'format_' . strtolower($country) . '.tpl'))
|
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'format_' . strtolower($country) . '.tpl'));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'format_us.tpl'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$afont)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$afont = $GLOBALS['egw_info']['theme']['font'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->set_var('font',$afont);
|
|
|
|
|
$a .= $t->set_var('fontsize',$asize);
|
|
|
|
|
$a .= $t->set_var('company',$company);
|
|
|
|
|
$a .= $t->set_var('department',$address['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);
|
|
|
|
|
|
2005-08-27 14:24:56 +02:00
|
|
|
|
if ($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$countryname = $s->get_full_name($country);
|
|
|
|
|
$a .= $t->set_var('country',lang($countryname));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->fp('out','address_format');
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatted_address_full($id, $business = True, $afont = '', $asize = '2')
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
|
2003-10-25 12:14:25 +02:00
|
|
|
|
$s = CreateObject('phpgwapi.sbox');
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
$fields = array(
|
2003-10-25 12:14:25 +02:00
|
|
|
|
'n_given' => 'n_given',
|
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
|
'title' => 'title',
|
|
|
|
|
'org_name' => 'org_name',
|
|
|
|
|
'org_unit' => 'org_unit',
|
|
|
|
|
'adr_one_street' => 'adr_one_street',
|
|
|
|
|
'adr_one_locality' => 'adr_one_locality',
|
|
|
|
|
'adr_one_postalcode' => 'adr_one_postalcode',
|
|
|
|
|
'adr_one_region' => 'adr_one_region',
|
|
|
|
|
'tel_work' => 'tel_work',
|
|
|
|
|
'tel_fax' => 'tel_fax',
|
|
|
|
|
'email' => 'email',
|
|
|
|
|
'url' => 'url',
|
|
|
|
|
'adr_one_countryname' => 'adr_one_countryname',
|
|
|
|
|
'adr_two_street' => 'adr_two_street',
|
|
|
|
|
'adr_two_locality' => 'adr_two_locality',
|
|
|
|
|
'adr_two_postalcode' => 'adr_two_postalcode',
|
|
|
|
|
'adr_two_region' => 'adr_two_region',
|
|
|
|
|
'adr_two_countryname' => 'adr_two_countryname',
|
|
|
|
|
'tel_home' => 'tel_home',
|
|
|
|
|
'email_home' => 'email_home'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
list($address) = $this->read_single_entry($id,$fields);
|
|
|
|
|
foreach($address as $k => $val)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$address[$k] = $GLOBALS['egw']->strip_html($val);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($address['title'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$title = $address['title'] . ' ';
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($business)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($address['org_name'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$company = $address['org_name'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$street = $address['adr_one_street'];
|
|
|
|
|
$city = $address['adr_one_locality'];
|
|
|
|
|
$zip = $address['adr_one_postalcode'];
|
|
|
|
|
$state = $address['adr_one_region'];
|
|
|
|
|
$country = $address['adr_one_countryname'];
|
|
|
|
|
$tel = $address['tel_work'];
|
|
|
|
|
$email = $address['email'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
$street = $address['adr_two_street'];
|
|
|
|
|
$city = $address['adr_two_locality'];
|
|
|
|
|
$zip = $address['adr_two_postalcode'];
|
|
|
|
|
$state = $address['adr_two_region'];
|
|
|
|
|
$country = $address['adr_two_countryname'];
|
|
|
|
|
$tel = $address['tel_home'];
|
|
|
|
|
$email = $address['email_home'];
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(!$country)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'full_format_' . strtolower($country) . '.tpl'))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'full_format_' . strtolower($country) . '.tpl'));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'full_format_us.tpl'));
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(!$afont)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$afont = $GLOBALS['egw_info']['theme']['font'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->set_var('font',$afont);
|
|
|
|
|
$a .= $t->set_var('fontsize',$asize);
|
|
|
|
|
$a .= $t->set_var('lang_url',lang('url'));
|
|
|
|
|
$a .= $t->set_var('lang_email',lang('email'));
|
|
|
|
|
$a .= $t->set_var('lang_fax',lang('fax number'));
|
|
|
|
|
$a .= $t->set_var('lang_fon',lang('phone number'));
|
|
|
|
|
$a .= $t->set_var('company',$company);
|
|
|
|
|
$a .= $t->set_var('department',$address['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('email',$email);
|
|
|
|
|
$a .= $t->set_var('tel',$tel);
|
|
|
|
|
$a .= $t->set_var('fax',$address['tel_fax']);
|
|
|
|
|
$a .= $t->set_var('url',$address['url']);
|
|
|
|
|
|
2005-08-27 14:24:56 +02:00
|
|
|
|
if($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$countryname = $s->get_full_name($country);
|
|
|
|
|
$a .= $t->set_var('country',lang($countryname));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->fp('out','address_format');
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatted_address_line($id, $business = True, $afont = '', $asize = '2')
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$t = CreateObject('phpgwapi.Template',$GLOBALS['egw']->common->get_tpl_dir('addressbook'));
|
2003-10-25 12:14:25 +02:00
|
|
|
|
$s = CreateObject('phpgwapi.sbox');
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
$fields = array(
|
2003-10-25 12:14:25 +02:00
|
|
|
|
'n_given' => 'n_given',
|
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
|
'title' => 'title',
|
|
|
|
|
'org_name' => 'org_name',
|
|
|
|
|
'adr_one_street' => 'adr_one_street',
|
|
|
|
|
'adr_one_locality' => 'adr_one_locality',
|
|
|
|
|
'adr_one_postalcode' => 'adr_one_postalcode',
|
|
|
|
|
'adr_one_region' => 'adr_one_region',
|
|
|
|
|
'adr_one_countryname' => 'adr_one_countryname',
|
|
|
|
|
'adr_two_street' => 'adr_two_street',
|
|
|
|
|
'adr_two_locality' => 'adr_two_locality',
|
|
|
|
|
'adr_two_postalcode' => 'adr_two_postalcode',
|
|
|
|
|
'adr_two_region' => 'adr_two_region',
|
|
|
|
|
'adr_two_countryname' => 'adr_two_countryname'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
list($address) = $this->read_single_entry($id,$fields);
|
|
|
|
|
foreach($address as $k => $val)
|
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$address[$k] = $GLOBALS['egw']->strip_html($val);
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($address['title'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$title = $address['title'] . ' ';
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($business)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if($address['org_name'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$company = $address['org_name'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$street = $address['adr_one_street'];
|
|
|
|
|
$city = $address['adr_one_locality'];
|
|
|
|
|
$zip = $address['adr_one_postalcode'];
|
|
|
|
|
$state = $address['adr_one_region'];
|
|
|
|
|
$country = $address['adr_one_countryname'];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$company = $title . $address['n_given'] . ' ' . $address['n_family'];
|
|
|
|
|
$street = $address['adr_two_street'];
|
|
|
|
|
$city = $address['adr_two_locality'];
|
|
|
|
|
$zip = $address['adr_two_postalcode'];
|
|
|
|
|
$state = $address['adr_two_region'];
|
|
|
|
|
$country = $address['adr_two_countryname'];
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(!$country)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$country = $GLOBALS['egw_info']['user']['preferences']['common']['country'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'line_format_' . strtolower($country) . '.tpl'))
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'line_format_' . strtolower($country) . '.tpl'));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$a = $t->set_file(array('address_format' => 'line_format_us.tpl'));
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-24 16:57:57 +01:00
|
|
|
|
if(!$afont)
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
2005-08-27 14:24:56 +02:00
|
|
|
|
$afont = $GLOBALS['egw_info']['theme']['font'];
|
2003-10-25 12:14:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->set_var('font',$afont);
|
|
|
|
|
$a .= $t->set_var('fontsize',$asize);
|
|
|
|
|
$a .= $t->set_var('company',$company);
|
|
|
|
|
$a .= $t->set_var('street',$street);
|
|
|
|
|
$a .= $t->set_var('city',$city);
|
|
|
|
|
$a .= $t->set_var('zip',$zip);
|
|
|
|
|
$a .= $t->set_var('state',$state);
|
|
|
|
|
|
2005-08-27 14:24:56 +02:00
|
|
|
|
if($country != $GLOBALS['egw_info']['user']['preferences']['common']['country'])
|
2003-10-25 12:14:25 +02:00
|
|
|
|
{
|
|
|
|
|
$countryname = $s->get_full_name($country);
|
|
|
|
|
$a .= $t->set_var('country',' <3B> ' . lang($countryname));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a .= $t->fp('out','address_format');
|
|
|
|
|
return $a;
|
|
|
|
|
}
|
2001-05-21 11:12:10 +02:00
|
|
|
|
}
|
2001-01-25 08:07:04 +01:00
|
|
|
|
?>
|