4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/func.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide addressbook functionality and GUI objects |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: func.inc 1939 2008-10-05 07:18:15Z alec $
22 // instantiate a contacts object according to the given source
23 $CONTACTS = $RCMAIL->get_address_book(($source = get_input_value('_source', RCUBE_INPUT_GPC)));
25 $CONTACTS->set_pagesize($CONFIG['pagesize']);
27 // set list properties and session vars
28 if (!empty($_GET['_page']))
29 $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
31 $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
33 // set message set for search result
34 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
35 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
37 // set data source env
38 $OUTPUT->set_env('source', $source ? $source : '0');
39 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
41 // add list of address sources to client env
43 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
44 // We are using the DB address book, add it.
45 $js_list = array("0" => array('id' => 0, 'readonly' => false));
47 if (is_array($CONFIG['ldap_public'])) {
48 foreach ($CONFIG['ldap_public'] as $id => $prop)
49 $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']);
51 $OUTPUT->set_env('address_sources', $js_list);
54 function rcmail_directory_list($attrib)
56 global $CONFIG, $OUTPUT;
59 $attrib['id'] = 'rcmdirectorylist';
63 $current = get_input_value('_source', RCUBE_INPUT_GPC);
64 $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'),
65 html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
67 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
68 $out .= sprintf($line_templ, $local_id, (!$current ? 'selected' : ''),
69 Q(rcmail_url(null, array('_source' => $local_id))), $local_id, rcube_label('personaladrbook'));
72 // DB address book not used, see if a source is set, if not use the
73 // first LDAP directory.
75 $current = key((array)$CONFIG['ldap_public']);
79 foreach ((array)$CONFIG['ldap_public'] as $id => $prop) {
81 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
82 $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
83 Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($prop['name']) ? Q($prop['name']) : Q($id)));
86 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
88 return html::tag('ul', $attrib, $out, html::$common_attrib);
92 // return the message list as HTML table
93 function rcmail_contacts_list($attrib)
95 global $CONTACTS, $OUTPUT;
97 // count contacts for this user
98 $result = $CONTACTS->list_records();
100 // add id to message list table if not specified
101 if (!strlen($attrib['id']))
102 $attrib['id'] = 'rcmAddressList';
104 // define list of cols to be displayed
105 $a_show_cols = array('name');
107 // create XHTML table
108 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
111 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
112 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
113 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
114 $OUTPUT->include_script('list.js');
116 // add some labels to client
117 $OUTPUT->add_label('deletecontactconfirm');
123 function rcmail_js_contacts_list($result, $prefix='')
127 if (empty($result) || $result->count == 0)
130 // define list of cols to be displayed
131 $a_show_cols = array('name');
133 while ($row = $result->next())
135 $a_row_cols = array();
138 foreach ($a_show_cols as $col)
139 $a_row_cols[$col] = Q($row[$col]);
141 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
146 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
147 function rcmail_contact_frame($attrib)
152 $attrib['id'] = 'rcmcontactframe';
154 $attrib['name'] = $attrib['id'];
156 $OUTPUT->set_env('contentframe', $attrib['name']);
157 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
159 return html::iframe($attrib);
163 function rcmail_rowcount_display($attrib)
168 $attrib['id'] = 'rcmcountdisplay';
170 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
172 return html::span($attrib, rcmail_get_rowcount_text());
177 function rcmail_get_rowcount_text()
181 // read nr of contacts
182 $result = $CONTACTS->get_result();
184 $result = $CONTACTS->count();
186 if ($result->count == 0)
187 $out = rcube_label('nocontactsfound');
189 $out = rcube_label(array(
190 'name' => 'contactsfromto',
192 'from' => $result->first + 1,
193 'to' => min($result->count, $result->first + $CONTACTS->page_size),
194 'count' => $result->count)
201 $OUTPUT->set_pagetitle(rcube_label('addressbook'));
203 // register UI objects
204 $OUTPUT->add_handlers(array(
205 'directorylist' => 'rcmail_directory_list',
206 'addresslist' => 'rcmail_contacts_list',
207 'addressframe' => 'rcmail_contact_frame',
208 'recordscountdisplay' => 'rcmail_rowcount_display',
209 'searchform' => array($OUTPUT, 'search_form')