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 4151 2010-10-28 07:10:11Z alec $
22 // add list of address sources to client env
23 $js_list = $RCMAIL->get_address_sources();
26 $source = get_input_value('_source', RCUBE_INPUT_GPC);
28 // if source is not set use first directory
30 $source = $js_list[key($js_list)]['id'];
32 // instantiate a contacts object according to the given source
33 $CONTACTS = $RCMAIL->get_address_book($source);
35 $CONTACTS->set_pagesize($CONFIG['pagesize']);
37 // set list properties and session vars
38 if (!empty($_GET['_page']))
39 $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
41 $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
43 if (!empty($_REQUEST['_gid']))
44 $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
46 // set message set for search result
47 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
48 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
50 // set data source env
51 $OUTPUT->set_env('source', $source ? $source : '0');
52 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
53 if (!$OUTPUT->ajax_call) {
54 $OUTPUT->set_env('address_sources', $js_list);
55 $OUTPUT->set_pagetitle(rcube_label('addressbook'));
59 function rcmail_directory_list($attrib)
61 global $RCMAIL, $OUTPUT;
64 $attrib['id'] = 'rcmdirectorylist';
69 $current = get_input_value('_source', RCUBE_INPUT_GPC);
70 $line_templ = html::tag('li', array(
71 'id' => 'rcmli%s', 'class' => 'addressbook %s'),
72 html::a(array('href' => '%s',
73 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
75 if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
79 // DB address book not used, see if a source is set, if not use the
80 // first LDAP directory.
81 $current = key((array)$RCMAIL->config->get('ldap_public', array()));
84 foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
85 $id = $source['id'] ? $source['id'] : $j;
87 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
88 $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
89 Q(rcmail_url(null, array('_source' => $id))),
90 $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
91 $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
92 $jsdata = $groupdata['jsdata'];
93 $out = $groupdata['out'];
96 $OUTPUT->set_env('contactgroups', $jsdata);
97 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
99 return html::tag('ul', $attrib, $out, html::$common_attrib);
103 function rcmail_contact_groups($args)
107 $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
109 if (!empty($groups)) {
110 $line_templ = html::tag('li', array(
111 'id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
112 html::a(array('href' => '#',
113 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
116 foreach ($groups as $group) {
117 $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
118 $args['jsdata']['G'.$args['source'].$group['ID']] = array(
119 'source' => $args['source'], 'id' => $group['ID'],
120 'name' => $group['name'], 'type' => 'group');
128 // return the message list as HTML table
129 function rcmail_contacts_list($attrib)
131 global $CONTACTS, $OUTPUT;
133 // count contacts for this user
134 $result = $CONTACTS->list_records();
136 // add id to message list table if not specified
137 if (!strlen($attrib['id']))
138 $attrib['id'] = 'rcmAddressList';
140 // define list of cols to be displayed
141 $a_show_cols = array('name');
143 // create XHTML table
144 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
147 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
148 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
149 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
150 $OUTPUT->include_script('list.js');
152 // add some labels to client
153 $OUTPUT->add_label('deletecontactconfirm');
159 function rcmail_js_contacts_list($result, $prefix='')
163 if (empty($result) || $result->count == 0)
166 // define list of cols to be displayed
167 $a_show_cols = array('name');
169 while ($row = $result->next()) {
170 $a_row_cols = array();
173 foreach ($a_show_cols as $col)
174 $a_row_cols[$col] = Q($row[$col]);
176 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
181 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
182 function rcmail_contact_frame($attrib)
187 $attrib['id'] = 'rcmcontactframe';
189 $attrib['name'] = $attrib['id'];
191 $OUTPUT->set_env('contentframe', $attrib['name']);
192 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
194 return html::iframe($attrib);
198 function rcmail_rowcount_display($attrib)
203 $attrib['id'] = 'rcmcountdisplay';
205 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
207 return html::span($attrib, rcmail_get_rowcount_text());
211 function rcmail_get_rowcount_text()
215 // read nr of contacts
216 $result = $CONTACTS->get_result();
218 $result = $CONTACTS->count();
221 if ($result->count == 0)
222 $out = rcube_label('nocontactsfound');
224 $out = rcube_label(array(
225 'name' => 'contactsfromto',
227 'from' => $result->first + 1,
228 'to' => min($result->count, $result->first + $CONTACTS->page_size),
229 'count' => $result->count)
236 function rcmail_contact_form($form, $record)
240 // Allow plugins to modify contact form content
241 $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
242 'form' => $form, 'record' => $record));
244 $form = $plugin['form'];
245 $record = $plugin['record'];
248 foreach ($form as $fieldset) {
249 if (empty($fieldset['content']))
253 if (is_array($fieldset['content'])) {
254 $table = new html_table(array('cols' => 2));
256 foreach ($fieldset['content'] as $col => $colprop) {
257 $colprop['id'] = 'rcmfd_'.$col;
259 $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
261 if (!empty($colprop['value'])) {
262 $value = $colprop['value'];
264 else if ($RCMAIL->action == 'show') {
265 $value = $record[$col];
268 $value = rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']);
271 $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
272 $table->add(null, $value);
274 $content = $table->show();
277 $content = $fieldset['content'];
280 $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
287 // register UI objects
288 $OUTPUT->add_handlers(array(
289 'directorylist' => 'rcmail_directory_list',
290 // 'groupslist' => 'rcmail_contact_groups',
291 'addresslist' => 'rcmail_contacts_list',
292 'addressframe' => 'rcmail_contact_frame',
293 'recordscountdisplay' => 'rcmail_rowcount_display',
294 'searchform' => array($OUTPUT, 'search_form')