phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / privmsg.php

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