2 /***************************************************************************
5 * begin : Saturday, Jun 9, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: privmsg.php,v 1.96.2.50 2006/12/16 13:11:25 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
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.
21 ***************************************************************************/
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);
33 if ( !empty($board_config['privmsg_disable']) )
35 message_die(GENERAL_MESSAGE, 'PM_disabled');
38 $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#');
39 $html_entities_replace = array('&', '<', '>', '"');
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 $sid = (isset($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : 0;
55 $refresh = $preview || $submit_search;
57 $mark_list = ( !empty($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : 0;
59 if ( isset($HTTP_POST_VARS['folder']) || isset($HTTP_GET_VARS['folder']) )
61 $folder = ( isset($HTTP_POST_VARS['folder']) ) ? $HTTP_POST_VARS['folder'] : $HTTP_GET_VARS['folder'];
62 $folder = htmlspecialchars($folder);
64 if ( $folder != 'inbox' && $folder != 'outbox' && $folder != 'sentbox' && $folder != 'savebox' )
75 // Start session management
77 $userdata = session_pagestart($user_ip, PAGE_PRIVMSGS);
78 init_userprefs($userdata);
80 // End session management
88 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
94 if ( !empty($HTTP_POST_VARS['mode']) || !empty($HTTP_GET_VARS['mode']) )
96 $mode = ( !empty($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
97 $mode = htmlspecialchars($mode);
104 $start = ( !empty($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
105 $start = ($start < 0) ? 0 : $start;
107 if ( isset($HTTP_POST_VARS[POST_POST_URL]) || isset($HTTP_GET_VARS[POST_POST_URL]) )
109 $privmsg_id = ( isset($HTTP_POST_VARS[POST_POST_URL]) ) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
119 // Define the box image links
121 $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'] . '" />';
122 $inbox_url = ( $folder != 'inbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '">' . $lang['Inbox'] . '</a>' : $lang['Inbox'];
124 $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'] . '" />';
125 $outbox_url = ( $folder != 'outbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=outbox") . '">' . $lang['Outbox'] . '</a>' : $lang['Outbox'];
127 $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'] . '" />';
128 $sentbox_url = ( $folder != 'sentbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=sentbox") . '">' . $lang['Sentbox'] . '</a>' : $lang['Sentbox'];
130 $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'] . '" />';
131 $savebox_url = ( $folder != 'savebox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=savebox") . '">' . $lang['Savebox'] . '</a>' : $lang['Savebox'];
136 if ( $mode == 'newpm' )
138 $gen_simple_header = TRUE;
140 $page_title = $lang['Private_Messaging'];
141 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
143 $template->set_filenames(array(
144 'body' => 'privmsgs_popup.tpl')
147 if ( $userdata['session_logged_in'] )
149 if ( $userdata['user_new_privmsg'] )
151 $l_new_message = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['You_new_pm'] : $lang['You_new_pms'];
155 $l_new_message = $lang['You_no_new_pm'];
158 $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>');
162 $l_new_message = $lang['Login_check_pm'];
165 $template->assign_vars(array(
166 'L_CLOSE_WINDOW' => $lang['Close_window'],
167 'L_MESSAGE' => $l_new_message)
170 $template->pparse('body');
172 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
175 else if ( $mode == 'read' )
177 if ( !empty($HTTP_GET_VARS[POST_POST_URL]) )
179 $privmsgs_id = intval($HTTP_GET_VARS[POST_POST_URL]);
183 message_die(GENERAL_ERROR, $lang['No_post_id']);
186 if ( !$userdata['session_logged_in'] )
188 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode&" . POST_POST_URL . "=$privmsgs_id", true));
192 // SQL to pull appropriate message, prevents nosey people
193 // reading other peoples messages ... hopefully!
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 . " )";
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 . " ) ";
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;
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 . " )
224 message_die(GENERAL_ERROR, $lang['No_such_folder']);
229 // Major query obtains the message ...
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
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)) )
240 message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql);
244 // Did the query return any data?
246 if ( !($privmsg = $db->sql_fetchrow($result)) )
248 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
251 $privmsg_id = $privmsg['privmsgs_id'];
254 // Is this a new message in the inbox? If it is then save
255 // a copy in the posters sent box
257 if (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL) && $folder == 'inbox')
259 // Update appropriate counter
260 switch ($privmsg['privmsgs_type'])
262 case PRIVMSGS_NEW_MAIL:
263 $sql = "user_new_privmsg = user_new_privmsg - 1";
265 case PRIVMSGS_UNREAD_MAIL:
266 $sql = "user_unread_privmsg = user_unread_privmsg - 1";
270 $sql = "UPDATE " . USERS_TABLE . "
272 WHERE user_id = " . $userdata['user_id'];
273 if ( !$db->sql_query($sql) )
275 message_die(GENERAL_ERROR, 'Could not update private message read status for user', '', __LINE__, __FILE__, $sql);
278 $sql = "UPDATE " . PRIVMSGS_TABLE . "
279 SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
280 WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
281 if ( !$db->sql_query($sql) )
283 message_die(GENERAL_ERROR, 'Could not update private message read status', '', __LINE__, __FILE__, $sql);
286 // Check to see if the poster has a 'full' sent box
287 $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time
288 FROM " . PRIVMSGS_TABLE . "
289 WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
290 AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
291 if ( !($result = $db->sql_query($sql)) )
293 message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
296 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
298 if ( $sent_info = $db->sql_fetchrow($result) )
300 if ($board_config['max_sentbox_privmsgs'] && $sent_info['sent_items'] >= $board_config['max_sentbox_privmsgs'])
302 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
303 WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
304 AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
305 AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
306 if ( !$result = $db->sql_query($sql) )
308 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs', '', __LINE__, __FILE__, $sql);
310 $old_privmsgs_id = $db->sql_fetchrow($result);
311 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
313 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
314 WHERE privmsgs_id = $old_privmsgs_id";
315 if ( !$db->sql_query($sql) )
317 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (sent)', '', __LINE__, __FILE__, $sql);
320 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
321 WHERE privmsgs_text_id = $old_privmsgs_id";
322 if ( !$db->sql_query($sql) )
324 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (sent)', '', __LINE__, __FILE__, $sql);
330 // This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
331 // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
332 // set limits on numbers of storable posts for users ... hopefully!
334 $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)
335 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'] . ")";
336 if ( !$db->sql_query($sql) )
338 message_die(GENERAL_ERROR, 'Could not insert private message sent info', '', __LINE__, __FILE__, $sql);
341 $privmsg_sent_id = $db->sql_nextid();
343 $sql = "INSERT $sql_priority INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
344 VALUES ($privmsg_sent_id, '" . $privmsg['privmsgs_bbcode_uid'] . "', '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_text'])) . "')";
345 if ( !$db->sql_query($sql) )
347 message_die(GENERAL_ERROR, 'Could not insert private message sent text', '', __LINE__, __FILE__, $sql);
352 // Pick a folder, any folder, so long as it's one below ...
355 'post' => append_sid("privmsg.$phpEx?mode=post"),
356 'reply' => append_sid("privmsg.$phpEx?mode=reply&" . POST_POST_URL . "=$privmsg_id"),
357 'quote' => append_sid("privmsg.$phpEx?mode=quote&" . POST_POST_URL . "=$privmsg_id"),
358 'edit' => append_sid("privmsg.$phpEx?mode=edit&" . POST_POST_URL . "=$privmsg_id")
361 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0" /></a>',
362 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['Post_new_pm'] . '</a>',
363 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['Post_reply_pm'] . '" border="0" /></a>',
364 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['Post_reply_pm'] . '</a>',
365 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['Post_quote_pm'] . '" border="0" /></a>',
366 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['Post_quote_pm'] . '</a>',
367 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['Edit_pm'] . '" border="0" /></a>',
368 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['Edit_pm'] . '</a>'
371 if ( $folder == 'inbox' )
373 $post_img = $post_icons['post_img'];
374 $reply_img = $post_icons['reply_img'];
375 $quote_img = $post_icons['quote_img'];
377 $post = $post_icons['post'];
378 $reply = $post_icons['reply'];
379 $quote = $post_icons['quote'];
381 $l_box_name = $lang['Inbox'];
383 else if ( $folder == 'outbox' )
385 $post_img = $post_icons['post_img'];
388 $edit_img = $post_icons['edit_img'];
389 $post = $post_icons['post'];
392 $edit = $post_icons['edit'];
393 $l_box_name = $lang['Outbox'];
395 else if ( $folder == 'savebox' )
397 if ( $privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL )
399 $post_img = $post_icons['post_img'];
400 $reply_img = $post_icons['reply_img'];
401 $quote_img = $post_icons['quote_img'];
403 $post = $post_icons['post'];
404 $reply = $post_icons['reply'];
405 $quote = $post_icons['quote'];
410 $post_img = $post_icons['post_img'];
414 $post = $post_icons['post'];
419 $l_box_name = $lang['Saved'];
421 else if ( $folder == 'sentbox' )
423 $post_img = $post_icons['post_img'];
427 $post = $post_icons['post'];
431 $l_box_name = $lang['Sent'];
434 $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />';
436 $page_title = $lang['Read_pm'];
437 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
442 $template->set_filenames(array(
443 'body' => 'privmsgs_read_body.tpl')
445 make_jumpbox('viewforum.'.$phpEx);
447 $template->assign_vars(array(
448 'INBOX_IMG' => $inbox_img,
449 'SENTBOX_IMG' => $sentbox_img,
450 'OUTBOX_IMG' => $outbox_img,
451 'SAVEBOX_IMG' => $savebox_img,
452 'INBOX' => $inbox_url,
454 'POST_PM_IMG' => $post_img,
455 'REPLY_PM_IMG' => $reply_img,
456 'EDIT_PM_IMG' => $edit_img,
457 'QUOTE_PM_IMG' => $quote_img,
459 'REPLY_PM' => $reply,
461 'QUOTE_PM' => $quote,
463 'SENTBOX' => $sentbox_url,
464 'OUTBOX' => $outbox_url,
465 'SAVEBOX' => $savebox_url,
467 'BOX_NAME' => $l_box_name,
469 'L_MESSAGE' => $lang['Message'],
470 'L_INBOX' => $lang['Inbox'],
471 'L_OUTBOX' => $lang['Outbox'],
472 'L_SENTBOX' => $lang['Sent'],
473 'L_SAVEBOX' => $lang['Saved'],
474 'L_FLAG' => $lang['Flag'],
475 'L_SUBJECT' => $lang['Subject'],
476 'L_POSTED' => $lang['Posted'],
477 'L_DATE' => $lang['Date'],
478 'L_FROM' => $lang['From'],
479 'L_TO' => $lang['To'],
480 'L_SAVE_MSG' => $lang['Save_message'],
481 'L_DELETE_MSG' => $lang['Delete_message'],
483 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
484 'S_HIDDEN_FIELDS' => $s_hidden_fields)
487 $username_from = $privmsg['username_1'];
488 $user_id_from = $privmsg['user_id_1'];
489 $username_to = $privmsg['username_2'];
490 $user_id_to = $privmsg['user_id_2'];
492 $post_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
494 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $user_id_from);
495 $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
496 $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
498 $temp_url = append_sid("privmsg.$phpEx?mode=post&" . POST_USERS_URL . "=$user_id_from");
499 $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
500 $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
502 if ( !empty($privmsg['user_viewemail']) || $userdata['user_level'] == ADMIN )
504 $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&" . POST_USERS_URL .'=' . $user_id_from) : 'mailto:' . $privmsg['user_email'];
506 $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
507 $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
515 $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>' : '';
516 $www = ( $privmsg['user_website'] ) ? '<a href="' . $privmsg['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
518 if ( !empty($privmsg['user_icq']) )
520 $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>';
521 $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>';
522 $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $privmsg['user_icq'] . '">' . $lang['ICQ'] . '</a>';
526 $icq_status_img = '';
531 $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>' : '';
532 $aim = ( $privmsg['user_aim'] ) ? '<a href="aim:goim?screenname=' . $privmsg['user_aim'] . '&message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
534 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id_from");
535 $msn_img = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
536 $msn = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
538 $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>' : '';
539 $yim = ( $privmsg['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $privmsg['user_yim'] . '&.src=pg">' . $lang['YIM'] . '</a>' : '';
541 $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($username_from) . "&showresults=posts");
542 $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . sprintf($lang['Search_user_posts'], $username_from) . '" title="' . sprintf($lang['Search_user_posts'], $username_from) . '" border="0" /></a>';
543 $search = '<a href="' . $temp_url . '">' . sprintf($lang['Search_user_posts'], $username_from) . '</a>';
546 // Processing of post
548 $post_subject = $privmsg['privmsgs_subject'];
550 $private_message = $privmsg['privmsgs_text'];
551 $bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
553 if ( $board_config['allow_sig'] )
555 $user_sig = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig'] : $privmsg['user_sig'];
562 $user_sig_bbcode_uid = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig_bbcode_uid'] : $privmsg['user_sig_bbcode_uid'];
565 // If the board has HTML off but the post has HTML
566 // on then we process it, else leave it alone
568 if ( !$board_config['allow_html'] || !$userdata['user_allowhtml'])
570 if ( $user_sig != '')
572 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
575 if ( $privmsg['privmsgs_enable_html'] )
577 $private_message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $private_message);
581 if ( $user_sig != '' && $privmsg['privmsgs_attach_sig'] && $user_sig_bbcode_uid != '' )
583 $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
586 if ( $bbcode_uid != '' )
588 $private_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($private_message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $private_message);
591 $private_message = make_clickable($private_message);
593 if ( $privmsg['privmsgs_attach_sig'] && $user_sig != '' )
595 $private_message .= '<br /><br />_________________<br />' . make_clickable($user_sig);
598 $orig_word = array();
599 $replacement_word = array();
600 obtain_word_list($orig_word, $replacement_word);
602 if ( count($orig_word) )
604 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
605 $private_message = preg_replace($orig_word, $replacement_word, $private_message);
608 if ( $board_config['allow_smilies'] && $privmsg['privmsgs_enable_smilies'] )
610 $private_message = smilies_pass($private_message);
613 $private_message = str_replace("\n", '<br />', $private_message);
616 // Dump it to the templating engine
618 $template->assign_vars(array(
619 'MESSAGE_TO' => $username_to,
620 'MESSAGE_FROM' => $username_from,
621 'RANK_IMAGE' => $rank_image,
622 'POSTER_JOINED' => $poster_joined,
623 'POSTER_POSTS' => $poster_posts,
624 'POSTER_FROM' => $poster_from,
625 'POSTER_AVATAR' => $poster_avatar,
626 'POST_SUBJECT' => $post_subject,
627 'POST_DATE' => $post_date,
628 'MESSAGE' => $private_message,
630 'PROFILE_IMG' => $profile_img,
631 'PROFILE' => $profile,
632 'SEARCH_IMG' => $search_img,
634 'EMAIL_IMG' => $email_img,
636 'WWW_IMG' => $www_img,
638 'ICQ_STATUS_IMG' => $icq_status_img,
639 'ICQ_IMG' => $icq_img,
641 'AIM_IMG' => $aim_img,
643 'MSN_IMG' => $msn_img,
645 'YIM_IMG' => $yim_img,
649 $template->pparse('body');
651 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
654 else if ( ( $delete && $mark_list ) || $delete_all )
656 if ( !$userdata['session_logged_in'] )
658 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
661 if ( isset($mark_list) && !is_array($mark_list) )
663 // Set to empty array instead of '0' if nothing is selected.
664 $mark_list = array();
669 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
670 $s_hidden_fields .= ( isset($HTTP_POST_VARS['delete']) ) ? '<input type="hidden" name="delete" value="true" />' : '<input type="hidden" name="deleteall" value="true" />';
672 for($i = 0; $i < count($mark_list); $i++)
674 $s_hidden_fields .= '<input type="hidden" name="mark[]" value="' . intval($mark_list[$i]) . '" />';
678 // Output confirmation page
680 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
682 $template->set_filenames(array(
683 'confirm_body' => 'confirm_body.tpl')
685 $template->assign_vars(array(
686 'MESSAGE_TITLE' => $lang['Information'],
687 'MESSAGE_TEXT' => ( count($mark_list) == 1 ) ? $lang['Confirm_delete_pm'] : $lang['Confirm_delete_pms'],
689 'L_YES' => $lang['Yes'],
690 'L_NO' => $lang['No'],
692 'S_CONFIRM_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
693 'S_HIDDEN_FIELDS' => $s_hidden_fields)
696 $template->pparse('confirm_body');
698 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
707 for ($i = 0; $i < count($mark_list); $i++)
709 $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
711 $delete_sql_id = "AND privmsgs_id IN ($delete_sql_id)";
717 $delete_type = "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
718 privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
722 $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
726 $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
730 $delete_type = "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
731 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
732 OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
733 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
737 $sql = "SELECT privmsgs_id
738 FROM " . PRIVMSGS_TABLE . "
739 WHERE $delete_type $delete_sql_id";
741 if ( !($result = $db->sql_query($sql)) )
743 message_die(GENERAL_ERROR, 'Could not obtain id list to delete messages', '', __LINE__, __FILE__, $sql);
746 $mark_list = array();
747 while ( $row = $db->sql_fetchrow($result) )
749 $mark_list[] = $row['privmsgs_id'];
754 if ( count($mark_list) )
757 for ($i = 0; $i < sizeof($mark_list); $i++)
759 $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
762 if ($folder == 'inbox' || $folder == 'outbox')
767 $sql = "privmsgs_to_userid = " . $userdata['user_id'];
770 $sql = "privmsgs_from_userid = " . $userdata['user_id'];
774 // Get information relevant to new or unread mail
775 // so we can adjust users counters appropriately
776 $sql = "SELECT privmsgs_to_userid, privmsgs_type
777 FROM " . PRIVMSGS_TABLE . "
778 WHERE privmsgs_id IN ($delete_sql_id)
780 AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
781 if ( !($result = $db->sql_query($sql)) )
783 message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
786 if ( $row = $db->sql_fetchrow($result))
788 $update_users = $update_list = array();
792 switch ($row['privmsgs_type'])
794 case PRIVMSGS_NEW_MAIL:
795 $update_users['new'][$row['privmsgs_to_userid']]++;
798 case PRIVMSGS_UNREAD_MAIL:
799 $update_users['unread'][$row['privmsgs_to_userid']]++;
803 while ($row = $db->sql_fetchrow($result));
805 if (sizeof($update_users))
807 while (list($type, $users) = each($update_users))
809 while (list($user_id, $dec) = each($users))
811 $update_list[$type][$dec][] = $user_id;
814 unset($update_users);
816 while (list($type, $dec_ary) = each($update_list))
821 $type = "user_new_privmsg";
825 $type = "user_unread_privmsg";
829 while (list($dec, $user_ary) = each($dec_ary))
831 $user_ids = implode(', ', $user_ary);
833 $sql = "UPDATE " . USERS_TABLE . "
834 SET $type = $type - $dec
835 WHERE user_id IN ($user_ids)";
836 if ( !$db->sql_query($sql) )
838 message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
845 $db->sql_freeresult($result);
848 // Delete the messages
849 $delete_text_sql = "DELETE FROM " . PRIVMSGS_TEXT_TABLE . "
850 WHERE privmsgs_text_id IN ($delete_sql_id)";
851 $delete_sql = "DELETE FROM " . PRIVMSGS_TABLE . "
852 WHERE privmsgs_id IN ($delete_sql_id)
858 $delete_sql .= "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
859 privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
863 $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND (
864 privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
868 $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
872 $delete_sql .= "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
873 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
874 OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
875 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
879 if ( !$db->sql_query($delete_sql, BEGIN_TRANSACTION) )
881 message_die(GENERAL_ERROR, 'Could not delete private message info', '', __LINE__, __FILE__, $delete_sql);
884 if ( !$db->sql_query($delete_text_sql, END_TRANSACTION) )
886 message_die(GENERAL_ERROR, 'Could not delete private message text', '', __LINE__, __FILE__, $delete_text_sql);
891 else if ( $save && $mark_list && $folder != 'savebox' && $folder != 'outbox' )
893 if ( !$userdata['session_logged_in'] )
895 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
898 if (sizeof($mark_list))
900 // See if recipient is at their savebox limit
901 $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time
902 FROM " . PRIVMSGS_TABLE . "
903 WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
904 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
905 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
906 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
907 if ( !($result = $db->sql_query($sql)) )
909 message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
912 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
914 if ( $saved_info = $db->sql_fetchrow($result) )
916 if ($board_config['max_savebox_privmsgs'] && $saved_info['savebox_items'] >= $board_config['max_savebox_privmsgs'] )
918 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
919 WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
920 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
921 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
922 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )
923 AND privmsgs_date = " . $saved_info['oldest_post_time'];
924 if ( !$result = $db->sql_query($sql) )
926 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
928 $old_privmsgs_id = $db->sql_fetchrow($result);
929 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
931 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
932 WHERE privmsgs_id = $old_privmsgs_id";
933 if ( !$db->sql_query($sql) )
935 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
938 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
939 WHERE privmsgs_text_id = $old_privmsgs_id";
940 if ( !$db->sql_query($sql) )
942 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (save)', '', __LINE__, __FILE__, $sql);
948 for ($i = 0; $i < sizeof($mark_list); $i++)
950 $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
954 $saved_sql = "UPDATE " . PRIVMSGS_TABLE;
956 // Decrement read/new counters if appropriate
957 if ($folder == 'inbox' || $folder == 'outbox')
962 $sql = "privmsgs_to_userid = " . $userdata['user_id'];
965 $sql = "privmsgs_from_userid = " . $userdata['user_id'];
969 // Get information relevant to new or unread mail
970 // so we can adjust users counters appropriately
971 $sql = "SELECT privmsgs_to_userid, privmsgs_type
972 FROM " . PRIVMSGS_TABLE . "
973 WHERE privmsgs_id IN ($saved_sql_id)
975 AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
976 if ( !($result = $db->sql_query($sql)) )
978 message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
981 if ( $row = $db->sql_fetchrow($result))
983 $update_users = $update_list = array();
987 switch ($row['privmsgs_type'])
989 case PRIVMSGS_NEW_MAIL:
990 $update_users['new'][$row['privmsgs_to_userid']]++;
993 case PRIVMSGS_UNREAD_MAIL:
994 $update_users['unread'][$row['privmsgs_to_userid']]++;
998 while ($row = $db->sql_fetchrow($result));
1000 if (sizeof($update_users))
1002 while (list($type, $users) = each($update_users))
1004 while (list($user_id, $dec) = each($users))
1006 $update_list[$type][$dec][] = $user_id;
1009 unset($update_users);
1011 while (list($type, $dec_ary) = each($update_list))
1016 $type = "user_new_privmsg";
1020 $type = "user_unread_privmsg";
1024 while (list($dec, $user_ary) = each($dec_ary))
1026 $user_ids = implode(', ', $user_ary);
1028 $sql = "UPDATE " . USERS_TABLE . "
1029 SET $type = $type - $dec
1030 WHERE user_id IN ($user_ids)";
1031 if ( !$db->sql_query($sql) )
1033 message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
1037 unset($update_list);
1040 $db->sql_freeresult($result);
1046 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
1047 WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
1048 AND ( privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1049 OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1050 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
1054 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
1055 WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1056 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1057 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
1061 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
1062 WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1063 AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1067 $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
1069 if ( !$db->sql_query($saved_sql) )
1071 message_die(GENERAL_ERROR, 'Could not save private messages', '', __LINE__, __FILE__, $saved_sql);
1074 redirect(append_sid("privmsg.$phpEx?folder=savebox", true));
1077 else if ( $submit || $refresh || $mode != '' )
1079 if ( !$userdata['session_logged_in'] )
1081 $user_id = ( isset($HTTP_GET_VARS[POST_USERS_URL]) ) ? '&' . POST_USERS_URL . '=' . intval($HTTP_GET_VARS[POST_USERS_URL]) : '';
1082 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode" . $user_id, true));
1088 if ( !$board_config['allow_html'] )
1094 $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : $userdata['user_allowhtml'];
1097 if ( !$board_config['allow_bbcode'] )
1103 $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : $userdata['user_allowbbcode'];
1106 if ( !$board_config['allow_smilies'] )
1112 $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : $userdata['user_allowsmile'];
1115 $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : $userdata['user_attachsig'];
1116 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : "";
1118 if ( $submit && $mode != 'edit' )
1123 $sql = "SELECT MAX(privmsgs_date) AS last_post_time
1124 FROM " . PRIVMSGS_TABLE . "
1125 WHERE privmsgs_from_userid = " . $userdata['user_id'];
1126 if ( $result = $db->sql_query($sql) )
1128 $db_row = $db->sql_fetchrow($result);
1130 $last_post_time = $db_row['last_post_time'];
1131 $current_time = time();
1133 if ( ( $current_time - $last_post_time ) < $board_config['flood_interval'])
1135 message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
1139 // End Flood control
1143 if ($submit && $mode == 'edit')
1145 $sql = 'SELECT privmsgs_from_userid
1146 FROM ' . PRIVMSGS_TABLE . '
1147 WHERE privmsgs_id = ' . (int) $privmsg_id . '
1148 AND privmsgs_from_userid = ' . $userdata['user_id'];
1150 if (!($result = $db->sql_query($sql)))
1152 message_die(GENERAL_ERROR, "Could not obtain message details", "", __LINE__, __FILE__, $sql);
1155 if (!($row = $db->sql_fetchrow($result)))
1157 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
1159 $db->sql_freeresult($result);
1167 if ($sid == '' || $sid != $userdata['session_id'])
1170 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Session_invalid'];
1173 if ( !empty($HTTP_POST_VARS['username']) )
1175 $to_username = phpbb_clean_username($HTTP_POST_VARS['username']);
1177 $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active
1178 FROM " . USERS_TABLE . "
1179 WHERE username = '" . str_replace("\'", "''", $to_username) . "'
1180 AND user_id <> " . ANONYMOUS;
1181 if ( !($result = $db->sql_query($sql)) )
1184 $error_msg = $lang['No_such_user'];
1187 if (!($to_userdata = $db->sql_fetchrow($result)))
1190 $error_msg = $lang['No_such_user'];
1196 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['No_to_user'];
1199 $privmsg_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
1200 if ( empty($privmsg_subject) )
1203 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject'];
1206 if ( !empty($HTTP_POST_VARS['message']) )
1212 $bbcode_uid = make_bbcode_uid();
1215 $privmsg_message = prepare_message($HTTP_POST_VARS['message'], $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
1222 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message'];
1226 if ( $submit && !$error )
1229 // Has admin prevented user from sending PM's?
1231 if ( !$userdata['user_allow_pm'] )
1233 $message = $lang['Cannot_send_privmsg'];
1234 message_die(GENERAL_MESSAGE, $message);
1239 if ( $mode != 'edit' )
1242 // See if recipient is at their inbox limit
1244 $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
1245 FROM " . PRIVMSGS_TABLE . "
1246 WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1247 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1248 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1249 AND privmsgs_to_userid = " . $to_userdata['user_id'];
1250 if ( !($result = $db->sql_query($sql)) )
1252 message_die(GENERAL_MESSAGE, $lang['No_such_user']);
1255 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
1257 if ( $inbox_info = $db->sql_fetchrow($result) )
1259 if ($board_config['max_inbox_privmsgs'] && $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'])
1261 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
1262 WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1263 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1264 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1265 AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
1266 AND privmsgs_to_userid = " . $to_userdata['user_id'];
1267 if ( !$result = $db->sql_query($sql) )
1269 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (inbox)', '', __LINE__, __FILE__, $sql);
1271 $old_privmsgs_id = $db->sql_fetchrow($result);
1272 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
1274 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
1275 WHERE privmsgs_id = $old_privmsgs_id";
1276 if ( !$db->sql_query($sql) )
1278 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (inbox)'.$sql, '', __LINE__, __FILE__, $sql);
1281 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
1282 WHERE privmsgs_text_id = $old_privmsgs_id";
1283 if ( !$db->sql_query($sql) )
1285 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (inbox)', '', __LINE__, __FILE__, $sql);
1290 $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)
1291 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)";
1295 $sql_info = "UPDATE " . PRIVMSGS_TABLE . "
1296 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
1297 WHERE privmsgs_id = $privmsg_id";
1300 if ( !($result = $db->sql_query($sql_info, BEGIN_TRANSACTION)) )
1302 message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info);
1305 if ( $mode != 'edit' )
1307 $privmsg_sent_id = $db->sql_nextid();
1309 $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
1310 VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')";
1314 $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . "
1315 SET privmsgs_text = '" . str_replace("\'", "''", $privmsg_message) . "', privmsgs_bbcode_uid = '$bbcode_uid'
1316 WHERE privmsgs_text_id = $privmsg_id";
1319 if ( !$db->sql_query($sql, END_TRANSACTION) )
1321 message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql);
1324 if ( $mode != 'edit' )
1327 // Add to the users new pm counter
1329 $sql = "UPDATE " . USERS_TABLE . "
1330 SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . "
1331 WHERE user_id = " . $to_userdata['user_id'];
1332 if ( !$status = $db->sql_query($sql) )
1334 message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
1337 if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] )
1339 $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path']));
1340 $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx;
1341 $server_name = trim($board_config['server_name']);
1342 $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
1343 $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
1345 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
1346 $emailer = new emailer($board_config['smtp_delivery']);
1348 $emailer->from($board_config['board_email']);
1349 $emailer->replyto($board_config['board_email']);
1351 $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
1352 $emailer->email_address($to_userdata['user_email']);
1353 $emailer->set_subject($lang['Notification_subject']);
1355 $emailer->assign_vars(array(
1356 'USERNAME' => stripslashes($to_username),
1357 'SITENAME' => $board_config['sitename'],
1358 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
1360 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox')
1368 $template->assign_vars(array(
1369 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("privmsg.$phpEx?folder=inbox") . '">')
1372 $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>');
1374 message_die(GENERAL_MESSAGE, $msg);
1376 else if ( $preview || $refresh || $error )
1380 // If we're previewing or refreshing then obtain the data
1381 // passed to the script, process it a little, do some checks
1382 // where neccessary, etc.
1384 $to_username = (isset($HTTP_POST_VARS['username']) ) ? trim(htmlspecialchars(stripslashes($HTTP_POST_VARS['username']))) : '';
1386 $privmsg_subject = ( isset($HTTP_POST_VARS['subject']) ) ? trim(htmlspecialchars(stripslashes($HTTP_POST_VARS['subject']))) : '';
1387 $privmsg_message = ( isset($HTTP_POST_VARS['message']) ) ? trim($HTTP_POST_VARS['message']) : '';
1388 // $privmsg_message = preg_replace('#<textarea>#si', '<textarea>', $privmsg_message);
1391 $privmsg_message = stripslashes($privmsg_message);
1395 // Do mode specific things
1397 if ( $mode == 'post' )
1399 $page_title = $lang['Post_new_pm'];
1401 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
1404 else if ( $mode == 'reply' )
1406 $page_title = $lang['Post_reply_pm'];
1408 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
1411 else if ( $mode == 'edit' )
1413 $page_title = $lang['Edit_pm'];
1415 $sql = "SELECT u.user_id, u.user_sig
1416 FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u
1417 WHERE pm.privmsgs_id = $privmsg_id
1418 AND u.user_id = pm.privmsgs_from_userid";
1419 if ( !($result = $db->sql_query($sql)) )
1421 message_die(GENERAL_ERROR, "Could not obtain post and post text", "", __LINE__, __FILE__, $sql);
1424 if ( $postrow = $db->sql_fetchrow($result) )
1426 if ( $userdata['user_id'] != $postrow['user_id'] )
1428 message_die(GENERAL_MESSAGE, $lang['Edit_own_posts']);
1431 $user_sig = ( $postrow['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow['user_sig'] : '';
1437 if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) )
1439 message_die(GENERAL_ERROR, $lang['No_post_id']);
1442 if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) )
1444 $user_id = intval($HTTP_GET_VARS[POST_USERS_URL]);
1446 $sql = "SELECT username
1447 FROM " . USERS_TABLE . "
1448 WHERE user_id = $user_id
1449 AND user_id <> " . ANONYMOUS;
1450 if ( !($result = $db->sql_query($sql)) )
1453 $error_msg = $lang['No_such_user'];
1456 if ( $row = $db->sql_fetchrow($result) )
1458 $to_username = $row['username'];
1461 else if ( $mode == 'edit' )
1463 $sql = "SELECT pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id, u.user_sig
1464 FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
1465 WHERE pm.privmsgs_id = $privmsg_id
1466 AND pmt.privmsgs_text_id = pm.privmsgs_id
1467 AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1468 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1469 OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1470 AND u.user_id = pm.privmsgs_to_userid";
1471 if ( !($result = $db->sql_query($sql)) )
1473 message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
1476 if ( !($privmsg = $db->sql_fetchrow($result)) )
1478 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
1481 $privmsg_subject = $privmsg['privmsgs_subject'];
1482 $privmsg_message = $privmsg['privmsgs_text'];
1483 $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
1484 $privmsg_bbcode_enabled = ($privmsg['privmsgs_enable_bbcode'] == 1);
1486 if ( $privmsg_bbcode_enabled )
1488 $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
1491 $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
1492 // $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message);
1494 $user_sig = ( $board_config['allow_sig'] ) ? (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL) ? $user_sig : $privmsg['user_sig']) : '';
1496 $to_username = $privmsg['username'];
1497 $to_userid = $privmsg['user_id'];
1500 else if ( $mode == 'reply' || $mode == 'quote' )
1503 $sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id
1504 FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
1505 WHERE pm.privmsgs_id = $privmsg_id
1506 AND pmt.privmsgs_text_id = pm.privmsgs_id
1507 AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1508 AND u.user_id = pm.privmsgs_from_userid";
1509 if ( !($result = $db->sql_query($sql)) )
1511 message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
1514 if ( !($privmsg = $db->sql_fetchrow($result)) )
1516 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
1519 $orig_word = $replacement_word = array();
1520 obtain_word_list($orig_word, $replacement_word);
1522 $privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ) . $privmsg['privmsgs_subject'];
1523 $privmsg_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject);
1525 $to_username = $privmsg['username'];
1526 $to_userid = $privmsg['user_id'];
1528 if ( $mode == 'quote' )
1530 $privmsg_message = $privmsg['privmsgs_text'];
1531 $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
1533 $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
1534 $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
1535 // $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message);
1536 $privmsg_message = preg_replace($orig_word, $replacement_word, $privmsg_message);
1538 $msg_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
1540 $privmsg_message = '[quote="' . $to_username . '"]' . $privmsg_message . '[/quote]';
1547 $privmsg_subject = $privmsg_message = $to_username = '';
1552 // Has admin prevented user from sending PM's?
1554 if ( !$userdata['user_allow_pm'] && $mode != 'edit' )
1556 $message = $lang['Cannot_send_privmsg'];
1557 message_die(GENERAL_MESSAGE, $message);
1561 // Start output, first preview, then errors then post form
1563 $page_title = $lang['Send_private_message'];
1564 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1566 if ( $preview && !$error )
1568 $orig_word = array();
1569 $replacement_word = array();
1570 obtain_word_list($orig_word, $replacement_word);
1574 $bbcode_uid = make_bbcode_uid();
1577 $preview_message = stripslashes(prepare_message($privmsg_message, $html_on, $bbcode_on, $smilies_on, $bbcode_uid));
1578 $privmsg_message = stripslashes(preg_replace($html_entities_match, $html_entities_replace, $privmsg_message));
1581 // Finalise processing as per viewtopic
1583 if ( !$html_on || !$board_config['allow_html'] || !$userdata['user_allowhtml'] )
1585 if ( $user_sig != '' )
1587 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
1591 if ( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] )
1593 $user_sig = bbencode_second_pass($user_sig, $userdata['user_sig_bbcode_uid']);
1598 $preview_message = bbencode_second_pass($preview_message, $bbcode_uid);
1601 if ( $attach_sig && $user_sig != '' )
1603 $preview_message = $preview_message . '<br /><br />_________________<br />' . $user_sig;
1606 if ( count($orig_word) )
1608 $preview_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject);
1609 $preview_message = preg_replace($orig_word, $replacement_word, $preview_message);
1613 $preview_subject = $privmsg_subject;
1618 $preview_message = smilies_pass($preview_message);
1621 $preview_message = make_clickable($preview_message);
1622 $preview_message = str_replace("\n", '<br />', $preview_message);
1624 $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
1625 $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
1627 if ( isset($privmsg_id) )
1629 $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
1632 $template->set_filenames(array(
1633 "preview" => 'privmsgs_preview.tpl')
1636 $template->assign_vars(array(
1637 'TOPIC_TITLE' => $preview_subject,
1638 'POST_SUBJECT' => $preview_subject,
1639 'MESSAGE_TO' => $to_username,
1640 'MESSAGE_FROM' => $userdata['username'],
1641 'POST_DATE' => create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']),
1642 'MESSAGE' => $preview_message,
1644 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1646 'L_SUBJECT' => $lang['Subject'],
1647 'L_DATE' => $lang['Date'],
1648 'L_FROM' => $lang['From'],
1649 'L_TO' => $lang['To'],
1650 'L_PREVIEW' => $lang['Preview'],
1651 'L_POSTED' => $lang['Posted'])
1654 $template->assign_var_from_handle('POST_PREVIEW_BOX', 'preview');
1658 // Start error handling
1662 $privmsg_message = htmlspecialchars($privmsg_message);
1663 $template->set_filenames(array(
1664 'reg_header' => 'error_body.tpl')
1666 $template->assign_vars(array(
1667 'ERROR_MESSAGE' => $error_msg)
1669 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
1675 $template->set_filenames(array(
1676 'body' => 'posting_body.tpl')
1678 make_jumpbox('viewforum.'.$phpEx);
1681 // Enable extensions in posting_body
1683 $template->assign_block_vars('switch_privmsg', array());
1686 // HTML toggle selection
1688 if ( $board_config['allow_html'] )
1690 $html_status = $lang['HTML_is_ON'];
1691 $template->assign_block_vars('switch_html_checkbox', array());
1695 $html_status = $lang['HTML_is_OFF'];
1699 // BBCode toggle selection
1701 if ( $board_config['allow_bbcode'] )
1703 $bbcode_status = $lang['BBCode_is_ON'];
1704 $template->assign_block_vars('switch_bbcode_checkbox', array());
1708 $bbcode_status = $lang['BBCode_is_OFF'];
1712 // Smilies toggle selection
1714 if ( $board_config['allow_smilies'] )
1716 $smilies_status = $lang['Smilies_are_ON'];
1717 $template->assign_block_vars('switch_smilies_checkbox', array());
1721 $smilies_status = $lang['Smilies_are_OFF'];
1725 // Signature toggle selection - only show if
1726 // the user has a signature
1728 if ( $user_sig != '' )
1730 $template->assign_block_vars('switch_signature_checkbox', array());
1733 if ( $mode == 'post' )
1735 $post_a = $lang['Send_a_new_message'];
1737 else if ( $mode == 'reply' )
1739 $post_a = $lang['Send_a_reply'];
1742 else if ( $mode == 'edit' )
1744 $post_a = $lang['Edit_message'];
1747 $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
1748 $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
1749 $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
1750 if ( $mode == 'edit' )
1752 $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
1756 // Send smilies to template
1758 generate_smilies('inline', PAGE_PRIVMSGS);
1760 $template->assign_vars(array(
1761 'SUBJECT' => $privmsg_subject,
1762 'USERNAME' => $to_username,
1763 'MESSAGE' => $privmsg_message,
1764 'HTML_STATUS' => $html_status,
1765 'SMILIES_STATUS' => $smilies_status,
1766 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
1767 'FORUM_NAME' => $lang['Private_Message'],
1769 'BOX_NAME' => $l_box_name,
1770 'INBOX_IMG' => $inbox_img,
1771 'SENTBOX_IMG' => $sentbox_img,
1772 'OUTBOX_IMG' => $outbox_img,
1773 'SAVEBOX_IMG' => $savebox_img,
1774 'INBOX' => $inbox_url,
1775 'SENTBOX' => $sentbox_url,
1776 'OUTBOX' => $outbox_url,
1777 'SAVEBOX' => $savebox_url,
1779 'L_SUBJECT' => $lang['Subject'],
1780 'L_MESSAGE_BODY' => $lang['Message_body'],
1781 'L_OPTIONS' => $lang['Options'],
1782 'L_SPELLCHECK' => $lang['Spellcheck'],
1783 'L_PREVIEW' => $lang['Preview'],
1784 'L_SUBMIT' => $lang['Submit'],
1785 'L_CANCEL' => $lang['Cancel'],
1786 'L_POST_A' => $post_a,
1787 'L_FIND_USERNAME' => $lang['Find_username'],
1788 'L_FIND' => $lang['Find'],
1789 'L_DISABLE_HTML' => $lang['Disable_HTML_pm'],
1790 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_pm'],
1791 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_pm'],
1792 'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
1794 'L_BBCODE_B_HELP' => $lang['bbcode_b_help'],
1795 'L_BBCODE_I_HELP' => $lang['bbcode_i_help'],
1796 'L_BBCODE_U_HELP' => $lang['bbcode_u_help'],
1797 'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'],
1798 'L_BBCODE_C_HELP' => $lang['bbcode_c_help'],
1799 'L_BBCODE_L_HELP' => $lang['bbcode_l_help'],
1800 'L_BBCODE_O_HELP' => $lang['bbcode_o_help'],
1801 'L_BBCODE_P_HELP' => $lang['bbcode_p_help'],
1802 'L_BBCODE_W_HELP' => $lang['bbcode_w_help'],
1803 'L_BBCODE_A_HELP' => $lang['bbcode_a_help'],
1804 'L_BBCODE_S_HELP' => $lang['bbcode_s_help'],
1805 'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],
1806 'L_EMPTY_MESSAGE' => $lang['Empty_message'],
1808 'L_FONT_COLOR' => $lang['Font_color'],
1809 'L_COLOR_DEFAULT' => $lang['color_default'],
1810 'L_COLOR_DARK_RED' => $lang['color_dark_red'],
1811 'L_COLOR_RED' => $lang['color_red'],
1812 'L_COLOR_ORANGE' => $lang['color_orange'],
1813 'L_COLOR_BROWN' => $lang['color_brown'],
1814 'L_COLOR_YELLOW' => $lang['color_yellow'],
1815 'L_COLOR_GREEN' => $lang['color_green'],
1816 'L_COLOR_OLIVE' => $lang['color_olive'],
1817 'L_COLOR_CYAN' => $lang['color_cyan'],
1818 'L_COLOR_BLUE' => $lang['color_blue'],
1819 'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'],
1820 'L_COLOR_INDIGO' => $lang['color_indigo'],
1821 'L_COLOR_VIOLET' => $lang['color_violet'],
1822 'L_COLOR_WHITE' => $lang['color_white'],
1823 'L_COLOR_BLACK' => $lang['color_black'],
1825 'L_FONT_SIZE' => $lang['Font_size'],
1826 'L_FONT_TINY' => $lang['font_tiny'],
1827 'L_FONT_SMALL' => $lang['font_small'],
1828 'L_FONT_NORMAL' => $lang['font_normal'],
1829 'L_FONT_LARGE' => $lang['font_large'],
1830 'L_FONT_HUGE' => $lang['font_huge'],
1832 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'],
1833 'L_STYLES_TIP' => $lang['Styles_tip'],
1835 'S_HTML_CHECKED' => ( !$html_on ) ? ' checked="checked"' : '',
1836 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? ' checked="checked"' : '',
1837 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? ' checked="checked"' : '',
1838 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? ' checked="checked"' : '',
1839 'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields,
1840 'S_POST_ACTION' => append_sid("privmsg.$phpEx"),
1842 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser"),
1843 'U_VIEW_FORUM' => append_sid("privmsg.$phpEx"))
1846 $template->pparse('body');
1848 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1854 if ( !$userdata['session_logged_in'] )
1856 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
1860 // Update unread status
1862 $sql = "UPDATE " . USERS_TABLE . "
1863 SET user_unread_privmsg = user_unread_privmsg + user_new_privmsg, user_new_privmsg = 0, user_last_privmsg = " . $userdata['session_start'] . "
1864 WHERE user_id = " . $userdata['user_id'];
1865 if ( !$db->sql_query($sql) )
1867 message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
1870 $sql = "UPDATE " . PRIVMSGS_TABLE . "
1871 SET privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
1872 WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1873 AND privmsgs_to_userid = " . $userdata['user_id'];
1874 if ( !$db->sql_query($sql) )
1876 message_die(GENERAL_ERROR, 'Could not update private message new/read status (2) for user', '', __LINE__, __FILE__, $sql);
1880 // Reset PM counters
1882 $userdata['user_new_privmsg'] = 0;
1883 $userdata['user_unread_privmsg'] = ( $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'] );
1888 $page_title = $lang['Private_Messaging'];
1889 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1894 $template->set_filenames(array(
1895 'body' => 'privmsgs_body.tpl')
1897 make_jumpbox('viewforum.'.$phpEx);
1899 $orig_word = array();
1900 $replacement_word = array();
1901 obtain_word_list($orig_word, $replacement_word);
1906 $post_new_mesg_url = '<a href="' . append_sid("privmsg.$phpEx?mode=post") . '"><img src="' . $images['post_new'] . '" alt="' . $lang['Send_a_new_message'] . '" border="0" /></a>';
1909 // General SQL to obtain messages
1911 $sql_tot = "SELECT COUNT(privmsgs_id) AS total
1912 FROM " . PRIVMSGS_TABLE . " ";
1913 $sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username
1914 FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u ";
1918 $sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
1919 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1920 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1921 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1923 $sql .= "WHERE pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1924 AND u.user_id = pm.privmsgs_from_userid
1925 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1926 OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1927 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1931 $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1932 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1933 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1935 $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1936 AND u.user_id = pm.privmsgs_to_userid
1937 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1938 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1942 $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1943 AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1945 $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1946 AND u.user_id = pm.privmsgs_to_userid
1947 AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1951 $sql_tot .= "WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
1952 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
1953 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
1954 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
1956 $sql .= "WHERE u.user_id = pm.privmsgs_from_userid
1957 AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1958 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
1959 OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1960 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )";
1964 message_die(GENERAL_MESSAGE, $lang['No_such_folder']);
1969 // Show messages over previous x days/months
1971 if ( $submit_msgdays && ( !empty($HTTP_POST_VARS['msgdays']) || !empty($HTTP_GET_VARS['msgdays']) ) )
1973 $msg_days = ( !empty($HTTP_POST_VARS['msgdays']) ) ? intval($HTTP_POST_VARS['msgdays']) : intval($HTTP_GET_VARS['msgdays']);
1974 $min_msg_time = time() - ($msg_days * 86400);
1976 $limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
1977 $limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";
1979 if ( !empty($HTTP_POST_VARS['msgdays']) )
1986 $limit_msg_time = $limit_msg_time_total = '';
1990 $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $board_config['topics_per_page'];
1991 $sql_all_tot = $sql_tot;
1992 $sql_tot .= $limit_msg_time_total;
1997 if ( !($result = $db->sql_query($sql_tot)) )
1999 message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
2002 $pm_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
2004 if ( !($result = $db->sql_query($sql_all_tot)) )
2006 message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
2009 $pm_all_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
2014 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
2015 $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']);
2017 $select_msg_days = '';
2018 for($i = 0; $i < count($previous_days); $i++)
2020 $selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : '';
2021 $select_msg_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
2025 // Define correct icons
2030 $l_box_name = $lang['Inbox'];
2033 $l_box_name = $lang['Outbox'];
2036 $l_box_name = $lang['Savebox'];
2039 $l_box_name = $lang['Sentbox'];
2042 $post_pm = append_sid("privmsg.$phpEx?mode=post");
2043 $post_pm_img = '<a href="' . $post_pm . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0" /></a>';
2044 $post_pm = '<a href="' . $post_pm . '">' . $lang['Post_new_pm'] . '</a>';
2047 // Output data for inbox status
2049 if ( $folder != 'outbox' )
2051 $inbox_limit_pct = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * 100) : 100;
2052 $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'];
2053 $inbox_limit_remain = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? $board_config['max_' . $folder . '_privmsgs'] - $pm_all_total : 0;
2055 $template->assign_block_vars('switch_box_size_notice', array());
2060 $l_box_size_status = sprintf($lang['Inbox_size'], $inbox_limit_pct);
2063 $l_box_size_status = sprintf($lang['Sentbox_size'], $inbox_limit_pct);
2066 $l_box_size_status = sprintf($lang['Savebox_size'], $inbox_limit_pct);
2069 $l_box_size_status = '';
2075 $inbox_limit_img_length = $inbox_limit_pct = $l_box_size_status = '';
2079 // Dump vars to template
2081 $template->assign_vars(array(
2082 'BOX_NAME' => $l_box_name,
2083 'INBOX_IMG' => $inbox_img,
2084 'SENTBOX_IMG' => $sentbox_img,
2085 'OUTBOX_IMG' => $outbox_img,
2086 'SAVEBOX_IMG' => $savebox_img,
2087 'INBOX' => $inbox_url,
2088 'SENTBOX' => $sentbox_url,
2089 'OUTBOX' => $outbox_url,
2090 'SAVEBOX' => $savebox_url,
2092 'POST_PM_IMG' => $post_pm_img,
2093 'POST_PM' => $post_pm,
2095 'INBOX_LIMIT_IMG_WIDTH' => $inbox_limit_img_length,
2096 'INBOX_LIMIT_PERCENT' => $inbox_limit_pct,
2098 'BOX_SIZE_STATUS' => $l_box_size_status,
2100 'L_INBOX' => $lang['Inbox'],
2101 'L_OUTBOX' => $lang['Outbox'],
2102 'L_SENTBOX' => $lang['Sent'],
2103 'L_SAVEBOX' => $lang['Saved'],
2104 'L_MARK' => $lang['Mark'],
2105 'L_FLAG' => $lang['Flag'],
2106 'L_SUBJECT' => $lang['Subject'],
2107 'L_DATE' => $lang['Date'],
2108 'L_DISPLAY_MESSAGES' => $lang['Display_messages'],
2109 'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? $lang['From'] : $lang['To'],
2110 'L_MARK_ALL' => $lang['Mark_all'],
2111 'L_UNMARK_ALL' => $lang['Unmark_all'],
2112 'L_DELETE_MARKED' => $lang['Delete_marked'],
2113 'L_DELETE_ALL' => $lang['Delete_all'],
2114 'L_SAVE_MARKED' => $lang['Save_marked'],
2116 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
2117 'S_HIDDEN_FIELDS' => '',
2118 'S_POST_NEW_MSG' => $post_new_mesg_url,
2119 'S_SELECT_MSG_DAYS' => $select_msg_days,
2121 'U_POST_NEW_TOPIC' => append_sid("privmsg.$phpEx?mode=post"))
2125 // Okay, let's build the correct folder
2127 if ( !($result = $db->sql_query($sql)) )
2129 message_die(GENERAL_ERROR, 'Could not query private messages', '', __LINE__, __FILE__, $sql);
2132 if ( $row = $db->sql_fetchrow($result) )
2137 $privmsg_id = $row['privmsgs_id'];
2139 $flag = $row['privmsgs_type'];
2141 $icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg'];
2142 $icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $lang['Unread_message'] : $lang['Read_message'];
2144 $msg_userid = $row['user_id'];
2145 $msg_username = $row['username'];
2147 $u_from_user_profile = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$msg_userid");
2149 $msg_subject = $row['privmsgs_subject'];
2151 if ( count($orig_word) )
2153 $msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject);
2156 $u_subject = append_sid("privmsg.$phpEx?folder=$folder&mode=read&" . POST_POST_URL . "=$privmsg_id");
2158 $msg_date = create_date($board_config['default_dateformat'], $row['privmsgs_date'], $board_config['board_timezone']);
2160 if ( $flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox' )
2162 $msg_subject = '<b>' . $msg_subject . '</b>';
2163 $msg_date = '<b>' . $msg_date . '</b>';
2164 $msg_username = '<b>' . $msg_username . '</b>';
2167 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
2168 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
2171 $template->assign_block_vars('listrow', array(
2172 'ROW_COLOR' => '#' . $row_color,
2173 'ROW_CLASS' => $row_class,
2174 'FROM' => $msg_username,
2175 'SUBJECT' => $msg_subject,
2176 'DATE' => $msg_date,
2177 'PRIVMSG_FOLDER_IMG' => $icon_flag,
2179 'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt,
2181 'S_MARK_ID' => $privmsg_id,
2183 'U_READ' => $u_subject,
2184 'U_FROM_USER_PROFILE' => $u_from_user_profile)
2187 while( $row = $db->sql_fetchrow($result) );
2189 $template->assign_vars(array(
2190 'PAGINATION' => generate_pagination("privmsg.$phpEx?folder=$folder", $pm_total, $board_config['topics_per_page'], $start),
2191 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $pm_total / $board_config['topics_per_page'] )),
2193 'L_GOTO_PAGE' => $lang['Goto_page'])
2199 $template->assign_vars(array(
2200 'L_NO_MESSAGES' => $lang['No_messages_folder'])
2203 $template->assign_block_vars("switch_no_messages", array() );
2206 $template->pparse('body');
2208 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);