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 | |
|
8 |
| Copyright (C) 2005, 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 |
|
|
22 |
$CONTACTS_LIST = array(); |
|
23 |
|
|
24 |
// set list properties and session vars |
|
25 |
if (strlen($_GET['_page'])) |
|
26 |
{ |
|
27 |
$CONTACTS_LIST['page'] = $_GET['_page']; |
|
28 |
$_SESSION['page'] = $_GET['_page']; |
|
29 |
} |
|
30 |
else |
|
31 |
$CONTACTS_LIST['page'] = $_SESSION['page'] ? $_SESSION['page'] : 1; |
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
// return the message list as HTML table |
|
36 |
function rcmail_contacts_list($attrib) |
|
37 |
{ |
|
38 |
global $DB, $CONFIG, $OUTPUT, $CONTACTS_LIST, $JS_OBJECT_NAME; |
|
39 |
|
|
40 |
//$skin_path = $CONFIG['skin_path']; |
|
41 |
//$image_tag = '<img src="%s%s" alt="%s" border="0" />'; |
|
42 |
|
|
43 |
// count contacts for this user |
d7cb77
|
44 |
$sql_result = $DB->query("SELECT COUNT(contact_id) AS rows |
S |
45 |
FROM ".get_table_name('contacts')." |
1cded8
|
46 |
WHERE del<>1 |
d7cb77
|
47 |
AND user_id=?", |
S |
48 |
$_SESSION['user_id']); |
4e17e6
|
49 |
|
T |
50 |
$sql_arr = $DB->fetch_assoc($sql_result); |
|
51 |
$rowcount = $sql_arr['rows']; |
|
52 |
|
|
53 |
if ($rowcount) |
|
54 |
{ |
|
55 |
$start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize']; |
|
56 |
|
|
57 |
// get contacts from DB |
d7cb77
|
58 |
$sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')." |
1cded8
|
59 |
WHERE del<>1 |
d7cb77
|
60 |
AND user_id= ? |
S |
61 |
ORDER BY name", |
|
62 |
$start_row, |
|
63 |
$CONFIG['pagesize'], |
|
64 |
$_SESSION['user_id']); |
4e17e6
|
65 |
} |
T |
66 |
else |
|
67 |
$sql_result = NULL; |
|
68 |
|
|
69 |
|
|
70 |
// add id to message list table if not specified |
|
71 |
if (!strlen($attrib['id'])) |
|
72 |
$attrib['id'] = 'rcmAddressList'; |
|
73 |
|
|
74 |
// define list of cols to be displayed |
|
75 |
$a_show_cols = array('name', 'email'); |
|
76 |
|
|
77 |
// create XHTML table |
|
78 |
$out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'contact_id'); |
|
79 |
|
|
80 |
// set client env |
|
81 |
$javascript = sprintf("%s.gui_object('contactslist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']); |
|
82 |
$javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $CONTACTS_LIST['page']); |
|
83 |
$javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($rowcount/$CONFIG['pagesize'])); |
|
84 |
//$javascript .= sprintf("%s.set_env('contacts', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr)); |
|
85 |
|
|
86 |
$OUTPUT->add_script($javascript); |
|
87 |
|
|
88 |
return $out; |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
function rcmail_js_contacts_list($sql_result, $obj_name='this') |
|
94 |
{ |
|
95 |
global $DB; |
|
96 |
|
|
97 |
$commands = ''; |
|
98 |
|
|
99 |
if (!$sql_result) |
|
100 |
return ''; |
|
101 |
|
|
102 |
// define list of cols to be displayed |
|
103 |
$a_show_cols = array('name', 'email'); |
|
104 |
|
|
105 |
while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|
106 |
{ |
|
107 |
$a_row_cols = array(); |
|
108 |
|
|
109 |
// format each col |
|
110 |
foreach ($a_show_cols as $col) |
|
111 |
{ |
|
112 |
$cont = rep_specialchars_output($sql_arr[$col]); |
|
113 |
$a_row_cols[$col] = $cont; |
|
114 |
} |
|
115 |
|
|
116 |
$commands .= sprintf("%s.add_contact_row(%s, %s);\n", |
|
117 |
$obj_name, |
|
118 |
$sql_arr['contact_id'], |
|
119 |
array2js($a_row_cols)); |
|
120 |
} |
|
121 |
|
|
122 |
return $commands; |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
// similar function as /steps/settings/identities.inc::rcmail_identity_frame() |
|
127 |
function rcmail_contact_frame($attrib) |
|
128 |
{ |
|
129 |
global $OUTPUT, $JS_OBJECT_NAME; |
|
130 |
|
|
131 |
if (!$attrib['id']) |
|
132 |
$attrib['id'] = 'rcmcontactframe'; |
|
133 |
|
|
134 |
$attrib['name'] = $attrib['id']; |
|
135 |
|
|
136 |
$OUTPUT->add_script(sprintf("%s.set_env('contentframe', '%s');", $JS_OBJECT_NAME, $attrib['name'])); |
|
137 |
|
|
138 |
$attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder')); |
|
139 |
$out = '<iframe'. $attrib_str . '></iframe>'; |
|
140 |
|
|
141 |
return $out; |
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
function rcmail_rowcount_display($attrib) |
|
146 |
{ |
|
147 |
global $OUTPUT, $JS_OBJECT_NAME; |
|
148 |
|
|
149 |
if (!$attrib['id']) |
|
150 |
$attrib['id'] = 'rcmcountdisplay'; |
|
151 |
|
|
152 |
$OUTPUT->add_script(sprintf("%s.gui_object('countdisplay', '%s');", $JS_OBJECT_NAME, $attrib['id'])); |
|
153 |
|
|
154 |
// allow the following attributes to be added to the <span> tag |
|
155 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); |
|
156 |
|
|
157 |
|
|
158 |
$out = '<span' . $attrib_str . '>'; |
|
159 |
$out .= rcmail_get_rowcount_text(); |
|
160 |
$out .= '</span>'; |
|
161 |
return $out; |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
function rcmail_get_rowcount_text($max=NULL) |
|
167 |
{ |
|
168 |
global $CONTACTS_LIST, $CONFIG, $DB; |
|
169 |
|
|
170 |
$start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'] + 1; |
|
171 |
|
|
172 |
// get nr of contacts |
|
173 |
if ($max===NULL) |
|
174 |
{ |
d7cb77
|
175 |
$sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')." |
1cded8
|
176 |
WHERE del<>1 |
d7cb77
|
177 |
AND user_id=?", |
S |
178 |
$_SESSION['user_id']); |
4e17e6
|
179 |
|
T |
180 |
$max = $DB->num_rows($sql_result); |
|
181 |
} |
|
182 |
|
|
183 |
if ($max==0) |
|
184 |
$out = rcube_label('nocontactsfound'); |
|
185 |
else |
|
186 |
$out = rcube_label(array('name' => 'contactsfromto', |
|
187 |
'vars' => array('from' => $start_row, |
|
188 |
'to' => min($max, $start_row + $CONFIG['pagesize'] - 1), |
|
189 |
'count' => $max))); |
|
190 |
|
|
191 |
return $out; |
|
192 |
} |
|
193 |
|
|
194 |
?> |