1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/ucp/ucp_pm_compose.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1311 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package ucp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* Compose private message
1.24 +* Called from ucp_pm with mode == 'compose'
1.25 +*/
1.26 +function compose_pm($id, $mode, $action, $user_folders = array())
1.27 +{
1.28 + global $template, $db, $auth, $user;
1.29 + global $phpbb_root_path, $phpEx, $config;
1.30 +
1.31 + // Damn php and globals - i know, this is horrible
1.32 + // Needed for handle_message_list_actions()
1.33 + global $refresh, $submit, $preview;
1.34 +
1.35 + include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1.36 + include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.37 + include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
1.38 +
1.39 + if (!$action)
1.40 + {
1.41 + $action = 'post';
1.42 + }
1.43 + add_form_key('ucp_pm_compose');
1.44 +
1.45 + // Grab only parameters needed here
1.46 + $to_user_id = request_var('u', 0);
1.47 + $to_group_id = request_var('g', 0);
1.48 + $msg_id = request_var('p', 0);
1.49 + $draft_id = request_var('d', 0);
1.50 + $lastclick = request_var('lastclick', 0);
1.51 +
1.52 + // Reply to all triggered (quote/reply)
1.53 + $reply_to_all = request_var('reply_to_all', 0);
1.54 +
1.55 + // Do NOT use request_var or specialchars here
1.56 + $address_list = isset($_REQUEST['address_list']) ? $_REQUEST['address_list'] : array();
1.57 +
1.58 + if (!is_array($address_list))
1.59 + {
1.60 + $address_list = array();
1.61 + }
1.62 +
1.63 + $submit = (isset($_POST['post'])) ? true : false;
1.64 + $preview = (isset($_POST['preview'])) ? true : false;
1.65 + $save = (isset($_POST['save'])) ? true : false;
1.66 + $load = (isset($_POST['load'])) ? true : false;
1.67 + $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
1.68 + $delete = (isset($_POST['delete'])) ? true : false;
1.69 +
1.70 + $remove_u = (isset($_REQUEST['remove_u'])) ? true : false;
1.71 + $remove_g = (isset($_REQUEST['remove_g'])) ? true : false;
1.72 + $add_to = (isset($_REQUEST['add_to'])) ? true : false;
1.73 + $add_bcc = (isset($_REQUEST['add_bcc'])) ? true : false;
1.74 +
1.75 + $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load
1.76 + || $remove_u || $remove_g || $add_to || $add_bcc;
1.77 +
1.78 + $action = ($delete && !$preview && !$refresh && $submit) ? 'delete' : $action;
1.79 + $select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? false : true;
1.80 +
1.81 + $error = array();
1.82 + $current_time = time();
1.83 +
1.84 + // Was cancel pressed? If so then redirect to the appropriate page
1.85 + if ($cancel || ($current_time - $lastclick < 2 && $submit))
1.86 + {
1.87 + if ($msg_id)
1.88 + {
1.89 + redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id));
1.90 + }
1.91 + redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'));
1.92 + }
1.93 +
1.94 + // Since viewtopic.php language entries are used in several modes,
1.95 + // we include the language file here
1.96 + $user->add_lang('viewtopic');
1.97 +
1.98 + // Output PM_TO box if message composing
1.99 + if ($action != 'edit')
1.100 + {
1.101 + // Add groups to PM box
1.102 + if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group'))
1.103 + {
1.104 + $sql = 'SELECT g.group_id, g.group_name, g.group_type
1.105 + FROM ' . GROUPS_TABLE . ' g';
1.106 +
1.107 + if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
1.108 + {
1.109 + $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
1.110 + ON (
1.111 + g.group_id = ug.group_id
1.112 + AND ug.user_id = ' . $user->data['user_id'] . '
1.113 + AND ug.user_pending = 0
1.114 + )
1.115 + WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
1.116 + }
1.117 +
1.118 + $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
1.119 +
1.120 + $sql .= 'g.group_receive_pm = 1
1.121 + ORDER BY g.group_type DESC, g.group_name ASC';
1.122 + $result = $db->sql_query($sql);
1.123 +
1.124 + $group_options = '';
1.125 + while ($row = $db->sql_fetchrow($result))
1.126 + {
1.127 + $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>';
1.128 + }
1.129 + $db->sql_freeresult($result);
1.130 + }
1.131 +
1.132 + $template->assign_vars(array(
1.133 + 'S_SHOW_PM_BOX' => true,
1.134 + 'S_ALLOW_MASS_PM' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? true : false,
1.135 + 'S_GROUP_OPTIONS' => ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) ? $group_options : '',
1.136 + 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&form=postform&field=username_list&select_single=$select_single"),
1.137 + ));
1.138 + }
1.139 +
1.140 + $sql = '';
1.141 + $folder_id = 0;
1.142 +
1.143 + // What is all this following SQL for? Well, we need to know
1.144 + // some basic information in all cases before we do anything.
1.145 + switch ($action)
1.146 + {
1.147 + case 'post':
1.148 + if (!$auth->acl_get('u_sendpm'))
1.149 + {
1.150 + trigger_error('NO_AUTH_SEND_MESSAGE');
1.151 + }
1.152 + break;
1.153 +
1.154 + case 'reply':
1.155 + case 'quote':
1.156 + case 'forward':
1.157 + case 'quotepost':
1.158 + if (!$msg_id)
1.159 + {
1.160 + trigger_error('NO_MESSAGE');
1.161 + }
1.162 +
1.163 + if (!$auth->acl_get('u_sendpm'))
1.164 + {
1.165 + trigger_error('NO_AUTH_SEND_MESSAGE');
1.166 + }
1.167 +
1.168 + if ($action == 'quotepost')
1.169 + {
1.170 + $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
1.171 + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u
1.172 + WHERE p.post_id = $msg_id
1.173 + AND t.topic_id = p.topic_id
1.174 + AND u.user_id = p.poster_id";
1.175 + }
1.176 + else
1.177 + {
1.178 + $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
1.179 + FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
1.180 + WHERE t.user_id = ' . $user->data['user_id'] . "
1.181 + AND p.author_id = u.user_id
1.182 + AND t.msg_id = p.msg_id
1.183 + AND p.msg_id = $msg_id";
1.184 + }
1.185 + break;
1.186 +
1.187 + case 'edit':
1.188 + if (!$msg_id)
1.189 + {
1.190 + trigger_error('NO_MESSAGE');
1.191 + }
1.192 +
1.193 + // check for outbox (not read) status, we do not allow editing if one user already having the message
1.194 + $sql = 'SELECT p.*, t.folder_id
1.195 + FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
1.196 + WHERE t.user_id = ' . $user->data['user_id'] . '
1.197 + AND t.folder_id = ' . PRIVMSGS_OUTBOX . "
1.198 + AND t.msg_id = $msg_id
1.199 + AND t.msg_id = p.msg_id";
1.200 + break;
1.201 +
1.202 + case 'delete':
1.203 + if (!$auth->acl_get('u_pm_delete'))
1.204 + {
1.205 + trigger_error('NO_AUTH_DELETE_MESSAGE');
1.206 + }
1.207 +
1.208 + if (!$msg_id)
1.209 + {
1.210 + trigger_error('NO_MESSAGE');
1.211 + }
1.212 +
1.213 + $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
1.214 + FROM ' . PRIVMSGS_TO_TABLE . '
1.215 + WHERE user_id = ' . $user->data['user_id'] . "
1.216 + AND msg_id = $msg_id";
1.217 + break;
1.218 +
1.219 + case 'smilies':
1.220 + generate_smilies('window', 0);
1.221 + break;
1.222 +
1.223 + default:
1.224 + trigger_error('NO_ACTION_MODE', E_USER_ERROR);
1.225 + break;
1.226 + }
1.227 +
1.228 + if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward')))
1.229 + {
1.230 + trigger_error('NO_AUTH_FORWARD_MESSAGE');
1.231 + }
1.232 +
1.233 + if ($action == 'edit' && !$auth->acl_get('u_pm_edit'))
1.234 + {
1.235 + trigger_error('NO_AUTH_EDIT_MESSAGE');
1.236 + }
1.237 +
1.238 + if ($sql)
1.239 + {
1.240 + $result = $db->sql_query($sql);
1.241 + $post = $db->sql_fetchrow($result);
1.242 + $db->sql_freeresult($result);
1.243 +
1.244 + if (!$post)
1.245 + {
1.246 + // If editing it could be the recipient already read the message...
1.247 + if ($action == 'edit')
1.248 + {
1.249 + $sql = 'SELECT p.*, t.folder_id
1.250 + FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
1.251 + WHERE t.user_id = ' . $user->data['user_id'] . "
1.252 + AND t.msg_id = $msg_id
1.253 + AND t.msg_id = p.msg_id";
1.254 + $result = $db->sql_query($sql);
1.255 + $post = $db->sql_fetchrow($result);
1.256 + $db->sql_freeresult($result);
1.257 +
1.258 + if ($post)
1.259 + {
1.260 + trigger_error('NO_EDIT_READ_MESSAGE');
1.261 + }
1.262 + }
1.263 +
1.264 + trigger_error('NO_MESSAGE');
1.265 + }
1.266 +
1.267 + if ($action == 'quotepost')
1.268 + {
1.269 + if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) || (!$post['forum_id'] && !$auth->acl_getf_global('f_read')))
1.270 + {
1.271 + trigger_error('NOT_AUTHORISED');
1.272 + }
1.273 +
1.274 + // Passworded forum?
1.275 + if ($post['forum_id'])
1.276 + {
1.277 + $sql = 'SELECT forum_password
1.278 + FROM ' . FORUMS_TABLE . '
1.279 + WHERE forum_id = ' . (int) $post['forum_id'];
1.280 + $result = $db->sql_query($sql);
1.281 + $forum_password = (string) $db->sql_fetchfield('forum_password');
1.282 + $db->sql_freeresult($result);
1.283 +
1.284 + if ($forum_password)
1.285 + {
1.286 + login_forum_box(array(
1.287 + 'forum_id' => $post['forum_id'],
1.288 + 'forum_password' => $forum_password,
1.289 + ));
1.290 + }
1.291 + }
1.292 + }
1.293 +
1.294 + $msg_id = (int) $post['msg_id'];
1.295 + $folder_id = (isset($post['folder_id'])) ? $post['folder_id'] : 0;
1.296 + $message_text = (isset($post['message_text'])) ? $post['message_text'] : '';
1.297 +
1.298 + if ((!$post['author_id'] || ($post['author_id'] == ANONYMOUS && $action != 'delete')) && $msg_id)
1.299 + {
1.300 + trigger_error('NO_AUTHOR');
1.301 + }
1.302 +
1.303 + if ($action == 'quotepost')
1.304 + {
1.305 + // Decode text for message display
1.306 + decode_message($message_text, $post['bbcode_uid']);
1.307 + }
1.308 +
1.309 + if ($action != 'delete')
1.310 + {
1.311 + $enable_urls = $post['enable_magic_url'];
1.312 + $enable_sig = (isset($post['enable_sig'])) ? $post['enable_sig'] : 0;
1.313 +
1.314 + $message_attachment = (isset($post['message_attachment'])) ? $post['message_attachment'] : 0;
1.315 + $message_subject = $post['message_subject'];
1.316 + $message_time = $post['message_time'];
1.317 + $bbcode_uid = $post['bbcode_uid'];
1.318 +
1.319 + $quote_username = (isset($post['quote_username'])) ? $post['quote_username'] : '';
1.320 + $icon_id = (isset($post['icon_id'])) ? $post['icon_id'] : 0;
1.321 +
1.322 + if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
1.323 + {
1.324 + // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all"
1.325 + if ($action == 'quotepost' || !$reply_to_all)
1.326 + {
1.327 + $address_list = array('u' => array($post['author_id'] => 'to'));
1.328 + }
1.329 + else
1.330 + {
1.331 + // We try to include every previously listed member from the TO Header - Reply to all
1.332 + $address_list = rebuild_header(array('to' => $post['to_address']));
1.333 +
1.334 + // Add the author (if he is already listed then this is no shame (it will be overwritten))
1.335 + $address_list['u'][$post['author_id']] = 'to';
1.336 +
1.337 + // Now, make sure the user itself is not listed. ;)
1.338 + if (isset($address_list['u'][$user->data['user_id']]))
1.339 + {
1.340 + unset($address_list['u'][$user->data['user_id']]);
1.341 + }
1.342 + }
1.343 + }
1.344 + else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview)
1.345 + {
1.346 + // Rebuild TO and BCC Header
1.347 + $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
1.348 + }
1.349 +
1.350 + if ($action == 'quotepost')
1.351 + {
1.352 + $check_value = 0;
1.353 + }
1.354 + else
1.355 + {
1.356 + $check_value = (($post['enable_bbcode']+1) << 8) + (($post['enable_smilies']+1) << 4) + (($enable_urls+1) << 2) + (($post['enable_sig']+1) << 1);
1.357 + }
1.358 + }
1.359 + }
1.360 + else
1.361 + {
1.362 + $message_attachment = 0;
1.363 + $message_text = $message_subject = '';
1.364 +
1.365 + if ($to_user_id && $action == 'post')
1.366 + {
1.367 + $address_list['u'][$to_user_id] = 'to';
1.368 + }
1.369 + else if ($to_group_id && $action == 'post')
1.370 + {
1.371 + $address_list['g'][$to_group_id] = 'to';
1.372 + }
1.373 + $check_value = 0;
1.374 + }
1.375 +
1.376 + if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')))
1.377 + {
1.378 + trigger_error('NO_AUTH_GROUP_MESSAGE');
1.379 + }
1.380 +
1.381 + if ($action == 'edit' && !$refresh && !$preview && !$submit)
1.382 + {
1.383 + if (!($message_time > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']))
1.384 + {
1.385 + trigger_error('CANNOT_EDIT_MESSAGE_TIME');
1.386 + }
1.387 + }
1.388 +
1.389 + if ($action == 'post')
1.390 + {
1.391 + $template->assign_var('S_NEW_MESSAGE', true);
1.392 + }
1.393 +
1.394 + if (!isset($icon_id))
1.395 + {
1.396 + $icon_id = 0;
1.397 + }
1.398 +
1.399 + $message_parser = new parse_message();
1.400 +
1.401 + $message_parser->message = ($action == 'reply') ? '' : $message_text;
1.402 + unset($message_text);
1.403 +
1.404 + $s_action = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=$mode&action=$action", true, $user->session_id);
1.405 + $s_action .= (($folder_id) ? "&f=$folder_id" : '') . (($msg_id) ? "&p=$msg_id" : '');
1.406 +
1.407 + // Delete triggered ?
1.408 + if ($action == 'delete')
1.409 + {
1.410 + // Folder id has been determined by the SQL Statement
1.411 + // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
1.412 +
1.413 + // Do we need to confirm ?
1.414 + if (confirm_box(true))
1.415 + {
1.416 + delete_pm($user->data['user_id'], $msg_id, $folder_id);
1.417 +
1.418 + // jump to next message in "history"? nope, not for the moment. But able to be included later.
1.419 + $meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&folder=$folder_id");
1.420 + $message = $user->lang['MESSAGE_DELETED'];
1.421 +
1.422 + meta_refresh(3, $meta_info);
1.423 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
1.424 + trigger_error($message);
1.425 + }
1.426 + else
1.427 + {
1.428 + $s_hidden_fields = array(
1.429 + 'p' => $msg_id,
1.430 + 'f' => $folder_id,
1.431 + 'action' => 'delete'
1.432 + );
1.433 +
1.434 + // "{$phpbb_root_path}ucp.$phpEx?i=pm&mode=compose"
1.435 + confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
1.436 + }
1.437 +
1.438 + redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&action=view_message&p=' . $msg_id));
1.439 + }
1.440 +
1.441 + // Get maximum number of allowed recipients
1.442 + $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
1.443 + FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
1.444 + WHERE ug.user_id = ' . $user->data['user_id'] . '
1.445 + AND ug.user_pending = 0
1.446 + AND ug.group_id = g.group_id';
1.447 + $result = $db->sql_query($sql);
1.448 + $max_recipients = (int) $db->sql_fetchfield('max_recipients');
1.449 + $db->sql_freeresult($result);
1.450 +
1.451 + $max_recipients = (!$max_recipients) ? $config['pm_max_recipients'] : $max_recipients;
1.452 +
1.453 + // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
1.454 + if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all)
1.455 + {
1.456 + // We try to include every previously listed member from the TO Header
1.457 + $list = rebuild_header(array('to' => $post['to_address']));
1.458 +
1.459 + // Can be an empty array too ;)
1.460 + $list = (!empty($list['u'])) ? $list['u'] : array();
1.461 + $list[$post['author_id']] = 'to';
1.462 +
1.463 + if (isset($list[$user->data['user_id']]))
1.464 + {
1.465 + unset($list[$user->data['user_id']]);
1.466 + }
1.467 +
1.468 + $max_recipients = ($max_recipients < sizeof($list)) ? sizeof($list) : $max_recipients;
1.469 +
1.470 + unset($list);
1.471 + }
1.472 +
1.473 + // Handle User/Group adding/removing
1.474 + handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
1.475 +
1.476 + // Check mass pm to group permission
1.477 + if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g']))
1.478 + {
1.479 + $address_list = array();
1.480 + $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE'];
1.481 + }
1.482 +
1.483 + // Check mass pm to users permission
1.484 + if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1)
1.485 + {
1.486 + $address_list = get_recipients($address_list, 1);
1.487 + $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
1.488 + }
1.489 +
1.490 + // Check for too many recipients
1.491 + if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients)
1.492 + {
1.493 + $address_list = get_recipients($address_list, $max_recipients);
1.494 + $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
1.495 + }
1.496 +
1.497 + // Always check if the submitted attachment data is valid and belongs to the user.
1.498 + // Further down (especially in submit_post()) we do not check this again.
1.499 + $message_parser->get_submitted_attachment_data();
1.500 +
1.501 + if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit')
1.502 + {
1.503 + // Do not change to SELECT *
1.504 + $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
1.505 + FROM ' . ATTACHMENTS_TABLE . "
1.506 + WHERE post_msg_id = $msg_id
1.507 + AND in_message = 1
1.508 + AND is_orphan = 0
1.509 + ORDER BY filetime DESC";
1.510 + $result = $db->sql_query($sql);
1.511 + $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
1.512 + $db->sql_freeresult($result);
1.513 + }
1.514 +
1.515 + if (!in_array($action, array('quote', 'edit', 'delete', 'forward')))
1.516 + {
1.517 + $enable_sig = ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig'));
1.518 + $enable_smilies = ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies'));
1.519 + $enable_bbcode = ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode'));
1.520 + $enable_urls = true;
1.521 + }
1.522 +
1.523 + $enable_magic_url = $drafts = false;
1.524 +
1.525 + // User own some drafts?
1.526 + if ($auth->acl_get('u_savedrafts') && $action != 'delete')
1.527 + {
1.528 + $sql = 'SELECT draft_id
1.529 + FROM ' . DRAFTS_TABLE . '
1.530 + WHERE forum_id = 0
1.531 + AND topic_id = 0
1.532 + AND user_id = ' . $user->data['user_id'] .
1.533 + (($draft_id) ? " AND draft_id <> $draft_id" : '');
1.534 + $result = $db->sql_query_limit($sql, 1);
1.535 + $row = $db->sql_fetchrow($result);
1.536 + $db->sql_freeresult($result);
1.537 +
1.538 + if ($row)
1.539 + {
1.540 + $drafts = true;
1.541 + }
1.542 + }
1.543 +
1.544 + if ($action == 'edit')
1.545 + {
1.546 + $message_parser->bbcode_uid = $bbcode_uid;
1.547 + }
1.548 +
1.549 + $bbcode_status = ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
1.550 + $smilies_status = ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ? true : false;
1.551 + $img_status = ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ? true : false;
1.552 + $flash_status = ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ? true : false;
1.553 + $url_status = ($config['allow_post_links']) ? true : false;
1.554 +
1.555 + // Save Draft
1.556 + if ($save && $auth->acl_get('u_savedrafts'))
1.557 + {
1.558 + $subject = utf8_normalize_nfc(request_var('subject', '', true));
1.559 + $subject = (!$subject && $action != 'post') ? $user->lang['NEW_MESSAGE'] : $subject;
1.560 + $message = utf8_normalize_nfc(request_var('message', '', true));
1.561 +
1.562 + if ($subject && $message)
1.563 + {
1.564 + if (confirm_box(true))
1.565 + {
1.566 + $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1.567 + 'user_id' => $user->data['user_id'],
1.568 + 'topic_id' => 0,
1.569 + 'forum_id' => 0,
1.570 + 'save_time' => $current_time,
1.571 + 'draft_subject' => $subject,
1.572 + 'draft_message' => $message
1.573 + )
1.574 + );
1.575 + $db->sql_query($sql);
1.576 +
1.577 + $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=$mode");
1.578 +
1.579 + meta_refresh(3, $redirect_url);
1.580 + $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
1.581 +
1.582 + trigger_error($message);
1.583 + }
1.584 + else
1.585 + {
1.586 + $s_hidden_fields = build_hidden_fields(array(
1.587 + 'mode' => $mode,
1.588 + 'action' => $action,
1.589 + 'save' => true,
1.590 + 'subject' => $subject,
1.591 + 'message' => $message,
1.592 + 'u' => $to_user_id,
1.593 + 'g' => $to_group_id,
1.594 + 'p' => $msg_id)
1.595 + );
1.596 + $s_hidden_fields .= build_address_field($address_list);
1.597 +
1.598 +
1.599 + confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
1.600 + }
1.601 + }
1.602 + else
1.603 + {
1.604 + if (utf8_clean_string($subject) === '')
1.605 + {
1.606 + $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
1.607 + }
1.608 +
1.609 + if (utf8_clean_string($message) === '')
1.610 + {
1.611 + $error[] = $user->lang['TOO_FEW_CHARS'];
1.612 + }
1.613 + }
1.614 +
1.615 + unset($subject, $message);
1.616 + }
1.617 +
1.618 + // Load Draft
1.619 + if ($draft_id && $auth->acl_get('u_savedrafts'))
1.620 + {
1.621 + $sql = 'SELECT draft_subject, draft_message
1.622 + FROM ' . DRAFTS_TABLE . "
1.623 + WHERE draft_id = $draft_id
1.624 + AND topic_id = 0
1.625 + AND forum_id = 0
1.626 + AND user_id = " . $user->data['user_id'];
1.627 + $result = $db->sql_query_limit($sql, 1);
1.628 +
1.629 + if ($row = $db->sql_fetchrow($result))
1.630 + {
1.631 + $message_parser->message = $row['draft_message'];
1.632 + $message_subject = $row['draft_subject'];
1.633 +
1.634 + $template->assign_var('S_DRAFT_LOADED', true);
1.635 + }
1.636 + else
1.637 + {
1.638 + $draft_id = 0;
1.639 + }
1.640 + $db->sql_freeresult($result);
1.641 + }
1.642 +
1.643 + // Load Drafts
1.644 + if ($load && $drafts)
1.645 + {
1.646 + load_drafts(0, 0, $id, $action, $msg_id);
1.647 + }
1.648 +
1.649 + if ($submit || $preview || $refresh)
1.650 + {
1.651 + if (($submit || $preview) && !check_form_key('ucp_pm_compose'))
1.652 + {
1.653 + $error[] = $user->lang['FORM_INVALID'];
1.654 + }
1.655 + $subject = utf8_normalize_nfc(request_var('subject', '', true));
1.656 + $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
1.657 +
1.658 + $icon_id = request_var('icon', 0);
1.659 +
1.660 + $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
1.661 + $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
1.662 + $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1;
1.663 + $enable_sig = (!$config['allow_sig'] ||!$config['allow_sig_pm']) ? false : ((isset($_POST['attach_sig'])) ? true : false);
1.664 +
1.665 + if ($submit)
1.666 + {
1.667 + $status_switch = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
1.668 + $status_switch = ($status_switch != $check_value);
1.669 + }
1.670 + else
1.671 + {
1.672 + $status_switch = 1;
1.673 + }
1.674 +
1.675 + // Parse Attachments - before checksum is calculated
1.676 + $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
1.677 +
1.678 + if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
1.679 + {
1.680 + $error[] = implode('<br />', $message_parser->warn_msg);
1.681 + $message_parser->warn_msg = array();
1.682 + }
1.683 +
1.684 + // Parse message
1.685 + $message_parser->parse($enable_bbcode, ($config['allow_post_links']) ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
1.686 +
1.687 + // On a refresh we do not care about message parsing errors
1.688 + if (sizeof($message_parser->warn_msg) && !$refresh)
1.689 + {
1.690 + $error[] = implode('<br />', $message_parser->warn_msg);
1.691 + }
1.692 +
1.693 + if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood'))
1.694 + {
1.695 + // Flood check
1.696 + $last_post_time = $user->data['user_lastpost_time'];
1.697 +
1.698 + if ($last_post_time)
1.699 + {
1.700 + if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
1.701 + {
1.702 + $error[] = $user->lang['FLOOD_ERROR'];
1.703 + }
1.704 + }
1.705 + }
1.706 +
1.707 + // Subject defined
1.708 + if ($submit)
1.709 + {
1.710 + if (utf8_clean_string($subject) === '')
1.711 + {
1.712 + $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
1.713 + }
1.714 +
1.715 + if (!sizeof($address_list))
1.716 + {
1.717 + $error[] = $user->lang['NO_RECIPIENT'];
1.718 + }
1.719 + }
1.720 +
1.721 + // Store message, sync counters
1.722 + if (!sizeof($error) && $submit)
1.723 + {
1.724 + $pm_data = array(
1.725 + 'msg_id' => (int) $msg_id,
1.726 + 'from_user_id' => $user->data['user_id'],
1.727 + 'from_user_ip' => $user->ip,
1.728 + 'from_username' => $user->data['username'],
1.729 + 'reply_from_root_level' => (isset($post['root_level'])) ? (int) $post['root_level'] : 0,
1.730 + 'reply_from_msg_id' => (int) $msg_id,
1.731 + 'icon_id' => (int) $icon_id,
1.732 + 'enable_sig' => (bool) $enable_sig,
1.733 + 'enable_bbcode' => (bool) $enable_bbcode,
1.734 + 'enable_smilies' => (bool) $enable_smilies,
1.735 + 'enable_urls' => (bool) $enable_urls,
1.736 + 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
1.737 + 'bbcode_uid' => $message_parser->bbcode_uid,
1.738 + 'message' => $message_parser->message,
1.739 + 'attachment_data' => $message_parser->attachment_data,
1.740 + 'filename_data' => $message_parser->filename_data,
1.741 + 'address_list' => $address_list
1.742 + );
1.743 +
1.744 + // ((!$message_subject) ? $subject : $message_subject)
1.745 + $msg_id = submit_pm($action, $subject, $pm_data);
1.746 +
1.747 + $return_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=view&p=' . $msg_id);
1.748 + $inbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox');
1.749 + $outbox_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=outbox');
1.750 +
1.751 + $folder_url = '';
1.752 + if (($folder_id > 0) && isset($user_folders[$folder_id]))
1.753 + {
1.754 + $folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=' . $folder_id);
1.755 + }
1.756 +
1.757 + $return_box_url = ($action === 'post' || $action === 'edit') ? $outbox_folder_url : $inbox_folder_url;
1.758 + $return_box_lang = ($action === 'post' || $action === 'edit') ? 'PM_OUTBOX' : 'PM_INBOX';
1.759 +
1.760 +
1.761 + $message = $user->lang['MESSAGE_STORED'] . '<br /><br />' . sprintf($user->lang['VIEW_PRIVATE_MESSAGE'], '<a href="' . $return_message_url . '">', '</a>');
1.762 +
1.763 + $last_click_type = 'CLICK_RETURN_FOLDER';
1.764 + if ($folder_url)
1.765 + {
1.766 + $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $folder_url . '">', '</a>', $user_folders[$folder_id]['folder_name']);
1.767 + $last_click_type = 'CLICK_GOTO_FOLDER';
1.768 + }
1.769 + $message .= '<br /><br />' . sprintf($user->lang[$last_click_type], '<a href="' . $return_box_url . '">', '</a>', $user->lang[$return_box_lang]);
1.770 +
1.771 + meta_refresh(3, $return_message_url);
1.772 + trigger_error($message);
1.773 + }
1.774 +
1.775 + $message_subject = $subject;
1.776 + }
1.777 +
1.778 + // Preview
1.779 + if (!sizeof($error) && $preview)
1.780 + {
1.781 + $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
1.782 +
1.783 + $preview_signature = $user->data['user_sig'];
1.784 + $preview_signature_uid = $user->data['user_sig_bbcode_uid'];
1.785 + $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];
1.786 +
1.787 + // Signature
1.788 + if ($enable_sig && $config['allow_sig'] && $preview_signature)
1.789 + {
1.790 + $parse_sig = new parse_message($preview_signature);
1.791 + $parse_sig->bbcode_uid = $preview_signature_uid;
1.792 + $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1.793 +
1.794 + $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
1.795 + $preview_signature = $parse_sig->message;
1.796 + unset($parse_sig);
1.797 + }
1.798 + else
1.799 + {
1.800 + $preview_signature = '';
1.801 + }
1.802 +
1.803 + // Attachment Preview
1.804 + if (sizeof($message_parser->attachment_data))
1.805 + {
1.806 + $template->assign_var('S_HAS_ATTACHMENTS', true);
1.807 +
1.808 + $update_count = array();
1.809 + $attachment_data = $message_parser->attachment_data;
1.810 +
1.811 + parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
1.812 +
1.813 + foreach ($attachment_data as $i => $attachment)
1.814 + {
1.815 + $template->assign_block_vars('attachment', array(
1.816 + 'DISPLAY_ATTACHMENT' => $attachment)
1.817 + );
1.818 + }
1.819 + unset($attachment_data);
1.820 + }
1.821 +
1.822 + $preview_subject = censor_text($subject);
1.823 +
1.824 + if (!sizeof($error))
1.825 + {
1.826 + $template->assign_vars(array(
1.827 + 'PREVIEW_SUBJECT' => $preview_subject,
1.828 + 'PREVIEW_MESSAGE' => $preview_message,
1.829 + 'PREVIEW_SIGNATURE' => $preview_signature,
1.830 +
1.831 + 'S_DISPLAY_PREVIEW' => true)
1.832 + );
1.833 + }
1.834 + unset($message_text);
1.835 + }
1.836 +
1.837 + // Decode text for message display
1.838 + $bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || (sizeof($error) && !$submit))) ? $bbcode_uid : $message_parser->bbcode_uid;
1.839 +
1.840 + $message_parser->decode_message($bbcode_uid);
1.841 +
1.842 + if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit)
1.843 + {
1.844 + if ($action == 'quotepost')
1.845 + {
1.846 + $post_id = request_var('p', 0);
1.847 + if ($config['allow_post_links'])
1.848 + {
1.849 + $message_link = "[url=" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}: {$message_subject}[/url]\n\n";
1.850 + }
1.851 + else
1.852 + {
1.853 + $message_link = $user->lang['SUBJECT'] . ': ' . $message_subject . " (" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id})\n\n";
1.854 + }
1.855 + }
1.856 + else
1.857 + {
1.858 + $message_link = '';
1.859 + }
1.860 + $message_parser->message = $message_link . '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1.861 + }
1.862 +
1.863 + if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh)
1.864 + {
1.865 + $message_subject = ((!preg_match('/^Re:/', $message_subject)) ? 'Re: ' : '') . censor_text($message_subject);
1.866 + }
1.867 +
1.868 + if ($action == 'forward' && !$preview && !$refresh && !$submit)
1.869 + {
1.870 + $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
1.871 +
1.872 + if ($config['allow_post_links'])
1.873 + {
1.874 + $quote_username_text = '[url=' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']}]{$quote_username}[/url]";
1.875 + }
1.876 + else
1.877 + {
1.878 + $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&u={$post['author_id']})";
1.879 + }
1.880 +
1.881 + $forward_text = array();
1.882 + $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
1.883 + $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
1.884 + $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true));
1.885 + $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
1.886 + $forward_text[] = sprintf($user->lang['FWD_TO'], implode(', ', $fwd_to_field['to']));
1.887 +
1.888 + $message_parser->message = implode("\n", $forward_text) . "\n\n[quote="{$quote_username}"]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
1.889 + $message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject);
1.890 + }
1.891 +
1.892 + $attachment_data = $message_parser->attachment_data;
1.893 + $filename_data = $message_parser->filename_data;
1.894 + $message_text = $message_parser->message;
1.895 +
1.896 + // MAIN PM PAGE BEGINS HERE
1.897 +
1.898 + // Generate smiley listing
1.899 + generate_smilies('inline', 0);
1.900 +
1.901 + // Generate PM Icons
1.902 + $s_pm_icons = false;
1.903 + if ($config['enable_pm_icons'])
1.904 + {
1.905 + $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
1.906 + }
1.907 +
1.908 + // Generate inline attachment select box
1.909 + posting_gen_inline_attachments($attachment_data);
1.910 +
1.911 + // Build address list for display
1.912 + // array('u' => array($author_id => 'to'));
1.913 + if (sizeof($address_list))
1.914 + {
1.915 + // Get Usernames and Group Names
1.916 + $result = array();
1.917 + if (!empty($address_list['u']))
1.918 + {
1.919 + $sql = 'SELECT user_id as id, username as name, user_colour as colour
1.920 + FROM ' . USERS_TABLE . '
1.921 + WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
1.922 + ORDER BY username_clean ASC';
1.923 + $result['u'] = $db->sql_query($sql);
1.924 + }
1.925 +
1.926 + if (!empty($address_list['g']))
1.927 + {
1.928 + $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
1.929 + FROM ' . GROUPS_TABLE . ' g';
1.930 +
1.931 + if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
1.932 + {
1.933 + $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
1.934 + ON (
1.935 + g.group_id = ug.group_id
1.936 + AND ug.user_id = ' . $user->data['user_id'] . '
1.937 + AND ug.user_pending = 0
1.938 + )
1.939 + WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
1.940 + }
1.941 +
1.942 + $sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';
1.943 +
1.944 + $sql .= 'g.group_receive_pm = 1
1.945 + AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
1.946 + ORDER BY g.group_name ASC';
1.947 +
1.948 + $result['g'] = $db->sql_query($sql);
1.949 + }
1.950 +
1.951 + $u = $g = array();
1.952 + $_types = array('u', 'g');
1.953 + foreach ($_types as $type)
1.954 + {
1.955 + if (isset($result[$type]) && $result[$type])
1.956 + {
1.957 + while ($row = $db->sql_fetchrow($result[$type]))
1.958 + {
1.959 + if ($type == 'g')
1.960 + {
1.961 + $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
1.962 + }
1.963 +
1.964 + ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
1.965 + }
1.966 + $db->sql_freeresult($result[$type]);
1.967 + }
1.968 + }
1.969 +
1.970 + // Now Build the address list
1.971 + $plain_address_field = '';
1.972 + foreach ($address_list as $type => $adr_ary)
1.973 + {
1.974 + foreach ($adr_ary as $id => $field)
1.975 + {
1.976 + if (!isset(${$type}[$id]))
1.977 + {
1.978 + unset($address_list[$type][$id]);
1.979 + continue;
1.980 + }
1.981 +
1.982 + $field = ($field == 'to') ? 'to' : 'bcc';
1.983 + $type = ($type == 'u') ? 'u' : 'g';
1.984 + $id = (int) $id;
1.985 +
1.986 + $tpl_ary = array(
1.987 + 'IS_GROUP' => ($type == 'g') ? true : false,
1.988 + 'IS_USER' => ($type == 'u') ? true : false,
1.989 + 'UG_ID' => $id,
1.990 + 'NAME' => ${$type}[$id]['name'],
1.991 + 'COLOUR' => (${$type}[$id]['colour']) ? '#' . ${$type}[$id]['colour'] : '',
1.992 + 'TYPE' => $type,
1.993 + );
1.994 +
1.995 + if ($type == 'u')
1.996 + {
1.997 + $tpl_ary = array_merge($tpl_ary, array(
1.998 + 'U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
1.999 + 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
1.1000 + ));
1.1001 + }
1.1002 + else
1.1003 + {
1.1004 + $tpl_ary = array_merge($tpl_ary, array(
1.1005 + 'U_VIEW' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $id),
1.1006 + ));
1.1007 + }
1.1008 +
1.1009 + $template->assign_block_vars($field . '_recipient', $tpl_ary);
1.1010 + }
1.1011 + }
1.1012 + }
1.1013 +
1.1014 + // Build hidden address list
1.1015 + $s_hidden_address_field = build_address_field($address_list);
1.1016 +
1.1017 +
1.1018 + $bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ? !$user->optionget('bbcode') : 1);
1.1019 + $smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ? !$user->optionget('smilies') : 1);
1.1020 + $urls_checked = (isset($enable_urls)) ? !$enable_urls : 0;
1.1021 + $sig_checked = $enable_sig;
1.1022 +
1.1023 + switch ($action)
1.1024 + {
1.1025 + case 'post':
1.1026 + $page_title = $user->lang['POST_NEW_PM'];
1.1027 + break;
1.1028 +
1.1029 + case 'quote':
1.1030 + $page_title = $user->lang['POST_QUOTE_PM'];
1.1031 + break;
1.1032 +
1.1033 + case 'quotepost':
1.1034 + $page_title = $user->lang['POST_PM_POST'];
1.1035 + break;
1.1036 +
1.1037 + case 'reply':
1.1038 + $page_title = $user->lang['POST_REPLY_PM'];
1.1039 + break;
1.1040 +
1.1041 + case 'edit':
1.1042 + $page_title = $user->lang['POST_EDIT_PM'];
1.1043 + break;
1.1044 +
1.1045 + case 'forward':
1.1046 + $page_title = $user->lang['POST_FORWARD_PM'];
1.1047 + break;
1.1048 +
1.1049 + default:
1.1050 + trigger_error('NO_ACTION_MODE', E_USER_ERROR);
1.1051 + break;
1.1052 + }
1.1053 +
1.1054 + $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1.1055 + $s_hidden_fields .= (isset($check_value)) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
1.1056 + $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) . '" />' : '';
1.1057 +
1.1058 + $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"';
1.1059 +
1.1060 + // Start assigning vars for main posting page ...
1.1061 + $template->assign_vars(array(
1.1062 + 'L_POST_A' => $page_title,
1.1063 + 'L_ICON' => $user->lang['PM_ICON'],
1.1064 + 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1.1065 +
1.1066 + 'SUBJECT' => (isset($message_subject)) ? $message_subject : '',
1.1067 + 'MESSAGE' => $message_text,
1.1068 + '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>'),
1.1069 + 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1.1070 + 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1.1071 + 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1.1072 + 'URL_STATUS' => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1.1073 + 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'],
1.1074 + 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']),
1.1075 + 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1.1076 + 'MAX_RECIPIENTS' => ($config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group'))) ? $max_recipients : 0,
1.1077 +
1.1078 + 'S_COMPOSE_PM' => true,
1.1079 + 'S_EDIT_POST' => ($action == 'edit'),
1.1080 + 'S_SHOW_PM_ICONS' => $s_pm_icons,
1.1081 + 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0,
1.1082 + 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1.1083 + 'S_SMILIES_ALLOWED' => $smilies_status,
1.1084 + 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1.1085 + 'S_SIG_ALLOWED' => ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')),
1.1086 + 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1.1087 + 'S_LINKS_ALLOWED' => $url_status,
1.1088 + 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1.1089 + 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $action != 'edit') ? true : false,
1.1090 + 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $drafts),
1.1091 + 'S_FORM_ENCTYPE' => $form_enctype,
1.1092 +
1.1093 + 'S_BBCODE_IMG' => $img_status,
1.1094 + 'S_BBCODE_FLASH' => $flash_status,
1.1095 + 'S_BBCODE_QUOTE' => true,
1.1096 + 'S_BBCODE_URL' => $url_status,
1.1097 +
1.1098 + 'S_POST_ACTION' => $s_action,
1.1099 + 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field,
1.1100 + 'S_HIDDEN_FIELDS' => $s_hidden_fields,
1.1101 +
1.1102 + 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']),
1.1103 + 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup'),
1.1104 + 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&mode=popup')),
1.1105 + ));
1.1106 +
1.1107 + // Build custom bbcodes array
1.1108 + display_custom_bbcodes();
1.1109 +
1.1110 + // Show attachment box for adding attachments if true
1.1111 + $allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype);
1.1112 +
1.1113 + // Attachment entry
1.1114 + posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1.1115 +
1.1116 + // Message History
1.1117 + if ($action == 'reply' || $action == 'quote' || $action == 'forward')
1.1118 + {
1.1119 + if (message_history($msg_id, $user->data['user_id'], $post, array(), true))
1.1120 + {
1.1121 + $template->assign_var('S_DISPLAY_HISTORY', true);
1.1122 + }
1.1123 + }
1.1124 +}
1.1125 +
1.1126 +/**
1.1127 +* For composing messages, handle list actions
1.1128 +*/
1.1129 +function handle_message_list_actions(&$address_list, &$error, $remove_u, $remove_g, $add_to, $add_bcc)
1.1130 +{
1.1131 + global $auth, $db, $user;
1.1132 +
1.1133 + // Delete User [TO/BCC]
1.1134 + if ($remove_u && !empty($_REQUEST['remove_u']) && is_array($_REQUEST['remove_u']))
1.1135 + {
1.1136 + $remove_user_id = array_keys($_REQUEST['remove_u']);
1.1137 +
1.1138 + if (isset($remove_user_id[0]))
1.1139 + {
1.1140 + unset($address_list['u'][(int) $remove_user_id[0]]);
1.1141 + }
1.1142 + }
1.1143 +
1.1144 + // Delete Group [TO/BCC]
1.1145 + if ($remove_g && !empty($_REQUEST['remove_g']) && is_array($_REQUEST['remove_g']))
1.1146 + {
1.1147 + $remove_group_id = array_keys($_REQUEST['remove_g']);
1.1148 +
1.1149 + if (isset($remove_group_id[0]))
1.1150 + {
1.1151 + unset($address_list['g'][(int) $remove_group_id[0]]);
1.1152 + }
1.1153 + }
1.1154 +
1.1155 + // Add Selected Groups
1.1156 + $group_list = request_var('group_list', array(0));
1.1157 +
1.1158 + // Build usernames to add
1.1159 + $usernames = request_var('username', '', true);
1.1160 + $usernames = (empty($usernames)) ? array() : array($usernames);
1.1161 +
1.1162 + $username_list = request_var('username_list', '', true);
1.1163 + if ($username_list)
1.1164 + {
1.1165 + $usernames = array_merge($usernames, explode("\n", $username_list));
1.1166 + }
1.1167 +
1.1168 + // If add to or add bcc not pressed, users could still have usernames listed they want to add...
1.1169 + if (!$add_to && !$add_bcc && (sizeof($group_list) || sizeof($usernames)))
1.1170 + {
1.1171 + $add_to = true;
1.1172 +
1.1173 + global $refresh, $submit, $preview;
1.1174 +
1.1175 + $refresh = true;
1.1176 + $submit = false;
1.1177 +
1.1178 + // Preview is only true if there was also a message entered
1.1179 + if (request_var('message', ''))
1.1180 + {
1.1181 + $preview = true;
1.1182 + }
1.1183 + }
1.1184 +
1.1185 + // Add User/Group [TO]
1.1186 + if ($add_to || $add_bcc)
1.1187 + {
1.1188 + $type = ($add_to) ? 'to' : 'bcc';
1.1189 +
1.1190 + if (sizeof($group_list))
1.1191 + {
1.1192 + foreach ($group_list as $group_id)
1.1193 + {
1.1194 + $address_list['g'][$group_id] = $type;
1.1195 + }
1.1196 + }
1.1197 +
1.1198 + // User ID's to add...
1.1199 + $user_id_ary = array();
1.1200 +
1.1201 + // Reveal the correct user_ids
1.1202 + if (sizeof($usernames))
1.1203 + {
1.1204 + $user_id_ary = array();
1.1205 + user_get_id_name($user_id_ary, $usernames, array(USER_NORMAL, USER_FOUNDER, USER_INACTIVE));
1.1206 +
1.1207 + // If there are users not existing, we will at least print a notice...
1.1208 + if (!sizeof($user_id_ary))
1.1209 + {
1.1210 + $error[] = $user->lang['PM_NO_USERS'];
1.1211 + }
1.1212 + }
1.1213 +
1.1214 + // Add Friends if specified
1.1215 + $friend_list = (isset($_REQUEST['add_' . $type]) && is_array($_REQUEST['add_' . $type])) ? array_map('intval', array_keys($_REQUEST['add_' . $type])) : array();
1.1216 + $user_id_ary = array_merge($user_id_ary, $friend_list);
1.1217 +
1.1218 + foreach ($user_id_ary as $user_id)
1.1219 + {
1.1220 + if ($user_id == ANONYMOUS)
1.1221 + {
1.1222 + continue;
1.1223 + }
1.1224 +
1.1225 + $address_list['u'][$user_id] = $type;
1.1226 + }
1.1227 + }
1.1228 +
1.1229 + // Check for disallowed recipients
1.1230 + if (!empty($address_list['u']))
1.1231 + {
1.1232 + // We need to check their PM status (do they want to receive PM's?)
1.1233 + // Only check if not a moderator or admin, since they are allowed to override this user setting
1.1234 + if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
1.1235 + {
1.1236 + $sql = 'SELECT user_id
1.1237 + FROM ' . USERS_TABLE . '
1.1238 + WHERE ' . $db->sql_in_set('user_id', array_keys($address_list['u'])) . '
1.1239 + AND user_allow_pm = 0';
1.1240 + $result = $db->sql_query($sql);
1.1241 +
1.1242 + $removed = false;
1.1243 + while ($row = $db->sql_fetchrow($result))
1.1244 + {
1.1245 + $removed = true;
1.1246 + unset($address_list['u'][$row['user_id']]);
1.1247 + }
1.1248 + $db->sql_freeresult($result);
1.1249 +
1.1250 + // print a notice about users not being added who do not want to receive pms
1.1251 + if ($removed)
1.1252 + {
1.1253 + $error[] = $user->lang['PM_USERS_REMOVED_NO_PM'];
1.1254 + }
1.1255 + }
1.1256 + }
1.1257 +}
1.1258 +
1.1259 +/**
1.1260 +* Build the hidden field for the recipients. Needed, as the variable is not read via request_var.
1.1261 +*/
1.1262 +function build_address_field($address_list)
1.1263 +{
1.1264 + $s_hidden_address_field = '';
1.1265 + foreach ($address_list as $type => $adr_ary)
1.1266 + {
1.1267 + foreach ($adr_ary as $id => $field)
1.1268 + {
1.1269 + $s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ? 'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ? 'to' : 'bcc') . '" />';
1.1270 + }
1.1271 + }
1.1272 + return $s_hidden_address_field;
1.1273 +}
1.1274 +
1.1275 +/**
1.1276 +* Return number of private message recipients
1.1277 +*/
1.1278 +function num_recipients($address_list)
1.1279 +{
1.1280 + $num_recipients = 0;
1.1281 +
1.1282 + foreach ($address_list as $field => $adr_ary)
1.1283 + {
1.1284 + $num_recipients += sizeof($adr_ary);
1.1285 + }
1.1286 +
1.1287 + return $num_recipients;
1.1288 +}
1.1289 +
1.1290 +/**
1.1291 +* Get number of 'num_recipients' recipients from first position
1.1292 +*/
1.1293 +function get_recipients($address_list, $num_recipients = 1)
1.1294 +{
1.1295 + $recipient = array();
1.1296 +
1.1297 + $count = 0;
1.1298 + foreach ($address_list as $field => $adr_ary)
1.1299 + {
1.1300 + foreach ($adr_ary as $id => $type)
1.1301 + {
1.1302 + if ($count >= $num_recipients)
1.1303 + {
1.1304 + break 2;
1.1305 + }
1.1306 + $recipient[$field][$id] = $type;
1.1307 + $count++;
1.1308 + }
1.1309 + }
1.1310 +
1.1311 + return $recipient;
1.1312 +}
1.1313 +
1.1314 +?>
1.1315 \ No newline at end of file