forked from extern/egroupware
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,16 +412,24 @@
|
||||
#reset($this->stock_contact_fields);
|
||||
#$myfilter = $this->makefilter($filterfields,$this->stock_contact_fields,$query,$DEBUG);
|
||||
|
||||
// don't search about any fields any more
|
||||
$search_filter = array(
|
||||
'fn' => 'cn',
|
||||
'n_given' => 'givenname',
|
||||
'n_family' => 'sn',
|
||||
'email' => 'mail',
|
||||
'org_name' => 'o',
|
||||
'org_unit' => 'ou'
|
||||
);
|
||||
$myfilter = $this->makefilter($filterfields,$search_filter,$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',
|
||||
'n_given' => 'givenname',
|
||||
'n_family' => 'sn',
|
||||
'email' => 'mail',
|
||||
'org_name' => 'o',
|
||||
'org_unit' => 'ou'
|
||||
);
|
||||
$myfilter = $this->makefilter($filterfields,$search_filter,$query,$DEBUG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -534,7 +542,6 @@
|
||||
if($DEBUG) { echo '<br>Searching...'; }
|
||||
foreach($extra as $name => $value)
|
||||
{
|
||||
|
||||
$qarray[] = array($value => $query);
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,45 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare API - Contacts manager for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* and Miles Lott <milosch@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$ */
|
||||
|
||||
/*!
|
||||
@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');
|
||||
/**************************************************************************\
|
||||
* phpGroupWare API - Contacts manager for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* and Miles Lott <milosch@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 *
|
||||
\**************************************************************************/
|
||||
|
||||
/**
|
||||
* 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_
|
||||
{
|
||||
var $db = '';
|
||||
@ -507,19 +513,40 @@
|
||||
}
|
||||
elseif($query)
|
||||
{
|
||||
$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)
|
||||
if(is_array($query))
|
||||
{
|
||||
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
||||
$sqlcount .= " UPPER($f) LIKE UPPER('%$query%') OR ";
|
||||
$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);
|
||||
|
||||
$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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user