PageRenderTime 67ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/station/forum/includes/ucp/ucp_pm_compose.php

https://github.com/bryanveloso/sayonarane
PHP | 1253 lines | 952 code | 199 blank | 102 comment | 309 complexity | efd828ca75ecbb058c60a7fd32612e2d MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package ucp
  5. * @version $Id: ucp_pm_compose.php 9045 2008-11-02 15:28:00Z acydburn $
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Compose private message
  19. * Called from ucp_pm with mode == 'compose'
  20. */
  21. function compose_pm($id, $mode, $action)
  22. {
  23. global $template, $db, $auth, $user;
  24. global $phpbb_root_path, $phpEx, $config;
  25. // Damn php and globals - i know, this is horrible
  26. // Needed for handle_message_list_actions()
  27. global $refresh, $submit, $preview;
  28. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  29. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  30. include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  31. if (!$action)
  32. {
  33. $action = 'post';
  34. }
  35. add_form_key('ucp_pm_compose');
  36. // Grab only parameters needed here
  37. $to_user_id = request_var('u', 0);
  38. $to_group_id = request_var('g', 0);
  39. $msg_id = request_var('p', 0);
  40. $draft_id = request_var('d', 0);
  41. $lastclick = request_var('lastclick', 0);
  42. // Do NOT use request_var or specialchars here
  43. $address_list = isset($_REQUEST['address_list']) ? $_REQUEST['address_list'] : array();
  44. if (!is_array($address_list))
  45. {
  46. $address_list = array();
  47. }
  48. $submit = (isset($_POST['post'])) ? true : false;
  49. $preview = (isset($_POST['preview'])) ? true : false;
  50. $save = (isset($_POST['save'])) ? true : false;
  51. $load = (isset($_POST['load'])) ? true : false;
  52. $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
  53. $delete = (isset($_POST['delete'])) ? true : false;
  54. $remove_u = (isset($_REQUEST['remove_u'])) ? true : false;
  55. $remove_g = (isset($_REQUEST['remove_g'])) ? true : false;
  56. $add_to = (isset($_REQUEST['add_to'])) ? true : false;
  57. $add_bcc = (isset($_REQUEST['add_bcc'])) ? true : false;
  58. $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load
  59. || $remove_u || $remove_g || $add_to || $add_bcc;
  60. $action = ($delete && !$preview && !$refresh && $submit) ? 'delete' : $action;
  61. $select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? false : true;
  62. $error = array();
  63. $current_time = time();
  64. // Was cancel pressed? If so then redirect to the appropriate page
  65. if ($cancel || ($current_time - $lastclick < 2 && $submit))
  66. {
  67. if ($msg_id)
  68. {
  69. redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
  70. }
  71. redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'));
  72. }
  73. // Output PM_TO box if message composing
  74. if ($action != 'edit')
  75. {
  76. // Add groups to PM box
  77. if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group'))
  78. {
  79. $sql = 'SELECT g.group_id, g.group_name, g.group_type
  80. FROM ' . GROUPS_TABLE . ' g';
  81. if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  82. {
  83. $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  84. ON (
  85. g.group_id = ug.group_id
  86. AND ug.user_id = ' . $user->data['user_id'] . '
  87. AND ug.user_pending = 0
  88. )
  89. WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
  90. }
  91. $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
  92. $sql .= 'g.group_receive_pm = 1
  93. ORDER BY g.group_type DESC, g.group_name ASC';
  94. $result = $db->sql_query($sql);
  95. $group_options = '';
  96. while ($row = $db->sql_fetchrow($result))
  97. {
  98. $group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
  99. }
  100. $db->sql_freeresult($result);
  101. }
  102. $template->assign_vars(array(
  103. 'S_SHOW_PM_BOX' => true,
  104. 'S_ALLOW_MASS_PM' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? true : false,
  105. 'S_GROUP_OPTIONS' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) ? $group_options : '',
  106. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=postform&amp;field=username_list&amp;select_single=$select_single"),
  107. ));
  108. }
  109. $sql = '';
  110. // What is all this following SQL for? Well, we need to know
  111. // some basic information in all cases before we do anything.
  112. switch ($action)
  113. {
  114. case 'post':
  115. if (!$auth->acl_get('u_sendpm'))
  116. {
  117. trigger_error('NO_AUTH_SEND_MESSAGE');
  118. }
  119. break;
  120. case 'reply':
  121. case 'quote':
  122. case 'forward':
  123. case 'quotepost':
  124. if (!$msg_id)
  125. {
  126. trigger_error('NO_MESSAGE');
  127. }
  128. if (!$auth->acl_get('u_sendpm'))
  129. {
  130. trigger_error('NO_AUTH_SEND_MESSAGE');
  131. }
  132. if ($action == 'quotepost')
  133. {
  134. $sql = 'SELECT p.post_id as msg_id, p.forum_id, p.post_text as message_text, p.poster_id as author_id, p.post_time as message_time, p.bbcode_bitfield, p.bbcode_uid, p.enable_sig, p.enable_smilies, p.enable_magic_url, t.topic_title as message_subject, u.username as quote_username
  135. FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u
  136. WHERE p.post_id = $msg_id
  137. AND t.topic_id = p.topic_id
  138. AND u.user_id = p.poster_id";
  139. }
  140. else
  141. {
  142. $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
  143. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
  144. WHERE t.user_id = ' . $user->data['user_id'] . "
  145. AND p.author_id = u.user_id
  146. AND t.msg_id = p.msg_id
  147. AND p.msg_id = $msg_id";
  148. }
  149. break;
  150. case 'edit':
  151. if (!$msg_id)
  152. {
  153. trigger_error('NO_MESSAGE');
  154. }
  155. // check for outbox (not read) status, we do not allow editing if one user already having the message
  156. $sql = 'SELECT p.*, t.folder_id
  157. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
  158. WHERE t.user_id = ' . $user->data['user_id'] . '
  159. AND t.folder_id = ' . PRIVMSGS_OUTBOX . "
  160. AND t.msg_id = $msg_id
  161. AND t.msg_id = p.msg_id";
  162. break;
  163. case 'delete':
  164. if (!$auth->acl_get('u_pm_delete'))
  165. {
  166. trigger_error('NO_AUTH_DELETE_MESSAGE');
  167. }
  168. if (!$msg_id)
  169. {
  170. trigger_error('NO_MESSAGE');
  171. }
  172. $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
  173. FROM ' . PRIVMSGS_TO_TABLE . '
  174. WHERE user_id = ' . $user->data['user_id'] . "
  175. AND msg_id = $msg_id";
  176. break;
  177. case 'smilies':
  178. generate_smilies('window', 0);
  179. break;
  180. default:
  181. trigger_error('NO_ACTION_MODE', E_USER_ERROR);
  182. break;
  183. }
  184. if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward')))
  185. {
  186. trigger_error('NO_AUTH_FORWARD_MESSAGE');
  187. }
  188. if ($action == 'edit' && !$auth->acl_get('u_pm_edit'))
  189. {
  190. trigger_error('NO_AUTH_EDIT_MESSAGE');
  191. }
  192. if ($sql)
  193. {
  194. $result = $db->sql_query($sql);
  195. $post = $db->sql_fetchrow($result);
  196. $db->sql_freeresult($result);
  197. if (!$post)
  198. {
  199. // If editing it could be the recipient already read the message...
  200. if ($action == 'edit')
  201. {
  202. $sql = 'SELECT p.*, t.folder_id
  203. FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
  204. WHERE t.user_id = ' . $user->data['user_id'] . "
  205. AND t.msg_id = $msg_id
  206. AND t.msg_id = p.msg_id";
  207. $result = $db->sql_query($sql);
  208. $post = $db->sql_fetchrow($result);
  209. $db->sql_freeresult($result);
  210. if ($post)
  211. {
  212. trigger_error('NO_EDIT_READ_MESSAGE');
  213. }
  214. }
  215. trigger_error('NO_MESSAGE');
  216. }
  217. if ($action == 'quotepost')
  218. {
  219. if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) || (!$post['forum_id'] && !$auth->acl_getf_global('f_read')))
  220. {
  221. trigger_error('NOT_AUTHORISED');
  222. }
  223. }
  224. $msg_id = (int) $post['msg_id'];
  225. $folder_id = (isset($post['folder_id'])) ? $post['folder_id'] : 0;
  226. $message_text = (isset($post['message_text'])) ? $post['message_text'] : '';
  227. if ((!$post['author_id'] || ($post['author_id'] == ANONYMOUS && $action != 'delete')) && $msg_id)
  228. {
  229. trigger_error('NO_AUTHOR');
  230. }
  231. if ($action == 'quotepost')
  232. {
  233. // Decode text for message display
  234. decode_message($message_text, $post['bbcode_uid']);
  235. }
  236. if ($action != 'delete')
  237. {
  238. $enable_urls = $post['enable_magic_url'];
  239. $enable_sig = (isset($post['enable_sig'])) ? $post['enable_sig'] : 0;
  240. $message_attachment = (isset($post['message_attachment'])) ? $post['message_attachment'] : 0;
  241. $message_subject = $post['message_subject'];
  242. $message_time = $post['message_time'];
  243. $bbcode_uid = $post['bbcode_uid'];
  244. $quote_username = (isset($post['quote_username'])) ? $post['quote_username'] : '';
  245. $icon_id = (isset($post['icon_id'])) ? $post['icon_id'] : 0;
  246. if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
  247. {
  248. if ($action == 'quotepost')
  249. {
  250. $address_list = array('u' => array($post['author_id'] => 'to'));
  251. }
  252. else
  253. {
  254. // We try to include every previously listed member from the TO Header
  255. $address_list = rebuild_header(array('to' => $post['to_address']));
  256. // Add the author (if he is already listed then this is no shame (it will be overwritten))
  257. $address_list['u'][$post['author_id']] = 'to';
  258. // Now, make sure the user itself is not listed. ;)
  259. if (isset($address_list['u'][$user->data['user_id']]))
  260. {
  261. unset($address_list['u'][$user->data['user_id']]);
  262. }
  263. }
  264. }
  265. else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview)
  266. {
  267. // Rebuild TO and BCC Header
  268. $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
  269. }
  270. if ($action == 'quotepost')
  271. {
  272. $check_value = 0;
  273. }
  274. else
  275. {
  276. $check_value = (($post['enable_bbcode']+1) << 8) + (($post['enable_smilies']+1) << 4) + (($enable_urls+1) << 2) + (($post['enable_sig']+1) << 1);
  277. }
  278. }
  279. }
  280. else
  281. {
  282. $message_attachment = 0;
  283. $message_text = $message_subject = '';
  284. if ($to_user_id && $action == 'post')
  285. {
  286. $address_list['u'][$to_user_id] = 'to';
  287. }
  288. else if ($to_group_id && $action == 'post')
  289. {
  290. $address_list['g'][$to_group_id] = 'to';
  291. }
  292. $check_value = 0;
  293. }
  294. if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')))
  295. {
  296. trigger_error('NO_AUTH_GROUP_MESSAGE');
  297. }
  298. if ($action == 'edit' && !$refresh && !$preview && !$submit)
  299. {
  300. if (!($message_time > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']))
  301. {
  302. trigger_error('CANNOT_EDIT_MESSAGE_TIME');
  303. }
  304. }
  305. if ($action == 'post')
  306. {
  307. $template->assign_var('S_NEW_MESSAGE', true);
  308. }
  309. if (!isset($icon_id))
  310. {
  311. $icon_id = 0;
  312. }
  313. $message_parser = new parse_message();
  314. $message_parser->message = ($action == 'reply') ? '' : $message_text;
  315. unset($message_text);
  316. $s_action = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=$mode&amp;action=$action", true, $user->session_id);
  317. $s_action .= ($msg_id) ? "&amp;p=$msg_id" : '';
  318. // Delete triggered ?
  319. if ($action == 'delete')
  320. {
  321. // Folder id has been determined by the SQL Statement
  322. // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
  323. // Do we need to confirm ?
  324. if (confirm_box(true))
  325. {
  326. delete_pm($user->data['user_id'], $msg_id, $folder_id);
  327. // jump to next message in "history"? nope, not for the moment. But able to be included later.
  328. $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;folder=$folder_id");
  329. $message = $user->lang['MESSAGE_DELETED'];
  330. meta_refresh(3, $meta_info);
  331. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
  332. trigger_error($message);
  333. }
  334. else
  335. {
  336. $s_hidden_fields = array(
  337. 'p' => $msg_id,
  338. 'f' => $folder_id,
  339. 'action' => 'delete'
  340. );
  341. // "{$phpbb_root_path}ucp.$phpEx?i=pm&amp;mode=compose"
  342. confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
  343. }
  344. redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
  345. }
  346. // Get maximum number of allowed recipients
  347. $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
  348. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
  349. WHERE ug.user_id = ' . $user->data['user_id'] . '
  350. AND ug.user_pending = 0
  351. AND ug.group_id = g.group_id';
  352. $result = $db->sql_query($sql);
  353. $max_recipients = (int) $db->sql_fetchfield('max_recipients');
  354. $db->sql_freeresult($result);
  355. $max_recipients = (!$max_recipients) ? $config['pm_max_recipients'] : $max_recipients;
  356. // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
  357. if (($action == 'reply' || $action == 'quote') && $max_recipients)
  358. {
  359. // We try to include every previously listed member from the TO Header
  360. $list = rebuild_header(array('to' => $post['to_address']));
  361. $list = $list['u'];
  362. $list[$post['author_id']] = 'to';
  363. if (isset($list[$user->data['user_id']]))
  364. {
  365. unset($list[$user->data['user_id']]);
  366. }
  367. $max_recipients = ($max_recipients < sizeof($list)) ? sizeof($list) : $max_recipients;
  368. unset($list);
  369. }
  370. // Handle User/Group adding/removing
  371. handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
  372. // Check mass pm to group permission
  373. if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g']))
  374. {
  375. $address_list = array();
  376. $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE'];
  377. }
  378. // Check mass pm to users permission
  379. if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1)
  380. {
  381. $address_list = get_recipients($address_list, 1);
  382. $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
  383. }
  384. // Check for too many recipients
  385. if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients)
  386. {
  387. $address_list = get_recipients($address_list, $max_recipients);
  388. $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
  389. }
  390. // Always check if the submitted attachment data is valid and belongs to the user.
  391. // Further down (especially in submit_post()) we do not check this again.
  392. $message_parser->get_submitted_attachment_data();
  393. if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit')
  394. {
  395. // Do not change to SELECT *
  396. $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
  397. FROM ' . ATTACHMENTS_TABLE . "
  398. WHERE post_msg_id = $msg_id
  399. AND in_message = 1
  400. AND is_orphan = 0
  401. ORDER BY filetime DESC";
  402. $result = $db->sql_query($sql);
  403. $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
  404. $db->sql_freeresult($result);
  405. }
  406. if (!in_array($action, array('quote', 'edit', 'delete', 'forward')))
  407. {
  408. $enable_sig = ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig'));
  409. $enable_smilies = ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies'));
  410. $enable_bbcode = ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode'));
  411. $enable_urls = true;
  412. }
  413. $enable_magic_url = $drafts = false;
  414. // User own some drafts?
  415. if ($auth->acl_get('u_savedrafts') && $action != 'delete')
  416. {
  417. $sql = 'SELECT draft_id
  418. FROM ' . DRAFTS_TABLE . '
  419. WHERE forum_id = 0
  420. AND topic_id = 0
  421. AND user_id = ' . $user->data['user_id'] .
  422. (($draft_id) ? " AND draft_id <> $draft_id" : '');
  423. $result = $db->sql_query_limit($sql, 1);
  424. $row = $db->sql_fetchrow($result);
  425. $db->sql_freeresult($result);
  426. if ($row)
  427. {
  428. $drafts = true;
  429. }
  430. }
  431. if ($action == 'edit')
  432. {
  433. $message_parser->bbcode_uid = $bbcode_uid;
  434. }
  435. $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
  436. $smilies_status = ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ? true : false;
  437. $img_status = ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ? true : false;
  438. $flash_status = ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ? true : false;
  439. $url_status = ($config['allow_post_links']) ? true : false;
  440. // Save Draft
  441. if ($save && $auth->acl_get('u_savedrafts'))
  442. {
  443. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  444. $subject = (!$subject && $action != 'post') ? $user->lang['NEW_MESSAGE'] : $subject;
  445. $message = utf8_normalize_nfc(request_var('message', '', true));
  446. if ($subject && $message)
  447. {
  448. if (confirm_box(true))
  449. {
  450. $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  451. 'user_id' => $user->data['user_id'],
  452. 'topic_id' => 0,
  453. 'forum_id' => 0,
  454. 'save_time' => $current_time,
  455. 'draft_subject' => $subject,
  456. 'draft_message' => $message
  457. )
  458. );
  459. $db->sql_query($sql);
  460. $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=$mode");
  461. meta_refresh(3, $redirect_url);
  462. $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
  463. trigger_error($message);
  464. }
  465. else
  466. {
  467. $s_hidden_fields = build_hidden_fields(array(
  468. 'mode' => $mode,
  469. 'action' => $action,
  470. 'save' => true,
  471. 'subject' => $subject,
  472. 'message' => $message,
  473. 'u' => $to_user_id,
  474. 'g' => $to_group_id,
  475. 'p' => $msg_id)
  476. );
  477. $s_hidden_fields .= build_address_field($address_list);
  478. confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
  479. }
  480. }
  481. else
  482. {
  483. if (utf8_clean_string($subject) === '')
  484. {
  485. $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
  486. }
  487. if (utf8_clean_string($message) === '')
  488. {
  489. $error[] = $user->lang['TOO_FEW_CHARS'];
  490. }
  491. }
  492. unset($subject, $message);
  493. }
  494. // Load Draft
  495. if ($draft_id && $auth->acl_get('u_savedrafts'))
  496. {
  497. $sql = 'SELECT draft_subject, draft_message
  498. FROM ' . DRAFTS_TABLE . "
  499. WHERE draft_id = $draft_id
  500. AND topic_id = 0
  501. AND forum_id = 0
  502. AND user_id = " . $user->data['user_id'];
  503. $result = $db->sql_query_limit($sql, 1);
  504. if ($row = $db->sql_fetchrow($result))
  505. {
  506. $message_parser->message = $row['draft_message'];
  507. $message_subject = $row['draft_subject'];
  508. $template->assign_var('S_DRAFT_LOADED', true);
  509. }
  510. else
  511. {
  512. $draft_id = 0;
  513. }
  514. $db->sql_freeresult($result);
  515. }
  516. // Load Drafts
  517. if ($load && $drafts)
  518. {
  519. load_drafts(0, 0, $id);
  520. }
  521. if ($submit || $preview || $refresh)
  522. {
  523. if (($submit || $preview) && !check_form_key('ucp_pm_compose'))
  524. {
  525. $error[] = $user->lang['FORM_INVALID'];
  526. }
  527. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  528. $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
  529. $icon_id = request_var('icon', 0);
  530. $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
  531. $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
  532. $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1;
  533. $enable_sig = (!$config['allow_sig'] ||!$config['allow_sig_pm']) ? false : ((isset($_POST['attach_sig'])) ? true : false);
  534. if ($submit)
  535. {
  536. $status_switch = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
  537. $status_switch = ($status_switch != $check_value);
  538. }
  539. else
  540. {
  541. $status_switch = 1;
  542. }
  543. // Parse Attachments - before checksum is calculated
  544. $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
  545. if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
  546. {
  547. $error[] = implode('<br />', $message_parser->warn_msg);
  548. $message_parser->warn_msg = array();
  549. }
  550. // Parse message
  551. $message_parser->parse($enable_bbcode, ($config['allow_post_links']) ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
  552. // On a refresh we do not care about message parsing errors
  553. if (sizeof($message_parser->warn_msg) && !$refresh)
  554. {
  555. $error[] = implode('<br />', $message_parser->warn_msg);
  556. }
  557. if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood'))
  558. {
  559. // Flood check
  560. $last_post_time = $user->data['user_lastpost_time'];
  561. if ($last_post_time)
  562. {
  563. if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
  564. {
  565. $error[] = $user->lang['FLOOD_ERROR'];
  566. }
  567. }
  568. }
  569. // Subject defined
  570. if ($submit)
  571. {
  572. if (utf8_clean_string($subject) === '')
  573. {
  574. $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
  575. }
  576. if (!sizeof($address_list))
  577. {
  578. $error[] = $user->lang['NO_RECIPIENT'];
  579. }
  580. }
  581. // Store message, sync counters
  582. if (!sizeof($error) && $submit)
  583. {
  584. $pm_data = array(
  585. 'msg_id' => (int) $msg_id,
  586. 'from_user_id' => $user->data['user_id'],
  587. 'from_user_ip' => $user->ip,
  588. 'from_username' => $user->data['username'],
  589. 'reply_from_root_level' => (isset($post['root_level'])) ? (int) $post['root_level'] : 0,
  590. 'reply_from_msg_id' => (int) $msg_id,
  591. 'icon_id' => (int) $icon_id,
  592. 'enable_sig' => (bool) $enable_sig,
  593. 'enable_bbcode' => (bool) $enable_bbcode,
  594. 'enable_smilies' => (bool) $enable_smilies,
  595. 'enable_urls' => (bool) $enable_urls,
  596. 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
  597. 'bbcode_uid' => $message_parser->bbcode_uid,
  598. 'message' => $message_parser->message,
  599. 'attachment_data' => $message_parser->attachment_data,
  600. 'filename_data' => $message_parser->filename_data,
  601. 'address_list' => $address_list
  602. );
  603. // ((!$message_subject) ? $subject : $message_subject)
  604. $msg_id = submit_pm($action, $subject, $pm_data);
  605. $return_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;p=' . $msg_id);
  606. $return_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=outbox');
  607. meta_refresh(3, $return_message_url);
  608. $message = $user->lang['MESSAGE_STORED'] . '<br /><br />' . sprintf($user->lang['VIEW_PRIVATE_MESSAGE'], '<a href="' . $return_message_url . '">', '</a>') . '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $return_folder_url . '">', '</a>', $user->lang['PM_OUTBOX']);
  609. trigger_error($message);
  610. }
  611. $message_subject = $subject;
  612. }
  613. // Preview
  614. if (!sizeof($error) && $preview)
  615. {
  616. $user->add_lang('viewtopic');
  617. $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
  618. $preview_signature = $user->data['user_sig'];
  619. $preview_signature_uid = $user->data['user_sig_bbcode_uid'];
  620. $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];
  621. // Signature
  622. if ($enable_sig && $config['allow_sig'] && $preview_signature)
  623. {
  624. $parse_sig = new parse_message($preview_signature);
  625. $parse_sig->bbcode_uid = $preview_signature_uid;
  626. $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
  627. $parse_sig->format_display($enable_bbcode, $enable_urls, $enable_smilies);
  628. $preview_signature = $parse_sig->message;
  629. unset($parse_sig);
  630. }
  631. else
  632. {
  633. $preview_signature = '';
  634. }
  635. // Attachment Preview
  636. if (sizeof($message_parser->attachment_data))
  637. {
  638. $template->assign_var('S_HAS_ATTACHMENTS', true);
  639. $update_count = array();
  640. $attachment_data = $message_parser->attachment_data;
  641. parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
  642. foreach ($attachment_data as $i => $attachment)
  643. {
  644. $template->assign_block_vars('attachment', array(
  645. 'DISPLAY_ATTACHMENT' => $attachment)
  646. );
  647. }
  648. unset($attachment_data);
  649. }
  650. $preview_subject = censor_text($subject);
  651. if (!sizeof($error))
  652. {
  653. $template->assign_vars(array(
  654. 'PREVIEW_SUBJECT' => $preview_subject,
  655. 'PREVIEW_MESSAGE' => $preview_message,
  656. 'PREVIEW_SIGNATURE' => $preview_signature,
  657. 'S_DISPLAY_PREVIEW' => true)
  658. );
  659. }
  660. unset($message_text);
  661. }
  662. // Decode text for message display
  663. $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid;
  664. $message_parser->decode_message($bbcode_uid);
  665. if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit)
  666. {
  667. if ($action == 'quotepost')
  668. {
  669. $post_id = request_var('p', 0);
  670. if ($config['allow_post_links'])
  671. {
  672. $message_link = "[url=" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}: {$message_subject}[/url]\n\n";
  673. }
  674. else
  675. {
  676. $message_link = $user->lang['SUBJECT'] . ': ' . $message_subject . " (" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id})\n\n";
  677. }
  678. }
  679. else
  680. {
  681. $message_link = '';
  682. }
  683. $message_parser->message = $message_link . '[quote=&quot;' . $quote_username . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
  684. }
  685. if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh)
  686. {
  687. $message_subject = ((!preg_match('/^Re:/', $message_subject)) ? 'Re: ' : '') . censor_text($message_subject);
  688. }
  689. if ($action == 'forward' && !$preview && !$refresh && !$submit)
  690. {
  691. $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
  692. if ($config['allow_post_links'])
  693. {
  694. $quote_username_text = '[url=' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&amp;u={$post['author_id']}]{$quote_username}[/url]";
  695. }
  696. else
  697. {
  698. $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&amp;u={$post['author_id']})";
  699. }
  700. $forward_text = array();
  701. $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
  702. $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
  703. $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time));
  704. $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
  705. $forward_text[] = sprintf($user->lang['FWD_TO'], implode(', ', $fwd_to_field['to']));
  706. $message_parser->message = implode("\n", $forward_text) . "\n\n[quote=&quot;{$quote_username}&quot;]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
  707. $message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject);
  708. }
  709. $attachment_data = $message_parser->attachment_data;
  710. $filename_data = $message_parser->filename_data;
  711. $message_text = $message_parser->message;
  712. // MAIN PM PAGE BEGINS HERE
  713. // Generate smiley listing
  714. generate_smilies('inline', 0);
  715. // Generate PM Icons
  716. $s_pm_icons = false;
  717. if ($config['enable_pm_icons'])
  718. {
  719. $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
  720. }
  721. // Generate inline attachment select box
  722. posting_gen_inline_attachments($attachment_data);
  723. // Build address list for display
  724. // array('u' => array($author_id => 'to'));
  725. if (sizeof($address_list))
  726. {
  727. // Get Usernames and Group Names
  728. $result = array();
  729. if (!empty($address_list['u']))
  730. {
  731. $sql = 'SELECT user_id as id, username as name, user_colour as colour
  732. FROM ' . USERS_TABLE . '
  733. WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
  734. ORDER BY username_clean ASC';
  735. $result['u'] = $db->sql_query($sql);
  736. }
  737. if (!empty($address_list['g']))
  738. {
  739. $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
  740. FROM ' . GROUPS_TABLE . ' g';
  741. if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  742. {
  743. $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  744. ON (
  745. g.group_id = ug.group_id
  746. AND ug.user_id = ' . $user->data['user_id'] . '
  747. AND ug.user_pending = 0
  748. )
  749. WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
  750. }
  751. $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
  752. $sql .= 'g.group_receive_pm = 1
  753. AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
  754. ORDER BY g.group_name ASC';
  755. $result['g'] = $db->sql_query($sql);
  756. }
  757. $u = $g = array();
  758. $_types = array('u', 'g');
  759. foreach ($_types as $type)
  760. {
  761. if (isset($result[$type]) && $result[$type])
  762. {
  763. while ($row = $db->sql_fetchrow($result[$type]))
  764. {
  765. if ($type == 'g')
  766. {
  767. $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
  768. }
  769. ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
  770. }
  771. $db->sql_freeresult($result[$type]);
  772. }
  773. }
  774. // Now Build the address list
  775. $plain_address_field = '';
  776. foreach ($address_list as $type => $adr_ary)
  777. {
  778. foreach ($adr_ary as $id => $field)
  779. {
  780. if (!isset(${$type}[$id]))
  781. {
  782. unset($address_list[$type][$id]);
  783. continue;
  784. }
  785. $field = ($field == 'to') ? 'to' : 'bcc';
  786. $type = ($type == 'u') ? 'u' : 'g';
  787. $id = (int) $id;
  788. $tpl_ary = array(
  789. 'IS_GROUP' => ($type == 'g') ? true : false,
  790. 'IS_USER' => ($type == 'u') ? true : false,
  791. 'UG_ID' => $id,
  792. 'NAME' => ${$type}[$id]['name'],
  793. 'COLOUR' => (${$type}[$id]['colour']) ? '#' . ${$type}[$id]['colour'] : '',
  794. 'TYPE' => $type,
  795. );
  796. if ($type == 'u')
  797. {
  798. $tpl_ary = array_merge($tpl_ary, array(
  799. 'U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
  800. 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
  801. ));
  802. }
  803. else
  804. {
  805. $tpl_ary = array_merge($tpl_ary, array(
  806. 'U_VIEW' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $id),
  807. ));
  808. }
  809. $template->assign_block_vars($field . '_recipient', $tpl_ary);
  810. }
  811. }
  812. }
  813. // Build hidden address list
  814. $s_hidden_address_field = build_address_field($address_list);
  815. $bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ? !$user->optionget('bbcode') : 1);
  816. $smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ? !$user->optionget('smilies') : 1);
  817. $urls_checked = (isset($enable_urls)) ? !$enable_urls : 0;
  818. $sig_checked = $enable_sig;
  819. switch ($action)
  820. {
  821. case 'post':
  822. $page_title = $user->lang['POST_NEW_PM'];
  823. break;
  824. case 'quote':
  825. $page_title = $user->lang['POST_QUOTE_PM'];
  826. break;
  827. case 'quotepost':
  828. $page_title = $user->lang['POST_PM_POST'];
  829. break;
  830. case 'reply':
  831. $page_title = $user->lang['POST_REPLY_PM'];
  832. break;
  833. case 'edit':
  834. $page_title = $user->lang['POST_EDIT_PM'];
  835. break;
  836. case 'forward':
  837. $page_title = $user->lang['POST_FORWARD_PM'];
  838. break;
  839. default:
  840. trigger_error('NO_ACTION_MODE', E_USER_ERROR);
  841. break;
  842. }
  843. $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
  844. $s_hidden_fields .= (isset($check_value)) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
  845. $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . ((isset($_REQUEST['draft_loaded'])) ? intval($_REQUEST['draft_loaded']) : $draft_id) . '" />' : '';
  846. $form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_pm_attach'] || !$auth->acl_get('u_pm_attach')) ? '' : ' enctype="multipart/form-data"';
  847. // Start assigning vars for main posting page ...
  848. $template->assign_vars(array(
  849. 'L_POST_A' => $page_title,
  850. 'L_ICON' => $user->lang['PM_ICON'],
  851. 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
  852. 'SUBJECT' => (isset($message_subject)) ? $message_subject : '',
  853. 'MESSAGE' => $message_text,
  854. 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
  855. 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  856. 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  857. 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  858. 'URL_STATUS' => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  859. 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']),
  860. 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
  861. 'MAX_RECIPIENTS' => ($config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group'))) ? $max_recipients : 0,
  862. 'S_COMPOSE_PM' => true,
  863. 'S_EDIT_POST' => ($action == 'edit'),
  864. 'S_SHOW_PM_ICONS' => $s_pm_icons,
  865. 'S_BBCODE_ALLOWED' => $bbcode_status,
  866. 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
  867. 'S_SMILIES_ALLOWED' => $smilies_status,
  868. 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
  869. 'S_SIG_ALLOWED' => ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')),
  870. 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
  871. 'S_LINKS_ALLOWED' => $url_status,
  872. 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
  873. 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $action != 'edit') ? true : false,
  874. 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $drafts),
  875. 'S_FORM_ENCTYPE' => $form_enctype,
  876. 'S_BBCODE_IMG' => $img_status,
  877. 'S_BBCODE_FLASH' => $flash_status,
  878. 'S_BBCODE_QUOTE' => true,
  879. 'S_BBCODE_URL' => $url_status,
  880. 'S_POST_ACTION' => $s_action,
  881. 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field,
  882. 'S_HIDDEN_FIELDS' => $s_hidden_fields,
  883. 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']),
  884. 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&amp;mode=popup'),
  885. 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&amp;mode=popup')),
  886. ));
  887. // Build custom bbcodes array
  888. display_custom_bbcodes();
  889. // Show attachment box for adding attachments if true
  890. $allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype);
  891. // Attachment entry
  892. posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
  893. // Message History
  894. if ($action == 'reply' || $action == 'quote' || $action == 'forward')
  895. {
  896. if (message_history($msg_id, $user->data['user_id'], $post, array(), true))
  897. {
  898. $template->assign_var('S_DISPLAY_HISTORY', true);
  899. }
  900. }
  901. }
  902. /**
  903. * For composing messages, handle list actions
  904. */
  905. function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc)
  906. {
  907. global $auth, $db, $user;
  908. // Delete User [TO/BCC]
  909. if ($remove_u && !empty($_REQUEST['remove_u']) && is_array($_REQUEST['remove_u']))
  910. {
  911. $remove_user_id = array_keys($_REQUEST['remove_u']);
  912. if (isset($remove_user_id[0]))
  913. {
  914. unset($address_list['u'][(int) $remove_user_id[0]]);
  915. }
  916. }
  917. // Delete Group [TO/BCC]
  918. if ($remove_g && !empty($_REQUEST['remove_g']) && is_array($_REQUEST['remove_g']))
  919. {
  920. $remove_group_id = array_keys($_REQUEST['remove_g']);
  921. if (isset($remove_group_id[0]))
  922. {
  923. unset($address_list['g'][(int) $remove_group_id[0]]);
  924. }
  925. }
  926. // Add Selected Groups
  927. $group_list = request_var('group_list', array(0));
  928. // Build usernames to add
  929. $usernames = (isset($_REQUEST['username'])) ? array(request_var('username', '', true)) : array();
  930. $username_list = request_var('username_list', '', true);
  931. if ($username_list)
  932. {
  933. $usernames = array_merge($usernames, explode("\n", $username_list));
  934. }
  935. // If add to or add bcc not pressed, users could still have usernames listed they want to add...
  936. if (!$add_to && !$add_bcc && (sizeof($group_list) || sizeof($usernames)))
  937. {
  938. $add_to = true;
  939. global $refresh, $submit, $preview;
  940. $refresh = $preview = true;
  941. $submit = false;
  942. }
  943. // Add User/Group [TO]
  944. if ($add_to || $add_bcc)
  945. {
  946. $type = ($add_to) ? 'to' : 'bcc';
  947. if (sizeof($group_list))
  948. {
  949. foreach ($group_list as $group_id)
  950. {
  951. $address_list['g'][$group_id] = $type;
  952. }
  953. }
  954. // User ID's to add...
  955. $user_id_ary = array();
  956. // Reveal the correct user_ids
  957. if (sizeof($usernames))
  958. {
  959. $user_id_ary = array();
  960. user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL, USER_FOUNDER, USER_INACTIVE));
  961. // If there are users not existing, we will at least print a notice...
  962. if (!sizeof($user_id_ary))
  963. {
  964. $error[] = $user->lang['PM_NO_USERS'];
  965. }
  966. }
  967. // Add Friends if specified
  968. $friend_list = (isset($_REQUEST['add_' . $type]) && is_array($_REQUEST['add_' . $type])) ? array_map('intval', array_keys($_REQUEST['add_' . $type])) : array();
  969. $user_id_ary = array_merge($user_id_ary, $friend_list);
  970. foreach ($user_id_ary as $user_id)
  971. {
  972. if ($user_id == ANONYMOUS)
  973. {
  974. continue;
  975. }
  976. $address_list['u'][$user_id] = $type;
  977. }
  978. }
  979. // Check for disallowed recipients
  980. if (!empty($address_list['u']))
  981. {
  982. // We need to check their PM status (do they want to receive PM's?)
  983. // Only check if not a moderator or admin, since they are allowed to override this user setting
  984. if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
  985. {
  986. $sql = 'SELECT user_id
  987. FROM ' . USERS_TABLE . '
  988. WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . '
  989. AND user_allow_pm = 0';
  990. $result = $db->sql_query($sql);
  991. $removed = false;
  992. while ($row = $db->sql_fetchrow($result))
  993. {
  994. $removed = true;
  995. unset($address_list['u'][$row['user_id']]);
  996. }
  997. $db->sql_freeresult($result);
  998. // print a notice about users not being added who do not want to receive pms
  999. if ($removed)
  1000. {
  1001. $error[] = $user->lang['PM_USERS_REMOVED_NO_PM'];
  1002. }
  1003. }
  1004. }
  1005. }
  1006. /**
  1007. * Build the hidden field for the recipients. Needed, as the variable is not read via request_var.
  1008. */
  1009. function build_address_field($address_list)
  1010. {
  1011. $s_hidden_address_field = '';
  1012. foreach ($address_list as $type => $adr_ary)
  1013. {
  1014. foreach ($adr_ary as $id => $field)
  1015. {
  1016. $s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ? 'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ? 'to' : 'bcc') . '" />';
  1017. }
  1018. }
  1019. return $s_hidden_address_field;
  1020. }
  1021. /**
  1022. * Return number of private message recipients
  1023. */
  1024. function num_recipients($address_list)
  1025. {
  1026. $num_recipients = 0;
  1027. foreach ($address_list as $field => $adr_ary)
  1028. {
  1029. $num_recipients += sizeof($adr_ary);
  1030. }
  1031. return $num_recipients;
  1032. }
  1033. /**
  1034. * Get number of 'num_recipients' recipients from first position
  1035. */
  1036. function get_recipients($address_list, $num_recipients = 1)
  1037. {
  1038. $recipient = array();
  1039. $count = 0;
  1040. foreach ($address_list as $field => $adr_ary)
  1041. {
  1042. foreach ($adr_ary as $id => $type)
  1043. {
  1044. if ($count >= $num_recipients)
  1045. {
  1046. break 2;
  1047. }
  1048. $recipient[$field][$id] = $type;
  1049. $count++;
  1050. }
  1051. }
  1052. return $recipient;
  1053. }
  1054. ?>