root / tags / release_2_0_2 / phpBB / privmsg.php
History | View | Annotate | Download (67.2 kB)
| 1 | <?php
|
|---|---|
| 2 | /***************************************************************************
|
| 3 | * privmsgs.php |
| 4 | * ------------------- |
| 5 | * begin : Saturday, Jun 9, 2001 |
| 6 | * copyright : (C) 2001 The phpBB Group |
| 7 | * email : support@phpbb.com |
| 8 | * |
| 9 | * $Id: privmsg.php 2845 2002-08-08 18:06:53Z $ |
| 10 | * |
| 11 | * |
| 12 | ***************************************************************************/ |
| 13 | |
| 14 | /***************************************************************************
|
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | define('IN_PHPBB', true); |
| 24 | $phpbb_root_path = './'; |
| 25 | include($phpbb_root_path . 'extension.inc'); |
| 26 | include($phpbb_root_path . 'common.'.$phpEx); |
| 27 | include($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 28 | include($phpbb_root_path . 'includes/functions_post.'.$phpEx); |
| 29 | |
| 30 | //
|
| 31 | // Is PM disabled?
|
| 32 | //
|
| 33 | if ( !empty($board_config['privmsg_disable']) ) |
| 34 | {
|
| 35 | message_die(GENERAL_MESSAGE, 'PM_disabled'); |
| 36 | } |
| 37 | |
| 38 | $html_entities_match = array('#&#', '#<#', '#>#'); |
| 39 | $html_entities_replace = array('&', '<', '>'); |
| 40 | |
| 41 | //
|
| 42 | // Parameters
|
| 43 | //
|
| 44 | $submit = ( isset($HTTP_POST_VARS['post']) ) ? TRUE : 0; |
| 45 | $submit_search = ( isset($HTTP_POST_VARS['usersubmit']) ) ? TRUE : 0; |
| 46 | $submit_msgdays = ( isset($HTTP_POST_VARS['submit_msgdays']) ) ? TRUE : 0; |
| 47 | $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : 0; |
| 48 | $preview = ( isset($HTTP_POST_VARS['preview']) ) ? TRUE : 0; |
| 49 | $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : 0; |
| 50 | $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : 0; |
| 51 | $delete_all = ( isset($HTTP_POST_VARS['deleteall']) ) ? TRUE : 0; |
| 52 | $save = ( isset($HTTP_POST_VARS['save']) ) ? TRUE : 0; |
| 53 | |
| 54 | $refresh = $preview || $submit_search; |
| 55 | |
| 56 | $mark_list = ( !empty($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : 0; |
| 57 | |
| 58 | if ( isset($HTTP_POST_VARS['folder']) || isset($HTTP_GET_VARS['folder']) ) |
| 59 | {
|
| 60 | $folder = ( isset($HTTP_POST_VARS['folder']) ) ? $HTTP_POST_VARS['folder'] : $HTTP_GET_VARS['folder']; |
| 61 | |
| 62 | if ( $folder != 'inbox' && $folder != 'outbox' && $folder != 'sentbox' && $folder != 'savebox' ) |
| 63 | {
|
| 64 | $folder = 'inbox'; |
| 65 | } |
| 66 | } |
| 67 | else
|
| 68 | {
|
| 69 | $folder = 'inbox'; |
| 70 | } |
| 71 | |
| 72 | //
|
| 73 | // Start session management
|
| 74 | //
|
| 75 | $userdata = session_pagestart($user_ip, PAGE_PRIVMSGS); |
| 76 | init_userprefs($userdata);
|
| 77 | //
|
| 78 | // End session management
|
| 79 | //
|
| 80 | |
| 81 | //
|
| 82 | // Cancel
|
| 83 | //
|
| 84 | if ( $cancel ) |
| 85 | {
|
| 86 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 87 | header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true)); |
| 88 | exit;
|
| 89 | } |
| 90 | |
| 91 | //
|
| 92 | // Var definitions
|
| 93 | //
|
| 94 | if ( !empty($HTTP_POST_VARS['mode']) || !empty($HTTP_GET_VARS['mode']) ) |
| 95 | {
|
| 96 | $mode = ( !empty($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode']; |
| 97 | } |
| 98 | else
|
| 99 | {
|
| 100 | $mode = ''; |
| 101 | } |
| 102 | |
| 103 | $start = ( !empty($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0; |
| 104 | |
| 105 | if ( isset($HTTP_POST_VARS[POST_POST_URL]) || isset($HTTP_GET_VARS[POST_POST_URL]) ) |
| 106 | {
|
| 107 | $privmsg_id = ( isset($HTTP_POST_VARS[POST_POST_URL]) ) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]); |
| 108 | } |
| 109 | else
|
| 110 | {
|
| 111 | $privmsg_id = ''; |
| 112 | } |
| 113 | |
| 114 | $error = FALSE; |
| 115 | |
| 116 | //
|
| 117 | // Define the box image links
|
| 118 | //
|
| 119 | $inbox_img = ( $folder != 'inbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '"><img src="' . $images['pm_inbox'] . '" border="0" alt="' . $lang['Inbox'] . '" /></a>' : '<img src="' . $images['pm_inbox'] . '" border="0" alt="' . $lang['Inbox'] . '" />'; |
| 120 | $inbox_url = ( $folder != 'inbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '">' . $lang['Inbox'] . '</a>' : $lang['Inbox']; |
| 121 | |
| 122 | $outbox_img = ( $folder != 'outbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=outbox") . '"><img src="' . $images['pm_outbox'] . '" border="0" alt="' . $lang['Outbox'] . '" /></a>' : '<img src="' . $images['pm_outbox'] . '" border="0" alt="' . $lang['Outbox'] . '" />'; |
| 123 | $outbox_url = ( $folder != 'outbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=outbox") . '">' . $lang['Outbox'] . '</a>' : $lang['Outbox']; |
| 124 | |
| 125 | $sentbox_img = ( $folder != 'sentbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=sentbox") . '"><img src="' . $images['pm_sentbox'] . '" border="0" alt="' . $lang['Sentbox'] . '" /></a>' : '<img src="' . $images['pm_sentbox'] . '" border="0" alt="' . $lang['Sentbox'] . '" />'; |
| 126 | $sentbox_url = ( $folder != 'sentbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=sentbox") . '">' . $lang['Sentbox'] . '</a>' : $lang['Sentbox']; |
| 127 | |
| 128 | $savebox_img = ( $folder != 'savebox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=savebox") . '"><img src="' . $images['pm_savebox'] . '" border="0" alt="' . $lang['Savebox'] . '" /></a>' : '<img src="' . $images['pm_savebox'] . '" border="0" alt="' . $lang['Savebox'] . '" />'; |
| 129 | $savebox_url = ( $folder != 'savebox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=savebox") . '">' . $lang['Savebox'] . '</a>' : $lang['Savebox']; |
| 130 | |
| 131 | // ----------
|
| 132 | // Start main
|
| 133 | //
|
| 134 | if ( $mode == 'newpm' ) |
| 135 | {
|
| 136 | $gen_simple_header = TRUE; |
| 137 | |
| 138 | $page_title = $lang['Private_Messaging']; |
| 139 | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 140 | |
| 141 | $template->set_filenames(array( |
| 142 | 'body' => 'privmsgs_popup.tpl') |
| 143 | ); |
| 144 | |
| 145 | if ( $userdata['session_logged_in'] ) |
| 146 | {
|
| 147 | if ( $userdata['user_new_privmsg'] ) |
| 148 | {
|
| 149 | $l_new_message = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['You_new_pm'] : $lang['You_new_pms']; |
| 150 | } |
| 151 | else
|
| 152 | {
|
| 153 | $l_new_message = $lang['You_no_new_pm']; |
| 154 | } |
| 155 | |
| 156 | $l_new_message .= '<br /><br />' . sprintf($lang['Click_view_privmsg'], '<a href="' . append_sid("privmsg.".$phpEx."?folder=inbox") . '" onClick="jump_to_inbox();return false;" target="_new">', '</a>'); |
| 157 | } |
| 158 | else
|
| 159 | {
|
| 160 | $l_new_message = $lang['Login_check_pm']; |
| 161 | } |
| 162 | |
| 163 | $template->assign_vars(array( |
| 164 | 'L_CLOSE_WINDOW' => $lang['Close_window'], |
| 165 | 'L_MESSAGE' => $l_new_message) |
| 166 | ); |
| 167 | |
| 168 | $template->pparse('body'); |
| 169 | |
| 170 | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 171 | |
| 172 | } |
| 173 | else if ( $mode == 'read' ) |
| 174 | {
|
| 175 | if ( !empty($HTTP_GET_VARS[POST_POST_URL]) ) |
| 176 | {
|
| 177 | $privmsgs_id = intval($HTTP_GET_VARS[POST_POST_URL]); |
| 178 | } |
| 179 | else
|
| 180 | {
|
| 181 | message_die(GENERAL_ERROR, $lang['No_post_id']); |
| 182 | } |
| 183 | |
| 184 | if ( !$userdata['session_logged_in'] ) |
| 185 | {
|
| 186 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 187 | header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode&" . POST_POST_URL . "=$privmsgs_id", true)); |
| 188 | exit;
|
| 189 | } |
| 190 | |
| 191 | //
|
| 192 | // SQL to pull appropriate message, prevents nosey people
|
| 193 | // reading other peoples messages ... hopefully!
|
| 194 | //
|
| 195 | switch( $folder ) |
| 196 | {
|
| 197 | case 'inbox': |
| 198 | $l_box_name = $lang['Inbox']; |
| 199 | $pm_sql_user = "AND pm.privmsgs_to_userid = " . $userdata['user_id'] . " |
| 200 | AND ( pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 201 | OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 202 | OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 203 | break;
|
| 204 | case 'outbox': |
| 205 | $l_box_name = $lang['Outbox']; |
| 206 | $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 207 | AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 208 | OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) "; |
| 209 | break;
|
| 210 | case 'sentbox': |
| 211 | $l_box_name = $lang['Sentbox']; |
| 212 | $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 213 | AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 214 | break;
|
| 215 | case 'savebox': |
| 216 | $l_box_name = $lang['Savebox']; |
| 217 | $pm_sql_user .= "AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . " |
| 218 | AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) |
| 219 | OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 220 | AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) |
| 221 | )";
|
| 222 | break;
|
| 223 | default:
|
| 224 | message_die(GENERAL_ERROR, $lang['No_such_folder']); |
| 225 | break;
|
| 226 | } |
| 227 | |
| 228 | //
|
| 229 | // Major query obtains the message ...
|
| 230 | //
|
| 231 | $sql = "SELECT u.username AS username_1, u.user_id AS user_id_1, u2.username AS username_2, u2.user_id AS user_id_2, u.user_sig_bbcode_uid, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_avatar, pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text |
| 232 | FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2 |
| 233 | WHERE pm.privmsgs_id = $privmsgs_id |
| 234 | AND pmt.privmsgs_text_id = pm.privmsgs_id |
| 235 | $pm_sql_user |
| 236 | AND u.user_id = pm.privmsgs_from_userid |
| 237 | AND u2.user_id = pm.privmsgs_to_userid";
|
| 238 | if ( !($result = $db->sql_query($sql)) ) |
| 239 | {
|
| 240 | message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql); |
| 241 | } |
| 242 | |
| 243 | //
|
| 244 | // Did the query return any data?
|
| 245 | //
|
| 246 | if ( !($privmsg = $db->sql_fetchrow($result)) ) |
| 247 | {
|
| 248 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 249 | header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true)); |
| 250 | exit;
|
| 251 | } |
| 252 | |
| 253 | $privmsg_id = $privmsg['privmsgs_id']; |
| 254 | |
| 255 | //
|
| 256 | // Is this a new message in the inbox? If it is then save
|
| 257 | // a copy in the posters sent box
|
| 258 | //
|
| 259 | if ( ( $privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL ) && $folder == 'inbox' ) |
| 260 | {
|
| 261 | $sql = "UPDATE " . PRIVMSGS_TABLE . " |
| 262 | SET privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 263 | WHERE privmsgs_id = " . $privmsg['privmsgs_id']; |
| 264 | if ( !$db->sql_query($sql) ) |
| 265 | {
|
| 266 | message_die(GENERAL_ERROR, 'Could not update private message read status', '', __LINE__, __FILE__, $sql); |
| 267 | } |
| 268 | |
| 269 | $sql = "UPDATE " . USERS_TABLE . " |
| 270 | SET user_unread_privmsg = user_unread_privmsg - 1 |
| 271 | WHERE user_id = " . $userdata['user_id']; |
| 272 | if ( !$db->sql_query($sql) ) |
| 273 | {
|
| 274 | message_die(GENERAL_ERROR, 'Could not update private message read status for user', '', __LINE__, __FILE__, $sql); |
| 275 | } |
| 276 | |
| 277 | //
|
| 278 | // Check to see if the poster has a 'full' sent box
|
| 279 | //
|
| 280 | $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time |
| 281 | FROM " . PRIVMSGS_TABLE . " |
| 282 | WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . " |
| 283 | AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid']; |
| 284 | if ( !($result = $db->sql_query($sql)) ) |
| 285 | {
|
| 286 | message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql); |
| 287 | } |
| 288 | |
| 289 | $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : ''; |
| 290 | |
| 291 | if ( $sent_info = $db->sql_fetchrow($result) ) |
| 292 | {
|
| 293 | if ( $sent_info['sent_items'] >= $board_config['max_sentbox_privmsgs'] ) |
| 294 | {
|
| 295 | $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . " |
| 296 | WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . " |
| 297 | AND privmsgs_date = " . $sent_info['oldest_post_time'] . " |
| 298 | AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid']; |
| 299 | if ( !$db->sql_query($sql) ) |
| 300 | {
|
| 301 | message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | //
|
| 307 | // This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
|
| 308 | // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
|
| 309 | // set limits on numbers of storable posts for users ... hopefully!
|
| 310 | //
|
| 311 | $sql = "INSERT $sql_priority INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig) |
| 312 | VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_subject'])) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "', " . $privmsg['privmsgs_enable_html'] . ", " . $privmsg['privmsgs_enable_bbcode'] . ", " . $privmsg['privmsgs_enable_smilies'] . ", " . $privmsg['privmsgs_attach_sig'] . ")"; |
| 313 | if ( !$db->sql_query($sql) ) |
| 314 | {
|
| 315 | message_die(GENERAL_ERROR, 'Could not insert private message sent info', '', __LINE__, __FILE__, $sql); |
| 316 | } |
| 317 | |
| 318 | $privmsg_sent_id = $db->sql_nextid(); |
| 319 | |
| 320 | $sql = "INSERT $sql_priority INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) |
| 321 | VALUES ($privmsg_sent_id, '" . $privmsg['privmsgs_bbcode_uid'] . "', '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_text'])) . "')"; |
| 322 | if ( !$db->sql_query($sql) ) |
| 323 | {
|
| 324 | message_die(GENERAL_ERROR, 'Could not insert private message sent text', '', __LINE__, __FILE__, $sql); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | //
|
| 329 | // Pick a folder, any folder, so long as it's one below ...
|
| 330 | //
|
| 331 | $post_urls = array( |
| 332 | 'post' => append_sid("privmsg.$phpEx?mode=post"), |
| 333 | 'reply' => append_sid("privmsg.$phpEx?mode=reply&" . POST_POST_URL . "=$privmsg_id"), |
| 334 | 'quote' => append_sid("privmsg.$phpEx?mode=quote&" . POST_POST_URL . "=$privmsg_id"), |
| 335 | 'edit' => append_sid("privmsg.$phpEx?mode=edit&" . POST_POST_URL . "=$privmsg_id") |
| 336 | ); |
| 337 | $post_icons = array( |
| 338 | 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0"></a>', |
| 339 | 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['Post_new_pm'] . '</a>', |
| 340 | 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['Post_reply_pm'] . '" border="0"></a>', |
| 341 | 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['Post_reply_pm'] . '</a>', |
| 342 | 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['Post_quote_pm'] . '" border="0"></a>', |
| 343 | 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['Post_quote_pm'] . '</a>', |
| 344 | 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['Edit_pm'] . '" border="0"></a>', |
| 345 | 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['Edit_pm'] . '</a>' |
| 346 | ); |
| 347 | |
| 348 | if ( $folder == 'inbox' ) |
| 349 | {
|
| 350 | $post_img = $post_icons['post_img']; |
| 351 | $reply_img = $post_icons['reply_img']; |
| 352 | $quote_img = $post_icons['quote_img']; |
| 353 | $edit_img = ''; |
| 354 | $post = $post_icons['post']; |
| 355 | $reply = $post_icons['reply']; |
| 356 | $quote = $post_icons['quote']; |
| 357 | $edit = ''; |
| 358 | $l_box_name = $lang['Inbox']; |
| 359 | } |
| 360 | else if ( $folder == 'outbox' ) |
| 361 | {
|
| 362 | $post_img = $post_icons['post_img']; |
| 363 | $reply_img = ''; |
| 364 | $quote_img = ''; |
| 365 | $edit_img = $post_icons['edit_img']; |
| 366 | $post = $post_icons['post']; |
| 367 | $reply = ''; |
| 368 | $quote = ''; |
| 369 | $edit = $post_icons['edit']; |
| 370 | $l_box_name = $lang['Outbox']; |
| 371 | } |
| 372 | else if ( $folder == 'savebox' ) |
| 373 | {
|
| 374 | if ( $privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL ) |
| 375 | {
|
| 376 | $post_img = $post_icons['post_img']; |
| 377 | $reply_img = $post_icons['reply_img']; |
| 378 | $quote_img = $post_icons['quote_img']; |
| 379 | $edit_img = ''; |
| 380 | $post = $post_icons['post']; |
| 381 | $reply = $post_icons['reply']; |
| 382 | $quote = $post_icons['quote']; |
| 383 | $edit = ''; |
| 384 | } |
| 385 | else
|
| 386 | {
|
| 387 | $post_img = $post_icons['post_img']; |
| 388 | $reply_img = ''; |
| 389 | $quote_img = ''; |
| 390 | $edit_img = ''; |
| 391 | $post = $post_icons['post']; |
| 392 | $reply = ''; |
| 393 | $quote = ''; |
| 394 | $edit = ''; |
| 395 | } |
| 396 | $l_box_name = $lang['Saved']; |
| 397 | } |
| 398 | else if ( $folder == 'sentbox' ) |
| 399 | {
|
| 400 | $post_img = $post_icons['post_img']; |
| 401 | $reply_img = ''; |
| 402 | $quote_img = ''; |
| 403 | $edit_img = ''; |
| 404 | $post = $post_icons['post']; |
| 405 | $reply = ''; |
| 406 | $quote = ''; |
| 407 | $edit = ''; |
| 408 | $l_box_name = $lang['Sent']; |
| 409 | } |
| 410 | |
| 411 | $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />'; |
| 412 | |
| 413 | $page_title = $lang['Read_pm']; |
| 414 | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 415 | |
| 416 | //
|
| 417 | // Load templates
|
| 418 | //
|
| 419 | $template->set_filenames(array( |
| 420 | 'body' => 'privmsgs_read_body.tpl') |
| 421 | ); |
| 422 | make_jumpbox('viewforum.'.$phpEx); |
| 423 | |
| 424 | $template->assign_vars(array( |
| 425 | 'INBOX_IMG' => $inbox_img, |
| 426 | 'SENTBOX_IMG' => $sentbox_img, |
| 427 | 'OUTBOX_IMG' => $outbox_img, |
| 428 | 'SAVEBOX_IMG' => $savebox_img, |
| 429 | 'INBOX' => $inbox_url, |
| 430 | |
| 431 | 'POST_PM_IMG' => $post_img, |
| 432 | 'REPLY_PM_IMG' => $reply_img, |
| 433 | 'EDIT_PM_IMG' => $edit_img, |
| 434 | 'QUOTE_PM_IMG' => $quote_img, |
| 435 | 'POST_PM' => $post, |
| 436 | 'REPLY_PM' => $reply, |
| 437 | 'EDIT_PM' => $edit, |
| 438 | 'QUOTE_PM' => $quote, |
| 439 | |
| 440 | 'SENTBOX' => $sentbox_url, |
| 441 | 'OUTBOX' => $outbox_url, |
| 442 | 'SAVEBOX' => $savebox_url, |
| 443 | |
| 444 | 'BOX_NAME' => $l_box_name, |
| 445 | |
| 446 | 'L_MESSAGE' => $lang['Message'], |
| 447 | 'L_INBOX' => $lang['Inbox'], |
| 448 | 'L_OUTBOX' => $lang['Outbox'], |
| 449 | 'L_SENTBOX' => $lang['Sent'], |
| 450 | 'L_SAVEBOX' => $lang['Saved'], |
| 451 | 'L_FLAG' => $lang['Flag'], |
| 452 | 'L_SUBJECT' => $lang['Subject'], |
| 453 | 'L_POSTED' => $lang['Posted'], |
| 454 | 'L_DATE' => $lang['Date'], |
| 455 | 'L_FROM' => $lang['From'], |
| 456 | 'L_TO' => $lang['To'], |
| 457 | 'L_SAVE_MSG' => $lang['Save_message'], |
| 458 | 'L_DELETE_MSG' => $lang['Delete_message'], |
| 459 | |
| 460 | 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"), |
| 461 | 'S_HIDDEN_FIELDS' => $s_hidden_fields) |
| 462 | ); |
| 463 | |
| 464 | $username_from = $privmsg['username_1']; |
| 465 | $user_id_from = $privmsg['user_id_1']; |
| 466 | $username_to = $privmsg['username_2']; |
| 467 | $user_id_to = $privmsg['user_id_2']; |
| 468 | |
| 469 | $post_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']); |
| 470 | |
| 471 | $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $user_id_from); |
| 472 | $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>'; |
| 473 | $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>'; |
| 474 | |
| 475 | $temp_url = append_sid("privmsg.$phpEx?mode=post&" . POST_USERS_URL . "=$poster_id"); |
| 476 | $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>'; |
| 477 | $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>'; |
| 478 | |
| 479 | if ( !empty($privmsg['user_viewemail']) || $userdata['user_level'] == ADMIN ) |
| 480 | {
|
| 481 | $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&" . POST_USERS_URL .'=' . $user_id_from) : 'mailto:' . $privmsg['user_email']; |
| 482 | |
| 483 | $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>'; |
| 484 | $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>'; |
| 485 | } |
| 486 | else
|
| 487 | {
|
| 488 | $email_img = ''; |
| 489 | $email = ''; |
| 490 | } |
| 491 | |
| 492 | $www_img = ( $privmsg['user_website'] ) ? '<a href="' . $privmsg['user_website'] . '" target="_userwww"><img src="' . $images['icon_www'] . '" alt="' . $lang['Visit_website'] . '" title="' . $lang['Visit_website'] . '" border="0" /></a>' : ''; |
| 493 | $www = ( $privmsg['user_website'] ) ? '<a href="' . $privmsg['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : ''; |
| 494 | |
| 495 | if ( !empty($privmsg['user_icq']) ) |
| 496 | {
|
| 497 | $icq_status_img = '<a href="http://wwp.icq.com/' . $privmsg['user_icq'] . '#pager"><img src="http://web.icq.com/whitepages/online?icq=' . $privmsg['user_icq'] . '&img=5" width="18" height="18" border="0" /></a>'; |
| 498 | $icq_img = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $privmsg['user_icq'] . '"><img src="' . $images['icon_icq'] . '" alt="' . $lang['ICQ'] . '" title="' . $lang['ICQ'] . '" border="0" /></a>'; |
| 499 | $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $privmsg['user_icq'] . '">' . $lang['ICQ'] . '</a>'; |
| 500 | } |
| 501 | else
|
| 502 | {
|
| 503 | $icq_status_img = ''; |
| 504 | $icq_img = ''; |
| 505 | $icq = ''; |
| 506 | } |
| 507 | |
| 508 | $aim_img = ( $privmsg['user_aim'] ) ? '<a href="aim:goim?screenname=' . $privmsg['user_aim'] . '&message=Hello+Are+you+there?"><img src="' . $images['icon_aim'] . '" alt="' . $lang['AIM'] . '" title="' . $lang['AIM'] . '" border="0" /></a>' : ''; |
| 509 | $aim = ( $privmsg['user_aim'] ) ? '<a href="aim:goim?screenname=' . $privmsg['user_aim'] . '&message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : ''; |
| 510 | |
| 511 | $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$poster_id"); |
| 512 | $msn_img = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : ''; |
| 513 | $msn = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : ''; |
| 514 | |
| 515 | $yim_img = ( $privmsg['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $privmsg['user_yim'] . '&.src=pg"><img src="' . $images['icon_yim'] . '" alt="' . $lang['YIM'] . '" title="' . $lang['YIM'] . '" border="0" /></a>' : ''; |
| 516 | $yim = ( $privmsg['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $privmsg['user_yim'] . '&.src=pg">' . $lang['YIM'] . '</a>' : ''; |
| 517 | |
| 518 | $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($username_from) . "&showresults=posts"); |
| 519 | $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>'; |
| 520 | $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>'; |
| 521 | |
| 522 | //
|
| 523 | // Processing of post
|
| 524 | //
|
| 525 | $post_subject = $privmsg['privmsgs_subject']; |
| 526 | |
| 527 | $private_message = $privmsg['privmsgs_text']; |
| 528 | $bbcode_uid = $privmsg['privmsgs_bbcode_uid']; |
| 529 | |
| 530 | if ( $board_config['allow_sig'] ) |
| 531 | {
|
| 532 | $user_sig = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig'] : $privmsg['user_sig']; |
| 533 | } |
| 534 | else
|
| 535 | {
|
| 536 | $user_sig = ''; |
| 537 | } |
| 538 | |
| 539 | $user_sig_bbcode_uid = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig_bbcode_uid'] : $privmsg['user_sig_bbcode_uid']; |
| 540 | |
| 541 | //
|
| 542 | // If the board has HTML off but the post has HTML
|
| 543 | // on then we process it, else leave it alone
|
| 544 | //
|
| 545 | if ( !$board_config['allow_html'] ) |
| 546 | {
|
| 547 | if ( $user_sig != '' && $privmsg['privmsgs_enable_sig'] && $userdata['user_allowhtml'] ) |
| 548 | {
|
| 549 | $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig); |
| 550 | } |
| 551 | |
| 552 | if ( $privmsg['privmsgs_enable_html'] ) |
| 553 | {
|
| 554 | $private_message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $private_message); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if ( $user_sig != '' && $privmsg['privmsgs_attach_sig'] && $user_sig_bbcode_uid != '' ) |
| 559 | {
|
| 560 | $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig); |
| 561 | } |
| 562 | |
| 563 | if ( $bbcode_uid != '' ) |
| 564 | {
|
| 565 | $private_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($private_message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $private_message); |
| 566 | } |
| 567 | |
| 568 | $private_message = make_clickable($private_message); |
| 569 | |
| 570 | if ( $privmsg['privmsgs_attach_sig'] && $user_sig != '' ) |
| 571 | {
|
| 572 | $private_message .= '<br /><br />_________________<br />' . make_clickable($user_sig); |
| 573 | } |
| 574 | |
| 575 | $orig_word = array(); |
| 576 | $replacement_word = array(); |
| 577 | obtain_word_list($orig_word, $replacement_word); |
| 578 | |
| 579 | if ( count($orig_word) ) |
| 580 | {
|
| 581 | $post_subject = preg_replace($orig_word, $replacement_word, $post_subject); |
| 582 | $private_message = preg_replace($orig_word, $replacement_word, $private_message); |
| 583 | } |
| 584 | |
| 585 | if ( $board_config['allow_smilies'] && $privmsg['privmsgs_enable_smilies'] ) |
| 586 | {
|
| 587 | $private_message = smilies_pass($private_message); |
| 588 | } |
| 589 | |
| 590 | $private_message = str_replace("\n", '<br />', $private_message); |
| 591 | |
| 592 | //
|
| 593 | // Dump it to the templating engine
|
| 594 | //
|
| 595 | $template->assign_vars(array( |
| 596 | 'MESSAGE_TO' => $username_to, |
| 597 | 'MESSAGE_FROM' => $username_from, |
| 598 | 'RANK_IMAGE' => $rank_image, |
| 599 | 'POSTER_JOINED' => $poster_joined, |
| 600 | 'POSTER_POSTS' => $poster_posts, |
| 601 | 'POSTER_FROM' => $poster_from, |
| 602 | 'POSTER_AVATAR' => $poster_avatar, |
| 603 | 'POST_SUBJECT' => $post_subject, |
| 604 | 'POST_DATE' => $post_date, |
| 605 | 'MESSAGE' => $private_message, |
| 606 | |
| 607 | 'PROFILE_IMG' => $profile_img, |
| 608 | 'PROFILE' => $profile, |
| 609 | 'SEARCH_IMG' => $search_img, |
| 610 | 'SEARCH' => $search, |
| 611 | 'EMAIL_IMG' => $email_img, |
| 612 | 'EMAIL' => $email, |
| 613 | 'WWW_IMG' => $www_img, |
| 614 | 'WWW' => $www, |
| 615 | 'ICQ_STATUS_IMG' => $icq_status_img, |
| 616 | 'ICQ_IMG' => $icq_img, |
| 617 | 'ICQ' => $icq, |
| 618 | 'AIM_IMG' => $aim_img, |
| 619 | 'AIM' => $aim, |
| 620 | 'MSN_IMG' => $msn_img, |
| 621 | 'MSN' => $msn, |
| 622 | 'YIM_IMG' => $yim_img, |
| 623 | 'YIM' => $yim) |
| 624 | ); |
| 625 | |
| 626 | $template->pparse('body'); |
| 627 | |
| 628 | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 629 | |
| 630 | } |
| 631 | else if ( ( $delete && $mark_list ) || $delete_all ) |
| 632 | {
|
| 633 | if ( !$userdata['session_logged_in'] ) |
| 634 | {
|
| 635 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 636 | header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true)); |
| 637 | exit;
|
| 638 | } |
| 639 | if ( isset($mark_list) && !is_array($mark_list) ) |
| 640 | {
|
| 641 | // Set to empty array instead of '0' if nothing is selected.
|
| 642 | $mark_list = array(); |
| 643 | } |
| 644 | |
| 645 | if ( !$confirm ) |
| 646 | {
|
| 647 | $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" />'; |
| 648 | $s_hidden_fields .= ( isset($HTTP_POST_VARS['delete']) ) ? '<input type="hidden" name="delete" value="true" />' : '<input type="hidden" name="deleteall" value="true" />'; |
| 649 | |
| 650 | for($i = 0; $i < count($mark_list); $i++) |
| 651 | {
|
| 652 | $s_hidden_fields .= '<input type="hidden" name="mark[]" value="' . $mark_list[$i] . '" />'; |
| 653 | } |
| 654 | |
| 655 | //
|
| 656 | // Output confirmation page
|
| 657 | //
|
| 658 | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 659 | |
| 660 | $template->set_filenames(array( |
| 661 | 'confirm_body' => 'confirm_body.tpl') |
| 662 | ); |
| 663 | $template->assign_vars(array( |
| 664 | 'MESSAGE_TITLE' => $lang['Information'], |
| 665 | 'MESSAGE_TEXT' => ( count($mark_list) == 1 ) ? $lang['Confirm_delete_pm'] : $lang['Confirm_delete_pms'], |
| 666 | |
| 667 | 'L_YES' => $lang['Yes'], |
| 668 | 'L_NO' => $lang['No'], |
| 669 | |
| 670 | 'S_CONFIRM_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"), |
| 671 | 'S_HIDDEN_FIELDS' => $s_hidden_fields) |
| 672 | ); |
| 673 | |
| 674 | $template->pparse('confirm_body'); |
| 675 | |
| 676 | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 677 | |
| 678 | } |
| 679 | else if ( $confirm ) |
| 680 | {
|
| 681 | if ( $delete_all ) |
| 682 | {
|
| 683 | switch($folder) |
| 684 | {
|
| 685 | case 'inbox': |
| 686 | $delete_type = "privmsgs_to_userid = " . $userdata['user_id'] . " AND ( |
| 687 | privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 688 | break;
|
| 689 | |
| 690 | case 'outbox': |
| 691 | $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 692 | break;
|
| 693 | |
| 694 | case 'sentbox': |
| 695 | $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 696 | break;
|
| 697 | |
| 698 | case 'savebox': |
| 699 | $delete_type = "( ( privmsgs_from_userid = " . $userdata['user_id'] . " |
| 700 | AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) |
| 701 | OR ( privmsgs_to_userid = " . $userdata['user_id'] . " |
| 702 | AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )"; |
| 703 | break;
|
| 704 | } |
| 705 | |
| 706 | $sql = "SELECT privmsgs_id |
| 707 | FROM " . PRIVMSGS_TABLE . " |
| 708 | WHERE $delete_type"; |
| 709 | if ( !($result = $db->sql_query($sql)) ) |
| 710 | {
|
| 711 | message_die(GENERAL_ERROR, 'Could not obtain id list to delete all messages', '', __LINE__, __FILE__, $sql); |
| 712 | } |
| 713 | |
| 714 | while ( $row = $db->sql_fetchrow($result) ) |
| 715 | {
|
| 716 | $mark_list[] = $row['privmsgs_id']; |
| 717 | } |
| 718 | |
| 719 | unset($delete_type); |
| 720 | } |
| 721 | |
| 722 | if ( count($mark_list) ) |
| 723 | {
|
| 724 | $delete_sql_id = implode(', ', $mark_list); |
| 725 | |
| 726 | //
|
| 727 | // Need to decrement the new message counter of recipient
|
| 728 | // problem is this doesn't affect the unread counter even
|
| 729 | // though it may be the one that needs changing ... hhmmm
|
| 730 | //
|
| 731 | if ( $folder == 'outbox' ) |
| 732 | {
|
| 733 | $sql = "SELECT privmsgs_to_userid |
| 734 | FROM " . PRIVMSGS_TABLE . " |
| 735 | WHERE privmsgs_id IN ($delete_sql_id) |
| 736 | AND privmsgs_from_userid = " . $userdata['user_id'] . " |
| 737 | AND privmsgs_type = " . PRIVMSGS_NEW_MAIL; |
| 738 | if ( !($result = $db->sql_query($sql)) ) |
| 739 | {
|
| 740 | message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql); |
| 741 | } |
| 742 | |
| 743 | $update_pm_sql = ''; |
| 744 | while( $row = $db->sql_fetchrow($result) ) |
| 745 | {
|
| 746 | $update_pm_sql .= ( ( $update_pm_sql != '' ) ? ', ' : '' ) . $row['privmsgs_to_userid']; |
| 747 | } |
| 748 | |
| 749 | if ( $update_pm_sql != '' ) |
| 750 | {
|
| 751 | $sql = "UPDATE " . USERS_TABLE . " |
| 752 | SET user_new_privmsg = user_new_privmsg - 1 |
| 753 | WHERE user_id IN ($update_pm_sql)"; |
| 754 | if ( !$db->sql_query($sql) ) |
| 755 | {
|
| 756 | message_die(GENERAL_ERROR, 'Could not update users new msg counters', '', __LINE__, __FILE__, $sql); |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | $sql = "SELECT privmsgs_to_userid |
| 761 | FROM " . PRIVMSGS_TABLE . " |
| 762 | WHERE privmsgs_id IN ($delete_sql_id) |
| 763 | AND privmsgs_from_userid = " . $userdata['user_id'] . " |
| 764 | AND privmsgs_type = " . PRIVMSGS_UNREAD_MAIL; |
| 765 | if ( !($result = $db->sql_query($sql)) ) |
| 766 | {
|
| 767 | message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql); |
| 768 | } |
| 769 | |
| 770 | $update_pm_sql = ''; |
| 771 | while( $row = $db->sql_fetchrow($result) ) |
| 772 | {
|
| 773 | $update_pm_sql .= ( ( $update_pm_sql != '' ) ? ', ' : '' ) . $row['privmsgs_to_userid']; |
| 774 | } |
| 775 | |
| 776 | if ( $update_pm_sql != '' ) |
| 777 | {
|
| 778 | $sql = "UPDATE " . USERS_TABLE . " |
| 779 | SET user_unread_privmsg = user_unread_privmsg - 1 |
| 780 | WHERE user_id IN ($update_pm_sql)"; |
| 781 | if ( !$db->sql_query($sql) ) |
| 782 | {
|
| 783 | message_die(GENERAL_ERROR, 'Could not update users new msg counters', '', __LINE__, __FILE__, $sql); |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | $delete_text_sql = "DELETE FROM " . PRIVMSGS_TEXT_TABLE . " |
| 789 | WHERE privmsgs_text_id IN ($delete_sql_id)"; |
| 790 | $delete_sql = "DELETE FROM " . PRIVMSGS_TABLE . " |
| 791 | WHERE privmsgs_id IN ($delete_sql_id) |
| 792 | AND ";
|
| 793 | |
| 794 | switch( $folder ) |
| 795 | {
|
| 796 | case 'inbox': |
| 797 | $delete_sql .= "privmsgs_to_userid = " . $userdata['user_id'] . " AND ( |
| 798 | privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 799 | break;
|
| 800 | |
| 801 | case 'outbox': |
| 802 | $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( |
| 803 | privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 804 | break;
|
| 805 | |
| 806 | case 'sentbox': |
| 807 | $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 808 | break;
|
| 809 | |
| 810 | case 'savebox': |
| 811 | $delete_sql .= "( ( privmsgs_from_userid = " . $userdata['user_id'] . " |
| 812 | AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) |
| 813 | OR ( privmsgs_to_userid = " . $userdata['user_id'] . " |
| 814 | AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )"; |
| 815 | break;
|
| 816 | } |
| 817 | |
| 818 | if ( !$db->sql_query($delete_sql, BEGIN_TRANSACTION) ) |
| 819 | {
|
| 820 | message_die(GENERAL_ERROR, 'Could not delete private message info', '', __LINE__, __FILE__, $delete_sql); |
| 821 | } |
| 822 | |
| 823 | if ( !$db->sql_query($delete_text_sql, END_TRANSACTION) ) |
| 824 | {
|
| 825 | message_die(GENERAL_ERROR, 'Could not delete private message text', '', __LINE__, __FILE__, $delete_text_sql); |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | else if ( $save && $mark_list && $folder != 'savebox' && $folder != 'outbox' ) |
| 831 | {
|
| 832 | if ( !$userdata['session_logged_in'] ) |
| 833 | {
|
| 834 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 835 | header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true)); |
| 836 | exit;
|
| 837 | } |
| 838 | |
| 839 | //
|
| 840 | // See if recipient is at their savebox limit
|
| 841 | //
|
| 842 | $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time |
| 843 | FROM " . PRIVMSGS_TABLE . " |
| 844 | WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . " |
| 845 | AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) |
| 846 | OR ( privmsgs_from_userid = " . $userdata['user_id'] . " |
| 847 | AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )"; |
| 848 | if ( !($result = $db->sql_query($sql)) ) |
| 849 | {
|
| 850 | message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql); |
| 851 | } |
| 852 | |
| 853 | $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : ''; |
| 854 | |
| 855 | if ( $saved_info = $db->sql_fetchrow($result) ) |
| 856 | {
|
| 857 | if ( $saved_info['savebox_items'] >= $board_config['max_savebox_privmsgs'] ) |
| 858 | {
|
| 859 | $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . " |
| 860 | WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . " |
| 861 | AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) |
| 862 | OR ( privmsgs_from_userid = " . $userdata['user_id'] . " |
| 863 | AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") ) |
| 864 | AND privmsgs_date = " . $saved_info['oldest_post_time']; |
| 865 | if ( !$db->sql_query($sql) ) |
| 866 | {
|
| 867 | message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql); |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | //
|
| 873 | // Process request
|
| 874 | //
|
| 875 | $saved_sql = "UPDATE " . PRIVMSGS_TABLE; |
| 876 | |
| 877 | switch( $folder ) |
| 878 | {
|
| 879 | case 'inbox': |
| 880 | $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " |
| 881 | WHERE privmsgs_to_userid = " . $userdata['user_id'] . " |
| 882 | AND ( privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 883 | OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 884 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")"; |
| 885 | break;
|
| 886 | |
| 887 | case 'outbox': |
| 888 | $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " |
| 889 | WHERE privmsgs_from_userid = " . $userdata['user_id'] . " |
| 890 | AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 891 | OR privmsgs_type = " . PRIVMSGS_UNERAD_MAIL . " ) "; |
| 892 | break;
|
| 893 | |
| 894 | case 'sentbox': |
| 895 | $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " |
| 896 | WHERE privmsgs_from_userid = " . $userdata['user_id'] . " |
| 897 | AND privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 898 | break;
|
| 899 | } |
| 900 | |
| 901 | if ( count($mark_list) ) |
| 902 | {
|
| 903 | $saved_sql_id = ''; |
| 904 | for($i = 0; $i < count($mark_list); $i++) |
| 905 | {
|
| 906 | $saved_sql_id .= ( ( $saved_sql_id != '' ) ? ', ' : '' ) . $mark_list[$i]; |
| 907 | } |
| 908 | |
| 909 | $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)"; |
| 910 | |
| 911 | if ( !$db->sql_query($saved_sql) ) |
| 912 | {
|
| 913 | message_die(GENERAL_ERROR, 'Could not save private messages', '', __LINE__, __FILE__, $saved_sql); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | } |
| 918 | else if ( $submit || $refresh || $mode != '' ) |
| 919 | {
|
| 920 | |
| 921 | if ( !$userdata['session_logged_in'] ) |
| 922 | {
|
| 923 | $user_id = ( isset($HTTP_GET_VARS[POST_USERS_URL]) ) ? '&' . POST_USERS_URL . '=' . intval($HTTP_GET_VARS[POST_USERS_URL]) : ''; |
| 924 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 925 | header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode" . $user_id, true)); |
| 926 | exit;
|
| 927 | } |
| 928 | |
| 929 | //
|
| 930 | // Toggles
|
| 931 | //
|
| 932 | if ( !$board_config['allow_html'] ) |
| 933 | {
|
| 934 | $html_on = 0; |
| 935 | } |
| 936 | else
|
| 937 | {
|
| 938 | $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : $userdata['user_allowhtml']; |
| 939 | } |
| 940 | |
| 941 | if ( !$board_config['allow_bbcode'] ) |
| 942 | {
|
| 943 | $bbcode_on = 0; |
| 944 | } |
| 945 | else
|
| 946 | {
|
| 947 | $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : $userdata['user_allowbbcode']; |
| 948 | } |
| 949 | |
| 950 | if ( !$board_config['allow_smilies'] ) |
| 951 | {
|
| 952 | $smilies_on = 0; |
| 953 | } |
| 954 | else
|
| 955 | {
|
| 956 | $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : $userdata['user_allowsmile']; |
| 957 | } |
| 958 | |
| 959 | $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : $userdata['user_attachsig']; |
| 960 | $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : ""; |
| 961 | |
| 962 | if ( $submit && $mode != 'edit' ) |
| 963 | {
|
| 964 | //
|
| 965 | // Flood control
|
| 966 | //
|
| 967 | $sql = "SELECT MAX(privmsgs_date) AS last_post_time |
| 968 | FROM " . PRIVMSGS_TABLE . " |
| 969 | WHERE privmsgs_from_userid = " . $userdata['user_id']; |
| 970 | if ( $result = $db->sql_query($sql) ) |
| 971 | {
|
| 972 | $db_row = $db->sql_fetchrow($result); |
| 973 | |
| 974 | $last_post_time = $db_row['last_post_time']; |
| 975 | $current_time = time(); |
| 976 | |
| 977 | if ( ( $current_time - $last_post_time ) < $board_config['flood_interval']) |
| 978 | {
|
| 979 | message_die(GENERAL_MESSAGE, $lang['Flood_Error']); |
| 980 | } |
| 981 | } |
| 982 | //
|
| 983 | // End Flood control
|
| 984 | //
|
| 985 | } |
| 986 | |
| 987 | if ( $submit ) |
| 988 | {
|
| 989 | if ( !empty($HTTP_POST_VARS['username']) ) |
| 990 | {
|
| 991 | $to_username = $HTTP_POST_VARS['username']; |
| 992 | |
| 993 | $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active |
| 994 | FROM " . USERS_TABLE . " |
| 995 | WHERE username = '" . str_replace("\'", "''", $to_username) . "' |
| 996 | AND user_id <> " . ANONYMOUS; |
| 997 | if ( !($result = $db->sql_query($sql)) ) |
| 998 | {
|
| 999 | $error = TRUE; |
| 1000 | $error_msg = $lang['No_such_user']; |
| 1001 | } |
| 1002 | |
| 1003 | $to_userdata = $db->sql_fetchrow($result); |
| 1004 | } |
| 1005 | else
|
| 1006 | {
|
| 1007 | $error = TRUE; |
| 1008 | $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['No_to_user']; |
| 1009 | } |
| 1010 | |
| 1011 | $privmsg_subject = trim(strip_tags($HTTP_POST_VARS['subject'])); |
| 1012 | if ( empty($privmsg_subject) ) |
| 1013 | {
|
| 1014 | $error = TRUE; |
| 1015 | $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject']; |
| 1016 | } |
| 1017 | |
| 1018 | if ( !empty($HTTP_POST_VARS['message']) ) |
| 1019 | {
|
| 1020 | if ( !$error ) |
| 1021 | {
|
| 1022 | if ( $bbcode_on ) |
| 1023 | {
|
| 1024 | $bbcode_uid = make_bbcode_uid();
|
| 1025 | } |
| 1026 | |
| 1027 | $privmsg_message = prepare_message($HTTP_POST_VARS['message'], $html_on, $bbcode_on, $smilies_on, $bbcode_uid); |
| 1028 | |
| 1029 | } |
| 1030 | } |
| 1031 | else
|
| 1032 | {
|
| 1033 | $error = TRUE; |
| 1034 | $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message']; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | if ( $submit && !$error ) |
| 1039 | {
|
| 1040 | //
|
| 1041 | // Has admin prevented user from sending PM's?
|
| 1042 | //
|
| 1043 | if ( !$userdata['user_allow_pm'] ) |
| 1044 | {
|
| 1045 | $message = $lang['Cannot_send_privmsg']; |
| 1046 | message_die(GENERAL_MESSAGE, $message); |
| 1047 | } |
| 1048 | |
| 1049 | $msg_time = time(); |
| 1050 | |
| 1051 | if ( $mode != 'edit' ) |
| 1052 | {
|
| 1053 | //
|
| 1054 | // See if recipient is at their inbox limit
|
| 1055 | //
|
| 1056 | $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time |
| 1057 | FROM " . PRIVMSGS_TABLE . " |
| 1058 | WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1059 | OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 1060 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) |
| 1061 | AND privmsgs_to_userid = " . $to_userdata['user_id']; |
| 1062 | if ( !($result = $db->sql_query($sql)) ) |
| 1063 | {
|
| 1064 | message_die(GENERAL_MESSAGE, $lang['No_such_user']); |
| 1065 | } |
| 1066 | |
| 1067 | $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : ''; |
| 1068 | |
| 1069 | if ( $inbox_info = $db->sql_fetchrow($result) ) |
| 1070 | {
|
| 1071 | if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] ) |
| 1072 | {
|
| 1073 | $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . " |
| 1074 | WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1075 | OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 1076 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) |
| 1077 | AND privmsgs_date = " . $inbox_info['oldest_post_time'] . " |
| 1078 | AND privmsgs_to_userid = " . $to_userdata['user_id']; |
| 1079 | if ( !$db->sql_query($sql) ) |
| 1080 | {
|
| 1081 | message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | $sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig) |
| 1087 | VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $html_on, $bbcode_on, $smilies_on, $attach_sig)"; |
| 1088 | } |
| 1089 | else
|
| 1090 | {
|
| 1091 | $sql_info = "UPDATE " . PRIVMSGS_TABLE . " |
| 1092 | SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . str_replace("\'", "''", $privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '$user_ip', privmsgs_enable_html = $html_on, privmsgs_enable_bbcode = $bbcode_on, privmsgs_enable_smilies = $smilies_on, privmsgs_attach_sig = $attach_sig |
| 1093 | WHERE privmsgs_id = $privmsg_id"; |
| 1094 | } |
| 1095 | |
| 1096 | if ( !($result = $db->sql_query($sql_info, BEGIN_TRANSACTION)) ) |
| 1097 | {
|
| 1098 | message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info); |
| 1099 | } |
| 1100 | |
| 1101 | if ( $mode != 'edit' ) |
| 1102 | {
|
| 1103 | $privmsg_sent_id = $db->sql_nextid(); |
| 1104 | |
| 1105 | $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) |
| 1106 | VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')"; |
| 1107 | } |
| 1108 | else
|
| 1109 | {
|
| 1110 | $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . " |
| 1111 | SET privmsgs_text = '" . str_replace("\'", "''", $privmsg_message) . "', privmsgs_bbcode_uid = '$bbcode_uid' |
| 1112 | WHERE privmsgs_text_id = $privmsg_id"; |
| 1113 | } |
| 1114 | |
| 1115 | if ( !$db->sql_query($sql, END_TRANSACTION) ) |
| 1116 | {
|
| 1117 | message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql_info); |
| 1118 | } |
| 1119 | |
| 1120 | if ( $mode != 'edit' ) |
| 1121 | {
|
| 1122 | //
|
| 1123 | // Add to the users new pm counter
|
| 1124 | //
|
| 1125 | $sql = "UPDATE " . USERS_TABLE . " |
| 1126 | SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . " |
| 1127 | WHERE user_id = " . $to_userdata['user_id']; |
| 1128 | if ( !$status = $db->sql_query($sql) ) |
| 1129 | {
|
| 1130 | message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql); |
| 1131 | } |
| 1132 | |
| 1133 | if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] ) |
| 1134 | {
|
| 1135 | $email_headers = 'From: ' . $board_config['board_email'] . "\nReturn-Path: " . $board_config['board_email'] . "\n"; |
| 1136 | |
| 1137 | $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])); |
| 1138 | $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx; |
| 1139 | $server_name = trim($board_config['server_name']); |
| 1140 | $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; |
| 1141 | $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/'; |
| 1142 | |
| 1143 | include($phpbb_root_path . 'includes/emailer.'.$phpEx); |
| 1144 | $emailer = new emailer($board_config['smtp_delivery']); |
| 1145 | |
| 1146 | $emailer->use_template('privmsg_notify', $to_userdata['user_lang']); |
| 1147 | $emailer->extra_headers($email_headers); |
| 1148 | $emailer->email_address($to_userdata['user_email']); |
| 1149 | $emailer->set_subject(); //$lang['Notification_subject'] |
| 1150 | |
| 1151 | $emailer->assign_vars(array( |
| 1152 | 'USERNAME' => $to_username, |
| 1153 | 'SITENAME' => $board_config['sitename'], |
| 1154 | 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']), |
| 1155 | |
| 1156 | 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox') |
| 1157 | ); |
| 1158 | |
| 1159 | $emailer->send();
|
| 1160 | $emailer->reset(); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | $template->assign_vars(array( |
| 1165 | 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("privmsg.$phpEx?folder=inbox") . '">') |
| 1166 | ); |
| 1167 | |
| 1168 | $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>'); |
| 1169 | |
| 1170 | message_die(GENERAL_MESSAGE, $msg); |
| 1171 | } |
| 1172 | else if ( $preview || $refresh || $error ) |
| 1173 | {
|
| 1174 | |
| 1175 | //
|
| 1176 | // If we're previewing or refreshing then obtain the data
|
| 1177 | // passed to the script, process it a little, do some checks
|
| 1178 | // where neccessary, etc.
|
| 1179 | //
|
| 1180 | $to_username = ( isset($HTTP_POST_VARS['username']) ) ? trim(strip_tags(stripslashes($HTTP_POST_VARS['username']))) : ''; |
| 1181 | $privmsg_subject = ( isset($HTTP_POST_VARS['subject']) ) ? trim(strip_tags(stripslashes($HTTP_POST_VARS['subject']))) : ''; |
| 1182 | $privmsg_message = ( isset($HTTP_POST_VARS['message']) ) ? trim($HTTP_POST_VARS['message']) : ''; |
| 1183 | $privmsg_message = preg_replace('#<textarea>#si', '<textarea>', $privmsg_message); |
| 1184 | if ( !$preview ) |
| 1185 | {
|
| 1186 | $privmsg_message = stripslashes($privmsg_message); |
| 1187 | } |
| 1188 | |
| 1189 | //
|
| 1190 | // Do mode specific things
|
| 1191 | //
|
| 1192 | if ( $mode == 'post' ) |
| 1193 | {
|
| 1194 | $page_title = $lang['Post_new_pm']; |
| 1195 | |
| 1196 | $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : ''; |
| 1197 | |
| 1198 | } |
| 1199 | else if ( $mode == 'reply' ) |
| 1200 | {
|
| 1201 | $page_title = $lang['Post_reply_pm']; |
| 1202 | |
| 1203 | $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : ''; |
| 1204 | |
| 1205 | } |
| 1206 | else if ( $mode == 'edit' ) |
| 1207 | {
|
| 1208 | $page_title = $lang['Edit_pm']; |
| 1209 | |
| 1210 | $sql = "SELECT u.user_id, u.user_sig |
| 1211 | FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u |
| 1212 | WHERE pm.privmsgs_id = $privmsg_id |
| 1213 | AND u.user_id = pm.privmsgs_from_userid";
|
| 1214 | if ( !($result = $db->sql_query($sql)) ) |
| 1215 | {
|
| 1216 | message_die(GENERAL_ERROR, "Could not obtain post and post text", "", __LINE__, __FILE__, $sql); |
| 1217 | } |
| 1218 | |
| 1219 | if ( $postrow = $db->sql_fetchrow($result) ) |
| 1220 | {
|
| 1221 | if ( $userdata['user_id'] != $postrow['user_id'] ) |
| 1222 | {
|
| 1223 | message_die(GENERAL_MESSAGE, $lang['Edit_own_posts']); |
| 1224 | } |
| 1225 | |
| 1226 | $user_sig = ( $postrow['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow['user_sig'] : ''; |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | else
|
| 1231 | {
|
| 1232 | if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) ) |
| 1233 | {
|
| 1234 | message_die(GENERAL_ERROR, $lang['No_post_id']); |
| 1235 | } |
| 1236 | |
| 1237 | if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) ) |
| 1238 | {
|
| 1239 | $user_id = intval($HTTP_GET_VARS[POST_USERS_URL]); |
| 1240 | |
| 1241 | $sql = "SELECT username |
| 1242 | FROM " . USERS_TABLE . " |
| 1243 | WHERE user_id = $user_id |
| 1244 | AND user_id <> " . ANONYMOUS; |
| 1245 | if ( !($result = $db->sql_query($sql)) ) |
| 1246 | {
|
| 1247 | $error = TRUE; |
| 1248 | $error_msg = $lang['No_such_user']; |
| 1249 | } |
| 1250 | |
| 1251 | if ( $row = $db->sql_fetchrow($result) ) |
| 1252 | {
|
| 1253 | $to_username = $row['username']; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | if ( $mode == 'edit' ) |
| 1258 | {
|
| 1259 | $sql = "SELECT pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id, u.user_sig |
| 1260 | FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u |
| 1261 | WHERE pm.privmsgs_id = $privmsg_id |
| 1262 | AND pmt.privmsgs_text_id = pm.privmsgs_id |
| 1263 | AND pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1264 | AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1265 | OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) |
| 1266 | AND u.user_id = pm.privmsgs_to_userid";
|
| 1267 | if ( !($result = $db->sql_query($sql)) ) |
| 1268 | {
|
| 1269 | message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql); |
| 1270 | } |
| 1271 | |
| 1272 | if ( !($privmsg = $db->sql_fetchrow($result)) ) |
| 1273 | {
|
| 1274 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 1275 | header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true)); |
| 1276 | exit;
|
| 1277 | } |
| 1278 | |
| 1279 | $privmsg_subject = $privmsg['privmsgs_subject']; |
| 1280 | $privmsg_message = $privmsg['privmsgs_text']; |
| 1281 | $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid']; |
| 1282 | $privmsg_bbcode_enabled = ($privmsg['privmsgs_enable_bbcode'] == 1); |
| 1283 | |
| 1284 | if ( $privmsg_bbcode_enabled ) |
| 1285 | {
|
| 1286 | $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message); |
| 1287 | } |
| 1288 | |
| 1289 | $privmsg_message = str_replace('<br />', "\n", $privmsg_message); |
| 1290 | $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message); |
| 1291 | |
| 1292 | $user_sig = ( $board_config['allow_sig'] ) ? $privmsg['user_sig'] : ''; |
| 1293 | |
| 1294 | $to_username = $privmsg['username']; |
| 1295 | $to_userid = $privmsg['user_id']; |
| 1296 | |
| 1297 | } |
| 1298 | else if ( $mode == 'reply' || $mode == 'quote' ) |
| 1299 | {
|
| 1300 | |
| 1301 | $sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id |
| 1302 | FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u |
| 1303 | WHERE pm.privmsgs_id = $privmsg_id |
| 1304 | AND pmt.privmsgs_text_id = pm.privmsgs_id |
| 1305 | AND pm.privmsgs_to_userid = " . $userdata['user_id'] . " |
| 1306 | AND u.user_id = pm.privmsgs_from_userid";
|
| 1307 | if ( !($result = $db->sql_query($sql)) ) |
| 1308 | {
|
| 1309 | message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql); |
| 1310 | } |
| 1311 | |
| 1312 | if ( !($privmsg = $db->sql_fetchrow($result)) ) |
| 1313 | {
|
| 1314 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 1315 | header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true)); |
| 1316 | exit;
|
| 1317 | } |
| 1318 | |
| 1319 | $privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ) . $privmsg['privmsgs_subject']; |
| 1320 | |
| 1321 | $to_username = $privmsg['username']; |
| 1322 | $to_userid = $privmsg['user_id']; |
| 1323 | |
| 1324 | if ( $mode == 'quote' ) |
| 1325 | {
|
| 1326 | $privmsg_message = $privmsg['privmsgs_text']; |
| 1327 | $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid']; |
| 1328 | |
| 1329 | $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message); |
| 1330 | $privmsg_message = str_replace('<br />', "\n", $privmsg_message); |
| 1331 | $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message); |
| 1332 | |
| 1333 | $msg_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']); |
| 1334 | |
| 1335 | $privmsg_message = '[quote="' . $to_username . '"]' . $privmsg_message . '[/quote]'; |
| 1336 | |
| 1337 | $mode = 'reply'; |
| 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | //
|
| 1343 | // Has admin prevented user from sending PM's?
|
| 1344 | //
|
| 1345 | if ( !$userdata['user_allow_pm'] && $mode != 'edit' ) |
| 1346 | {
|
| 1347 | $message = $lang['Cannot_send_privmsg']; |
| 1348 | message_die(GENERAL_MESSAGE, $message); |
| 1349 | } |
| 1350 | |
| 1351 | //
|
| 1352 | // Start output, first preview, then errors then post form
|
| 1353 | //
|
| 1354 | $page_title = $lang['Send_private_message']; |
| 1355 | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 1356 | |
| 1357 | if ( $preview && !$error ) |
| 1358 | {
|
| 1359 | $orig_word = array(); |
| 1360 | $replacement_word = array(); |
| 1361 | obtain_word_list($orig_word, $replacement_word); |
| 1362 | |
| 1363 | if ( $bbcode_on ) |
| 1364 | {
|
| 1365 | $bbcode_uid = make_bbcode_uid();
|
| 1366 | } |
| 1367 | |
| 1368 | $preview_message = stripslashes(prepare_message($privmsg_message, $html_on, $bbcode_on, $smilies_on, $bbcode_uid)); |
| 1369 | $privmsg_message = stripslashes(preg_replace($html_entities_match, $html_entities_replace, $privmsg_message)); |
| 1370 | |
| 1371 | //
|
| 1372 | // Finalise processing as per viewtopic
|
| 1373 | //
|
| 1374 | if ( !$html_on ) |
| 1375 | {
|
| 1376 | if ( $user_sig != '' || !$userdata['user_allowhtml'] ) |
| 1377 | {
|
| 1378 | $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | if ( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] ) |
| 1383 | {
|
| 1384 | $user_sig = bbencode_second_pass($user_sig, $userdata['user_sig_bbcode_uid']); |
| 1385 | } |
| 1386 | |
| 1387 | if ( $bbcode_on ) |
| 1388 | {
|
| 1389 | $preview_message = bbencode_second_pass($preview_message, $bbcode_uid); |
| 1390 | } |
| 1391 | |
| 1392 | if ( $attach_sig && $user_sig != '' ) |
| 1393 | {
|
| 1394 | $preview_message = $preview_message . '<br /><br />_________________<br />' . $user_sig; |
| 1395 | } |
| 1396 | |
| 1397 | if ( count($orig_word) ) |
| 1398 | {
|
| 1399 | $preview_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject); |
| 1400 | $preview_message = preg_replace($orig_word, $replacement_word, $preview_message); |
| 1401 | } |
| 1402 | else
|
| 1403 | {
|
| 1404 | $preview_subject = $privmsg_subject; |
| 1405 | } |
| 1406 | |
| 1407 | if ( $smilies_on ) |
| 1408 | {
|
| 1409 | $preview_message = smilies_pass($preview_message); |
| 1410 | } |
| 1411 | |
| 1412 | $preview_message = make_clickable($preview_message); |
| 1413 | $preview_message = str_replace("\n", '<br />', $preview_message); |
| 1414 | |
| 1415 | $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />'; |
| 1416 | $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />'; |
| 1417 | |
| 1418 | if ( isset($privmsg_id) ) |
| 1419 | {
|
| 1420 | $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />'; |
| 1421 | } |
| 1422 | |
| 1423 | $template->set_filenames(array( |
| 1424 | "preview" => 'privmsgs_preview.tpl') |
| 1425 | ); |
| 1426 | |
| 1427 | $template->assign_vars(array( |
| 1428 | 'TOPIC_TITLE' => $preview_subject, |
| 1429 | 'POST_SUBJECT' => $preview_subject, |
| 1430 | 'MESSAGE_TO' => $to_username, |
| 1431 | 'MESSAGE_FROM' => $userdata['username'], |
| 1432 | 'POST_DATE' => create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']), |
| 1433 | 'MESSAGE' => $preview_message, |
| 1434 | |
| 1435 | 'S_HIDDEN_FIELDS' => $s_hidden_fields, |
| 1436 | |
| 1437 | 'L_SUBJECT' => $lang['Subject'], |
| 1438 | 'L_DATE' => $lang['Date'], |
| 1439 | 'L_FROM' => $lang['From'], |
| 1440 | 'L_TO' => $lang['To'], |
| 1441 | 'L_PREVIEW' => $lang['Preview'], |
| 1442 | 'L_POSTED' => $lang['Posted']) |
| 1443 | ); |
| 1444 | |
| 1445 | $template->assign_var_from_handle('POST_PREVIEW_BOX', 'preview'); |
| 1446 | } |
| 1447 | |
| 1448 | //
|
| 1449 | // Start error handling
|
| 1450 | //
|
| 1451 | if ($error) |
| 1452 | {
|
| 1453 | $template->set_filenames(array( |
| 1454 | 'reg_header' => 'error_body.tpl') |
| 1455 | ); |
| 1456 | $template->assign_vars(array( |
| 1457 | 'ERROR_MESSAGE' => $error_msg) |
| 1458 | ); |
| 1459 | $template->assign_var_from_handle('ERROR_BOX', 'reg_header'); |
| 1460 | } |
| 1461 | |
| 1462 | //
|
| 1463 | // Load templates
|
| 1464 | //
|
| 1465 | $template->set_filenames(array( |
| 1466 | 'body' => 'posting_body.tpl') |
| 1467 | ); |
| 1468 | make_jumpbox('viewforum.'.$phpEx); |
| 1469 | |
| 1470 | //
|
| 1471 | // Enable extensions in posting_body
|
| 1472 | //
|
| 1473 | $template->assign_block_vars('switch_privmsg', array()); |
| 1474 | |
| 1475 | //
|
| 1476 | // HTML toggle selection
|
| 1477 | //
|
| 1478 | if ( $board_config['allow_html'] ) |
| 1479 | {
|
| 1480 | $html_status = $lang['HTML_is_ON']; |
| 1481 | $template->assign_block_vars('switch_html_checkbox', array()); |
| 1482 | } |
| 1483 | else
|
| 1484 | {
|
| 1485 | $html_status = $lang['HTML_is_OFF']; |
| 1486 | } |
| 1487 | |
| 1488 | //
|
| 1489 | // BBCode toggle selection
|
| 1490 | //
|
| 1491 | if ( $board_config['allow_bbcode'] ) |
| 1492 | {
|
| 1493 | $bbcode_status = $lang['BBCode_is_ON']; |
| 1494 | $template->assign_block_vars('switch_bbcode_checkbox', array()); |
| 1495 | } |
| 1496 | else
|
| 1497 | {
|
| 1498 | $bbcode_status = $lang['BBCode_is_OFF']; |
| 1499 | } |
| 1500 | |
| 1501 | //
|
| 1502 | // Smilies toggle selection
|
| 1503 | //
|
| 1504 | if ( $board_config['allow_smilies'] ) |
| 1505 | {
|
| 1506 | $smilies_status = $lang['Smilies_are_ON']; |
| 1507 | $template->assign_block_vars('switch_smilies_checkbox', array()); |
| 1508 | } |
| 1509 | else
|
| 1510 | {
|
| 1511 | $smilies_status = $lang['Smilies_are_OFF']; |
| 1512 | } |
| 1513 | |
| 1514 | //
|
| 1515 | // Signature toggle selection - only show if
|
| 1516 | // the user has a signature
|
| 1517 | //
|
| 1518 | if ( $user_sig != '' ) |
| 1519 | {
|
| 1520 | $template->assign_block_vars('switch_signature_checkbox', array()); |
| 1521 | } |
| 1522 | |
| 1523 | if ( $mode == 'post' ) |
| 1524 | {
|
| 1525 | $post_a = $lang['Send_a_new_message']; |
| 1526 | } |
| 1527 | else if ( $mode == 'reply' ) |
| 1528 | {
|
| 1529 | $post_a = $lang['Send_a_reply']; |
| 1530 | $mode = 'post'; |
| 1531 | } |
| 1532 | else if ( $mode == 'edit' ) |
| 1533 | {
|
| 1534 | $post_a = $lang['Edit_message']; |
| 1535 | } |
| 1536 | |
| 1537 | $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />'; |
| 1538 | $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />'; |
| 1539 | if ( $mode == 'edit' ) |
| 1540 | {
|
| 1541 | $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />'; |
| 1542 | } |
| 1543 | |
| 1544 | //
|
| 1545 | // Send smilies to template
|
| 1546 | //
|
| 1547 | generate_smilies('inline', PAGE_PRIVMSGS); |
| 1548 | |
| 1549 | $template->assign_vars(array( |
| 1550 | 'SUBJECT' => preg_replace($html_entities_match, $html_entities_replace, $privmsg_subject), |
| 1551 | 'USERNAME' => preg_replace($html_entities_match, $html_entities_replace, $to_username), |
| 1552 | 'MESSAGE' => $privmsg_message, |
| 1553 | 'HTML_STATUS' => $html_status, |
| 1554 | 'SMILIES_STATUS' => $smilies_status, |
| 1555 | 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'), |
| 1556 | 'FORUM_NAME' => $lang['Private_message'], |
| 1557 | |
| 1558 | 'BOX_NAME' => $l_box_name, |
| 1559 | 'INBOX_IMG' => $inbox_img, |
| 1560 | 'SENTBOX_IMG' => $sentbox_img, |
| 1561 | 'OUTBOX_IMG' => $outbox_img, |
| 1562 | 'SAVEBOX_IMG' => $savebox_img, |
| 1563 | 'INBOX' => $inbox_url, |
| 1564 | 'SENTBOX' => $sentbox_url, |
| 1565 | 'OUTBOX' => $outbox_url, |
| 1566 | 'SAVEBOX' => $savebox_url, |
| 1567 | |
| 1568 | 'L_SUBJECT' => $lang['Subject'], |
| 1569 | 'L_MESSAGE_BODY' => $lang['Message_body'], |
| 1570 | 'L_OPTIONS' => $lang['Options'], |
| 1571 | 'L_SPELLCHECK' => $lang['Spellcheck'], |
| 1572 | 'L_PREVIEW' => $lang['Preview'], |
| 1573 | 'L_SUBMIT' => $lang['Submit'], |
| 1574 | 'L_CANCEL' => $lang['Cancel'], |
| 1575 | 'L_POST_A' => $post_a, |
| 1576 | 'L_FIND_USERNAME' => $lang['Find_username'], |
| 1577 | 'L_FIND' => $lang['Find'], |
| 1578 | 'L_DISABLE_HTML' => $lang['Disable_HTML_pm'], |
| 1579 | 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_pm'], |
| 1580 | 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_pm'], |
| 1581 | 'L_ATTACH_SIGNATURE' => $lang['Attach_signature'], |
| 1582 | |
| 1583 | 'L_BBCODE_B_HELP' => $lang['bbcode_b_help'], |
| 1584 | 'L_BBCODE_I_HELP' => $lang['bbcode_i_help'], |
| 1585 | 'L_BBCODE_U_HELP' => $lang['bbcode_u_help'], |
| 1586 | 'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'], |
| 1587 | 'L_BBCODE_C_HELP' => $lang['bbcode_c_help'], |
| 1588 | 'L_BBCODE_L_HELP' => $lang['bbcode_l_help'], |
| 1589 | 'L_BBCODE_O_HELP' => $lang['bbcode_o_help'], |
| 1590 | 'L_BBCODE_P_HELP' => $lang['bbcode_p_help'], |
| 1591 | 'L_BBCODE_W_HELP' => $lang['bbcode_w_help'], |
| 1592 | 'L_BBCODE_A_HELP' => $lang['bbcode_a_help'], |
| 1593 | 'L_BBCODE_S_HELP' => $lang['bbcode_s_help'], |
| 1594 | 'L_BBCODE_F_HELP' => $lang['bbcode_f_help'], |
| 1595 | 'L_EMPTY_MESSAGE' => $lang['Empty_message'], |
| 1596 | |
| 1597 | 'L_FONT_COLOR' => $lang['Font_color'], |
| 1598 | 'L_COLOR_DEFAULT' => $lang['color_default'], |
| 1599 | 'L_COLOR_DARK_RED' => $lang['color_dark_red'], |
| 1600 | 'L_COLOR_RED' => $lang['color_red'], |
| 1601 | 'L_COLOR_ORANGE' => $lang['color_orange'], |
| 1602 | 'L_COLOR_BROWN' => $lang['color_brown'], |
| 1603 | 'L_COLOR_YELLOW' => $lang['color_yellow'], |
| 1604 | 'L_COLOR_GREEN' => $lang['color_green'], |
| 1605 | 'L_COLOR_OLIVE' => $lang['color_olive'], |
| 1606 | 'L_COLOR_CYAN' => $lang['color_cyan'], |
| 1607 | 'L_COLOR_BLUE' => $lang['color_blue'], |
| 1608 | 'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'], |
| 1609 | 'L_COLOR_INDIGO' => $lang['color_indigo'], |
| 1610 | 'L_COLOR_VIOLET' => $lang['color_violet'], |
| 1611 | 'L_COLOR_WHITE' => $lang['color_white'], |
| 1612 | 'L_COLOR_BLACK' => $lang['color_black'], |
| 1613 | |
| 1614 | 'L_FONT_SIZE' => $lang['Font_size'], |
| 1615 | 'L_FONT_TINY' => $lang['font_tiny'], |
| 1616 | 'L_FONT_SMALL' => $lang['font_small'], |
| 1617 | 'L_FONT_NORMAL' => $lang['font_normal'], |
| 1618 | 'L_FONT_LARGE' => $lang['font_large'], |
| 1619 | 'L_FONT_HUGE' => $lang['font_huge'], |
| 1620 | |
| 1621 | 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'], |
| 1622 | 'L_STYLES_TIP' => $lang['Styles_tip'], |
| 1623 | |
| 1624 | 'S_HTML_CHECKED' => ( !$html_on ) ? ' checked="checked"' : '', |
| 1625 | 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? ' checked="checked"' : '', |
| 1626 | 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? ' checked="checked"' : '', |
| 1627 | 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? ' checked="checked"' : '', |
| 1628 | 'S_NAMES_SELECT' => $user_names_select, |
| 1629 | 'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields, |
| 1630 | 'S_POST_ACTION' => append_sid("privmsg.$phpEx"), |
| 1631 | |
| 1632 | 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser"), |
| 1633 | 'U_VIEW_FORUM' => append_sid("privmsg.$phpEx")) |
| 1634 | ); |
| 1635 | |
| 1636 | $template->pparse('body'); |
| 1637 | |
| 1638 | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 1639 | } |
| 1640 | |
| 1641 | //
|
| 1642 | // Default page
|
| 1643 | //
|
| 1644 | if ( !$userdata['session_logged_in'] ) |
| 1645 | {
|
| 1646 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 1647 | header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true)); |
| 1648 | exit;
|
| 1649 | } |
| 1650 | |
| 1651 | //
|
| 1652 | // Update unread status
|
| 1653 | //
|
| 1654 | $sql = "UPDATE " . USERS_TABLE . " |
| 1655 | SET user_unread_privmsg = user_unread_privmsg + user_new_privmsg, user_new_privmsg = 0, user_last_privmsg = " . $userdata['session_start'] . " |
| 1656 | WHERE user_id = " . $userdata['user_id']; |
| 1657 | if ( !$db->sql_query($sql) ) |
| 1658 | {
|
| 1659 | message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql); |
| 1660 | } |
| 1661 | |
| 1662 | $sql = "UPDATE " . PRIVMSGS_TABLE . " |
| 1663 | SET privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " |
| 1664 | WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1665 | AND privmsgs_to_userid = " . $userdata['user_id']; |
| 1666 | if ( !$db->sql_query($sql) ) |
| 1667 | {
|
| 1668 | message_die(GENERAL_ERROR, 'Could not update private message new/read status (2) for user', '', __LINE__, __FILE__, $sql); |
| 1669 | } |
| 1670 | |
| 1671 | //
|
| 1672 | // Reset PM counters
|
| 1673 | //
|
| 1674 | $userdata['user_new_privmsg'] = 0; |
| 1675 | $userdata['user_unread_privmsg'] = ( $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'] ); |
| 1676 | |
| 1677 | //
|
| 1678 | // Generate page
|
| 1679 | //
|
| 1680 | $page_title = $lang['Private_Messaging']; |
| 1681 | include($phpbb_root_path . 'includes/page_header.'.$phpEx); |
| 1682 | |
| 1683 | //
|
| 1684 | // Load templates
|
| 1685 | //
|
| 1686 | $template->set_filenames(array( |
| 1687 | 'body' => 'privmsgs_body.tpl') |
| 1688 | ); |
| 1689 | make_jumpbox('viewforum.'.$phpEx); |
| 1690 | |
| 1691 | $orig_word = array(); |
| 1692 | $replacement_word = array(); |
| 1693 | obtain_word_list($orig_word, $replacement_word); |
| 1694 | |
| 1695 | //
|
| 1696 | // New message
|
| 1697 | //
|
| 1698 | $post_new_mesg_url = '<a href="' . append_sid("privmsg.$phpEx?mode=post") . '"><img src="' . $images['post_new'] . '" alt="' . $lang['Post_new_message'] . '" border="0" /></a>'; |
| 1699 | |
| 1700 | //
|
| 1701 | // General SQL to obtain messages
|
| 1702 | //
|
| 1703 | $sql_tot = "SELECT COUNT(privmsgs_id) AS total |
| 1704 | FROM " . PRIVMSGS_TABLE . " "; |
| 1705 | $sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username |
| 1706 | FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u "; |
| 1707 | switch( $folder ) |
| 1708 | {
|
| 1709 | case 'inbox': |
| 1710 | $sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . " |
| 1711 | AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1712 | OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 1713 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 1714 | |
| 1715 | $sql .= "WHERE pm.privmsgs_to_userid = " . $userdata['user_id'] . " |
| 1716 | AND u.user_id = pm.privmsgs_from_userid |
| 1717 | AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1718 | OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . " |
| 1719 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 1720 | break;
|
| 1721 | |
| 1722 | case 'outbox': |
| 1723 | $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1724 | AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1725 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 1726 | |
| 1727 | $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1728 | AND u.user_id = pm.privmsgs_to_userid |
| 1729 | AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . " |
| 1730 | OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )"; |
| 1731 | break;
|
| 1732 | |
| 1733 | case 'sentbox': |
| 1734 | $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1735 | AND privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 1736 | |
| 1737 | $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1738 | AND u.user_id = pm.privmsgs_to_userid |
| 1739 | AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL; |
| 1740 | break;
|
| 1741 | |
| 1742 | case 'savebox': |
| 1743 | $sql_tot .= "WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . " |
| 1744 | AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) |
| 1745 | OR ( privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1746 | AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )"; |
| 1747 | |
| 1748 | $sql .= "WHERE ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . " |
| 1749 | AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " |
| 1750 | AND u.user_id = pm.privmsgs_from_userid ) |
| 1751 | OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . " |
| 1752 | AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " |
| 1753 | AND u.user_id = pm.privmsgs_from_userid ) )";
|
| 1754 | break;
|
| 1755 | |
| 1756 | default:
|
| 1757 | message_die(GENERAL_MESSAGE, $lang['No_such_folder']); |
| 1758 | break;
|
| 1759 | } |
| 1760 | |
| 1761 | //
|
| 1762 | // Show messages over previous x days/months
|
| 1763 | //
|
| 1764 | if ( $submit_msgdays && ( !empty($HTTP_POST_VARS['msgdays']) || !empty($HTTP_GET_VARS['msgdays']) ) ) |
| 1765 | {
|
| 1766 | $msg_days = ( !empty($HTTP_POST_VARS['msgdays']) ) ? intval($HTTP_POST_VARS['msgdays']) : intval($HTTP_GET_VARS['msgdays']); |
| 1767 | $min_msg_time = time() - ($msg_days * 86400); |
| 1768 | |
| 1769 | $limit_msg_time_total = " AND privmsgs_date > $min_msg_time"; |
| 1770 | $limit_msg_time = " AND pm.privmsgs_date > $min_msg_time "; |
| 1771 | |
| 1772 | if ( !empty($HTTP_POST_VARS['msgdays']) ) |
| 1773 | {
|
| 1774 | $start = 0; |
| 1775 | } |
| 1776 | } |
| 1777 | else
|
| 1778 | {
|
| 1779 | $limit_msg_time = ''; |
| 1780 | $post_days = 0; |
| 1781 | } |
| 1782 | |
| 1783 | $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $board_config['topics_per_page']; |
| 1784 | $sql_all_tot = $sql_tot; |
| 1785 | $sql_tot .= $limit_msg_time_total; |
| 1786 | |
| 1787 | //
|
| 1788 | // Get messages
|
| 1789 | //
|
| 1790 | if ( !($result = $db->sql_query($sql_tot)) ) |
| 1791 | {
|
| 1792 | message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot); |
| 1793 | } |
| 1794 | |
| 1795 | $pm_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0; |
| 1796 | |
| 1797 | if ( !($result = $db->sql_query($sql_all_tot)) ) |
| 1798 | {
|
| 1799 | message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot); |
| 1800 | } |
| 1801 | |
| 1802 | $pm_all_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0; |
| 1803 | |
| 1804 | //
|
| 1805 | // Build select box
|
| 1806 | //
|
| 1807 | $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364); |
| 1808 | $previous_days_text = array($lang['All_Posts'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']); |
| 1809 | |
| 1810 | $select_msg_days = ''; |
| 1811 | for($i = 0; $i < count($previous_days); $i++) |
| 1812 | {
|
| 1813 | $selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : ''; |
| 1814 | $select_msg_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>'; |
| 1815 | } |
| 1816 | |
| 1817 | //
|
| 1818 | // Define correct icons
|
| 1819 | //
|
| 1820 | switch ( $folder ) |
| 1821 | {
|
| 1822 | case 'inbox': |
| 1823 | $l_box_name = $lang['Inbox']; |
| 1824 | break;
|
| 1825 | case 'outbox': |
| 1826 | $l_box_name = $lang['Outbox']; |
| 1827 | break;
|
| 1828 | case 'savebox': |
| 1829 | $l_box_name = $lang['Savebox']; |
| 1830 | break;
|
| 1831 | case 'sentbox': |
| 1832 | $l_box_name = $lang['Sentbox']; |
| 1833 | break;
|
| 1834 | } |
| 1835 | $post_pm = append_sid("privmsg.$phpEx?mode=post"); |
| 1836 | $post_pm_img = '<a href="' . $post_pm . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0"></a>'; |
| 1837 | $post_pm = '<a href="' . $post_pm . '">' . $lang['Post_new_pm'] . '</a>'; |
| 1838 | |
| 1839 | //
|
| 1840 | // Output data for inbox status
|
| 1841 | //
|
| 1842 | if ( $folder != 'outbox' ) |
| 1843 | {
|
| 1844 | $inbox_limit_pct = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * 100) : 100; |
| 1845 | $inbox_limit_img_length = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * $board_config['privmsg_graphic_length']) : $board_config['privmsg_graphic_length']; |
| 1846 | $inbox_limit_remain = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? $board_config['max_' . $folder . '_privmsgs'] - $pm_all_total : 0; |
| 1847 | |
| 1848 | $template->assign_block_vars('switch_box_size_notice', array()); |
| 1849 | |
| 1850 | switch( $folder ) |
| 1851 | {
|
| 1852 | case 'inbox': |
| 1853 | $l_box_size_status = sprintf($lang['Inbox_size'], $inbox_limit_pct); |
| 1854 | break;
|
| 1855 | case 'sentbox': |
| 1856 | $l_box_size_status = sprintf($lang['Sentbox_size'], $inbox_limit_pct); |
| 1857 | break;
|
| 1858 | case 'savebox': |
| 1859 | $l_box_size_status = sprintf($lang['Savebox_size'], $inbox_limit_pct); |
| 1860 | break;
|
| 1861 | default:
|
| 1862 | $l_box_size_status = ''; |
| 1863 | break;
|
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | //
|
| 1868 | // Dump vars to template
|
| 1869 | //
|
| 1870 | $template->assign_vars(array( |
| 1871 | 'BOX_NAME' => $l_box_name, |
| 1872 | 'INBOX_IMG' => $inbox_img, |
| 1873 | 'SENTBOX_IMG' => $sentbox_img, |
| 1874 | 'OUTBOX_IMG' => $outbox_img, |
| 1875 | 'SAVEBOX_IMG' => $savebox_img, |
| 1876 | 'INBOX' => $inbox_url, |
| 1877 | 'SENTBOX' => $sentbox_url, |
| 1878 | 'OUTBOX' => $outbox_url, |
| 1879 | 'SAVEBOX' => $savebox_url, |
| 1880 | |
| 1881 | 'POST_PM_IMG' => $post_pm_img, |
| 1882 | 'POST_PM' => $post_pm, |
| 1883 | |
| 1884 | 'INBOX_LIMIT_IMG_WIDTH' => $inbox_limit_img_length, |
| 1885 | 'INBOX_LIMIT_PERCENT' => $inbox_limit_pct, |
| 1886 | |
| 1887 | 'BOX_SIZE_STATUS' => $l_box_size_status, |
| 1888 | |
| 1889 | 'L_INBOX' => $lang['Inbox'], |
| 1890 | 'L_OUTBOX' => $lang['Outbox'], |
| 1891 | 'L_SENTBOX' => $lang['Sent'], |
| 1892 | 'L_SAVEBOX' => $lang['Saved'], |
| 1893 | 'L_MARK' => $lang['Mark'], |
| 1894 | 'L_FLAG' => $lang['Flag'], |
| 1895 | 'L_SUBJECT' => $lang['Subject'], |
| 1896 | 'L_DATE' => $lang['Date'], |
| 1897 | 'L_DISPLAY_MESSAGES' => $lang['Display_messages'], |
| 1898 | 'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? $lang['From'] : $lang['To'], |
| 1899 | 'L_MARK_ALL' => $lang['Mark_all'], |
| 1900 | 'L_UNMARK_ALL' => $lang['Unmark_all'], |
| 1901 | 'L_DELETE_MARKED' => $lang['Delete_marked'], |
| 1902 | 'L_DELETE_ALL' => $lang['Delete_all'], |
| 1903 | 'L_SAVE_MARKED' => $lang['Save_marked'], |
| 1904 | |
| 1905 | 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"), |
| 1906 | 'S_HIDDEN_FIELDS' => '', |
| 1907 | 'S_POST_NEW_MSG' => $post_new_mesg_url, |
| 1908 | 'S_SELECT_MSG_DAYS' => $select_msg_days, |
| 1909 | |
| 1910 | 'U_POST_NEW_TOPIC' => $post_new_topic_url) |
| 1911 | ); |
| 1912 | |
| 1913 | //
|
| 1914 | // Okay, let's build the correct folder
|
| 1915 | //
|
| 1916 | if ( !($result = $db->sql_query($sql)) ) |
| 1917 | {
|
| 1918 | message_die(GENERAL_ERROR, 'Could not query private messages', '', __LINE__, __FILE__, $sql); |
| 1919 | } |
| 1920 | |
| 1921 | if ( $row = $db->sql_fetchrow($result) ) |
| 1922 | {
|
| 1923 | do
|
| 1924 | {
|
| 1925 | $privmsg_id = $row['privmsgs_id']; |
| 1926 | |
| 1927 | $flag = $row['privmsgs_type']; |
| 1928 | |
| 1929 | $icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg']; |
| 1930 | $icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $lang['Unread_message'] : $lang['Read_message']; |
| 1931 | |
| 1932 | $msg_userid = $row['user_id']; |
| 1933 | $msg_username = $row['username']; |
| 1934 | |
| 1935 | $u_from_user_profile = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$msg_userid"); |
| 1936 | |
| 1937 | $msg_subject = $row['privmsgs_subject']; |
| 1938 | |
| 1939 | if ( count($orig_word) ) |
| 1940 | {
|
| 1941 | $msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject); |
| 1942 | } |
| 1943 | |
| 1944 | $u_subject = append_sid("privmsg.$phpEx?folder=$folder&mode=read&" . POST_POST_URL . "=$privmsg_id"); |
| 1945 | |
| 1946 | $msg_date = create_date($board_config['default_dateformat'], $row['privmsgs_date'], $board_config['board_timezone']); |
| 1947 | |
| 1948 | if ( $flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox' ) |
| 1949 | {
|
| 1950 | $msg_subject = '<b>' . $msg_subject . '</b>'; |
| 1951 | $msg_date = '<b>' . $msg_date . '</b>'; |
| 1952 | $msg_username = '<b>' . $msg_username . '</b>'; |
| 1953 | } |
| 1954 | |
| 1955 | $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2']; |
| 1956 | $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2']; |
| 1957 | |
| 1958 | $template->assign_block_vars('listrow', array( |
| 1959 | 'ROW_COLOR' => '#' . $row_color, |
| 1960 | 'ROW_CLASS' => $row_class, |
| 1961 | 'FROM' => $msg_username, |
| 1962 | 'SUBJECT' => $msg_subject, |
| 1963 | 'DATE' => $msg_date, |
| 1964 | 'PRIVMSG_FOLDER_IMG' => $icon_flag, |
| 1965 | |
| 1966 | 'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt, |
| 1967 | |
| 1968 | 'S_MARK_ID' => $privmsg_id, |
| 1969 | |
| 1970 | 'U_READ' => $u_subject, |
| 1971 | 'U_FROM_USER_PROFILE' => $u_from_user_profile) |
| 1972 | ); |
| 1973 | } |
| 1974 | while( $row = $db->sql_fetchrow($result) ); |
| 1975 | |
| 1976 | $template->assign_vars(array( |
| 1977 | 'PAGINATION' => generate_pagination("privmsg.$phpEx?folder=$folder", $pm_total, $board_config['topics_per_page'], $start), |
| 1978 | 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $pm_total / $board_config['topics_per_page'] )), |
| 1979 | |
| 1980 | 'L_GOTO_PAGE' => $lang['Goto_page']) |
| 1981 | ); |
| 1982 | |
| 1983 | } |
| 1984 | else
|
| 1985 | {
|
| 1986 | $template->assign_vars(array( |
| 1987 | 'L_NO_MESSAGES' => $lang['No_messages_folder']) |
| 1988 | ); |
| 1989 | |
| 1990 | $template->assign_block_vars("switch_no_messages", array() ); |
| 1991 | } |
| 1992 | |
| 1993 | $template->pparse('body'); |
| 1994 | |
| 1995 | include($phpbb_root_path . 'includes/page_tail.'.$phpEx); |
| 1996 | |
| 1997 | ?> |

