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.37 2004/11/18 17:49:36 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;
54 $refresh = $preview || $submit_search;
56 $mark_list = ( !empty($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : 0;
58 if ( isset($HTTP_POST_VARS['folder']) || isset($HTTP_GET_VARS['folder']) )
60 $folder = ( isset($HTTP_POST_VARS['folder']) ) ? $HTTP_POST_VARS['folder'] : $HTTP_GET_VARS['folder'];
61 $folder = htmlspecialchars($folder);
63 if ( $folder != 'inbox' && $folder != 'outbox' && $folder != 'sentbox' && $folder != 'savebox' )
74 // Start session management
76 $userdata = session_pagestart($user_ip, PAGE_PRIVMSGS);
77 init_userprefs($userdata);
79 // End session management
87 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
93 if ( !empty($HTTP_POST_VARS['mode']) || !empty($HTTP_GET_VARS['mode']) )
95 $mode = ( !empty($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
96 $mode = htmlspecialchars($mode);
103 $start = ( !empty($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
105 if ( isset($HTTP_POST_VARS[POST_POST_URL]) || isset($HTTP_GET_VARS[POST_POST_URL]) )
107 $privmsg_id = ( isset($HTTP_POST_VARS[POST_POST_URL]) ) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
117 // Define the box image links
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'];
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'];
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'];
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'];
134 if ( $mode == 'newpm' )
136 $gen_simple_header = TRUE;
138 $page_title = $lang['Private_Messaging'];
139 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
141 $template->set_filenames(array(
142 'body' => 'privmsgs_popup.tpl')
145 if ( $userdata['session_logged_in'] )
147 if ( $userdata['user_new_privmsg'] )
149 $l_new_message = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['You_new_pm'] : $lang['You_new_pms'];
153 $l_new_message = $lang['You_no_new_pm'];
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>');
160 $l_new_message = $lang['Login_check_pm'];
163 $template->assign_vars(array(
164 'L_CLOSE_WINDOW' => $lang['Close_window'],
165 'L_MESSAGE' => $l_new_message)
168 $template->pparse('body');
170 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
173 else if ( $mode == 'read' )
175 if ( !empty($HTTP_GET_VARS[POST_POST_URL]) )
177 $privmsgs_id = intval($HTTP_GET_VARS[POST_POST_URL]);
181 message_die(GENERAL_ERROR, $lang['No_post_id']);
184 if ( !$userdata['session_logged_in'] )
186 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode&" . POST_POST_URL . "=$privmsgs_id", true));
190 // SQL to pull appropriate message, prevents nosey people
191 // reading other peoples messages ... hopefully!
196 $l_box_name = $lang['Inbox'];
197 $pm_sql_user = "AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
198 AND ( pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
199 OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
200 OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
203 $l_box_name = $lang['Outbox'];
204 $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
205 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
206 OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
209 $l_box_name = $lang['Sentbox'];
210 $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
211 AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
214 $l_box_name = $lang['Savebox'];
215 $pm_sql_user = "AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
216 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
217 OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
218 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
222 message_die(GENERAL_ERROR, $lang['No_such_folder']);
227 // Major query obtains the message ...
229 $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
230 FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
231 WHERE pm.privmsgs_id = $privmsgs_id
232 AND pmt.privmsgs_text_id = pm.privmsgs_id
234 AND u.user_id = pm.privmsgs_from_userid
235 AND u2.user_id = pm.privmsgs_to_userid";
236 if ( !($result = $db->sql_query($sql)) )
238 message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql);
242 // Did the query return any data?
244 if ( !($privmsg = $db->sql_fetchrow($result)) )
246 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
249 $privmsg_id = $privmsg['privmsgs_id'];
252 // Is this a new message in the inbox? If it is then save
253 // a copy in the posters sent box
255 if (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL) && $folder == 'inbox')
257 // Update appropriate counter
258 switch ($privmsg['privmsgs_type'])
260 case PRIVMSGS_NEW_MAIL:
261 $sql = "user_new_privmsg = user_new_privmsg - 1";
263 case PRIVMSGS_UNREAD_MAIL:
264 $sql = "user_unread_privmsg = user_unread_privmsg - 1";
268 $sql = "UPDATE " . USERS_TABLE . "
270 WHERE user_id = " . $userdata['user_id'];
271 if ( !$db->sql_query($sql) )
273 message_die(GENERAL_ERROR, 'Could not update private message read status for user', '', __LINE__, __FILE__, $sql);
276 $sql = "UPDATE " . PRIVMSGS_TABLE . "
277 SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
278 WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
279 if ( !$db->sql_query($sql) )
281 message_die(GENERAL_ERROR, 'Could not update private message read status', '', __LINE__, __FILE__, $sql);
284 // Check to see if the poster has a 'full' sent box
285 $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time
286 FROM " . PRIVMSGS_TABLE . "
287 WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
288 AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
289 if ( !($result = $db->sql_query($sql)) )
291 message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
294 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
296 if ( $sent_info = $db->sql_fetchrow($result) )
298 if ( $sent_info['sent_items'] >= $board_config['max_sentbox_privmsgs'] )
300 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
301 WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
302 AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
303 AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
304 if ( !$result = $db->sql_query($sql) )
306 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs', '', __LINE__, __FILE__, $sql);
308 $old_privmsgs_id = $db->sql_fetchrow($result);
309 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
311 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
312 WHERE privmsgs_id = $old_privmsgs_id";
313 if ( !$db->sql_query($sql) )
315 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (sent)', '', __LINE__, __FILE__, $sql);
318 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
319 WHERE privmsgs_text_id = $old_privmsgs_id";
320 if ( !$db->sql_query($sql) )
322 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (sent)', '', __LINE__, __FILE__, $sql);
328 // This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
329 // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
330 // set limits on numbers of storable posts for users ... hopefully!
332 $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)
333 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'] . ")";
334 if ( !$db->sql_query($sql) )
336 message_die(GENERAL_ERROR, 'Could not insert private message sent info', '', __LINE__, __FILE__, $sql);
339 $privmsg_sent_id = $db->sql_nextid();
341 $sql = "INSERT $sql_priority INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
342 VALUES ($privmsg_sent_id, '" . $privmsg['privmsgs_bbcode_uid'] . "', '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_text'])) . "')";
343 if ( !$db->sql_query($sql) )
345 message_die(GENERAL_ERROR, 'Could not insert private message sent text', '', __LINE__, __FILE__, $sql);
350 // Pick a folder, any folder, so long as it's one below ...
353 'post' => append_sid("privmsg.$phpEx?mode=post"),
354 'reply' => append_sid("privmsg.$phpEx?mode=reply&" . POST_POST_URL . "=$privmsg_id"),
355 'quote' => append_sid("privmsg.$phpEx?mode=quote&" . POST_POST_URL . "=$privmsg_id"),
356 'edit' => append_sid("privmsg.$phpEx?mode=edit&" . POST_POST_URL . "=$privmsg_id")
359 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0" /></a>',
360 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['Post_new_pm'] . '</a>',
361 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['Post_reply_pm'] . '" border="0" /></a>',
362 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['Post_reply_pm'] . '</a>',
363 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['Post_quote_pm'] . '" border="0" /></a>',
364 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['Post_quote_pm'] . '</a>',
365 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['Edit_pm'] . '" border="0" /></a>',
366 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['Edit_pm'] . '</a>'
369 if ( $folder == 'inbox' )
371 $post_img = $post_icons['post_img'];
372 $reply_img = $post_icons['reply_img'];
373 $quote_img = $post_icons['quote_img'];
375 $post = $post_icons['post'];
376 $reply = $post_icons['reply'];
377 $quote = $post_icons['quote'];
379 $l_box_name = $lang['Inbox'];
381 else if ( $folder == 'outbox' )
383 $post_img = $post_icons['post_img'];
386 $edit_img = $post_icons['edit_img'];
387 $post = $post_icons['post'];
390 $edit = $post_icons['edit'];
391 $l_box_name = $lang['Outbox'];
393 else if ( $folder == 'savebox' )
395 if ( $privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL )
397 $post_img = $post_icons['post_img'];
398 $reply_img = $post_icons['reply_img'];
399 $quote_img = $post_icons['quote_img'];
401 $post = $post_icons['post'];
402 $reply = $post_icons['reply'];
403 $quote = $post_icons['quote'];
408 $post_img = $post_icons['post_img'];
412 $post = $post_icons['post'];
417 $l_box_name = $lang['Saved'];
419 else if ( $folder == 'sentbox' )
421 $post_img = $post_icons['post_img'];
425 $post = $post_icons['post'];
429 $l_box_name = $lang['Sent'];
432 $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />';
434 $page_title = $lang['Read_pm'];
435 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
440 $template->set_filenames(array(
441 'body' => 'privmsgs_read_body.tpl')
443 make_jumpbox('viewforum.'.$phpEx);
445 $template->assign_vars(array(
446 'INBOX_IMG' => $inbox_img,
447 'SENTBOX_IMG' => $sentbox_img,
448 'OUTBOX_IMG' => $outbox_img,
449 'SAVEBOX_IMG' => $savebox_img,
450 'INBOX' => $inbox_url,
452 'POST_PM_IMG' => $post_img,
453 'REPLY_PM_IMG' => $reply_img,
454 'EDIT_PM_IMG' => $edit_img,
455 'QUOTE_PM_IMG' => $quote_img,
457 'REPLY_PM' => $reply,
459 'QUOTE_PM' => $quote,
461 'SENTBOX' => $sentbox_url,
462 'OUTBOX' => $outbox_url,
463 'SAVEBOX' => $savebox_url,
465 'BOX_NAME' => $l_box_name,
467 'L_MESSAGE' => $lang['Message'],
468 'L_INBOX' => $lang['Inbox'],
469 'L_OUTBOX' => $lang['Outbox'],
470 'L_SENTBOX' => $lang['Sent'],
471 'L_SAVEBOX' => $lang['Saved'],
472 'L_FLAG' => $lang['Flag'],
473 'L_SUBJECT' => $lang['Subject'],
474 'L_POSTED' => $lang['Posted'],
475 'L_DATE' => $lang['Date'],
476 'L_FROM' => $lang['From'],
477 'L_TO' => $lang['To'],
478 'L_SAVE_MSG' => $lang['Save_message'],
479 'L_DELETE_MSG' => $lang['Delete_message'],
481 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
482 'S_HIDDEN_FIELDS' => $s_hidden_fields)
485 $username_from = $privmsg['username_1'];
486 $user_id_from = $privmsg['user_id_1'];
487 $username_to = $privmsg['username_2'];
488 $user_id_to = $privmsg['user_id_2'];
490 $post_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
492 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $user_id_from);
493 $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
494 $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
496 $temp_url = append_sid("privmsg.$phpEx?mode=post&" . POST_USERS_URL . "=$user_id_from");
497 $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
498 $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
500 if ( !empty($privmsg['user_viewemail']) || $userdata['user_level'] == ADMIN )
502 $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&" . POST_USERS_URL .'=' . $user_id_from) : 'mailto:' . $privmsg['user_email'];
504 $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
505 $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
513 $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>' : '';
514 $www = ( $privmsg['user_website'] ) ? '<a href="' . $privmsg['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
516 if ( !empty($privmsg['user_icq']) )
518 $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>';
519 $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>';
520 $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $privmsg['user_icq'] . '">' . $lang['ICQ'] . '</a>';
524 $icq_status_img = '';
529 $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>' : '';
530 $aim = ( $privmsg['user_aim'] ) ? '<a href="aim:goim?screenname=' . $privmsg['user_aim'] . '&message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
532 $temp_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id_from");
533 $msn_img = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
534 $msn = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
536 $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>' : '';
537 $yim = ( $privmsg['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $privmsg['user_yim'] . '&.src=pg">' . $lang['YIM'] . '</a>' : '';
539 $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($username_from) . "&showresults=posts");
540 $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>';
541 $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>';
544 // Processing of post
546 $post_subject = $privmsg['privmsgs_subject'];
548 $private_message = $privmsg['privmsgs_text'];
549 $bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
551 if ( $board_config['allow_sig'] )
553 $user_sig = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig'] : $privmsg['user_sig'];
560 $user_sig_bbcode_uid = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig_bbcode_uid'] : $privmsg['user_sig_bbcode_uid'];
563 // If the board has HTML off but the post has HTML
564 // on then we process it, else leave it alone
566 if ( !$board_config['allow_html'] )
568 if ( $user_sig != '' && $privmsg['privmsgs_enable_sig'] && $userdata['user_allowhtml'] )
570 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
573 if ( $privmsg['privmsgs_enable_html'] )
575 $private_message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $private_message);
579 if ( $user_sig != '' && $privmsg['privmsgs_attach_sig'] && $user_sig_bbcode_uid != '' )
581 $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
584 if ( $bbcode_uid != '' )
586 $private_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($private_message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $private_message);
589 $private_message = make_clickable($private_message);
591 if ( $privmsg['privmsgs_attach_sig'] && $user_sig != '' )
593 $private_message .= '<br /><br />_________________<br />' . make_clickable($user_sig);
596 $orig_word = array();
597 $replacement_word = array();
598 obtain_word_list($orig_word, $replacement_word);
600 if ( count($orig_word) )
602 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
603 $private_message = preg_replace($orig_word, $replacement_word, $private_message);
606 if ( $board_config['allow_smilies'] && $privmsg['privmsgs_enable_smilies'] )
608 $private_message = smilies_pass($private_message);
611 $private_message = str_replace("\n", '<br />', $private_message);
614 // Dump it to the templating engine
616 $template->assign_vars(array(
617 'MESSAGE_TO' => $username_to,
618 'MESSAGE_FROM' => $username_from,
619 'RANK_IMAGE' => $rank_image,
620 'POSTER_JOINED' => $poster_joined,
621 'POSTER_POSTS' => $poster_posts,
622 'POSTER_FROM' => $poster_from,
623 'POSTER_AVATAR' => $poster_avatar,
624 'POST_SUBJECT' => $post_subject,
625 'POST_DATE' => $post_date,
626 'MESSAGE' => $private_message,
628 'PROFILE_IMG' => $profile_img,
629 'PROFILE' => $profile,
630 'SEARCH_IMG' => $search_img,
632 'EMAIL_IMG' => $email_img,
634 'WWW_IMG' => $www_img,
636 'ICQ_STATUS_IMG' => $icq_status_img,
637 'ICQ_IMG' => $icq_img,
639 'AIM_IMG' => $aim_img,
641 'MSN_IMG' => $msn_img,
643 'YIM_IMG' => $yim_img,
647 $template->pparse('body');
649 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
652 else if ( ( $delete && $mark_list ) || $delete_all )
654 if ( !$userdata['session_logged_in'] )
656 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
659 if ( isset($mark_list) && !is_array($mark_list) )
661 // Set to empty array instead of '0' if nothing is selected.
662 $mark_list = array();
667 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
668 $s_hidden_fields .= ( isset($HTTP_POST_VARS['delete']) ) ? '<input type="hidden" name="delete" value="true" />' : '<input type="hidden" name="deleteall" value="true" />';
670 for($i = 0; $i < count($mark_list); $i++)
672 $s_hidden_fields .= '<input type="hidden" name="mark[]" value="' . intval($mark_list[$i]) . '" />';
676 // Output confirmation page
678 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
680 $template->set_filenames(array(
681 'confirm_body' => 'confirm_body.tpl')
683 $template->assign_vars(array(
684 'MESSAGE_TITLE' => $lang['Information'],
685 'MESSAGE_TEXT' => ( count($mark_list) == 1 ) ? $lang['Confirm_delete_pm'] : $lang['Confirm_delete_pms'],
687 'L_YES' => $lang['Yes'],
688 'L_NO' => $lang['No'],
690 'S_CONFIRM_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
691 'S_HIDDEN_FIELDS' => $s_hidden_fields)
694 $template->pparse('confirm_body');
696 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
706 $delete_type = "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
707 privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
711 $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
715 $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
719 $delete_type = "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
720 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
721 OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
722 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
726 $sql = "SELECT privmsgs_id
727 FROM " . PRIVMSGS_TABLE . "
729 if ( !($result = $db->sql_query($sql)) )
731 message_die(GENERAL_ERROR, 'Could not obtain id list to delete all messages', '', __LINE__, __FILE__, $sql);
734 while ( $row = $db->sql_fetchrow($result) )
736 $mark_list[] = $row['privmsgs_id'];
742 if ( count($mark_list) )
745 for ($i = 0; $i < sizeof($mark_list); $i++)
747 $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
750 if ($folder == 'inbox' || $folder == 'outbox')
755 $sql = "privmsgs_to_userid = " . $userdata['user_id'];
758 $sql = "privmsgs_from_userid = " . $userdata['user_id'];
762 // Get information relevant to new or unread mail
763 // so we can adjust users counters appropriately
764 $sql = "SELECT privmsgs_to_userid, privmsgs_type
765 FROM " . PRIVMSGS_TABLE . "
766 WHERE privmsgs_id IN ($delete_sql_id)
768 AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
769 if ( !($result = $db->sql_query($sql)) )
771 message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
774 if ( $row = $db->sql_fetchrow($result))
776 $update_users = $update_list = array();
780 switch ($row['privmsgs_type'])
782 case PRIVMSGS_NEW_MAIL:
783 $update_users['new'][$row['privmsgs_to_userid']]++;
786 case PRIVMSGS_UNREAD_MAIL:
787 $update_users['unread'][$row['privmsgs_to_userid']]++;
791 while ($row = $db->sql_fetchrow($result));
793 if (sizeof($update_users))
795 while (list($type, $users) = each($update_users))
797 while (list($user_id, $dec) = each($users))
799 $update_list[$type][$dec][] = $user_id;
802 unset($update_users);
804 while (list($type, $dec_ary) = each($update_list))
809 $type = "user_new_privmsg";
813 $type = "user_unread_privmsg";
817 while (list($dec, $user_ary) = each($dec_ary))
819 $user_ids = implode(', ', $user_ary);
821 $sql = "UPDATE " . USERS_TABLE . "
822 SET $type = $type - $dec
823 WHERE user_id IN ($user_ids)";
824 if ( !$db->sql_query($sql) )
826 message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
833 $db->sql_freeresult($result);
836 // Delete the messages
837 $delete_text_sql = "DELETE FROM " . PRIVMSGS_TEXT_TABLE . "
838 WHERE privmsgs_text_id IN ($delete_sql_id)";
839 $delete_sql = "DELETE FROM " . PRIVMSGS_TABLE . "
840 WHERE privmsgs_id IN ($delete_sql_id)
846 $delete_sql .= "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
847 privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
851 $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND (
852 privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
856 $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
860 $delete_sql .= "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
861 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
862 OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
863 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
867 if ( !$db->sql_query($delete_sql, BEGIN_TRANSACTION) )
869 message_die(GENERAL_ERROR, 'Could not delete private message info', '', __LINE__, __FILE__, $delete_sql);
872 if ( !$db->sql_query($delete_text_sql, END_TRANSACTION) )
874 message_die(GENERAL_ERROR, 'Could not delete private message text', '', __LINE__, __FILE__, $delete_text_sql);
879 else if ( $save && $mark_list && $folder != 'savebox' && $folder != 'outbox' )
881 if ( !$userdata['session_logged_in'] )
883 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
886 if (sizeof($mark_list))
888 // See if recipient is at their savebox limit
889 $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time
890 FROM " . PRIVMSGS_TABLE . "
891 WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
892 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
893 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
894 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
895 if ( !($result = $db->sql_query($sql)) )
897 message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
900 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
902 if ( $saved_info = $db->sql_fetchrow($result) )
904 if ( $saved_info['savebox_items'] >= $board_config['max_savebox_privmsgs'] )
906 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
907 WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
908 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
909 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
910 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )
911 AND privmsgs_date = " . $saved_info['oldest_post_time'];
912 if ( !$result = $db->sql_query($sql) )
914 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
916 $old_privmsgs_id = $db->sql_fetchrow($result);
917 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
919 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
920 WHERE privmsgs_id = $old_privmsgs_id";
921 if ( !$db->sql_query($sql) )
923 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
926 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
927 WHERE privmsgs_text_id = $old_privmsgs_id";
928 if ( !$db->sql_query($sql) )
930 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (save)', '', __LINE__, __FILE__, $sql);
936 for ($i = 0; $i < sizeof($mark_list); $i++)
938 $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
942 $saved_sql = "UPDATE " . PRIVMSGS_TABLE;
944 // Decrement read/new counters if appropriate
945 if ($folder == 'inbox' || $folder == 'outbox')
950 $sql = "privmsgs_to_userid = " . $userdata['user_id'];
953 $sql = "privmsgs_from_userid = " . $userdata['user_id'];
957 // Get information relevant to new or unread mail
958 // so we can adjust users counters appropriately
959 $sql = "SELECT privmsgs_to_userid, privmsgs_type
960 FROM " . PRIVMSGS_TABLE . "
961 WHERE privmsgs_id IN ($saved_sql_id)
963 AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
964 if ( !($result = $db->sql_query($sql)) )
966 message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
969 if ( $row = $db->sql_fetchrow($result))
971 $update_users = $update_list = array();
975 switch ($row['privmsgs_type'])
977 case PRIVMSGS_NEW_MAIL:
978 $update_users['new'][$row['privmsgs_to_userid']]++;
981 case PRIVMSGS_UNREAD_MAIL:
982 $update_users['unread'][$row['privmsgs_to_userid']]++;
986 while ($row = $db->sql_fetchrow($result));
988 if (sizeof($update_users))
990 while (list($type, $users) = each($update_users))
992 while (list($user_id, $dec) = each($users))
994 $update_list[$type][$dec][] = $user_id;
997 unset($update_users);
999 while (list($type, $dec_ary) = each($update_list))
1004 $type = "user_new_privmsg";
1008 $type = "user_unread_privmsg";
1012 while (list($dec, $user_ary) = each($dec_ary))
1014 $user_ids = implode(', ', $user_ary);
1016 $sql = "UPDATE " . USERS_TABLE . "
1017 SET $type = $type - $dec
1018 WHERE user_id IN ($user_ids)";
1019 if ( !$db->sql_query($sql) )
1021 message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
1025 unset($update_list);
1028 $db->sql_freeresult($result);
1034 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
1035 WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
1036 AND ( privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1037 OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1038 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
1042 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
1043 WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1044 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1045 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
1049 $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
1050 WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1051 AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1055 $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
1057 if ( !$db->sql_query($saved_sql) )
1059 message_die(GENERAL_ERROR, 'Could not save private messages', '', __LINE__, __FILE__, $saved_sql);
1062 redirect(append_sid("privmsg.$phpEx?folder=savebox", true));
1065 else if ( $submit || $refresh || $mode != '' )
1067 if ( !$userdata['session_logged_in'] )
1069 $user_id = ( isset($HTTP_GET_VARS[POST_USERS_URL]) ) ? '&' . POST_USERS_URL . '=' . intval($HTTP_GET_VARS[POST_USERS_URL]) : '';
1070 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode" . $user_id, true));
1076 if ( !$board_config['allow_html'] )
1082 $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : $userdata['user_allowhtml'];
1085 if ( !$board_config['allow_bbcode'] )
1091 $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : $userdata['user_allowbbcode'];
1094 if ( !$board_config['allow_smilies'] )
1100 $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : $userdata['user_allowsmile'];
1103 $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : $userdata['user_attachsig'];
1104 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : "";
1106 if ( $submit && $mode != 'edit' )
1111 $sql = "SELECT MAX(privmsgs_date) AS last_post_time
1112 FROM " . PRIVMSGS_TABLE . "
1113 WHERE privmsgs_from_userid = " . $userdata['user_id'];
1114 if ( $result = $db->sql_query($sql) )
1116 $db_row = $db->sql_fetchrow($result);
1118 $last_post_time = $db_row['last_post_time'];
1119 $current_time = time();
1121 if ( ( $current_time - $last_post_time ) < $board_config['flood_interval'])
1123 message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
1127 // End Flood control
1133 if ( !empty($HTTP_POST_VARS['username']) )
1135 $to_username = phpbb_clean_username($HTTP_POST_VARS['username']);
1137 $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active
1138 FROM " . USERS_TABLE . "
1139 WHERE username = '" . str_replace("\'", "''", $to_username) . "'
1140 AND user_id <> " . ANONYMOUS;
1141 if ( !($result = $db->sql_query($sql)) )
1144 $error_msg = $lang['No_such_user'];
1147 $to_userdata = $db->sql_fetchrow($result);
1152 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['No_to_user'];
1155 $privmsg_subject = trim(strip_tags($HTTP_POST_VARS['subject']));
1156 if ( empty($privmsg_subject) )
1159 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject'];
1162 if ( !empty($HTTP_POST_VARS['message']) )
1168 $bbcode_uid = make_bbcode_uid();
1171 $privmsg_message = prepare_message($HTTP_POST_VARS['message'], $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
1178 $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message'];
1182 if ( $submit && !$error )
1185 // Has admin prevented user from sending PM's?
1187 if ( !$userdata['user_allow_pm'] )
1189 $message = $lang['Cannot_send_privmsg'];
1190 message_die(GENERAL_MESSAGE, $message);
1195 if ( $mode != 'edit' )
1198 // See if recipient is at their inbox limit
1200 $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
1201 FROM " . PRIVMSGS_TABLE . "
1202 WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1203 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1204 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1205 AND privmsgs_to_userid = " . $to_userdata['user_id'];
1206 if ( !($result = $db->sql_query($sql)) )
1208 message_die(GENERAL_MESSAGE, $lang['No_such_user']);
1211 $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
1213 if ( $inbox_info = $db->sql_fetchrow($result) )
1215 if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] )
1217 $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
1218 WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1219 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1220 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1221 AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
1222 AND privmsgs_to_userid = " . $to_userdata['user_id'];
1223 if ( !$result = $db->sql_query($sql) )
1225 message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (inbox)', '', __LINE__, __FILE__, $sql);
1227 $old_privmsgs_id = $db->sql_fetchrow($result);
1228 $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
1230 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
1231 WHERE privmsgs_id = $old_privmsgs_id";
1232 if ( !$db->sql_query($sql) )
1234 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (inbox)'.$sql, '', __LINE__, __FILE__, $sql);
1237 $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
1238 WHERE privmsgs_text_id = $old_privmsgs_id";
1239 if ( !$db->sql_query($sql) )
1241 message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (inbox)', '', __LINE__, __FILE__, $sql);
1246 $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)
1247 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)";
1251 $sql_info = "UPDATE " . PRIVMSGS_TABLE . "
1252 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
1253 WHERE privmsgs_id = $privmsg_id";
1256 if ( !($result = $db->sql_query($sql_info, BEGIN_TRANSACTION)) )
1258 message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info);
1261 if ( $mode != 'edit' )
1263 $privmsg_sent_id = $db->sql_nextid();
1265 $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
1266 VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')";
1270 $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . "
1271 SET privmsgs_text = '" . str_replace("\'", "''", $privmsg_message) . "', privmsgs_bbcode_uid = '$bbcode_uid'
1272 WHERE privmsgs_text_id = $privmsg_id";
1275 if ( !$db->sql_query($sql, END_TRANSACTION) )
1277 message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql_info);
1280 if ( $mode != 'edit' )
1283 // Add to the users new pm counter
1285 $sql = "UPDATE " . USERS_TABLE . "
1286 SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . "
1287 WHERE user_id = " . $to_userdata['user_id'];
1288 if ( !$status = $db->sql_query($sql) )
1290 message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
1293 if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] )
1295 $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path']));
1296 $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx;
1297 $server_name = trim($board_config['server_name']);
1298 $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
1299 $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
1301 include($phpbb_root_path . 'includes/emailer.'.$phpEx);
1302 $emailer = new emailer($board_config['smtp_delivery']);
1304 $emailer->from($board_config['board_email']);
1305 $emailer->replyto($board_config['board_email']);
1307 $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
1308 $emailer->email_address($to_userdata['user_email']);
1309 $emailer->set_subject($lang['Notification_subject']);
1311 $emailer->assign_vars(array(
1312 'USERNAME' => $to_username,
1313 'SITENAME' => $board_config['sitename'],
1314 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
1316 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox')
1324 $template->assign_vars(array(
1325 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("privmsg.$phpEx?folder=inbox") . '">')
1328 $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>');
1330 message_die(GENERAL_MESSAGE, $msg);
1332 else if ( $preview || $refresh || $error )
1336 // If we're previewing or refreshing then obtain the data
1337 // passed to the script, process it a little, do some checks
1338 // where neccessary, etc.
1340 $to_username = (isset($HTTP_POST_VARS['username']) ) ? trim(htmlspecialchars(stripslashes($HTTP_POST_VARS['username']))) : '';
1342 $privmsg_subject = ( isset($HTTP_POST_VARS['subject']) ) ? trim(strip_tags(stripslashes($HTTP_POST_VARS['subject']))) : '';
1343 $privmsg_message = ( isset($HTTP_POST_VARS['message']) ) ? trim($HTTP_POST_VARS['message']) : '';
1344 $privmsg_message = preg_replace('#<textarea>#si', '<textarea>', $privmsg_message);
1347 $privmsg_message = stripslashes($privmsg_message);
1351 // Do mode specific things
1353 if ( $mode == 'post' )
1355 $page_title = $lang['Post_new_pm'];
1357 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
1360 else if ( $mode == 'reply' )
1362 $page_title = $lang['Post_reply_pm'];
1364 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
1367 else if ( $mode == 'edit' )
1369 $page_title = $lang['Edit_pm'];
1371 $sql = "SELECT u.user_id, u.user_sig
1372 FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u
1373 WHERE pm.privmsgs_id = $privmsg_id
1374 AND u.user_id = pm.privmsgs_from_userid";
1375 if ( !($result = $db->sql_query($sql)) )
1377 message_die(GENERAL_ERROR, "Could not obtain post and post text", "", __LINE__, __FILE__, $sql);
1380 if ( $postrow = $db->sql_fetchrow($result) )
1382 if ( $userdata['user_id'] != $postrow['user_id'] )
1384 message_die(GENERAL_MESSAGE, $lang['Edit_own_posts']);
1387 $user_sig = ( $postrow['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow['user_sig'] : '';
1393 if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) )
1395 message_die(GENERAL_ERROR, $lang['No_post_id']);
1398 if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) )
1400 $user_id = intval($HTTP_GET_VARS[POST_USERS_URL]);
1402 $sql = "SELECT username
1403 FROM " . USERS_TABLE . "
1404 WHERE user_id = $user_id
1405 AND user_id <> " . ANONYMOUS;
1406 if ( !($result = $db->sql_query($sql)) )
1409 $error_msg = $lang['No_such_user'];
1412 if ( $row = $db->sql_fetchrow($result) )
1414 $to_username = $row['username'];
1418 if ( $mode == 'edit' )
1420 $sql = "SELECT pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id, u.user_sig
1421 FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
1422 WHERE pm.privmsgs_id = $privmsg_id
1423 AND pmt.privmsgs_text_id = pm.privmsgs_id
1424 AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1425 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1426 OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
1427 AND u.user_id = pm.privmsgs_to_userid";
1428 if ( !($result = $db->sql_query($sql)) )
1430 message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
1433 if ( !($privmsg = $db->sql_fetchrow($result)) )
1435 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
1438 $privmsg_subject = $privmsg['privmsgs_subject'];
1439 $privmsg_message = $privmsg['privmsgs_text'];
1440 $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
1441 $privmsg_bbcode_enabled = ($privmsg['privmsgs_enable_bbcode'] == 1);
1443 if ( $privmsg_bbcode_enabled )
1445 $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
1448 $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
1449 $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message);
1451 $user_sig = ( $board_config['allow_sig'] ) ? (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL) ? $user_sig : $privmsg['user_sig']) : '';
1453 $to_username = $privmsg['username'];
1454 $to_userid = $privmsg['user_id'];
1457 else if ( $mode == 'reply' || $mode == 'quote' )
1460 $sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id
1461 FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
1462 WHERE pm.privmsgs_id = $privmsg_id
1463 AND pmt.privmsgs_text_id = pm.privmsgs_id
1464 AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1465 AND u.user_id = pm.privmsgs_from_userid";
1466 if ( !($result = $db->sql_query($sql)) )
1468 message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
1471 if ( !($privmsg = $db->sql_fetchrow($result)) )
1473 redirect(append_sid("privmsg.$phpEx?folder=$folder", true));
1476 $privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ) . $privmsg['privmsgs_subject'];
1478 $to_username = $privmsg['username'];
1479 $to_userid = $privmsg['user_id'];
1481 if ( $mode == 'quote' )
1483 $privmsg_message = $privmsg['privmsgs_text'];
1484 $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
1486 $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
1487 $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
1488 $privmsg_message = preg_replace('#</textarea>#si', '</textarea>', $privmsg_message);
1490 $msg_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
1492 $privmsg_message = '[quote="' . $to_username . '"]' . $privmsg_message . '[/quote]';
1500 // Has admin prevented user from sending PM's?
1502 if ( !$userdata['user_allow_pm'] && $mode != 'edit' )
1504 $message = $lang['Cannot_send_privmsg'];
1505 message_die(GENERAL_MESSAGE, $message);
1509 // Start output, first preview, then errors then post form
1511 $page_title = $lang['Send_private_message'];
1512 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1514 if ( $preview && !$error )
1516 $orig_word = array();
1517 $replacement_word = array();
1518 obtain_word_list($orig_word, $replacement_word);
1522 $bbcode_uid = make_bbcode_uid();
1525 $preview_message = stripslashes(prepare_message($privmsg_message, $html_on, $bbcode_on, $smilies_on, $bbcode_uid));
1526 $privmsg_message = stripslashes(preg_replace($html_entities_match, $html_entities_replace, $privmsg_message));
1529 // Finalise processing as per viewtopic
1533 if ( $user_sig != '' || !$userdata['user_allowhtml'] )
1535 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
1539 if ( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] )
1541 $user_sig = bbencode_second_pass($user_sig, $userdata['user_sig_bbcode_uid']);
1546 $preview_message = bbencode_second_pass($preview_message, $bbcode_uid);
1549 if ( $attach_sig && $user_sig != '' )
1551 $preview_message = $preview_message . '<br /><br />_________________<br />' . $user_sig;
1554 if ( count($orig_word) )
1556 $preview_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject);
1557 $preview_message = preg_replace($orig_word, $replacement_word, $preview_message);
1561 $preview_subject = $privmsg_subject;
1566 $preview_message = smilies_pass($preview_message);
1569 $preview_message = make_clickable($preview_message);
1570 $preview_message = str_replace("\n", '<br />', $preview_message);
1572 $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
1573 $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
1575 if ( isset($privmsg_id) )
1577 $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
1580 $template->set_filenames(array(
1581 "preview" => 'privmsgs_preview.tpl')
1584 $template->assign_vars(array(
1585 'TOPIC_TITLE' => $preview_subject,
1586 'POST_SUBJECT' => $preview_subject,
1587 'MESSAGE_TO' => $to_username,
1588 'MESSAGE_FROM' => $userdata['username'],
1589 'POST_DATE' => create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']),
1590 'MESSAGE' => $preview_message,
1592 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1594 'L_SUBJECT' => $lang['Subject'],
1595 'L_DATE' => $lang['Date'],
1596 'L_FROM' => $lang['From'],
1597 'L_TO' => $lang['To'],
1598 'L_PREVIEW' => $lang['Preview'],
1599 'L_POSTED' => $lang['Posted'])
1602 $template->assign_var_from_handle('POST_PREVIEW_BOX', 'preview');
1606 // Start error handling
1610 $template->set_filenames(array(
1611 'reg_header' => 'error_body.tpl')
1613 $template->assign_vars(array(
1614 'ERROR_MESSAGE' => $error_msg)
1616 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
1622 $template->set_filenames(array(
1623 'body' => 'posting_body.tpl')
1625 make_jumpbox('viewforum.'.$phpEx);
1628 // Enable extensions in posting_body
1630 $template->assign_block_vars('switch_privmsg', array());
1633 // HTML toggle selection
1635 if ( $board_config['allow_html'] )
1637 $html_status = $lang['HTML_is_ON'];
1638 $template->assign_block_vars('switch_html_checkbox', array());
1642 $html_status = $lang['HTML_is_OFF'];
1646 // BBCode toggle selection
1648 if ( $board_config['allow_bbcode'] )
1650 $bbcode_status = $lang['BBCode_is_ON'];
1651 $template->assign_block_vars('switch_bbcode_checkbox', array());
1655 $bbcode_status = $lang['BBCode_is_OFF'];
1659 // Smilies toggle selection
1661 if ( $board_config['allow_smilies'] )
1663 $smilies_status = $lang['Smilies_are_ON'];
1664 $template->assign_block_vars('switch_smilies_checkbox', array());
1668 $smilies_status = $lang['Smilies_are_OFF'];
1672 // Signature toggle selection - only show if
1673 // the user has a signature
1675 if ( $user_sig != '' )
1677 $template->assign_block_vars('switch_signature_checkbox', array());
1680 if ( $mode == 'post' )
1682 $post_a = $lang['Send_a_new_message'];
1684 else if ( $mode == 'reply' )
1686 $post_a = $lang['Send_a_reply'];
1689 else if ( $mode == 'edit' )
1691 $post_a = $lang['Edit_message'];
1694 $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
1695 $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
1696 if ( $mode == 'edit' )
1698 $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
1702 // Send smilies to template
1704 generate_smilies('inline', PAGE_PRIVMSGS);
1706 $privmsg_subject = preg_replace($html_entities_match, $html_entities_replace, $privmsg_subject);
1707 $privmsg_subject = str_replace('"', '"', $privmsg_subject);
1709 $template->assign_vars(array(
1710 'SUBJECT' => $privmsg_subject,
1711 'USERNAME' => $to_username,
1712 'MESSAGE' => $privmsg_message,
1713 'HTML_STATUS' => $html_status,
1714 'SMILIES_STATUS' => $smilies_status,
1715 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
1716 'FORUM_NAME' => $lang['Private_Message'],
1718 'BOX_NAME' => $l_box_name,
1719 'INBOX_IMG' => $inbox_img,
1720 'SENTBOX_IMG' => $sentbox_img,
1721 'OUTBOX_IMG' => $outbox_img,
1722 'SAVEBOX_IMG' => $savebox_img,
1723 'INBOX' => $inbox_url,
1724 'SENTBOX' => $sentbox_url,
1725 'OUTBOX' => $outbox_url,
1726 'SAVEBOX' => $savebox_url,
1728 'L_SUBJECT' => $lang['Subject'],
1729 'L_MESSAGE_BODY' => $lang['Message_body'],
1730 'L_OPTIONS' => $lang['Options'],
1731 'L_SPELLCHECK' => $lang['Spellcheck'],
1732 'L_PREVIEW' => $lang['Preview'],
1733 'L_SUBMIT' => $lang['Submit'],
1734 'L_CANCEL' => $lang['Cancel'],
1735 'L_POST_A' => $post_a,
1736 'L_FIND_USERNAME' => $lang['Find_username'],
1737 'L_FIND' => $lang['Find'],
1738 'L_DISABLE_HTML' => $lang['Disable_HTML_pm'],
1739 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_pm'],
1740 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_pm'],
1741 'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
1743 'L_BBCODE_B_HELP' => $lang['bbcode_b_help'],
1744 'L_BBCODE_I_HELP' => $lang['bbcode_i_help'],
1745 'L_BBCODE_U_HELP' => $lang['bbcode_u_help'],
1746 'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'],
1747 'L_BBCODE_C_HELP' => $lang['bbcode_c_help'],
1748 'L_BBCODE_L_HELP' => $lang['bbcode_l_help'],
1749 'L_BBCODE_O_HELP' => $lang['bbcode_o_help'],
1750 'L_BBCODE_P_HELP' => $lang['bbcode_p_help'],
1751 'L_BBCODE_W_HELP' => $lang['bbcode_w_help'],
1752 'L_BBCODE_A_HELP' => $lang['bbcode_a_help'],
1753 'L_BBCODE_S_HELP' => $lang['bbcode_s_help'],
1754 'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],
1755 'L_EMPTY_MESSAGE' => $lang['Empty_message'],
1757 'L_FONT_COLOR' => $lang['Font_color'],
1758 'L_COLOR_DEFAULT' => $lang['color_default'],
1759 'L_COLOR_DARK_RED' => $lang['color_dark_red'],
1760 'L_COLOR_RED' => $lang['color_red'],
1761 'L_COLOR_ORANGE' => $lang['color_orange'],
1762 'L_COLOR_BROWN' => $lang['color_brown'],
1763 'L_COLOR_YELLOW' => $lang['color_yellow'],
1764 'L_COLOR_GREEN' => $lang['color_green'],
1765 'L_COLOR_OLIVE' => $lang['color_olive'],
1766 'L_COLOR_CYAN' => $lang['color_cyan'],
1767 'L_COLOR_BLUE' => $lang['color_blue'],
1768 'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'],
1769 'L_COLOR_INDIGO' => $lang['color_indigo'],
1770 'L_COLOR_VIOLET' => $lang['color_violet'],
1771 'L_COLOR_WHITE' => $lang['color_white'],
1772 'L_COLOR_BLACK' => $lang['color_black'],
1774 'L_FONT_SIZE' => $lang['Font_size'],
1775 'L_FONT_TINY' => $lang['font_tiny'],
1776 'L_FONT_SMALL' => $lang['font_small'],
1777 'L_FONT_NORMAL' => $lang['font_normal'],
1778 'L_FONT_LARGE' => $lang['font_large'],
1779 'L_FONT_HUGE' => $lang['font_huge'],
1781 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'],
1782 'L_STYLES_TIP' => $lang['Styles_tip'],
1784 'S_HTML_CHECKED' => ( !$html_on ) ? ' checked="checked"' : '',
1785 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? ' checked="checked"' : '',
1786 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? ' checked="checked"' : '',
1787 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? ' checked="checked"' : '',
1788 'S_NAMES_SELECT' => $user_names_select,
1789 'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields,
1790 'S_POST_ACTION' => append_sid("privmsg.$phpEx"),
1792 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser"),
1793 'U_VIEW_FORUM' => append_sid("privmsg.$phpEx"))
1796 $template->pparse('body');
1798 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1804 if ( !$userdata['session_logged_in'] )
1806 redirect(append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
1810 // Update unread status
1812 $sql = "UPDATE " . USERS_TABLE . "
1813 SET user_unread_privmsg = user_unread_privmsg + user_new_privmsg, user_new_privmsg = 0, user_last_privmsg = " . $userdata['session_start'] . "
1814 WHERE user_id = " . $userdata['user_id'];
1815 if ( !$db->sql_query($sql) )
1817 message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
1820 $sql = "UPDATE " . PRIVMSGS_TABLE . "
1821 SET privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
1822 WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1823 AND privmsgs_to_userid = " . $userdata['user_id'];
1824 if ( !$db->sql_query($sql) )
1826 message_die(GENERAL_ERROR, 'Could not update private message new/read status (2) for user', '', __LINE__, __FILE__, $sql);
1830 // Reset PM counters
1832 $userdata['user_new_privmsg'] = 0;
1833 $userdata['user_unread_privmsg'] = ( $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'] );
1838 $page_title = $lang['Private_Messaging'];
1839 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1844 $template->set_filenames(array(
1845 'body' => 'privmsgs_body.tpl')
1847 make_jumpbox('viewforum.'.$phpEx);
1849 $orig_word = array();
1850 $replacement_word = array();
1851 obtain_word_list($orig_word, $replacement_word);
1856 $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>';
1859 // General SQL to obtain messages
1861 $sql_tot = "SELECT COUNT(privmsgs_id) AS total
1862 FROM " . PRIVMSGS_TABLE . " ";
1863 $sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username
1864 FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u ";
1868 $sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
1869 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1870 OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1871 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1873 $sql .= "WHERE pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1874 AND u.user_id = pm.privmsgs_from_userid
1875 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1876 OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
1877 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1881 $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1882 AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1883 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1885 $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1886 AND u.user_id = pm.privmsgs_to_userid
1887 AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
1888 OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
1892 $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
1893 AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1895 $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1896 AND u.user_id = pm.privmsgs_to_userid
1897 AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
1901 $sql_tot .= "WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
1902 AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
1903 OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
1904 AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
1906 $sql .= "WHERE u.user_id = pm.privmsgs_from_userid
1907 AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
1908 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
1909 OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
1910 AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )";
1914 message_die(GENERAL_MESSAGE, $lang['No_such_folder']);
1919 // Show messages over previous x days/months
1921 if ( $submit_msgdays && ( !empty($HTTP_POST_VARS['msgdays']) || !empty($HTTP_GET_VARS['msgdays']) ) )
1923 $msg_days = ( !empty($HTTP_POST_VARS['msgdays']) ) ? intval($HTTP_POST_VARS['msgdays']) : intval($HTTP_GET_VARS['msgdays']);
1924 $min_msg_time = time() - ($msg_days * 86400);
1926 $limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
1927 $limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";
1929 if ( !empty($HTTP_POST_VARS['msgdays']) )
1936 $limit_msg_time = $limit_msg_time_total = '';
1940 $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $board_config['topics_per_page'];
1941 $sql_all_tot = $sql_tot;
1942 $sql_tot .= $limit_msg_time_total;
1947 if ( !($result = $db->sql_query($sql_tot)) )
1949 message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
1952 $pm_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
1954 if ( !($result = $db->sql_query($sql_all_tot)) )
1956 message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
1959 $pm_all_total = ( $row = $db->sql_fetchrow($result) ) ? $row['total'] : 0;
1964 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
1965 $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']);
1967 $select_msg_days = '';
1968 for($i = 0; $i < count($previous_days); $i++)
1970 $selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : '';
1971 $select_msg_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
1975 // Define correct icons
1980 $l_box_name = $lang['Inbox'];
1983 $l_box_name = $lang['Outbox'];
1986 $l_box_name = $lang['Savebox'];
1989 $l_box_name = $lang['Sentbox'];
1992 $post_pm = append_sid("privmsg.$phpEx?mode=post");
1993 $post_pm_img = '<a href="' . $post_pm . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0" /></a>';
1994 $post_pm = '<a href="' . $post_pm . '">' . $lang['Post_new_pm'] . '</a>';
1997 // Output data for inbox status
1999 if ( $folder != 'outbox' )
2001 $inbox_limit_pct = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_' . $folder . '_privmsgs'] ) * 100) : 100;
2002 $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'];
2003 $inbox_limit_remain = ( $board_config['max_' . $folder . '_privmsgs'] > 0 ) ? $board_config['max_' . $folder . '_privmsgs'] - $pm_all_total : 0;
2005 $template->assign_block_vars('switch_box_size_notice', array());
2010 $l_box_size_status = sprintf($lang['Inbox_size'], $inbox_limit_pct);
2013 $l_box_size_status = sprintf($lang['Sentbox_size'], $inbox_limit_pct);
2016 $l_box_size_status = sprintf($lang['Savebox_size'], $inbox_limit_pct);
2019 $l_box_size_status = '';
2025 // Dump vars to template
2027 $template->assign_vars(array(
2028 'BOX_NAME' => $l_box_name,
2029 'INBOX_IMG' => $inbox_img,
2030 'SENTBOX_IMG' => $sentbox_img,
2031 'OUTBOX_IMG' => $outbox_img,
2032 'SAVEBOX_IMG' => $savebox_img,
2033 'INBOX' => $inbox_url,
2034 'SENTBOX' => $sentbox_url,
2035 'OUTBOX' => $outbox_url,
2036 'SAVEBOX' => $savebox_url,
2038 'POST_PM_IMG' => $post_pm_img,
2039 'POST_PM' => $post_pm,
2041 'INBOX_LIMIT_IMG_WIDTH' => $inbox_limit_img_length,
2042 'INBOX_LIMIT_PERCENT' => $inbox_limit_pct,
2044 'BOX_SIZE_STATUS' => $l_box_size_status,
2046 'L_INBOX' => $lang['Inbox'],
2047 'L_OUTBOX' => $lang['Outbox'],
2048 'L_SENTBOX' => $lang['Sent'],
2049 'L_SAVEBOX' => $lang['Saved'],
2050 'L_MARK' => $lang['Mark'],
2051 'L_FLAG' => $lang['Flag'],
2052 'L_SUBJECT' => $lang['Subject'],
2053 'L_DATE' => $lang['Date'],
2054 'L_DISPLAY_MESSAGES' => $lang['Display_messages'],
2055 'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? $lang['From'] : $lang['To'],
2056 'L_MARK_ALL' => $lang['Mark_all'],
2057 'L_UNMARK_ALL' => $lang['Unmark_all'],
2058 'L_DELETE_MARKED' => $lang['Delete_marked'],
2059 'L_DELETE_ALL' => $lang['Delete_all'],
2060 'L_SAVE_MARKED' => $lang['Save_marked'],
2062 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
2063 'S_HIDDEN_FIELDS' => '',
2064 'S_POST_NEW_MSG' => $post_new_mesg_url,
2065 'S_SELECT_MSG_DAYS' => $select_msg_days,
2067 'U_POST_NEW_TOPIC' => append_sid("privmsg.$phpEx?mode=post"))
2071 // Okay, let's build the correct folder
2073 if ( !($result = $db->sql_query($sql)) )
2075 message_die(GENERAL_ERROR, 'Could not query private messages', '', __LINE__, __FILE__, $sql);
2078 if ( $row = $db->sql_fetchrow($result) )
2083 $privmsg_id = $row['privmsgs_id'];
2085 $flag = $row['privmsgs_type'];
2087 $icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg'];
2088 $icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $lang['Unread_message'] : $lang['Read_message'];
2090 $msg_userid = $row['user_id'];
2091 $msg_username = $row['username'];
2093 $u_from_user_profile = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$msg_userid");
2095 $msg_subject = $row['privmsgs_subject'];
2097 if ( count($orig_word) )
2099 $msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject);
2102 $u_subject = append_sid("privmsg.$phpEx?folder=$folder&mode=read&" . POST_POST_URL . "=$privmsg_id");
2104 $msg_date = create_date($board_config['default_dateformat'], $row['privmsgs_date'], $board_config['board_timezone']);
2106 if ( $flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox' )
2108 $msg_subject = '<b>' . $msg_subject . '</b>';
2109 $msg_date = '<b>' . $msg_date . '</b>';
2110 $msg_username = '<b>' . $msg_username . '</b>';
2113 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
2114 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
2117 $template->assign_block_vars('listrow', array(
2118 'ROW_COLOR' => '#' . $row_color,
2119 'ROW_CLASS' => $row_class,
2120 'FROM' => $msg_username,
2121 'SUBJECT' => $msg_subject,
2122 'DATE' => $msg_date,
2123 'PRIVMSG_FOLDER_IMG' => $icon_flag,
2125 'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt,
2127 'S_MARK_ID' => $privmsg_id,
2129 'U_READ' => $u_subject,
2130 'U_FROM_USER_PROFILE' => $u_from_user_profile)
2133 while( $row = $db->sql_fetchrow($result) );
2135 $template->assign_vars(array(
2136 'PAGINATION' => generate_pagination("privmsg.$phpEx?folder=$folder", $pm_total, $board_config['topics_per_page'], $start),
2137 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $pm_total / $board_config['topics_per_page'] )),
2139 'L_GOTO_PAGE' => $lang['Goto_page'])
2145 $template->assign_vars(array(
2146 'L_NO_MESSAGES' => $lang['No_messages_folder'])
2149 $template->assign_block_vars("switch_no_messages", array() );
2152 $template->pparse('body');
2154 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);