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