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 |
// instantiate a contacts object according to the given source |
ade8e1
|
23 |
$CONTACTS = $RCMAIL->get_address_book(($source = get_input_value('_source', RCUBE_INPUT_GPC))); |
f11541
|
24 |
|
T |
25 |
$CONTACTS->set_pagesize($CONFIG['pagesize']); |
4e17e6
|
26 |
|
T |
27 |
// set list properties and session vars |
f11541
|
28 |
if (!empty($_GET['_page'])) |
c57996
|
29 |
$CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); |
4e17e6
|
30 |
else |
f11541
|
31 |
$CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); |
4e17e6
|
32 |
|
f11541
|
33 |
// set message set for search result |
T |
34 |
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) |
|
35 |
$CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); |
|
36 |
|
|
37 |
// set data source env |
|
38 |
$OUTPUT->set_env('source', $source ? $source : '0'); |
|
39 |
$OUTPUT->set_env('readonly', $CONTACTS->readonly, false); |
|
40 |
|
597c09
|
41 |
// add list of address sources to client env |
4f9c83
|
42 |
$js_list = array(); |
ed5ed9
|
43 |
if (strtolower($CONFIG['address_book_type']) != 'ldap') { |
4f9c83
|
44 |
// We are using the DB address book, add it. |
S |
45 |
$js_list = array("0" => array('id' => 0, 'readonly' => false)); |
e1eafd
|
46 |
} |
T |
47 |
if (is_array($CONFIG['ldap_public'])) { |
3dc20a
|
48 |
foreach ($CONFIG['ldap_public'] as $id => $prop) |
A |
49 |
$js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']); |
|
50 |
} |
597c09
|
51 |
$OUTPUT->set_env('address_sources', $js_list); |
T |
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 |
|
f89f03
|
61 |
$out = ''; |
f11541
|
62 |
$local_id = '0'; |
T |
63 |
$current = get_input_value('_source', RCUBE_INPUT_GPC); |
f89f03
|
64 |
$line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => '%s'), |
T |
65 |
html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); |
f11541
|
66 |
|
ed5ed9
|
67 |
if (strtolower($CONFIG['address_book_type']) != 'ldap') { |
f89f03
|
68 |
$out .= sprintf($line_templ, $local_id, (!$current ? 'selected' : ''), |
T |
69 |
Q(rcmail_url(null, array('_source' => $local_id))), $local_id, rcube_label('personaladrbook')); |
4f9c83
|
70 |
} // end if |
S |
71 |
else { |
|
72 |
// DB address book not used, see if a source is set, if not use the |
|
73 |
// first LDAP directory. |
|
74 |
if (!$current) { |
|
75 |
$current = key((array)$CONFIG['ldap_public']); |
|
76 |
} // end if |
|
77 |
} // end else |
f11541
|
78 |
|
f89f03
|
79 |
foreach ((array)$CONFIG['ldap_public'] as $id => $prop) { |
f11541
|
80 |
$js_id = JQ($id); |
T |
81 |
$dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); |
f89f03
|
82 |
$out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), |
T |
83 |
Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($prop['name']) ? Q($prop['name']) : Q($id))); |
f11541
|
84 |
} |
T |
85 |
|
|
86 |
$OUTPUT->add_gui_object('folderlist', $attrib['id']); |
|
87 |
|
f89f03
|
88 |
return html::tag('ul', $attrib, $out, html::$common_attrib); |
f11541
|
89 |
} |
T |
90 |
|
4e17e6
|
91 |
|
T |
92 |
// return the message list as HTML table |
|
93 |
function rcmail_contacts_list($attrib) |
|
94 |
{ |
f11541
|
95 |
global $CONTACTS, $OUTPUT; |
4e17e6
|
96 |
|
T |
97 |
// count contacts for this user |
f11541
|
98 |
$result = $CONTACTS->list_records(); |
T |
99 |
|
4e17e6
|
100 |
// add id to message list table if not specified |
T |
101 |
if (!strlen($attrib['id'])) |
|
102 |
$attrib['id'] = 'rcmAddressList'; |
|
103 |
|
f11541
|
104 |
// define list of cols to be displayed |
T |
105 |
$a_show_cols = array('name'); |
4e17e6
|
106 |
|
f11541
|
107 |
// create XHTML table |
T |
108 |
$out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key); |
|
109 |
|
|
110 |
// set client env |
|
111 |
$OUTPUT->add_gui_object('contactslist', $attrib['id']); |
|
112 |
$OUTPUT->set_env('current_page', (int)$CONTACTS->list_page); |
|
113 |
$OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size)); |
|
114 |
$OUTPUT->include_script('list.js'); |
|
115 |
|
5e3512
|
116 |
// add some labels to client |
112c91
|
117 |
$OUTPUT->add_label('deletecontactconfirm'); |
f11541
|
118 |
|
4e17e6
|
119 |
return $out; |
T |
120 |
} |
|
121 |
|
|
122 |
|
f11541
|
123 |
function rcmail_js_contacts_list($result, $prefix='') |
4e17e6
|
124 |
{ |
f11541
|
125 |
global $OUTPUT; |
4e17e6
|
126 |
|
f11541
|
127 |
if (empty($result) || $result->count == 0) |
T |
128 |
return; |
4e17e6
|
129 |
|
T |
130 |
// define list of cols to be displayed |
f11541
|
131 |
$a_show_cols = array('name'); |
T |
132 |
|
|
133 |
while ($row = $result->next()) |
4e17e6
|
134 |
{ |
T |
135 |
$a_row_cols = array(); |
f11541
|
136 |
|
4e17e6
|
137 |
// format each col |
T |
138 |
foreach ($a_show_cols as $col) |
47124c
|
139 |
$a_row_cols[$col] = Q($row[$col]); |
4e17e6
|
140 |
|
f11541
|
141 |
$OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); |
T |
142 |
} |
4e17e6
|
143 |
} |
T |
144 |
|
|
145 |
|
|
146 |
// similar function as /steps/settings/identities.inc::rcmail_identity_frame() |
|
147 |
function rcmail_contact_frame($attrib) |
|
148 |
{ |
f11541
|
149 |
global $OUTPUT; |
4e17e6
|
150 |
|
T |
151 |
if (!$attrib['id']) |
|
152 |
$attrib['id'] = 'rcmcontactframe'; |
|
153 |
|
|
154 |
$attrib['name'] = $attrib['id']; |
f11541
|
155 |
|
T |
156 |
$OUTPUT->set_env('contentframe', $attrib['name']); |
|
157 |
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); |
e2c610
|
158 |
|
95fcc3
|
159 |
return html::iframe($attrib); |
4e17e6
|
160 |
} |
T |
161 |
|
|
162 |
|
|
163 |
function rcmail_rowcount_display($attrib) |
|
164 |
{ |
f11541
|
165 |
global $OUTPUT; |
4e17e6
|
166 |
|
T |
167 |
if (!$attrib['id']) |
|
168 |
$attrib['id'] = 'rcmcountdisplay'; |
|
169 |
|
f11541
|
170 |
$OUTPUT->add_gui_object('countdisplay', $attrib['id']); |
4e17e6
|
171 |
|
e2c610
|
172 |
return html::span($attrib, rcmail_get_rowcount_text()); |
4e17e6
|
173 |
} |
T |
174 |
|
|
175 |
|
|
176 |
|
f11541
|
177 |
function rcmail_get_rowcount_text() |
4e17e6
|
178 |
{ |
f11541
|
179 |
global $CONTACTS; |
4e17e6
|
180 |
|
f11541
|
181 |
// read nr of contacts |
T |
182 |
$result = $CONTACTS->get_result(); |
|
183 |
if (!$result) |
|
184 |
$result = $CONTACTS->count(); |
|
185 |
|
|
186 |
if ($result->count == 0) |
4e17e6
|
187 |
$out = rcube_label('nocontactsfound'); |
T |
188 |
else |
f11541
|
189 |
$out = rcube_label(array( |
T |
190 |
'name' => 'contactsfromto', |
|
191 |
'vars' => array( |
|
192 |
'from' => $result->first + 1, |
|
193 |
'to' => min($result->count, $result->first + $CONTACTS->page_size), |
|
194 |
'count' => $result->count) |
|
195 |
)); |
4e17e6
|
196 |
|
T |
197 |
return $out; |
|
198 |
} |
a55606
|
199 |
|
e2c610
|
200 |
|
a55606
|
201 |
$OUTPUT->set_pagetitle(rcube_label('addressbook')); |
f11541
|
202 |
|
T |
203 |
// register UI objects |
|
204 |
$OUTPUT->add_handlers(array( |
|
205 |
'directorylist' => 'rcmail_directory_list', |
|
206 |
'addresslist' => 'rcmail_contacts_list', |
|
207 |
'addressframe' => 'rcmail_contact_frame', |
|
208 |
'recordscountdisplay' => 'rcmail_rowcount_display', |
47124c
|
209 |
'searchform' => array($OUTPUT, 'search_form') |
f11541
|
210 |
)); |
4e17e6
|
211 |
|
d1d2c4
|
212 |
?> |