From a61bbb24aafec5718ca9bc985e7c596c5821f018 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Fri, 26 Mar 2010 12:38:20 -0400 Subject: [PATCH] Added basic contact groups feature --- program/steps/addressbook/func.inc | 59 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 43 insertions(+), 16 deletions(-) diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index e3d7606..ec0662b 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -19,8 +19,18 @@ */ +// add list of address sources to client env +$js_list = $RCMAIL->get_address_sources(); + +// select source +$source = get_input_value('_source', RCUBE_INPUT_GPC); + +// if source is not set use first directory +if (empty($source)) + $source = $js_list[key($js_list)]['id']; + // instantiate a contacts object according to the given source -$CONTACTS = $RCMAIL->get_address_book(($source = get_input_value('_source', RCUBE_INPUT_GPC))); +$CONTACTS = $RCMAIL->get_address_book($source); $CONTACTS->set_pagesize($CONFIG['pagesize']); @@ -29,6 +39,9 @@ $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']])) @@ -37,20 +50,7 @@ // set data source env $OUTPUT->set_env('source', $source ? $source : '0'); $OUTPUT->set_env('readonly', $CONTACTS->readonly, false); - -// add list of address sources to client env -$js_list = array(); -if (strtolower($CONFIG['address_book_type']) != 'ldap') { - // We are using the DB address book, add it. - $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false); -} -if (is_array($CONFIG['ldap_public'])) { - foreach ($CONFIG['ldap_public'] as $id => $prop) - $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']); -} - -$plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list)); -$OUTPUT->set_env('address_sources', $plugin['sources']); +$OUTPUT->set_env('address_sources', $js_list); function rcmail_directory_list($attrib) @@ -63,7 +63,7 @@ $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') { @@ -82,10 +82,36 @@ $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']); return html::tag('ul', $attrib, $out, html::$common_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); } @@ -203,6 +229,7 @@ // 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', -- Gitblit v1.9.1