root / branches / phpBB-3_0_0 / phpBB / includes / ucp / ucp_pm_compose.php @ 8620

View | Annotate | Download (35.6 KB)

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