phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / privmsg.php

History | View | Annotate | Download (67 kB)

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