PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/privmsg.php

http://torrentpier2.googlecode.com/
PHP | 1732 lines | 1338 code | 242 blank | 152 comment | 281 complexity | 9f98dd7960c350c215c2293ba4627d24 MD5 | raw file
  1. <?php
  2. define('IN_FORUM', true);
  3. define('BB_SCRIPT', 'pm');
  4. define('IN_PM', true);
  5. define('BB_ROOT', './');
  6. require(BB_ROOT .'common.php');
  7. require(INC_DIR .'bbcode.php');
  8. require(INC_DIR .'functions_post.php');
  9. $privmsg_sent_id = $l_box_name = $to_username = $privmsg_subject = $privmsg_message = $error_msg = '';
  10. $page_cfg['use_tablesorter'] = true;
  11. $page_cfg['load_tpl_vars'] = array(
  12. 'pm_icons',
  13. );
  14. //
  15. // Is PM disabled?
  16. //
  17. if ($bb_cfg['privmsg_disable']) bb_die('PM_DISABLED');
  18. //
  19. // Parameters
  20. //
  21. //$submit = ( isset($_POST['post']) ) ? TRUE : 0;
  22. $submit = (bool) request_var('post', false); //test it!
  23. $submit_search = ( isset($_POST['usersubmit']) ) ? TRUE : 0;
  24. $submit_msgdays = ( isset($_POST['submit_msgdays']) ) ? TRUE : 0;
  25. $cancel = ( isset($_POST['cancel']) ) ? TRUE : 0;
  26. $preview = ( isset($_POST['preview']) ) ? TRUE : 0;
  27. $confirmed = ( isset($_POST['confirm']) ) ? TRUE : 0;
  28. $delete = ( isset($_POST['delete']) ) ? TRUE : 0;
  29. $delete_all = ( isset($_POST['deleteall']) ) ? TRUE : 0;
  30. $save = ( isset($_POST['save']) ) ? TRUE : 0;
  31. $mode = isset($_REQUEST['mode']) ? (string) $_REQUEST['mode'] : '';
  32. $refresh = $preview || $submit_search;
  33. $mark_list = ( !empty($_POST['mark']) ) ? $_POST['mark'] : 0;
  34. if ($folder =& $_REQUEST['folder'])
  35. {
  36. if ($folder != 'inbox' && $folder != 'outbox' && $folder != 'sentbox' && $folder != 'savebox')
  37. {
  38. $folder = 'inbox';
  39. }
  40. }
  41. else
  42. {
  43. $folder = 'inbox';
  44. }
  45. // Start session management
  46. $user->session_start(array('req_login' => true));
  47. if (IS_AM)
  48. {
  49. $bb_cfg['max_inbox_privmsgs'] += 1000;
  50. $bb_cfg['max_sentbox_privmsgs'] += 1000;
  51. $bb_cfg['max_savebox_privmsgs'] += 1000;
  52. }
  53. else if (IS_GROUP_MEMBER)
  54. {
  55. $bb_cfg['max_inbox_privmsgs'] += 200;
  56. $bb_cfg['max_sentbox_privmsgs'] += 200;
  57. $bb_cfg['max_savebox_privmsgs'] += 200;
  58. }
  59. $template->assign_vars(array(
  60. 'IN_PM' => true,
  61. 'QUICK_REPLY' => ($bb_cfg['show_quick_reply'] && $folder == 'inbox' && $mode == 'read'),
  62. ));
  63. //
  64. // Cancel
  65. //
  66. if ( $cancel )
  67. {
  68. redirect(PM_URL . "?folder=$folder");
  69. }
  70. //
  71. // Var definitions
  72. //
  73. $start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0;
  74. if ( isset($_POST[POST_POST_URL]) || isset($_GET[POST_POST_URL]) )
  75. {
  76. $privmsg_id = ( isset($_POST[POST_POST_URL]) ) ? intval($_POST[POST_POST_URL]) : intval($_GET[POST_POST_URL]);
  77. }
  78. else
  79. {
  80. $privmsg_id = '';
  81. }
  82. $error = FALSE;
  83. //
  84. // Define the box image links
  85. //
  86. $inbox_url = ( $folder != 'inbox' || $mode != '' ) ? '<a href="' . PM_URL . "?folder=inbox".'">'. $lang['INBOX'] .'</a>' : $lang['INBOX'];
  87. $outbox_url = ( $folder != 'outbox' || $mode != '' ) ? '<a href="' . PM_URL . "?folder=outbox".'">'. $lang['OUTBOX'] .'</a>' : $lang['OUTBOX'];
  88. $sentbox_url = ( $folder != 'sentbox' || $mode != '' ) ? '<a href="' . PM_URL . "?folder=sentbox".'">'. $lang['SENTBOX'] .'</a>' : $lang['SENTBOX'];
  89. $savebox_url = ( $folder != 'savebox' || $mode != '' ) ? '<a href="' . PM_URL . "?folder=savebox".'">'. $lang['SAVEBOX'] .'</a>' : $lang['SAVEBOX'];
  90. // ----------
  91. // Start main
  92. //
  93. $template->assign_var('POSTING_SUBJECT');
  94. if ( $mode == 'read' )
  95. {
  96. if ( !empty($_GET[POST_POST_URL]) )
  97. {
  98. $privmsgs_id = intval($_GET[POST_POST_URL]);
  99. }
  100. else
  101. {
  102. message_die(GENERAL_ERROR, $lang['NO_PM_ID']);
  103. }
  104. //
  105. // SQL to pull appropriate message, prevents nosey people
  106. // reading other peoples messages ... hopefully!
  107. //
  108. switch( $folder )
  109. {
  110. case 'inbox':
  111. $l_box_name = $lang['INBOX'];
  112. $pm_sql_user = "AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  113. AND ( pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  114. OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  115. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  116. break;
  117. case 'outbox':
  118. $l_box_name = $lang['OUTBOX'];
  119. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  120. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  121. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
  122. break;
  123. case 'sentbox':
  124. $l_box_name = $lang['SENTBOX'];
  125. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  126. AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  127. break;
  128. case 'savebox':
  129. $l_box_name = $lang['SAVEBOX'];
  130. $pm_sql_user = "AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  131. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  132. OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  133. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  134. )";
  135. break;
  136. default:
  137. message_die(GENERAL_ERROR, $lang['NO_SUCH_FOLDER']);
  138. break;
  139. }
  140. //
  141. // Major query obtains the message ...
  142. //
  143. $sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_email, u.user_regdate, u.user_rank,
  144. u2.username AS to_username, u2.user_id AS to_user_id, u2.user_rank as to_user_rank,
  145. pm.*, pmt.privmsgs_text
  146. FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u, " . BB_USERS . " u2
  147. WHERE pm.privmsgs_id = $privmsgs_id
  148. AND pmt.privmsgs_text_id = pm.privmsgs_id
  149. $pm_sql_user
  150. AND u.user_id = pm.privmsgs_from_userid
  151. AND u2.user_id = pm.privmsgs_to_userid";
  152. if ( !($result = DB()->sql_query($sql)) )
  153. {
  154. message_die(GENERAL_ERROR, 'Could not query private message post information', '', __LINE__, __FILE__, $sql);
  155. }
  156. //
  157. // Did the query return any data?
  158. //
  159. if ( !($privmsg = DB()->sql_fetchrow($result)) )
  160. {
  161. redirect(PM_URL . "?folder=$folder");
  162. }
  163. $privmsg_id = $privmsg['privmsgs_id'];
  164. //
  165. // Is this a new message in the inbox? If it is then save
  166. // a copy in the posters sent box
  167. //
  168. if (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL || $privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL) && $folder == 'inbox')
  169. {
  170. // Update appropriate counter
  171. switch ($privmsg['privmsgs_type'])
  172. {
  173. case PRIVMSGS_NEW_MAIL:
  174. $sql = "user_new_privmsg = IF(user_new_privmsg, user_new_privmsg - 1, 0)";
  175. break;
  176. case PRIVMSGS_UNREAD_MAIL:
  177. $sql = "user_unread_privmsg = IF(user_unread_privmsg, user_unread_privmsg - 1, 0)";
  178. break;
  179. }
  180. $sql = "UPDATE " . BB_USERS . "
  181. SET $sql
  182. WHERE user_id = " . $userdata['user_id'];
  183. if ( !DB()->sql_query($sql) )
  184. {
  185. message_die(GENERAL_ERROR, 'Could not update private message read status for user', '', __LINE__, __FILE__, $sql);
  186. }
  187. if (DB()->affected_rows())
  188. {
  189. cache_rm_userdata($userdata);
  190. }
  191. $sql = "UPDATE " . BB_PRIVMSGS . "
  192. SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  193. WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
  194. if ( !DB()->sql_query($sql) )
  195. {
  196. message_die(GENERAL_ERROR, 'Could not update private message read status', '', __LINE__, __FILE__, $sql);
  197. }
  198. // Check to see if the poster has a 'full' sent box
  199. $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time
  200. FROM " . BB_PRIVMSGS . "
  201. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  202. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  203. if ( !($result = DB()->sql_query($sql)) )
  204. {
  205. message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
  206. }
  207. if ( $sent_info = DB()->sql_fetchrow($result) )
  208. {
  209. if ($bb_cfg['max_sentbox_privmsgs'] && $sent_info['sent_items'] >= $bb_cfg['max_sentbox_privmsgs'])
  210. {
  211. $sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
  212. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  213. AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
  214. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  215. if ( !$result = DB()->sql_query($sql) )
  216. {
  217. message_die(GENERAL_ERROR, 'Could not find oldest privmsgs', '', __LINE__, __FILE__, $sql);
  218. }
  219. $old_privmsgs_id = DB()->sql_fetchrow($result);
  220. $old_privmsgs_id = (int) $old_privmsgs_id['privmsgs_id'];
  221. $sql = "DELETE FROM " . BB_PRIVMSGS . "
  222. WHERE privmsgs_id = $old_privmsgs_id";
  223. if ( !DB()->sql_query($sql) )
  224. {
  225. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (sent)', '', __LINE__, __FILE__, $sql);
  226. }
  227. $sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . "
  228. WHERE privmsgs_text_id = $old_privmsgs_id";
  229. if ( !DB()->sql_query($sql) )
  230. {
  231. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (sent)', '', __LINE__, __FILE__, $sql);
  232. }
  233. }
  234. }
  235. //
  236. // This makes a copy of the post and stores it as a SENT message from the sendee. Perhaps
  237. // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
  238. // set limits on numbers of storable posts for users ... hopefully!
  239. //
  240. $sql = "INSERT INTO " . BB_PRIVMSGS . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip)
  241. VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . DB()->escape($privmsg['privmsgs_subject']) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "')";
  242. if ( !DB()->sql_query($sql) )
  243. {
  244. message_die(GENERAL_ERROR, 'Could not insert private message sent info', '', __LINE__, __FILE__, $sql);
  245. }
  246. $privmsg_sent_id = DB()->sql_nextid();
  247. $sql = "INSERT INTO " . BB_PRIVMSGS_TEXT . " (privmsgs_text_id, privmsgs_text)
  248. VALUES ($privmsg_sent_id, '" . DB()->escape($privmsg['privmsgs_text']) . "')";
  249. if ( !DB()->sql_query($sql) )
  250. {
  251. message_die(GENERAL_ERROR, 'Could not insert private message sent text', '', __LINE__, __FILE__, $sql);
  252. }
  253. }
  254. //
  255. // Pick a folder, any folder, so long as it's one below ...
  256. //
  257. $post_urls = array(
  258. 'post' => PM_URL . "?mode=post",
  259. 'reply' => PM_URL . "?mode=reply&amp;" . POST_POST_URL . "=$privmsg_id",
  260. 'quote' => PM_URL . "?mode=quote&amp;" . POST_POST_URL . "=$privmsg_id",
  261. 'edit' => PM_URL . "?mode=edit&amp;" . POST_POST_URL . "=$privmsg_id"
  262. );
  263. $post_icons = array(
  264. 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['POST_NEW_PM'] . '" border="0" /></a>',
  265. 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['POST_NEW_PM'] . '</a>',
  266. 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['POST_REPLY_PM'] . '" border="0" /></a>',
  267. 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['POST_REPLY_PM'] . '</a>',
  268. 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['POST_QUOTE_PM'] . '" border="0" /></a>',
  269. 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['POST_QUOTE_PM'] . '</a>',
  270. 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['EDIT_PM'] . '" border="0" /></a>',
  271. 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['EDIT_PM'] . '</a>'
  272. );
  273. if ( $folder == 'inbox' )
  274. {
  275. $post_img = $post_icons['post_img'];
  276. $reply_img = $post_icons['reply_img'];
  277. $quote_img = $post_icons['quote_img'];
  278. $edit_img = '';
  279. $post = $post_icons['post'];
  280. $reply = $post_icons['reply'];
  281. $quote = $post_icons['quote'];
  282. $edit = '';
  283. $l_box_name = $lang['INBOX'];
  284. }
  285. else if ( $folder == 'outbox' )
  286. {
  287. $post_img = $post_icons['post_img'];
  288. $reply_img = '';
  289. $quote_img = '';
  290. $edit_img = $post_icons['edit_img'];
  291. $post = $post_icons['post'];
  292. $reply = '';
  293. $quote = '';
  294. $edit = $post_icons['edit'];
  295. $l_box_name = $lang['OUTBOX'];
  296. }
  297. else if ( $folder == 'savebox' )
  298. {
  299. if ( $privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL )
  300. {
  301. $post_img = $post_icons['post_img'];
  302. $reply_img = $post_icons['reply_img'];
  303. $quote_img = $post_icons['quote_img'];
  304. $edit_img = '';
  305. $post = $post_icons['post'];
  306. $reply = $post_icons['reply'];
  307. $quote = $post_icons['quote'];
  308. $edit = '';
  309. }
  310. else
  311. {
  312. $post_img = $post_icons['post_img'];
  313. $reply_img = '';
  314. $quote_img = '';
  315. $edit_img = '';
  316. $post = $post_icons['post'];
  317. $reply = '';
  318. $quote = '';
  319. $edit = '';
  320. }
  321. $l_box_name = $lang['SAVED'];
  322. }
  323. else if ( $folder == 'sentbox' )
  324. {
  325. $post_img = $post_icons['post_img'];
  326. $reply_img = '';
  327. $quote_img = '';
  328. $edit_img = '';
  329. $post = $post_icons['post'];
  330. $reply = '';
  331. $quote = '';
  332. $edit = '';
  333. $l_box_name = $lang['SENT'];
  334. }
  335. // Report
  336. //
  337. // Get report privmsg module and create report links
  338. //
  339. if ($folder == 'inbox')
  340. {
  341. include(INC_DIR ."functions_report.php");
  342. $report_privmsg = report_modules('name', 'report_privmsg');
  343. if ($report_privmsg && $report_privmsg->auth_check('auth_write'))
  344. {
  345. if ($privmsg['privmsgs_reported'])
  346. {
  347. $report_img = '<img src="' . $images['icon_reported'] . '" alt="' . $report_privmsg->lang['DUPLICATE_REPORT'] . '" title="' . $report_privmsg->lang['DUPLICATE_REPORT'] . '" border="0" />';
  348. $report = $report_privmsg->lang['DUPLICATE_REPORT'];
  349. }
  350. else
  351. {
  352. $temp_url = "report.php?mode=" . $report_privmsg->mode . "&amp;id=$privmsg_id";
  353. $report_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_report'] . '" alt="' . $report_privmsg->lang['WRITE_REPORT'] . '" title="' . $report_privmsg->lang['WRITE_REPORT'] . '" border="0" /></a>';
  354. $report = '<a href="' . $temp_url . '">' . $report_privmsg->lang['WRITE_REPORT'] . '</a>';
  355. }
  356. $template->assign_vars(array(
  357. 'REPORT_PM_IMG' => $report_img,
  358. 'REPORT_PM' => $report)
  359. );
  360. }
  361. }
  362. // Report [END]
  363. $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />';
  364. $page_title = $lang['READ_PM'];
  365. //
  366. // Load templates
  367. //
  368. $template->set_filenames(array(
  369. 'body' => 'privmsgs_read.tpl')
  370. );
  371. $template->assign_vars(array(
  372. 'INBOX' => $inbox_url,
  373. 'POST_PM_IMG' => $post_img,
  374. 'REPLY_PM_IMG' => $reply_img,
  375. 'EDIT_PM_IMG' => $edit_img,
  376. 'QUOTE_PM_IMG' => $quote_img,
  377. 'POST_PM' => $post,
  378. 'REPLY_PM' => $reply,
  379. 'EDIT_PM' => $edit,
  380. 'QUOTE_PM' => $quote,
  381. 'SENTBOX' => $sentbox_url,
  382. 'OUTBOX' => $outbox_url,
  383. 'SAVEBOX' => $savebox_url,
  384. 'BOX_NAME' => $l_box_name,
  385. 'S_PRIVMSGS_ACTION' => PM_URL . "?folder=$folder",
  386. 'S_HIDDEN_FIELDS' => $s_hidden_fields)
  387. );
  388. $username_from = $privmsg['username'];
  389. $user_id_from = $privmsg['user_id'];
  390. $username_to = $privmsg['to_username'];
  391. $user_id_to = $privmsg['to_user_id'];
  392. $post_date = bb_date($privmsg['privmsgs_date']);
  393. $temp_url = "profile.php?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $user_id_from;
  394. $profile_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_profile'] . '" alt="' . $lang['READ_PROFILE'] . '" title="' . $lang['READ_PROFILE'] . '" border="0" /></a>';
  395. $profile = '<a href="' . $temp_url . '">' . $lang['READ_PROFILE'] . '</a>';
  396. $temp_url = PM_URL . "?mode=post&amp;" . POST_USERS_URL . "=$user_id_from";
  397. $pm_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_pm'] . '" alt="' . $lang['SEND_PRIVATE_MESSAGE'] . '" title="' . $lang['SEND_PRIVATE_MESSAGE'] . '" border="0" /></a>';
  398. $pm = '<a href="' . $temp_url . '">' . $lang['SEND_PRIVATE_MESSAGE'] . '</a>';
  399. $temp_url = "search.php?search_author=1&amp;uid=$user_id_from";
  400. $search_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_search'] . '" alt="' . sprintf($lang['SEARCH_USER_POSTS'], $username_from) . '" title="' . sprintf($lang['SEARCH_USER_POSTS'], $username_from) . '" border="0" /></a>';
  401. $search = '<a href="' . $temp_url . '">' . sprintf($lang['SEARCH_USER_POSTS'], $username_from) . '</a>';
  402. //
  403. // Processing of post
  404. //
  405. $post_subject = htmlCHR($privmsg['privmsgs_subject']);
  406. $private_message = $privmsg['privmsgs_text'];
  407. $orig_word = array();
  408. $replacement_word = array();
  409. obtain_word_list($orig_word, $replacement_word);
  410. if ( count($orig_word) )
  411. {
  412. $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
  413. $private_message = preg_replace($orig_word, $replacement_word, $private_message);
  414. }
  415. $private_message = bbcode2html($private_message);
  416. //
  417. // Dump it to the templating engine
  418. //
  419. $template->assign_vars(array(
  420. 'TO_USER' => profile_url(array('username' => $username_to, 'user_id' => $user_id_to, 'user_rank' => $privmsg['to_user_rank'])),
  421. 'FROM_USER' => profile_url($privmsg),
  422. 'QR_SUBJECT' => (!preg_match('/^Re:/', $post_subject) ? 'Re: ' : '') . $post_subject,
  423. 'MESSAGE_TO' => $username_to,
  424. 'MESSAGE_FROM' => $username_from,
  425. 'RANK_IMAGE' => (@$rank_image) ? $rank_image : '',
  426. 'POSTER_JOINED' => (@$poster_joined) ? $poster_joined : '',
  427. 'POSTER_POSTS' => (@$poster_posts) ? $poster_posts : '',
  428. 'POSTER_FROM' => (@$poster_from) ? $poster_from : '',
  429. 'POST_SUBJECT' => $post_subject,
  430. 'POST_DATE' => $post_date,
  431. 'PM_MESSAGE' => $private_message,
  432. 'PROFILE_IMG' => $profile_img,
  433. 'PROFILE' => $profile,
  434. 'SEARCH_IMG' => $search_img,
  435. 'SEARCH' => $search,
  436. ));
  437. }
  438. else if ( ( $delete && $mark_list ) || $delete_all )
  439. {
  440. if ( isset($mark_list) && !is_array($mark_list) )
  441. {
  442. // Set to empty array instead of '0' if nothing is selected.
  443. $mark_list = array();
  444. }
  445. if (!$confirmed)
  446. {
  447. $delete = isset($_POST['delete']) ? 'delete' : 'deleteall';
  448. $hidden_fields = array(
  449. 'mode' => $mode,
  450. $delete => 1,
  451. );
  452. foreach ($mark_list as $pm_id)
  453. {
  454. $hidden_fields['mark'][] = (int) $pm_id;
  455. }
  456. print_confirmation(array(
  457. 'QUESTION' => (count($mark_list) == 1) ? $lang['CONFIRM_DELETE_PM'] : $lang['CONFIRM_DELETE_PMS'],
  458. 'FORM_ACTION' => PM_URL . "?folder=$folder",
  459. 'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
  460. ));
  461. }
  462. else if ( $confirmed )
  463. {
  464. $delete_sql_id = '';
  465. if (!$delete_all)
  466. {
  467. for ($i = 0; $i < count($mark_list); $i++)
  468. {
  469. $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  470. }
  471. $delete_sql_id = "AND privmsgs_id IN ($delete_sql_id)";
  472. }
  473. switch($folder)
  474. {
  475. case 'inbox':
  476. $delete_type = "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
  477. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  478. break;
  479. case 'outbox':
  480. $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  481. break;
  482. case 'sentbox':
  483. $delete_type = "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  484. break;
  485. case 'savebox':
  486. $delete_type = "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
  487. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  488. OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
  489. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
  490. break;
  491. }
  492. $sql = "SELECT privmsgs_id
  493. FROM " . BB_PRIVMSGS . "
  494. WHERE $delete_type $delete_sql_id";
  495. if ( !($result = DB()->sql_query($sql)) )
  496. {
  497. message_die(GENERAL_ERROR, 'Could not obtain id list to delete messages', '', __LINE__, __FILE__, $sql);
  498. }
  499. $mark_list = array();
  500. while ( $row = DB()->sql_fetchrow($result) )
  501. {
  502. $mark_list[] = $row['privmsgs_id'];
  503. }
  504. unset($delete_type);
  505. if ( count($mark_list) )
  506. {
  507. $delete_sql_id = '';
  508. for ($i = 0; $i < sizeof($mark_list); $i++)
  509. {
  510. $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  511. }
  512. if ($folder == 'inbox' || $folder == 'outbox')
  513. {
  514. switch ($folder)
  515. {
  516. case 'inbox':
  517. $sql = "privmsgs_to_userid = " . $userdata['user_id'];
  518. break;
  519. case 'outbox':
  520. $sql = "privmsgs_from_userid = " . $userdata['user_id'];
  521. break;
  522. }
  523. // Get information relevant to new or unread mail
  524. // so we can adjust users counters appropriately
  525. $sql = "SELECT privmsgs_to_userid, privmsgs_type
  526. FROM " . BB_PRIVMSGS . "
  527. WHERE privmsgs_id IN ($delete_sql_id)
  528. AND $sql
  529. AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
  530. if ( !($result = DB()->sql_query($sql)) )
  531. {
  532. message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
  533. }
  534. if ( $row = DB()->sql_fetchrow($result))
  535. {
  536. $update_users = $update_list = array();
  537. do
  538. {
  539. switch ($row['privmsgs_type'])
  540. {
  541. case PRIVMSGS_NEW_MAIL:
  542. @$update_users['new'][$row['privmsgs_to_userid']]++;
  543. break;
  544. case PRIVMSGS_UNREAD_MAIL:
  545. @$update_users['unread'][$row['privmsgs_to_userid']]++;
  546. break;
  547. }
  548. }
  549. while ($row = DB()->sql_fetchrow($result));
  550. if (sizeof($update_users))
  551. {
  552. while (list($type, $users) = each($update_users))
  553. {
  554. while (list($user_id, $dec) = each($users))
  555. {
  556. $update_list[$type][$dec][] = $user_id;
  557. }
  558. }
  559. unset($update_users);
  560. while (list($type, $dec_ary) = each($update_list))
  561. {
  562. switch ($type)
  563. {
  564. case 'new':
  565. $type = "user_new_privmsg";
  566. break;
  567. case 'unread':
  568. $type = "user_unread_privmsg";
  569. break;
  570. }
  571. while (list($dec, $user_ary) = each($dec_ary))
  572. {
  573. $user_ids = join(', ', $user_ary);
  574. $sql = "UPDATE " . BB_USERS . "
  575. SET $type = $type - $dec
  576. WHERE user_id IN ($user_ids)";
  577. if ( !DB()->sql_query($sql) )
  578. {
  579. message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
  580. }
  581. }
  582. }
  583. unset($update_list);
  584. }
  585. }
  586. DB()->sql_freeresult($result);
  587. }
  588. // Delete the messages
  589. $delete_text_sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . "
  590. WHERE privmsgs_text_id IN ($delete_sql_id)";
  591. $delete_sql = "DELETE FROM " . BB_PRIVMSGS . "
  592. WHERE privmsgs_id IN ($delete_sql_id)
  593. AND ";
  594. switch( $folder )
  595. {
  596. case 'inbox':
  597. $delete_sql .= "privmsgs_to_userid = " . $userdata['user_id'] . " AND (
  598. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  599. break;
  600. case 'outbox':
  601. $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND (
  602. privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  603. break;
  604. case 'sentbox':
  605. $delete_sql .= "privmsgs_from_userid = " . $userdata['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  606. break;
  607. case 'savebox':
  608. $delete_sql .= "( ( privmsgs_from_userid = " . $userdata['user_id'] . "
  609. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " )
  610. OR ( privmsgs_to_userid = " . $userdata['user_id'] . "
  611. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " ) )";
  612. break;
  613. }
  614. if ( !DB()->sql_query($delete_sql) )
  615. {
  616. message_die(GENERAL_ERROR, 'Could not delete private message info', '', __LINE__, __FILE__, $delete_sql);
  617. }
  618. if ( !DB()->sql_query($delete_text_sql) )
  619. {
  620. message_die(GENERAL_ERROR, 'Could not delete private message text', '', __LINE__, __FILE__, $delete_text_sql);
  621. }
  622. pm_message_die($lang['DELETE_POSTS_SUCCESFULLY']);
  623. }
  624. else
  625. {
  626. pm_message_die($lang['NONE_SELECTED']);
  627. }
  628. }
  629. }
  630. else if ( $save && $mark_list && $folder != 'savebox' && $folder != 'outbox' )
  631. {
  632. if (sizeof($mark_list))
  633. {
  634. // See if recipient is at their savebox limit
  635. $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time
  636. FROM " . BB_PRIVMSGS . "
  637. WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
  638. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  639. OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
  640. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
  641. if ( !($result = DB()->sql_query($sql)) )
  642. {
  643. message_die(GENERAL_ERROR, 'Could not obtain sent message info for sendee', '', __LINE__, __FILE__, $sql);
  644. }
  645. if ( $saved_info = DB()->sql_fetchrow($result) )
  646. {
  647. if ($bb_cfg['max_savebox_privmsgs'] && $saved_info['savebox_items'] >= $bb_cfg['max_savebox_privmsgs'] )
  648. {
  649. $sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
  650. WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
  651. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  652. OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
  653. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )
  654. AND privmsgs_date = " . $saved_info['oldest_post_time'];
  655. if ( !$result = DB()->sql_query($sql) )
  656. {
  657. message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
  658. }
  659. $old_privmsgs_id = DB()->sql_fetchrow($result);
  660. $old_privmsgs_id = (int) $old_privmsgs_id['privmsgs_id'];
  661. $sql = "DELETE FROM " . BB_PRIVMSGS . "
  662. WHERE privmsgs_id = $old_privmsgs_id";
  663. if ( !DB()->sql_query($sql) )
  664. {
  665. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (save)', '', __LINE__, __FILE__, $sql);
  666. }
  667. $sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . "
  668. WHERE privmsgs_text_id = $old_privmsgs_id";
  669. if ( !DB()->sql_query($sql) )
  670. {
  671. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (save)', '', __LINE__, __FILE__, $sql);
  672. }
  673. }
  674. }
  675. $saved_sql_id = '';
  676. for ($i = 0; $i < sizeof($mark_list); $i++)
  677. {
  678. $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  679. }
  680. // Process request
  681. $saved_sql = "UPDATE " . BB_PRIVMSGS;
  682. // Decrement read/new counters if appropriate
  683. if ($folder == 'inbox' || $folder == 'outbox')
  684. {
  685. switch ($folder)
  686. {
  687. case 'inbox':
  688. $sql = "privmsgs_to_userid = " . $userdata['user_id'];
  689. break;
  690. case 'outbox':
  691. $sql = "privmsgs_from_userid = " . $userdata['user_id'];
  692. break;
  693. }
  694. // Get information relevant to new or unread mail
  695. // so we can adjust users counters appropriately
  696. $sql = "SELECT privmsgs_to_userid, privmsgs_type
  697. FROM " . BB_PRIVMSGS . "
  698. WHERE privmsgs_id IN ($saved_sql_id)
  699. AND $sql
  700. AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
  701. if ( !($result = DB()->sql_query($sql)) )
  702. {
  703. message_die(GENERAL_ERROR, 'Could not obtain user id list for outbox messages', '', __LINE__, __FILE__, $sql);
  704. }
  705. if ( $row = DB()->sql_fetchrow($result))
  706. {
  707. $update_users = $update_list = array();
  708. do
  709. {
  710. switch ($row['privmsgs_type'])
  711. {
  712. case PRIVMSGS_NEW_MAIL:
  713. @$update_users['new'][$row['privmsgs_to_userid']]++;
  714. break;
  715. case PRIVMSGS_UNREAD_MAIL:
  716. @$update_users['unread'][$row['privmsgs_to_userid']]++;
  717. break;
  718. }
  719. }
  720. while ($row = DB()->sql_fetchrow($result));
  721. if (sizeof($update_users))
  722. {
  723. while (list($type, $users) = each($update_users))
  724. {
  725. while (list($user_id, $dec) = each($users))
  726. {
  727. $update_list[$type][$dec][] = $user_id;
  728. }
  729. }
  730. unset($update_users);
  731. while (list($type, $dec_ary) = each($update_list))
  732. {
  733. switch ($type)
  734. {
  735. case 'new':
  736. $type = "user_new_privmsg";
  737. break;
  738. case 'unread':
  739. $type = "user_unread_privmsg";
  740. break;
  741. }
  742. while (list($dec, $user_ary) = each($dec_ary))
  743. {
  744. $user_ids = join(', ', $user_ary);
  745. $sql = "UPDATE " . BB_USERS . "
  746. SET $type = $type - $dec
  747. WHERE user_id IN ($user_ids)";
  748. if ( !DB()->sql_query($sql) )
  749. {
  750. message_die(GENERAL_ERROR, 'Could not update user pm counters', '', __LINE__, __FILE__, $sql);
  751. }
  752. }
  753. }
  754. unset($update_list);
  755. }
  756. }
  757. DB()->sql_freeresult($result);
  758. }
  759. switch ($folder)
  760. {
  761. case 'inbox':
  762. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
  763. WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
  764. AND ( privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  765. OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  766. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  767. break;
  768. case 'outbox':
  769. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  770. WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  771. AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  772. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ";
  773. break;
  774. case 'sentbox':
  775. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  776. WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  777. AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  778. break;
  779. }
  780. $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
  781. if ( !DB()->sql_query($saved_sql) )
  782. {
  783. message_die(GENERAL_ERROR, 'Could not save private messages', '', __LINE__, __FILE__, $saved_sql);
  784. }
  785. redirect(PM_URL . "?folder=savebox");
  786. }
  787. }
  788. else if ( $submit || $refresh || $mode != '' )
  789. {
  790. if (IS_USER && $submit && $mode != 'edit')
  791. {
  792. //
  793. // Flood control
  794. //
  795. $sql = "SELECT MAX(privmsgs_date) AS last_post_time
  796. FROM " . BB_PRIVMSGS . "
  797. WHERE privmsgs_from_userid = " . $userdata['user_id'];
  798. if ( $result = DB()->sql_query($sql) )
  799. {
  800. $db_row = DB()->sql_fetchrow($result);
  801. $last_post_time = $db_row['last_post_time'];
  802. $current_time = TIMENOW;
  803. if ( ( $current_time - $last_post_time ) < $bb_cfg['flood_interval'])
  804. {
  805. message_die(GENERAL_MESSAGE, $lang['FLOOD_ERROR']);
  806. }
  807. }
  808. //
  809. // End Flood control
  810. //
  811. }
  812. if ($submit && $mode == 'edit')
  813. {
  814. $sql = 'SELECT privmsgs_from_userid
  815. FROM ' . BB_PRIVMSGS . '
  816. WHERE privmsgs_id = ' . (int) $privmsg_id . '
  817. AND privmsgs_from_userid = ' . $userdata['user_id'];
  818. if (!($result = DB()->sql_query($sql)))
  819. {
  820. message_die(GENERAL_ERROR, "Could not obtain message details", "", __LINE__, __FILE__, $sql);
  821. }
  822. if (!($row = DB()->sql_fetchrow($result)))
  823. {
  824. message_die(GENERAL_MESSAGE, $lang['NO_SUCH_POST']);
  825. }
  826. DB()->sql_freeresult($result);
  827. unset($row);
  828. }
  829. if ( $submit )
  830. {
  831. if ( !empty($_POST['username']) )
  832. {
  833. $to_username = clean_username($_POST['username']);
  834. // DelUsrKeepPM
  835. $to_username_sql = DB()->escape($to_username);
  836. $to_userdata = get_userdata ($to_username_sql);
  837. if (!$to_userdata || $to_userdata['user_id'] == GUEST_UID)
  838. {
  839. $error = TRUE;
  840. $error_msg = $lang['NO_SUCH_USER'];
  841. }
  842. // DelUsrKeepPM end
  843. }
  844. else
  845. {
  846. $error = TRUE;
  847. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['NO_TO_USER'];
  848. }
  849. $privmsg_subject = htmlCHR($_POST['subject']);
  850. if ( empty($privmsg_subject) )
  851. {
  852. $error = TRUE;
  853. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['EMPTY_SUBJECT'];
  854. }
  855. if ( !empty($_POST['message']) )
  856. {
  857. if ( !$error )
  858. {
  859. $privmsg_message = prepare_message($_POST['message']);
  860. }
  861. }
  862. else
  863. {
  864. $error = TRUE;
  865. $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['EMPTY_MESSAGE'];
  866. }
  867. }
  868. if ( $submit && !$error )
  869. {
  870. //
  871. // Has admin prevented user from sending PM's?
  872. //
  873. if ( bf($userdata['user_opt'], 'user_opt', 'allow_pm') )
  874. {
  875. bb_die($lang['CANNOT_SEND_PRIVMSG']);
  876. }
  877. $msg_time = TIMENOW;
  878. if ( $mode != 'edit' )
  879. {
  880. //
  881. // See if recipient is at their inbox limit
  882. //
  883. $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
  884. FROM " . BB_PRIVMSGS . "
  885. WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  886. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  887. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  888. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  889. if ( !($result = DB()->sql_query($sql)) )
  890. {
  891. message_die(GENERAL_MESSAGE, $lang['NO_SUCH_USER']);
  892. }
  893. if ( $inbox_info = DB()->sql_fetchrow($result) )
  894. {
  895. if ($bb_cfg['max_inbox_privmsgs'] && $inbox_info['inbox_items'] >= $bb_cfg['max_inbox_privmsgs'])
  896. {
  897. $sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
  898. WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  899. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  900. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  901. AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
  902. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  903. if ( !$result = DB()->sql_query($sql) )
  904. {
  905. message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (inbox)', '', __LINE__, __FILE__, $sql);
  906. }
  907. $old_privmsgs_id = DB()->sql_fetchrow($result);
  908. $old_privmsgs_id = (int) $old_privmsgs_id['privmsgs_id'];
  909. $sql = "DELETE FROM " . BB_PRIVMSGS . "
  910. WHERE privmsgs_id = $old_privmsgs_id";
  911. if ( !DB()->sql_query($sql) )
  912. {
  913. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (inbox)'.$sql, '', __LINE__, __FILE__, $sql);
  914. }
  915. $sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . "
  916. WHERE privmsgs_text_id = $old_privmsgs_id";
  917. if ( !DB()->sql_query($sql) )
  918. {
  919. message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (inbox)', '', __LINE__, __FILE__, $sql);
  920. }
  921. }
  922. }
  923. $sql_info = "INSERT INTO " . BB_PRIVMSGS . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip)
  924. VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . DB()->escape($privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '". USER_IP ."')";
  925. }
  926. else
  927. {
  928. $sql_info = "UPDATE " . BB_PRIVMSGS . "
  929. SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . DB()->escape($privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '". USER_IP ."'
  930. WHERE privmsgs_id = $privmsg_id";
  931. }
  932. if ( !($result = DB()->sql_query($sql_info)) )
  933. {
  934. message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info);
  935. }
  936. if ( $mode != 'edit' )
  937. {
  938. $privmsg_sent_id = DB()->sql_nextid();
  939. $sql = "INSERT INTO " . BB_PRIVMSGS_TEXT . " (privmsgs_text_id, privmsgs_text)
  940. VALUES ($privmsg_sent_id, '" . DB()->escape($privmsg_message) . "')";
  941. }
  942. else
  943. {
  944. $sql = "UPDATE " . BB_PRIVMSGS_TEXT . "
  945. SET privmsgs_text = '" . DB()->escape($privmsg_message) . "'
  946. WHERE privmsgs_text_id = $privmsg_id";
  947. }
  948. if ( !DB()->sql_query($sql) )
  949. {
  950. message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql_info);
  951. }
  952. if ( $mode != 'edit' )
  953. {
  954. $timenow = TIMENOW;
  955. //
  956. // Add to the users new pm counter
  957. //
  958. $sql = "UPDATE ". BB_USERS ." SET
  959. user_new_privmsg = user_new_privmsg + 1,
  960. user_last_privmsg = $timenow,
  961. user_newest_pm_id = $privmsg_sent_id
  962. WHERE user_id = {$to_userdata['user_id']}
  963. LIMIT 1";
  964. if ( !$status = DB()->sql_query($sql) )
  965. {
  966. message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
  967. }
  968. cache_rm_user_sessions ($to_userdata['user_id']);
  969. if ( bf($to_userdata['user_opt'], 'user_opt', 'notify_pm') && !empty($to_userdata['user_email']) && $to_userdata['user_active'] && $bb_cfg['pm_notify_enabled'] )
  970. {
  971. require(INC_DIR .'emailer.class.php');
  972. $emailer = new emailer($bb_cfg['smtp_delivery']);
  973. $emailer->from($bb_cfg['sitename'] ." <{$bb_cfg['board_email']}>");
  974. $emailer->email_address($to_userdata['username'] ." <{$to_userdata['user_email']}>");
  975. $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
  976. $emailer->assign_vars(array(
  977. 'USERNAME' => html_entity_decode($to_username),
  978. 'NAME_FROM' => $userdata['username'],
  979. 'MSG_SUBJECT' => html_entity_decode($privmsg_subject),
  980. 'SITENAME' => $bb_cfg['sitename'],
  981. 'U_INBOX' => make_url(PM_URL . "?folder=inbox&mode=read&p=". $privmsg_sent_id),
  982. ));
  983. $emailer->send();
  984. $emailer->reset();
  985. }
  986. }
  987. pm_message_die($lang['MESSAGE_SENT']);
  988. }
  989. else if ( $preview || $refresh || $error )
  990. {
  991. //
  992. // If we're previewing or refreshing then obtain the data
  993. // passed to the script, process it a little, do some checks
  994. // where neccessary, etc.
  995. //
  996. $to_username = (isset($_POST['username']) ) ? clean_username($_POST['username']) : '';
  997. $privmsg_subject = ( isset($_POST['subject']) ) ? clean_title($_POST['subject']) : '';
  998. $privmsg_message = ( isset($_POST['message']) ) ? trim($_POST['message']) : '';
  999. //
  1000. // Do mode specific things
  1001. //
  1002. if ( $mode == 'post' )
  1003. {
  1004. $page_title = $lang['POST_NEW_PM'];
  1005. }
  1006. else if ( $mode == 'reply' )
  1007. {
  1008. $page_title = $lang['POST_REPLY_PM'];
  1009. }
  1010. else if ( $mode == 'edit' )
  1011. {
  1012. $page_title = $lang['EDIT_PM'];
  1013. $sql = "SELECT u.user_id
  1014. FROM " . BB_PRIVMSGS . " pm, " . BB_USERS . " u
  1015. WHERE pm.privmsgs_id = $privmsg_id
  1016. AND u.user_id = pm.privmsgs_from_userid";
  1017. if ( !($result = DB()->sql_query($sql)) )
  1018. {
  1019. message_die(GENERAL_ERROR, "Could not obtain post and post text", "", __LINE__, __FILE__, $sql);
  1020. }
  1021. if ( $postrow = DB()->sql_fetchrow($result) )
  1022. {
  1023. if ( $userdata['user_id'] != $postrow['user_id'] )
  1024. {
  1025. message_die(GENERAL_MESSAGE, $lang['EDIT_OWN_POSTS']);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) )
  1033. {
  1034. message_die(GENERAL_ERROR, $lang['NO_POST_ID']);
  1035. }
  1036. if ( !empty($_GET[POST_USERS_URL]) )
  1037. {
  1038. $user_id = intval($_GET[POST_USERS_URL]);
  1039. $sql = "SELECT username
  1040. FROM " . BB_USERS . "
  1041. WHERE user_id = $user_id
  1042. AND user_id <> " . GUEST_UID;
  1043. if ( !($result = DB()->sql_query($sql)) )
  1044. {
  1045. $error = TRUE;
  1046. $error_msg = $lang['NO_SUCH_USER'];
  1047. }
  1048. if ( $row = DB()->sql_fetchrow($result) )
  1049. {
  1050. $to_username = $row['username'];
  1051. }
  1052. }
  1053. else if ( $mode == 'edit' )
  1054. {
  1055. $sql = "SELECT pm.*, pmt.privmsgs_text, u.username, u.user_id
  1056. FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u
  1057. WHERE pm.privmsgs_id = $privmsg_id
  1058. AND pmt.privmsgs_text_id = pm.privmsgs_id
  1059. AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  1060. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1061. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  1062. AND u.user_id = pm.privmsgs_to_userid";
  1063. if ( !($result = DB()->sql_query($sql)) )
  1064. {
  1065. message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
  1066. }
  1067. if ( !($privmsg = DB()->sql_fetchrow($result)) )
  1068. {
  1069. redirect(PM_URL . "?folder=$folder");
  1070. }
  1071. $privmsg_subject = $privmsg['privmsgs_subject'];
  1072. $privmsg_message = $privmsg['privmsgs_text'];
  1073. $to_username = $privmsg['username'];
  1074. $to_userid = $privmsg['user_id'];
  1075. }
  1076. else if ( $mode == 'reply' || $mode == 'quote' )
  1077. {
  1078. $sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_text, u.username, u.user_id
  1079. FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u
  1080. WHERE pm.privmsgs_id = $privmsg_id
  1081. AND pmt.privmsgs_text_id = pm.privmsgs_id
  1082. AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  1083. AND u.user_id = pm.privmsgs_from_userid";
  1084. if ( !($result = DB()->sql_query($sql)) )
  1085. {
  1086. message_die(GENERAL_ERROR, 'Could not obtain private message for editing', '', __LINE__, __FILE__, $sql);
  1087. }
  1088. if ( !($privmsg = DB()->sql_fetchrow($result)) )
  1089. {
  1090. redirect(PM_URL . "?folder=$folder");
  1091. }
  1092. $privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ) . $privmsg['privmsgs_subject'];
  1093. $to_username = $privmsg['username'];
  1094. $to_userid = $privmsg['user_id'];
  1095. if ( $mode == 'quote' )
  1096. {
  1097. $privmsg_message = $privmsg['privmsgs_text'];
  1098. $msg_date = bb_date($privmsg['privmsgs_date']);
  1099. $privmsg_message = '[quote="' . $to_username . '"]' . $privmsg_message . '[/quote]';
  1100. $mode = 'reply';
  1101. }
  1102. }
  1103. else
  1104. {
  1105. $privmsg_subject = $privmsg_message = $to_username = '';
  1106. }
  1107. }
  1108. //
  1109. // Has admin prevented user from sending PM's?
  1110. //
  1111. if ( bf($userdata['user_opt'], 'user_opt', 'allow_pm') && $mode != 'edit' )
  1112. {
  1113. $message = ($lang['CANNOT_SEND_PRIVMSG']);
  1114. }
  1115. //
  1116. // Start output, first preview, then errors then post form
  1117. //
  1118. $page_title = $lang['SEND_PRIVATE_MESSAGE'];
  1119. if ( $preview && !$error )
  1120. {
  1121. $orig_word = array();
  1122. $replacement_word = array();
  1123. obtain_word_list($orig_word, $replacement_word);
  1124. $preview_message = htmlCHR($privmsg_message, false, ENT_NOQUOTES);
  1125. $preview_message = bbcode2html($privmsg_message);
  1126. if ( count($orig_word) )
  1127. {
  1128. $preview_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject);
  1129. $preview_message = preg_replace($orig_word, $replacement_word, $preview_message);
  1130. }
  1131. else
  1132. {
  1133. $preview_subject = $privmsg_subject;
  1134. }
  1135. $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
  1136. $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
  1137. if ( isset($privmsg_id) )
  1138. {
  1139. $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
  1140. }
  1141. $template->assign_vars(array(
  1142. 'TPL_PREVIEW_POST' => true,
  1143. 'TOPIC_TITLE' => wbr($preview_subject),
  1144. 'POST_SUBJECT' => $preview_subject,
  1145. 'MESSAGE_TO' => $to_username,
  1146. 'MESSAGE_FROM' => $userdata['username'],
  1147. 'POST_DATE' => bb_date(TIMENOW),
  1148. 'PREVIEW_MSG' => $preview_message,
  1149. 'S_HIDDEN_FIELDS' => $s_hidden_fields,
  1150. ));
  1151. }
  1152. //
  1153. // Start error handling
  1154. //
  1155. if ($error)
  1156. {
  1157. $template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
  1158. }
  1159. //
  1160. // Load templates
  1161. //
  1162. $template->set_filenames(array(
  1163. 'body' => 'posting.tpl')
  1164. );
  1165. //
  1166. // Enable extensions in posting_body
  1167. //
  1168. $template->assign_block_vars('switch_privmsg', array());
  1169. $template->assign_var('POSTING_USERNAME');
  1170. $post_a = '&nbsp;';
  1171. if ( $mode == 'post' )
  1172. {
  1173. $post_a = $lang['SEND_A_NEW_MESSAGE'];
  1174. }
  1175. else if ( $mode == 'reply' )
  1176. {
  1177. $post_a = $lang['SEND_A_REPLY'];
  1178. $mode = 'post';
  1179. }
  1180. else if ( $mode == 'edit' )
  1181. {
  1182. $post_a = $lang['EDIT_MESSAGE'];
  1183. }
  1184. $s_hidden_fields = '<input type="hidden" name="folder" value="' . $folder . '" />';
  1185. $s_hidden_fields .= '<input type="hidden" name="mode" value="' . $mode . '" />';
  1186. if ( $mode == 'edit' )
  1187. {
  1188. $s_hidden_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $privmsg_id . '" />';
  1189. }
  1190. //
  1191. // Send smilies to template
  1192. //
  1193. generate_smilies('inline');
  1194. $privmsg_subject = clean_title($privmsg_subject);
  1195. $template->assign_vars(array(
  1196. 'SUBJECT' => htmlCHR($privmsg_subject),
  1197. 'USERNAME' => $to_username,
  1198. 'MESSAGE' => $privmsg_message,
  1199. 'FORUM_NAME' => $lang['PRIVATE_MESSAGE'],
  1200. 'BOX_NAME' => $l_box_name,
  1201. 'INBOX' => $inbox_url,
  1202. 'SENTBOX' => $sentbox_url,
  1203. 'OUTBOX' => $outbox_url,
  1204. 'SAVEBOX' => $savebox_url,
  1205. 'POSTING_TYPE_TITLE' => $post_a,
  1206. 'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields,
  1207. 'S_POST_ACTION' => PM_URL,
  1208. 'U_SEARCH_USER' => "search.php?mode=searchuser",
  1209. 'U_VIEW_FORUM' => PM_URL,
  1210. ));
  1211. }
  1212. else
  1213. {
  1214. //
  1215. // Reset PM counters
  1216. //
  1217. $userdata['user_new_privmsg'] = 0;
  1218. $userdata['user_unread_privmsg'] = $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'];
  1219. $userdata['user_last_privmsg'] = $userdata['session_start'];
  1220. //
  1221. // Update unread status
  1222. //
  1223. db_update_userdata($userdata, array(
  1224. 'user_unread_privmsg' => 'user_unread_privmsg + user_new_privmsg',
  1225. 'user_new_privmsg' => 0,
  1226. 'user_last_privmsg' => $userdata['session_start'],
  1227. ));
  1228. $sql = "UPDATE " . BB_PRIVMSGS . "
  1229. SET privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
  1230. WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1231. AND privmsgs_to_userid = " . $userdata['user_id'];
  1232. if ( !DB()->sql_query($sql) )
  1233. {
  1234. message_die(GENERAL_ERROR, 'Could not update private message new/read status (2) for user', '', __LINE__, __FILE__, $sql);
  1235. }
  1236. //
  1237. // Generate page
  1238. //
  1239. $page_title = $lang['PRIVATE_MESSAGING'];
  1240. //
  1241. // Load templates
  1242. //
  1243. $template->set_filenames(array(
  1244. 'body' => 'privmsgs.tpl')
  1245. );
  1246. $orig_word = array();
  1247. $replacement_word = array();
  1248. obtain_word_list($orig_word, $replacement_word);
  1249. //
  1250. // New message
  1251. //
  1252. $post_new_mesg_url = '<a href="' . PM_URL .'?mode=post"><img src="' . $images['post_new'] . '" alt="' . $lang['SEND_A_NEW_MESSAGE'] . '" border="0" /></a>';
  1253. //
  1254. // General SQL to obtain messages
  1255. //
  1256. $sql_tot = "SELECT COUNT(privmsgs_id) AS total
  1257. FROM " . BB_PRIVMSGS . " ";
  1258. $sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username, u.user_rank
  1259. FROM " . BB_PRIVMSGS . " pm, " . BB_USERS . " u ";
  1260. switch( $folder )
  1261. {
  1262. case 'inbox':
  1263. $sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
  1264. AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1265. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  1266. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  1267. $sql .= "WHERE pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  1268. AND u.user_id = pm.privmsgs_from_userid
  1269. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1270. OR pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  1271. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  1272. break;
  1273. case 'outbox':
  1274. $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  1275. AND ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1276. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  1277. $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  1278. AND u.user_id = pm.privmsgs_to_userid
  1279. AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1280. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )";
  1281. break;
  1282. case 'sentbox':
  1283. $sql_tot .= "WHERE privmsgs_from_userid = " . $userdata['user_id'] . "
  1284. AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  1285. $sql .= "WHERE pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  1286. AND u.user_id = pm.privmsgs_to_userid
  1287. AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  1288. break;
  1289. case 'savebox':
  1290. $sql_tot .= "WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
  1291. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  1292. OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
  1293. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
  1294. $sql .= "WHERE u.user_id = pm.privmsgs_from_userid
  1295. AND ( ( pm.privmsgs_to_userid = " . $userdata['user_id'] . "
  1296. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
  1297. OR ( pm.privmsgs_from_userid = " . $userdata['user_id'] . "
  1298. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . " ) )";
  1299. break;
  1300. default:
  1301. message_die(GENERAL_MESSAGE, $lang['NO_SUCH_FOLDER']);
  1302. break;
  1303. }
  1304. //
  1305. // Show messages over previous x days/months
  1306. //
  1307. if ( $submit_msgdays && ( !empty($_POST['msgdays']) || !empty($_GET['msgdays']) ) )
  1308. {
  1309. $msg_days = ( !empty($_POST['msgdays']) ) ? intval($_POST['msgdays']) : intval($_GET['msgdays']);
  1310. $min_msg_time = TIMENOW - ($msg_days * 86400);
  1311. $limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
  1312. $limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";
  1313. if ( !empty($_POST['msgdays']) )
  1314. {
  1315. $start = 0;
  1316. }
  1317. }
  1318. else
  1319. {
  1320. $limit_msg_time = $limit_msg_time_total = '';
  1321. $msg_days = 0;
  1322. }
  1323. $sql .= $limit_msg_time . " ORDER BY pm.privmsgs_date DESC LIMIT $start, " . $bb_cfg['topics_per_page'];
  1324. $sql_all_tot = $sql_tot;
  1325. $sql_tot .= $limit_msg_time_total;
  1326. //
  1327. // Get messages
  1328. //
  1329. if ( !($result = DB()->sql_query($sql_tot)) )
  1330. {
  1331. message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
  1332. }
  1333. $pm_total = ( $row = DB()->sql_fetchrow($result) ) ? $row['total'] : 0;
  1334. if ( !($result = DB()->sql_query($sql_all_tot)) )
  1335. {
  1336. message_die(GENERAL_ERROR, 'Could not query private message information', '', __LINE__, __FILE__, $sql_tot);
  1337. }
  1338. $pm_all_total = ( $row = DB()->sql_fetchrow($result) ) ? $row['total'] : 0;
  1339. //
  1340. // Build select box
  1341. //
  1342. $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
  1343. $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']);
  1344. $select_msg_days = '';
  1345. for($i = 0; $i < count($previous_days); $i++)
  1346. {
  1347. $selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : '';
  1348. $select_msg_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
  1349. }
  1350. //
  1351. // Define correct icons
  1352. //
  1353. switch ( $folder )
  1354. {
  1355. case 'inbox':
  1356. $l_box_name = $lang['INBOX'];
  1357. break;
  1358. case 'outbox':
  1359. $l_box_name = $lang['OUTBOX'];
  1360. break;
  1361. case 'savebox':
  1362. $l_box_name = $lang['SAVEBOX'];
  1363. break;
  1364. case 'sentbox':
  1365. $l_box_name = $lang['SENTBOX'];
  1366. break;
  1367. }
  1368. $post_pm = PM_URL . "?mode=post";
  1369. $post_pm_img = '<a href="' . $post_pm . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['POST_NEW_PM'] . '" border="0" /></a>';
  1370. $post_pm = '<a href="' . $post_pm . '">' . $lang['POST_NEW_PM'] . '</a>';
  1371. //
  1372. // Output data for inbox status
  1373. //
  1374. $box_limit_img_length = $box_limit_percent = $l_box_size_status = '';
  1375. $max_pm = ($folder != 'outbox') ? $bb_cfg["max_{$folder}_privmsgs"] : null;
  1376. if ($max_pm)
  1377. {
  1378. $box_limit_percent = min(round(($pm_all_total / $max_pm) * 100), 100);
  1379. $box_limit_img_length = min(round(($pm_all_total / $max_pm) * $bb_cfg['privmsg_graphic_length']), $bb_cfg['privmsg_graphic_length']);
  1380. $box_limit_remain = max(($max_pm - $pm_all_total), 0);
  1381. $template->assign_var('PM_BOX_SIZE_INFO');
  1382. switch( $folder )
  1383. {
  1384. case 'inbox':
  1385. $l_box_size_status = sprintf($lang['INBOX_SIZE'], $box_limit_percent);
  1386. break;
  1387. case 'sentbox':
  1388. $l_box_size_status = sprintf($lang['SENTBOX_SIZE'], $box_limit_percent);
  1389. break;
  1390. case 'savebox':
  1391. $l_box_size_status = sprintf($lang['SAVEBOX_SIZE'], $box_limit_percent);
  1392. break;
  1393. default:
  1394. $l_box_size_status = '';
  1395. break;
  1396. }
  1397. }
  1398. //
  1399. // Dump vars to template
  1400. //
  1401. $template->assign_vars(array(
  1402. 'BOX_NAME' => $l_box_name,
  1403. 'BOX_EXPL' => ($folder == 'outbox') ? $lang['OUTBOX_EXPL'] : '',
  1404. 'INBOX' => $inbox_url,
  1405. 'SENTBOX' => $sentbox_url,
  1406. 'OUTBOX' => $outbox_url,
  1407. 'SAVEBOX' => $savebox_url,
  1408. 'POST_PM_IMG' => $post_pm_img,
  1409. 'POST_PM' => $post_pm,
  1410. 'INBOX_LIMIT_IMG_WIDTH' => max(4, $box_limit_img_length),
  1411. 'INBOX_LIMIT_PERCENT' => $box_limit_percent,
  1412. 'BOX_SIZE_STATUS' => ($l_box_size_status) ? $l_box_size_status : '',
  1413. 'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? $lang['FROM'] : $lang['TO'],
  1414. 'S_PRIVMSGS_ACTION' => PM_URL . "?folder=$folder",
  1415. 'S_HIDDEN_FIELDS' => '',
  1416. 'S_POST_NEW_MSG' => $post_new_mesg_url,
  1417. 'S_SELECT_MSG_DAYS' => $select_msg_days,
  1418. 'U_POST_NEW_TOPIC' => PM_URL . "?mode=post")
  1419. );
  1420. //
  1421. // Okay, let's build the correct folder
  1422. //
  1423. if ( !($result = DB()->sql_query($sql)) )
  1424. {
  1425. message_die(GENERAL_ERROR, 'Could not query private messages', '', __LINE__, __FILE__, $sql);
  1426. }
  1427. if ( $row = DB()->sql_fetchrow($result) )
  1428. {
  1429. $i = 0;
  1430. do
  1431. {
  1432. $privmsg_id = $row['privmsgs_id'];
  1433. $flag = $row['privmsgs_type'];
  1434. $icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg'];
  1435. $icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $lang['UNREAD_MESSAGE'] : $lang['READ_MESSAGE'];
  1436. $msg_userid = $row['user_id'];
  1437. $msg_user = profile_url($row);
  1438. $msg_subject = $row['privmsgs_subject'];
  1439. if ( count($orig_word) )
  1440. {
  1441. $msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject);
  1442. }
  1443. $u_subject = PM_URL . "?folder=$folder&amp;mode=read&amp;" . POST_POST_URL . "=$privmsg_id";
  1444. $msg_date = bb_date($row['privmsgs_date']);
  1445. if ( $flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox' )
  1446. {
  1447. $msg_subject = '<b>' . $msg_subject . '</b>';
  1448. $msg_date = '<b>' . $msg_date . '</b>';
  1449. $msg_user = '<b>' . $msg_user . '</b>';
  1450. }
  1451. $row_class = !($i & 1) ? 'row1' : 'row2';
  1452. $i++;
  1453. $template->assign_block_vars('listrow', array(
  1454. 'ROW_CLASS' => $row_class,
  1455. 'FROM' => $msg_user,
  1456. 'SUBJECT' => htmlCHR($msg_subject),
  1457. 'DATE' => $msg_date,
  1458. 'PRIVMSG_FOLDER_IMG' => $icon_flag,
  1459. 'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt,
  1460. 'S_MARK_ID' => $privmsg_id,
  1461. 'U_READ' => $u_subject,
  1462. ));
  1463. }
  1464. while( $row = DB()->sql_fetchrow($result) );
  1465. generate_pagination(PM_URL . "?folder=$folder", $pm_total, $bb_cfg['topics_per_page'], $start);
  1466. }
  1467. else
  1468. {
  1469. $template->assign_block_vars("switch_no_messages", array() );
  1470. }
  1471. }
  1472. $template->assign_vars(array('PAGE_TITLE' => @$page_title));
  1473. require(PAGE_HEADER);
  1474. $template->pparse('body');
  1475. require(PAGE_FOOTER);
  1476. //
  1477. // Functions
  1478. //
  1479. function pm_message_die ($msg)
  1480. {
  1481. global $lang;
  1482. $msg .= '<br /><br />';
  1483. $msg .= sprintf($lang['CLICK_RETURN_INBOX'], '<a href="' . PM_URL . "?folder=inbox".'">', '</a> ');
  1484. $msg .= sprintf($lang['CLICK_RETURN_SENTBOX'], '<a href="' . PM_URL . "?folder=sentbox".'">', '</a> ');
  1485. $msg .= sprintf($lang['CLICK_RETURN_OUTBOX'], '<a href="' . PM_URL . "?folder=outbox".'">', '</a> ');
  1486. $msg .= sprintf($lang['CLICK_RETURN_SAVEBOX'], '<a href="' . PM_URL . "?folder=savebox".'">', '</a> ');
  1487. $msg .= '<br /><br />';
  1488. $msg .= sprintf($lang['CLICK_RETURN_INDEX'], '<a href="'."index.php".'">', '</a>');
  1489. message_die(GENERAL_MESSAGE, $msg);
  1490. }