source: trunk/forum/includes/ucp/ucp_pm_compose.php

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