includes/ucp/ucp_pm.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/ucp/ucp_pm.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,416 @@
     1.4 +<?php
     1.5 +/**
     1.6 +* @package ucp
     1.7 +* @version $Id$
     1.8 +* @copyright (c) 2005 phpBB Group
     1.9 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.10 +*
    1.11 +*/
    1.12 +
    1.13 +/**
    1.14 +* @ignore
    1.15 +*/
    1.16 +if (!defined('IN_PHPBB'))
    1.17 +{
    1.18 +	exit;
    1.19 +}
    1.20 +
    1.21 +/**
    1.22 +* Private Message Class
    1.23 +*
    1.24 +* $_REQUEST['folder'] display folder with the id used
    1.25 +* $_REQUEST['folder'] inbox|outbox|sentbox display folder with the associated name
    1.26 +*
    1.27 +*	Display Messages (default to inbox) - mode=view
    1.28 +*	Display single message - mode=view&p=[msg_id] or &p=[msg_id] (short linkage)
    1.29 +*
    1.30 +*	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
    1.31 +*	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
    1.32 +*	sure the user is able to view the message.
    1.33 +*
    1.34 +*	Composing Messages (mode=compose):
    1.35 +*		To specific user (u=[user_id])
    1.36 +*		To specific group (g=[group_id])
    1.37 +*		Quoting a post (action=quotepost&p=[post_id])
    1.38 +*		Quoting a PM (action=quote&p=[msg_id])
    1.39 +*		Forwarding a PM (action=forward&p=[msg_id])
    1.40 +*
    1.41 +* @package ucp
    1.42 +*/
    1.43 +class ucp_pm
    1.44 +{
    1.45 +	var $u_action;
    1.46 +
    1.47 +	function main($id, $mode)
    1.48 +	{
    1.49 +		global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config;
    1.50 +
    1.51 +		if (!$user->data['is_registered'])
    1.52 +		{
    1.53 +			trigger_error('NO_MESSAGE');
    1.54 +		}
    1.55 +
    1.56 +		// Is PM disabled?
    1.57 +		if (!$config['allow_privmsg'])
    1.58 +		{
    1.59 +			trigger_error('PM_DISABLED');
    1.60 +		}
    1.61 +
    1.62 +		$user->add_lang('posting');
    1.63 +		$template->assign_var('S_PRIVMSGS', true);
    1.64 +
    1.65 +		// Folder directly specified?
    1.66 +		$folder_specified = request_var('folder', '');
    1.67 +
    1.68 +		if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox')))
    1.69 +		{
    1.70 +			$folder_specified = (int) $folder_specified;
    1.71 +		}
    1.72 +		else
    1.73 +		{
    1.74 +			$folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX);
    1.75 +		}
    1.76 +
    1.77 +		if (!$folder_specified)
    1.78 +		{
    1.79 +			$mode = (!$mode) ? request_var('mode', 'view') : $mode;
    1.80 +		}
    1.81 +		else
    1.82 +		{
    1.83 +			$mode = 'view';
    1.84 +		}
    1.85 +
    1.86 +		include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
    1.87 +
    1.88 +		switch ($mode)
    1.89 +		{
    1.90 +			// New private messages popup
    1.91 +			case 'popup':
    1.92 +
    1.93 +				$l_new_message = '';
    1.94 +				if ($user->data['is_registered'])
    1.95 +				{
    1.96 +					if ($user->data['user_new_privmsg'])
    1.97 +					{
    1.98 +						$l_new_message = ($user->data['user_new_privmsg'] == 1) ? $user->lang['YOU_NEW_PM'] : $user->lang['YOU_NEW_PMS'];
    1.99 +					}
   1.100 +					else
   1.101 +					{
   1.102 +						$l_new_message = $user->lang['YOU_NO_NEW_PM'];
   1.103 +					}
   1.104 +				}
   1.105 +
   1.106 +				$template->assign_vars(array(
   1.107 +					'MESSAGE'			=> $l_new_message,
   1.108 +					'S_NOT_LOGGED_IN'	=> ($user->data['user_id'] == ANONYMOUS) ? true : false,
   1.109 +					'CLICK_TO_VIEW'		=> sprintf($user->lang['CLICK_VIEW_PRIVMSG'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox') . '" onclick="jump_to_inbox(this.href); return false;">', '</a>'),
   1.110 +					'U_INBOX'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox'),
   1.111 +					'UA_INBOX'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox', false))
   1.112 +				);
   1.113 +
   1.114 +				$tpl_file = 'ucp_pm_popup';
   1.115 +			break;
   1.116 +
   1.117 +			// Compose message
   1.118 +			case 'compose':
   1.119 +				$action = request_var('action', 'post');
   1.120 +
   1.121 +				$user_folders = get_folder($user->data['user_id']);
   1.122 +
   1.123 +				if (!$auth->acl_get('u_sendpm'))
   1.124 +				{
   1.125 +					// trigger_error('NO_AUTH_SEND_MESSAGE');
   1.126 +					$template->assign_vars(array(
   1.127 +						'S_NO_AUTH_SEND_MESSAGE'	=> true,
   1.128 +						'S_COMPOSE_PM_VIEW'			=> true,
   1.129 +					));
   1.130 +
   1.131 +					$tpl_file = 'ucp_pm_viewfolder';
   1.132 +					break;
   1.133 +				}
   1.134 +
   1.135 +				include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
   1.136 +				compose_pm($id, $mode, $action, $user_folders);
   1.137 +
   1.138 +				$tpl_file = 'posting_body';
   1.139 +			break;
   1.140 +
   1.141 +			case 'options':
   1.142 +				set_user_message_limit();
   1.143 +				get_folder($user->data['user_id']);
   1.144 +
   1.145 +				include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
   1.146 +				message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
   1.147 +
   1.148 +				$tpl_file = 'ucp_pm_options';
   1.149 +			break;
   1.150 +
   1.151 +			case 'drafts':
   1.152 +
   1.153 +				get_folder($user->data['user_id']);
   1.154 +				$this->p_name = 'pm';
   1.155 +
   1.156 +				// Call another module... please do not try this at home... Hoochie Coochie Man
   1.157 +				include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
   1.158 +
   1.159 +				$module = new ucp_main($this);
   1.160 +				$module->u_action = $this->u_action;
   1.161 +				$module->main($id, $mode);
   1.162 +
   1.163 +				$this->tpl_name = $module->tpl_name;
   1.164 +				$this->page_title = 'UCP_PM_DRAFTS';
   1.165 +
   1.166 +				unset($module);
   1.167 +				return;
   1.168 +
   1.169 +			break;
   1.170 +
   1.171 +			case 'view':
   1.172 +
   1.173 +				set_user_message_limit();
   1.174 +
   1.175 +				if ($folder_specified)
   1.176 +				{
   1.177 +					$folder_id = $folder_specified;
   1.178 +					$action = 'view_folder';
   1.179 +				}
   1.180 +				else
   1.181 +				{
   1.182 +					$folder_id = request_var('f', PRIVMSGS_NO_BOX);
   1.183 +					$action = request_var('action', 'view_folder');
   1.184 +				}
   1.185 +
   1.186 +				$msg_id = request_var('p', 0);
   1.187 +				$view	= request_var('view', '');
   1.188 +
   1.189 +				// View message if specified
   1.190 +				if ($msg_id)
   1.191 +				{
   1.192 +					$action = 'view_message';
   1.193 +				}
   1.194 +
   1.195 +				if (!$auth->acl_get('u_readpm'))
   1.196 +				{
   1.197 +					trigger_error('NO_AUTH_READ_MESSAGE');
   1.198 +				}
   1.199 +
   1.200 +				// Do not allow hold messages to be seen
   1.201 +				if ($folder_id == PRIVMSGS_HOLD_BOX)
   1.202 +				{
   1.203 +					trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
   1.204 +				}
   1.205 +
   1.206 +
   1.207 +				// First Handle Mark actions and moving messages
   1.208 +				$submit_mark	= (isset($_POST['submit_mark'])) ? true : false;
   1.209 +				$move_pm		= (isset($_POST['move_pm'])) ? true : false;
   1.210 +				$mark_option	= request_var('mark_option', '');
   1.211 +				$dest_folder	= request_var('dest_folder', PRIVMSGS_NO_BOX);
   1.212 +
   1.213 +				// Is moving PM triggered through mark options?
   1.214 +				if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
   1.215 +				{
   1.216 +					$move_pm = true;
   1.217 +					$dest_folder = (int) $mark_option;
   1.218 +					$submit_mark = false;
   1.219 +				}
   1.220 +
   1.221 +				// Move PM
   1.222 +				if ($move_pm)
   1.223 +				{
   1.224 +					$move_msg_ids	= (isset($_POST['marked_msg_id'])) ? request_var('marked_msg_id', array(0)) : array();
   1.225 +					$cur_folder_id	= request_var('cur_folder_id', PRIVMSGS_NO_BOX);
   1.226 +
   1.227 +					if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
   1.228 +					{
   1.229 +						// Return to folder view if single message moved
   1.230 +						if ($action == 'view_message')
   1.231 +						{
   1.232 +							$msg_id		= 0;
   1.233 +							$folder_id	= request_var('cur_folder_id', PRIVMSGS_NO_BOX);
   1.234 +							$action		= 'view_folder';
   1.235 +						}
   1.236 +					}
   1.237 +				}
   1.238 +
   1.239 +				// Message Mark Options
   1.240 +				if ($submit_mark)
   1.241 +				{
   1.242 +					handle_mark_actions($user->data['user_id'], $mark_option);
   1.243 +				}
   1.244 +
   1.245 +				// If new messages arrived, place them into the appropriate folder
   1.246 +				$num_not_moved = $num_removed = 0;
   1.247 +				$release = request_var('release', 0);
   1.248 +
   1.249 +				if ($user->data['user_new_privmsg'] && ($action == 'view_folder' || $action == 'view_message'))
   1.250 +				{
   1.251 +					$return = place_pm_into_folder($global_privmsgs_rules, $release);
   1.252 +					$num_not_moved = $return['not_moved'];
   1.253 +					$num_removed = $return['removed'];
   1.254 +				}
   1.255 +
   1.256 +				if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
   1.257 +				{
   1.258 +					$folder_id = PRIVMSGS_INBOX;
   1.259 +				}
   1.260 +				else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
   1.261 +				{
   1.262 +					$sql = 'SELECT folder_id
   1.263 +						FROM ' . PRIVMSGS_TO_TABLE . "
   1.264 +						WHERE msg_id = $msg_id
   1.265 +							AND folder_id <> " . PRIVMSGS_NO_BOX . '
   1.266 +							AND user_id = ' . $user->data['user_id'];
   1.267 +					$result = $db->sql_query($sql);
   1.268 +					$row = $db->sql_fetchrow($result);
   1.269 +					$db->sql_freeresult($result);
   1.270 +
   1.271 +					if (!$row)
   1.272 +					{
   1.273 +						trigger_error('NO_MESSAGE');
   1.274 +					}
   1.275 +					$folder_id = (int) $row['folder_id'];
   1.276 +				}
   1.277 +
   1.278 +				$message_row = array();
   1.279 +				if ($action == 'view_message' && $msg_id)
   1.280 +				{
   1.281 +					// Get Message user want to see
   1.282 +					if ($view == 'next' || $view == 'previous')
   1.283 +					{
   1.284 +						$sql_condition = ($view == 'next') ? '>' : '<';
   1.285 +						$sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
   1.286 +
   1.287 +						$sql = 'SELECT t.msg_id
   1.288 +							FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
   1.289 +							WHERE p2.msg_id = $msg_id
   1.290 +								AND t.folder_id = $folder_id
   1.291 +								AND t.user_id = " . $user->data['user_id'] . "
   1.292 +								AND t.msg_id = p.msg_id
   1.293 +								AND p.message_time $sql_condition p2.message_time
   1.294 +							ORDER BY p.message_time $sql_ordering";
   1.295 +						$result = $db->sql_query_limit($sql, 1);
   1.296 +						$row = $db->sql_fetchrow($result);
   1.297 +						$db->sql_freeresult($result);
   1.298 +
   1.299 +						if (!$row)
   1.300 +						{
   1.301 +							$message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
   1.302 +							trigger_error($message);
   1.303 +						}
   1.304 +						else
   1.305 +						{
   1.306 +							$msg_id = $row['msg_id'];
   1.307 +						}
   1.308 +					}
   1.309 +
   1.310 +					$sql = 'SELECT t.*, p.*, u.*
   1.311 +						FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
   1.312 +						WHERE t.user_id = ' . $user->data['user_id'] . "
   1.313 +							AND p.author_id = u.user_id
   1.314 +							AND t.folder_id = $folder_id
   1.315 +							AND t.msg_id = p.msg_id
   1.316 +							AND p.msg_id = $msg_id";
   1.317 +					$result = $db->sql_query($sql);
   1.318 +					$message_row = $db->sql_fetchrow($result);
   1.319 +					$db->sql_freeresult($result);
   1.320 +
   1.321 +					if (!$message_row)
   1.322 +					{
   1.323 +						trigger_error('NO_MESSAGE');
   1.324 +					}
   1.325 +
   1.326 +					// Update unread status
   1.327 +					update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
   1.328 +				}
   1.329 +
   1.330 +				$folder = get_folder($user->data['user_id'], $folder_id);
   1.331 +
   1.332 +				$s_folder_options = $s_to_folder_options = '';
   1.333 +				foreach ($folder as $f_id => $folder_ary)
   1.334 +				{
   1.335 +					$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>';
   1.336 +
   1.337 +					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
   1.338 +					$s_folder_options .= $option;
   1.339 +				}
   1.340 +				clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
   1.341 +
   1.342 +				// Header for message view - folder and so on
   1.343 +				$folder_status = get_folder_status($folder_id, $folder);
   1.344 +
   1.345 +				$template->assign_vars(array(
   1.346 +					'CUR_FOLDER_ID'			=> $folder_id,
   1.347 +					'CUR_FOLDER_NAME'		=> $folder_status['folder_name'],
   1.348 +					'NUM_NOT_MOVED'			=> $num_not_moved,
   1.349 +					'NUM_REMOVED'			=> $num_removed,
   1.350 +					'RELEASE_MESSAGE_INFO'	=> sprintf($user->lang['RELEASE_MESSAGES'], '<a href="' . $this->u_action . '&amp;folder=' . $folder_id . '&amp;release=1">', '</a>'),
   1.351 +					'NOT_MOVED_MESSAGES'	=> ($num_not_moved == 1) ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved),
   1.352 +					'RULE_REMOVED_MESSAGES'	=> ($num_removed == 1) ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed),
   1.353 +
   1.354 +					'S_FOLDER_OPTIONS'		=> $s_folder_options,
   1.355 +					'S_TO_FOLDER_OPTIONS'	=> $s_to_folder_options,
   1.356 +					'S_FOLDER_ACTION'		=> $this->u_action . '&amp;action=view_folder',
   1.357 +					'S_PM_ACTION'			=> $this->u_action . '&amp;action=' . $action,
   1.358 +
   1.359 +					'U_INBOX'				=> $this->u_action . '&amp;folder=inbox',
   1.360 +					'U_OUTBOX'				=> $this->u_action . '&amp;folder=outbox',
   1.361 +					'U_SENTBOX'				=> $this->u_action . '&amp;folder=sentbox',
   1.362 +					'U_CREATE_FOLDER'		=> $this->u_action . '&amp;mode=options',
   1.363 +					'U_CURRENT_FOLDER'		=> $this->u_action . '&amp;folder=' . $folder_id,
   1.364 +
   1.365 +					'S_IN_INBOX'			=> ($folder_id == PRIVMSGS_INBOX) ? true : false,
   1.366 +					'S_IN_OUTBOX'			=> ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
   1.367 +					'S_IN_SENTBOX'			=> ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
   1.368 +
   1.369 +					'FOLDER_STATUS'				=> $folder_status['message'],
   1.370 +					'FOLDER_MAX_MESSAGES'		=> $folder_status['max'],
   1.371 +					'FOLDER_CUR_MESSAGES'		=> $folder_status['cur'],
   1.372 +					'FOLDER_REMAINING_MESSAGES'	=> $folder_status['remaining'],
   1.373 +					'FOLDER_PERCENT'			=> $folder_status['percent'])
   1.374 +				);
   1.375 +
   1.376 +				if ($action == 'view_folder')
   1.377 +				{
   1.378 +					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
   1.379 +					view_folder($id, $mode, $folder_id, $folder);
   1.380 +
   1.381 +					$tpl_file = 'ucp_pm_viewfolder';
   1.382 +				}
   1.383 +				else if ($action == 'view_message')
   1.384 +				{
   1.385 +					$template->assign_vars(array(
   1.386 +						'S_VIEW_MESSAGE'	=> true,
   1.387 +						'MSG_ID'			=> $msg_id)
   1.388 +					);
   1.389 +
   1.390 +					if (!$msg_id)
   1.391 +					{
   1.392 +						trigger_error('NO_MESSAGE');
   1.393 +					}
   1.394 +
   1.395 +					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
   1.396 +					view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
   1.397 +
   1.398 +					$tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
   1.399 +				}
   1.400 +
   1.401 +			break;
   1.402 +
   1.403 +			default:
   1.404 +				trigger_error('NO_ACTION_MODE', E_USER_ERROR);
   1.405 +			break;
   1.406 +		}
   1.407 +
   1.408 +		$template->assign_vars(array(
   1.409 +			'L_TITLE'			=> $user->lang['UCP_PM_' . strtoupper($mode)],
   1.410 +			'S_UCP_ACTION'		=> $this->u_action . ((isset($action)) ? "&amp;action=$action" : ''))
   1.411 +		);
   1.412 +
   1.413 +		// Set desired template
   1.414 +		$this->tpl_name = $tpl_file;
   1.415 +		$this->page_title = 'UCP_PM_' . strtoupper($mode);
   1.416 +	}
   1.417 +}
   1.418 +
   1.419 +?>
   1.420 \ No newline at end of file