Fix LDAP search calls and return the number of matches
This commit is contained in:
parent
115c4c54b7
commit
7d5fe4c794
2 changed files with 41 additions and 5 deletions
|
@ -36,6 +36,7 @@ function kolab_folderlist(node, p)
|
||||||
var search_results_widget;
|
var search_results_widget;
|
||||||
var search_results_container;
|
var search_results_container;
|
||||||
var listsearch_request;
|
var listsearch_request;
|
||||||
|
var search_messagebox;
|
||||||
|
|
||||||
var Q = rcmail.quote_html;
|
var Q = rcmail.quote_html;
|
||||||
|
|
||||||
|
@ -164,8 +165,29 @@ function kolab_folderlist(node, p)
|
||||||
}
|
}
|
||||||
search_results = {};
|
search_results = {};
|
||||||
|
|
||||||
|
if (search_messagebox)
|
||||||
|
rcmail.hide_message(search_messagebox);
|
||||||
|
|
||||||
// send search request(s) to server
|
// send search request(s) to server
|
||||||
if (search.query && search.execute) {
|
if (search.query && search.execute) {
|
||||||
|
// require a minimum length for the search string
|
||||||
|
if (rcmail.env.autocomplete_min_length && search.query.length < rcmail.env.autocomplete_min_length) {
|
||||||
|
search_messagebox = rcmail.display_message(
|
||||||
|
rcmail.get_label('autocompletechars').replace('$min', rcmail.env.autocomplete_min_length));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listsearch_request) {
|
||||||
|
// ignore, let the currently runnung sequest finish
|
||||||
|
if (listsearch_request.query == search.query) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else { // cancel previous search request
|
||||||
|
rcmail.multi_thread_request_abort(listsearch_request.id);
|
||||||
|
listsearch_request = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var sources = p.search_sources || [ 'folders' ];
|
var sources = p.search_sources || [ 'folders' ];
|
||||||
var reqid = rcmail.multi_thread_http_request({
|
var reqid = rcmail.multi_thread_http_request({
|
||||||
items: sources,
|
items: sources,
|
||||||
|
@ -173,10 +195,15 @@ function kolab_folderlist(node, p)
|
||||||
action: p.search_action || 'listsearch',
|
action: p.search_action || 'listsearch',
|
||||||
postdata: { action:'search', q:search.query, source:'%s' },
|
postdata: { action:'search', q:search.query, source:'%s' },
|
||||||
lock: rcmail.display_message(rcmail.get_label('searching'), 'loading'),
|
lock: rcmail.display_message(rcmail.get_label('searching'), 'loading'),
|
||||||
onresponse: render_search_results
|
onresponse: render_search_results,
|
||||||
|
whendone: function(e){ listsearch_request = null; }
|
||||||
});
|
});
|
||||||
|
|
||||||
listsearch_request = { id:reqid, sources:sources.slice(), num:sources.length };
|
listsearch_request = { id:reqid, query:search.query };
|
||||||
|
}
|
||||||
|
else if (!search.query && listsearch_request) {
|
||||||
|
rcmail.multi_thread_request_abort(listsearch_request.id);
|
||||||
|
listsearch_request = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1318,11 +1318,12 @@ class kolab_storage
|
||||||
* @param mixed $query Search value (or array of field => value pairs)
|
* @param mixed $query Search value (or array of field => value pairs)
|
||||||
* @param int $mode Matching mode: 0 - partial (*abc*), 1 - strict (=), 2 - prefix (abc*)
|
* @param int $mode Matching mode: 0 - partial (*abc*), 1 - strict (=), 2 - prefix (abc*)
|
||||||
* @param array $required List of fields that shall ot be empty
|
* @param array $required List of fields that shall ot be empty
|
||||||
* @param int $limit Number of records
|
* @param int $limit Maximum number of records
|
||||||
|
* @param int $count Returns the number of records found
|
||||||
*
|
*
|
||||||
* @return array List or false on error
|
* @return array List or false on error
|
||||||
*/
|
*/
|
||||||
public static function search_users($query, $mode = 1, $required = array(), $limit = 0)
|
public static function search_users($query, $mode = 1, $required = array(), $limit = 0, &$count = 0)
|
||||||
{
|
{
|
||||||
// requires a working LDAP setup
|
// requires a working LDAP setup
|
||||||
if (!self::ldap()) {
|
if (!self::ldap()) {
|
||||||
|
@ -1330,7 +1331,12 @@ class kolab_storage
|
||||||
}
|
}
|
||||||
|
|
||||||
// search users using the configured attributes
|
// search users using the configured attributes
|
||||||
$results = self::$ldap->search(self::$config->get('kolab_users_search_attrib', array('cn','mail','alias')), $query, $mode, $required, $limit);
|
$results = self::$ldap->dosearch(self::$config->get('kolab_users_search_attrib', array('cn','mail','alias')), $query, $mode, $required, $limit, $count);
|
||||||
|
|
||||||
|
// exclude myself
|
||||||
|
if ($_SESSION['kolab_dn']) {
|
||||||
|
unset($results[$_SESSION['kolab_dn']]);
|
||||||
|
}
|
||||||
|
|
||||||
// resolve to IMAP folder name
|
// resolve to IMAP folder name
|
||||||
$root = self::namespace_root('other');
|
$root = self::namespace_root('other');
|
||||||
|
@ -1391,6 +1397,9 @@ class kolab_storage
|
||||||
$path_len = count(explode($delimiter, $other_ns));
|
$path_len = count(explode($delimiter, $other_ns));
|
||||||
|
|
||||||
foreach ((array)self::list_folders($other_ns, '*', '', $subscribed) as $foldername) {
|
foreach ((array)self::list_folders($other_ns, '*', '', $subscribed) as $foldername) {
|
||||||
|
if ($foldername == 'INBOX') // skip INBOX which is added by default
|
||||||
|
continue;
|
||||||
|
|
||||||
// truncate folder path to top-level folders of the 'other' namespace
|
// truncate folder path to top-level folders of the 'other' namespace
|
||||||
$path = explode($delimiter, $foldername);
|
$path = explode($delimiter, $foldername);
|
||||||
$foldername = join($delimiter, array_slice($path, 0, $path_len + 1));
|
$foldername = join($delimiter, array_slice($path, 0, $path_len + 1));
|
||||||
|
|
Loading…
Add table
Reference in a new issue