PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/doweneed/forums/privmsg.php

https://bitbucket.org/natis/masscap-main
PHP | 1997 lines | 1510 code | 289 blank | 198 comment | 318 complexity | d5303bf2450fb76cf33fc0cfe539cc7c MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  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.9 2002/07/19 15:19:31 psotfx Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. define('IN_PHPBB', true);
  22. $phpbb_root_path = './';
  23. include($phpbb_root_path . 'extension.inc');
  24. include($phpbb_root_path . 'common.'.$phpEx);
  25. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  26. include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
  27. //
  28. // Is PM disabled?
  29. //
  30. if ( !empty($board_config['privmsg_disable']) )
  31. {
  32. message_die(GENERAL_MESSAGE, 'PM_disabled');
  33. }
  34. $html_entities_match = array('#&#', '#<#', '#>#');
  35. $html_entities_replace = array('&amp;', '&lt;', '&gt;');
  36. //
  37. // Parameters
  38. //
  39. $submit = ( isset($HTTP_POST_VARS['post']) ) ? TRUE : 0;
  40. $submit_search = ( isset($HTTP_POST_VARS['usersubmit']) ) ? TRUE : 0;
  41. $submit_msgdays = ( isset($HTTP_POST_VARS['submit_msgdays']) ) ? TRUE : 0;
  42. $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? TRUE : 0;
  43. $preview = ( isset($HTTP_POST_VARS['preview']) ) ? TRUE : 0;
  44. $confirm = ( isset($HTTP_POST_VARS['confirm']) ) ? TRUE : 0;
  45. $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : 0;
  46. $delete_all = ( isset($HTTP_POST_VARS['deleteall']) ) ? TRUE : 0;
  47. $save = ( isset($HTTP_POST_VARS['save']) ) ? TRUE : 0;
  48. $refresh = $preview || $submit_search;
  49. $mark_list = ( !empty($HTTP_POST_VARS['mark']) ) ? $HTTP_POST_VARS['mark'] : 0;
  50. if ( isset($HTTP_POST_VARS['folder']) || isset($HTTP_GET_VARS['folder']) )
  51. {
  52. $folder = ( isset($HTTP_POST_VARS['folder']) ) ? $HTTP_POST_VARS['folder'] : $HTTP_GET_VARS['folder'];
  53. if ( $folder != 'inbox' && $folder != 'outbox' && $folder != 'sentbox' && $folder != 'savebox' )
  54. {
  55. $folder = 'inbox';
  56. }
  57. }
  58. else
  59. {
  60. $folder = 'inbox';
  61. }
  62. //
  63. // Start session management
  64. //
  65. $userdata = session_pagestart($user_ip, PAGE_PRIVMSGS);
  66. init_userprefs($userdata);
  67. //
  68. // End session management
  69. //
  70. //
  71. // Cancel
  72. //
  73. if ( $cancel )
  74. {
  75. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  76. header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true));
  77. exit;
  78. }
  79. //
  80. // Var definitions
  81. //
  82. if ( !empty($HTTP_POST_VARS['mode']) || !empty($HTTP_GET_VARS['mode']) )
  83. {
  84. $mode = ( !empty($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  85. }
  86. else
  87. {
  88. $mode = '';
  89. }
  90. $start = ( !empty($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  91. if ( isset($HTTP_POST_VARS[POST_POST_URL]) || isset($HTTP_GET_VARS[POST_POST_URL]) )
  92. {
  93. $privmsg_id = ( isset($HTTP_POST_VARS[POST_POST_URL]) ) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
  94. }
  95. else
  96. {
  97. $privmsg_id = '';
  98. }
  99. $error = FALSE;
  100. //
  101. // Define the box image links
  102. //
  103. $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'] . '" />';
  104. $inbox_url = ( $folder != 'inbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '">' . $lang['Inbox'] . '</a>' : $lang['Inbox'];
  105. $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'] . '" />';
  106. $outbox_url = ( $folder != 'outbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=outbox") . '">' . $lang['Outbox'] . '</a>' : $lang['Outbox'];
  107. $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'] . '" />';
  108. $sentbox_url = ( $folder != 'sentbox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=sentbox") . '">' . $lang['Sentbox'] . '</a>' : $lang['Sentbox'];
  109. $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'] . '" />';
  110. $savebox_url = ( $folder != 'savebox' || $mode != '' ) ? '<a href="' . append_sid("privmsg.$phpEx?folder=savebox") . '">' . $lang['Savebox'] . '</a>' : $lang['Savebox'];
  111. // ----------
  112. // Start main
  113. //
  114. if ( $mode == 'newpm' )
  115. {
  116. $gen_simple_header = TRUE;
  117. $page_title = $lang['Private_Messaging'];
  118. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  119. $template->set_filenames(array(
  120. 'body' => 'privmsgs_popup.tpl')
  121. );
  122. if ( $userdata['session_logged_in'] )
  123. {
  124. if ( $userdata['user_new_privmsg'] )
  125. {
  126. $l_new_message = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['You_new_pm'] : $lang['You_new_pms'];
  127. }
  128. else
  129. {
  130. $l_new_message = $lang['You_no_new_pm'];
  131. }
  132. $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>');
  133. }
  134. else
  135. {
  136. $l_new_message = $lang['Login_check_pm'];
  137. }
  138. $template->assign_vars(array(
  139. 'L_CLOSE_WINDOW' => $lang['Close_window'],
  140. 'L_MESSAGE' => $l_new_message)
  141. );
  142. $template->pparse('body');
  143. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  144. }
  145. else if ( $mode == 'read' )
  146. {
  147. if ( !empty($HTTP_GET_VARS[POST_POST_URL]) )
  148. {
  149. $privmsgs_id = intval($HTTP_GET_VARS[POST_POST_URL]);
  150. }
  151. else
  152. {
  153. message_die(GENERAL_ERROR, $lang['No_post_id']);
  154. }
  155. if ( !$userdata['session_logged_in'] )
  156. {
  157. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  158. header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode&" . POST_POST_URL . "=$privmsgs_id", true));
  159. exit;
  160. }
  161. //
  162. // SQL to pull appropriate message, prevents nosey people
  163. // reading other peoples messages ... hopefully!
  164. //
  165. switch( $folder )
  166. {
  167. case 'inbox':
  168. $l_box_name = $lang['Inbox'];
  169. $pm_sql_user = "AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  170. AND ( pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  171. OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  172. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  173. break;
  174. case 'outbox':
  175. $l_box_name = $lang['Outbox'];
  176. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  177. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  178. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
  179. break;
  180. case 'sentbox':
  181. $l_box_name = $lang['Sentbox'];
  182. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  183. AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  184. break;
  185. case 'savebox':
  186. $l_box_name = $lang['Savebox'];
  187. $pm_sql_user .= "AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  188. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  189. OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  190. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  191. )";
  192. break;
  193. default:
  194. message_die(GENERAL_ERROR, $lang['No_such_folder']);
  195. break;
  196. }
  197. //
  198. // Major query obtains the message ...
  199. //
  200. $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
  201. FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
  202. WHERE pm.privmsgs_id = $privmsgs_id
  203. AND pmt.privmsgs_text_id = pm.privmsgs_id
  204. $pm_sql_user
  205. AND u.user_id = pm.privmsgs_from_userid
  206. AND u2.user_id = pm.privmsgs_to_userid";
  207. if ( !($result = $db->sql_query($sql)) )
  208. {
  209. message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql);
  210. }
  211. //
  212. // Did the query return any data?
  213. //
  214. if ( !($privmsg = $db->sql_fetchrow($result)) )
  215. {
  216. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  217. header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true));
  218. exit;
  219. }
  220. $privmsg_id = $privmsg['privmsgs_id'];
  221. //
  222. // Is this a new message in the inbox? If it is then save
  223. // a copy in the posters sent box
  224. //
  225. if ( ( $privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL ) && $folder == 'inbox' )
  226. {
  227. $sql = "UPDATE " . PRIVMSGS_TABLE . "
  228. SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  229. WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
  230. if ( !$db->sql_query($sql) )
  231. {
  232. message_die(GENERAL_ERROR, 'Could not update private message read status', '', __LINE__, __FILE__, $sql);
  233. }
  234. $sql = "UPDATE " . USERS_TABLE . "
  235. SET user_unread_privmsg = user_unread_privmsg - 1
  236. WHERE user_id = " . $userdata['user_id'];
  237. if ( !$db->sql_query($sql) )
  238. {
  239. message_die(GENERAL_ERROR, 'Could not update private message read status for user', '', __LINE__, __FILE__, $sql);
  240. }
  241. //
  242. // Check to see if the poster has a 'full' sent box
  243. //
  244. $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time
  245. FROM " . PRIVMSGS_TABLE . "
  246. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  247. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  248. if ( !($result = $db->sql_query($sql)) )
  249. {
  250. message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
  251. }
  252. $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
  253. if ( $sent_info = $db->sql_fetchrow($result) )
  254. {
  255. if ( $sent_info['sent_items'] >= $board_config['max_sentbox_privmsgs'] )
  256. {
  257. $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
  258. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  259. AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
  260. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  261. if ( !$db->sql_query($sql) )
  262. {
  263. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql);
  264. }
  265. }
  266. }
  267. //
  268. // This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
  269. // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
  270. // set limits on numbers of storable posts for users ... hopefully!
  271. //
  272. $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)
  273. 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'] . ")";
  274. if ( !$db->sql_query($sql) )
  275. {
  276. message_die(GENERAL_ERROR, 'Could not insert private message sent info', '', __LINE__, __FILE__, $sql);
  277. }
  278. $privmsg_sent_id = $db->sql_nextid();
  279. $sql = "INSERT $sql_priority INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
  280. VALUES ($privmsg_sent_id, '" . $privmsg['privmsgs_bbcode_uid'] . "', '" . str_replace("\'", "''", addslashes($privmsg['privmsgs_text'])) . "')";
  281. if ( !$db->sql_query($sql) )
  282. {
  283. message_die(GENERAL_ERROR, 'Could not insert private message sent text', '', __LINE__, __FILE__, $sql);
  284. }
  285. }
  286. //
  287. // Pick a folder, any folder, so long as it's one below ...
  288. //
  289. $post_urls = array(
  290. 'post' => append_sid("privmsg.$phpEx?mode=post"),
  291. 'reply' => append_sid("privmsg.$phpEx?mode=reply&amp;" . POST_POST_URL . "=$privmsg_id"),
  292. 'quote' => append_sid("privmsg.$phpEx?mode=quote&amp;" . POST_POST_URL . "=$privmsg_id"),
  293. 'edit' => append_sid("privmsg.$phpEx?mode=edit&amp;" . POST_POST_URL . "=$privmsg_id")
  294. );
  295. $post_icons = array(
  296. 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" border="0"></a>',
  297. 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['Post_new_pm'] . '</a>',
  298. 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['Post_reply_pm'] . '" border="0"></a>',
  299. 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['Post_reply_pm'] . '</a>',
  300. 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['Post_quote_pm'] . '" border="0"></a>',
  301. 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['Post_quote_pm'] . '</a>',
  302. 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['Edit_pm'] . '" border="0"></a>',
  303. 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['Edit_pm'] . '</a>'
  304. );
  305. if ( $folder == 'inbox' )
  306. {
  307. $post_img = $post_icons['post_img'];
  308. $reply_img = $post_icons['reply_img'];
  309. $quote_img = $post_icons['quote_img'];
  310. $edit_img = '';
  311. $post = $post_icons['post'];
  312. $reply = $post_icons['reply'];
  313. $quote = $post_icons['quote'];
  314. $edit = '';
  315. $l_box_name = $lang['Inbox'];
  316. }
  317. else if ( $folder == 'outbox' )
  318. {
  319. $post_img = $post_icons['post_img'];
  320. $reply_img = '';
  321. $quote_img = '';
  322. $edit_img = $post_icons['edit_img'];
  323. $post = $post_icons['post'];
  324. $reply = '';
  325. $quote = '';
  326. $edit = $post_icons['edit'];
  327. $l_box_name = $lang['Outbox'];
  328. }
  329. else if ( $folder == 'savebox' )
  330. {
  331. if ( $privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL )
  332. {
  333. $post_img = $post_icons['post_img'];
  334. $reply_img = $post_icons['reply_img'];
  335. $quote_img = $post_icons['quote_img'];
  336. $edit_img = '';
  337. $post = $post_icons['post'];
  338. $reply = $post_icons['reply'];
  339. $quote = $post_icons['quote'];
  340. $edit = '';
  341. }
  342. else
  343. {
  344. $post_img = $post_icons['post_img'];
  345. $reply_img = '';
  346. $quote_img = '';
  347. $edit_img = '';
  348. $post = $post_icons['post'];
  349. $reply = '';
  350. $quote = '';
  351. $edit = '';
  352. }
  353. $l_box_name = $lang['Saved'];
  354. }
  355. else if ( $folder == 'sentbox' )
  356. {
  357. $post_img = $post_icons['post_img'];
  358. $reply_img = '';
  359. $quote_img = '';
  360. $edit_img = '';
  361. $post = $post_icons['post'];
  362. $reply = '';
  363. $quote = '';
  364. $edit = '';
  365. $l_box_name = $lang['Sent'];
  366. }
  367. $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />';
  368. $page_title = $lang['Read_pm'];
  369. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  370. //
  371. // Load templates
  372. //
  373. $template->set_filenames(array(
  374. 'body' => 'privmsgs_read_body.tpl')
  375. );
  376. make_jumpbox('viewforum.'.$phpEx);
  377. $template->assign_vars(array(
  378. 'INBOX_IMG' => $inbox_img,
  379. 'SENTBOX_IMG' => $sentbox_img,
  380. 'OUTBOX_IMG' => $outbox_img,
  381. 'SAVEBOX_IMG' => $savebox_img,
  382. 'INBOX' => $inbox_url,
  383. 'POST_PM_IMG' => $post_img,
  384. 'REPLY_PM_IMG' => $reply_img,
  385. 'EDIT_PM_IMG' => $edit_img,
  386. 'QUOTE_PM_IMG' => $quote_img,
  387. 'POST_PM' => $post,
  388. 'REPLY_PM' => $reply,
  389. 'EDIT_PM' => $edit,
  390. 'QUOTE_PM' => $quote,
  391. 'SENTBOX' => $sentbox_url,
  392. 'OUTBOX' => $outbox_url,
  393. 'SAVEBOX' => $savebox_url,
  394. 'BOX_NAME' => $l_box_name,
  395. 'L_MESSAGE' => $lang['Message'],
  396. 'L_INBOX' => $lang['Inbox'],
  397. 'L_OUTBOX' => $lang['Outbox'],
  398. 'L_SENTBOX' => $lang['Sent'],
  399. 'L_SAVEBOX' => $lang['Saved'],
  400. 'L_FLAG' => $lang['Flag'],
  401. 'L_SUBJECT' => $lang['Subject'],
  402. 'L_POSTED' => $lang['Posted'],
  403. 'L_DATE' => $lang['Date'],
  404. 'L_FROM' => $lang['From'],
  405. 'L_TO' => $lang['To'],
  406. 'L_SAVE_MSG' => $lang['Save_message'],
  407. 'L_DELETE_MSG' => $lang['Delete_message'],
  408. 'S_PRIVMSGS_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
  409. 'S_HIDDEN_FIELDS' => $s_hidden_fields)
  410. );
  411. $username_from = $privmsg['username_1'];
  412. $user_id_from = $privmsg['user_id_1'];
  413. $username_to = $privmsg['username_2'];
  414. $user_id_to = $privmsg['user_id_2'];
  415. $post_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
  416. $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $user_id_from);
  417. $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['Read_profile'] . '" title="' . $lang['Read_profile'] . '" border="0" /></a>';
  418. $profile = '<a href="' . $temp_url . '">' . $lang['Read_profile'] . '</a>';
  419. $temp_url = append_sid("privmsg.$phpEx?mode=post&amp;" . POST_USERS_URL . "=$poster_id");
  420. $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['Send_private_message'] . '" title="' . $lang['Send_private_message'] . '" border="0" /></a>';
  421. $pm = '<a href="' . $temp_url . '">' . $lang['Send_private_message'] . '</a>';
  422. if ( !empty($privmsg['user_viewemail']) || $userdata['user_level'] == ADMIN )
  423. {
  424. $email_uri = ( $board_config['board_email_form'] ) ? append_sid("profile.$phpEx?mode=email&amp;" . POST_USERS_URL .'=' . $user_id_from) : 'mailto:' . $privmsg['user_email'];
  425. $email_img = '<a href="' . $email_uri . '"><img src="' . $images['icon_email'] . '" alt="' . $lang['Send_email'] . '" title="' . $lang['Send_email'] . '" border="0" /></a>';
  426. $email = '<a href="' . $email_uri . '">' . $lang['Send_email'] . '</a>';
  427. }
  428. else
  429. {
  430. $email_img = '';
  431. $email = '';
  432. }
  433. $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>' : '';
  434. $www = ( $privmsg['user_website'] ) ? '<a href="' . $privmsg['user_website'] . '" target="_userwww">' . $lang['Visit_website'] . '</a>' : '';
  435. if ( !empty($privmsg['user_icq']) )
  436. {
  437. $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>';
  438. $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>';
  439. $icq = '<a href="http://wwp.icq.com/scripts/search.dll?to=' . $privmsg['user_icq'] . '">' . $lang['ICQ'] . '</a>';
  440. }
  441. else
  442. {
  443. $icq_status_img = '';
  444. $icq_img = '';
  445. $icq = '';
  446. }
  447. $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>' : '';
  448. $aim = ( $privmsg['user_aim'] ) ? '<a href="aim:goim?screenname=' . $privmsg['user_aim'] . '&amp;message=Hello+Are+you+there?">' . $lang['AIM'] . '</a>' : '';
  449. $temp_url = append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$poster_id");
  450. $msn_img = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '"><img src="' . $images['icon_msnm'] . '" alt="' . $lang['MSNM'] . '" title="' . $lang['MSNM'] . '" border="0" /></a>' : '';
  451. $msn = ( $privmsg['user_msnm'] ) ? '<a href="' . $temp_url . '">' . $lang['MSNM'] . '</a>' : '';
  452. $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>' : '';
  453. $yim = ( $privmsg['user_yim'] ) ? '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $privmsg['user_yim'] . '&amp;.src=pg">' . $lang['YIM'] . '</a>' : '';
  454. $temp_url = append_sid("search.$phpEx?search_author=" . urlencode($username_from) . "&amp;showresults=posts");
  455. $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . $lang['Search_user_posts'] . '" title="' . $lang['Search_user_posts'] . '" border="0" /></a>';
  456. $search = '<a href="' . $temp_url . '">' . $lang['Search_user_posts'] . '</a>';
  457. //
  458. // Processing of post
  459. //
  460. $post_subject = $privmsg['privmsgs_subject'];
  461. $private_message = $privmsg['privmsgs_text'];
  462. $bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
  463. if ( $board_config['allow_sig'] )
  464. {
  465. $user_sig = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig'] : $privmsg['user_sig'];
  466. }
  467. else
  468. {
  469. $user_sig = '';
  470. }
  471. $user_sig_bbcode_uid = ( $privmsg['privmsgs_from_userid'] == $userdata['user_id'] ) ? $userdata['user_sig_bbcode_uid'] : $privmsg['user_sig_bbcode_uid'];
  472. //
  473. // If the board has HTML off but the post has HTML
  474. // on then we process it, else leave it alone
  475. //
  476. if ( !$board_config['allow_html'] )
  477. {
  478. if ( $user_sig != '' && $privmsg['privmsgs_enable_sig'] && $userdata['user_allowhtml'] )
  479. {
  480. $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
  481. }
  482. if ( $privmsg['privmsgs_enable_html'] )
  483. {
  484. $private_message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $private_message);
  485. }
  486. }
  487. if ( $user_sig != '' && $privmsg['privmsgs_attach_sig'] && $user_sig_bbcode_uid != '' )
  488. {
  489. $user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
  490. }
  491. if ( $bbcode_uid != '' )
  492. {
  493. $private_message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($private_message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $private_message);
  494. }
  495. $private_message = make_clickable($private_message);
  496. if ( $privmsg['privmsgs_attach_sig'] && $user_sig != '' )
  497. {
  498. $private_message .= '<br /><br />_________________<br />' . make_clickable($user_sig);
  499. }
  500. $orig_word = array();
  501. $replacement_word = array();
  502. obtain_word_list($orig_word, $replacement_word);
  503. if ( count($orig_word) )
  504. {
  505. $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
  506. $private_message = preg_replace($orig_word, $replacement_word, $private_message);
  507. }
  508. if ( $board_config['allow_smilies'] && $privmsg['privmsgs_enable_smilies'] )
  509. {
  510. $private_message = smilies_pass($private_message);
  511. }
  512. $private_message = str_replace("\n", '<br />', $private_message);
  513. //
  514. // Dump it to the templating engine
  515. //
  516. $template->assign_vars(array(
  517. 'MESSAGE_TO' => $username_to,
  518. 'MESSAGE_FROM' => $username_from,
  519. 'RANK_IMAGE' => $rank_image,
  520. 'POSTER_JOINED' => $poster_joined,
  521. 'POSTER_POSTS' => $poster_posts,
  522. 'POSTER_FROM' => $poster_from,
  523. 'POSTER_AVATAR' => $poster_avatar,
  524. 'POST_SUBJECT' => $post_subject,
  525. 'POST_DATE' => $post_date,
  526. 'MESSAGE' => $private_message,
  527. 'PROFILE_IMG' => $profile_img,
  528. 'PROFILE' => $profile,
  529. 'SEARCH_IMG' => $search_img,
  530. 'SEARCH' => $search,
  531. 'EMAIL_IMG' => $email_img,
  532. 'EMAIL' => $email,
  533. 'WWW_IMG' => $www_img,
  534. 'WWW' => $www,
  535. 'ICQ_STATUS_IMG' => $icq_status_img,
  536. 'ICQ_IMG' => $icq_img,
  537. 'ICQ' => $icq,
  538. 'AIM_IMG' => $aim_img,
  539. 'AIM' => $aim,
  540. 'MSN_IMG' => $msn_img,
  541. 'MSN' => $msn,
  542. 'YIM_IMG' => $yim_img,
  543. 'YIM' => $yim)
  544. );
  545. $template->pparse('body');
  546. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  547. }
  548. else if ( ( $delete && $mark_list ) || $delete_all )
  549. {
  550. if ( !$userdata['session_logged_in'] )
  551. {
  552. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  553. header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
  554. exit;
  555. }
  556. if ( isset($mark_list) && !is_array($mark_list) )
  557. {
  558. // Set to empty array instead of '0' if nothing is selected.
  559. $mark_list = array();
  560. }
  561. if ( !$confirm )
  562. {
  563. $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
  564. $s_hidden_fields .= ( isset($HTTP_POST_VARS['delete']) ) ? '<input type="hidden" name="delete" value="true" />' : '<input type="hidden" name="deleteall" value="true" />';
  565. for($i = 0; $i < count($mark_list); $i++)
  566. {
  567. $s_hidden_fields .= '<input type="hidden" name="mark[]" value="' . $mark_list[$i] . '" />';
  568. }
  569. //
  570. // Output confirmation page
  571. //
  572. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  573. $template->set_filenames(array(
  574. 'confirm_body' => 'confirm_body.tpl')
  575. );
  576. $template->assign_vars(array(
  577. 'MESSAGE_TITLE' => $lang['Information'],
  578. 'MESSAGE_TEXT' => ( count($mark_list) == 1 ) ? $lang['Confirm_delete_pm'] : $lang['Confirm_delete_pms'],
  579. 'L_YES' => $lang['Yes'],
  580. 'L_NO' => $lang['No'],
  581. 'S_CONFIRM_ACTION' => append_sid("privmsg.$phpEx?folder=$folder"),
  582. 'S_HIDDEN_FIELDS' => $s_hidden_fields)
  583. );
  584. $template->pparse('confirm_body');
  585. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  586. }
  587. else if ( $confirm )
  588. {
  589. if ( $delete_all )
  590. {
  591. switch($folder)
  592. {
  593. case 'inbox':
  594. $delete_type = "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
  595. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  596. break;
  597. case 'outbox':
  598. $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  599. break;
  600. case 'sentbox':
  601. $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  602. break;
  603. case 'savebox':
  604. $delete_type = "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
  605. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  606. OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
  607. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
  608. break;
  609. }
  610. $sql = "SELECT privmsgs_id
  611. FROM " . PRIVMSGS_TABLE . "
  612. WHERE $delete_type";
  613. if ( !($result = $db->sql_query($sql)) )
  614. {
  615. message_die(GENERAL_ERROR, 'Could not obtain id list to delete all messages', '', __LINE__, __FILE__, $sql);
  616. }
  617. while ( $row = $db->sql_fetchrow($result) )
  618. {
  619. $mark_list[] = $row['privmsgs_id'];
  620. }
  621. unset($delete_type);
  622. }
  623. if ( count($mark_list) )
  624. {
  625. $delete_sql_id = implode(', ', $mark_list);
  626. //
  627. // Need to decrement the new message counter of recipient
  628. // problem is this doesn't affect the unread counter even
  629. // though it may be the one that needs changing ... hhmmm
  630. //
  631. if ( $folder == 'outbox' )
  632. {
  633. $sql = "SELECT privmsgs_to_userid
  634. FROM " . PRIVMSGS_TABLE . "
  635. WHERE privmsgs_id IN ($delete_sql_id)
  636. AND privmsgs_from_userid = " . $userdata['user_id'] . "
  637. AND privmsgs_type = " . PRIVMSGS_NEW_MAIL;
  638. if ( !($result = $db->sql_query($sql)) )
  639. {
  640. message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
  641. }
  642. $update_pm_sql = '';
  643. while( $row = $db->sql_fetchrow($result) )
  644. {
  645. $update_pm_sql .= ( ( $update_pm_sql != '' ) ? ', ' : '' ) . $row['privmsgs_to_userid'];
  646. }
  647. if ( $update_pm_sql != '' )
  648. {
  649. $sql = "UPDATE " . USERS_TABLE . "
  650. SET user_new_privmsg = user_new_privmsg - 1
  651. WHERE user_id IN ($update_pm_sql)";
  652. if ( !$db->sql_query($sql) )
  653. {
  654. message_die(GENERAL_ERROR, 'Could not update users new msg counters', '', __LINE__, __FILE__, $sql);
  655. }
  656. }
  657. $sql = "SELECT privmsgs_to_userid
  658. FROM " . PRIVMSGS_TABLE . "
  659. WHERE privmsgs_id IN ($delete_sql_id)
  660. AND privmsgs_from_userid = " . $userdata['user_id'] . "
  661. AND privmsgs_type = " . PRIVMSGS_UNREAD_MAIL;
  662. if ( !($result = $db->sql_query($sql)) )
  663. {
  664. message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
  665. }
  666. $update_pm_sql = '';
  667. while( $row = $db->sql_fetchrow($result) )
  668. {
  669. $update_pm_sql .= ( ( $update_pm_sql != '' ) ? ', ' : '' ) . $row['privmsgs_to_userid'];
  670. }
  671. if ( $update_pm_sql != '' )
  672. {
  673. $sql = "UPDATE " . USERS_TABLE . "
  674. SET user_unread_privmsg = user_unread_privmsg - 1
  675. WHERE user_id IN ($update_pm_sql)";
  676. if ( !$db->sql_query($sql) )
  677. {
  678. message_die(GENERAL_ERROR, 'Could not update users new msg counters', '', __LINE__, __FILE__, $sql);
  679. }
  680. }
  681. }
  682. $delete_text_sql = "DELETE FROM " . PRIVMSGS_TEXT_TABLE . "
  683. WHERE privmsgs_text_id IN ($delete_sql_id)";
  684. $delete_sql = "DELETE FROM " . PRIVMSGS_TABLE . "
  685. WHERE privmsgs_id IN ($delete_sql_id)
  686. AND ";
  687. switch( $folder )
  688. {
  689. case 'inbox':
  690. $delete_sql .= "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
  691. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  692. break;
  693. case 'outbox':
  694. $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND (
  695. privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  696. break;
  697. case 'sentbox':
  698. $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  699. break;
  700. case 'savebox':
  701. $delete_sql .= "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
  702. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  703. OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
  704. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
  705. break;
  706. }
  707. if ( !$db->sql_query($delete_sql, BEGIN_TRANSACTION) )
  708. {
  709. message_die(GENERAL_ERROR, 'Could not delete private message info', '', __LINE__, __FILE__, $delete_sql);
  710. }
  711. if ( !$db->sql_query($delete_text_sql, END_TRANSACTION) )
  712. {
  713. message_die(GENERAL_ERROR, 'Could not delete private message text', '', __LINE__, __FILE__, $delete_text_sql);
  714. }
  715. }
  716. }
  717. }
  718. else if ( $save && $mark_list && $folder != 'savebox' && $folder != 'outbox' )
  719. {
  720. if ( !$userdata['session_logged_in'] )
  721. {
  722. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  723. header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=inbox", true));
  724. exit;
  725. }
  726. //
  727. // See if recipient is at their savebox limit
  728. //
  729. $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time
  730. FROM " . PRIVMSGS_TABLE . "
  731. WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
  732. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  733. OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
  734. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
  735. if ( !($result = $db->sql_query($sql)) )
  736. {
  737. message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
  738. }
  739. $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
  740. if ( $saved_info = $db->sql_fetchrow($result) )
  741. {
  742. if ( $saved_info['savebox_items'] >= $board_config['max_savebox_privmsgs'] )
  743. {
  744. $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
  745. WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
  746. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  747. OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
  748. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )
  749. AND privmsgs_date = " . $saved_info['oldest_post_time'];
  750. if ( !$db->sql_query($sql) )
  751. {
  752. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql);
  753. }
  754. }
  755. }
  756. //
  757. // Process request
  758. //
  759. $saved_sql = "UPDATE " . PRIVMSGS_TABLE;
  760. switch( $folder )
  761. {
  762. case 'inbox':
  763. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
  764. WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
  765. AND ( privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  766. OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  767. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  768. break;
  769. case 'outbox':
  770. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  771. WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  772. AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  773. OR privmsgs_type = " . PRIVMSGS_UNERAD_MAIL . " ) ";
  774. break;
  775. case 'sentbox':
  776. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  777. WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  778. AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  779. break;
  780. }
  781. if ( count($mark_list) )
  782. {
  783. $saved_sql_id = '';
  784. for($i = 0; $i < count($mark_list); $i++)
  785. {
  786. $saved_sql_id .= ( ( $saved_sql_id != '' ) ? ', ' : '' ) . $mark_list[$i];
  787. }
  788. $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
  789. if ( !$db->sql_query($saved_sql) )
  790. {
  791. message_die(GENERAL_ERROR, 'Could not save private messages', '', __LINE__, __FILE__, $saved_sql);
  792. }
  793. }
  794. }
  795. else if ( $submit || $refresh || $mode != '' )
  796. {
  797. if ( !$userdata['session_logged_in'] )
  798. {
  799. $user_id = ( isset($HTTP_GET_VARS[POST_USERS_URL]) ) ? '&' . POST_USERS_URL . '=' . intval($HTTP_GET_VARS[POST_USERS_URL]) : '';
  800. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  801. header($header_location . append_sid("login.$phpEx?redirect=privmsg.$phpEx&folder=$folder&mode=$mode" . $user_id, true));
  802. exit;
  803. }
  804. //
  805. // Toggles
  806. //
  807. if ( !$board_config['allow_html'] )
  808. {
  809. $html_on = 0;
  810. }
  811. else
  812. {
  813. $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : $userdata['user_allowhtml'];
  814. }
  815. if ( !$board_config['allow_bbcode'] )
  816. {
  817. $bbcode_on = 0;
  818. }
  819. else
  820. {
  821. $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : $userdata['user_allowbbcode'];
  822. }
  823. if ( !$board_config['allow_smilies'] )
  824. {
  825. $smilies_on = 0;
  826. }
  827. else
  828. {
  829. $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : $userdata['user_allowsmile'];
  830. }
  831. $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : $userdata['user_attachsig'];
  832. $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : "";
  833. if ( $submit && $mode != 'edit' )
  834. {
  835. //
  836. // Flood control
  837. //
  838. $sql = "SELECT MAX(privmsgs_date) AS last_post_time
  839. FROM " . PRIVMSGS_TABLE . "
  840. WHERE privmsgs_from_userid = " . $userdata['user_id'];
  841. if ( $result = $db->sql_query($sql) )
  842. {
  843. $db_row = $db->sql_fetchrow($result);
  844. $last_post_time = $db_row['last_post_time'];
  845. $current_time = time();
  846. if ( ( $current_time - $last_post_time ) < $board_config['flood_interval'])
  847. {
  848. message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
  849. }
  850. }
  851. //
  852. // End Flood control
  853. //
  854. }
  855. if ( $submit )
  856. {
  857. if ( !empty($HTTP_POST_VARS['username']) )
  858. {
  859. $to_username = $HTTP_POST_VARS['username'];
  860. $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active
  861. FROM " . USERS_TABLE . "
  862. WHERE username = '" . str_replace("\'", "''", $to_username) . "'
  863. AND user_id <> " . ANONYMOUS;
  864. if ( !($result = $db->sql_query($sql)) )
  865. {
  866. $error = TRUE;
  867. $error_msg = $lang['No_such_user'];
  868. }
  869. $to_userdata = $db->sql_fetchrow($result);
  870. }
  871. else
  872. {
  873. $error = TRUE;
  874. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['No_to_user'];
  875. }
  876. $privmsg_subject = trim(strip_tags($HTTP_POST_VARS['subject']));
  877. if ( empty($privmsg_subject) )
  878. {
  879. $error = TRUE;
  880. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject'];
  881. }
  882. if ( !empty($HTTP_POST_VARS['message']) )
  883. {
  884. if ( !$error )
  885. {
  886. if ( $bbcode_on )
  887. {
  888. $bbcode_uid = make_bbcode_uid();
  889. }
  890. $privmsg_message = prepare_message($HTTP_POST_VARS['message'], $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
  891. }
  892. }
  893. else
  894. {
  895. $error = TRUE;
  896. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message'];
  897. }
  898. }
  899. if ( $submit && !$error )
  900. {
  901. //
  902. // Has admin prevented user from sending PM's?
  903. //
  904. if ( !$userdata['user_allow_pm'] )
  905. {
  906. $message = $lang['Cannot_send_privmsg'];
  907. message_die(GENERAL_MESSAGE, $message);
  908. }
  909. $msg_time = time();
  910. if ( $mode != 'edit' )
  911. {
  912. //
  913. // See if recipient is at their inbox limit
  914. //
  915. $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
  916. FROM " . PRIVMSGS_TABLE . "
  917. WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  918. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  919. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  920. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  921. if ( !($result = $db->sql_query($sql)) )
  922. {
  923. message_die(GENERAL_MESSAGE, $lang['No_such_user']);
  924. }
  925. $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
  926. if ( $inbox_info = $db->sql_fetchrow($result) )
  927. {
  928. if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] )
  929. {
  930. $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
  931. WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  932. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  933. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  934. AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
  935. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  936. if ( !$db->sql_query($sql) )
  937. {
  938. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs', '', __LINE__, __FILE__, $sql);
  939. }
  940. }
  941. }
  942. $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)
  943. 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)";
  944. }
  945. else
  946. {
  947. $sql_info = "UPDATE " . PRIVMSGS_TABLE . "
  948. 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
  949. WHERE privmsgs_id = $privmsg_id";
  950. }
  951. if ( !($result = $db->sql_query($sql_info, BEGIN_TRANSACTION)) )
  952. {
  953. message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info);
  954. }
  955. if ( $mode != 'edit' )
  956. {
  957. $privmsg_sent_id = $db->sql_nextid();
  958. $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
  959. VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')";
  960. }
  961. else
  962. {
  963. $sql = "UPDATE " . PRIVMSGS_TEXT_TABLE . "
  964. SET privmsgs_text = '" . str_replace("\'", "''", $privmsg_message) . "', privmsgs_bbcode_uid = '$bbcode_uid'
  965. WHERE privmsgs_text_id = $privmsg_id";
  966. }
  967. if ( !$db->sql_query($sql, END_TRANSACTION) )
  968. {
  969. message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql_info);
  970. }
  971. if ( $mode != 'edit' )
  972. {
  973. //
  974. // Add to the users new pm counter
  975. //
  976. $sql = "UPDATE " . USERS_TABLE . "
  977. SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . "
  978. WHERE user_id = " . $to_userdata['user_id'];
  979. if ( !$status = $db->sql_query($sql) )
  980. {
  981. message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
  982. }
  983. if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] )
  984. {
  985. $email_headers = 'From: ' . $board_config['board_email'] . "\nReturn-Path: " . $board_config['board_email'] . "\n";
  986. $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path']));
  987. $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx;
  988. $server_name = trim($board_config['server_name']);
  989. $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
  990. $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
  991. include($phpbb_root_path . 'includes/emailer.'.$phpEx);
  992. $emailer = new emailer($board_config['smtp_delivery']);
  993. $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
  994. $emailer->extra_headers($email_headers);
  995. $emailer->email_address($to_userdata['user_email']);
  996. $emailer->set_subject(); //$lang['Notification_subject']
  997. $emailer->assign_vars(array(
  998. 'USERNAME' => $to_username,
  999. 'SITENAME' => $board_config['sitename'],
  1000. 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']),
  1001. 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox')
  1002. );
  1003. $emailer->send();
  1004. $emailer->reset();
  1005. }
  1006. }
  1007. $template->assign_vars(array(
  1008. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("privmsg.$phpEx?folder=inbox") . '">')
  1009. );
  1010. $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>');
  1011. message_die(GENERAL_MESSAGE, $msg);
  1012. }
  1013. else if ( $preview || $refresh || $error )
  1014. {
  1015. //
  1016. // If we're previewing or refreshing then obtain the data
  1017. // passed to the script, process it a little, do some checks
  1018. // where neccessary, etc.
  1019. //
  1020. $to_username = ( isset($HTTP_POST_VARS['username']) ) ? trim(strip_tags(stripslashes($HTTP_POST_VARS['username']))) : '';
  1021. $privmsg_subject = ( isset($HTTP_POST_VARS['subject']) ) ? trim(strip_tags(stripslashes($HTTP_POST_VARS['subject']))) : '';
  1022. $privmsg_message = ( isset($HTTP_POST_VARS['message']) ) ? trim($HTTP_POST_VARS['message']) : '';
  1023. $privmsg_message = preg_replace('#<textarea>#si', '&lt;textarea&gt;', $privmsg_message);
  1024. if ( !$preview )
  1025. {
  1026. $privmsg_message = stripslashes($privmsg_message);
  1027. }
  1028. //
  1029. // Do mode specific things
  1030. //
  1031. if ( $mode == 'post' )
  1032. {
  1033. $page_title = $lang['Post_new_pm'];
  1034. $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
  1035. }
  1036. else if ( $mode == 'reply' )
  1037. {
  1038. $page_title = $lang['Post_reply_pm'];
  1039. $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
  1040. }
  1041. else if ( $mode == 'edit' )
  1042. {
  1043. $page_title = $lang['Edit_pm'];
  1044. $sql = "SELECT u.user_id, u.user_sig
  1045. FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u
  1046. WHERE pm.privmsgs_id = $privmsg_id
  1047. AND u.user_id = pm.privmsgs_from_userid";
  1048. if ( !($result = $db->sql_query($sql)) )
  1049. {
  1050. message_die(GENERAL_ERROR, "Could not obtain post and post text", "", __LINE__, __FILE__, $sql);
  1051. }
  1052. if ( $postrow = $db->sql_fetchrow($result) )
  1053. {
  1054. if ( $userdata['user_id'] != $postrow['user_id'] )
  1055. {
  1056. message_die(GENERAL_MESSAGE, $lang['Edit_own_posts']);
  1057. }
  1058. $user_sig = ( $postrow['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow['user_sig'] : '';
  1059. }
  1060. }
  1061. }
  1062. else
  1063. {
  1064. if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) )
  1065. {
  1066. message_die(GENERAL_ERROR, $lang['No_post_id']);
  1067. }
  1068. if ( !empty($HTTP_GET_VARS[POST_USERS_URL]) )
  1069. {
  1070. $user_id = intval($HTTP_GET_VARS[POST_USERS_URL]);
  1071. $sql = "SELECT username
  1072. FROM " . USERS_TABLE . "
  1073. WHERE user_id = $user_id
  1074. AND user_id <> " . ANONYMOUS;
  1075. if ( !($result = $db->sql_query($sql)) )
  1076. {
  1077. $error = TRUE;
  1078. $error_msg = $lang['No_such_user'];
  1079. }
  1080. if ( $row = $db->sql_fetchrow($result) )
  1081. {
  1082. $to_username = $row['username'];
  1083. }
  1084. }
  1085. if ( $mode == 'edit' )
  1086. {
  1087. $sql = "SELECT pm.*, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id, u.user_sig
  1088. FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
  1089. WHERE pm.privmsgs_id = $privmsg_id
  1090. AND pmt.privmsgs_text_id = pm.privmsgs_id
  1091. AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  1092. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1093. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  1094. AND u.user_id = pm.privmsgs_to_userid";
  1095. if ( !($result = $db->sql_query($sql)) )
  1096. {
  1097. message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
  1098. }
  1099. if ( !($privmsg = $db->sql_fetchrow($result)) )
  1100. {
  1101. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  1102. header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true));
  1103. exit;
  1104. }
  1105. $privmsg_subject = $privmsg['privmsgs_subject'];
  1106. $privmsg_message = $privmsg['privmsgs_text'];
  1107. $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
  1108. $privmsg_bbcode_enabled = ($privmsg['privmsgs_enable_bbcode'] == 1);
  1109. if ( $privmsg_bbcode_enabled )
  1110. {
  1111. $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
  1112. }
  1113. $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
  1114. $privmsg_message = preg_replace('#</textarea>#si', '&lt;/textarea&gt;', $privmsg_message);
  1115. $user_sig = ( $board_config['allow_sig'] ) ? $privmsg['user_sig'] : '';
  1116. $to_username = $privmsg['username'];
  1117. $to_userid = $privmsg['user_id'];
  1118. }
  1119. else if ( $mode == 'reply' || $mode == 'quote' )
  1120. {
  1121. $sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_bbcode_uid, pmt.privmsgs_text, u.username, u.user_id
  1122. FROM " . PRIVMSGS_TABLE . " pm, " . PRIVMSGS_TEXT_TABLE . " pmt, " . USERS_TABLE . " u
  1123. WHERE pm.privmsgs_id = $privmsg_id
  1124. AND pmt.privmsgs_text_id = pm.privmsgs_id
  1125. AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  1126. AND u.user_id = pm.privmsgs_from_userid";
  1127. if ( !($result = $db->sql_query($sql)) )
  1128. {
  1129. message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
  1130. }
  1131. if ( !($privmsg = $db->sql_fetchrow($result)) )
  1132. {
  1133. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  1134. header($header_location . append_sid("privmsg.$phpEx?folder=$folder", true));
  1135. exit;
  1136. }
  1137. $privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ) . $privmsg['privmsgs_subject'];
  1138. $to_username = $privmsg['username'];
  1139. $to_userid = $privmsg['user_id'];
  1140. if ( $mode == 'quote' )
  1141. {
  1142. $privmsg_message = $privmsg['privmsgs_text'];
  1143. $privmsg_bbcode_uid = $privmsg['privmsgs_bbcode_uid'];
  1144. $privmsg_message = preg_replace("/\:(([a-z0-9]:)?)$privmsg_bbcode_uid/si", '', $privmsg_message);
  1145. $privmsg_message = str_replace('<br />', "\n", $privmsg_message);
  1146. $privmsg_message = preg_replace('#</textarea>#si', '&lt;/textarea&gt;', $privmsg_message);
  1147. $msg_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date'], $board_config['board_timezone']);
  1148. $privmsg_message = '[quote="' . $to_username . '"]' . $privmsg_message . '[/quote]';
  1149. $mode = 'reply';
  1150. }
  1151. }
  1152. }
  1153. //
  1154. // Has admin prevented user from sending PM's?
  1155. //
  1156. if ( !$userdata['user_allow_pm'] && $mode != 'edit' )
  1157. {
  1158. $message = $lang['Cannot_send_privmsg'];
  1159. message_die(GENERAL_MESSAGE, $message);
  1160. }
  1161. //
  1162. // Start output, first preview, then errors then post form
  1163. //
  1164. $page_title = $lang['Send_private_message'];
  1165. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  1166. if ( $preview && !$error )
  1167. {
  1168. $orig_word = array();
  1169. $replacement_word = array();
  1170. obtain_word_list($orig_word, $replacement_word);
  1171. if ( $bbcode_on )
  1172. {
  1173. $bbcode_uid = make_bbcode_uid();
  1174. }
  1175. $preview_message = stripslashes(prepare_message($privmsg_message, $html_on, $bbcode_on, $smilies_on, $bbcode_uid));
  1176. $privmsg_message = stripslashes(preg_replace($html_entities_match, $html_entities_replace, $privmsg_message));
  1177. //
  1178. // Finalise processing as per viewtopic
  1179. //
  1180. if ( !$html_on )
  1181. {
  1182. if ( $user_sig != '' || !$userdata['user_allowhtml'] )
  1183. {
  1184. $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
  1185. }
  1186. }
  1187. if ( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] )
  1188. {
  1189. $user_sig = bbencode_second_pass($user_sig, $userdata[

Large files files are truncated, but you can click here to view the full file