mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-08 23:05:10 +02:00
add wraper function to support phpgw contact api
This commit is contained in:
@ -83,6 +83,82 @@
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the the person data what you want. Wrapper function to be compatible with phpgroupware
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// transform criteria from phpgw to egw structure
|
||||||
|
if(is_array($_criteria))
|
||||||
|
{
|
||||||
|
foreach($_criteria as $criteriaKey => $criteriaValue)
|
||||||
|
{
|
||||||
|
if($GLOBALS['phpgw_info']['server']['contact_repository'] == 'ldap')
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
function split_stock_and_extras($fields)
|
function split_stock_and_extras($fields)
|
||||||
{
|
{
|
||||||
settype($fields, 'array');
|
settype($fields, 'array');
|
||||||
|
@ -412,16 +412,24 @@
|
|||||||
#reset($this->stock_contact_fields);
|
#reset($this->stock_contact_fields);
|
||||||
#$myfilter = $this->makefilter($filterfields,$this->stock_contact_fields,$query,$DEBUG);
|
#$myfilter = $this->makefilter($filterfields,$this->stock_contact_fields,$query,$DEBUG);
|
||||||
|
|
||||||
// don't search about any fields any more
|
if(is_array($query))
|
||||||
$search_filter = array(
|
{
|
||||||
'fn' => 'cn',
|
// must be fixed somehow Milosch????
|
||||||
'n_given' => 'givenname',
|
$myfilter = $this->makefilter($filterfields,$query,'',$DEBUG);
|
||||||
'n_family' => 'sn',
|
}
|
||||||
'email' => 'mail',
|
else
|
||||||
'org_name' => 'o',
|
{
|
||||||
'org_unit' => 'ou'
|
// don't search about any fields any more
|
||||||
);
|
$search_filter = array(
|
||||||
$myfilter = $this->makefilter($filterfields,$search_filter,$query,$DEBUG);
|
'fn' => 'cn',
|
||||||
|
'n_given' => 'givenname',
|
||||||
|
'n_family' => 'sn',
|
||||||
|
'email' => 'mail',
|
||||||
|
'org_name' => 'o',
|
||||||
|
'org_unit' => 'ou'
|
||||||
|
);
|
||||||
|
$myfilter = $this->makefilter($filterfields,$search_filter,$query,$DEBUG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -534,7 +542,6 @@
|
|||||||
if($DEBUG) { echo '<br>Searching...'; }
|
if($DEBUG) { echo '<br>Searching...'; }
|
||||||
foreach($extra as $name => $value)
|
foreach($extra as $name => $value)
|
||||||
{
|
{
|
||||||
|
|
||||||
$qarray[] = array($value => $query);
|
$qarray[] = array($value => $query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
/**************************************************************************\
|
/**************************************************************************\
|
||||||
* phpGroupWare API - Contacts manager for SQL *
|
* phpGroupWare API - Contacts manager for SQL *
|
||||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||||
* and Miles Lott <milosch@phpgroupware.org> *
|
* and Miles Lott <milosch@phpgroupware.org> *
|
||||||
* View and manipulate contact records using SQL *
|
* View and manipulate contact records using SQL *
|
||||||
* Copyright (C) 2001 Joseph Engo *
|
* Copyright (C) 2001 Joseph Engo *
|
||||||
* ------------------------------------------------------------------------ *
|
* ------------------------------------------------------------------------ *
|
||||||
* This library is part of the phpGroupWare API *
|
* This library is part of the phpGroupWare API *
|
||||||
* http://www.phpgroupware.org/api *
|
* http://www.phpgroupware.org/api *
|
||||||
* ------------------------------------------------------------------------ *
|
* ------------------------------------------------------------------------ *
|
||||||
* This library is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* under the terms of the GNU Lesser General Public License as published by *
|
||||||
* the Free Software Foundation; either version 2.1 of the License, *
|
* the Free Software Foundation; either version 2.1 of the License, *
|
||||||
* or any later version. *
|
* or any later version. *
|
||||||
* This library is distributed in the hope that it will be useful, but *
|
* This library is distributed in the hope that it will be useful, but *
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
* See the GNU Lesser General Public License for more details. *
|
* See the GNU Lesser General Public License for more details. *
|
||||||
* You should have received a copy of the GNU Lesser General Public License *
|
* 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, *
|
* along with this library; if not, write to the Free Software Foundation, *
|
||||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||||
\**************************************************************************/
|
\**************************************************************************/
|
||||||
|
|
||||||
/* $Id$ */
|
/**
|
||||||
|
* This class provides a contact database scheme.
|
||||||
/*!
|
* It attempts to be based on the vcard 2.1 standard, with mods as needed
|
||||||
@class contacts_
|
* to make for more reasonable sql storage.
|
||||||
@abstract Contact Management System
|
* Note that changes here must also work in the LDAP version.
|
||||||
@discussion Author: jengo/Milosch <br>
|
* Syntax: CreateObject('phpgwapi.contacts');
|
||||||
This class provides a contact database scheme. <br>
|
* Example1: $contacts = CreateObject('phpgwapi.contacts');
|
||||||
It attempts to be based on the vcard 2.1 standard, with mods as needed to make for more reasonable sql storage. <br>
|
*
|
||||||
Note that changes here must also work in the LDAP version. <br>
|
* Last Editor: $Author$
|
||||||
Syntax: CreateObject('phpgwapi.contacts'); <br>
|
* @class contacts_
|
||||||
Example1: $contacts = CreateObject('phpgwapi.contacts');
|
* @abstract Contact Management System
|
||||||
|
* @author jengo/Milosch
|
||||||
|
* @version $Revision$
|
||||||
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
class contacts_
|
class contacts_
|
||||||
{
|
{
|
||||||
var $db = '';
|
var $db = '';
|
||||||
@ -507,19 +513,40 @@
|
|||||||
}
|
}
|
||||||
elseif($query)
|
elseif($query)
|
||||||
{
|
{
|
||||||
$query = str_replace("'",'',$query);
|
if(is_array($query))
|
||||||
$query = str_replace('"','',$query);
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM $this->std_table WHERE (";
|
|
||||||
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
|
|
||||||
foreach($this->stock_contact_fields as $f => $x)
|
|
||||||
{
|
{
|
||||||
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
$sql = "SELECT * FROM $this->std_table WHERE (";
|
||||||
$sqlcount .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
|
||||||
|
foreach($query as $queryKey => $queryValue)
|
||||||
|
{
|
||||||
|
// how to do real addslashes????
|
||||||
|
$queryKey = str_replace("'",'',$queryKey);
|
||||||
|
$queryKey = str_replace('"','',$queryKey);
|
||||||
|
$queryValue = str_replace("'",'',$queryValue);
|
||||||
|
$queryValue = str_replace('"','',$queryValue);
|
||||||
|
$sql .= " UPPER($queryKey) LIKE UPPER('$queryValue') AND ";
|
||||||
|
$sqlcount .= " UPPER($queryKey) LIKE UPPER('$queryValue') AND ";
|
||||||
|
}
|
||||||
|
$sql = substr($sql,0,-5) . ') ' . $fand . $filtermethod . $ordermethod;
|
||||||
|
$sqlcount = substr($sqlcount,0,-5) . ') ' . $fand . $filtermethod;
|
||||||
|
unset($queryKey); unset($queryValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$query = str_replace("'",'',$query);
|
||||||
|
$query = str_replace('"','',$query);
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM $this->std_table WHERE (";
|
||||||
|
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
|
||||||
|
foreach($this->stock_contact_fields as $f => $x)
|
||||||
|
{
|
||||||
|
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
||||||
|
$sqlcount .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
||||||
|
}
|
||||||
|
$sql = substr($sql,0,-3) . ') ' . $fand . $filtermethod . $ordermethod;
|
||||||
|
$sqlcount = substr($sqlcount,0,-3) . ') ' . $fand . $filtermethod;
|
||||||
|
unset($f); unset($x);
|
||||||
}
|
}
|
||||||
$sql = substr($sql,0,-3) . ') ' . $fand . $filtermethod . $ordermethod;
|
|
||||||
$sqlcount = substr($sqlcount,0,-3) . ') ' . $fand . $filtermethod;
|
|
||||||
unset($f); unset($x);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user