summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/addressbook/func.inc29
-rw-r--r--program/steps/addressbook/search.inc71
2 files changed, 97 insertions, 3 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 55d4255aa..b290bbb2d 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -227,7 +227,32 @@ function rcmail_directory_list($attrib)
$out = $groupdata['out'];
}
- $OUTPUT->set_env('contactgroups', $jsdata);
+ $line_templ = html::tag('li', array(
+ 'id' => 'rcmliS%s', 'class' => '%s'),
+ html::a(array('href' => '#', 'rel' => 'S%s',
+ 'onclick' => "return ".JS_OBJECT_NAME.".command('listsearch', '%s', this)"), '%s'));
+
+ // Saved searches
+ $sources = $RCMAIL->user->list_searches(rcube_user::SEARCH_ADDRESSBOOK);
+ foreach ($sources as $j => $source) {
+ $id = $source['id'];
+ $js_id = JQ($id);
+
+ // set class name(s)
+ $class_name = 'contactsearch';
+ if ($current === $id)
+ $class_name .= ' selected';
+ if ($source['class_name'])
+ $class_name .= ' ' . $source['class_name'];
+
+ $out .= sprintf($line_templ,
+ html_identifier($id),
+ $class_name,
+ $id,
+ $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
+ }
+
+ $OUTPUT->set_env('contactgroups', $jsdata);
$OUTPUT->add_gui_object('folderlist', $attrib['id']);
// add some labels to client
$OUTPUT->add_label('deletegroupconfirm', 'groupdeleting', 'addingmember', 'removingmember');
@@ -745,4 +770,6 @@ $RCMAIL->register_action_map(array(
'group-delete' => 'groups.inc',
'group-addmembers' => 'groups.inc',
'group-delmembers' => 'groups.inc',
+ 'search-create' => 'search.inc',
+ 'search-delete' => 'search.inc',
));
diff --git a/program/steps/addressbook/search.inc b/program/steps/addressbook/search.inc
index 352556de0..ad1df9792 100644
--- a/program/steps/addressbook/search.inc
+++ b/program/steps/addressbook/search.inc
@@ -21,6 +21,60 @@
*/
+if ($RCMAIL->action == 'search-create') {
+ $id = get_input_value('_search', RCUBE_INPUT_POST);
+ $name = get_input_value('_name', RCUBE_INPUT_POST, true);
+
+ if (($params = $_SESSION['search_params']) && $params['id'] == $id) {
+
+ $data = array(
+ 'type' => rcube_user::SEARCH_ADDRESSBOOK,
+ 'name' => $name,
+ 'data' => array(
+ 'fields' => $params['data'][0],
+ 'search' => $params['data'][1],
+ ),
+ );
+
+ $plugin = $RCMAIL->plugins->exec_hook('saved_search_create', array('data' => $data));
+
+ if (!$plugin['abort'])
+ $result = $RCMAIL->user->insert_search($plugin['data']);
+ else
+ $result = $plugin['result'];
+ }
+
+ if ($result) {
+ $OUTPUT->show_message('savedsearchcreated', 'confirmation');
+ $OUTPUT->command('insert_saved_search', Q($name), Q($result));
+ }
+ else
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'savedsearchcreateerror', 'error');
+
+ $OUTPUT->send();
+}
+
+if ($RCMAIL->action == 'search-delete') {
+ $id = get_input_value('_sid', RCUBE_INPUT_POST);
+
+ $plugin = $RCMAIL->plugins->exec_hook('saved_search_delete', array('id' => $id));
+
+ if (!$plugin['abort'])
+ $result = $RCMAIL->user->delete_search($id);
+ else
+ $result = $plugin['result'];
+
+ if ($result) {
+ $OUTPUT->show_message('savedsearchdeleted', 'confirmation');
+ $OUTPUT->command('remove_search_item', Q($id));
+ }
+ else
+ $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'savedsearchdeleteerror', 'error');
+
+ $OUTPUT->send();
+}
+
+
if (!isset($_GET['_form'])) {
rcmail_contact_search();
}
@@ -34,9 +88,15 @@ function rcmail_contact_search()
global $RCMAIL, $OUTPUT, $CONFIG, $SEARCH_MODS_DEFAULT;
$adv = isset($_POST['_adv']);
+ $sid = get_input_value('_sid', RCUBE_INPUT_GET);
+ // get search criteria from saved search
+ if ($sid && ($search = $RCMAIL->user->get_search($sid))) {
+ $fields = $search['data']['fields'];
+ $search = $search['data']['search'];
+ }
// get fields/values from advanced search form
- if ($adv) {
+ else if ($adv) {
foreach (array_keys($_POST) as $key) {
$s = trim(get_input_value($key, RCUBE_INPUT_POST, true));
if (strlen($s) && preg_match('/^_search_([a-zA-Z0-9_-]+)$/', $key, $m)) {
@@ -145,6 +205,7 @@ function rcmail_contact_search()
// save search settings in session
$_SESSION['search'][$search_request] = $search_set;
+ $_SESSION['search_params'] = array('id' => $search_request, 'data' => array($fields, $search));
$_SESSION['page'] = 1;
if ($adv)
@@ -153,6 +214,7 @@ function rcmail_contact_search()
if ($result->count > 0) {
// create javascript list
rcmail_js_contacts_list($result);
+ $OUTPUT->show_message('contactsearchsuccessful', 'confirmation', array('nr' => $result->count));
}
else {
$OUTPUT->show_message('nocontactsfound', 'notice');
@@ -162,9 +224,14 @@ function rcmail_contact_search()
$OUTPUT->command('set_env', 'search_request', $search_request);
$OUTPUT->command('set_env', 'pagecount', ceil($result->count / $CONFIG['pagesize']));
$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
+ // Re-set current source
+ $OUTPUT->command('set_env', 'search_id', $sid);
+ $OUTPUT->command('set_env', 'source', '');
+ $OUTPUT->command('set_env', 'group', '');
// unselect currently selected directory/group
- $OUTPUT->command('unselect_directory');
+ if (!$sid)
+ $OUTPUT->command('unselect_directory');
$OUTPUT->command('update_group_commands');
// send response