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

