Browse Source

add scope param for contact search

pull/9902/head
PhilW 1 month ago
parent
commit
01612aaddf
  1. 39
      program/actions/contacts/search.php
  2. 1
      program/actions/contacts/search_create.php
  3. 5
      program/js/app.js
  4. 2
      program/localization/en_US/labels.inc
  5. 9
      skins/elastic/templates/addressbook.html
  6. 2
      skins/elastic/ui.js

39
program/actions/contacts/search.php

@ -45,10 +45,13 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
$adv = isset($_POST['_adv']);
$sid = rcube_utils::get_input_string('_sid', rcube_utils::INPUT_GET);
$search = null;
$scope = null;
// get search criteria from saved search
if ($sid && ($search = $rcmail->user->get_search($sid))) {
$fields = $search['data']['fields'];
// scope param added in 1.7, existence check for backwards compatibility
$scope = isset($search['data']['scope']) ? $search['data']['scope'] : null;
$search = $search['data']['search'];
}
// get fields/values from advanced search form
@ -56,9 +59,13 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
$fields = [];
foreach (array_keys($_POST) as $key) {
$s = trim(rcube_utils::get_input_string($key, rcube_utils::INPUT_POST, true));
if (strlen($s) && preg_match('/^_search_([a-zA-Z0-9_-]+)$/', $key, $m)) {
$search[] = $s;
$fields[] = $m[1];
if (strlen($s)) {
if (preg_match('/^_search_([a-zA-Z0-9_-]+)$/', $key, $m)) {
$search[] = $s;
$fields[] = $m[1];
} elseif ($key == '_scope') {
$scope = $s;
}
}
}
@ -71,6 +78,7 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
else {
$search = trim(rcube_utils::get_input_string('_q', rcube_utils::INPUT_GET, true));
$fields = rcube_utils::get_input_string('_headers', rcube_utils::INPUT_GET);
$scope = strlen($_GET['_scope']) ? rcube_utils::get_input_string('_scope', rcube_utils::INPUT_GET) : null;
if (empty($fields)) {
$fields = array_keys(self::$SEARCH_MODS_DEFAULT);
@ -104,6 +112,10 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
$records = [];
foreach ($sources as $s) {
if (isset($scope) && $scope !== $s['id']) {
continue;
}
$source = $rcmail->get_address_book($s['id']);
// check if search fields are supported....
@ -167,7 +179,7 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
// save search settings in session
$_SESSION['contact_search'][$search_request] = $search_set;
$_SESSION['contact_search_params'] = ['id' => $search_request, 'data' => [$fields, $search]];
$_SESSION['contact_search_params'] = ['id' => $search_request, 'data' => [$fields, $search], 'scope' => $scope];
$_SESSION['page'] = 1;
if ($adv) {
@ -249,6 +261,20 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
}
}
// add search scope field
$coltypes['_scope'] = [
'id' => 'scope',
'type' => 'select',
'category'=> 'main',
'label' => $rcmail->gettext('searchscope'),
'options' => [
'base' => $rcmail->gettext('currentaddressbook'),
'all' => $rcmail->gettext('alladdressbooks')
],
'value' => 'all',
'skip-empty' => true
];
// build form fields list
foreach ($coltypes as $col => $colprop) {
if (!isset($colprop['type'])) {
@ -266,11 +292,12 @@ class rcmail_action_contacts_search extends rcmail_action_contacts_index
$colprop['size'] = $i_size;
}
$colprop['id'] = '_search_' . $col;
$fname = !empty($colprop['id']) ? $colprop['id'] : 'search_' . $col;
$colprop['id'] = !empty($colprop['id']) ? '_' . $colprop['id'] : '_search_' . $col;
$content = html::div('row',
html::label(['class' => 'contactfieldlabel label', 'for' => $colprop['id']], rcube::Q($label))
. html::div('contactfieldcontent', rcube_output::get_edit_field('search_' . $col, '', $colprop, $ftype))
. html::div('contactfieldcontent', rcube_output::get_edit_field($fname, $colprop['value'] ?? '', $colprop, $ftype))
);
$form[$category]['content'][] = $content;

1
program/actions/contacts/search_create.php

@ -47,6 +47,7 @@ class rcmail_action_contacts_search_create extends rcmail_action
'data' => [
'fields' => $params['data'][0],
'search' => $params['data'][1],
'scope' => $params['scope'],
],
];

5
program/js/app.js

@ -5832,6 +5832,8 @@ function rcube_webmail() {
this.clear_message_list();
} else if (this.contact_list) {
this.list_contacts_clear();
// use env.last_source as env.source is overwritten by search action
url._scope = this.env.search_scope == 'base' ? this.env.last_source : null;
}
if (this.env.source) {
@ -7489,6 +7491,9 @@ function rcube_webmail() {
if (this.name.match(/^_search/) && this.value != '') {
form[this.name] = this.value;
valid = true;
} else if (this.name == '_scope' && this.value == 'base') {
// use env.last_source as env.source is overwritten by search action
form[this.name] = ref.env.last_source;
}
});

2
program/localization/en_US/labels.inc

@ -265,6 +265,8 @@ $labels['searchinterval-1Y'] = 'older than a year';
$labels['searchinterval1W'] = 'younger than a week';
$labels['searchinterval1M'] = 'younger than a month';
$labels['searchinterval1Y'] = 'younger than a year';
$labels['currentaddressbook'] = 'Current address book';
$labels['alladdressbooks'] = 'All address books';
$labels['openinextwin'] = 'Open in new window';
$labels['emlsave'] = 'Download (.eml)';

9
skins/elastic/templates/addressbook.html

@ -42,6 +42,15 @@
<li><label><input type="checkbox" name="s_mods[]" value="email" /><roundcube:label name="email" /></label></li>
<li><label><input type="checkbox" name="s_mods[]" value="*" /><roundcube:label name="allfields" /></label></li>
</ul>
<div class="input-group">
<div class="input-group-prepend">
<label for="s_scope" class="input-group-text"><roundcube:label name="searchscope" /></label>
</div>
<select name="s_scope" id="s_scope" class="custom-select">
<option value="base"><roundcube:label name="currentaddressbook" /></option>
<option value="all"><roundcube:label name="alladdressbooks" /></option>
</select>
</div>
</div>
<div class="formbuttons">
<button type="button" class="btn btn-primary icon search" onclick="return rcmail.command('search')"><roundcube:label name="search" /></button>

2
skins/elastic/ui.js

@ -2843,7 +2843,7 @@ function rcube_elastic_ui() {
interval_select = $('#s_interval', obj),
mbox = rcmail.env.mailbox,
mods = rcmail.env.search_mods,
scope = rcmail.env.search_scope || 'base';
scope = rcmail.env.search_scope || (rcmail.task == 'addressbook' ? 'all' : 'base');
if (!$(obj).data('initialized')) {
$(obj).data('initialized', true);

Loading…
Cancel
Save