commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/func.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
f11541
|
8 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Provide addressbook functionality and GUI objects | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
f11541
|
22 |
require_once('include/rcube_contacts.inc'); |
T |
23 |
require_once('include/rcube_ldap.inc'); |
|
24 |
|
|
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]); |
|
28 |
else |
|
29 |
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); |
|
30 |
|
|
31 |
$CONTACTS->set_pagesize($CONFIG['pagesize']); |
4e17e6
|
32 |
|
T |
33 |
// set list properties and session vars |
f11541
|
34 |
if (!empty($_GET['_page'])) |
c57996
|
35 |
$CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); |
4e17e6
|
36 |
else |
f11541
|
37 |
$CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); |
4e17e6
|
38 |
|
f11541
|
39 |
// set message set for search result |
T |
40 |
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) |
|
41 |
$CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); |
|
42 |
|
|
43 |
// set data source env |
|
44 |
$OUTPUT->set_env('source', $source ? $source : '0'); |
|
45 |
$OUTPUT->set_env('readonly', $CONTACTS->readonly, false); |
|
46 |
|
597c09
|
47 |
// add list of address sources to client env |
T |
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); |
|
52 |
|
f11541
|
53 |
|
T |
54 |
function rcmail_directory_list($attrib) |
|
55 |
{ |
|
56 |
global $CONFIG, $OUTPUT; |
c0da98
|
57 |
|
f11541
|
58 |
if (!$attrib['id']) |
T |
59 |
$attrib['id'] = 'rcmdirectorylist'; |
|
60 |
|
|
61 |
$local_id = '0'; |
|
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'. |
|
68 |
"</a></li>\n"; |
|
69 |
|
|
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, |
|
73 |
'rcmli'.$local_id, |
|
74 |
!$current ? 'selected' : '', |
41bece
|
75 |
Q(rcmail_url('list', array('_source' => 0))), |
f11541
|
76 |
JS_OBJECT_NAME, |
T |
77 |
$local_id, |
|
78 |
JS_OBJECT_NAME, |
|
79 |
$local_id, |
|
80 |
JS_OBJECT_NAME, |
|
81 |
$local_id, |
|
82 |
JS_OBJECT_NAME, |
|
83 |
$local_id, |
|
84 |
rcube_label('personaladrbook')); |
|
85 |
|
|
86 |
foreach ((array)$CONFIG['ldap_public'] as $id => $prop) |
|
87 |
{ |
|
88 |
$js_id = JQ($id); |
|
89 |
$dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); |
|
90 |
$out .= sprintf($line_templ, |
|
91 |
'rcmli'.$dom_id, |
|
92 |
$current == $id ? 'selected' : '', |
41bece
|
93 |
Q(rcmail_url('list', array('_source' => $id))), |
f11541
|
94 |
JS_OBJECT_NAME, |
T |
95 |
$js_id, |
|
96 |
JS_OBJECT_NAME, |
|
97 |
$js_id, |
|
98 |
JS_OBJECT_NAME, |
|
99 |
$js_id, |
|
100 |
JS_OBJECT_NAME, |
|
101 |
$js_id, |
|
102 |
!empty($prop['name']) ? Q($prop['name']) : Q($id)); |
|
103 |
} |
|
104 |
|
|
105 |
$out .= '</ul>'; |
|
106 |
|
|
107 |
$OUTPUT->add_gui_object('folderlist', $attrib['id']); |
|
108 |
|
|
109 |
return $out; |
|
110 |
} |
|
111 |
|
4e17e6
|
112 |
|
T |
113 |
// return the message list as HTML table |
|
114 |
function rcmail_contacts_list($attrib) |
|
115 |
{ |
f11541
|
116 |
global $CONTACTS, $OUTPUT; |
4e17e6
|
117 |
|
T |
118 |
// count contacts for this user |
f11541
|
119 |
$result = $CONTACTS->list_records(); |
T |
120 |
|
4e17e6
|
121 |
// add id to message list table if not specified |
T |
122 |
if (!strlen($attrib['id'])) |
|
123 |
$attrib['id'] = 'rcmAddressList'; |
|
124 |
|
f11541
|
125 |
// define list of cols to be displayed |
T |
126 |
$a_show_cols = array('name'); |
4e17e6
|
127 |
|
f11541
|
128 |
// create XHTML table |
T |
129 |
$out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key); |
|
130 |
|
|
131 |
// set client env |
|
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'); |
|
136 |
|
5e3512
|
137 |
// add some labels to client |
T |
138 |
rcube_add_label('deletecontactconfirm'); |
f11541
|
139 |
|
4e17e6
|
140 |
return $out; |
T |
141 |
} |
|
142 |
|
|
143 |
|
f11541
|
144 |
function rcmail_js_contacts_list($result, $prefix='') |
4e17e6
|
145 |
{ |
f11541
|
146 |
global $OUTPUT; |
4e17e6
|
147 |
|
f11541
|
148 |
if (empty($result) || $result->count == 0) |
T |
149 |
return; |
4e17e6
|
150 |
|
T |
151 |
// define list of cols to be displayed |
f11541
|
152 |
$a_show_cols = array('name'); |
T |
153 |
|
|
154 |
while ($row = $result->next()) |
4e17e6
|
155 |
{ |
T |
156 |
$a_row_cols = array(); |
f11541
|
157 |
|
4e17e6
|
158 |
// format each col |
T |
159 |
foreach ($a_show_cols as $col) |
f11541
|
160 |
$a_row_cols[$col] = $row[$col]; |
4e17e6
|
161 |
|
f11541
|
162 |
$OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); |
T |
163 |
} |
4e17e6
|
164 |
} |
T |
165 |
|
|
166 |
|
|
167 |
// similar function as /steps/settings/identities.inc::rcmail_identity_frame() |
|
168 |
function rcmail_contact_frame($attrib) |
|
169 |
{ |
f11541
|
170 |
global $OUTPUT; |
4e17e6
|
171 |
|
T |
172 |
if (!$attrib['id']) |
|
173 |
$attrib['id'] = 'rcmcontactframe'; |
|
174 |
|
|
175 |
$attrib['name'] = $attrib['id']; |
|
176 |
$attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder')); |
f11541
|
177 |
|
T |
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>'; |
4e17e6
|
181 |
} |
T |
182 |
|
|
183 |
|
|
184 |
function rcmail_rowcount_display($attrib) |
|
185 |
{ |
f11541
|
186 |
global $OUTPUT; |
4e17e6
|
187 |
|
T |
188 |
if (!$attrib['id']) |
|
189 |
$attrib['id'] = 'rcmcountdisplay'; |
|
190 |
|
f11541
|
191 |
$OUTPUT->add_gui_object('countdisplay', $attrib['id']); |
4e17e6
|
192 |
|
T |
193 |
// allow the following attributes to be added to the <span> tag |
|
194 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); |
|
195 |
|
|
196 |
$out = '<span' . $attrib_str . '>'; |
|
197 |
$out .= rcmail_get_rowcount_text(); |
|
198 |
$out .= '</span>'; |
|
199 |
return $out; |
|
200 |
} |
|
201 |
|
|
202 |
|
|
203 |
|
f11541
|
204 |
function rcmail_get_rowcount_text() |
4e17e6
|
205 |
{ |
f11541
|
206 |
global $CONTACTS; |
4e17e6
|
207 |
|
f11541
|
208 |
// read nr of contacts |
T |
209 |
$result = $CONTACTS->get_result(); |
|
210 |
if (!$result) |
|
211 |
$result = $CONTACTS->count(); |
|
212 |
|
|
213 |
if ($result->count == 0) |
4e17e6
|
214 |
$out = rcube_label('nocontactsfound'); |
T |
215 |
else |
f11541
|
216 |
$out = rcube_label(array( |
T |
217 |
'name' => 'contactsfromto', |
|
218 |
'vars' => array( |
|
219 |
'from' => $result->first + 1, |
|
220 |
'to' => min($result->count, $result->first + $CONTACTS->page_size), |
|
221 |
'count' => $result->count) |
|
222 |
)); |
4e17e6
|
223 |
|
T |
224 |
return $out; |
|
225 |
} |
f11541
|
226 |
|
T |
227 |
|
|
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' |
|
235 |
)); |
4e17e6
|
236 |
|
d1d2c4
|
237 |
?> |