summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-06-01 13:44:51 +0000
committeralecpl <alec@alec.pl>2011-06-01 13:44:51 +0000
commit3cacf941fa30e8c02f3f7aebcc8747036d0d8d20 (patch)
tree3d873bb15f9454b28c3c4a8ba3216421ededdfd4 /program
parent2912de6f9bea6c0491a7bc4321e66637da0a6746 (diff)
- Add popup with basic fields selection for addressbook search
Diffstat (limited to 'program')
-rw-r--r--program/include/rcube_contacts.php13
-rw-r--r--program/include/rcube_ldap.php15
-rw-r--r--program/js/app.js26
-rw-r--r--program/localization/en_US/labels.inc1
-rw-r--r--program/localization/pl_PL/labels.inc1
-rw-r--r--program/steps/addressbook/func.inc6
-rw-r--r--program/steps/addressbook/search.inc31
7 files changed, 57 insertions, 36 deletions
diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php
index 687b4b111..7c142f545 100644
--- a/program/include/rcube_contacts.php
+++ b/program/include/rcube_contacts.php
@@ -192,7 +192,7 @@ class rcube_contacts extends rcube_addressbook
// determine whether we have to parse the vcard or if only db cols are requested
$read_vcard = !$cols || count(array_intersect($cols, $this->table_cols)) < count($cols);
-
+
while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) {
$sql_arr['ID'] = $sql_arr[$this->primary_key];
@@ -255,17 +255,18 @@ class rcube_contacts extends rcube_addressbook
$ids = $this->db->array2list($ids, 'integer');
$where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
}
- else if ($strict) {
- $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($value);
- }
else if ($col == '*') {
$words = array();
foreach(explode(" ", self::normalize_string($value)) as $word)
$words[] = $this->db->ilike('words', '%'.$word.'%');
$where[] = '(' . join(' AND ', $words) . ')';
- }
- else
+ }
+ else if ($strict) {
+ $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($value);
+ }
+ else if (in_array($col, $this->table_cols)) {
$where[] = $this->db->ilike($col, '%'.$value.'%');
+ }
}
foreach ($required as $col) {
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index f166fd23a..7f0ea84fa 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -479,21 +479,20 @@ class rcube_ldap extends rcube_addressbook
$filter = '(|';
$wc = !$strict && $this->prop['fuzzy_search'] ? '*' : '';
- if ($fields != '*')
+ if ($fields == '*')
{
// search_fields are required for fulltext search
- if (!$this->prop['search_fields'])
+ if (empty($this->prop['search_fields']))
{
$this->set_error(self::ERROR_SEARCH, 'nofulltextsearch');
$this->result = new rcube_result_set();
return $this->result;
}
- }
-
- if (is_array($this->prop['search_fields']))
- {
- foreach ($this->prop['search_fields'] as $k => $field)
- $filter .= "($field=$wc" . $this->_quote_string($value) . "$wc)";
+ if (is_array($this->prop['search_fields']))
+ {
+ foreach ($this->prop['search_fields'] as $k => $field)
+ $filter .= "($field=$wc" . $this->_quote_string($value) . "$wc)";
+ }
}
else
{
diff --git a/program/js/app.js b/program/js/app.js
index 32d7a6332..db79772a1 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3332,31 +3332,33 @@ function rcube_webmail()
this.qsearch = function(value)
{
if (value != '') {
- var addurl = '';
+ var n, addurl = '', mods_arr = [],
+ mods = this.env.search_mods,
+ mbox = this.env.mailbox,
+ lock = this.set_busy(true, 'searching');
+
if (this.message_list) {
this.clear_message_list();
- if (this.env.search_mods) {
- var mods = this.env.search_mods[this.env.mailbox] ? this.env.search_mods[this.env.mailbox] : this.env.search_mods['*'];
- if (mods) {
- var head_arr = [];
- for (var n in mods)
- head_arr.push(n);
- addurl += '&_headers='+head_arr.join(',');
- }
- }
+ if (mods)
+ mods = mods[mbox] ? mods[mbox] : mods['*'];
} else if (this.contact_list) {
this.contact_list.clear(true);
this.show_contentframe(false);
}
+ if (mods) {
+ for (n in mods)
+ mods_arr.push(n);
+ addurl += '&_headers='+mods_arr.join(',');
+ }
+
if (this.gui_objects.search_filter)
addurl += '&_filter=' + this.gui_objects.search_filter.value;
// reset vars
this.env.current_page = 1;
- var lock = this.set_busy(true, 'searching');
this.http_request('search', '_q='+urlencode(value)
- + (this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : '')
+ + (mbox ? '&_mbox='+urlencode(mbox) : '')
+ (this.env.source ? '&_source='+urlencode(this.env.source) : '')
+ (this.env.group ? '&_gid='+urlencode(this.env.group) : '')
+ (addurl ? addurl : ''), lock);
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 45da21cb4..c04531cf5 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -271,6 +271,7 @@ $labels['female'] = 'female';
$labels['manager'] = 'Manager';
$labels['assistant'] = 'Assistant';
$labels['spouse'] = 'Spouse';
+$labels['allfields'] = 'All fields';
$labels['typehome'] = 'Home';
$labels['typework'] = 'Work';
diff --git a/program/localization/pl_PL/labels.inc b/program/localization/pl_PL/labels.inc
index 637768e4d..8c4e910cd 100644
--- a/program/localization/pl_PL/labels.inc
+++ b/program/localization/pl_PL/labels.inc
@@ -408,5 +408,6 @@ $labels['otherfolder'] = 'Folder innego użytkownika';
$labels['sharedfolder'] = 'Folder współdzielony';
$labels['defaultaddressbook'] = 'Nowe kontakty dodawaj do wybranej książki adresowej';
$labels['spellcheckbeforesend'] = 'Przed wysłaniem wiadomości sprawdzaj pisownię';
+$labels['allfields'] = 'Wszystkie pola';
?>
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 8b4a9f10f..545f140bf 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -19,6 +19,8 @@
*/
+$SEARCH_MODS_DEFAULT = array('name'=>1, 'firstname'=>1, 'surname'=>1, 'email'=>1, '*'=>1);
+
// add list of address sources to client env
$js_list = $RCMAIL->get_address_sources();
@@ -39,7 +41,7 @@ if (!empty($_GET['_page']))
$CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
else
$CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
-
+
if (!empty($_REQUEST['_gid']))
$CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
@@ -51,6 +53,8 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search
$OUTPUT->set_env('source', $source ? $source : '0');
$OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
if (!$OUTPUT->ajax_call) {
+ $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
+ $OUTPUT->set_env('search_mods', $search_mods);
$OUTPUT->set_env('address_sources', $js_list);
$OUTPUT->set_pagetitle(rcube_label('addressbook'));
}
diff --git a/program/steps/addressbook/search.inc b/program/steps/addressbook/search.inc
index 8d25a8fbc..fe7099fac 100644
--- a/program/steps/addressbook/search.inc
+++ b/program/steps/addressbook/search.inc
@@ -22,22 +22,35 @@
$CONTACTS->set_page(1);
$_SESSION['page'] = 1;
+// get input
$search = trim(get_input_value('_q', RCUBE_INPUT_GET, true));
-$search_request = md5('addr'.$search);
+$fields = explode(',', get_input_value('_headers', RCUBE_INPUT_GET));
+
+if (empty($fields)) {
+ $fields = $SEARCH_MODS_DEFAULT;
+}
+
+$search_request = md5('addr'.$search.implode($fields, ','));
+
+// update search_mods setting
+$search_mods = array_fill_keys($fields, 1);
+$RCMAIL->user->save_prefs(array('addressbook_search_mods' => $search_mods));
+
+if ($fields['all'] || count($fields) == count($SEARCH_MODS_DEFAULT)) {
+ $fields = '*';
+}
// get contacts for this user
-$result = $CONTACTS->search('*', $search);
+$result = $CONTACTS->search($fields, $search);
// save search settings in session
$_SESSION['search'][$search_request] = $CONTACTS->get_search_set();
-if ($result->count > 0)
-{
- // create javascript list
- rcmail_js_contacts_list($result);
+if ($result->count > 0) {
+ // create javascript list
+ rcmail_js_contacts_list($result);
}
-else
-{
+else {
$OUTPUT->show_message('nocontactsfound', 'notice');
}
@@ -45,6 +58,6 @@ else
$OUTPUT->set_env('search_request', $search_request);
$OUTPUT->set_env('pagecount', ceil($result->count / $CONTACTS->page_size));
$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text());
-
+
// send response
$OUTPUT->send();