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