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 930 2007-11-25 17:34:19Z 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']))
35 $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
37 $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
39 // set message set for search result
40 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
41 $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
43 // set data source env
44 $OUTPUT->set_env('source', $source ? $source : '0');
45 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
47 // add list of address sources to client env
48 $js_list = array("0" => array('id' => 0, 'readonly' => false));
49 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
50 $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writeable']);
51 $OUTPUT->set_env('address_sources', $js_list);
54 function rcmail_directory_list($attrib)
56 global $CONFIG, $OUTPUT;
59 $attrib['id'] = 'rcmdirectorylist';
62 $current = get_input_value('_source', RCUBE_INPUT_GPC);
63 $line_templ = '<li id="%s" class="%s"><a href="%s"' .
64 ' onclick="return %s.command(\'list\',\'%s\',this)"' .
65 ' onmouseover="return %s.focus_folder(\'%s\')"' .
66 ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
67 ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
70 // allow the following attributes to be added to the <ul> tag
71 $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
72 $out .= sprintf($line_templ,
74 !$current ? 'selected' : '',
75 Q(rcmail_url('list', array('_source' => 0))),
84 rcube_label('personaladrbook'));
86 foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
89 $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
90 $out .= sprintf($line_templ,
92 $current == $id ? 'selected' : '',
93 Q(rcmail_url('list', array('_source' => $id))),
102 !empty($prop['name']) ? Q($prop['name']) : Q($id));
107 $OUTPUT->add_gui_object('folderlist', $attrib['id']);
113 // return the message list as HTML table
114 function rcmail_contacts_list($attrib)
116 global $CONTACTS, $OUTPUT;
118 // count contacts for this user
119 $result = $CONTACTS->list_records();
121 // add id to message list table if not specified
122 if (!strlen($attrib['id']))
123 $attrib['id'] = 'rcmAddressList';
125 // define list of cols to be displayed
126 $a_show_cols = array('name');
128 // create XHTML table
129 $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
132 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
133 $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
134 $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
135 $OUTPUT->include_script('list.js');
137 // add some labels to client
138 rcube_add_label('deletecontactconfirm');
144 function rcmail_js_contacts_list($result, $prefix='')
148 if (empty($result) || $result->count == 0)
151 // define list of cols to be displayed
152 $a_show_cols = array('name');
154 while ($row = $result->next())
156 $a_row_cols = array();
159 foreach ($a_show_cols as $col)
160 $a_row_cols[$col] = $row[$col];
162 $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
167 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
168 function rcmail_contact_frame($attrib)
173 $attrib['id'] = 'rcmcontactframe';
175 $attrib['name'] = $attrib['id'];
176 $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
178 $OUTPUT->set_env('contentframe', $attrib['name']);
179 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
180 return '<iframe'. $attrib_str . '></iframe>';
184 function rcmail_rowcount_display($attrib)
189 $attrib['id'] = 'rcmcountdisplay';
191 $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
193 // allow the following attributes to be added to the <span> tag
194 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
196 $out = '<span' . $attrib_str . '>';
197 $out .= rcmail_get_rowcount_text();
204 function rcmail_get_rowcount_text()
208 // read nr of contacts
209 $result = $CONTACTS->get_result();
211 $result = $CONTACTS->count();
213 if ($result->count == 0)
214 $out = rcube_label('nocontactsfound');
216 $out = rcube_label(array(
217 'name' => 'contactsfromto',
219 'from' => $result->first + 1,
220 'to' => min($result->count, $result->first + $CONTACTS->page_size),
221 'count' => $result->count)
228 // register UI objects
229 $OUTPUT->add_handlers(array(
230 'directorylist' => 'rcmail_directory_list',
231 'addresslist' => 'rcmail_contacts_list',
232 'addressframe' => 'rcmail_contact_frame',
233 'recordscountdisplay' => 'rcmail_rowcount_display',
234 'searchform' => 'rcmail_search_form'