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 1412 2008-05-21 07:45:54Z alec $
22 // instantiate a contacts object according to the given source
23 if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source]))
24 $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]);
25 else if (strtolower($CONFIG['address_book_type']) == 'ldap') {
26 // Get the first LDAP address book.
27 $source = key((array)$CONFIG['ldap_public']);
28 $prop = current((array)$CONFIG['ldap_public']);
29 $CONTACTS = new rcube_ldap($prop);
31 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
34 $CONTACTS->set_pagesize($CONFIG['pagesize']);
36 // set list properties and session vars
37 if (!empty($_GET['_page']))
38 $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
40 $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
42 // set message set for search result
43 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
44 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
46 // set data source env
47 $OUTPUT->set_env('source', $source ? $source : '0');
48 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
50 // add list of address sources to client env
52 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
53 // We are using the DB address book, add it.
54 $js_list = array("0" => array('id' => 0, 'readonly' => false));
56 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
57 $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']);
58 $OUTPUT->set_env('address_sources', $js_list);
61 function rcmail_directory_list($attrib)
63 global $CONFIG, $OUTPUT;
66 $attrib['id'] = 'rcmdirectorylist';
69 $current = get_input_value('_source', RCUBE_INPUT_GPC);
70 $line_templ = '<li id="%s" class="%s"><a href="%s"' .
71 ' onclick="return %s.command(\'list\',\'%s\',this)"' .
72 ' onmouseover="return %s.focus_folder(\'%s\')"' .
73 ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
74 ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
77 // allow the following attributes to be added to the <ul> tag
78 $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
79 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
80 $out .= sprintf($line_templ,
82 !$current ? 'selected' : '',
83 Q(rcmail_url('list', array('_source' => 0))),
92 rcube_label('personaladrbook'));
95 // DB address book not used, see if a source is set, if not use the
96 // first LDAP directory.
98 $current = key((array)$CONFIG['ldap_public']);
102 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
105 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
106 $out .= sprintf($line_templ,
108 $current == $id ? 'selected' : '',
109 Q(rcmail_url('list', array('_source' => $id))),
118 !empty($prop['name']) ? Q($prop['name']) : Q($id));
123 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
129 // return the message list as HTML table
130 function rcmail_contacts_list($attrib)
132 global $CONTACTS, $OUTPUT;
134 // count contacts for this user
135 $result = $CONTACTS->list_records();
137 // add id to message list table if not specified
138 if (!strlen($attrib['id']))
139 $attrib['id'] = 'rcmAddressList';
141 // define list of cols to be displayed
142 $a_show_cols = array('name');
144 // create XHTML table
145 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
148 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
149 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
150 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
151 $OUTPUT->include_script('list.js');
153 // add some labels to client
154 rcube_add_label('deletecontactconfirm');
160 function rcmail_js_contacts_list($result, $prefix='')
164 if (empty($result) || $result->count == 0)
167 // define list of cols to be displayed
168 $a_show_cols = array('name');
170 while ($row = $result->next())
172 $a_row_cols = array();
175 foreach ($a_show_cols as $col)
176 $a_row_cols[$col] = Q($row[$col]);
178 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
183 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
184 function rcmail_contact_frame($attrib)
189 $attrib['id'] = 'rcmcontactframe';
191 $attrib['name'] = $attrib['id'];
192 $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
194 $OUTPUT->set_env('contentframe', $attrib['name']);
195 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
196 return '<iframe'. $attrib_str . '></iframe>';
200 function rcmail_rowcount_display($attrib)
205 $attrib['id'] = 'rcmcountdisplay';
207 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
209 // allow the following attributes to be added to the <span> tag
210 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
212 $out = '<span' . $attrib_str . '>';
213 $out .= rcmail_get_rowcount_text();
220 function rcmail_get_rowcount_text()
224 // read nr of contacts
225 $result = $CONTACTS->get_result();
227 $result = $CONTACTS->count();
229 if ($result->count == 0)
230 $out = rcube_label('nocontactsfound');
232 $out = rcube_label(array(
233 'name' => 'contactsfromto',
235 'from' => $result->first + 1,
236 'to' => min($result->count, $result->first + $CONTACTS->page_size),
237 'count' => $result->count)
243 $OUTPUT->set_pagetitle(rcube_label('addressbook'));
245 // register UI objects
246 $OUTPUT->add_handlers(array(
247 'directorylist' => 'rcmail_directory_list',
248 'addresslist' => 'rcmail_contacts_list',
249 'addressframe' => 'rcmail_contact_frame',
250 'recordscountdisplay' => 'rcmail_rowcount_display',
251 'searchform' => array($OUTPUT, 'search_form')