6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
20 * Compose private message
21 * Called from ucp_pm with mode == 'compose'
23 function compose_pm($id, $mode, $action)
25 global $template, $db, $auth, $user, $config;
27 // Damn php and globals - i know, this is horrible
28 // Needed for handle_message_list_actions()
29 global $refresh, $submit, $preview;
31 include(PHPBB_ROOT_PATH
. 'includes/functions_posting.' . PHP_EXT
);
32 include(PHPBB_ROOT_PATH
. 'includes/functions_display.' . PHP_EXT
);
33 include(PHPBB_ROOT_PATH
. 'includes/message_parser.' . PHP_EXT
);
39 add_form_key('ucp_pm_compose');
41 // Grab only parameters needed here
42 $to_user_id = request_var('u', 0);
43 $to_group_id = request_var('g', 0);
44 $msg_id = request_var('p', 0);
45 $draft_id = request_var('d', 0);
46 $lastclick = request_var('lastclick', 0);
48 // Do NOT use request_var or specialchars here
49 $address_list = isset($_REQUEST['address_list']) ?
$_REQUEST['address_list'] : array();
51 if (!is_array($address_list))
53 $address_list = array();
56 $submit = (isset($_POST['post'])) ?
true : false;
57 $preview = (isset($_POST['preview'])) ?
true : false;
58 $save = (isset($_POST['save'])) ?
true : false;
59 $load = (isset($_POST['load'])) ?
true : false;
60 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ?
true : false;
61 $delete = (isset($_POST['delete'])) ?
true : false;
63 $remove_u = (isset($_REQUEST['remove_u'])) ?
true : false;
64 $remove_g = (isset($_REQUEST['remove_g'])) ?
true : false;
65 $add_to = (isset($_REQUEST['add_to'])) ?
true : false;
66 $add_bcc = (isset($_REQUEST['add_bcc'])) ?
true : false;
68 $refresh = isset($_POST['add_file']) ||
isset($_POST['delete_file']) ||
$save ||
$load
69 ||
$remove_u ||
$remove_g ||
$add_to ||
$add_bcc;
71 $action = ($delete && !$preview && !$refresh && $submit) ?
'delete' : $action;
72 $select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ?
false : true;
75 $current_time = time();
77 // Was cancel pressed? If so then redirect to the appropriate page
78 if ($cancel ||
($current_time - $lastclick < 2 && $submit))
82 redirect(append_sid('ucp', 'i=pm&mode=view&action=view_message&p=' . $msg_id));
84 redirect(append_sid('ucp', 'i=pm'));
87 // Output PM_TO box if message composing
88 if ($action != 'edit')
90 // Add groups to PM box
91 if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group'))
93 $sql = 'SELECT g.group_id, g.group_name, g.group_type
94 FROM ' . GROUPS_TABLE
. ' g';
96 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
98 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE
. ' ug
100 g.group_id = ug.group_id
101 AND ug.user_id = ' . $user->data
['user_id'] . '
102 AND ug.user_pending = 0
104 WHERE (g.group_type <> ' . GROUP_HIDDEN
. ' OR ug.user_id = ' . $user->data
['user_id'] . ')';
107 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ?
' WHERE ' : ' AND ';
109 $sql .= 'g.group_receive_pm = 1
110 ORDER BY g.group_type DESC, g.group_name ASC';
111 $result = $db->sql_query($sql);
114 while ($row = $db->sql_fetchrow($result))
116 $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>';
118 $db->sql_freeresult($result);
121 $template->assign_vars(array(
122 'S_SHOW_PM_BOX' => true,
123 'S_ALLOW_MASS_PM' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ?
true : false,
124 'S_GROUP_OPTIONS' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) ?
$group_options : '',
125 'U_FIND_USERNAME' => append_sid('memberlist', "mode=searchuser&form=postform&field=username_list&select_single=$select_single"),
131 // What is all this following SQL for? Well, we need to know
132 // some basic information in all cases before we do anything.
136 if (!$auth->acl_get('u_sendpm'))
138 trigger_error('NO_AUTH_SEND_MESSAGE');
148 trigger_error('NO_MESSAGE');
151 if (!$auth->acl_get('u_sendpm'))
153 trigger_error('NO_AUTH_SEND_MESSAGE');
156 if ($action == 'quotepost')
158 $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
159 FROM ' . POSTS_TABLE
. ' p, ' . TOPICS_TABLE
. ' t, ' . USERS_TABLE
. " u
160 WHERE p.post_id = $msg_id
161 AND t.topic_id = p.topic_id
162 AND u.user_id = p.poster_id";
166 $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
167 FROM ' . PRIVMSGS_TO_TABLE
. ' t, ' . PRIVMSGS_TABLE
. ' p, ' . USERS_TABLE
. ' u
168 WHERE t.user_id = ' . $user->data
['user_id'] . "
169 AND p.author_id = u.user_id
170 AND t.msg_id = p.msg_id
171 AND p.msg_id = $msg_id";
178 trigger_error('NO_MESSAGE');
181 // check for outbox (not read) status, we do not allow editing if one user already having the message
182 $sql = 'SELECT p.*, t.folder_id
183 FROM ' . PRIVMSGS_TO_TABLE
. ' t, ' . PRIVMSGS_TABLE
. ' p
184 WHERE t.user_id = ' . $user->data
['user_id'] . '
185 AND t.folder_id = ' . PRIVMSGS_OUTBOX
. "
186 AND t.msg_id = $msg_id
187 AND t.msg_id = p.msg_id";
191 if (!$auth->acl_get('u_pm_delete'))
193 trigger_error('NO_AUTH_DELETE_MESSAGE');
198 trigger_error('NO_MESSAGE');
201 $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
202 FROM ' . PRIVMSGS_TO_TABLE
. '
203 WHERE user_id = ' . $user->data
['user_id'] . "
204 AND msg_id = $msg_id";
208 generate_smilies('window', 0);
212 trigger_error('NO_ACTION_MODE', E_USER_ERROR
);
216 if ($action == 'forward' && (!$config['forward_pm'] ||
!$auth->acl_get('u_pm_forward')))
218 trigger_error('NO_AUTH_FORWARD_MESSAGE');
221 if ($action == 'edit' && !$auth->acl_get('u_pm_edit'))
223 trigger_error('NO_AUTH_EDIT_MESSAGE');
228 $result = $db->sql_query($sql);
229 $post = $db->sql_fetchrow($result);
230 $db->sql_freeresult($result);
234 // If editing it could be the recipient already read the message...
235 if ($action == 'edit')
237 $sql = 'SELECT p.*, t.folder_id
238 FROM ' . PRIVMSGS_TO_TABLE
. ' t, ' . PRIVMSGS_TABLE
. ' p
239 WHERE t.user_id = ' . $user->data
['user_id'] . "
240 AND t.msg_id = $msg_id
241 AND t.msg_id = p.msg_id";
242 $result = $db->sql_query($sql);
243 $post = $db->sql_fetchrow($result);
244 $db->sql_freeresult($result);
248 trigger_error('NO_EDIT_READ_MESSAGE');
252 trigger_error('NO_MESSAGE');
255 if ($action == 'quotepost')
257 if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) ||
(!$post['forum_id'] && !$auth->acl_getf_global('f_read')))
259 trigger_error('NOT_AUTHORISED');
263 $msg_id = (int) $post['msg_id'];
264 $folder_id = (isset($post['folder_id'])) ?
$post['folder_id'] : 0;
265 $message_text = (isset($post['message_text'])) ?
$post['message_text'] : '';
267 if ((!$post['author_id'] ||
($post['author_id'] == ANONYMOUS
&& $action != 'delete')) && $msg_id)
269 trigger_error('NO_AUTHOR');
272 if ($action == 'quotepost')
274 // Decode text for message display
275 decode_message($message_text, $post['bbcode_uid']);
278 if ($action != 'delete')
280 $enable_urls = $post['enable_magic_url'];
281 $enable_sig = (isset($post['enable_sig'])) ?
$post['enable_sig'] : 0;
283 $message_attachment = (isset($post['message_attachment'])) ?
$post['message_attachment'] : 0;
284 $message_subject = $post['message_subject'];
285 $message_time = $post['message_time'];
286 $bbcode_uid = $post['bbcode_uid'];
288 $quote_username = (isset($post['quote_username'])) ?
$post['quote_username'] : '';
289 $icon_id = (isset($post['icon_id'])) ?
$post['icon_id'] : 0;
291 if (($action == 'reply' ||
$action == 'quote' ||
$action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
293 if ($action == 'quotepost')
295 $address_list = array('u' => array($post['author_id'] => 'to'));
299 // We try to include every previously listed member from the TO Header
300 $address_list = rebuild_header(array('to' => $post['to_address']));
302 // Add the author (if he is already listed then this is no shame (it will be overwritten))
303 $address_list['u'][$post['author_id']] = 'to';
305 // Now, make sure the user itself is not listed. ;)
306 if (isset($address_list['u'][$user->data
['user_id']]))
308 unset($address_list['u'][$user->data
['user_id']]);
312 else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview)
314 // Rebuild TO and BCC Header
315 $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
318 if ($action == 'quotepost')
324 $check_value = (($post['enable_bbcode']+
1) << 8) +
(($post['enable_smilies']+
1) << 4) +
(($enable_urls+
1) << 2) +
(($post['enable_sig']+
1) << 1);
330 $message_attachment = 0;
331 $message_text = $message_subject = '';
333 if ($to_user_id && $action == 'post')
335 $address_list['u'][$to_user_id] = 'to';
337 else if ($to_group_id && $action == 'post')
339 $address_list['g'][$to_group_id] = 'to';
344 if (($to_group_id ||
isset($address_list['g'])) && (!$config['allow_mass_pm'] ||
!$auth->acl_get('u_masspm_group')))
346 trigger_error('NO_AUTH_GROUP_MESSAGE');
349 if ($action == 'edit' && !$refresh && !$preview && !$submit)
351 if (!($message_time > time() - ($config['pm_edit_time'] * 60) ||
!$config['pm_edit_time']))
353 trigger_error('CANNOT_EDIT_MESSAGE_TIME');
357 if ($action == 'post')
359 $template->assign_var('S_NEW_MESSAGE', true);
362 if (!isset($icon_id))
367 $message_parser = new parse_message();
369 $message_parser->message
= ($action == 'reply') ?
'' : $message_text;
370 unset($message_text);
372 $s_action = append_sid('ucp', "i=$id&mode=$mode&action=$action", true, $user->session_id
);
373 $s_action .= ($msg_id) ?
"&p=$msg_id" : '';
375 // Delete triggered ?
376 if ($action == 'delete')
378 // Folder id has been determined by the SQL Statement
379 // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
381 // Do we need to confirm ?
382 if (confirm_box(true))
384 delete_pm($user->data
['user_id'], $msg_id, $folder_id);
386 // jump to next message in "history"? nope, not for the moment. But able to be included later.
387 $meta_info = append_sid('ucp', "i=pm&folder=$folder_id");
388 $message = $user->lang
['MESSAGE_DELETED'];
390 meta_refresh(3, $meta_info);
391 $message .= '<br /><br />' . sprintf($user->lang
['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
392 trigger_error($message);
396 $s_hidden_fields = array(
402 // "ucp.php?i=pm&mode=compose"
403 confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
406 redirect(append_sid('ucp', 'i=pm&mode=view&action=view_message&p=' . $msg_id));
409 // Get maximum number of allowed recipients
410 $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
411 FROM ' . GROUPS_TABLE
. ' g, ' . USER_GROUP_TABLE
. ' ug
412 WHERE ug.user_id = ' . $user->data
['user_id'] . '
413 AND ug.user_pending = 0
414 AND ug.group_id = g.group_id';
415 $result = $db->sql_query($sql);
416 $max_recipients = (int) $db->sql_fetchfield('max_recipients');
417 $db->sql_freeresult($result);
419 $max_recipients = (!$max_recipients) ?
$config['pm_max_recipients'] : $max_recipients;
421 // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
422 if (($action == 'reply' ||
$action == 'quote') && $max_recipients)
424 // We try to include every previously listed member from the TO Header
425 $list = rebuild_header(array('to' => $post['to_address']));
427 // Can be an empty array too ;)
428 $list = (!empty($list['u'])) ?
$list['u'] : array();
429 $list[$post['author_id']] = 'to';
431 if (isset($list[$user->data
['user_id']]))
433 unset($list[$user->data
['user_id']]);
436 $max_recipients = ($max_recipients < sizeof($list)) ?
sizeof($list) : $max_recipients;
441 // Handle User/Group adding/removing
442 handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
444 // Check mass pm to group permission
445 if ((!$config['allow_mass_pm'] ||
!$auth->acl_get('u_masspm_group')) && !empty($address_list['g']))
447 $address_list = array();
448 $error[] = $user->lang
['NO_AUTH_GROUP_MESSAGE'];
451 // Check mass pm to users permission
452 if ((!$config['allow_mass_pm'] ||
!$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1)
454 $address_list = get_recipients($address_list, 1);
455 $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
458 // Check for too many recipients
459 if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients)
461 $address_list = get_recipients($address_list, $max_recipients);
462 $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
465 // Always check if the submitted attachment data is valid and belongs to the user.
466 // Further down (especially in submit_post()) we do not check this again.
467 $message_parser->get_submitted_attachment_data();
469 if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit')
471 // Do not change to SELECT *
472 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
473 FROM ' . ATTACHMENTS_TABLE
. "
474 WHERE post_msg_id = $msg_id
477 ORDER BY filetime DESC";
478 $result = $db->sql_query($sql);
479 $message_parser->attachment_data
= array_merge($message_parser->attachment_data
, $db->sql_fetchrowset($result));
480 $db->sql_freeresult($result);
483 if (!in_array($action, array('quote', 'edit', 'delete', 'forward')))
485 $enable_sig = ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig'));
486 $enable_smilies = ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies'));
487 $enable_bbcode = ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode'));
491 $enable_magic_url = $drafts = false;
493 // User own some drafts?
494 if ($auth->acl_get('u_savedrafts') && $action != 'delete')
496 $sql = 'SELECT draft_id
497 FROM ' . DRAFTS_TABLE
. '
500 AND user_id = ' . $user->data
['user_id'] .
501 (($draft_id) ?
" AND draft_id <> $draft_id" : '');
502 $result = $db->sql_query_limit($sql, 1);
503 $row = $db->sql_fetchrow($result);
504 $db->sql_freeresult($result);
512 if ($action == 'edit')
514 $message_parser->bbcode_uid
= $bbcode_uid;
517 $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ?
true : false;
518 $smilies_status = ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ?
true : false;
519 $img_status = ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ?
true : false;
520 $flash_status = ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ?
true : false;
521 $url_status = ($config['allow_post_links']) ?
true : false;
524 if ($save && $auth->acl_get('u_savedrafts'))
526 $subject = utf8_normalize_nfc(request_var('subject', '', true));
527 $subject = (!$subject && $action != 'post') ?
$user->lang
['NEW_MESSAGE'] : $subject;
528 $message = utf8_normalize_nfc(request_var('message', '', true));
530 if ($subject && $message)
532 if (confirm_box(true))
534 $sql = 'INSERT INTO ' . DRAFTS_TABLE
. ' ' . $db->sql_build_array('INSERT', array(
535 'user_id' => $user->data
['user_id'],
538 'save_time' => $current_time,
539 'draft_subject' => $subject,
540 'draft_message' => $message
543 $db->sql_query($sql);
545 $redirect_url = append_sid('ucp', "i=pm&mode=$mode");
547 meta_refresh(3, $redirect_url);
548 $message = $user->lang
['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang
['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
550 trigger_error($message);
554 $s_hidden_fields = build_hidden_fields(array(
558 'subject' => $subject,
559 'message' => $message,
564 $s_hidden_fields .= build_address_field($address_list);
567 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
572 if (utf8_clean_string($subject) === '')
574 $error[] = $user->lang
['EMPTY_MESSAGE_SUBJECT'];
577 if (utf8_clean_string($message) === '')
579 $error[] = $user->lang
['TOO_FEW_CHARS'];
583 unset($subject, $message);
587 if ($draft_id && $auth->acl_get('u_savedrafts'))
589 $sql = 'SELECT draft_subject, draft_message
590 FROM ' . DRAFTS_TABLE
. "
591 WHERE draft_id = $draft_id
594 AND user_id = " . $user->data
['user_id'];
595 $result = $db->sql_query_limit($sql, 1);
597 if ($row = $db->sql_fetchrow($result))
599 $message_parser->message
= $row['draft_message'];
600 $message_subject = $row['draft_subject'];
602 $template->assign_var('S_DRAFT_LOADED', true);
608 $db->sql_freeresult($result);
612 if ($load && $drafts)
614 load_drafts(0, 0, $id);
617 if ($submit ||
$preview ||
$refresh)
619 if (($submit ||
$preview) && !check_form_key('ucp_pm_compose'))
621 $error[] = $user->lang
['FORM_INVALID'];
623 $subject = utf8_normalize_nfc(request_var('subject', '', true));
624 $message_parser->message
= utf8_normalize_nfc(request_var('message', '', true));
626 $icon_id = request_var('icon', 0);
628 $enable_bbcode = (!$bbcode_status ||
isset($_POST['disable_bbcode'])) ?
false : true;
629 $enable_smilies = (!$smilies_status ||
isset($_POST['disable_smilies'])) ?
false : true;
630 $enable_urls = (isset($_POST['disable_magic_url'])) ?
0 : 1;
631 $enable_sig = (!$config['allow_sig'] ||
!$config['allow_sig_pm']) ?
false : ((isset($_POST['attach_sig'])) ?
true : false);
635 $status_switch = (($enable_bbcode+
1) << 8) +
(($enable_smilies+
1) << 4) +
(($enable_urls+
1) << 2) +
(($enable_sig+
1) << 1);
636 $status_switch = ($status_switch != $check_value);
643 // Parse Attachments - before checksum is calculated
644 $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
646 if (sizeof($message_parser->warn_msg
) && !($remove_u ||
$remove_g ||
$add_to ||
$add_bcc))
648 $error[] = implode('<br />', $message_parser->warn_msg
);
649 $message_parser->warn_msg
= array();
653 $message_parser->parse($enable_bbcode, ($config['allow_post_links']) ?
$enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
655 // On a refresh we do not care about message parsing errors
656 if (sizeof($message_parser->warn_msg
) && !$refresh)
658 $error[] = implode('<br />', $message_parser->warn_msg
);
661 if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood'))
664 $last_post_time = $user->data
['user_lastpost_time'];
668 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
670 $error[] = $user->lang
['FLOOD_ERROR'];
678 if (utf8_clean_string($subject) === '')
680 $error[] = $user->lang
['EMPTY_MESSAGE_SUBJECT'];
683 if (!sizeof($address_list))
685 $error[] = $user->lang
['NO_RECIPIENT'];
689 // Store message, sync counters
690 if (!sizeof($error) && $submit)
693 'msg_id' => (int) $msg_id,
694 'from_user_id' => $user->data
['user_id'],
695 'from_user_ip' => $user->ip
,
696 'from_username' => $user->data
['username'],
697 'reply_from_root_level' => (isset($post['root_level'])) ?
(int) $post['root_level'] : 0,
698 'reply_from_msg_id' => (int) $msg_id,
699 'icon_id' => (int) $icon_id,
700 'enable_sig' => (bool) $enable_sig,
701 'enable_bbcode' => (bool) $enable_bbcode,
702 'enable_smilies' => (bool) $enable_smilies,
703 'enable_urls' => (bool) $enable_urls,
704 'bbcode_bitfield' => $message_parser->bbcode_bitfield
,
705 'bbcode_uid' => $message_parser->bbcode_uid
,
706 'message' => $message_parser->message
,
707 'attachment_data' => $message_parser->attachment_data
,
708 'filename_data' => $message_parser->filename_data
,
709 'address_list' => $address_list
712 // ((!$message_subject) ? $subject : $message_subject)
713 $msg_id = submit_pm($action, $subject, $pm_data);
715 $return_message_url = append_sid('ucp', 'i=pm&mode=view&p=' . $msg_id);
716 $return_folder_url = append_sid('ucp', 'i=pm&folder=outbox');
717 meta_refresh(3, $return_message_url);
719 $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']);
720 trigger_error($message);
723 $message_subject = $subject;
727 if (!sizeof($error) && $preview)
729 $user->add_lang('viewtopic');
730 $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
732 $preview_signature = $user->data
['user_sig'];
733 $preview_signature_uid = $user->data
['user_sig_bbcode_uid'];
734 $preview_signature_bitfield = $user->data
['user_sig_bbcode_bitfield'];
737 if ($enable_sig && $config['allow_sig'] && $preview_signature)
739 $parse_sig = new parse_message($preview_signature);
740 $parse_sig->bbcode_uid
= $preview_signature_uid;
741 $parse_sig->bbcode_bitfield
= $preview_signature_bitfield;
743 $parse_sig->format_display($enable_bbcode, $enable_urls, $enable_smilies);
744 $preview_signature = $parse_sig->message
;
749 $preview_signature = '';
752 // Attachment Preview
753 if (sizeof($message_parser->attachment_data
))
755 $template->assign_var('S_HAS_ATTACHMENTS', true);
757 $update_count = array();
758 $attachment_data = $message_parser->attachment_data
;
760 parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
762 foreach ($attachment_data as $i => $attachment)
764 $template->assign_block_vars('attachment', array(
765 'DISPLAY_ATTACHMENT' => $attachment)
768 unset($attachment_data);
771 $preview_subject = censor_text($subject);
775 $template->assign_vars(array(
776 'PREVIEW_SUBJECT' => $preview_subject,
777 'PREVIEW_MESSAGE' => $preview_message,
778 'PREVIEW_SIGNATURE' => $preview_signature,
780 'S_DISPLAY_PREVIEW' => true)
783 unset($message_text);
786 // Decode text for message display
787 $bbcode_uid = (($action == 'quote' ||
$action == 'forward') && !$preview && !$refresh && !sizeof($error)) ?
$bbcode_uid : $message_parser->bbcode_uid
;
789 $message_parser->decode_message($bbcode_uid);
791 if (($action == 'quote' ||
$action == 'quotepost') && !$preview && !$refresh && !$submit)
793 if ($action == 'quotepost')
795 $post_id = request_var('p', 0);
796 if ($config['allow_post_links'])
798 $message_link = "[url=" . generate_board_url() . '/viewtopic.' . PHP_EXT
. "?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}: {$message_subject}[/url]\n\n";
802 $message_link = $user->lang
['SUBJECT'] . ': ' . $message_subject . " (" . generate_board_url() . '/viewtopic.' . PHP_EXT
. "?p={$post_id}#p{$post_id})\n\n";
809 $message_parser->message
= $message_link . '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message
)) . "[/quote]\n";
812 if (($action == 'reply' ||
$action == 'quote' ||
$action == 'quotepost') && !$preview && !$refresh)
814 $message_subject = ((!preg_match('/^Re:/', $message_subject)) ?
'Re: ' : '') . censor_text($message_subject);
817 if ($action == 'forward' && !$preview && !$refresh && !$submit)
819 $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
821 if ($config['allow_post_links'])
823 $quote_username_text = '[url=' . generate_board_url() . '/memberlist.' . PHP_EXT
. "?mode=viewprofile&u={$post['author_id']}]{$quote_username}[/url]";
827 $quote_username_text = $quote_username . ' (' . generate_board_url() . '/memberlist.' . PHP_EXT
. "?mode=viewprofile&u={$post['author_id']})";
830 $forward_text = array();
831 $forward_text[] = $user->lang
['FWD_ORIGINAL_MESSAGE'];
832 $forward_text[] = sprintf($user->lang
['FWD_SUBJECT'], censor_text($message_subject));
833 $forward_text[] = sprintf($user->lang
['FWD_DATE'], $user->format_date($message_time));
834 $forward_text[] = sprintf($user->lang
['FWD_FROM'], $quote_username_text);
835 $forward_text[] = sprintf($user->lang
['FWD_TO'], implode(', ', $fwd_to_field['to']));
837 $message_parser->message
= implode("\n", $forward_text) . "\n\n[quote="{$quote_username}"]\n" . censor_text(trim($message_parser->message
)) . "\n[/quote]";
838 $message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ?
'Fwd: ' : '') . censor_text($message_subject);
841 $attachment_data = $message_parser->attachment_data
;
842 $filename_data = $message_parser->filename_data
;
843 $message_text = $message_parser->message
;
845 // MAIN PM PAGE BEGINS HERE
847 // Generate smiley listing
848 generate_smilies('inline', 0);
852 if ($config['enable_pm_icons'])
854 $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
857 // Generate inline attachment select box
858 posting_gen_inline_attachments($attachment_data);
860 // Build address list for display
861 // array('u' => array($author_id => 'to'));
862 if (sizeof($address_list))
864 // Get Usernames and Group Names
866 if (!empty($address_list['u']))
868 $sql = 'SELECT user_id as id, username as name, user_colour as colour
869 FROM ' . USERS_TABLE
. '
870 WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
871 ORDER BY username_clean ASC';
872 $result['u'] = $db->sql_query($sql);
875 if (!empty($address_list['g']))
877 $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
878 FROM ' . GROUPS_TABLE
. ' g';
880 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
882 $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE
. ' ug
884 g.group_id = ug.group_id
885 AND ug.user_id = ' . $user->data
['user_id'] . '
886 AND ug.user_pending = 0
888 WHERE (g.group_type <> ' . GROUP_HIDDEN
. ' OR ug.user_id = ' . $user->data
['user_id'] . ')';
891 $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ?
' WHERE ' : ' AND ';
893 $sql .= 'g.group_receive_pm = 1
894 AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
895 ORDER BY g.group_name ASC';
897 $result['g'] = $db->sql_query($sql);
901 $_types = array('u', 'g');
902 foreach ($_types as $type)
904 if (isset($result[$type]) && $result[$type])
906 while ($row = $db->sql_fetchrow($result[$type]))
910 $row['name'] = ($row['group_type'] == GROUP_SPECIAL
) ?
$user->lang
['G_' . $row['name']] : $row['name'];
913 $
{$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
915 $db->sql_freeresult($result[$type]);
919 // Now Build the address list
920 $plain_address_field = '';
921 foreach ($address_list as $type => $adr_ary)
923 foreach ($adr_ary as $id => $field)
925 if (!isset($
{$type}[$id]))
927 unset($address_list[$type][$id]);
931 $field = ($field == 'to') ?
'to' : 'bcc';
932 $type = ($type == 'u') ?
'u' : 'g';
936 'IS_GROUP' => ($type == 'g') ?
true : false,
937 'IS_USER' => ($type == 'u') ?
true : false,
939 'NAME' => $
{$type}[$id]['name'],
940 'COLOUR' => ($
{$type}[$id]['colour']) ?
'#' . $
{$type}[$id]['colour'] : '',
946 $tpl_ary = array_merge($tpl_ary, array(
947 'U_VIEW' => get_username_string('profile', $id, $
{$type}[$id]['name'], $
{$type}[$id]['colour']),
948 'NAME_FULL' => get_username_string('full', $id, $
{$type}[$id]['name'], $
{$type}[$id]['colour']),
953 $tpl_ary = array_merge($tpl_ary, array(
954 'U_VIEW' => append_sid('memberlist', 'mode=group&g=' . $id),
958 $template->assign_block_vars($field . '_recipient', $tpl_ary);
963 // Build hidden address list
964 $s_hidden_address_field = build_address_field($address_list);
967 $bbcode_checked = (isset($enable_bbcode)) ?
!$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ?
!$user->optionget('bbcode') : 1);
968 $smilies_checked = (isset($enable_smilies)) ?
!$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ?
!$user->optionget('smilies') : 1);
969 $urls_checked = (isset($enable_urls)) ?
!$enable_urls : 0;
970 $sig_checked = $enable_sig;
975 $page_title = $user->lang
['POST_NEW_PM'];
979 $page_title = $user->lang
['POST_QUOTE_PM'];
983 $page_title = $user->lang
['POST_PM_POST'];
987 $page_title = $user->lang
['POST_REPLY_PM'];
991 $page_title = $user->lang
['POST_EDIT_PM'];
995 $page_title = $user->lang
['POST_FORWARD_PM'];
999 trigger_error('NO_ACTION_MODE', E_USER_ERROR
);
1003 $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1004 $s_hidden_fields .= (isset($check_value)) ?
'<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
1005 $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) . '" />' : '';
1007 $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"';
1009 // Start assigning vars for main posting page ...
1010 $template->assign_vars(array(
1011 'L_POST_A' => $page_title,
1012 'L_ICON' => $user->lang
['PM_ICON'],
1013 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ?
sprintf($user->lang
['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1015 'SUBJECT' => (isset($message_subject)) ?
$message_subject : '',
1016 'MESSAGE' => $message_text,
1017 'BBCODE_STATUS' => ($bbcode_status) ?
sprintf($user->lang
['BBCODE_IS_ON'], '<a href="' . append_sid('faq', 'mode=bbcode') . '">', '</a>') : sprintf($user->lang
['BBCODE_IS_OFF'], '<a href="' . append_sid('faq', 'mode=bbcode') . '">', '</a>'),
1018 'IMG_STATUS' => ($img_status) ?
$user->lang
['IMAGES_ARE_ON'] : $user->lang
['IMAGES_ARE_OFF'],
1019 'FLASH_STATUS' => ($flash_status) ?
$user->lang
['FLASH_IS_ON'] : $user->lang
['FLASH_IS_OFF'],
1020 'SMILIES_STATUS' => ($smilies_status) ?
$user->lang
['SMILIES_ARE_ON'] : $user->lang
['SMILIES_ARE_OFF'],
1021 'URL_STATUS' => ($url_status) ?
$user->lang
['URL_IS_ON'] : $user->lang
['URL_IS_OFF'],
1022 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang
['PM']),
1023 'ERROR' => (sizeof($error)) ?
implode('<br />', $error) : '',
1024 'MAX_RECIPIENTS' => ($config['allow_mass_pm'] && ($auth->acl_get('u_masspm') ||
$auth->acl_get('u_masspm_group'))) ?
$max_recipients : 0,
1026 'S_COMPOSE_PM' => true,
1027 'S_EDIT_POST' => ($action == 'edit'),
1028 'S_SHOW_PM_ICONS' => $s_pm_icons,
1029 'S_BBCODE_ALLOWED' => $bbcode_status,
1030 'S_BBCODE_CHECKED' => ($bbcode_checked) ?
' checked="checked"' : '',
1031 'S_SMILIES_ALLOWED' => $smilies_status,
1032 'S_SMILIES_CHECKED' => ($smilies_checked) ?
' checked="checked"' : '',
1033 'S_SIG_ALLOWED' => ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')),
1034 'S_SIGNATURE_CHECKED' => ($sig_checked) ?
' checked="checked"' : '',
1035 'S_LINKS_ALLOWED' => $url_status,
1036 'S_MAGIC_URL_CHECKED' => ($urls_checked) ?
' checked="checked"' : '',
1037 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $action != 'edit') ?
true : false,
1038 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $drafts),
1039 'S_FORM_ENCTYPE' => $form_enctype,
1041 'S_BBCODE_IMG' => $img_status,
1042 'S_BBCODE_FLASH' => $flash_status,
1043 'S_BBCODE_QUOTE' => true,
1044 'S_BBCODE_URL' => $url_status,
1046 'S_POST_ACTION' => $s_action,
1047 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field,
1048 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1050 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']),
1051 'U_PROGRESS_BAR' => append_sid('posting', 'f=0&mode=popup'),
1052 'UA_PROGRESS_BAR' => addslashes(append_sid('posting', 'f=0&mode=popup')),
1055 // Build custom bbcodes array
1056 display_custom_bbcodes();
1058 // Show attachment box for adding attachments if true
1059 $allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype);
1062 posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1065 if ($action == 'reply' ||
$action == 'quote' ||
$action == 'forward')
1067 if (message_history($msg_id, $user->data
['user_id'], $post, array(), true))
1069 $template->assign_var('S_DISPLAY_HISTORY', true);
1075 * For composing messages, handle list actions
1077 function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc)
1079 global $auth, $db, $user;
1081 // Delete User [TO/BCC]
1082 if ($remove_u && !empty($_REQUEST['remove_u']) && is_array($_REQUEST['remove_u']))
1084 $remove_user_id = array_keys($_REQUEST['remove_u']);
1086 if (isset($remove_user_id[0]))
1088 unset($address_list['u'][(int) $remove_user_id[0]]);
1092 // Delete Group [TO/BCC]
1093 if ($remove_g && !empty($_REQUEST['remove_g']) && is_array($_REQUEST['remove_g']))
1095 $remove_group_id = array_keys($_REQUEST['remove_g']);
1097 if (isset($remove_group_id[0]))
1099 unset($address_list['g'][(int) $remove_group_id[0]]);
1103 // Add Selected Groups
1104 $group_list = request_var('group_list', array(0));
1106 // Build usernames to add
1107 $usernames = (isset($_REQUEST['username'])) ?
array(request_var('username', '', true)) : array();
1108 $username_list = request_var('username_list', '', true);
1111 $usernames = array_merge($usernames, explode("\n", $username_list));
1114 // If add to or add bcc not pressed, users could still have usernames listed they want to add...
1115 if (!$add_to && !$add_bcc && (sizeof($group_list) ||
sizeof($usernames)))
1119 global $refresh, $submit, $preview;
1121 $refresh = $preview = true;
1125 // Add User/Group [TO]
1126 if ($add_to ||
$add_bcc)
1128 $type = ($add_to) ?
'to' : 'bcc';
1130 if (sizeof($group_list))
1132 foreach ($group_list as $group_id)
1134 $address_list['g'][$group_id] = $type;
1138 // User ID's to add...
1139 $user_id_ary = array();
1141 // Reveal the correct user_ids
1142 if (sizeof($usernames))
1144 $user_id_ary = array();
1145 user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL
, USER_FOUNDER
, USER_INACTIVE
));
1147 // If there are users not existing, we will at least print a notice...
1148 if (!sizeof($user_id_ary))
1150 $error[] = $user->lang
['PM_NO_USERS'];
1154 // Add Friends if specified
1155 $friend_list = (isset($_REQUEST['add_' . $type]) && is_array($_REQUEST['add_' . $type])) ?
array_map('intval', array_keys($_REQUEST['add_' . $type])) : array();
1156 $user_id_ary = array_merge($user_id_ary, $friend_list);
1158 foreach ($user_id_ary as $user_id)
1160 if ($user_id == ANONYMOUS
)
1165 $address_list['u'][$user_id] = $type;
1169 // Check for disallowed recipients
1170 if (!empty($address_list['u']))
1172 // We need to check their PM status (do they want to receive PM's?)
1173 // Only check if not a moderator or admin, since they are allowed to override this user setting
1174 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
1176 $sql = 'SELECT user_id
1177 FROM ' . USERS_TABLE
. '
1178 WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . '
1179 AND user_allow_pm = 0';
1180 $result = $db->sql_query($sql);
1183 while ($row = $db->sql_fetchrow($result))
1186 unset($address_list['u'][$row['user_id']]);
1188 $db->sql_freeresult($result);
1190 // print a notice about users not being added who do not want to receive pms
1193 $error[] = $user->lang
['PM_USERS_REMOVED_NO_PM'];
1200 * Build the hidden field for the recipients. Needed, as the variable is not read via request_var.
1202 function build_address_field($address_list)
1204 $s_hidden_address_field = '';
1205 foreach ($address_list as $type => $adr_ary)
1207 foreach ($adr_ary as $id => $field)
1209 $s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ?
'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ?
'to' : 'bcc') . '" />';
1212 return $s_hidden_address_field;
1216 * Return number of private message recipients
1218 function num_recipients($address_list)
1220 $num_recipients = 0;
1222 foreach ($address_list as $field => $adr_ary)
1224 $num_recipients +
= sizeof($adr_ary);
1227 return $num_recipients;
1231 * Get number of 'num_recipients' recipients from first position
1233 function get_recipients($address_list, $num_recipients = 1)
1235 $recipient = array();
1238 foreach ($address_list as $field => $adr_ary)
1240 foreach ($adr_ary as $id => $type)
1242 if ($count >= $num_recipients)
1246 $recipient[$field][$id] = $type;