1 | <?php
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * @package ucp
|
---|
5 | * @version $Id: ucp_pm_viewfolder.php 8795 2008-08-29 11:50:01Z Kellanved $
|
---|
6 | * @copyright (c) 2005 phpBB Group
|
---|
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @ignore
|
---|
13 | */
|
---|
14 | if (!defined('IN_PHPBB'))
|
---|
15 | {
|
---|
16 | exit;
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * View message folder
|
---|
21 | * Called from ucp_pm with mode == 'view' && action == 'view_folder'
|
---|
22 | */
|
---|
23 | function view_folder($id, $mode, $folder_id, $folder)
|
---|
24 | {
|
---|
25 | global $user, $template, $auth, $db, $cache;
|
---|
26 | global $phpbb_root_path, $config, $phpEx;
|
---|
27 |
|
---|
28 | $submit_export = (isset($_POST['submit_export'])) ? true : false;
|
---|
29 |
|
---|
30 | $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']);
|
---|
31 |
|
---|
32 | if (!$submit_export)
|
---|
33 | {
|
---|
34 | $user->add_lang('viewforum');
|
---|
35 |
|
---|
36 | // Grab icons
|
---|
37 | $icons = $cache->obtain_icons();
|
---|
38 |
|
---|
39 | $color_rows = array('marked', 'replied');
|
---|
40 |
|
---|
41 | // only show the friend/foe color rows if the module is enabled
|
---|
42 | $zebra_enabled = false;
|
---|
43 |
|
---|
44 | $_module = new p_master();
|
---|
45 | $_module->list_modules('ucp');
|
---|
46 | $_module->set_active('zebra');
|
---|
47 |
|
---|
48 | $zebra_enabled = ($_module->active_module === false) ? false : true;
|
---|
49 |
|
---|
50 | unset($_module);
|
---|
51 |
|
---|
52 | if ($zebra_enabled)
|
---|
53 | {
|
---|
54 | $color_rows = array_merge($color_rows, array('friend', 'foe'));
|
---|
55 | }
|
---|
56 |
|
---|
57 | foreach ($color_rows as $var)
|
---|
58 | {
|
---|
59 | $template->assign_block_vars('pm_colour_info', array(
|
---|
60 | 'IMG' => $user->img("pm_{$var}", ''),
|
---|
61 | 'CLASS' => "pm_{$var}_colour",
|
---|
62 | 'LANG' => $user->lang[strtoupper($var) . '_MESSAGE'])
|
---|
63 | );
|
---|
64 | }
|
---|
65 |
|
---|
66 | $mark_options = array('mark_important', 'delete_marked');
|
---|
67 |
|
---|
68 | $s_mark_options = '';
|
---|
69 | foreach ($mark_options as $mark_option)
|
---|
70 | {
|
---|
71 | $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
|
---|
72 | }
|
---|
73 |
|
---|
74 | // We do the folder moving options here too, for template authors to use...
|
---|
75 | $s_folder_move_options = '';
|
---|
76 | if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX)
|
---|
77 | {
|
---|
78 | foreach ($folder as $f_id => $folder_ary)
|
---|
79 | {
|
---|
80 | if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)
|
---|
81 | {
|
---|
82 | continue;
|
---|
83 | }
|
---|
84 |
|
---|
85 | $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="sep"' : '') . ' value="' . $f_id . '">';
|
---|
86 | $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']);
|
---|
87 | $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
|
---|
88 | }
|
---|
89 | }
|
---|
90 | $friend = $foe = array();
|
---|
91 |
|
---|
92 | // Get friends and foes
|
---|
93 | $sql = 'SELECT *
|
---|
94 | FROM ' . ZEBRA_TABLE . '
|
---|
95 | WHERE user_id = ' . $user->data['user_id'];
|
---|
96 | $result = $db->sql_query($sql);
|
---|
97 |
|
---|
98 | while ($row = $db->sql_fetchrow($result))
|
---|
99 | {
|
---|
100 | $friend[$row['zebra_id']] = $row['friend'];
|
---|
101 | $foe[$row['zebra_id']] = $row['foe'];
|
---|
102 | }
|
---|
103 | $db->sql_freeresult($result);
|
---|
104 |
|
---|
105 | $template->assign_vars(array(
|
---|
106 | 'S_MARK_OPTIONS' => $s_mark_options,
|
---|
107 | 'S_MOVE_MARKED_OPTIONS' => $s_folder_move_options)
|
---|
108 | );
|
---|
109 |
|
---|
110 | // Okay, lets dump out the page ...
|
---|
111 | if (sizeof($folder_info['pm_list']))
|
---|
112 | {
|
---|
113 | $address_list = array();
|
---|
114 |
|
---|
115 | // Build Recipient List if in outbox/sentbox - max two additional queries
|
---|
116 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
---|
117 | {
|
---|
118 | $recipient_list = $address = array();
|
---|
119 |
|
---|
120 | foreach ($folder_info['rowset'] as $message_id => $row)
|
---|
121 | {
|
---|
122 | $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
|
---|
123 | $_save = array('u', 'g');
|
---|
124 | foreach ($_save as $save)
|
---|
125 | {
|
---|
126 | if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save]))
|
---|
127 | {
|
---|
128 | foreach (array_keys($address[$message_id][$save]) as $ug_id)
|
---|
129 | {
|
---|
130 | $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | $_types = array('u', 'g');
|
---|
137 | foreach ($_types as $ug_type)
|
---|
138 | {
|
---|
139 | if (!empty($recipient_list[$ug_type]))
|
---|
140 | {
|
---|
141 | if ($ug_type == 'u')
|
---|
142 | {
|
---|
143 | $sql = 'SELECT user_id as id, username as name, user_colour as colour
|
---|
144 | FROM ' . USERS_TABLE . '
|
---|
145 | WHERE ';
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type
|
---|
150 | FROM ' . GROUPS_TABLE . '
|
---|
151 | WHERE ';
|
---|
152 | }
|
---|
153 | $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type])));
|
---|
154 |
|
---|
155 | $result = $db->sql_query($sql);
|
---|
156 |
|
---|
157 | while ($row = $db->sql_fetchrow($result))
|
---|
158 | {
|
---|
159 | if ($ug_type == 'g')
|
---|
160 | {
|
---|
161 | $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
|
---|
162 | }
|
---|
163 |
|
---|
164 | $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
|
---|
165 | }
|
---|
166 | $db->sql_freeresult($result);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | foreach ($address as $message_id => $adr_ary)
|
---|
171 | {
|
---|
172 | foreach ($adr_ary as $type => $id_ary)
|
---|
173 | {
|
---|
174 | foreach ($id_ary as $ug_id => $_id)
|
---|
175 | {
|
---|
176 | if ($type == 'u')
|
---|
177 | {
|
---|
178 | $address_list[$message_id][] = get_username_string('full', $ug_id, $recipient_list[$type][$ug_id]['name'], $recipient_list[$type][$ug_id]['colour']);
|
---|
179 | }
|
---|
180 | else
|
---|
181 | {
|
---|
182 | $user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="font-weight: bold; color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : '';
|
---|
183 | $link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $ug_id) . '"' . $user_colour . '>';
|
---|
184 | $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : '');
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 | unset($recipient_list, $address);
|
---|
190 | }
|
---|
191 |
|
---|
192 | $data = array();
|
---|
193 |
|
---|
194 | foreach ($folder_info['pm_list'] as $message_id)
|
---|
195 | {
|
---|
196 | $row = &$folder_info['rowset'][$message_id];
|
---|
197 |
|
---|
198 | $folder_img = ($row['pm_unread']) ? 'pm_unread' : 'pm_read';
|
---|
199 | $folder_alt = ($row['pm_unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
|
---|
200 |
|
---|
201 | // Generate all URIs ...
|
---|
202 | $view_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=view&f=$folder_id&p=$message_id");
|
---|
203 | $remove_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&action=delete&p=$message_id");
|
---|
204 |
|
---|
205 | $row_indicator = '';
|
---|
206 | foreach ($color_rows as $var)
|
---|
207 | {
|
---|
208 | if (($var != 'friend' && $var != 'foe' && $row['pm_' . $var])
|
---|
209 | ||
|
---|
210 | (($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]))
|
---|
211 | {
|
---|
212 | $row_indicator = $var;
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | // Send vars to template
|
---|
218 | $template->assign_block_vars('messagerow', array(
|
---|
219 | 'PM_CLASS' => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '',
|
---|
220 |
|
---|
221 | 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
---|
222 | 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
---|
223 | 'MESSAGE_AUTHOR' => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
---|
224 | 'U_MESSAGE_AUTHOR' => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
---|
225 |
|
---|
226 | 'FOLDER_ID' => $folder_id,
|
---|
227 | 'MESSAGE_ID' => $message_id,
|
---|
228 | 'SENT_TIME' => $user->format_date($row['message_time']),
|
---|
229 | 'SUBJECT' => censor_text($row['message_subject']),
|
---|
230 | 'FOLDER' => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '',
|
---|
231 | 'U_FOLDER' => (isset($folder[$row['folder_id']])) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'folder=' . $row['folder_id']) : '',
|
---|
232 | '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="" />' : '',
|
---|
233 | 'PM_ICON_URL' => (!empty($icons[$row['icon_id']])) ? $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '',
|
---|
234 | 'FOLDER_IMG' => $user->img($folder_img, $folder_alt),
|
---|
235 | 'FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
|
---|
236 | 'PM_IMG' => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '',
|
---|
237 | 'ATTACH_ICON_IMG' => ($auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
|
---|
238 |
|
---|
239 | 'S_PM_DELETED' => ($row['pm_deleted']) ? true : false,
|
---|
240 | 'S_AUTHOR_DELETED' => ($row['author_id'] == ANONYMOUS) ? true : false,
|
---|
241 |
|
---|
242 | 'U_VIEW_PM' => ($row['pm_deleted']) ? '' : $view_message_url,
|
---|
243 | 'U_REMOVE_PM' => ($row['pm_deleted']) ? $remove_message_url : '',
|
---|
244 | 'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '')
|
---|
245 | );
|
---|
246 | }
|
---|
247 | unset($folder_info['rowset']);
|
---|
248 |
|
---|
249 | $template->assign_vars(array(
|
---|
250 | 'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false,
|
---|
251 | 'S_SHOW_COLOUR_LEGEND' => true,
|
---|
252 |
|
---|
253 | 'S_PM_ICONS' => ($config['enable_pm_icons']) ? true : false)
|
---|
254 | );
|
---|
255 | }
|
---|
256 | }
|
---|
257 | else
|
---|
258 | {
|
---|
259 | $export_type = request_var('export_option', '');
|
---|
260 | $enclosure = request_var('enclosure', '');
|
---|
261 | $delimiter = request_var('delimiter', '');
|
---|
262 |
|
---|
263 | if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === ''))
|
---|
264 | {
|
---|
265 | $template->assign_var('PROMPT', true);
|
---|
266 | }
|
---|
267 | else
|
---|
268 | {
|
---|
269 | // Build Recipient List if in outbox/sentbox
|
---|
270 | $address = array();
|
---|
271 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
---|
272 | {
|
---|
273 | foreach ($folder_info['rowset'] as $message_id => $row)
|
---|
274 | {
|
---|
275 | $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | foreach ($folder_info['pm_list'] as $message_id)
|
---|
280 | {
|
---|
281 | $row = &$folder_info['rowset'][$message_id];
|
---|
282 |
|
---|
283 | include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
---|
284 |
|
---|
285 | $sql = 'SELECT p.message_text, p.bbcode_uid
|
---|
286 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
287 | WHERE t.user_id = ' . $user->data['user_id'] . "
|
---|
288 | AND p.author_id = u.user_id
|
---|
289 | AND t.folder_id = $folder_id
|
---|
290 | AND t.msg_id = p.msg_id
|
---|
291 | AND p.msg_id = $message_id";
|
---|
292 | $result = $db->sql_query_limit($sql, 1);
|
---|
293 | $message_row = $db->sql_fetchrow($result);
|
---|
294 | $db->sql_freeresult($result);
|
---|
295 |
|
---|
296 | $_types = array('u', 'g');
|
---|
297 | foreach ($_types as $ug_type)
|
---|
298 | {
|
---|
299 | if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type]))
|
---|
300 | {
|
---|
301 | if ($ug_type == 'u')
|
---|
302 | {
|
---|
303 | $sql = 'SELECT user_id as id, username as name
|
---|
304 | FROM ' . USERS_TABLE . '
|
---|
305 | WHERE ';
|
---|
306 | }
|
---|
307 | else
|
---|
308 | {
|
---|
309 | $sql = 'SELECT group_id as id, group_name as name
|
---|
310 | FROM ' . GROUPS_TABLE . '
|
---|
311 | WHERE ';
|
---|
312 | }
|
---|
313 | $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address[$message_id][$ug_type])));
|
---|
314 |
|
---|
315 | $result = $db->sql_query($sql);
|
---|
316 |
|
---|
317 | while ($info_row = $db->sql_fetchrow($result))
|
---|
318 | {
|
---|
319 | $address[$message_id][$ug_type][$address[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
|
---|
320 | unset($address[$message_id][$ug_type][$info_row['id']]);
|
---|
321 | }
|
---|
322 | $db->sql_freeresult($result);
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | decode_message($message_row['message_text'], $message_row['bbcode_uid']);
|
---|
327 |
|
---|
328 | $data[] = array(
|
---|
329 | 'subject' => censor_text($row['message_subject']),
|
---|
330 | 'sender' => $row['username'],
|
---|
331 | 'date' => $user->format_date($row['message_time']),
|
---|
332 | 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '',
|
---|
333 | 'message' => $message_row['message_text']
|
---|
334 | );
|
---|
335 | }
|
---|
336 |
|
---|
337 | switch ($export_type)
|
---|
338 | {
|
---|
339 | case 'CSV':
|
---|
340 | case 'CSV_EXCEL':
|
---|
341 | $mimetype = 'text/csv';
|
---|
342 | $filetype = 'csv';
|
---|
343 |
|
---|
344 | if ($export_type == 'CSV_EXCEL')
|
---|
345 | {
|
---|
346 | $enclosure = '"';
|
---|
347 | $delimiter = ',';
|
---|
348 | $newline = "\r\n";
|
---|
349 | }
|
---|
350 | else
|
---|
351 | {
|
---|
352 | $newline = "\n";
|
---|
353 | }
|
---|
354 |
|
---|
355 | $string = '';
|
---|
356 | foreach ($data as $value)
|
---|
357 | {
|
---|
358 | $recipients = $value['to'];
|
---|
359 | $value['to'] = $value['bcc'] = '';
|
---|
360 |
|
---|
361 | if (is_array($recipients))
|
---|
362 | {
|
---|
363 | foreach ($recipients as $values)
|
---|
364 | {
|
---|
365 | $value['bcc'] .= (isset($values['bcc']) && is_array($values['bcc'])) ? ',' . implode(',', $values['bcc']) : '';
|
---|
366 | $value['to'] .= (isset($values['to']) && is_array($values['to'])) ? ',' . implode(',', $values['to']) : '';
|
---|
367 | }
|
---|
368 |
|
---|
369 | // Remove the commas which will appear before the first entry.
|
---|
370 | $value['to'] = substr($value['to'], 1);
|
---|
371 | $value['bcc'] = substr($value['bcc'], 1);
|
---|
372 | }
|
---|
373 |
|
---|
374 | foreach ($value as $tag => $text)
|
---|
375 | {
|
---|
376 | $cell = str_replace($enclosure, $enclosure . $enclosure, $text);
|
---|
377 |
|
---|
378 | if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false)
|
---|
379 | {
|
---|
380 | $string .= $enclosure . $text . $enclosure . $delimiter;
|
---|
381 | }
|
---|
382 | else
|
---|
383 | {
|
---|
384 | $string .= $cell . $delimiter;
|
---|
385 | }
|
---|
386 | }
|
---|
387 | $string = substr($string, 0, -1) . $newline;
|
---|
388 | }
|
---|
389 | break;
|
---|
390 |
|
---|
391 | case 'XML':
|
---|
392 | $mimetype = 'application/xml';
|
---|
393 | $filetype = 'xml';
|
---|
394 | $string = '<?xml version="1.0"?>' . "\n";
|
---|
395 | $string .= "<phpbb>\n";
|
---|
396 |
|
---|
397 | foreach ($data as $value)
|
---|
398 | {
|
---|
399 | $string .= "\t<privmsg>\n";
|
---|
400 |
|
---|
401 | if (is_array($value['to']))
|
---|
402 | {
|
---|
403 | foreach ($value['to'] as $key => $values)
|
---|
404 | {
|
---|
405 | foreach ($values as $type => $types)
|
---|
406 | {
|
---|
407 | foreach ($types as $name)
|
---|
408 | {
|
---|
409 | $string .= "\t\t<recipient type=\"$type\" status=\"$key\">$name</recipient>\n";
|
---|
410 | }
|
---|
411 | }
|
---|
412 | }
|
---|
413 | }
|
---|
414 |
|
---|
415 | unset($value['to']);
|
---|
416 |
|
---|
417 | foreach ($value as $tag => $text)
|
---|
418 | {
|
---|
419 | $string .= "\t\t<$tag>$text</$tag>\n";
|
---|
420 | }
|
---|
421 |
|
---|
422 | $string .= "\t</privmsg>\n";
|
---|
423 | }
|
---|
424 | $string .= '</phpbb>';
|
---|
425 | break;
|
---|
426 | }
|
---|
427 |
|
---|
428 | header('Pragma: no-cache');
|
---|
429 | header("Content-Type: $mimetype; name=\"data.$filetype\"");
|
---|
430 | header("Content-disposition: attachment; filename=data.$filetype");
|
---|
431 | echo $string;
|
---|
432 | exit;
|
---|
433 | }
|
---|
434 | }
|
---|
435 | }
|
---|
436 |
|
---|
437 | /**
|
---|
438 | * Get Messages from folder/user
|
---|
439 | */
|
---|
440 | function get_pm_from($folder_id, $folder, $user_id)
|
---|
441 | {
|
---|
442 | global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
|
---|
443 |
|
---|
444 | $start = request_var('start', 0);
|
---|
445 |
|
---|
446 | // Additional vars later, pm ordering is mostly different from post ordering. :/
|
---|
447 | $sort_days = request_var('st', 0);
|
---|
448 | $sort_key = request_var('sk', 't');
|
---|
449 | $sort_dir = request_var('sd', 'd');
|
---|
450 |
|
---|
451 | // PM ordering options
|
---|
452 | $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'], 365 => $user->lang['1_YEAR']);
|
---|
453 |
|
---|
454 | // No sort by Author for sentbox/outbox (already only author available)
|
---|
455 | // Also, sort by msg_id for the time - private messages are not as prone to errors as posts are.
|
---|
456 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
---|
457 | {
|
---|
458 | $sort_by_text = array('t' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
|
---|
459 | $sort_by_sql = array('t' => 'p.msg_id', 's' => 'p.message_subject');
|
---|
460 | }
|
---|
461 | else
|
---|
462 | {
|
---|
463 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
|
---|
464 | $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.msg_id', 's' => 'p.message_subject');
|
---|
465 | }
|
---|
466 |
|
---|
467 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
---|
468 | 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);
|
---|
469 |
|
---|
470 | $folder_sql = 't.folder_id = ' . (int) $folder_id;
|
---|
471 |
|
---|
472 | // Limit pms to certain time frame, obtain correct pm count
|
---|
473 | if ($sort_days)
|
---|
474 | {
|
---|
475 | $min_post_time = time() - ($sort_days * 86400);
|
---|
476 |
|
---|
477 | if (isset($_POST['sort']))
|
---|
478 | {
|
---|
479 | $start = 0;
|
---|
480 | }
|
---|
481 |
|
---|
482 | $sql = 'SELECT COUNT(t.msg_id) AS pm_count
|
---|
483 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
|
---|
484 | WHERE $folder_sql
|
---|
485 | AND t.user_id = $user_id
|
---|
486 | AND t.msg_id = p.msg_id
|
---|
487 | AND p.message_time >= $min_post_time";
|
---|
488 | $result = $db->sql_query_limit($sql, 1);
|
---|
489 | $pm_count = (int) $db->sql_fetchfield('pm_count');
|
---|
490 | $db->sql_freeresult($result);
|
---|
491 |
|
---|
492 | $sql_limit_time = "AND p.message_time >= $min_post_time";
|
---|
493 | }
|
---|
494 | else
|
---|
495 | {
|
---|
496 | $pm_count = (!empty($folder[$folder_id]['num_messages'])) ? $folder[$folder_id]['num_messages'] : 0;
|
---|
497 | $sql_limit_time = '';
|
---|
498 | }
|
---|
499 |
|
---|
500 | $template->assign_vars(array(
|
---|
501 | 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id&$u_sort_param"), $pm_count, $config['topics_per_page'], $start),
|
---|
502 | 'PAGE_NUMBER' => on_page($pm_count, $config['topics_per_page'], $start),
|
---|
503 | 'TOTAL_MESSAGES' => (($pm_count == 1) ? $user->lang['VIEW_PM_MESSAGE'] : sprintf($user->lang['VIEW_PM_MESSAGES'], $pm_count)),
|
---|
504 |
|
---|
505 | 'POST_IMG' => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'PM_LOCKED') : $user->img('button_pm_new', 'POST_PM'),
|
---|
506 |
|
---|
507 | 'L_NO_MESSAGES' => (!$auth->acl_get('u_sendpm')) ? $user->lang['POST_PM_LOCKED'] : $user->lang['NO_MESSAGES'],
|
---|
508 |
|
---|
509 | 'S_SELECT_SORT_DIR' => $s_sort_dir,
|
---|
510 | 'S_SELECT_SORT_KEY' => $s_sort_key,
|
---|
511 | 'S_SELECT_SORT_DAYS' => $s_limit_days,
|
---|
512 | 'S_TOPIC_ICONS' => ($config['enable_pm_icons']) ? true : false,
|
---|
513 |
|
---|
514 | 'U_POST_NEW_TOPIC' => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose') : '',
|
---|
515 | 'S_PM_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id" . (($start !== 0) ? "&start=$start" : '')),
|
---|
516 | ));
|
---|
517 |
|
---|
518 | // Grab all pm data
|
---|
519 | $rowset = $pm_list = array();
|
---|
520 |
|
---|
521 | // If the user is trying to reach late pages, start searching from the end
|
---|
522 | $store_reverse = false;
|
---|
523 | $sql_limit = $config['topics_per_page'];
|
---|
524 | if ($start > $pm_count / 2)
|
---|
525 | {
|
---|
526 | $store_reverse = true;
|
---|
527 |
|
---|
528 | if ($start + $config['topics_per_page'] > $pm_count)
|
---|
529 | {
|
---|
530 | $sql_limit = min($config['topics_per_page'], max(1, $pm_count - $start));
|
---|
531 | }
|
---|
532 |
|
---|
533 | // Select the sort order
|
---|
534 | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
|
---|
535 | $sql_start = max(0, $pm_count - $sql_limit - $start);
|
---|
536 | }
|
---|
537 | else
|
---|
538 | {
|
---|
539 | // Select the sort order
|
---|
540 | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
---|
541 | $sql_start = $start;
|
---|
542 | }
|
---|
543 |
|
---|
544 | $sql = 'SELECT t.*, p.root_level, p.message_time, p.message_subject, p.icon_id, p.to_address, p.message_attachment, p.bcc_address, u.username, u.username_clean, u.user_colour
|
---|
545 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
|
---|
546 | WHERE t.user_id = $user_id
|
---|
547 | AND p.author_id = u.user_id
|
---|
548 | AND $folder_sql
|
---|
549 | AND t.msg_id = p.msg_id
|
---|
550 | $sql_limit_time
|
---|
551 | ORDER BY $sql_sort_order";
|
---|
552 | $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
|
---|
553 |
|
---|
554 | while ($row = $db->sql_fetchrow($result))
|
---|
555 | {
|
---|
556 | $rowset[$row['msg_id']] = $row;
|
---|
557 | $pm_list[] = $row['msg_id'];
|
---|
558 | }
|
---|
559 | $db->sql_freeresult($result);
|
---|
560 |
|
---|
561 | $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list;
|
---|
562 |
|
---|
563 | return array(
|
---|
564 | 'pm_count' => $pm_count,
|
---|
565 | 'pm_list' => $pm_list,
|
---|
566 | 'rowset' => $rowset
|
---|
567 | );
|
---|
568 | }
|
---|
569 |
|
---|
570 | ?>
|
---|