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