phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / privmsg.php

History | View | Annotate | Download (67 kB)

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