| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | *
|
|---|
| 4 | * @package ucp
|
|---|
| 5 | * @version $Id$
|
|---|
| 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 | // Minimise edits
|
|---|
| 69 | if (!$auth->acl_get('u_pm_delete') && $key = array_search('delete_marked', $mark_options))
|
|---|
| 70 | {
|
|---|
| 71 | unset($mark_options[$key]);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | $s_mark_options = '';
|
|---|
| 75 | foreach ($mark_options as $mark_option)
|
|---|
| 76 | {
|
|---|
| 77 | $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | // We do the folder moving options here too, for template authors to use...
|
|---|
| 81 | $s_folder_move_options = '';
|
|---|
| 82 | if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX)
|
|---|
| 83 | {
|
|---|
| 84 | foreach ($folder as $f_id => $folder_ary)
|
|---|
| 85 | {
|
|---|
| 86 | if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id)
|
|---|
| 87 | {
|
|---|
| 88 | continue;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="sep"' : '') . ' value="' . $f_id . '">';
|
|---|
| 92 | $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']);
|
|---|
| 93 | $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 | $friend = $foe = array();
|
|---|
| 97 |
|
|---|
| 98 | // Get friends and foes
|
|---|
| 99 | $sql = 'SELECT *
|
|---|
| 100 | FROM ' . ZEBRA_TABLE . '
|
|---|
| 101 | WHERE user_id = ' . $user->data['user_id'];
|
|---|
| 102 | $result = $db->sql_query($sql);
|
|---|
| 103 |
|
|---|
| 104 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 105 | {
|
|---|
| 106 | $friend[$row['zebra_id']] = $row['friend'];
|
|---|
| 107 | $foe[$row['zebra_id']] = $row['foe'];
|
|---|
| 108 | }
|
|---|
| 109 | $db->sql_freeresult($result);
|
|---|
| 110 |
|
|---|
| 111 | $template->assign_vars(array(
|
|---|
| 112 | 'S_MARK_OPTIONS' => $s_mark_options,
|
|---|
| 113 | 'S_MOVE_MARKED_OPTIONS' => $s_folder_move_options)
|
|---|
| 114 | );
|
|---|
| 115 |
|
|---|
| 116 | // Okay, lets dump out the page ...
|
|---|
| 117 | if (sizeof($folder_info['pm_list']))
|
|---|
| 118 | {
|
|---|
| 119 | $address_list = array();
|
|---|
| 120 |
|
|---|
| 121 | // Build Recipient List if in outbox/sentbox - max two additional queries
|
|---|
| 122 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
|---|
| 123 | {
|
|---|
| 124 | $address_list = get_recipient_strings($folder_info['rowset']);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | foreach ($folder_info['pm_list'] as $message_id)
|
|---|
| 128 | {
|
|---|
| 129 | $row = &$folder_info['rowset'][$message_id];
|
|---|
| 130 |
|
|---|
| 131 | $folder_img = ($row['pm_unread']) ? 'pm_unread' : 'pm_read';
|
|---|
| 132 | $folder_alt = ($row['pm_unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
|
|---|
| 133 |
|
|---|
| 134 | // Generate all URIs ...
|
|---|
| 135 | $view_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=view&f=$folder_id&p=$message_id");
|
|---|
| 136 | $remove_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&action=delete&p=$message_id");
|
|---|
| 137 |
|
|---|
| 138 | $row_indicator = '';
|
|---|
| 139 | foreach ($color_rows as $var)
|
|---|
| 140 | {
|
|---|
| 141 | if (($var != 'friend' && $var != 'foe' && $row['pm_' . $var])
|
|---|
| 142 | ||
|
|---|
| 143 | (($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]))
|
|---|
| 144 | {
|
|---|
| 145 | $row_indicator = $var;
|
|---|
| 146 | break;
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | // Send vars to template
|
|---|
| 151 | $template->assign_block_vars('messagerow', array(
|
|---|
| 152 | 'PM_CLASS' => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '',
|
|---|
| 153 |
|
|---|
| 154 | 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
|---|
| 155 | 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
|---|
| 156 | 'MESSAGE_AUTHOR' => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
|---|
| 157 | 'U_MESSAGE_AUTHOR' => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour'], $row['username']),
|
|---|
| 158 |
|
|---|
| 159 | 'FOLDER_ID' => $folder_id,
|
|---|
| 160 | 'MESSAGE_ID' => $message_id,
|
|---|
| 161 | 'SENT_TIME' => $user->format_date($row['message_time']),
|
|---|
| 162 | 'SUBJECT' => censor_text($row['message_subject']),
|
|---|
| 163 | 'FOLDER' => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '',
|
|---|
| 164 | 'U_FOLDER' => (isset($folder[$row['folder_id']])) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'folder=' . $row['folder_id']) : '',
|
|---|
| 165 | '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="" />' : '',
|
|---|
| 166 | 'PM_ICON_URL' => (!empty($icons[$row['icon_id']])) ? $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '',
|
|---|
| 167 | 'FOLDER_IMG' => $user->img($folder_img, $folder_alt),
|
|---|
| 168 | 'FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
|
|---|
| 169 | 'PM_IMG' => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '',
|
|---|
| 170 | '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']) : '',
|
|---|
| 171 |
|
|---|
| 172 | 'S_PM_DELETED' => ($row['pm_deleted']) ? true : false,
|
|---|
| 173 | 'S_AUTHOR_DELETED' => ($row['author_id'] == ANONYMOUS) ? true : false,
|
|---|
| 174 |
|
|---|
| 175 | 'U_VIEW_PM' => ($row['pm_deleted']) ? '' : $view_message_url,
|
|---|
| 176 | 'U_REMOVE_PM' => ($row['pm_deleted']) ? $remove_message_url : '',
|
|---|
| 177 | 'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '')
|
|---|
| 178 | );
|
|---|
| 179 | }
|
|---|
| 180 | unset($folder_info['rowset']);
|
|---|
| 181 |
|
|---|
| 182 | $template->assign_vars(array(
|
|---|
| 183 | 'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false,
|
|---|
| 184 | 'S_SHOW_COLOUR_LEGEND' => true,
|
|---|
| 185 |
|
|---|
| 186 | 'S_PM_ICONS' => ($config['enable_pm_icons']) ? true : false)
|
|---|
| 187 | );
|
|---|
| 188 | }
|
|---|
| 189 | }
|
|---|
| 190 | else
|
|---|
| 191 | {
|
|---|
| 192 | $export_type = request_var('export_option', '');
|
|---|
| 193 | $enclosure = request_var('enclosure', '');
|
|---|
| 194 | $delimiter = request_var('delimiter', '');
|
|---|
| 195 |
|
|---|
| 196 | if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === ''))
|
|---|
| 197 | {
|
|---|
| 198 | $template->assign_var('PROMPT', true);
|
|---|
| 199 | }
|
|---|
| 200 | else
|
|---|
| 201 | {
|
|---|
| 202 | // Build Recipient List if in outbox/sentbox
|
|---|
| 203 |
|
|---|
| 204 | $address_temp = $address = $data = array();
|
|---|
| 205 |
|
|---|
| 206 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
|---|
| 207 | {
|
|---|
| 208 | foreach ($folder_info['rowset'] as $message_id => $row)
|
|---|
| 209 | {
|
|---|
| 210 | $address_temp[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
|
|---|
| 211 | $address[$message_id] = array();
|
|---|
| 212 | }
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | foreach ($folder_info['pm_list'] as $message_id)
|
|---|
| 216 | {
|
|---|
| 217 | $row = &$folder_info['rowset'][$message_id];
|
|---|
| 218 |
|
|---|
| 219 | include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
|---|
| 220 |
|
|---|
| 221 | $sql = 'SELECT p.message_text, p.bbcode_uid
|
|---|
| 222 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
|
|---|
| 223 | WHERE t.user_id = ' . $user->data['user_id'] . "
|
|---|
| 224 | AND p.author_id = u.user_id
|
|---|
| 225 | AND t.folder_id = $folder_id
|
|---|
| 226 | AND t.msg_id = p.msg_id
|
|---|
| 227 | AND p.msg_id = $message_id";
|
|---|
| 228 | $result = $db->sql_query_limit($sql, 1);
|
|---|
| 229 | $message_row = $db->sql_fetchrow($result);
|
|---|
| 230 | $db->sql_freeresult($result);
|
|---|
| 231 |
|
|---|
| 232 | $_types = array('u', 'g');
|
|---|
| 233 | foreach ($_types as $ug_type)
|
|---|
| 234 | {
|
|---|
| 235 | if (isset($address_temp[$message_id][$ug_type]) && sizeof($address_temp[$message_id][$ug_type]))
|
|---|
| 236 | {
|
|---|
| 237 | if (!isset($address[$message_id][$ug_type]))
|
|---|
| 238 | {
|
|---|
| 239 | $address[$message_id][$ug_type] = array();
|
|---|
| 240 | }
|
|---|
| 241 | if ($ug_type == 'u')
|
|---|
| 242 | {
|
|---|
| 243 | $sql = 'SELECT user_id as id, username as name
|
|---|
| 244 | FROM ' . USERS_TABLE . '
|
|---|
| 245 | WHERE ';
|
|---|
| 246 | }
|
|---|
| 247 | else
|
|---|
| 248 | {
|
|---|
| 249 | $sql = 'SELECT group_id as id, group_name as name
|
|---|
| 250 | FROM ' . GROUPS_TABLE . '
|
|---|
| 251 | WHERE ';
|
|---|
| 252 | }
|
|---|
| 253 | $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address_temp[$message_id][$ug_type])));
|
|---|
| 254 |
|
|---|
| 255 | $result = $db->sql_query($sql);
|
|---|
| 256 |
|
|---|
| 257 | while ($info_row = $db->sql_fetchrow($result))
|
|---|
| 258 | {
|
|---|
| 259 | $address[$message_id][$ug_type][$address_temp[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
|
|---|
| 260 | unset($address_temp[$message_id][$ug_type][$info_row['id']]);
|
|---|
| 261 | }
|
|---|
| 262 | $db->sql_freeresult($result);
|
|---|
| 263 | }
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | // There is the chance that all recipients of the message got deleted. To avoid creating
|
|---|
| 267 | // exports without recipients, we add a bogus "undisclosed recipient".
|
|---|
| 268 | if (!(isset($address[$message_id]['g']) && sizeof($address[$message_id]['g'])) &&
|
|---|
| 269 | !(isset($address[$message_id]['u']) && sizeof($address[$message_id]['u'])))
|
|---|
| 270 | {
|
|---|
| 271 | $address[$message_id]['u'] = array();
|
|---|
| 272 | $address[$message_id]['u']['to'] = array();
|
|---|
| 273 | $address[$message_id]['u']['to'][] = $user->lang['UNDISCLOSED_RECIPIENT'];
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | decode_message($message_row['message_text'], $message_row['bbcode_uid']);
|
|---|
| 277 |
|
|---|
| 278 | $data[] = array(
|
|---|
| 279 | 'subject' => censor_text($row['message_subject']),
|
|---|
| 280 | 'sender' => $row['username'],
|
|---|
| 281 | // ISO 8601 date. For PHP4 we are able to hardcode the timezone because $user->format_date() does not set it.
|
|---|
| 282 | 'date' => $user->format_date($row['message_time'], (PHP_VERSION >= 5) ? 'c' : "Y-m-d\TH:i:s+00:00", true),
|
|---|
| 283 | 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '',
|
|---|
| 284 | 'message' => $message_row['message_text']
|
|---|
| 285 | );
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | switch ($export_type)
|
|---|
| 289 | {
|
|---|
| 290 | case 'CSV':
|
|---|
| 291 | case 'CSV_EXCEL':
|
|---|
| 292 | $mimetype = 'text/csv';
|
|---|
| 293 | $filetype = 'csv';
|
|---|
| 294 |
|
|---|
| 295 | if ($export_type == 'CSV_EXCEL')
|
|---|
| 296 | {
|
|---|
| 297 | $enclosure = '"';
|
|---|
| 298 | $delimiter = ',';
|
|---|
| 299 | $newline = "\r\n";
|
|---|
| 300 | }
|
|---|
| 301 | else
|
|---|
| 302 | {
|
|---|
| 303 | $newline = "\n";
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | $string = '';
|
|---|
| 307 | foreach ($data as $value)
|
|---|
| 308 | {
|
|---|
| 309 | $recipients = $value['to'];
|
|---|
| 310 | $value['to'] = $value['bcc'] = '';
|
|---|
| 311 |
|
|---|
| 312 | if (is_array($recipients))
|
|---|
| 313 | {
|
|---|
| 314 | foreach ($recipients as $values)
|
|---|
| 315 | {
|
|---|
| 316 | $value['bcc'] .= (isset($values['bcc']) && is_array($values['bcc'])) ? ',' . implode(',', $values['bcc']) : '';
|
|---|
| 317 | $value['to'] .= (isset($values['to']) && is_array($values['to'])) ? ',' . implode(',', $values['to']) : '';
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | // Remove the commas which will appear before the first entry.
|
|---|
| 321 | $value['to'] = substr($value['to'], 1);
|
|---|
| 322 | $value['bcc'] = substr($value['bcc'], 1);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | foreach ($value as $tag => $text)
|
|---|
| 326 | {
|
|---|
| 327 | $cell = str_replace($enclosure, $enclosure . $enclosure, $text);
|
|---|
| 328 |
|
|---|
| 329 | if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false)
|
|---|
| 330 | {
|
|---|
| 331 | $string .= $enclosure . $text . $enclosure . $delimiter;
|
|---|
| 332 | }
|
|---|
| 333 | else
|
|---|
| 334 | {
|
|---|
| 335 | $string .= $cell . $delimiter;
|
|---|
| 336 | }
|
|---|
| 337 | }
|
|---|
| 338 | $string = substr($string, 0, -1) . $newline;
|
|---|
| 339 | }
|
|---|
| 340 | break;
|
|---|
| 341 |
|
|---|
| 342 | case 'XML':
|
|---|
| 343 | $mimetype = 'application/xml';
|
|---|
| 344 | $filetype = 'xml';
|
|---|
| 345 | $string = '<?xml version="1.0"?>' . "\n";
|
|---|
| 346 | $string .= "<phpbb>\n";
|
|---|
| 347 |
|
|---|
| 348 | foreach ($data as $value)
|
|---|
| 349 | {
|
|---|
| 350 | $string .= "\t<privmsg>\n";
|
|---|
| 351 |
|
|---|
| 352 | if (is_array($value['to']))
|
|---|
| 353 | {
|
|---|
| 354 | foreach ($value['to'] as $key => $values)
|
|---|
| 355 | {
|
|---|
| 356 | foreach ($values as $type => $types)
|
|---|
| 357 | {
|
|---|
| 358 | foreach ($types as $name)
|
|---|
| 359 | {
|
|---|
| 360 | $string .= "\t\t<recipient type=\"$type\" status=\"$key\">$name</recipient>\n";
|
|---|
| 361 | }
|
|---|
| 362 | }
|
|---|
| 363 | }
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | unset($value['to']);
|
|---|
| 367 |
|
|---|
| 368 | foreach ($value as $tag => $text)
|
|---|
| 369 | {
|
|---|
| 370 | $string .= "\t\t<$tag>$text</$tag>\n";
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | $string .= "\t</privmsg>\n";
|
|---|
| 374 | }
|
|---|
| 375 | $string .= '</phpbb>';
|
|---|
| 376 | break;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | header('Pragma: no-cache');
|
|---|
| 380 | header("Content-Type: $mimetype; name=\"data.$filetype\"");
|
|---|
| 381 | header("Content-disposition: attachment; filename=data.$filetype");
|
|---|
| 382 | echo $string;
|
|---|
| 383 | exit;
|
|---|
| 384 | }
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | /**
|
|---|
| 389 | * Get Messages from folder/user
|
|---|
| 390 | */
|
|---|
| 391 | function get_pm_from($folder_id, $folder, $user_id)
|
|---|
| 392 | {
|
|---|
| 393 | global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
|
|---|
| 394 |
|
|---|
| 395 | $start = request_var('start', 0);
|
|---|
| 396 |
|
|---|
| 397 | // Additional vars later, pm ordering is mostly different from post ordering. :/
|
|---|
| 398 | $sort_days = request_var('st', 0);
|
|---|
| 399 | $sort_key = request_var('sk', 't');
|
|---|
| 400 | $sort_dir = request_var('sd', 'd');
|
|---|
| 401 |
|
|---|
| 402 | // PM ordering options
|
|---|
| 403 | $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']);
|
|---|
| 404 |
|
|---|
| 405 | // No sort by Author for sentbox/outbox (already only author available)
|
|---|
| 406 | // Also, sort by msg_id for the time - private messages are not as prone to errors as posts are.
|
|---|
| 407 | if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX)
|
|---|
| 408 | {
|
|---|
| 409 | $sort_by_text = array('t' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
|
|---|
| 410 | $sort_by_sql = array('t' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
|
|---|
| 411 | }
|
|---|
| 412 | else
|
|---|
| 413 | {
|
|---|
| 414 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
|
|---|
| 415 | $sort_by_sql = array('a' => array('u.username_clean', 'p.message_time'), 't' => 'p.message_time', 's' => array('p.message_subject', 'p.message_time'));
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
|---|
| 419 | 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);
|
|---|
| 420 |
|
|---|
| 421 | $folder_sql = 't.folder_id = ' . (int) $folder_id;
|
|---|
| 422 |
|
|---|
| 423 | // Limit pms to certain time frame, obtain correct pm count
|
|---|
| 424 | if ($sort_days)
|
|---|
| 425 | {
|
|---|
| 426 | $min_post_time = time() - ($sort_days * 86400);
|
|---|
| 427 |
|
|---|
| 428 | if (isset($_POST['sort']))
|
|---|
| 429 | {
|
|---|
| 430 | $start = 0;
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | $sql = 'SELECT COUNT(t.msg_id) AS pm_count
|
|---|
| 434 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
|
|---|
| 435 | WHERE $folder_sql
|
|---|
| 436 | AND t.user_id = $user_id
|
|---|
| 437 | AND t.msg_id = p.msg_id
|
|---|
| 438 | AND p.message_time >= $min_post_time";
|
|---|
| 439 | $result = $db->sql_query_limit($sql, 1);
|
|---|
| 440 | $pm_count = (int) $db->sql_fetchfield('pm_count');
|
|---|
| 441 | $db->sql_freeresult($result);
|
|---|
| 442 |
|
|---|
| 443 | $sql_limit_time = "AND p.message_time >= $min_post_time";
|
|---|
| 444 | }
|
|---|
| 445 | else
|
|---|
| 446 | {
|
|---|
| 447 | $pm_count = (!empty($folder[$folder_id]['num_messages'])) ? $folder[$folder_id]['num_messages'] : 0;
|
|---|
| 448 | $sql_limit_time = '';
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | $template->assign_vars(array(
|
|---|
| 452 | '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),
|
|---|
| 453 | 'PAGE_NUMBER' => on_page($pm_count, $config['topics_per_page'], $start),
|
|---|
| 454 | 'TOTAL_MESSAGES' => (($pm_count == 1) ? $user->lang['VIEW_PM_MESSAGE'] : sprintf($user->lang['VIEW_PM_MESSAGES'], $pm_count)),
|
|---|
| 455 |
|
|---|
| 456 | 'POST_IMG' => (!$auth->acl_get('u_sendpm')) ? $user->img('button_topic_locked', 'POST_PM_LOCKED') : $user->img('button_pm_new', 'POST_NEW_PM'),
|
|---|
| 457 |
|
|---|
| 458 | 'S_NO_AUTH_SEND_MESSAGE' => !$auth->acl_get('u_sendpm'),
|
|---|
| 459 |
|
|---|
| 460 | 'S_SELECT_SORT_DIR' => $s_sort_dir,
|
|---|
| 461 | 'S_SELECT_SORT_KEY' => $s_sort_key,
|
|---|
| 462 | 'S_SELECT_SORT_DAYS' => $s_limit_days,
|
|---|
| 463 | 'S_TOPIC_ICONS' => ($config['enable_pm_icons']) ? true : false,
|
|---|
| 464 |
|
|---|
| 465 | 'U_POST_NEW_TOPIC' => ($auth->acl_get('u_sendpm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose') : '',
|
|---|
| 466 | 'S_PM_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id" . (($start !== 0) ? "&start=$start" : '')),
|
|---|
| 467 | ));
|
|---|
| 468 |
|
|---|
| 469 | // Grab all pm data
|
|---|
| 470 | $rowset = $pm_list = array();
|
|---|
| 471 |
|
|---|
| 472 | // If the user is trying to reach late pages, start searching from the end
|
|---|
| 473 | $store_reverse = false;
|
|---|
| 474 | $sql_limit = $config['topics_per_page'];
|
|---|
| 475 | if ($start > $pm_count / 2)
|
|---|
| 476 | {
|
|---|
| 477 | $store_reverse = true;
|
|---|
| 478 |
|
|---|
| 479 | if ($start + $config['topics_per_page'] > $pm_count)
|
|---|
| 480 | {
|
|---|
| 481 | $sql_limit = min($config['topics_per_page'], max(1, $pm_count - $start));
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | // Select the sort order
|
|---|
| 485 | $direction = ($sort_dir == 'd') ? 'ASC' : 'DESC';
|
|---|
| 486 | $sql_start = max(0, $pm_count - $sql_limit - $start);
|
|---|
| 487 | }
|
|---|
| 488 | else
|
|---|
| 489 | {
|
|---|
| 490 | // Select the sort order
|
|---|
| 491 | $direction = ($sort_dir == 'd') ? 'DESC' : 'ASC';
|
|---|
| 492 | $sql_start = $start;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | // Sql sort order
|
|---|
| 496 | if (is_array($sort_by_sql[$sort_key]))
|
|---|
| 497 | {
|
|---|
| 498 | $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction;
|
|---|
| 499 | }
|
|---|
| 500 | else
|
|---|
| 501 | {
|
|---|
| 502 | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | $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
|
|---|
| 506 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u
|
|---|
| 507 | WHERE t.user_id = $user_id
|
|---|
| 508 | AND p.author_id = u.user_id
|
|---|
| 509 | AND $folder_sql
|
|---|
| 510 | AND t.msg_id = p.msg_id
|
|---|
| 511 | $sql_limit_time
|
|---|
| 512 | ORDER BY $sql_sort_order";
|
|---|
| 513 | $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
|
|---|
| 514 |
|
|---|
| 515 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 516 | {
|
|---|
| 517 | $rowset[$row['msg_id']] = $row;
|
|---|
| 518 | $pm_list[] = $row['msg_id'];
|
|---|
| 519 | }
|
|---|
| 520 | $db->sql_freeresult($result);
|
|---|
| 521 |
|
|---|
| 522 | $pm_list = ($store_reverse) ? array_reverse($pm_list) : $pm_list;
|
|---|
| 523 |
|
|---|
| 524 | return array(
|
|---|
| 525 | 'pm_count' => $pm_count,
|
|---|
| 526 | 'pm_list' => $pm_list,
|
|---|
| 527 | 'rowset' => $rowset
|
|---|
| 528 | );
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | ?>
|
|---|