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 2894 2009-08-29 20:56:00Z alec $
22 // add list of address sources to client env
24 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
25 // We are using the DB address book, add it.
26 $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false);
28 if (is_array($CONFIG['ldap_public'])) {
29 foreach ($CONFIG['ldap_public'] as $id => $prop)
30 $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']);
33 $plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list));
34 $js_list = $plugin['sources'];
37 $source = get_input_value('_source', RCUBE_INPUT_GPC);
39 // if source is not set use first directory
41 $source = $js_list[key($js_list)]['id'];
44 // instantiate a contacts object according to the given source
45 $CONTACTS = $RCMAIL->get_address_book($source);
47 $CONTACTS->set_pagesize($CONFIG['pagesize']);
49 // set list properties and session vars
50 if (!empty($_GET['_page']))
51 $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
53 $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
55 // set message set for search result
56 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
57 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
59 // set data source env
60 $OUTPUT->set_env('source', $source ? $source : '0');
61 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
62 $OUTPUT->set_env('address_sources', $js_list);
65 function rcmail_directory_list($attrib)
67 global $RCMAIL, $OUTPUT;
70 $attrib['id'] = 'rcmdirectorylist';
74 $current = get_input_value('_source', RCUBE_INPUT_GPC);
75 $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'),
76 html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
78 if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
82 // DB address book not used, see if a source is set, if not use the
83 // first LDAP directory.
84 $current = key((array)$RCMAIL->config->get('ldap_public', array()));
87 foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
88 $id = $source['id'] ? $source['id'] : $j;
90 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
91 $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
92 Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
95 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
97 return html::tag('ul', $attrib, $out, html::$common_attrib);
101 // return the message list as HTML table
102 function rcmail_contacts_list($attrib)
104 global $CONTACTS, $OUTPUT;
106 // count contacts for this user
107 $result = $CONTACTS->list_records();
109 // add id to message list table if not specified
110 if (!strlen($attrib['id']))
111 $attrib['id'] = 'rcmAddressList';
113 // define list of cols to be displayed
114 $a_show_cols = array('name');
116 // create XHTML table
117 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
120 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
121 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
122 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
123 $OUTPUT->include_script('list.js');
125 // add some labels to client
126 $OUTPUT->add_label('deletecontactconfirm');
132 function rcmail_js_contacts_list($result, $prefix='')
136 if (empty($result) || $result->count == 0)
139 // define list of cols to be displayed
140 $a_show_cols = array('name');
142 while ($row = $result->next())
144 $a_row_cols = array();
147 foreach ($a_show_cols as $col)
148 $a_row_cols[$col] = Q($row[$col]);
150 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
155 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
156 function rcmail_contact_frame($attrib)
161 $attrib['id'] = 'rcmcontactframe';
163 $attrib['name'] = $attrib['id'];
165 $OUTPUT->set_env('contentframe', $attrib['name']);
166 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
168 return html::iframe($attrib);
172 function rcmail_rowcount_display($attrib)
177 $attrib['id'] = 'rcmcountdisplay';
179 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
181 return html::span($attrib, rcmail_get_rowcount_text());
186 function rcmail_get_rowcount_text()
190 // read nr of contacts
191 $result = $CONTACTS->get_result();
193 $result = $CONTACTS->count();
195 if ($result->count == 0)
196 $out = rcube_label('nocontactsfound');
198 $out = rcube_label(array(
199 'name' => 'contactsfromto',
201 'from' => $result->first + 1,
202 'to' => min($result->count, $result->first + $CONTACTS->page_size),
203 'count' => $result->count)
210 $OUTPUT->set_pagetitle(rcube_label('addressbook'));
212 // register UI objects
213 $OUTPUT->add_handlers(array(
214 'directorylist' => 'rcmail_directory_list',
215 'addresslist' => 'rcmail_contacts_list',
216 'addressframe' => 'rcmail_contact_frame',
217 'recordscountdisplay' => 'rcmail_rowcount_display',
218 'searchform' => array($OUTPUT, 'search_form')