Now doing a single OR search on query, instead a bunch of single field queries;

move class vars to top where possible.
This commit is contained in:
Miles Lott 2001-11-23 01:58:19 +00:00
parent 26c57a5d85
commit 8ba7bbbbcc

View File

@ -35,32 +35,19 @@
*/
class contacts_
{
var $db;
var $ldap;
var $nextid;
var $std_table='';
var $ext_table='phpgw_addressbook_extra';
var $db = '';
var $ldap = '';
var $nextid = '';
var $std_table = '';
var $ext_table = 'phpgw_addressbook_extra';
var $account_id;
var $stock_contact_fields;
var $non_contact_fields;
var $email_types;
var $adr_types;
var $total_records;
var $grants;
function contacts_()
{
$this->db = $GLOBALS['phpgw']->db;
$this->ldap = $GLOBALS['phpgw']->common->ldapConnect(
$GLOBALS['phpgw_info']['server']['ldap_contact_host'],
$GLOBALS['phpgw_info']['server']['ldap_contact_dn'],
$GLOBALS['phpgw_info']['server']['ldap_contact_pw']
);
$this->account_id = $GLOBALS['phpgw_info']['user']['account_id'];
$this->grants = $GLOBALS['phpgw']->acl->get_grants('addressbook');
/* The left side are the array elements used throughout phpgw, right side are the ldap attributes */
$this->stock_contact_fields = array(
var $stock_contact_fields = array(
'fn' => 'cn',
'n_given' => 'givenname',
'n_family' => 'sn',
@ -113,7 +100,7 @@
'email_home_type' => 'phpgwmailhometype'
);
$this->non_contact_fields = array(
var $non_contact_fields = array(
'id' => 'uidnumber',
'lid' => 'uid',
'tid' => 'phpgwcontacttypeid',
@ -122,21 +109,8 @@
'owner' => 'phpgwcontactowner'
);
/* Used to flag an address as being:
domestic OR international(default)
parcel(default)
postal(default)
work(default) OR home
*/
$this->adr_types = array(
'dom' => lang('Domestic'),
'intl' => lang('International'),
'parcel' => lang('Parcel'),
'postal' => lang('Postal')
);
/* Used to set preferphone field */
$this->tel_types = array(
var $tel_types = array(
'work' => 'work',
'home' => 'home',
'voice' => 'voice',
@ -152,7 +126,7 @@
);
/* Used to set mail_type fields */
$this->email_types = array(
var $email_types = array(
'INTERNET' => 'INTERNET',
'CompuServe' => 'CompuServe',
'AOL' => 'AOL',
@ -167,6 +141,30 @@
'X.400' => 'X.400',
'TLX' => 'TLX'
);
function contacts_()
{
$this->db = $GLOBALS['phpgw']->db;
$this->ldap = $GLOBALS['phpgw']->common->ldapConnect(
$GLOBALS['phpgw_info']['server']['ldap_contact_host'],
$GLOBALS['phpgw_info']['server']['ldap_contact_dn'],
$GLOBALS['phpgw_info']['server']['ldap_contact_pw']
);
$this->account_id = $GLOBALS['phpgw_info']['user']['account_id'];
$this->grants = $GLOBALS['phpgw']->acl->get_grants('addressbook');
/* Used to flag an address as being:
domestic OR international(default)
parcel(default)
postal(default)
work(default) OR home
*/
$this->adr_types = array(
'dom' => lang('Domestic'),
'intl' => lang('International'),
'parcel' => lang('Parcel'),
'postal' => lang('Postal')
);
}
/* send this the id and whatever fields you want to see */
@ -381,53 +379,30 @@
{
$ldap_fields = array();
$total = 0;
/*
Query each field seperately instead of using ldap OR search.
This should be changed to use ldap and/or syntax
*/
reset($stock_fieldnames);
while (list($name,$value) = each($stock_fieldnames) )
reset($this->stock_contact_fields);
$lquery = '(&(|'; /* $lquery = '(|'; */
while (list($name,$value) = each($this->stock_contact_fields) )
{
$lquery = $value.'=*'.$query.'*';
$lquery .= '(' . $value . '=*' . $query . '*)';
}
$lquery .= ')(phpgwcontactowner=*))'; /* $lquery .= ')'; */
/* echo $lquery; exit; */
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], $lquery);
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], "$lquery");
/* append the results */
$ldap_fields += ldap_get_entries($this->ldap, $sri);
/* add the # rows to our total */
$total = $total + ldap_count_entries($this->ldap, $sri);
}
/* _debug_array($ldap_fields);exit; */
if ($filterfields)
{
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
}
/* Now, remove duplicate rows */
$ldap_fields = $this->asortbyindex($ldap_fields,'uidnumber');
@reset($ldap_fields);
if (count($ldap_fields) > 0)
{
for ($a = 0; $a < count($ldap_fields); $a++)
{
if ($ldap_fields[$a])
{
/*
echo '<br>comparing "'.$ldap_fields[$a]['uidnumber'][0]
.'" to "'.$ldap_fields[$a - 1]['uidnumber'][0].'"';
*/
if (($ldap_fields[$a]['uidnumber'][0] <> $ldap_fields[$a - 1]['uidnumber'][0]))
{
$uniquearray[$a] = $ldap_fields[$a];
}
else
{
/* echo '<br>deleting "'.$ldap_fields[$a -1 ]['uidnumber'][0]; */
}
}
}
$ldap_fields = $uniquearray;
}
$this->total_records = count($ldap_fields);
/* echo '<br>total="'.$this->total_records.'"'; */
}
@ -516,6 +491,13 @@
function add($owner,$fields,$access='private',$cat_id='0',$tid='n')
{
$tid = $fields['tid'] ? trim($fields['tid']) : $tid;
unset($fields['tid']);
if(empty($tid))
{
$tid = 'n';
}
if (!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
{
return False;
@ -567,6 +549,7 @@
$ldap_fields['objectclass'][1] = 'inetOrgPerson';
$ldap_fields['objectclass'][2] = 'phpgwContact';
_debug_array($ldap_fields);
$err = ldap_add($this->ldap, $dn, $ldap_fields);
if (count($extra_fields))