Blame Identity/Webenv/phpBB/3.0.4/includes/ucp/ucp_pm.php

ef5584
ef5584
/**
ef5584
* @package ucp
ef5584
* @version $Id: ucp_pm.php 8521 2008-04-21 13:20:13Z acydburn $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* Private Message Class
ef5584
*
ef5584
* $_REQUEST['folder'] display folder with the id used
ef5584
* $_REQUEST['folder'] inbox|outbox|sentbox display folder with the associated name
ef5584
*
ef5584
*	Display Messages (default to inbox) - mode=view
ef5584
*	Display single message - mode=view&p=[msg_id] or &p=[msg_id] (short linkage)
ef5584
*
ef5584
*	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
ef5584
*	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
ef5584
*	sure the user is able to view the message.
ef5584
*
ef5584
*	Composing Messages (mode=compose):
ef5584
*		To specific user (u=[user_id])
ef5584
*		To specific group (g=[group_id])
ef5584
*		Quoting a post (action=quotepost&p=[post_id])
ef5584
*		Quoting a PM (action=quote&p=[msg_id])
ef5584
*		Forwarding a PM (action=forward&p=[msg_id])
ef5584
*
ef5584
* @package ucp
ef5584
*/
ef5584
class ucp_pm
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config;
ef5584
ef5584
		if (!$user->data['is_registered'])
ef5584
		{
ef5584
			trigger_error('NO_MESSAGE');
ef5584
		}
ef5584
ef5584
		// Is PM disabled?
ef5584
		if (!$config['allow_privmsg'])
ef5584
		{
ef5584
			trigger_error('PM_DISABLED');
ef5584
		}
ef5584
ef5584
		$user->add_lang('posting');
ef5584
		$template->assign_var('S_PRIVMSGS', true);
ef5584
ef5584
		// Folder directly specified?
ef5584
		$folder_specified = request_var('folder', '');
ef5584
ef5584
		if (!in_array($folder_specified, array('inbox', 'outbox', 'sentbox')))
ef5584
		{
ef5584
			$folder_specified = (int) $folder_specified;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$folder_specified = ($folder_specified == 'inbox') ? PRIVMSGS_INBOX : (($folder_specified == 'outbox') ? PRIVMSGS_OUTBOX : PRIVMSGS_SENTBOX);
ef5584
		}
ef5584
ef5584
		if (!$folder_specified)
ef5584
		{
ef5584
			$mode = (!$mode) ? request_var('mode', 'view') : $mode;
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$mode = 'view';
ef5584
		}
ef5584
ef5584
		include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			// New private messages popup
ef5584
			case 'popup':
ef5584
ef5584
				$l_new_message = '';
ef5584
				if ($user->data['is_registered'])
ef5584
				{
ef5584
					if ($user->data['user_new_privmsg'])
ef5584
					{
ef5584
						$l_new_message = ($user->data['user_new_privmsg'] == 1) ? $user->lang['YOU_NEW_PM'] : $user->lang['YOU_NEW_PMS'];
ef5584
					}
ef5584
					else
ef5584
					{
ef5584
						$l_new_message = $user->lang['YOU_NO_NEW_PM'];
ef5584
					}
ef5584
				}
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'MESSAGE'			=> $l_new_message,
ef5584
					'S_NOT_LOGGED_IN'	=> ($user->data['user_id'] == ANONYMOUS) ? true : false,
ef5584
					'CLICK_TO_VIEW'		=> sprintf($user->lang['CLICK_VIEW_PRIVMSG'], '', ''),
ef5584
					'U_INBOX'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'),
ef5584
					'UA_INBOX'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox', false))
ef5584
				);
ef5584
ef5584
				$tpl_file = 'ucp_pm_popup';
ef5584
			break;
ef5584
ef5584
			// Compose message
ef5584
			case 'compose':
ef5584
				$action = request_var('action', 'post');
ef5584
ef5584
				get_folder($user->data['user_id']);
ef5584
ef5584
				if (!$auth->acl_get('u_sendpm'))
ef5584
				{
ef5584
					trigger_error('NO_AUTH_SEND_MESSAGE');
ef5584
				}
ef5584
ef5584
				include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
ef5584
				compose_pm($id, $mode, $action);
ef5584
ef5584
				$tpl_file = 'posting_body';
ef5584
			break;
ef5584
ef5584
			case 'options':
ef5584
				set_user_message_limit();
ef5584
				get_folder($user->data['user_id']);
ef5584
ef5584
				include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
ef5584
				message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
ef5584
ef5584
				$tpl_file = 'ucp_pm_options';
ef5584
			break;
ef5584
ef5584
			case 'drafts':
ef5584
ef5584
				get_folder($user->data['user_id']);
ef5584
				$this->p_name = 'pm';
ef5584
ef5584
				// Call another module... please do not try this at home... Hoochie Coochie Man
ef5584
				include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
ef5584
ef5584
				$module = new ucp_main($this);
ef5584
				$module->u_action = $this->u_action;
ef5584
				$module->main($id, $mode);
ef5584
ef5584
				$this->tpl_name = $module->tpl_name;
ef5584
				$this->page_title = 'UCP_PM_DRAFTS';
ef5584
ef5584
				unset($module);
ef5584
				return;
ef5584
ef5584
			break;
ef5584
ef5584
			case 'view':
ef5584
ef5584
				set_user_message_limit();
ef5584
ef5584
				if ($folder_specified)
ef5584
				{
ef5584
					$folder_id = $folder_specified;
ef5584
					$action = 'view_folder';
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$folder_id = request_var('f', PRIVMSGS_NO_BOX);
ef5584
					$action = request_var('action', 'view_folder');
ef5584
				}
ef5584
ef5584
				$msg_id = request_var('p', 0);
ef5584
				$view	= request_var('view', '');
ef5584
ef5584
				// View message if specified
ef5584
				if ($msg_id)
ef5584
				{
ef5584
					$action = 'view_message';
ef5584
				}
ef5584
ef5584
				if (!$auth->acl_get('u_readpm'))
ef5584
				{
ef5584
					trigger_error('NO_AUTH_READ_MESSAGE');
ef5584
				}
ef5584
ef5584
				// Do not allow hold messages to be seen
ef5584
				if ($folder_id == PRIVMSGS_HOLD_BOX)
ef5584
				{
ef5584
					trigger_error('NO_AUTH_READ_HOLD_MESSAGE');
ef5584
				}
ef5584
ef5584
ef5584
				// First Handle Mark actions and moving messages
ef5584
				$submit_mark	= (isset($_POST['submit_mark'])) ? true : false;
ef5584
				$move_pm		= (isset($_POST['move_pm'])) ? true : false;
ef5584
				$mark_option	= request_var('mark_option', '');
ef5584
				$dest_folder	= request_var('dest_folder', PRIVMSGS_NO_BOX);
ef5584
ef5584
				// Is moving PM triggered through mark options?
ef5584
				if (!in_array($mark_option, array('mark_important', 'delete_marked')) && $submit_mark)
ef5584
				{
ef5584
					$move_pm = true;
ef5584
					$dest_folder = (int) $mark_option;
ef5584
					$submit_mark = false;
ef5584
				}
ef5584
ef5584
				// Move PM
ef5584
				if ($move_pm)
ef5584
				{
ef5584
					$move_msg_ids	= (isset($_POST['marked_msg_id'])) ? request_var('marked_msg_id', array(0)) : array();
ef5584
					$cur_folder_id	= request_var('cur_folder_id', PRIVMSGS_NO_BOX);
ef5584
ef5584
					if (move_pm($user->data['user_id'], $user->data['message_limit'], $move_msg_ids, $dest_folder, $cur_folder_id))
ef5584
					{
ef5584
						// Return to folder view if single message moved
ef5584
						if ($action == 'view_message')
ef5584
						{
ef5584
							$msg_id		= 0;
ef5584
							$folder_id	= request_var('cur_folder_id', PRIVMSGS_NO_BOX);
ef5584
							$action		= 'view_folder';
ef5584
						}
ef5584
					}
ef5584
				}
ef5584
ef5584
				// Message Mark Options
ef5584
				if ($submit_mark)
ef5584
				{
ef5584
					handle_mark_actions($user->data['user_id'], $mark_option);
ef5584
				}
ef5584
ef5584
				// If new messages arrived, place them into the appropriate folder
ef5584
				$num_not_moved = $num_removed = 0;
ef5584
				$release = request_var('release', 0);
ef5584
ef5584
				if ($user->data['user_new_privmsg'] && $action == 'view_folder')
ef5584
				{
ef5584
					$return = place_pm_into_folder($global_privmsgs_rules, $release);
ef5584
					$num_not_moved = $return['not_moved'];
ef5584
					$num_removed = $return['removed'];
ef5584
				}
ef5584
ef5584
				if (!$msg_id && $folder_id == PRIVMSGS_NO_BOX)
ef5584
				{
ef5584
					$folder_id = PRIVMSGS_INBOX;
ef5584
				}
ef5584
				else if ($msg_id && $folder_id == PRIVMSGS_NO_BOX)
ef5584
				{
ef5584
					$sql = 'SELECT folder_id
ef5584
						FROM ' . PRIVMSGS_TO_TABLE . "
ef5584
						WHERE msg_id = $msg_id
ef5584
							AND folder_id <> " . PRIVMSGS_NO_BOX . '
ef5584
							AND user_id = ' . $user->data['user_id'];
ef5584
					$result = $db->sql_query($sql);
ef5584
					$row = $db->sql_fetchrow($result);
ef5584
					$db->sql_freeresult($result);
ef5584
ef5584
					if (!$row)
ef5584
					{
ef5584
						trigger_error('NO_MESSAGE');
ef5584
					}
ef5584
					$folder_id = (int) $row['folder_id'];
ef5584
				}
ef5584
ef5584
				$message_row = array();
ef5584
				if ($action == 'view_message' && $msg_id)
ef5584
				{
ef5584
					// Get Message user want to see
ef5584
					if ($view == 'next' || $view == 'previous')
ef5584
					{
ef5584
						$sql_condition = ($view == 'next') ? '>' : '<';
ef5584
						$sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
ef5584
ef5584
						$sql = 'SELECT t.msg_id
ef5584
							FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TABLE . " p2
ef5584
							WHERE p2.msg_id = $msg_id
ef5584
								AND t.folder_id = $folder_id
ef5584
								AND t.user_id = " . $user->data['user_id'] . "
ef5584
								AND t.msg_id = p.msg_id
ef5584
								AND p.message_time $sql_condition p2.message_time
ef5584
							ORDER BY p.message_time $sql_ordering";
ef5584
						$result = $db->sql_query_limit($sql, 1);
ef5584
						$row = $db->sql_fetchrow($result);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						if (!$row)
ef5584
						{
ef5584
							$message = ($view == 'next') ? 'NO_NEWER_PM' : 'NO_OLDER_PM';
ef5584
							trigger_error($message);
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							$msg_id = $row['msg_id'];
ef5584
						}
ef5584
					}
ef5584
ef5584
					$sql = 'SELECT t.*, p.*, u.*
ef5584
						FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
ef5584
						WHERE t.user_id = ' . $user->data['user_id'] . "
ef5584
							AND p.author_id = u.user_id
ef5584
							AND t.folder_id = $folder_id
ef5584
							AND t.msg_id = p.msg_id
ef5584
							AND p.msg_id = $msg_id";
ef5584
					$result = $db->sql_query($sql);
ef5584
					$message_row = $db->sql_fetchrow($result);
ef5584
					$db->sql_freeresult($result);
ef5584
ef5584
					if (!$message_row)
ef5584
					{
ef5584
						trigger_error('NO_MESSAGE');
ef5584
					}
ef5584
ef5584
					// Update unread status
ef5584
					update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $folder_id);
ef5584
				}
ef5584
ef5584
				$folder = get_folder($user->data['user_id'], $folder_id);
ef5584
ef5584
				$s_folder_options = $s_to_folder_options = '';
ef5584
				foreach ($folder as $f_id => $folder_ary)
ef5584
				{
ef5584
					$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>';
ef5584
ef5584
					$s_to_folder_options .= ($f_id != PRIVMSGS_OUTBOX && $f_id != PRIVMSGS_SENTBOX) ? $option : '';
ef5584
					$s_folder_options .= $option;
ef5584
				}
ef5584
				clean_sentbox($folder[PRIVMSGS_SENTBOX]['num_messages']);
ef5584
ef5584
				// Header for message view - folder and so on
ef5584
				$folder_status = get_folder_status($folder_id, $folder);
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'CUR_FOLDER_ID'			=> $folder_id,
ef5584
					'CUR_FOLDER_NAME'		=> $folder_status['folder_name'],
ef5584
					'NUM_NOT_MOVED'			=> $num_not_moved,
ef5584
					'NUM_REMOVED'			=> $num_removed,
ef5584
					'RELEASE_MESSAGE_INFO'	=> sprintf($user->lang['RELEASE_MESSAGES'], '', ''),
ef5584
					'NOT_MOVED_MESSAGES'	=> ($num_not_moved == 1) ? $user->lang['NOT_MOVED_MESSAGE'] : sprintf($user->lang['NOT_MOVED_MESSAGES'], $num_not_moved),
ef5584
					'RULE_REMOVED_MESSAGES'	=> ($num_removed == 1) ? $user->lang['RULE_REMOVED_MESSAGE'] : sprintf($user->lang['RULE_REMOVED_MESSAGES'], $num_removed),
ef5584
ef5584
					'S_FOLDER_OPTIONS'		=> $s_folder_options,
ef5584
					'S_TO_FOLDER_OPTIONS'	=> $s_to_folder_options,
ef5584
					'S_FOLDER_ACTION'		=> $this->u_action . '&action=view_folder',
ef5584
					'S_PM_ACTION'			=> $this->u_action . '&action=' . $action,
ef5584
ef5584
					'U_INBOX'				=> $this->u_action . '&folder=inbox',
ef5584
					'U_OUTBOX'				=> $this->u_action . '&folder=outbox',
ef5584
					'U_SENTBOX'				=> $this->u_action . '&folder=sentbox',
ef5584
					'U_CREATE_FOLDER'		=> $this->u_action . '&mode=options',
ef5584
					'U_CURRENT_FOLDER'		=> $this->u_action . '&folder=' . $folder_id,
ef5584
ef5584
					'S_IN_INBOX'			=> ($folder_id == PRIVMSGS_INBOX) ? true : false,
ef5584
					'S_IN_OUTBOX'			=> ($folder_id == PRIVMSGS_OUTBOX) ? true : false,
ef5584
					'S_IN_SENTBOX'			=> ($folder_id == PRIVMSGS_SENTBOX) ? true : false,
ef5584
ef5584
					'FOLDER_STATUS'				=> $folder_status['message'],
ef5584
					'FOLDER_MAX_MESSAGES'		=> $folder_status['max'],
ef5584
					'FOLDER_CUR_MESSAGES'		=> $folder_status['cur'],
ef5584
					'FOLDER_REMAINING_MESSAGES'	=> $folder_status['remaining'],
ef5584
					'FOLDER_PERCENT'			=> $folder_status['percent'])
ef5584
				);
ef5584
ef5584
				if ($action == 'view_folder')
ef5584
				{
ef5584
					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
ef5584
					view_folder($id, $mode, $folder_id, $folder);
ef5584
ef5584
					$tpl_file = 'ucp_pm_viewfolder';
ef5584
				}
ef5584
				else if ($action == 'view_message')
ef5584
				{
ef5584
					$template->assign_vars(array(
ef5584
						'S_VIEW_MESSAGE'	=> true,
ef5584
						'MSG_ID'			=> $msg_id)
ef5584
					);
ef5584
ef5584
					if (!$msg_id)
ef5584
					{
ef5584
						trigger_error('NO_MESSAGE');
ef5584
					}
ef5584
ef5584
					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
ef5584
					view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
ef5584
ef5584
					$tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
ef5584
				}
ef5584
ef5584
			break;
ef5584
ef5584
			default:
ef5584
				trigger_error('NO_ACTION_MODE', E_USER_ERROR);
ef5584
			break;
ef5584
		}
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'L_TITLE'			=> $user->lang['UCP_PM_' . strtoupper($mode)],
ef5584
			'S_UCP_ACTION'		=> $this->u_action . ((isset($action)) ? "&action=$action" : ''))
ef5584
		);
ef5584
ef5584
		// Set desired template
ef5584
		$this->tpl_name = $tpl_file;
ef5584
		$this->page_title = 'UCP_PM_' . strtoupper($mode);
ef5584
	}
ef5584
}
ef5584
ef5584
?>