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 578 2007-05-18 13:06:01Z thomasb $
22 require_once('include/rcube_contacts.inc');
23 require_once('include/rcube_ldap.inc');
25 // instantiate a contacts object according to the given source
26 if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source]))
27 $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]);
29 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
31 $CONTACTS->set_pagesize($CONFIG['pagesize']);
33 // set list properties and session vars
34 if (!empty($_GET['_page']))
36 $CONTACTS->set_page(intval($_GET['_page']));
37 $_SESSION['page'] = $_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
51 $js_list = array("0" => array('id' => 0, 'readonly' => false));
52 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
53 $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writeable']);
54 $OUTPUT->set_env('address_sources', $js_list);
57 function rcmail_directory_list($attrib)
59 global $CONFIG, $OUTPUT;
62 $attrib['id'] = 'rcmdirectorylist';
65 $current = get_input_value('_source', RCUBE_INPUT_GPC);
66 $line_templ = '<li id="%s" class="%s"><a href="%s"' .
67 ' onclick="return %s.command(\'list\',\'%s\',this)"' .
68 ' onmouseover="return %s.focus_folder(\'%s\')"' .
69 ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
70 ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
73 // allow the following attributes to be added to the <ul> tag
74 $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
75 $out .= sprintf($line_templ,
77 !$current ? 'selected' : '',
78 Q(rcmail_url('list', array('_source' => 0))),
87 rcube_label('personaladrbook'));
89 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
92 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
93 $out .= sprintf($line_templ,
95 $current == $id ? 'selected' : '',
96 Q(rcmail_url('list', array('_source' => $id))),
105 !empty($prop['name']) ? Q($prop['name']) : Q($id));
110 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
116 // return the message list as HTML table
117 function rcmail_contacts_list($attrib)
119 global $CONTACTS, $OUTPUT;
121 // count contacts for this user
122 $result = $CONTACTS->list_records();
124 // add id to message list table if not specified
125 if (!strlen($attrib['id']))
126 $attrib['id'] = 'rcmAddressList';
128 // define list of cols to be displayed
129 $a_show_cols = array('name');
131 // create XHTML table
132 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
135 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
136 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
137 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
138 $OUTPUT->include_script('list.js');
140 // add some labels to client
141 rcube_add_label('deletecontactconfirm');
147 function rcmail_js_contacts_list($result, $prefix='')
151 if (empty($result) || $result->count == 0)
154 // define list of cols to be displayed
155 $a_show_cols = array('name');
157 while ($row = $result->next())
159 $a_row_cols = array();
162 foreach ($a_show_cols as $col)
163 $a_row_cols[$col] = $row[$col];
165 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
170 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
171 function rcmail_contact_frame($attrib)
176 $attrib['id'] = 'rcmcontactframe';
178 $attrib['name'] = $attrib['id'];
179 $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
181 $OUTPUT->set_env('contentframe', $attrib['name']);
182 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
183 return '<iframe'. $attrib_str . '></iframe>';
187 function rcmail_rowcount_display($attrib)
192 $attrib['id'] = 'rcmcountdisplay';
194 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
196 // allow the following attributes to be added to the <span> tag
197 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
199 $out = '<span' . $attrib_str . '>';
200 $out .= rcmail_get_rowcount_text();
207 function rcmail_get_rowcount_text()
211 // read nr of contacts
212 $result = $CONTACTS->get_result();
214 $result = $CONTACTS->count();
216 if ($result->count == 0)
217 $out = rcube_label('nocontactsfound');
219 $out = rcube_label(array(
220 'name' => 'contactsfromto',
222 'from' => $result->first + 1,
223 'to' => min($result->count, $result->first + $CONTACTS->page_size),
224 'count' => $result->count)
231 // register UI objects
232 $OUTPUT->add_handlers(array(
233 'directorylist' => 'rcmail_directory_list',
234 'addresslist' => 'rcmail_contacts_list',
235 'addressframe' => 'rcmail_contact_frame',
236 'recordscountdisplay' => 'rcmail_rowcount_display',
237 'searchform' => 'rcmail_search_form'