PageRenderTime 226ms CodeModel.GetById 28ms RepoModel.GetById 2ms app.codeStats 0ms

/privmsg.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 2330 lines | 1917 code | 290 blank | 123 comment | 384 complexity | 683998d027a85142824677bf2203ff51 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. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Icy Phoenix is based on phpBB
  13. * @copyright (c) 2008 phpBB Group
  14. *
  15. */
  16. define('IN_PM', true);
  17. // MG Cash MOD For IP - BEGIN
  18. define('IN_CASHMOD', true);
  19. // MG Cash MOD For IP - END
  20. // Added to optimize memory for attachments
  21. define('ATTACH_DISPLAY', true);
  22. define('ATTACH_PM', true);
  23. define('IN_ICYPHOENIX', true);
  24. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  25. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  26. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  27. include_once(IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
  28. include_once(IP_ROOT_PATH . 'includes/functions_post.' . PHP_EXT);
  29. include_once(IP_ROOT_PATH . 'includes/functions_users.' . PHP_EXT);
  30. include_once(IP_ROOT_PATH . 'includes/functions_zebra.' . PHP_EXT);
  31. // Adding CPL_NAV only if needed
  32. define('PARSE_CPL_NAV', true);
  33. // Is PM disabled?
  34. if (!empty($config['privmsg_disable']))
  35. {
  36. message_die(GENERAL_MESSAGE, 'PM_disabled');
  37. }
  38. $html_entities_match = array('#&(?!(\#[0-9]+;))#', '#<#', '#>#', '#"#');
  39. $html_entities_replace = array('&amp;', '&lt;', '&gt;', '&quot;');
  40. // Parameters
  41. $privmsg_id = request_var(POST_POST_URL, 0);
  42. $mode = request_var('mode', '');
  43. $start = request_var('start', 0);
  44. $start = ($start < 0) ? 0 : $start;
  45. $sid = request_post_var('sid', '');
  46. $submit = (isset($_POST['post'])) ? true : false;
  47. $submit_search = (isset($_POST['usersubmit'])) ? true : false;
  48. $submit_msgdays = (isset($_POST['submit_msgdays'])) ? true : false;
  49. $cancel = (isset($_POST['cancel'])) ? true : false;
  50. $preview = (isset($_POST['preview'])) ? true : false;
  51. $confirm = (isset($_POST['confirm'])) ? true : false;
  52. $delete = (isset($_POST['delete'])) ? true : false;
  53. $delete_all = (isset($_POST['deleteall'])) ? true : false;
  54. $download = (isset($_POST['download'])) ? true : false;
  55. $save = (isset($_POST['save'])) ? true : false;
  56. $draft = request_var('draft', '');
  57. $draft_mode = request_var('draft_mode', '');
  58. $draft_confirm = !empty($_POST['draft_confirm']) ? true : false;
  59. $draft = (!empty($draft) || $draft_confirm) ? true : false;
  60. $draft_id = request_var('d', 0);
  61. if (($config['allow_drafts'] == true) && ($draft_mode == 'draft_load') && ($draft_id > 0))
  62. {
  63. $sql = "SELECT d.*
  64. FROM " . DRAFTS_TABLE . " d
  65. WHERE d.draft_id = '" . $draft_id . "'
  66. AND d.user_id = '" . $user->data['user_id'] . "'
  67. LIMIT 1";
  68. $result = $db->sql_query($sql);
  69. if ($draft_row = $db->sql_fetchrow($result))
  70. {
  71. $db->sql_freeresult($result);
  72. $draft_subject = $draft_row['draft_subject'];
  73. $draft_message = htmlspecialchars_decode($draft_row['draft_message'], ENT_COMPAT);
  74. $preview = true;
  75. }
  76. }
  77. $search_type = request_var('searchvar', '');
  78. $search_value = request_var('searchvalue', '');
  79. $search_value_tmp = request_var('searchvalue2', '');
  80. $search_value = (!empty($search_value) && !empty($search_value_tmp)) ? $search_value_tmp : $search_value;
  81. $refresh = $preview || $submit_search || ($draft && !$draft_confirm);
  82. $mark_list = request_var('mark', array(0));
  83. $folders_array = array('inbox', 'outbox', 'sentbox', 'savebox');
  84. $folder = request_var('folder', 'inbox');
  85. $folder = check_var_value($folder, $folders_array);
  86. // Start session management
  87. $user->session_begin();
  88. $auth->acl($user->data);
  89. $user->setup();
  90. // End session management
  91. // Cancel
  92. if ($cancel)
  93. {
  94. redirect(append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder, true));
  95. }
  96. // Check search fields
  97. $search_list = array(
  98. 'author' => 'author is',
  99. 'subject' => 'subject contains',
  100. );
  101. if(empty($search_value) || empty($search_type) || intval($search_type) || !isset($search_list[$search_type]))
  102. {
  103. $search_type = '';
  104. }
  105. if(empty($search_type))
  106. {
  107. $search_value = '';
  108. }
  109. $template->vars['SEARCH_TYPES'] = '';
  110. foreach($search_list as $var => $value)
  111. {
  112. $template->vars['SEARCH_TYPES'] .= '<option value="' . $var . '"' . ($search_type === $var ? ' selected="selected"' : '') . '>' . $value . '</option>';
  113. }
  114. $template->vars['SEARCH_VALUE'] = htmlspecialchars($search_value);
  115. $error = false;
  116. // Define the box image links
  117. $inbox_img = ($folder != 'inbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '"><img src="' . $images['pm_inbox'] . '" alt="' . $lang['Inbox'] . '" title="' . $lang['Inbox'] . '" /></a>' : '<img src="' . $images['pm_inbox'] . '" alt="' . $lang['Inbox'] . '" title="' . $lang['Inbox'] . '" />';
  118. $inbox_url = ($folder != 'inbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '">' . $lang['Inbox'] . '</a>' : $lang['Inbox'];
  119. $outbox_img = ($folder != 'outbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=outbox') . '"><img src="' . $images['pm_outbox'] . '" alt="' . $lang['Outbox'] . '" title="' . $lang['Outbox'] . '" /></a>' : '<img src="' . $images['pm_outbox'] . '" alt="' . $lang['Outbox'] . '" title="' . $lang['Outbox'] . '" />';
  120. $outbox_url = ($folder != 'outbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=outbox') . '">' . $lang['Outbox'] . '</a>' : $lang['Outbox'];
  121. $sentbox_img = ($folder != 'sentbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=sentbox') . '"><img src="' . $images['pm_sentbox'] . '" alt="' . $lang['Sentbox'] . '" title="' . $lang['Sentbox'] . '" /></a>' : '<img src="' . $images['pm_sentbox'] . '" alt="' . $lang['Sentbox'] . '" title="' . $lang['Sentbox'] . '" />';
  122. $sentbox_url = ($folder != 'sentbox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=sentbox') . '">' . $lang['Sentbox'] . '</a>' : $lang['Sentbox'];
  123. $savebox_img = ($folder != 'savebox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=savebox') . '"><img src="' . $images['pm_savebox'] . '" alt="' . $lang['Savebox'] . '" title="' . $lang['Savebox'] . '" /></a>' : '<img src="' . $images['pm_savebox'] . '" alt="' . $lang['Savebox'] . '" title="' . $lang['Savebox'] . '" />';
  124. $savebox_url = ($folder != 'savebox' || $mode != '') ? '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=savebox') . '">' . $lang['Savebox'] . '</a>' : $lang['Savebox'];
  125. execute_privmsgs_attachment_handling($mode);
  126. // Start main
  127. if ($mode == 'newpm')
  128. {
  129. $link_name = '';
  130. if ($mode == 'post')
  131. {
  132. $link_name = $lang['Send_a_new_message'];
  133. }
  134. elseif ($mode == 'reply')
  135. {
  136. $link_name = $lang['Send_a_reply'];
  137. }
  138. elseif ($mode == 'edit')
  139. {
  140. $link_name = $lang['Edit_message'];
  141. }
  142. $nav_server_url = create_server_url();
  143. $breadcrumbs['address'] = $lang['Nav_Separator'] . '<a href="' . $nav_server_url . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '"' . (!empty($link_name) ? '' : ' class="nav-current"') . '>' . $lang['Private_Messaging'] . '</a>' . (!empty($link_name) ? ($lang['Nav_Separator'] . '<a class="nav-current" href="#">' . $link_name . '</a>') : '');
  144. include_once(IP_ROOT_PATH . 'includes/users_zebra_block.' . PHP_EXT);
  145. if ($user->data['session_logged_in'])
  146. {
  147. if ($user->data['user_new_privmsg'])
  148. {
  149. $l_new_message = ($user->data['user_new_privmsg'] == 1) ? $lang['You_new_pm'] : $lang['You_new_pms'];
  150. }
  151. else
  152. {
  153. $l_new_message = $lang['You_no_new_pm'];
  154. }
  155. $l_new_message .= '<br /><br />' . sprintf($lang['Click_view_privmsg'], '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '" onclick="jump_to_inbox();return false;" target="_new">', '</a>');
  156. }
  157. else
  158. {
  159. $l_new_message = $lang['Login_check_pm'];
  160. }
  161. $template->assign_vars(array(
  162. 'L_CLOSE_WINDOW' => $lang['Close_window'],
  163. 'L_MESSAGE' => $l_new_message
  164. )
  165. );
  166. $gen_simple_header = true;
  167. full_page_generation('privmsgs_popup.tpl', $lang['Private_Messaging'], '', '');
  168. }
  169. elseif ($mode == 'read')
  170. {
  171. if (!empty($_GET[POST_POST_URL]))
  172. {
  173. $privmsgs_id = intval($_GET[POST_POST_URL]);
  174. }
  175. else
  176. {
  177. message_die(GENERAL_ERROR, $lang['No_post_id']);
  178. }
  179. if (!$user->data['session_logged_in'])
  180. {
  181. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=privmsg.' . PHP_EXT . '&folder=' . $folder . '&mode=' . $mode . '&' . POST_POST_URL . '=' . $privmsgs_id, true));
  182. }
  183. $ranks_array = $cache->obtain_ranks(false);
  184. // SQL to pull appropriate message, prevents nosey people
  185. // reading other peoples messages ... hopefully!
  186. switch($folder)
  187. {
  188. case 'inbox':
  189. $l_box_name = $lang['Inbox'];
  190. $pm_sql_user = "AND pm.privmsgs_to_userid = " . $user->data['user_id'] . "
  191. AND (pm.privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  192. OR pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  193. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  194. break;
  195. case 'outbox':
  196. $l_box_name = $lang['Outbox'];
  197. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $user->data['user_id'] . "
  198. AND (pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  199. OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ") ";
  200. break;
  201. case 'sentbox':
  202. $l_box_name = $lang['Sentbox'];
  203. $pm_sql_user = "AND pm.privmsgs_from_userid = " . $user->data['user_id'] . "
  204. AND pm.privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  205. break;
  206. case 'savebox':
  207. $l_box_name = $lang['Savebox'];
  208. $pm_sql_user = "AND ((pm.privmsgs_to_userid = " . $user->data['user_id'] . "
  209. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . ")
  210. OR (pm.privmsgs_from_userid = " . $user->data['user_id'] . "
  211. AND pm.privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ")
  212. )";
  213. break;
  214. default:
  215. message_die(GENERAL_ERROR, $lang['No_such_folder']);
  216. break;
  217. }
  218. // BEGIN PM Navigation MOD
  219. if(($_GET['view'] == 'next') || ($_GET['view'] == 'prev'))
  220. {
  221. $sql_condition = ($_GET['view'] == 'next') ? '>' : '<';
  222. $sql_ordering = ($_GET['view'] == 'next') ? 'ASC' : 'DESC';
  223. $sql_nav = "SELECT pm.privmsgs_id FROM ". PRIVMSGS_TABLE ." pm, ". PRIVMSGS_TABLE ." p2
  224. WHERE p2.privmsgs_id = $privmsgs_id
  225. $pm_sql_user
  226. AND pm.privmsgs_date $sql_condition p2.privmsgs_date
  227. ORDER BY pm.privmsgs_date $sql_ordering LIMIT 1" ;
  228. $result_nav = $db->sql_query($sql_nav);
  229. if ($row = $db->sql_fetchrow($result_nav))
  230. {
  231. $privmsgs_id = intval($row['privmsgs_id']);
  232. }
  233. else
  234. {
  235. $output_message = (($_GET['view'] == 'next') ? $lang['No_newer_pm'] : $lang['No_older_pm']) . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid(CMS_PAGE_FORUM) . '">', '</a>');
  236. message_die(GENERAL_MESSAGE, $output_message);
  237. }
  238. }
  239. // END PM Navigation MOD
  240. // Major query obtains the message ...
  241. $sql = "SELECT u.username AS username_1, u.user_id AS user_id_1, u.user_active AS user_active_1, u.user_color AS user_color_1, u2.username AS username_2, u2.user_id AS user_id_2, u2.user_active AS user_active_2, u2.user_color AS user_color_2, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_skype, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_rank, u.user_sig, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allow_viewonline, u.user_session_time, u.user_from, u.user_gender, pm.*
  242. FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
  243. WHERE pm.privmsgs_id = $privmsgs_id
  244. $pm_sql_user
  245. AND u.user_id = pm.privmsgs_from_userid
  246. AND u2.user_id = pm.privmsgs_to_userid";
  247. $result = $db->sql_query($sql);
  248. // Did the query return any data?
  249. if (!($privmsg = $db->sql_fetchrow($result)))
  250. {
  251. redirect(append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder, true));
  252. }
  253. $privmsg_id = $privmsg['privmsgs_id'];
  254. // Is this a new message in the inbox? If it is then save a copy in the posters sent box
  255. if ((($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL) || ($privmsg['privmsgs_type'] == PRIVMSGS_UNREAD_MAIL)) && ($folder == 'inbox'))
  256. {
  257. // Update appropriate counter
  258. switch ($privmsg['privmsgs_type'])
  259. {
  260. case PRIVMSGS_NEW_MAIL:
  261. $sql = "user_new_privmsg = user_new_privmsg - 1";
  262. break;
  263. case PRIVMSGS_UNREAD_MAIL:
  264. $sql = "user_unread_privmsg = user_unread_privmsg - 1";
  265. break;
  266. }
  267. $sql = "UPDATE " . USERS_TABLE . "
  268. SET $sql
  269. WHERE user_id = " . $user->data['user_id'];
  270. $result = $db->sql_query($sql);
  271. $sql = "UPDATE " . PRIVMSGS_TABLE . "
  272. SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  273. WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
  274. $result = $db->sql_query($sql);
  275. // Check to see if the poster has a 'full' sent box
  276. $sql = "SELECT COUNT(privmsgs_id) AS sent_items, MIN(privmsgs_date) AS oldest_post_time
  277. FROM " . PRIVMSGS_TABLE . "
  278. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  279. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  280. $result = $db->sql_query($sql);
  281. if ($sent_info = $db->sql_fetchrow($result))
  282. {
  283. if ($config['max_sentbox_privmsgs'] && ($sent_info['sent_items'] >= $config['max_sentbox_privmsgs']))
  284. {
  285. $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
  286. WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
  287. AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
  288. AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
  289. $result = $db->sql_query($sql);
  290. $old_privmsgs_id = $db->sql_fetchrow($result);
  291. $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
  292. if (!empty($old_privmsgs_id))
  293. {
  294. $sql = "DELETE FROM " . PRIVMSGS_TABLE . "
  295. WHERE privmsgs_id = " . $old_privmsgs_id;
  296. $result = $db->sql_query($sql);
  297. }
  298. }
  299. }
  300. //
  301. // This makes a copy of the post and stores it as a SENT message from the sender. Perhaps
  302. // not the most DB friendly way but a lot easier to manage, besides the admin will be able to
  303. // set limits on numbers of storable posts for users... hopefully!
  304. //
  305. $sql = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_text, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_enable_autolinks_acronyms, privmsgs_attach_sig)
  306. VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . $db->sql_escape($privmsg['privmsgs_subject']) . "', '" . $db->sql_escape($privmsg['privmsgs_text']) . "', " . $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_enable_autolinks_acronyms'] . ", " . $privmsg['privmsgs_attach_sig'] . ")";
  307. $result = $db->sql_query($sql);
  308. $privmsg_sent_id = $db->sql_nextid();
  309. }
  310. $attachment_mod['pm']->duplicate_attachment_pm($privmsg['privmsgs_attachment'], $privmsg['privmsgs_id'], $privmsg_sent_id);
  311. // Pick a folder, any folder, so long as it's one below ...
  312. $post_urls = array(
  313. 'post' => append_sid(CMS_PAGE_PRIVMSG . '?mode=post'),
  314. 'reply' => append_sid(CMS_PAGE_PRIVMSG . '?mode=reply&amp;' . POST_POST_URL . '=' . $privmsg_id),
  315. 'quote' => append_sid(CMS_PAGE_PRIVMSG . '?mode=quote&amp;' . POST_POST_URL . '=' . $privmsg_id),
  316. 'edit' => append_sid(CMS_PAGE_PRIVMSG . '?mode=edit&amp;' . POST_POST_URL . '=' . $privmsg_id)
  317. );
  318. $post_icons = array(
  319. 'post_img' => '<a href="' . $post_urls['post'] . '"><img src="' . $images['pm_postmsg'] . '" alt="' . $lang['Post_new_pm'] . '" /></a>',
  320. 'post' => '<a href="' . $post_urls['post'] . '">' . $lang['Post_new_pm'] . '</a>',
  321. 'reply_img' => '<a href="' . $post_urls['reply'] . '"><img src="' . $images['pm_replymsg'] . '" alt="' . $lang['Post_reply_pm'] . '" /></a>',
  322. 'reply' => '<a href="' . $post_urls['reply'] . '">' . $lang['Post_reply_pm'] . '</a>',
  323. 'quote_img' => '<a href="' . $post_urls['quote'] . '"><img src="' . $images['pm_quotemsg'] . '" alt="' . $lang['Post_quote_pm'] . '" /></a>',
  324. 'quote' => '<a href="' . $post_urls['quote'] . '">' . $lang['Post_quote_pm'] . '</a>',
  325. 'edit_img' => '<a href="' . $post_urls['edit'] . '"><img src="' . $images['pm_editmsg'] . '" alt="' . $lang['Edit_pm'] . '" /></a>',
  326. 'edit' => '<a href="' . $post_urls['edit'] . '">' . $lang['Edit_pm'] . '</a>'
  327. );
  328. if ($folder == 'inbox')
  329. {
  330. $post_img = $post_icons['post_img'];
  331. $reply_img = $post_icons['reply_img'];
  332. $quote_img = $post_icons['quote_img'];
  333. $edit_img = '';
  334. $post = $post_icons['post'];
  335. $reply = $post_icons['reply'];
  336. $quote = $post_icons['quote'];
  337. $edit = '';
  338. $post_url = $post_urls['post'];
  339. $reply_url = $post_urls['reply'];
  340. $quote_url = $post_urls['quote'];
  341. $edit_url = '';
  342. $l_box_name = $lang['Inbox'];
  343. }
  344. elseif ($folder == 'outbox')
  345. {
  346. $post_img = $post_icons['post_img'];
  347. $reply_img = '';
  348. $quote_img = '';
  349. $edit_img = $post_icons['edit_img'];
  350. $post = $post_icons['post'];
  351. $reply = '';
  352. $quote = '';
  353. $edit = $post_icons['edit'];
  354. $post_url = $post_urls['post'];
  355. $reply_url = '';
  356. $quote_url = '';
  357. $edit_url = $post_urls['edit'];
  358. $l_box_name = $lang['Outbox'];
  359. }
  360. elseif ($folder == 'savebox')
  361. {
  362. if ($privmsg['privmsgs_type'] == PRIVMSGS_SAVED_IN_MAIL)
  363. {
  364. $post_img = $post_icons['post_img'];
  365. $reply_img = $post_icons['reply_img'];
  366. $quote_img = $post_icons['quote_img'];
  367. $edit_img = '';
  368. $post = $post_icons['post'];
  369. $reply = $post_icons['reply'];
  370. $quote = $post_icons['quote'];
  371. $edit = '';
  372. $post_url = $post_urls['post'];
  373. $reply_url = $post_urls['reply'];
  374. $quote_url = $post_urls['quote'];
  375. $edit_url = '';
  376. }
  377. else
  378. {
  379. $post_img = $post_icons['post_img'];
  380. $reply_img = '';
  381. $quote_img = '';
  382. $edit_img = '';
  383. $post = $post_icons['post'];
  384. $reply = '';
  385. $quote = '';
  386. $edit = '';
  387. $post_url = $post_urls['post'];
  388. $reply_url = '';
  389. $quote_url = '';
  390. $edit_url = '';
  391. }
  392. $l_box_name = $lang['Saved'];
  393. }
  394. elseif ($folder == 'sentbox')
  395. {
  396. $post_img = $post_icons['post_img'];
  397. $reply_img = '';
  398. $quote_img = '';
  399. $edit_img = '';
  400. $post = $post_icons['post'];
  401. $reply = '';
  402. $quote = '';
  403. $edit = '';
  404. $post_url = $post_urls['post'];
  405. $reply_url = '';
  406. $quote_url = '';
  407. $edit_url = '';
  408. $l_box_name = '';
  409. }
  410. $s_hidden_fields = '<input type="hidden" name="mark[]" value="' . $privmsgs_id . '" />';
  411. $nav_server_url = create_server_url();
  412. $breadcrumbs['address'] = $lang['Nav_Separator'] . '<a href="' . $nav_server_url . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '">' . $lang['Private_Messaging'] . '</a>' . $lang['Nav_Separator'] . '<a class="nav-current" href="#">' . $privmsg['privmsgs_subject'] . '</a>';
  413. $breadcrumbs['bottom_right_links'] = '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder . '&amp;mode=' . $mode . '&amp;' . POST_POST_URL . '=' . $privmsgs_id . '&amp;view=prev', true) . '">' . $lang['Previous_privmsg'] . '</a> &bull; <a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder . '&amp;mode=' . $mode . '&amp;' . POST_POST_URL . '=' . $privmsgs_id . '&amp;view=next', true) . '">' . $lang['Next_privmsg'] . '</a>';
  414. $skip_nav_cat = true;
  415. include_once(IP_ROOT_PATH . 'includes/users_zebra_block.' . PHP_EXT);
  416. make_jumpbox(CMS_PAGE_VIEWFORUM);
  417. $template->assign_vars(array(
  418. 'INBOX_IMG' => $inbox_img,
  419. 'SENTBOX_IMG' => $sentbox_img,
  420. 'OUTBOX_IMG' => $outbox_img,
  421. 'SAVEBOX_IMG' => $savebox_img,
  422. 'INBOX' => $inbox_url,
  423. 'SENTBOX' => $sentbox_url,
  424. 'OUTBOX' => $outbox_url,
  425. 'SAVEBOX' => $savebox_url,
  426. 'BOX_NAME' => $l_box_name,
  427. 'L_QUICK_REPLY' => $lang['Quick_Reply'],
  428. 'L_EDIT_PM' => $lang['Edit_pm'],
  429. 'L_QUOTE_PM' => $lang['Post_quote_pm'],
  430. 'L_POST_PM' => $lang['Post_new_pm'],
  431. 'L_REPLY_PM' => $lang['Post_reply_pm'],
  432. 'EDIT_PM_URL' => $edit_url,
  433. 'POST_PM_URL' => $post_url,
  434. 'QUOTE_PM_URL' => $quote_url,
  435. 'REPLY_PM_URL' => $reply_url,
  436. 'POST_PM_IMG' => $post_img,
  437. 'REPLY_PM_IMG' => $reply_img,
  438. 'EDIT_PM_IMG' => $edit_img,
  439. 'QUOTE_PM_IMG' => $quote_img,
  440. 'POST_PM' => $post,
  441. 'REPLY_PM' => $reply,
  442. 'EDIT_PM' => $edit,
  443. 'QUOTE_PM' => $quote,
  444. 'IMG_QUICK_QUOTE' => $images['icon_quick_quote'],
  445. 'IMG_OFFTOPIC' => $images['icon_offtopic'],
  446. 'L_MESSAGE' => $lang['Message'],
  447. 'L_INBOX' => $lang['Inbox'],
  448. 'L_OUTBOX' => $lang['Outbox'],
  449. 'L_SENTBOX' => $lang['Sent'],
  450. 'L_SAVEBOX' => $lang['Saved'],
  451. 'L_FLAG' => $lang['Flag'],
  452. 'L_SUBJECT' => $lang['Subject'],
  453. 'L_QUICK_QUOTE' => $lang['QuickQuote'],
  454. 'L_OFFTOPIC' => $lang['OffTopic'],
  455. 'L_POSTED' => $lang['Posted'],
  456. 'L_DATE' => $lang['Date'],
  457. 'L_FROM' => $lang['From'],
  458. 'L_TO' => $lang['To'],
  459. 'L_SAVE_MSG' => $lang['Save_message'],
  460. 'L_DELETE_MSG' => $lang['Delete_message'],
  461. 'L_PM' => $lang['Private_Message'],
  462. 'L_EMAIL' => $lang['Email'],
  463. 'L_POSTS' => $lang['Posts'],
  464. 'L_CONTACTS' => $lang['User_Contacts'],
  465. 'L_WEBSITE' => $lang['Website'],
  466. 'L_FROM' => $lang['Location'],
  467. 'L_ONLINE_STATUS' => $lang['Online_status'],
  468. 'L_USER_WWW' => $lang['Website'],
  469. 'L_USER_EMAIL' => $lang['Send_Email'],
  470. 'L_USER_PROFILE' => $lang['Profile'],
  471. // BEGIN PM Navigation MOD
  472. 'L_PRIVMSG_NEXT' => $lang['Next_privmsg'],
  473. 'L_PRIVMSG_PREVIOUS' => $lang['Previous_privmsg'],
  474. 'U_PRIVMSG_NEXT' => append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder . '&amp;mode=' . $mode . '&amp;' . POST_POST_URL . '=' . $privmsgs_id . '&amp;view=next', true),
  475. 'U_PRIVMSG_PREVIOUS' => append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder . '&amp;mode=' . $mode . '&amp;' . POST_POST_URL . '=' . $privmsgs_id . '&amp;view=prev', true),
  476. // END PM Navigation MOD
  477. 'S_PRIVMSGS_ACTION' => append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder),
  478. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  479. )
  480. );
  481. $username_from = colorize_username($privmsg['user_id_1'], $privmsg['username_1'], $privmsg['user_color_1'], $privmsg['user_active_1']);
  482. $user_id_from = $privmsg['user_id_1'];
  483. $username_to = colorize_username($privmsg['user_id_2'], $privmsg['username_2'], $privmsg['user_color_2'], $privmsg['user_active_2']);
  484. $user_id_to = $privmsg['user_id_2'];
  485. // Needed for attachments... do not remove!
  486. $template_to_parse = 'privmsgs_read_body.tpl';
  487. $template->set_filenames(array('body' => $template_to_parse));
  488. init_display_pm_attachments($privmsg['privmsgs_attachment']);
  489. $post_date = create_date_ip($config['default_dateformat'], $privmsg['privmsgs_date'], $config['board_timezone']);
  490. $privmsg['user_id'] = $privmsg['user_id_1'];
  491. $privmsg['username'] = $privmsg['username_1'];
  492. $privmsg['user_color'] = $privmsg['user_color_1'];
  493. $privmsg['user_active'] = $privmsg['user_active_1'];
  494. $user_info = array();
  495. $user_info = generate_user_info($privmsg);
  496. foreach ($user_info as $k => $v)
  497. {
  498. ${$k} = $v;
  499. }
  500. $poster_avatar = $user_info['avatar'];
  501. $poster_posts = ($privmsg['user_id'] != ANONYMOUS) ? $lang['Posts'] . ': ' . $privmsg['user_posts'] : '';
  502. $poster_from = ($privmsg['user_from']) ? $lang['Location'] . ': ' . $privmsg['user_from'] : '';
  503. $poster_joined = ($privmsg['user_id'] != ANONYMOUS) ? $lang['Joined'] . ': ' . create_date($lang['JOINED_DATE_FORMAT'], $privmsg['user_regdate'], $config['board_timezone']) : '';
  504. // Mighty Gorgon - Quick Quote - BEGIN
  505. $look_up_array = array(
  506. '\"',
  507. '"',
  508. "<",
  509. ">",
  510. "\n",
  511. chr(13),
  512. );
  513. $replacement_array = array(
  514. '&q_mg;',
  515. '\"',
  516. "&lt_mg;",
  517. "&gt_mg;",
  518. "\\n",
  519. "",
  520. );
  521. $plain_message = $privmsg['privmsgs_text'];
  522. $plain_message = strtr($plain_message, array_flip(get_html_translation_table(HTML_ENTITIES)));
  523. $plain_message = censor_text($plain_message);
  524. $plain_message = str_replace($look_up_array, $replacement_array, $plain_message);
  525. // Mighty Gorgon - Quick Quote - END
  526. // Processing of post
  527. $post_subject = $privmsg['privmsgs_subject'];
  528. $private_message = $privmsg['privmsgs_text'];
  529. if ($config['allow_sig'])
  530. {
  531. $user_sig = ($privmsg['privmsgs_from_userid'] == $user->data['user_id']) ? $user->data['user_sig'] : $privmsg['user_sig'];
  532. }
  533. else
  534. {
  535. $user_sig = '';
  536. }
  537. // If the board has HTML off but the post has HTML on then we process it, else leave it alone
  538. if (!$config['allow_html'])
  539. {
  540. if ($user_sig != '' && $privmsg['privmsgs_enable_sig'] && $user->data['user_allowhtml'])
  541. {
  542. $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
  543. }
  544. if ($privmsg['privmsgs_enable_html'])
  545. {
  546. $private_message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $private_message);
  547. }
  548. }
  549. if (($user_sig != '') && $privmsg['privmsgs_attach_sig'])
  550. {
  551. $bbcode->allow_html = $config['allow_html'];
  552. $bbcode->allow_bbcode = $config['allow_bbcode'] ? true : false;
  553. $bbcode->allow_smilies = $config['allow_smilies'];
  554. $bbcode->is_sig = true;
  555. $user_sig = $bbcode->parse($user_sig);
  556. $bbcode->is_sig = false;
  557. }
  558. $bbcode->allow_html = (($config['allow_html'] && $user->data['user_allowhtml']) || $config['allow_html_only_for_admins']) && $privmsg['privmsgs_enable_html'];
  559. $bbcode->allow_bbcode = $config['allow_bbcode'] ? true : false;
  560. $bbcode->allow_smilies = $config['allow_smilies'] && $privmsg['privmsgs_enable_smilies'];
  561. $private_message = $bbcode->parse($private_message);
  562. if ($privmsg['privmsgs_attach_sig'] && $user_sig != '')
  563. {
  564. $signature = '<br />' . $config['sig_line'] . '<br />' . $user_sig;
  565. }
  566. $post_subject = censor_text($post_subject);
  567. $private_message = censor_text($private_message);
  568. //Acronyms, AutoLinks - BEGIN
  569. if ($privmsg['privmsgs_enable_autolinks_acronyms'])
  570. {
  571. $private_message = $bbcode->acronym_pass($private_message);
  572. $private_message = $bbcode->autolink_text($private_message, '999999');
  573. }
  574. //Acronyms, AutoLinks -END
  575. // Mighty Gorgon - Multiple Ranks - BEGIN
  576. $user_ranks = generate_ranks($privmsg, $ranks_array);
  577. if (($user_ranks['rank_01_html'] == '') && ($user_ranks['rank_01_img_html'] == '') && ($user_ranks['rank_02_html'] == '') && ($user_ranks['rank_02_img_html'] == '') && ($user_ranks['rank_03_html'] == '') && ($user_ranks['rank_03_img_html'] == '') && ($user_ranks['rank_04_html'] == '') && ($user_ranks['rank_04_img_html'] == '') && ($user_ranks['rank_05_html'] == '') && ($user_ranks['rank_05_img_html'] == ''))
  578. {
  579. $user_ranks['rank_01_html'] = '&nbsp;';
  580. }
  581. // Mighty Gorgon - Multiple Ranks - END
  582. $poster_rank = $user_ranks['rank_01_html'];
  583. $rank_image = $user_ranks['rank_01_img_html'];
  584. // Dump it to the templating engine
  585. $template->assign_vars(array(
  586. 'MESSAGE_TO' => $username_to,
  587. 'RECIPIENT_QQ' => $privmsg['username_1'],
  588. 'PM_ID' => $privmsgs_id,
  589. 'MESSAGE_FROM' => $username_from,
  590. 'RANK_IMAGE' => $rank_image,
  591. 'POSTER_JOINED' => $poster_joined,
  592. 'POSTER_POSTS' => $poster_posts,
  593. 'POSTER_FROM' => $poster_from,
  594. 'POSTER_AVATAR' => $poster_avatar,
  595. 'POST_SUBJECT' => $post_subject,
  596. 'POST_DATE' => $post_date,
  597. 'MESSAGE' => $private_message,
  598. 'PLAIN_MESSAGE' => $plain_message,
  599. 'SIGNATURE' => $signature,
  600. 'POSTER_RANK' => $poster_rank,
  601. 'RANK_IMAGE' => $rank_image,
  602. 'POSTER_GENDER' => $user_info['gender'],
  603. 'PROFILE_URL' => $user_info['profile_url'],
  604. 'PROFILE_IMG' => $user_info['profile_img'],
  605. 'PROFILE' => $user_info['profile'],
  606. 'PM_URL' => $user_info['pm_url'],
  607. 'PM_IMG' => $user_info['pm_img'],
  608. 'PM' => $user_info['pm'],
  609. 'SEARCH_URL' => $user_info['search_url'],
  610. 'SEARCH_IMG' => $user_info['search_img'],
  611. 'SEARCH' => $user_info['search'],
  612. 'IP_URL' => $user_info['ip_url'],
  613. 'IP_IMG' => $user_info['ip_img'],
  614. 'IP' => $user_info['ip'],
  615. 'EMAIL_URL' => $user_info['email_url'],
  616. 'EMAIL_IMG' => $user_info['email_img'],
  617. 'EMAIL' => $user_info['email'],
  618. 'WWW_URL' => $user_info['www_url'],
  619. 'WWW_IMG' => $user_info['www_img'],
  620. 'WWW' => $user_info['www'],
  621. 'AIM_URL' => $user_info['aim_url'],
  622. 'AIM_IMG' => $user_info['aim_img'],
  623. 'AIM' => $user_info['aim'],
  624. 'ICQ_STATUS_IMG' => $user_info['icq_status_img'],
  625. 'ICQ_URL' => $user_info['icq_url'],
  626. 'ICQ_IMG' => $user_info['icq_img'],
  627. 'ICQ' => $user_info['icq'],
  628. 'MSN_URL' => $user_info['msn_url'],
  629. 'MSN_IMG' => $user_info['msn_img'],
  630. 'MSN' => $user_info['msn'],
  631. 'SKYPE_URL' => $user_info['skype_url'],
  632. 'SKYPE_IMG' => $user_info['skype_img'],
  633. 'SKYPE' => $user_info['skype'],
  634. 'YIM_URL' => $user_info['yahoo_url'],
  635. 'YIM_IMG' => $user_info['yahoo_img'],
  636. 'YIM' => $user_info['yahoo'],
  637. 'ONLINE_STATUS_URL' => $user_info['online_status_url'],
  638. 'ONLINE_STATUS_CLASS' => $user_info['online_status_class'],
  639. 'ONLINE_STATUS_IMG' => $user_info['online_status_img'],
  640. 'ONLINE_STATUS' => $user_info['online_status'],
  641. 'L_ONLINE_STATUS' => $user_info['online_status_lang'],
  642. 'L_READ_MESSAGE' => $lang['Read_pm'],
  643. )
  644. );
  645. if (!function_exists('generate_smilies_row'))
  646. {
  647. include_once(IP_ROOT_PATH . 'includes/functions_bbcode.' . PHP_EXT);
  648. }
  649. generate_smilies_row();
  650. $template->assign_vars(array(
  651. 'L_SMILEYS_MORE' => $lang['More_emoticons'],
  652. 'U_SMILEYS_MORE' => append_sid('posting.' . PHP_EXT . '?mode=smilies'),
  653. )
  654. );
  655. full_page_generation($template_to_parse, $lang['Read_pm'], '', '');
  656. }
  657. elseif (($delete && $mark_list) || $delete_all)
  658. {
  659. if (!$user->data['session_logged_in'])
  660. {
  661. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=privmsg.' . PHP_EXT . '&folder=inbox', true));
  662. }
  663. if (isset($mark_list) && !is_array($mark_list))
  664. {
  665. // Set to empty array instead of '0' if nothing is selected.
  666. $mark_list = array();
  667. }
  668. if (!$confirm)
  669. {
  670. $s_hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
  671. $s_hidden_fields .= (isset($_POST['delete'])) ? '<input type="hidden" name="delete" value="true" />' : '<input type="hidden" name="deleteall" value="true" />';
  672. $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $user->data['session_id'] . '" />';
  673. for($i = 0; $i < sizeof($mark_list); $i++)
  674. {
  675. $s_hidden_fields .= '<input type="hidden" name="mark[]" value="' . intval($mark_list[$i]) . '" />';
  676. }
  677. // Output confirmation page
  678. $nav_server_url = create_server_url();
  679. $breadcrumbs['address'] = $lang['Nav_Separator'] . '<a href="' . $nav_server_url . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '" class="nav-current">' . $lang['Private_Messaging'] . '</a>';
  680. $template->assign_vars(array(
  681. 'MESSAGE_TITLE' => $lang['Information'],
  682. 'MESSAGE_TEXT' => (sizeof($mark_list) == 1) ? $lang['Confirm_delete_pm'] : $lang['Confirm_delete_pms'],
  683. 'L_YES' => $lang['Yes'],
  684. 'L_NO' => $lang['No'],
  685. 'S_CONFIRM_ACTION' => append_sid(CMS_PAGE_PRIVMSG . '?folder=' . $folder),
  686. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  687. )
  688. );
  689. full_page_generation('confirm_body.tpl', $lang['Confirm'], '', '');
  690. }
  691. elseif ($confirm && $sid === $user->data['session_id'])
  692. {
  693. if ($delete_all)
  694. {
  695. switch($folder)
  696. {
  697. case 'inbox':
  698. $delete_type = "privmsgs_to_userid = " . $user->data['user_id'] . " AND (
  699. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  700. break;
  701. case 'outbox':
  702. $delete_type = "privmsgs_from_userid = " . $user->data['user_id'] . " AND (privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  703. break;
  704. case 'sentbox':
  705. $delete_type = "privmsgs_from_userid = " . $user->data['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  706. break;
  707. case 'savebox':
  708. $delete_type = "((privmsgs_from_userid = " . $user->data['user_id'] . "
  709. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ")
  710. OR (privmsgs_to_userid = " . $user->data['user_id'] . "
  711. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "))";
  712. break;
  713. }
  714. $sql = "SELECT privmsgs_id
  715. FROM " . PRIVMSGS_TABLE . "
  716. WHERE $delete_type";
  717. $result = $db->sql_query($sql);
  718. while ($row = $db->sql_fetchrow($result))
  719. {
  720. $mark_list[] = $row['privmsgs_id'];
  721. }
  722. unset($delete_type);
  723. }
  724. $attachment_mod['pm']->delete_all_pm_attachments($mark_list);
  725. if (sizeof($mark_list))
  726. {
  727. $delete_sql_id = '';
  728. for ($i = 0; $i < sizeof($mark_list); $i++)
  729. {
  730. $delete_sql_id .= (($delete_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  731. }
  732. if ($folder == 'inbox' || $folder == 'outbox')
  733. {
  734. switch ($folder)
  735. {
  736. case 'inbox':
  737. $sql = "privmsgs_to_userid = " . $user->data['user_id'];
  738. break;
  739. case 'outbox':
  740. $sql = "privmsgs_from_userid = " . $user->data['user_id'];
  741. break;
  742. }
  743. // Get information relevant to new or unread mail
  744. // so we can adjust users counters appropriately
  745. $sql = "SELECT privmsgs_to_userid, privmsgs_type
  746. FROM " . PRIVMSGS_TABLE . "
  747. WHERE privmsgs_id IN ($delete_sql_id)
  748. AND $sql
  749. AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
  750. $result = $db->sql_query($sql);
  751. if ($row = $db->sql_fetchrow($result))
  752. {
  753. $update_users = $update_list = array();
  754. do
  755. {
  756. switch ($row['privmsgs_type'])
  757. {
  758. case PRIVMSGS_NEW_MAIL:
  759. $update_users['new'][$row['privmsgs_to_userid']]++;
  760. break;
  761. case PRIVMSGS_UNREAD_MAIL:
  762. $update_users['unread'][$row['privmsgs_to_userid']]++;
  763. break;
  764. }
  765. }
  766. while ($row = $db->sql_fetchrow($result));
  767. if (sizeof($update_users))
  768. {
  769. while (list($type, $users) = each($update_users))
  770. {
  771. while (list($user_id, $dec) = each($users))
  772. {
  773. $update_list[$type][$dec][] = $user_id;
  774. }
  775. }
  776. unset($update_users);
  777. while (list($type, $dec_ary) = each($update_list))
  778. {
  779. switch ($type)
  780. {
  781. case 'new':
  782. $type = "user_new_privmsg";
  783. break;
  784. case 'unread':
  785. $type = "user_unread_privmsg";
  786. break;
  787. }
  788. while (list($dec, $user_ary) = each($dec_ary))
  789. {
  790. $user_ids = implode(', ', $user_ary);
  791. $sql = "UPDATE " . USERS_TABLE . "
  792. SET $type = $type - $dec
  793. WHERE user_id IN ($user_ids)";
  794. $db->sql_query($sql);
  795. }
  796. }
  797. unset($update_list);
  798. }
  799. }
  800. $db->sql_freeresult($result);
  801. }
  802. // Delete the messages
  803. $delete_sql = "DELETE FROM " . PRIVMSGS_TABLE . "
  804. WHERE privmsgs_id IN ($delete_sql_id)
  805. AND ";
  806. switch($folder)
  807. {
  808. case 'inbox':
  809. $delete_sql .= "privmsgs_to_userid = " . $user->data['user_id'] . " AND (
  810. privmsgs_type = " . PRIVMSGS_READ_MAIL . " OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  811. break;
  812. case 'outbox':
  813. $delete_sql .= "privmsgs_from_userid = " . $user->data['user_id'] . " AND (
  814. privmsgs_type = " . PRIVMSGS_NEW_MAIL . " OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  815. break;
  816. case 'sentbox':
  817. $delete_sql .= "privmsgs_from_userid = " . $user->data['user_id'] . " AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  818. break;
  819. case 'savebox':
  820. $delete_sql .= "((privmsgs_from_userid = " . $user->data['user_id'] . "
  821. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ")
  822. OR (privmsgs_to_userid = " . $user->data['user_id'] . "
  823. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "))";
  824. break;
  825. }
  826. $db->sql_query($delete_sql);
  827. }
  828. }
  829. }
  830. elseif ($download && $mark_list)
  831. {
  832. if (!$user->data['session_logged_in'])
  833. {
  834. $header_location = (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE'))) ? 'Refresh: 0; URL=' : 'Location: ';
  835. header($header_location . append_sid(CMS_PAGE_LOGIN .'?redirect=privmsg.' . PHP_EXT . '&folder=inbox', true));
  836. exit;
  837. }
  838. switch($folder)
  839. {
  840. case 'inbox':
  841. $disp_folder = $lang['Inbox'];
  842. break;
  843. case 'outbox':
  844. $disp_folder = $lang['Outbox'];
  845. break;
  846. case 'sentbox':
  847. $disp_folder = $lang['Sentbox'];
  848. break;
  849. case 'savebox':
  850. $disp_folder = $lang['Savebox'];
  851. break;
  852. }
  853. if (sizeof($mark_list))
  854. {
  855. $i = 0;
  856. $crlf = "\r\n";
  857. $pmtext = $lang['Private_Messaging'] . ' (' . $config['sitename'] . ')' . $crlf;
  858. $user_dateformat = ($user->data['user_dateformat']) ? $user->data['user_dateformat'] : $config['default_dateformat'];
  859. $pmtext .= $disp_folder . ' (' . gmdate($user_dateformat) . ')' . $crlf;
  860. while($mark_list[$i] != '')
  861. {
  862. $sql = "SELECT pm.privmsgs_date, pm.privmsgs_subject, pm.privmsgs_text, us.username, us.user_id
  863. FROM " . PRIVMSGS_TABLE . " pm, " . USERS_TABLE . " us
  864. WHERE pm.privmsgs_id = " . $mark_list[$i] . "
  865. AND us.user_id = pm.privmsgs_from_userid";
  866. $db->sql_return_on_error(true);
  867. $result = $db->sql_query($sql);
  868. $db->sql_return_on_error(false);
  869. if ($result)
  870. {
  871. $db_row = $db->sql_fetchrow($result);
  872. $tmpmsg = wordwrap(htmlspecialchars_decode($db_row['privmsgs_text'], ENT_COMPAT), 78, $crlf);
  873. $from = (($folder == 'inbox') || ($folder == 'savebox')) ? $lang['From'] : $lang['To'];
  874. $pmtext .= '------------------------------------------------------------------------------' . $crlf;
  875. $pmtext .= $lang['Mailbox'] . ': ' . $user->data['username'] . $crlf;
  876. $pmtext .= $from . ': ' . $db_row['username'] . $crlf;
  877. $pmtext .= $lang['Posted'] . ': ' . gmdate($user_dateformat, $db_row['privmsgs_date']) . $crlf;
  878. $pmtext .= $lang['Subject'] . ': ' . htmlspecialchars_decode($db_row['privmsgs_subject'], ENT_COMPAT) . $crlf . $crlf;
  879. $pmtext .= $tmpmsg . $crlf;
  880. }
  881. else
  882. {
  883. print $sql . '<p>';
  884. message_die(GENERAL_ERROR, 'Could not read private message info', '', __LINE__, __FILE__, $sql);
  885. }
  886. $i++;
  887. }
  888. $filename = $config['sitename'] . '_' . $disp_folder . '_' . gmdate('Ymd');
  889. $filename = preg_replace('/[^A-Za-z0-9]+/', '_', strtolower($filename)) . '.txt';
  890. header('Content-Type: text/x-delimtext; name="' . $filename . '"');
  891. header('Content-Disposition: attachment;filename=' . $filename);
  892. header('Content-Transfer-Encoding: plain/text');
  893. header('Content-Length: ' . strlen($pmtext));
  894. print $pmtext;
  895. exit;
  896. }
  897. }
  898. elseif ($save && $mark_list && ($folder != 'savebox') && ($folder != 'outbox'))
  899. {
  900. if (!$user->data['session_logged_in'])
  901. {
  902. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=privmsg.' . PHP_EXT . '&folder=inbox', true));
  903. }
  904. if (sizeof($mark_list))
  905. {
  906. // See if recipient is at their savebox limit
  907. $sql = "SELECT COUNT(privmsgs_id) AS savebox_items, MIN(privmsgs_date) AS oldest_post_time
  908. FROM " . PRIVMSGS_TABLE . "
  909. WHERE ((privmsgs_to_userid = " . $user->data['user_id'] . "
  910. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . ")
  911. OR (privmsgs_from_userid = " . $user->data['user_id'] . "
  912. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "))";
  913. $result = $db->sql_query($sql);
  914. if ($saved_info = $db->sql_fetchrow($result))
  915. {
  916. if ($config['max_savebox_privmsgs'] && $saved_info['savebox_items'] >= $config['max_savebox_privmsgs'])
  917. {
  918. $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
  919. WHERE ((privmsgs_to_userid = " . $user->data['user_id'] . "
  920. AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . ")
  921. OR (privmsgs_from_userid = " . $user->data['user_id'] . "
  922. AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "))
  923. AND privmsgs_date = " . $saved_info['oldest_post_time'];
  924. $result = $db->sql_query($sql);
  925. $old_privmsgs_id = $db->sql_fetchrow($result);
  926. $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
  927. $sql = "DELETE FROM " . PRIVMSGS_TABLE . "
  928. WHERE privmsgs_id = $old_privmsgs_id";
  929. $result = $db->sql_query($sql);
  930. }
  931. }
  932. $saved_sql_id = '';
  933. for ($i = 0; $i < sizeof($mark_list); $i++)
  934. {
  935. $saved_sql_id .= (($saved_sql_id != '') ? ', ' : '') . intval($mark_list[$i]);
  936. }
  937. // Process request
  938. $saved_sql = "UPDATE " . PRIVMSGS_TABLE;
  939. // Decrement read/new counters if appropriate
  940. if ($folder == 'inbox' || $folder == 'outbox')
  941. {
  942. switch ($folder)
  943. {
  944. case 'inbox':
  945. $sql = "privmsgs_to_userid = " . $user->data['user_id'];
  946. break;
  947. case 'outbox':
  948. $sql = "privmsgs_from_userid = " . $user->data['user_id'];
  949. break;
  950. }
  951. // Get information relevant to new or unread mail
  952. // so we can adjust users counters appropriately
  953. $sql = "SELECT privmsgs_to_userid, privmsgs_type
  954. FROM " . PRIVMSGS_TABLE . "
  955. WHERE privmsgs_id IN ($saved_sql_id)
  956. AND $sql
  957. AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
  958. $result = $db->sql_query($sql);
  959. if ($row = $db->sql_fetchrow($result))
  960. {
  961. $update_users = $update_list = array();
  962. do
  963. {
  964. switch ($row['privmsgs_type'])
  965. {
  966. case PRIVMSGS_NEW_MAIL:
  967. $update_users['new'][$row['privmsgs_to_userid']]++;
  968. break;
  969. case PRIVMSGS_UNREAD_MAIL:
  970. $update_users['unread'][$row['privmsgs_to_userid']]++;
  971. break;
  972. }
  973. }
  974. while ($row = $db->sql_fetchrow($result));
  975. if (sizeof($update_users))
  976. {
  977. while (list($type, $users) = each($update_users))
  978. {
  979. while (list($user_id, $dec) = each($users))
  980. {
  981. $update_list[$type][$dec][] = $user_id;
  982. }
  983. }
  984. unset($update_users);
  985. while (list($type, $dec_ary) = each($update_list))
  986. {
  987. switch ($type)
  988. {
  989. case 'new':
  990. $type = "user_new_privmsg";
  991. break;
  992. case 'unread':
  993. $type = "user_unread_privmsg";
  994. break;
  995. }
  996. while (list($dec, $user_ary) = each($dec_ary))
  997. {
  998. $user_ids = implode(', ', $user_ary);
  999. $sql = "UPDATE " . USERS_TABLE . "
  1000. SET $type = $type - $dec
  1001. WHERE user_id IN ($user_ids)";
  1002. $result_tmp = $db->sql_query($sql);
  1003. }
  1004. }
  1005. unset($update_list);
  1006. }
  1007. }
  1008. $db->sql_freeresult($result);
  1009. }
  1010. switch ($folder)
  1011. {
  1012. case 'inbox':
  1013. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . "
  1014. WHERE privmsgs_to_userid = " . $user->data['user_id'] . "
  1015. AND (privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  1016. OR privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1017. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")";
  1018. break;
  1019. case 'outbox':
  1020. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  1021. WHERE privmsgs_from_userid = " . $user->data['user_id'] . "
  1022. AND (privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1023. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ") ";
  1024. break;
  1025. case 'sentbox':
  1026. $saved_sql .= " SET privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . "
  1027. WHERE privmsgs_from_userid = " . $user->data['user_id'] . "
  1028. AND privmsgs_type = " . PRIVMSGS_SENT_MAIL;
  1029. break;
  1030. }
  1031. $saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
  1032. $result_saved = $db->sql_query($saved_sql);
  1033. redirect(append_sid(CMS_PAGE_PRIVMSG . '?folder=savebox', true));
  1034. }
  1035. }
  1036. elseif ($submit || $refresh || ($mode != ''))
  1037. {
  1038. if (!$user->data['session_logged_in'])
  1039. {
  1040. $user_id = (isset($_GET[POST_USERS_URL])) ? '&' . POST_USERS_URL . '=' . intval($_GET[POST_USERS_URL]) : '';
  1041. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=privmsg.' . PHP_EXT . '&folder=' . $folder . '&mode=' . $mode . $user_id, true));
  1042. }
  1043. // Toggles
  1044. if (!$config['allow_html'])
  1045. {
  1046. $html_on = 0;
  1047. }
  1048. else
  1049. {
  1050. $html_on = ($submit || $refresh) ? ((!empty($_POST['disable_html'])) ? 0 : 1) : $user->data['user_allowhtml'];
  1051. }
  1052. $acro_auto_on = ($submit || $refresh) ? ((!empty($_POST['disable_acro_auto'])) ? 0 : 1) : 1;
  1053. if (!$config['allow_bbcode'])
  1054. {
  1055. $bbcode_on = 0;
  1056. }
  1057. else
  1058. {
  1059. $bbcode_on = ($submit || $refresh) ? ((!empty($_POST['disable_bbcode'])) ? 0 : 1) : $user->data['user_allowbbcode'];
  1060. }
  1061. if (!$config['allow_smilies'])
  1062. {
  1063. $smilies_on = 0;
  1064. }
  1065. else
  1066. {
  1067. $smilies_on = ($submit || $refresh) ? ((!empty($_POST['disable_smilies'])) ? 0 : 1) : $user->data['user_allowsmile'];
  1068. }
  1069. $attach_sig = ($submit || $refresh) ? ((!empty($_POST['attach_sig'])) ? 1 : 0) : $user->data['user_attachsig'];
  1070. $user_sig = ($user->data['user_sig'] != '' && $config['allow_sig']) ? $user->data['user_sig'] : '';
  1071. if (($submit) && ($mode != 'edit') && ($user->data['user_level'] != ADMIN))
  1072. {
  1073. // Flood control
  1074. $sql = "SELECT MAX(privmsgs_date) AS last_post_time
  1075. FROM " . PRIVMSGS_TABLE . "
  1076. WHERE privmsgs_from_userid = " . $user->data['user_id'];
  1077. $db->sql_return_on_error(true);
  1078. $result = $db->sql_query($sql);
  1079. $db->sql_return_on_error(false);
  1080. if ($result)
  1081. {
  1082. $db_row = $db->sql_fetchrow($result);
  1083. $last_post_time = $db_row['last_post_time'];
  1084. $current_time = time();
  1085. if (($current_time - $last_post_time) < $config['flood_interval'])
  1086. {
  1087. message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
  1088. }
  1089. }
  1090. // End Flood control
  1091. }
  1092. if ($submit && ($mode == 'edit'))
  1093. {
  1094. $sql = 'SELECT privmsgs_from_userid
  1095. FROM ' . PRIVMSGS_TABLE . '
  1096. WHERE privmsgs_id = ' . (int) $privmsg_id . '
  1097. AND privmsgs_from_userid = ' . $user->data['user_id'];
  1098. $result = $db->sql_query($sql);
  1099. if (!($row = $db->sql_fetchrow($result)))
  1100. {
  1101. message_die(GENERAL_MESSAGE, $lang['No_such_post']);
  1102. }
  1103. $db->sql_freeresult($result);
  1104. unset($row);
  1105. }
  1106. if ($submit || ($draft && $draft_confirm))
  1107. {
  1108. $username = request_var('username', '', true);
  1109. $username = htmlspecialchars_decode($username, ENT_COMPAT);
  1110. $subject = !empty($draft_subject) ? $draft_subject : request_post_var('subject', '', true);
  1111. $message = !empty($draft_message) ? $draft_message : htmlspecialchars_decode(request_post_var('message', '', true), ENT_COMPAT);
  1112. // session id check
  1113. if (($sid == '') || ($sid != $user->data['session_id']))
  1114. {
  1115. $error = true;
  1116. $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . $lang['Session_invalid'];
  1117. }
  1118. if (!empty($username))
  1119. {
  1120. $to_username = phpbb_clean_username($username);
  1121. $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active
  1122. FROM " . USERS_TABLE . "
  1123. WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($to_username)) . "'
  1124. AND user_id <> " . ANONYMOUS;
  1125. $db->sql_return_on_error(true);
  1126. $result = $db->sql_query($sql);
  1127. $db->sql_return_on_error(false);
  1128. if (!$result)
  1129. {
  1130. $error = true;
  1131. $error_msg = $lang['NO_USER'];
  1132. }
  1133. if (!($to_userdata = $db->sql_fetchrow($result)))
  1134. {
  1135. $error = true;
  1136. $error_msg = $lang['NO_USER'];
  1137. }
  1138. }
  1139. else
  1140. {
  1141. $error = true;
  1142. $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . $lang['No_to_user'];
  1143. }
  1144. $privmsg_subject = $subject;
  1145. if (empty($privmsg_subject))
  1146. {
  1147. $error = true;
  1148. $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . $lang['Empty_subject'];
  1149. }
  1150. if (!empty($message) && !$error)
  1151. {
  1152. $privmsg_message = prepare_message($message, $html_on, $bbcode_on, $smilies_on, '');
  1153. }
  1154. else
  1155. {
  1156. $error = true;
  1157. $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . $lang['Empty_message'];
  1158. }
  1159. }
  1160. if (($submit || ($draft && $draft_confirm)) && !$error)
  1161. {
  1162. // Has admin prevented user from sending PM's?
  1163. if (!$user->data['user_allow_pm'])
  1164. {
  1165. $error_message = $lang['Cannot_send_privmsg'];
  1166. message_die(GENERAL_MESSAGE, $error_message);
  1167. }
  1168. // MG Drafts - BEGIN
  1169. if (($config['allow_drafts'] == true) && $draft && $draft_confirm && $user->data['session_logged_in'])
  1170. {
  1171. save_draft($draft_id, $user->data['user_id'], 0, 0, $privmsg_subject, $message);
  1172. $output_message = $lang['Drafts_Saved'];
  1173. $output_message .= '<br /><br />' . sprintf($lang['Click_return_drafts'], '<a href="' . append_sid(CMS_PAGE_DRAFTS) . '">', '</a>');
  1174. $output_message .= '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid(CMS_PAGE_FORUM) . '">', '</a>');
  1175. $redirect_url = append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox');
  1176. meta_refresh(3, $redirect_url);
  1177. message_die(GENERAL_MESSAGE, $output_message);
  1178. }
  1179. // MG Drafts - END
  1180. $msg_time = time();
  1181. if ($mode != 'edit')
  1182. {
  1183. // See if recipient is at their inbox limit
  1184. $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
  1185. FROM " . PRIVMSGS_TABLE . "
  1186. WHERE (privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1187. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  1188. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . ")
  1189. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  1190. $result = $db->sql_query($sql);
  1191. if ($inbox_info = $db->sql_fetchrow($result))
  1192. {
  1193. if ($config['max_inbox_privmsgs'] && ($inbox_info['inbox_items'] >= $config['max_inbox_privmsgs']))
  1194. {
  1195. $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
  1196. WHERE (privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
  1197. OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
  1198. OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
  1199. AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
  1200. AND privmsgs_to_userid = " . $to_userdata['user_id'];
  1201. $result = $db->sql_query($sql);
  1202. $old_privmsgs_id = $db->sql_fetchrow($result);
  1203. $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
  1204. $sql = "DELETE FROM " . PRIVMSGS_TABLE . "
  1205. WHERE privmsgs_id = $old_privmsgs_id";
  1206. $db->sql_query($sql);
  1207. }
  1208. }
  1209. if ($user->data['user_level'] > 0)
  1210. {
  1211. $pm_send = true;
  1212. }
  1213. else
  1214. {
  1215. $u_pm_in = user_check_pm_in_allowed($to_userdata['user_id']);
  1216. if ($u_pm_in == true)
  1217. {
  1218. $pm_send = true;
  1219. }
  1220. else
  1221. {
  1222. $u_pm_friend = user_check_friend_foe($to_userdata['user_id'], true);
  1223. if ($u_pm_friend == true)
  1224. {
  1225. $pm_send = true;
  1226. }
  1227. else
  1228. {
  1229. $msg = $lang['Allow_PM_IN_SEND_ERROR'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . append_sid(CMS_PAGE_PRIVMSG . '?folder=inbox') . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid(CMS_PAGE_FORUM) . '">', '</a>');
  1230. message_die(GENERAL_MESSAGE, $msg);
  1231. }
  1232. }
  1233. }
  1234. $sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_text, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_enable_autolinks_acronyms, privmsgs_attach_sig)
  1235. VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . $db->sql_escape($privmsg_subject) . "', '" . $db->sql_escape($privmsg_message) . "', " . $user->data['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $html_on, $bbcode_on, $smilies_on, $acro_auto_on, $attach_sig)";
  1236. }
  1237. else
  1238. {
  1239. if ($user->data['user_level'] > 0)
  1240. {
  1241. $pm_send = true;
  1242. }
  1243. else
  1244. {
  1245. $u_pm_in = user_check_pm_in_al

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