From ab9ec83bc4d9ac6ad263fb80a57d059541428668 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 13 Jun 2004 20:11:31 +0000 Subject: [PATCH] implemented different search-types: - all fields - firstname, lastname, account-lid - start with - exact for the new account-selection popup --- phpgwapi/inc/class.accounts.inc.php | 17 +++++++++-- phpgwapi/inc/class.accounts_ldap.inc.php | 37 +++++++++++++++++++----- phpgwapi/inc/class.accounts_sql.inc.php | 28 ++++++++++++++---- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/phpgwapi/inc/class.accounts.inc.php b/phpgwapi/inc/class.accounts.inc.php index 734c6c0561..2314645eba 100644 --- a/phpgwapi/inc/class.accounts.inc.php +++ b/phpgwapi/inc/class.accounts.inc.php @@ -114,6 +114,15 @@ $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->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 "

accounts::get_list(".print_r($_type,True).",start='$start',sort='$sort',order='$order',query='$query',offset='$offset')

\n"; $this->setup_cache(); @@ -185,6 +194,7 @@ $order = $p['order']; $query = $p['query']; $offset = $p['offset']; + $query_type = $p['query_type']; } else { @@ -193,7 +203,8 @@ 'start' => $start, 'order' => $order, 'query' => $query, - 'offset' => $offset + 'offset' => $offset, + 'query_type' => $query_type , ); } $serial = serialize($p); @@ -204,7 +215,7 @@ } 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; } return $account_list[$serial]['data']; diff --git a/phpgwapi/inc/class.accounts_ldap.inc.php b/phpgwapi/inc/class.accounts_ldap.inc.php index 2ec1ddadbc..62a2ebc633 100644 --- a/phpgwapi/inc/class.accounts_ldap.inc.php +++ b/phpgwapi/inc/class.accounts_ldap.inc.php @@ -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
"; $query = strtolower($query); @@ -475,14 +475,37 @@ if($_type == 'accounts') { - if(empty($query) || $query == "*") + $filter = "(&(uidnumber=*)(phpgwaccounttype=u)"; + if (!empty($query) && $query != '*') { - $filter = "(&(uidnumber=*)(phpgwaccounttype=u))"; - } - else - { - $filter = "(&(uidnumber=*)(phpgwaccounttype=u)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; + switch($query_type) + { + case 'all': + default: + $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); $allValues = ldap_get_entries($this->ds, $sri); while (list($null,$allVals) = @each($allValues)) diff --git a/phpgwapi/inc/class.accounts_sql.inc.php b/phpgwapi/inc/class.accounts_sql.inc.php index 94b719333d..e234a4f545 100644 --- a/phpgwapi/inc/class.accounts_sql.inc.php +++ b/phpgwapi/inc/class.accounts_sql.inc.php @@ -39,6 +39,8 @@ function accounts_() { copyobj($GLOBALS['phpgw']->db,$this->db); + + unset($this->query_types['email']); } function list_methods($_type='xmlrpc') @@ -128,7 +130,7 @@ $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) { @@ -166,9 +168,26 @@ { $whereclause = ' WHERE ( '; } - $query = $this->db->db_addslashes($query); - $whereclause .= " account_firstname LIKE '%$query%' OR account_lastname LIKE " - . "'%$query%' OR account_lid LIKE '%$query%' )"; + switch($query_type) + { + 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"; @@ -184,7 +203,6 @@ { $this->db->query($sql,__LINE__,__FILE__); } - while ($this->db->next_record()) { $accounts[] = Array(