Blame Extras/phpBB/3.0.4/includes/ucp/ucp_pm.php

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