Aleksander Machniak
2016-03-28 46f7b7096450939fe03c95aa81ce06ae4bfca89d
program/steps/addressbook/search.inc
@@ -1,6 +1,6 @@
<?php
/*
/**
 +-----------------------------------------------------------------------+
 | program/steps/addressbook/search.inc                                  |
 |                                                                       |
@@ -22,8 +22,8 @@
*/
if ($RCMAIL->action == 'search-create') {
    $id   = get_input_value('_search', RCUBE_INPUT_POST);
    $name = get_input_value('_name', RCUBE_INPUT_POST, true);
    $id   = rcube_utils::get_input_value('_search', rcube_utils::INPUT_POST);
    $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true);
    if (($params = $_SESSION['search_params']) && $params['id'] == $id) {
@@ -46,16 +46,16 @@
    if ($result) {
        $OUTPUT->show_message('savedsearchcreated', 'confirmation');
        $OUTPUT->command('insert_saved_search', Q($name), Q($result));
        $OUTPUT->command('insert_saved_search', rcube::Q($name), rcube::Q($result));
    }
    else
        $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'savedsearchcreateerror', 'error');
        $OUTPUT->show_message($plugin['message'] ?: 'savedsearchcreateerror', 'error');
    $OUTPUT->send();
}
if ($RCMAIL->action == 'search-delete') {
    $id = get_input_value('_sid', RCUBE_INPUT_POST);
    $id = rcube_utils::get_input_value('_sid', rcube_utils::INPUT_POST);
    $plugin = $RCMAIL->plugins->exec_hook('saved_search_delete', array('id' => $id));
@@ -66,13 +66,13 @@
    if ($result) {
        $OUTPUT->show_message('savedsearchdeleted', 'confirmation');
        $OUTPUT->command('remove_search_item', Q($id));
        $OUTPUT->command('remove_search_item', rcube::Q($id));
        // contact list will be cleared, clear also page counter
        $OUTPUT->command('set_rowcount', rcube_label('nocontactsfound'));
        $OUTPUT->command('set_rowcount', $RCMAIL->gettext('nocontactsfound'));
        $OUTPUT->set_env('pagecount', 0);
    }
    else
        $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'savedsearchdeleteerror', 'error');
        $OUTPUT->show_message($plugin['message'] ?: 'savedsearchdeleteerror', 'error');
    $OUTPUT->send();
}
@@ -91,7 +91,7 @@
    global $RCMAIL, $OUTPUT, $SEARCH_MODS_DEFAULT, $PAGE_SIZE;
    $adv = isset($_POST['_adv']);
    $sid = get_input_value('_sid', RCUBE_INPUT_GET);
    $sid = rcube_utils::get_input_value('_sid', rcube_utils::INPUT_GET);
    // get search criteria from saved search
    if ($sid && ($search = $RCMAIL->user->get_search($sid))) {
@@ -101,7 +101,7 @@
    // get fields/values from advanced search form
    else if ($adv) {
        foreach (array_keys($_POST) as $key) {
            $s = trim(get_input_value($key, RCUBE_INPUT_POST, true));
            $s = trim(rcube_utils::get_input_value($key, rcube_utils::INPUT_POST, true));
            if (strlen($s) && preg_match('/^_search_([a-zA-Z0-9_-]+)$/', $key, $m)) {
                $search[] = $s;
                $fields[] = $m[1];
@@ -115,8 +115,8 @@
    }
    // quick-search
    else {
        $search = trim(get_input_value('_q', RCUBE_INPUT_GET, true));
        $fields = explode(',', get_input_value('_headers', RCUBE_INPUT_GET));
        $search = trim(rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true));
        $fields = explode(',', rcube_utils::get_input_value('_headers', rcube_utils::INPUT_GET));
        if (empty($fields)) {
            $fields = array_keys($SEARCH_MODS_DEFAULT);
@@ -184,7 +184,7 @@
        while ($row = $result->next()) {
            $row['sourceid'] = $s['id'];
            $key = rcmail_contact_key($row, $sort_col);
            $key = rcube_addressbook::compose_contact_key($row, $sort_col);
            $records[$key] = $row;
        }
@@ -237,9 +237,12 @@
    $OUTPUT->command('set_env', 'source', '');
    $OUTPUT->command('set_env', 'group', '');
    // unselect currently selected directory/group
    if (!$sid)
    if (!$sid) {
        // unselect currently selected directory/group
        $OUTPUT->command('unselect_directory');
        // enable "Save search" command
        $OUTPUT->command('enable_command', 'search-create', true);
    }
    $OUTPUT->command('update_group_commands');
    // send response
@@ -250,21 +253,21 @@
{
    global $RCMAIL, $CONTACT_COLTYPES;
    $i_size = !empty($attrib['size']) ? $attrib['size'] : 30;
    $i_size = $attrib['size'] ?: 30;
    $form = array(
        'main' => array(
            'name'    => rcube_label('properties'),
            'name'    => $RCMAIL->gettext('properties'),
            'content' => array(
            ),
        ),
        'personal' => array(
            'name'    => rcube_label('personalinfo'),
            'name'    => $RCMAIL->gettext('personalinfo'),
            'content' => array(
            ),
        ),
        'other' => array(
            'name'    => rcube_label('other'),
            'name'    => $RCMAIL->gettext('other'),
            'content' => array(
            ),
        ),
@@ -294,14 +297,18 @@
        if ($colprop['type'] != 'image' && !$colprop['nosearch'])
        {
            $ftype    = $colprop['type'] == 'select' ? 'select' : 'text';
            $label    = isset($colprop['label']) ? $colprop['label'] : rcube_label($col);
            $category = $colprop['category'] ? $colprop['category'] : 'other';
            $label    = isset($colprop['label']) ? $colprop['label'] : $RCMAIL->gettext($col);
            $category = $colprop['category'] ?: 'other';
            if ($ftype == 'text')
            // load jquery UI datepicker for date fields
            if ($colprop['type'] == 'date')
                $colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
            else if ($ftype == 'text')
                $colprop['size'] = $i_size;
            $content  = html::div('row', html::div('contactfieldlabel label', Q($label))
                . html::div('contactfieldcontent', rcmail_get_edit_field('search_'.$col, '', $colprop, $ftype)));
            $content  = html::div('row', html::div('contactfieldlabel label', rcube::Q($label))
                . html::div('contactfieldcontent', rcube_output::get_edit_field('search_'.$col, '', $colprop, $ftype)));
            $form[$category]['content'][] = $content;
        }
@@ -325,7 +332,7 @@
            $content = html::div('contactfieldgroup', join("\n", $f['content']));
            $out .= html::tag('fieldset', $attrib,
                html::tag('legend', null, Q($f['name']))
                html::tag('legend', null, rcube::Q($f['name']))
                . $content) . "\n";
        }
    }