diff options
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/addressbook/func.inc | 32 | ||||
-rw-r--r-- | program/steps/addressbook/groups.inc | 61 | ||||
-rw-r--r-- | program/steps/mail/autocomplete.inc | 34 |
3 files changed, 122 insertions, 5 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index ca1fd03fc..ec0662b24 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -39,6 +39,9 @@ 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)); // set message set for search result if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) @@ -60,7 +63,7 @@ function rcmail_directory_list($attrib) $out = ''; $local_id = '0'; $current = get_input_value('_source', RCUBE_INPUT_GPC); - $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'), + $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'), html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { @@ -79,6 +82,8 @@ function rcmail_directory_list($attrib) $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); } + + $out .= rcmail_contact_groups(array('items' => true)); $OUTPUT->add_gui_object('folderlist', $attrib['id']); @@ -86,6 +91,30 @@ function rcmail_directory_list($attrib) } +function rcmail_contact_groups($attrib) +{ + global $CONTACTS, $OUTPUT; + + if (!$attrib['id']) + $attrib['id'] = 'rcmgroupslist'; + + $groups = $CONTACTS->list_groups(); + $line_templ = html::tag('li', array('id' => 'rcmliG%s', 'class' => 'contactgroup'), + html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup','%s',this)"), '%s')); + + $jsdata = array(); + foreach ($groups as $group) { + $out .= sprintf($line_templ, $group['ID'], $group['ID'], Q($group['name'])); + $jsdata['G'.$group['ID']] = array('id' => $group['ID'], 'name' => $group['name'], 'type' => 'group'); + } + + $OUTPUT->set_env('contactgroups', $jsdata); + //$OUTPUT->add_gui_object('groupslist', $attrib['id']); + + return $attrib['items'] ? $out : html::tag('ul', $attrib, $out, html::$common_attrib); +} + + // return the message list as HTML table function rcmail_contacts_list($attrib) { @@ -200,6 +229,7 @@ $OUTPUT->set_pagetitle(rcube_label('addressbook')); // register UI objects $OUTPUT->add_handlers(array( 'directorylist' => 'rcmail_directory_list', +// 'groupslist' => 'rcmail_contact_groups', 'addresslist' => 'rcmail_contacts_list', 'addressframe' => 'rcmail_contact_frame', 'recordscountdisplay' => 'rcmail_rowcount_display', diff --git a/program/steps/addressbook/groups.inc b/program/steps/addressbook/groups.inc new file mode 100644 index 000000000..8c7aef64b --- /dev/null +++ b/program/steps/addressbook/groups.inc @@ -0,0 +1,61 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/addressbook/groups.inc | + | | + | This file is part of the RoundCube Webmail client | + | Copyright (C) 2010, RoundCube Dev. - Switzerland | + | Licensed under the GNU GPL | + | | + | PURPOSE: | + | Create/delete/rename contact groups and assign/remove contacts | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + + +if ($CONTACTS->readonly || !$CONTACTS->groups) { + $OUTPUT->show_message('sourceisreadonly', 'warning'); + $OUTPUT->send(); +} + +if ($RCMAIL->action == 'create-group') { + if (!empty($_POST['_name'])) { + $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); + $created = $CONTACTS->create_group($name); + } + + if ($created && $OUTPUT->ajax_call) { + $OUTPUT->command('insert_contact_group', $created); + } + else if (!$create) { + $OUTPUT->show_message('errorsaving', 'error'); + } +} + +else if ($RCMAIL->action == 'add2group') { + if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) + if ($CONTACTS->add_to_group($gid, $ids)) + $OUTPUT->show_message('contactaddedtogroup'); + //else + // $OUTPUT->show_message('erroraddingcontact', 'warning'); +} + +else if ($RCMAIL->action == 'removefromgroup') { + if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($ids = get_input_value('_cid', RCUBE_INPUT_POST))) + if ($CONTACTS->remove_from_group($gid, $ids)) + $OUTPUT->show_message('contactremovedfromgroup'); + //else + // $OUTPUT->show_message('erroraddingcontact', 'warning'); +} + +// send response +$OUTPUT->send(); + +?>
\ No newline at end of file diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc index 06209c41b..1e56fb222 100644 --- a/program/steps/mail/autocomplete.inc +++ b/program/steps/mail/autocomplete.inc @@ -5,7 +5,7 @@ | program/steps/mail/autocomplete.inc | | | | This file is part of the RoundCube Webmail client | - | Copyright (C) 2008-2009, RoundCube Dev Team | + | Copyright (C) 2008-2010, RoundCube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -23,7 +23,7 @@ $MAXNUM = 15; $contacts = array(); $book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql'); -if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_POST, true)) { +if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) { foreach ($book_types as $id) { $abook = $RCMAIL->get_address_book($id); @@ -32,16 +32,42 @@ if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_POST, true)) if ($result = $abook->search(array('email','name'), $search)) { while ($sql_arr = $result->iterate()) { $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); - if (count($contacts) >= $MAXNUM) + if (count($contacts) >= $MAXNUM) break 2; } } + + // also list matching contact groups + if ($abook->groups) { + foreach ($abook->list_groups($search) as $group) { + $members = array(); + $abook->reset(); + $abook->set_group($group['ID']); + $result = $abook->list_records(array('email','name')); + while ($result && ($sql_arr = $result->iterate())) + $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); + + if (count($members)) { + $contacts[] = array('name' => $group['name'] . ' (' . rcube_label('group') . ')', 'members' => $members); + if (count($contacts) >= $MAXNUM) + break; + } + } + } } - sort($contacts); + usort($contacts, 'contact_results_sort'); } $OUTPUT->command('ksearch_query_results', $contacts, $search); $OUTPUT->send(); + +function contact_results_sort($a, $b) +{ + $name_a = is_array($a) ? $a['name'] : $a; + $name_b = is_array($b) ? $b['name'] : $b; + return strcmp(trim($name_a, '" '), trim($name_b, '" ')); +} + ?> |