implemented different search-types:

- all fields
- firstname, lastname, account-lid
- start with
- exact
for the new account-selection popup
This commit is contained in:
Ralf Becker 2004-06-13 20:11:31 +00:00
parent 9952a1bdb8
commit ab9ec83bc4
3 changed files with 67 additions and 15 deletions

View File

@ -114,6 +114,15 @@
$this->account_type = $account_type; $this->account_type = $account_type;
} }
$this->query_types = array(
'all' => 'all fields',
'firstname' => 'firstname',
'lastname' => 'lastname',
'lid' => 'LoginID',
'email' => 'email', // sql-constructor unsets this again, til the email column is added
'start' => 'start with',
'exact' => 'exact',
);
$this->accounts_(); // call constructor of extended class $this->accounts_(); // call constructor of extended class
$this->xmlrpc_methods[] = array( $this->xmlrpc_methods[] = array(
@ -170,7 +179,7 @@
} }
} }
function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '') function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='')
{ {
//echo "<p>accounts::get_list(".print_r($_type,True).",start='$start',sort='$sort',order='$order',query='$query',offset='$offset')</p>\n"; //echo "<p>accounts::get_list(".print_r($_type,True).",start='$start',sort='$sort',order='$order',query='$query',offset='$offset')</p>\n";
$this->setup_cache(); $this->setup_cache();
@ -185,6 +194,7 @@
$order = $p['order']; $order = $p['order'];
$query = $p['query']; $query = $p['query'];
$offset = $p['offset']; $offset = $p['offset'];
$query_type = $p['query_type'];
} }
else else
{ {
@ -193,7 +203,8 @@
'start' => $start, 'start' => $start,
'order' => $order, 'order' => $order,
'query' => $query, 'query' => $query,
'offset' => $offset 'offset' => $offset,
'query_type' => $query_type ,
); );
} }
$serial = serialize($p); $serial = serialize($p);
@ -204,7 +215,7 @@
} }
else else
{ {
$account_list[$serial]['data'] = accounts_::get_list($_type,$start,$sort,$order,$query,$offset); $account_list[$serial]['data'] = accounts_::get_list($_type,$start,$sort,$order,$query,$offset,$query_type);
$account_list[$serial]['total'] = $this->total; $account_list[$serial]['total'] = $this->total;
} }
return $account_list[$serial]['data']; return $account_list[$serial]['data'];

View File

@ -455,7 +455,7 @@
} }
} }
function get_list($_type='both', $start = '',$sort = '', $order = '', $query = '', $offset = '') function get_list($_type='both', $start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='')
{ {
//print "\$_type=$_type, \$start=$start , \$sort=$sort, \$order=$order, \$query=$query, \$offset=$offset<br>"; //print "\$_type=$_type, \$start=$start , \$sort=$sort, \$order=$order, \$query=$query, \$offset=$offset<br>";
$query = strtolower($query); $query = strtolower($query);
@ -475,14 +475,37 @@
if($_type == 'accounts') if($_type == 'accounts')
{ {
if(empty($query) || $query == "*") $filter = "(&(uidnumber=*)(phpgwaccounttype=u)";
if (!empty($query) && $query != '*')
{ {
$filter = "(&(uidnumber=*)(phpgwaccounttype=u))"; switch($query_type)
} {
else case 'all':
{ default:
$filter = "(&(uidnumber=*)(phpgwaccounttype=u)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; $query = '*'.$query;
// fall-through
case 'start':
$query .= '*';
// fall-through
case 'exact':
$filter .= "(|(uid=$query)(sn=$query)(cn=$query)(givenname=$query)(email=$query))";
break;
case 'firstname':
case 'lastname':
case 'lid':
case 'email':
$to_ldap = array(
'firstname' => 'sn',
'lastname' => 'givenname',
'lid' => 'uid',
'email' => 'email',
);
$filter .= '('.$to_ldap[$query_type].'=*'.$query.'*)';
break;
}
} }
$filter .= ')';
$sri = ldap_search($this->ds, $this->user_context, $filter); $sri = ldap_search($this->ds, $this->user_context, $filter);
$allValues = ldap_get_entries($this->ds, $sri); $allValues = ldap_get_entries($this->ds, $sri);
while (list($null,$allVals) = @each($allValues)) while (list($null,$allVals) = @each($allValues))

View File

@ -39,6 +39,8 @@
function accounts_() function accounts_()
{ {
copyobj($GLOBALS['phpgw']->db,$this->db); copyobj($GLOBALS['phpgw']->db,$this->db);
unset($this->query_types['email']);
} }
function list_methods($_type='xmlrpc') function list_methods($_type='xmlrpc')
@ -128,7 +130,7 @@
$this->db->unlock(); $this->db->unlock();
} }
function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '') function get_list($_type='both',$start = '',$sort = '', $order = '', $query = '', $offset = '',$query_type='')
{ {
if (! $sort) if (! $sort)
{ {
@ -166,9 +168,26 @@
{ {
$whereclause = ' WHERE ( '; $whereclause = ' WHERE ( ';
} }
$query = $this->db->db_addslashes($query); switch($query_type)
$whereclause .= " account_firstname LIKE '%$query%' OR account_lastname LIKE " {
. "'%$query%' OR account_lid LIKE '%$query%' )"; case 'all':
default:
$query = '%'.$query;
// fall-through
case 'start':
$query .= '%';
// fall-through
case 'exact':
$query = $this->db->quote($query);
$whereclause .= " account_firstname LIKE $query OR account_lastname LIKE $query OR account_lid LIKE $query )";
break;
case 'firstname':
case 'lastname':
case 'lid':
$query = $this->db->quote('%'.$query.'%');
$whereclause .= " account_$query_type LIKE $query )";
break;
}
} }
$sql = "SELECT * FROM phpgw_accounts $whereclause $orderclause"; $sql = "SELECT * FROM phpgw_accounts $whereclause $orderclause";
@ -184,7 +203,6 @@
{ {
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
} }
while ($this->db->next_record()) while ($this->db->next_record())
{ {
$accounts[] = Array( $accounts[] = Array(