[400] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * @package ucp
|
---|
[702] | 4 | * @version $Id$
|
---|
[400] | 5 | * @copyright (c) 2005 phpBB Group
|
---|
| 6 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
| 7 | *
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | /**
|
---|
| 11 | * @ignore
|
---|
| 12 | */
|
---|
| 13 | if (!defined('IN_PHPBB'))
|
---|
| 14 | {
|
---|
| 15 | exit;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * Private Message Class
|
---|
| 20 | *
|
---|
| 21 | * $_REQUEST['folder'] display folder with the id used
|
---|
| 22 | * $_REQUEST['folder'] inbox|outbox|sentbox display folder with the associated name
|
---|
| 23 | *
|
---|
| 24 | * Display Messages (default to inbox) - mode=view
|
---|
| 25 | * Display single message - mode=view&p=[msg_id] or &p=[msg_id] (short linkage)
|
---|
| 26 | *
|
---|
| 27 | * if the folder id with (&f=[folder_id]) is used when displaying messages, one query will be saved. If it is not used, phpBB needs to grab
|
---|
| 28 | * the folder id first in order to display the input boxes and folder names and such things. ;) phpBB always checks this against the database to make
|
---|
| 29 | * sure the user is able to view the message.
|
---|
| 30 | *
|
---|
| 31 | * Composing Messages (mode=compose):
|
---|
| 32 | * To specific user (u=[user_id])
|
---|
| 33 | * To specific group (g=[group_id])
|
---|
| 34 | * Quoting a post (action=quotepost&p=[post_id])
|
---|
| 35 | * Quoting a PM (action=quote&p=[msg_id])
|
---|
| 36 | * Forwarding a PM (action=forward&p=[msg_id])
|
---|
| 37 | *
|
---|
| 38 | * @package ucp
|
---|
| 39 | */
|
---|
| 40 | class ucp_pm
|
---|
| 41 | {
|
---|
| 42 | var $u_action;
|
---|
| 43 |
|
---|
| 44 | function main($id, $mode)
|
---|
| 45 | {
|
---|
| 46 | global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config;
|
---|
| 47 |
|
---|
| 48 | if (!$user->data['is_registered'])
|
---|
| 49 | {
|
---|
| 50 | trigger_error('NO_MESSAGE');
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // Is PM disabled?
|
---|
| 54 | if (!$config['allow_privmsg'])
|
---|
| 55 | {
|
---|
| 56 | trigger_error('PM_DISABLED');
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | $user->add_lang('posting');
|
---|
| 60 | $template->assign_var('S_PRIVMSGS', true);
|
---|
| 61 |
|
---|
| 62 | // Folder directly specified?
|
---|
| 63 | $folder_specified = request_var('folder', '');
|
---|
| 64 |
|
---|
| 65 | if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox')))
|
---|
| 66 | {
|
---|
| 67 | $folder_specified = (int) $folder_specified;
|
---|
| 68 | }
|
---|
| 69 | else
|
---|
| 70 | {
|
---|
| 71 | $folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | if (!$folder_specified)
|
---|
| 75 | {
|
---|
| 76 | $mode = (!$mode) ? request_var('mode', 'view') : $mode;
|
---|
| 77 | }
|
---|
| 78 | else
|
---|
| 79 | {
|
---|
| 80 | $mode = 'view';
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
|
---|
| 84 |
|
---|
| 85 | switch ($mode)
|
---|
| 86 | {
|
---|
| 87 | // New private messages popup
|
---|
| 88 | case 'popup':
|
---|
| 89 |
|
---|
| 90 | $l_new_message = '';
|
---|
| 91 | if ($user->data['is_registered'])
|
---|
| 92 | {
|
---|
| 93 | if ($user->data['user_new_privmsg'])
|
---|
| 94 | {
|
---|
| 95 | $l_new_message = ($user->data['user_new_privmsg'] == 1) ? $user->lang['YOU_NEW_PM'] : $user->lang['YOU_NEW_PMS'];
|
---|
| 96 | }
|
---|
| 97 | else
|
---|
| 98 | {
|
---|
| 99 | $l_new_message = $user->lang['YOU_NO_NEW_PM'];
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | $template->assign_vars(array(
|
---|
| 104 | 'MESSAGE' => $l_new_message,
|
---|
| 105 | 'S_NOT_LOGGED_IN' => ($user->data['user_id'] == ANONYMOUS) ? true : false,
|
---|
| 106 | 'CLICK_TO_VIEW' => sprintf($user->lang['CLICK_VIEW_PRIVMSG'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox') . '" onclick="jump_to_inbox(this.href); return false;">', '</a>'),
|
---|
| 107 | 'U_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'),
|
---|
| 108 | 'UA_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox', false))
|
---|
| 109 | );
|
---|
| 110 |
|
---|
| 111 | $tpl_file = 'ucp_pm_popup';
|
---|
| 112 | break;
|
---|
| 113 |
|
---|
| 114 | // Compose message
|
---|
| 115 | case 'compose':
|
---|
| 116 | $action = request_var('action', 'post');
|
---|
| 117 |
|
---|
| 118 | get_folder($user->data['user_id']);
|
---|
| 119 |
|
---|
| 120 | if (!$auth->acl_get('u_sendpm'))
|
---|
| 121 | {
|
---|
[702] | 122 | // trigger_error('NO_AUTH_SEND_MESSAGE');
|
---|
| 123 | $template->assign_vars(array(
|
---|
| 124 | 'S_NO_AUTH_SEND_MESSAGE' => true,
|
---|
| 125 | 'S_COMPOSE_PM_VIEW' => true,
|
---|
| 126 | ));
|
---|
| 127 |
|
---|
| 128 | $tpl_file = 'ucp_pm_viewfolder';
|
---|
| 129 | break;
|
---|
[400] | 130 | }
|
---|
| 131 |
|
---|
| 132 | include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
|
---|
| 133 | compose_pm($id, $mode, $action);
|
---|
| 134 |
|
---|
| 135 | $tpl_file = 'posting_body';
|
---|
| 136 | break;
|
---|
| 137 |
|
---|
| 138 | case 'options':
|
---|
| 139 | set_user_message_limit();
|
---|
| 140 | get_folder($user->data['user_id']);
|
---|
| 141 |
|
---|
| 142 | include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
|
---|
| 143 | message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
|
---|
| 144 |
|
---|
| 145 | $tpl_file = 'ucp_pm_options';
|
---|
| 146 | break;
|
---|
| 147 |
|
---|
| 148 | case 'drafts':
|
---|
| 149 |
|
---|
| 150 | get_folder($user->data['user_id']);
|
---|
| 151 | $this->p_name = 'pm';
|
---|
| 152 |
|
---|
| 153 | // Call another module... please do not try this at home... Hoochie Coochie Man
|
---|
| 154 | include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
|
---|
| 155 |
|
---|
| 156 | $module = new ucp_main($this);
|
---|
| 157 | $module->u_action = $this->u_action;
|
---|
| 158 | $module->main($id, $mode);
|
---|
| 159 |
|
---|
| 160 | $this->tpl_name = $module->tpl_name;
|
---|
| 161 | $this->page_title = 'UCP_PM_DRAFTS';
|
---|
| 162 |
|
---|
| 163 | unset($module);
|
---|
| 164 | return;
|
---|
| 165 |
|
---|
| 166 | break;
|
---|
| 167 |
|
---|
| 168 | case 'view':
|
---|
| 169 |
|
---|
| 170 | set_user_message_limit();
|
---|
| 171 |
|
---|
| 172 | if ($folder_specified)
|
---|
| 173 | {
|
---|
| 174 | $folder_id = $folder_specified;
|
---|
| 175 | $action = 'view_folder';
|
---|
| 176 | }
|
---|
| 177 | else
|
---|
| 178 | {
|
---|
| 179 | $folder_id = request_var('f', PRIVMSGS_NO_BOX);
|
---|
| 180 | $action = request_var('action', 'view_folder');
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | $msg_id = request_var('p', 0);
|
---|
| 184 | $view = request_var('view', '');
|
---|
| 185 |
|
---|
| 186 | // View message if specified
|
---|
| 187 | if ($msg_id)
|
---|
| 188 | {
|
---|
| 189 | $action = 'view_message';
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | if (!$auth->acl_get('u_readpm'))
|
---|
| 193 | {
|
---|
| 194 | trigger_error('NO_AUTH_READ_MESSAGE');
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | // Do not allow hold messages to be seen
|
---|
| 198 | if ($folder_id == PRIVMSGS_HOLD_BOX)
|
---|
| 199 | {
|
---|
| 200 | trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | // First Handle Mark actions and moving messages
|
---|
| 205 | $submit_mark = (isset($_POST['submit_mark'])) ? true : false;
|
---|
| 206 | $move_pm = (isset($_POST['move_pm'])) ? true : false;
|
---|
| 207 | $mark_option = request_var('mark_option', '');
|
---|
| 208 | $dest_folder = request_var('dest_folder', PRIVMSGS_NO_BOX);
|
---|
| 209 |
|
---|
| 210 | // Is moving PM triggered through mark options?
|
---|
| 211 | if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
|
---|
| 212 | {
|
---|
| 213 | $move_pm = true;
|
---|
| 214 | $dest_folder = (int) $mark_option;
|
---|
| 215 | $submit_mark = false;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | // Move PM
|
---|
| 219 | if ($move_pm)
|
---|
| 220 | {
|
---|
| 221 | $move_msg_ids = (isset($_POST['marked_msg_id'])) ? request_var('marked_msg_id', array(0)) : array();
|
---|
| 222 | $cur_folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
|
---|
| 223 |
|
---|
| 224 | if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
|
---|
| 225 | {
|
---|
| 226 | // Return to folder view if single message moved
|
---|
| 227 | if ($action == 'view_message')
|
---|
| 228 | {
|
---|
| 229 | $msg_id = 0;
|
---|
| 230 | $folder_id = request_var('cur_folder_id', PRIVMSGS_NO_BOX);
|
---|
| 231 | $action = 'view_folder';
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | // Message Mark Options
|
---|
| 237 | if ($submit_mark)
|
---|
| 238 | {
|
---|
| 239 | handle_mark_actions($user->data['user_id'], $mark_option);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | // If new messages arrived, place them into the appropriate folder
|
---|
| 243 | $num_not_moved = $num_removed = 0;
|
---|
| 244 | $release = request_var('release', 0);
|
---|
| 245 |
|
---|
| 246 | if ($user->data['user_new_privmsg'] && $action == 'view_folder')
|
---|
| 247 | {
|
---|
| 248 | $return = place_pm_into_folder($global_privmsgs_rules, $release);
|
---|
| 249 | $num_not_moved = $return['not_moved'];
|
---|
| 250 | $num_removed = $return['removed'];
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
|
---|
| 254 | {
|
---|
| 255 | $folder_id = PRIVMSGS_INBOX;
|
---|
| 256 | }
|
---|
| 257 | else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
|
---|
| 258 | {
|
---|
| 259 | $sql = 'SELECT folder_id
|
---|
| 260 | FROM ' . PRIVMSGS_TO_TABLE . "
|
---|
| 261 | WHERE msg_id = $msg_id
|
---|
| 262 | AND folder_id <> " . PRIVMSGS_NO_BOX . '
|
---|
| 263 | AND user_id = ' . $user->data['user_id'];
|
---|
| 264 | $result = $db->sql_query($sql);
|
---|
| 265 | $row = $db->sql_fetchrow($result);
|
---|
| 266 | $db->sql_freeresult($result);
|
---|
| 267 |
|
---|
| 268 | if (!$row)
|
---|
| 269 | {
|
---|
| 270 | trigger_error('NO_MESSAGE');
|
---|
| 271 | }
|
---|
| 272 | $folder_id = (int) $row['folder_id'];
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | $message_row = array();
|
---|
| 276 | if ($action == 'view_message' && $msg_id)
|
---|
| 277 | {
|
---|
| 278 | // Get Message user want to see
|
---|
| 279 | if ($view == 'next' || $view == 'previous')
|
---|
| 280 | {
|
---|
| 281 | $sql_condition = ($view == 'next') ? '>' : '<';
|
---|
| 282 | $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
|
---|
| 283 |
|
---|
| 284 | $sql = 'SELECT t.msg_id
|
---|
| 285 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
|
---|
| 286 | WHERE p2.msg_id = $msg_id
|
---|
| 287 | AND t.folder_id = $folder_id
|
---|
| 288 | AND t.user_id = " . $user->data['user_id'] . "
|
---|
| 289 | AND t.msg_id = p.msg_id
|
---|
| 290 | AND p.message_time $sql_condition p2.message_time
|
---|
| 291 | ORDER BY p.message_time $sql_ordering";
|
---|
| 292 | $result = $db->sql_query_limit($sql, 1);
|
---|
| 293 | $row = $db->sql_fetchrow($result);
|
---|
| 294 | $db->sql_freeresult($result);
|
---|
| 295 |
|
---|
| 296 | if (!$row)
|
---|
| 297 | {
|
---|
| 298 | $message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
|
---|
| 299 | trigger_error($message);
|
---|
| 300 | }
|
---|
| 301 | else
|
---|
| 302 | {
|
---|
| 303 | $msg_id = $row['msg_id'];
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | $sql = 'SELECT t.*, p.*, u.*
|
---|
| 308 | FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
|
---|
| 309 | WHERE t.user_id = ' . $user->data['user_id'] . "
|
---|
| 310 | AND p.author_id = u.user_id
|
---|
| 311 | AND t.folder_id = $folder_id
|
---|
| 312 | AND t.msg_id = p.msg_id
|
---|
| 313 | AND p.msg_id = $msg_id";
|
---|
| 314 | $result = $db->sql_query($sql);
|
---|
| 315 | $message_row = $db->sql_fetchrow($result);
|
---|
| 316 | $db->sql_freeresult($result);
|
---|
| 317 |
|
---|
| 318 | if (!$message_row)
|
---|
| 319 | {
|
---|
| 320 | trigger_error('NO_MESSAGE');
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | // Update unread status
|
---|
| 324 | update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | $folder = get_folder($user->data['user_id'], $folder_id);
|
---|
| 328 |
|
---|
| 329 | $s_folder_options = $s_to_folder_options = '';
|
---|
| 330 | foreach ($folder as $f_id => $folder_ary)
|
---|
| 331 | {
|
---|
| 332 | $option = '<option' . ((!in_array($f_id, array(PRIVMSGS_INBOX, PRIVMSGS_OUTBOX, PRIVMSGS_SENTBOX))) ? ' class="sep"' : '') . ' value="' . $f_id . '"' . (($f_id == $folder_id) ? ' selected="selected"' : '') . '>' . $folder_ary['folder_name'] . (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
|
---|
| 333 |
|
---|
| 334 | $s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
|
---|
| 335 | $s_folder_options .= $option;
|
---|
| 336 | }
|
---|
| 337 | clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
|
---|
| 338 |
|
---|
| 339 | // Header for message view - folder and so on
|
---|
| 340 | $folder_status = get_folder_status($folder_id, $folder);
|
---|
| 341 |
|
---|
| 342 | $template->assign_vars(array(
|
---|
| 343 | 'CUR_FOLDER_ID' => $folder_id,
|
---|
| 344 | 'CUR_FOLDER_NAME' => $folder_status['folder_name'],
|
---|
| 345 | 'NUM_NOT_MOVED' => $num_not_moved,
|
---|
| 346 | 'NUM_REMOVED' => $num_removed,
|
---|
| 347 | 'RELEASE_MESSAGE_INFO' => sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&folder=' . $folder_id . '&release=1">', '</a>'),
|
---|
| 348 | 'NOT_MOVED_MESSAGES' => ($num_not_moved == 1) ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved),
|
---|
| 349 | 'RULE_REMOVED_MESSAGES' => ($num_removed == 1) ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed),
|
---|
| 350 |
|
---|
| 351 | 'S_FOLDER_OPTIONS' => $s_folder_options,
|
---|
| 352 | 'S_TO_FOLDER_OPTIONS' => $s_to_folder_options,
|
---|
| 353 | 'S_FOLDER_ACTION' => $this->u_action . '&action=view_folder',
|
---|
| 354 | 'S_PM_ACTION' => $this->u_action . '&action=' . $action,
|
---|
| 355 |
|
---|
| 356 | 'U_INBOX' => $this->u_action . '&folder=inbox',
|
---|
| 357 | 'U_OUTBOX' => $this->u_action . '&folder=outbox',
|
---|
| 358 | 'U_SENTBOX' => $this->u_action . '&folder=sentbox',
|
---|
| 359 | 'U_CREATE_FOLDER' => $this->u_action . '&mode=options',
|
---|
| 360 | 'U_CURRENT_FOLDER' => $this->u_action . '&folder=' . $folder_id,
|
---|
| 361 |
|
---|
| 362 | 'S_IN_INBOX' => ($folder_id == PRIVMSGS_INBOX) ? true : false,
|
---|
| 363 | 'S_IN_OUTBOX' => ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
|
---|
| 364 | 'S_IN_SENTBOX' => ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
|
---|
| 365 |
|
---|
| 366 | 'FOLDER_STATUS' => $folder_status['message'],
|
---|
| 367 | 'FOLDER_MAX_MESSAGES' => $folder_status['max'],
|
---|
| 368 | 'FOLDER_CUR_MESSAGES' => $folder_status['cur'],
|
---|
| 369 | 'FOLDER_REMAINING_MESSAGES' => $folder_status['remaining'],
|
---|
| 370 | 'FOLDER_PERCENT' => $folder_status['percent'])
|
---|
| 371 | );
|
---|
| 372 |
|
---|
| 373 | if ($action == 'view_folder')
|
---|
| 374 | {
|
---|
| 375 | include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
|
---|
| 376 | view_folder($id, $mode, $folder_id, $folder);
|
---|
| 377 |
|
---|
| 378 | $tpl_file = 'ucp_pm_viewfolder';
|
---|
| 379 | }
|
---|
| 380 | else if ($action == 'view_message')
|
---|
| 381 | {
|
---|
| 382 | $template->assign_vars(array(
|
---|
| 383 | 'S_VIEW_MESSAGE' => true,
|
---|
| 384 | 'MSG_ID' => $msg_id)
|
---|
| 385 | );
|
---|
| 386 |
|
---|
| 387 | if (!$msg_id)
|
---|
| 388 | {
|
---|
| 389 | trigger_error('NO_MESSAGE');
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
|
---|
| 393 | view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
|
---|
| 394 |
|
---|
| 395 | $tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | break;
|
---|
| 399 |
|
---|
| 400 | default:
|
---|
| 401 | trigger_error('NO_ACTION_MODE', E_USER_ERROR);
|
---|
| 402 | break;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | $template->assign_vars(array(
|
---|
| 406 | 'L_TITLE' => $user->lang['UCP_PM_' . strtoupper($mode)],
|
---|
| 407 | 'S_UCP_ACTION' => $this->u_action . ((isset($action)) ? "&action=$action" : ''))
|
---|
| 408 | );
|
---|
| 409 |
|
---|
| 410 | // Set desired template
|
---|
| 411 | $this->tpl_name = $tpl_file;
|
---|
| 412 | $this->page_title = 'UCP_PM_' . strtoupper($mode);
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | ?>
|
---|