mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-11 00:18:25 +01:00
add wraper function to support phpgw contact api
This commit is contained in:
parent
9ec5c51938
commit
269756f577
@ -83,6 +83,82 @@
|
||||
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)
|
||||
{
|
||||
settype($fields, 'array');
|
||||
|
@ -412,6 +412,13 @@
|
||||
#reset($this->stock_contact_fields);
|
||||
#$myfilter = $this->makefilter($filterfields,$this->stock_contact_fields,$query,$DEBUG);
|
||||
|
||||
if(is_array($query))
|
||||
{
|
||||
// must be fixed somehow Milosch????
|
||||
$myfilter = $this->makefilter($filterfields,$query,'',$DEBUG);
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't search about any fields any more
|
||||
$search_filter = array(
|
||||
'fn' => 'cn',
|
||||
@ -423,6 +430,7 @@
|
||||
);
|
||||
$myfilter = $this->makefilter($filterfields,$search_filter,$query,$DEBUG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$myfilter = $this->makefilter($filterfields,'','',$DEBUG);
|
||||
@ -534,7 +542,6 @@
|
||||
if($DEBUG) { echo '<br>Searching...'; }
|
||||
foreach($extra as $name => $value)
|
||||
{
|
||||
|
||||
$qarray[] = array($value => $query);
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,24 @@
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
/**
|
||||
* This class provides a contact database scheme.
|
||||
* It attempts to be based on the vcard 2.1 standard, with mods as needed
|
||||
* to make for more reasonable sql storage.
|
||||
* Note that changes here must also work in the LDAP version.
|
||||
* Syntax: CreateObject('phpgwapi.contacts');
|
||||
* Example1: $contacts = CreateObject('phpgwapi.contacts');
|
||||
*
|
||||
* Last Editor: $Author$
|
||||
* @class contacts_
|
||||
* @abstract Contact Management System
|
||||
* @author jengo/Milosch
|
||||
* @version $Revision$
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/*!
|
||||
@class contacts_
|
||||
@abstract Contact Management 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>
|
||||
Note that changes here must also work in the LDAP version. <br>
|
||||
Syntax: CreateObject('phpgwapi.contacts'); <br>
|
||||
Example1: $contacts = CreateObject('phpgwapi.contacts');
|
||||
*/
|
||||
class contacts_
|
||||
{
|
||||
var $db = '';
|
||||
@ -506,6 +512,26 @@
|
||||
unset($f); unset($x);
|
||||
}
|
||||
elseif($query)
|
||||
{
|
||||
if(is_array($query))
|
||||
{
|
||||
$sql = "SELECT * FROM $this->std_table WHERE (";
|
||||
$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);
|
||||
@ -521,6 +547,7 @@
|
||||
$sqlcount = substr($sqlcount,0,-3) . ') ' . $fand . $filtermethod;
|
||||
unset($f); unset($x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT id,lid,tid,owner,access,cat_id,last_mod $t_fields FROM $this->std_table " . $fwhere
|
||||
|
Loading…
Reference in New Issue
Block a user