From ade8e117dfbb62f6dbd16b4aca81dfbdbd054579 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Tue, 02 Sep 2008 03:42:46 -0400 Subject: [PATCH] Let rcmail class create address book instances --- program/steps/addressbook/func.inc | 67 ++++++++++++++++++--------------- 1 files changed, 37 insertions(+), 30 deletions(-) diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 574ef87..c4fbab2 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -19,23 +19,14 @@ */ -require_once('include/rcube_contacts.inc'); -require_once('include/rcube_ldap.inc'); - // instantiate a contacts object according to the given source -if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source])) - $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]); -else - $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); +$CONTACTS = $RCMAIL->get_address_book(($source = get_input_value('_source', RCUBE_INPUT_GPC))); $CONTACTS->set_pagesize($CONFIG['pagesize']); // set list properties and session vars if (!empty($_GET['_page'])) - { - $CONTACTS->set_page(intval($_GET['_page'])); - $_SESSION['page'] = $_GET['_page']; - } + $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); else $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); @@ -48,9 +39,15 @@ $OUTPUT->set_env('readonly', $CONTACTS->readonly, false); // add list of address sources to client env -$js_list = array("0" => array('id' => 0, 'readonly' => false)); -foreach ((array)$CONFIG['ldap_public'] as $id => $prop) - $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writeable']); +$js_list = array(); +if (strtolower($CONFIG['address_book_type']) != 'ldap') { + // We are using the DB address book, add it. + $js_list = array("0" => array('id' => 0, 'readonly' => false)); +} // end if +else if (!empty($CONFIG['ldap_public'])) { + foreach ($CONFIG['ldap_public'] as $id => $prop) + $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']); +} $OUTPUT->set_env('address_sources', $js_list); @@ -72,19 +69,28 @@ // allow the following attributes to be added to the <ul> tag $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n"; - $out .= sprintf($line_templ, - 'rcmli'.$local_id, - !$current ? 'selected' : '', - Q(rcmail_url('list', array('_source' => 0))), - JS_OBJECT_NAME, - $local_id, - JS_OBJECT_NAME, - $local_id, - JS_OBJECT_NAME, - $local_id, - JS_OBJECT_NAME, - $local_id, - rcube_label('personaladrbook')); + if (strtolower($CONFIG['address_book_type']) != 'ldap') { + $out .= sprintf($line_templ, + 'rcmli'.$local_id, + !$current ? 'selected' : '', + Q(rcmail_url('list', array('_source' => 0))), + JS_OBJECT_NAME, + $local_id, + JS_OBJECT_NAME, + $local_id, + JS_OBJECT_NAME, + $local_id, + JS_OBJECT_NAME, + $local_id, + rcube_label('personaladrbook')); + } // end if + else { + // DB address book not used, see if a source is set, if not use the + // first LDAP directory. + if (!$current) { + $current = key((array)$CONFIG['ldap_public']); + } // end if + } // end else foreach ((array)$CONFIG['ldap_public'] as $id => $prop) { @@ -160,7 +166,7 @@ // format each col foreach ($a_show_cols as $col) - $a_row_cols[$col] = $row[$col]; + $a_row_cols[$col] = Q($row[$col]); $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); } @@ -226,7 +232,8 @@ return $out; } - + +$OUTPUT->set_pagetitle(rcube_label('addressbook')); // register UI objects $OUTPUT->add_handlers(array( @@ -234,7 +241,7 @@ 'addresslist' => 'rcmail_contacts_list', 'addressframe' => 'rcmail_contact_frame', 'recordscountdisplay' => 'rcmail_rowcount_display', - 'searchform' => 'rcmail_search_form' + 'searchform' => array($OUTPUT, 'search_form') )); ?> -- Gitblit v1.9.1