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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
<?php
/**
*
* @package ucp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* View message folder
* Called from ucp_pm with mode == 'view_messages' && action == 'view_folder'
*/
function view_folder($id, $mode, $folder_id, $folder, $type)
{
global $phpbb_root_path, $phpEx, $SID, $user, $template, $auth, $config, $db;
$user->add_lang('viewforum');
// Grab icons
$icons = array();
obtain_icons($icons);
$color_rows = array('marked', 'replied', 'message_reported', 'friend', 'foe');
foreach ($color_rows as $var)
{
$template->assign_block_vars('pm_colour_info', array(
'IMG' => $user->img("pm_{$var}", ''),
'CLASS' => "pm_{$var}_colour",
'LANG' => $user->lang[strtoupper($var) . '_MESSAGE'])
);
}
$mark_options = array('mark_important', 'delete_marked');
$s_mark_options = '';
foreach ($mark_options as $mark_option)
{
$s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
}
$friend = $foe = array();
// Get friends and foes
$sql = 'SELECT *
FROM ' . ZEBRA_TABLE . '
WHERE user_id = ' . $user->data['user_id'];
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$friend[$row['zebra_id']] = $row['friend'];
$foe[$row['zebra_id']] = $row['foe'];
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'S_UNREAD' => ($type == 'unread'),
'S_MARK_OPTIONS'=> $s_mark_options)
);
$folder_info = get_pm_from($folder_id, $folder, $user->data['user_id'], "{$phpbb_root_path}ucp.$phpEx$SID&i=$id", $type);
// Okay, lets dump out the page ...
if (sizeof($folder_info['pm_list']))
{
// Build Recipient List if in outbox/sentbox - max two additional queries
$recipient_list = $address_list = $address = array();
if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
{
foreach ($folder_info['rowset'] as $message_id => $row)
{
$address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
foreach (array('u', 'g') as $save)
{
if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save]))
{
foreach (array_keys($address[$message_id][$save]) as $ug_id)
{
$recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
}
}
}
}
foreach (array('u', 'g') as $ug_type)
{
if (isset($recipient_list[$ug_type]) && sizeof($recipient_list[$ug_type]))
{
$sql = ($ug_type == 'u') ? 'SELECT user_id as id, username as name, user_colour as colour FROM ' . USERS_TABLE . ' WHERE user_id' : 'SELECT group_id as id, group_name as name, group_colour as colour FROM ' . GROUPS_TABLE . ' WHERE group_id';
$sql .= ' IN (' . implode(', ', array_keys($recipient_list[$ug_type])) . ')';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
}
$db->sql_freeresult($result);
}
}
foreach ($address as $message_id => $adr_ary)
{
foreach ($adr_ary as $type => $id_ary)
{
foreach ($id_ary as $ug_id => $_id)
{
$address_list[$message_id][] = (($type == 'u') ? "<a href=\"{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=$ug_id\">" : "<a href=\"{$phpbb_root_path}groupcp.$phpEx$SID&g=$ug_id\">") . (($recipient_list[$type][$ug_id]['colour']) ? '<span style="color:#' . $recipient_list[$type][$ug_id]['colour'] . '">' : '<span>') . $recipient_list[$type][$ug_id]['name'] . '</span></a>';
}
}
}
unset($recipient_list, $address);
}
$url = "{$phpbb_root_path}ucp.$phpEx$SID&i=$id";
foreach ($folder_info['pm_list'] as $message_id)
{
$row = &$folder_info['rowset'][$message_id];
$folder_img = ($row['unread']) ? 'folder_new' : 'folder';
$folder_alt = ($row['unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
// Generate all URIs ...
$message_author = "<a href=\"{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['author_id'] . '">' . $row['username'] . '</a>';
$view_message_url = "$url&f=$folder_id&p=$message_id";
$remove_message_url = "$url&mode=compose&action=delete&p=$message_id";
$row_indicator = '';
foreach ($color_rows as $var)
{
if (($var != 'friend' && $var != 'foe' && $row[$var])
||
(($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]))
{
$row_indicator = $var;
break;
}
}
// Send vars to template
$template->assign_block_vars('messagerow', array(
'PM_CLASS' => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '',
'FOLDER_ID' => $folder_id,
'MESSAGE_ID' => $message_id,
'MESSAGE_AUTHOR' => $message_author,
'SENT_TIME' => $user->format_date($row['message_time']),
'SUBJECT' => censor_text($row['message_subject']),
'FOLDER' => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '',
'U_FOLDER' => (isset($folder[$row['folder_id']])) ? "$url&folder=" . $row['folder_id'] : '',
'PM_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '',
'FOLDER_IMG' => $user->img($folder_img, $folder_alt),
'PM_IMG' => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '',
'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $row['message_attachment'] && $config['allow_pm_attach'] && $config['auth_download_pm']) ? $user->img('icon_attach', sprintf($user->lang['TOTAL_ATTACHMENTS'], $row['message_attachment'])) : '',
'S_PM_REPORTED' => (!empty($row['message_reported']) && $auth->acl_get('m_')) ? true : false,
'S_PM_DELETED' => ($row['deleted']) ? true : false,
'U_VIEW_PM' => ($row['deleted']) ? '' : $view_message_url,
'U_REMOVE_PM' => ($row['deleted']) ? $remove_message_url : '',
'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '',
'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&mode=reports&pm=$message_id")
// 'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&mode=mod_queue&t=$topic_id")
);
}
unset($folder_info['rowset']);
$template->assign_vars(array(
'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false,
'S_SHOW_COLOUR_LEGEND' => true)
);
}
}
/**
* Get Messages from folder/user
*
* @param unread|new|folder $type type of message
*/
function get_pm_from($folder_id, $folder, $user_id, $url, $type = 'folder')
{
global $user, $db, $template, $config, $auth, $_POST;
$start = request_var('start', 0);
$sort_days = request_var('st', ((!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0));
$sort_key = request_var('sk', ((!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'));
$sort_dir = request_var('sd', ((!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'));
// PM ordering options
$limit_days = array(0 => $user->lang['ALL_MESSAGES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
$sort_by_sql = array('a' => 'u.username', 't' => 'p.message_time', 's' => 'p.message_subject');
$sort_key = (!in_array($sort_key, array('a', 't', 's'))) ? 't' : $sort_key;
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
if ($type != 'folder')
{
$folder_sql = ($type == 'unread') ? 't.unread = 1' : 't.new = 1';
$folder_id = PRIVMSGS_INBOX;
}
else
{
$folder_sql = 't.folder_id = ' . (int) $folder_id;
}
// Limit pms to certain time frame, obtain correct pm count
if ($sort_days)
{
$min_post_time = time() - ($sort_days * 86400);
$sql = 'SELECT COUNT(t.msg_id) AS pm_count
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
WHERE $folder_sql
AND t.user_id = $user_id
AND t.msg_id = p.msg_id
AND p.message_time >= $min_post_time";
$result = $db->sql_query_limit($sql, 1);
if (isset($_POST['sort']))
{
$start = 0;
}
$pm_count = ($row = $db->sql_fetchrow($result)) ? $row['pm_count'] : 0;
$db->sql_freeresult($result);
$sql_limit_time = "AND p.message_time >= $min_post_time";
}
else
{
if ($type == 'folder')
{
$pm_count = $folder[$folder_id]['num_messages'];
}
else
{
if (in_array($folder_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX)))
{
$sql = 'SELECT COUNT(t.msg_id) AS pm_count
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
WHERE $folder_sql
AND t.user_id = $user_id
AND t.msg_id = p.msg_id";
}
else
{
$sql = 'SELECT pm_count
FROM ' . PRIVMSGS_FOLDER_TABLE . "
WHERE folder_id = $folder_id
AND user_id = $user_id";
}
$result = $db->sql_query_limit($sql, 1);
$pm_count = ($row = $db->sql_fetchrow($result)) ? $row['pm_count'] : 0;
$db->sql_freeresult($result);
}
$sql_limit_time = '';
}
$template->assign_vars(array(
'PAGINATION' => generate_pagination("$url&mode=view_messages&action=view_folder&f=$folder_id&$u_sort_param", $pm_count, $config['topics_per_page'], $start),
'PAGE_NUMBER' => on_page($pm_count, $config['topics_per_page'], $start),
'TOTAL_MESSAGES'=> (($pm_count == 1) ? $user->lang['VIEW_PM_MESSAGE'] : sprintf($user->lang['VIEW_PM_MESSAGES'], $pm_count)),
'POST_IMG' => (!$auth->acl_get('u_sendpm')) ? $user->img('btn_locked', 'PM_LOCKED') : $user->img('btn_post_pm', 'POST_PM'),
'REPORTED_IMG' => $user->img('icon_reported', 'MESSAGE_REPORTED'),
'L_NO_MESSAGES' => (!$auth->acl_get('u_sendpm')) ? $user->lang['POST_PM_LOCKED'] : $user->lang['NO_MESSAGES'],
'S_SELECT_SORT_DIR' => $s_sort_dir,
'S_SELECT_SORT_KEY' => $s_sort_key,
'S_SELECT_SORT_DAYS' => $s_limit_days,
'S_TOPIC_ICONS' => ($config['enable_pm_icons']) ? true : false,
'U_POST_NEW_TOPIC' => ($auth->acl_get('u_sendpm')) ? "$url&mode=compose&action=post" : '',
'S_PM_ACTION' => "$url&mode=view_messages&action=view_folder&f=$folder_id")
);
// Grab all pm data
$rowset = $pm_list = array();
// If the user is trying to reach late pages, start searching from the end
$store_reverse = false;
$sql_limit = $config['topics_per_page'];
if ($start > $pm_count / 2)
{
$store_reverse = true;
if ($start + $config['topics_per_page'] > $pm_count)
{
$sql_limit = min($config['topics_per_page'], max(1, $pm_count - $start));
}
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
$sql_start = max(0, $pm_count - $sql_limit - $start);
}
else
{
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
$sql_start = $start;
}
$sql = 'SELECT t.*, p.author_id, p.root_level, p.message_time, p.message_subject, p.icon_id, p.message_reported, p.to_address, p.message_attachment, p.bcc_address, u.username
FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE t.user_id = $user_id
AND p.author_id = u.user_id
AND $folder_sql
AND t.msg_id = p.msg_id
$sql_limit_time
ORDER BY $sql_sort_order";
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
while ($row = $db->sql_fetchrow($result))
{
$rowset[$row['msg_id']] = $row;
$pm_list[] = $row['msg_id'];
}
$db->sql_freeresult($result);
$pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list;
return array(
'pm_count' => $pm_count,
'pm_list' => $pm_list,
'rowset' => $rowset
);
}
?>
|