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

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package ucp
4c79b5
* @version $Id: ucp_main.php 9136 2008-11-30 14:36:59Z 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
* ucp_main
4c79b5
* UCP Front Panel
4c79b5
* @package ucp
4c79b5
*/
4c79b5
class ucp_main
4c79b5
{
4c79b5
	var $p_master;
4c79b5
	var $u_action;
4c79b5
4c79b5
	function ucp_main(&$p_master)
4c79b5
	{
4c79b5
		$this->p_master = &$p_master;
4c79b5
	}
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'front':
4c79b5
4c79b5
				$user->add_lang('memberlist');
4c79b5
4c79b5
				$sql_from = TOPICS_TABLE . ' t ';
4c79b5
				$sql_select = '';
4c79b5
4c79b5
				if ($config['load_db_track'])
4c79b5
				{
4c79b5
					$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
4c79b5
						AND tp.user_id = ' . $user->data['user_id'] . ')';
4c79b5
					$sql_select .= ', tp.topic_posted';
4c79b5
				}
4c79b5
4c79b5
				if ($config['load_db_lastread'])
4c79b5
				{
4c79b5
					$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
4c79b5
						AND tt.user_id = ' . $user->data['user_id'] . ')';
4c79b5
					$sql_select .= ', tt.mark_time';
4c79b5
				}
4c79b5
4c79b5
				$topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
4c79b5
				$folder = 'global_read';
4c79b5
				$folder_new = 'global_unread';
4c79b5
4c79b5
				// Get cleaned up list... return only those forums not having the f_read permission
4c79b5
				$forum_ary = $auth->acl_getf('!f_read', true);
4c79b5
				$forum_ary = array_unique(array_keys($forum_ary));
4c79b5
4c79b5
				// Determine first forum the user is able to read into - for global announcement link
4c79b5
				$sql = 'SELECT forum_id
4c79b5
					FROM ' . FORUMS_TABLE . '
4c79b5
					WHERE forum_type = ' . FORUM_POST;
4c79b5
4c79b5
				if (sizeof($forum_ary))
4c79b5
				{
4c79b5
					$sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
4c79b5
				}
4c79b5
				$result = $db->sql_query_limit($sql, 1);
4c79b5
				$g_forum_id = (int) $db->sql_fetchfield('forum_id');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$sql = "SELECT t.* $sql_select
4c79b5
					FROM $sql_from
4c79b5
					WHERE t.forum_id = 0
4c79b5
						AND t.topic_type = " . POST_GLOBAL . '
4c79b5
					ORDER BY t.topic_last_post_time DESC';
4c79b5
4c79b5
				$topic_list = $rowset = array();
4c79b5
				// If the user can't see any forums, he can't read any posts because fid of 0 is invalid
4c79b5
				if ($g_forum_id)
4c79b5
				{
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$topic_list[] = $row['topic_id'];
4c79b5
						$rowset[$row['topic_id']] = $row;
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				$topic_tracking_info = array();
4c79b5
				if ($config['load_db_lastread'])
4c79b5
				{
4c79b5
					$topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list);
4c79b5
				}
4c79b5
4c79b5
				foreach ($topic_list as $topic_id)
4c79b5
				{
4c79b5
					$row = &$rowset[$topic_id];
4c79b5
4c79b5
					$forum_id = $row['forum_id'];
4c79b5
					$topic_id = $row['topic_id'];
4c79b5
4c79b5
					$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
4c79b5
4c79b5
					$folder_img = ($unread_topic) ? $folder_new : $folder;
4c79b5
					$folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
4c79b5
4c79b5
					if ($row['topic_status'] == ITEM_LOCKED)
4c79b5
					{
4c79b5
						$folder_img .= '_locked';
4c79b5
					}
4c79b5
4c79b5
					// Posted image?
4c79b5
					if (!empty($row['topic_posted']) && $row['topic_posted'])
4c79b5
					{
4c79b5
						$folder_img .= '_mine';
4c79b5
					}
4c79b5
4c79b5
					$template->assign_block_vars('topicrow', array(
4c79b5
						'FORUM_ID'					=> $forum_id,
4c79b5
						'TOPIC_ID'					=> $topic_id,
4c79b5
						'TOPIC_AUTHOR'				=> get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
						'TOPIC_AUTHOR_COLOUR'		=> get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
						'TOPIC_AUTHOR_FULL'			=> get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
						'FIRST_POST_TIME'			=> $user->format_date($row['topic_time']),
4c79b5
						'LAST_POST_SUBJECT'			=> censor_text($row['topic_last_post_subject']),
4c79b5
						'LAST_POST_TIME'			=> $user->format_date($row['topic_last_post_time']),
4c79b5
						'LAST_VIEW_TIME'			=> $user->format_date($row['topic_last_view_time']),
4c79b5
						'LAST_POST_AUTHOR'			=> get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
						'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
						'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
						'TOPIC_TITLE'				=> censor_text($row['topic_title']),
4c79b5
						'TOPIC_TYPE'				=> $topic_type,
4c79b5
4c79b5
						'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
4c79b5
						'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
4c79b5
						'ATTACH_ICON_IMG'		=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
4c79b5
4c79b5
						'S_USER_POSTED'		=> (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
4c79b5
						'S_UNREAD'			=> $unread_topic,
4c79b5
4c79b5
						'U_TOPIC_AUTHOR'		=> get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
						'U_LAST_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&t=$topic_id&p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
4c79b5
						'U_LAST_POST_AUTHOR'	=> get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
						'U_NEWEST_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&t=$topic_id&view=unread") . '#unread',
4c79b5
						'U_VIEW_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&t=$topic_id"))
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
				if ($config['load_user_activity'])
4c79b5
				{
4c79b5
					if (!function_exists('display_user_activity'))
4c79b5
					{
4c79b5
						include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
					}
4c79b5
					display_user_activity($user->data);
4c79b5
				}
4c79b5
4c79b5
				// Do the relevant calculations
4c79b5
				$memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
4c79b5
				$posts_per_day = $user->data['user_posts'] / $memberdays;
4c79b5
				$percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'USER_COLOR'		=> (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
4c79b5
					'JOINED'			=> $user->format_date($user->data['user_regdate']),
4c79b5
					'VISITED'			=> (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
4c79b5
					'WARNINGS'			=> ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
4c79b5
					'POSTS'				=> ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
4c79b5
					'POSTS_DAY'			=> sprintf($user->lang['POST_DAY'], $posts_per_day),
4c79b5
					'POSTS_PCT'			=> sprintf($user->lang['POST_PCT'], $percentage),
4c79b5
4c79b5
					'OCCUPATION'	=> (!empty($row['user_occ'])) ? $row['user_occ'] : '',
4c79b5
					'INTERESTS'		=> (!empty($row['user_interests'])) ? $row['user_interests'] : '',
4c79b5
4c79b5
//					'S_GROUP_OPTIONS'	=> $group_options,
4c79b5
4c79b5
					'U_SEARCH_USER'		=> ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&sr=posts') : '',
4c79b5
				));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'subscribed':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
				$user->add_lang('viewforum');
4c79b5
4c79b5
				add_form_key('ucp_front_subscribed');
4c79b5
4c79b5
				$unwatch = (isset($_POST['unwatch'])) ? true : false;
4c79b5
4c79b5
				if ($unwatch)
4c79b5
				{
4c79b5
					if (check_form_key('ucp_front_subscribed'))
4c79b5
					{
4c79b5
						$forums = array_keys(request_var('f', array(0 => 0)));
4c79b5
						$topics = array_keys(request_var('t', array(0 => 0)));
4c79b5
						$msg = '';
4c79b5
4c79b5
						if (sizeof($forums) || sizeof($topics))
4c79b5
						{
4c79b5
							$l_unwatch = '';
4c79b5
							if (sizeof($forums))
4c79b5
							{
4c79b5
								$sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
4c79b5
									WHERE ' . $db->sql_in_set('forum_id', $forums) . '
4c79b5
										AND user_id = ' . $user->data['user_id'];
4c79b5
								$db->sql_query($sql);
4c79b5
4c79b5
								$l_unwatch .= '_FORUMS';
4c79b5
							}
4c79b5
4c79b5
							if (sizeof($topics))
4c79b5
							{
4c79b5
								$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
4c79b5
									WHERE ' . $db->sql_in_set('topic_id', $topics) . '
4c79b5
										AND user_id = ' . $user->data['user_id'];
4c79b5
								$db->sql_query($sql);
4c79b5
4c79b5
								$l_unwatch .= '_TOPICS';
4c79b5
							}
4c79b5
							$msg = $user->lang['UNWATCHED' . $l_unwatch];
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$msg = $user->lang['NO_WATCHED_SELECTED'];
4c79b5
						}
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$msg = $user->lang['FORM_INVALID'];
4c79b5
					}
4c79b5
					$message = $msg . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
4c79b5
					meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed"));
4c79b5
					trigger_error($message);
4c79b5
				}
4c79b5
4c79b5
				$forbidden_forums = array();
4c79b5
4c79b5
				if ($config['allow_forum_notify'])
4c79b5
				{
4c79b5
					$forbidden_forums = $auth->acl_getf('!f_read', true);
4c79b5
					$forbidden_forums = array_unique(array_keys($forbidden_forums));
4c79b5
4c79b5
					$sql_array = array(
4c79b5
						'SELECT'	=> 'f.*',
4c79b5
4c79b5
						'FROM'		=> array(
4c79b5
							FORUMS_WATCH_TABLE	=> 'fw',
4c79b5
							FORUMS_TABLE		=> 'f'
4c79b5
						),
4c79b5
4c79b5
						'WHERE'		=> 'fw.user_id = ' . $user->data['user_id'] . '
4c79b5
							AND f.forum_id = fw.forum_id
4c79b5
							AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
4c79b5
4c79b5
						'ORDER_BY'	=> 'left_id'
4c79b5
					);
4c79b5
4c79b5
					if ($config['load_db_lastread'])
4c79b5
					{
4c79b5
						$sql_array['LEFT_JOIN'] = array(
4c79b5
							array(
4c79b5
								'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
4c79b5
								'ON'	=> 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
4c79b5
							)
4c79b5
						);
4c79b5
4c79b5
						$sql_array['SELECT'] .= ', ft.mark_time ';
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
4c79b5
						$tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
4c79b5
					}
4c79b5
4c79b5
					$sql = $db->sql_build_query('SELECT', $sql_array);
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$forum_id = $row['forum_id'];
4c79b5
4c79b5
						if ($config['load_db_lastread'])
4c79b5
						{
4c79b5
							$forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$forum_check = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
4c79b5
						}
4c79b5
4c79b5
						$unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
4c79b5
4c79b5
						// Which folder should we display?
4c79b5
						if ($row['forum_status'] == ITEM_LOCKED)
4c79b5
						{
4c79b5
							$folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
4c79b5
							$folder_alt = 'FORUM_LOCKED';
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
4c79b5
							$folder_alt = ($unread_forum) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
4c79b5
						}
4c79b5
4c79b5
						// Create last post link information, if appropriate
4c79b5
						if ($row['forum_last_post_id'])
4c79b5
						{
4c79b5
							$last_post_time = $user->format_date($row['forum_last_post_time']);
4c79b5
							$last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$last_post_time = $last_post_url = '';
4c79b5
						}
4c79b5
4c79b5
						$template->assign_block_vars('forumrow', array(
4c79b5
							'FORUM_ID'				=> $forum_id,
4c79b5
							'FORUM_FOLDER_IMG'		=> $user->img($folder_image, $folder_alt),
4c79b5
							'FORUM_FOLDER_IMG_SRC'	=> $user->img($folder_image, $folder_alt, false, '', 'src'),
4c79b5
							'FORUM_IMAGE'			=> ($row['forum_image']) ? '' . $user->lang[$folder_alt] . '' : '',
4c79b5
							'FORUM_IMAGE_SRC'		=> ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
4c79b5
							'FORUM_NAME'			=> $row['forum_name'],
4c79b5
							'FORUM_DESC'			=> generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
4c79b5
							'LAST_POST_SUBJECT'		=> $row['forum_last_post_subject'],
4c79b5
							'LAST_POST_TIME'		=> $last_post_time,
4c79b5
4c79b5
							'LAST_POST_AUTHOR'			=> get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
4c79b5
							'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
4c79b5
							'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
4c79b5
							'U_LAST_POST_AUTHOR'		=> get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
4c79b5
4c79b5
							'U_LAST_POST'			=> $last_post_url,
4c79b5
							'U_VIEWFORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
4c79b5
						);
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				// Subscribed Topics
4c79b5
				if ($config['allow_topic_notify'])
4c79b5
				{
4c79b5
					if (empty($forbidden_forums))
4c79b5
					{
4c79b5
						$forbidden_forums = $auth->acl_getf('!f_read', true);
4c79b5
						$forbidden_forums = array_unique(array_keys($forbidden_forums));
4c79b5
					}
4c79b5
					$this->assign_topiclist('subscribed', $forbidden_forums);
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_TOPIC_NOTIFY'		=> $config['allow_topic_notify'],
4c79b5
					'S_FORUM_NOTIFY'		=> $config['allow_forum_notify'],
4c79b5
				));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'bookmarks':
4c79b5
4c79b5
				if (!$config['allow_bookmarks'])
4c79b5
				{
4c79b5
					$template->assign_vars(array(
4c79b5
						'S_NO_DISPLAY_BOOKMARKS'	=> true)
4c79b5
					);
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
				$user->add_lang('viewforum');
4c79b5
4c79b5
				if (isset($_POST['unbookmark']))
4c79b5
				{
4c79b5
					$s_hidden_fields = array('unbookmark' => 1);
4c79b5
					$topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
4c79b5
					$url = $this->u_action;
4c79b5
4c79b5
					if (!sizeof($topics))
4c79b5
					{
4c79b5
						trigger_error('NO_BOOKMARKS_SELECTED');
4c79b5
					}
4c79b5
4c79b5
					foreach ($topics as $topic_id)
4c79b5
					{
4c79b5
						$s_hidden_fields['t'][$topic_id] = 1;
4c79b5
					}
4c79b5
4c79b5
					if (confirm_box(true))
4c79b5
					{
4c79b5
						$sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
4c79b5
							WHERE user_id = ' . $user->data['user_id'] . '
4c79b5
								AND ' . $db->sql_in_set('topic_id', $topics);
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						meta_refresh(3, $url);
4c79b5
						$message = $user->lang['BOOKMARKS_REMOVED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
4c79b5
						trigger_error($message);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
4c79b5
					}
4c79b5
				}
4c79b5
				$forbidden_forums = $auth->acl_getf('!f_read', true);
4c79b5
				$forbidden_forums = array_unique(array_keys($forbidden_forums));
4c79b5
4c79b5
				$this->assign_topiclist('bookmarks', $forbidden_forums);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'drafts':
4c79b5
4c79b5
				$pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
4c79b5
				$template->assign_var('S_SHOW_DRAFTS', true);
4c79b5
4c79b5
				$user->add_lang('posting');
4c79b5
4c79b5
				$edit		= (isset($_REQUEST['edit'])) ? true : false;
4c79b5
				$submit		= (isset($_POST['submit'])) ? true : false;
4c79b5
				$draft_id	= ($edit) ? intval($_REQUEST['edit']) : 0;
4c79b5
				$delete		= (isset($_POST['delete'])) ? true : false;
4c79b5
4c79b5
				$s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
4c79b5
				$draft_subject = $draft_message = '';
4c79b5
				add_form_key('ucp_draft');
4c79b5
4c79b5
				if ($delete)
4c79b5
				{
4c79b5
					if (check_form_key('ucp_draft'))
4c79b5
					{
4c79b5
						$drafts = array_keys(request_var('d', array(0 => 0)));
4c79b5
4c79b5
						if (sizeof($drafts))
4c79b5
						{
4c79b5
							$sql = 'DELETE FROM ' . DRAFTS_TABLE . '
4c79b5
								WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
4c79b5
									AND user_id = ' . $user->data['user_id'];
4c79b5
							$db->sql_query($sql);
4c79b5
						}
4c79b5
						$msg = $user->lang['DRAFTS_DELETED'];
4c79b5
						unset($drafts);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$msg = $user->lang['FORM_INVALID'];
4c79b5
					}
4c79b5
					$message = $msg . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
4c79b5
					meta_refresh(3, $this->u_action);
4c79b5
					trigger_error($message);
4c79b5
				}
4c79b5
4c79b5
				if ($submit && $edit)
4c79b5
				{
4c79b5
					$draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
4c79b5
					$draft_message = utf8_normalize_nfc(request_var('message', '', true));
4c79b5
					if (check_form_key('ucp_draft'))
4c79b5
					{
4c79b5
						if ($draft_message && $draft_subject)
4c79b5
						{
4c79b5
							$draft_row = array(
4c79b5
								'draft_subject' => $draft_subject,
4c79b5
								'draft_message' => $draft_message
4c79b5
							);
4c79b5
4c79b5
							$sql = 'UPDATE ' . DRAFTS_TABLE . '
4c79b5
								SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
4c79b5
								WHERE draft_id = $draft_id
4c79b5
									AND user_id = " . $user->data['user_id'];
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							$message = $user->lang['DRAFT_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', '');
4c79b5
4c79b5
							meta_refresh(3, $this->u_action);
4c79b5
							trigger_error($message);
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							$template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
4c79b5
						}
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$template->assign_var('ERROR', $user->lang['FORM_INVALID']);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				if (!$pm_drafts)
4c79b5
				{
4c79b5
					$sql = 'SELECT d.*, f.forum_name
4c79b5
						FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
4c79b5
						WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
4c79b5
							(($edit) ? "AND d.draft_id = $draft_id" : '') . '
4c79b5
							AND f.forum_id = d.forum_id
4c79b5
						ORDER BY d.save_time DESC';
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
4c79b5
						WHERE user_id = ' . $user->data['user_id'] . ' ' .
4c79b5
							(($edit) ? "AND draft_id = $draft_id" : '') . '
4c79b5
							AND forum_id = 0
4c79b5
							AND topic_id = 0
4c79b5
						ORDER BY save_time DESC';
4c79b5
				}
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$draftrows = $topic_ids = array();
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					if ($row['topic_id'])
4c79b5
					{
4c79b5
						$topic_ids[] = (int) $row['topic_id'];
4c79b5
					}
4c79b5
					$draftrows[] = $row;
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if (sizeof($topic_ids))
4c79b5
				{
4c79b5
					$sql = 'SELECT topic_id, forum_id, topic_title
4c79b5
						FROM ' . TOPICS_TABLE . '
4c79b5
						WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$topic_rows[$row['topic_id']] = $row;
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
				unset($topic_ids);
4c79b5
4c79b5
				$template->assign_var('S_EDIT_DRAFT', $edit);
4c79b5
4c79b5
				$row_count = 0;
4c79b5
				foreach ($draftrows as $draft)
4c79b5
				{
4c79b5
					$link_topic = $link_forum = $link_pm = false;
4c79b5
					$insert_url = $view_url = $title = '';
4c79b5
4c79b5
					if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
4c79b5
					{
4c79b5
						$link_topic = true;
4c79b5
						$view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id']);
4c79b5
						$title = $topic_rows[$draft['topic_id']]['topic_title'];
4c79b5
4c79b5
						$insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']);
4c79b5
					}
4c79b5
					else if ($auth->acl_get('f_read', $draft['forum_id']))
4c79b5
					{
4c79b5
						$link_forum = true;
4c79b5
						$view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
4c79b5
						$title = $draft['forum_name'];
4c79b5
4c79b5
						$insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']);
4c79b5
					}
4c79b5
					else if ($pm_drafts)
4c79b5
					{
4c79b5
						$link_pm = true;
4c79b5
						$insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&d=" . $draft['draft_id']);
4c79b5
					}
4c79b5
4c79b5
					$template_row = array(
4c79b5
						'DATE'			=> $user->format_date($draft['save_time']),
4c79b5
						'DRAFT_MESSAGE'	=> ($submit) ? $draft_message : $draft['draft_message'],
4c79b5
						'DRAFT_SUBJECT'	=> ($submit) ? $draft_subject : $draft['draft_subject'],
4c79b5
						'TITLE'			=> $title,
4c79b5
4c79b5
						'DRAFT_ID'	=> $draft['draft_id'],
4c79b5
						'FORUM_ID'	=> $draft['forum_id'],
4c79b5
						'TOPIC_ID'	=> $draft['topic_id'],
4c79b5
4c79b5
						'U_VIEW'		=> $view_url,
4c79b5
						'U_VIEW_EDIT'	=> $this->u_action . '&edit=' . $draft['draft_id'],
4c79b5
						'U_INSERT'		=> $insert_url,
4c79b5
4c79b5
						'S_LINK_TOPIC'		=> $link_topic,
4c79b5
						'S_LINK_FORUM'		=> $link_forum,
4c79b5
						'S_LINK_PM'			=> $link_pm,
4c79b5
						'S_HIDDEN_FIELDS'	=> $s_hidden_fields
4c79b5
					);
4c79b5
					$row_count++;
4c79b5
4c79b5
					($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
4c79b5
				}
4c79b5
4c79b5
				if (!$edit)
4c79b5
				{
4c79b5
					$template->assign_var('S_DRAFT_ROWS', $row_count);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'L_TITLE'			=> $user->lang['UCP_MAIN_' . strtoupper($mode)],
4c79b5
4c79b5
			'S_DISPLAY_MARK_ALL'	=> ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
4c79b5
			'S_HIDDEN_FIELDS'		=> (isset($s_hidden_fields)) ? $s_hidden_fields : '',
4c79b5
			'S_UCP_ACTION'			=> $this->u_action,
4c79b5
4c79b5
			'LAST_POST_IMG'			=> $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
4c79b5
			'NEWEST_POST_IMG'		=> $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
4c79b5
		));
4c79b5
4c79b5
		// Set desired template
4c79b5
		$this->tpl_name = 'ucp_main_' . $mode;
4c79b5
		$this->page_title = 'UCP_MAIN_' . strtoupper($mode);
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Build and assign topiclist for bookmarks/subscribed topics
4c79b5
	*/
4c79b5
	function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
4c79b5
	{
4c79b5
		global $user, $db, $template, $config, $auth, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
		$table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
4c79b5
		$start = request_var('start', 0);
4c79b5
4c79b5
		$sql_array = array(
4c79b5
			'SELECT'	=> 'COUNT(t.topic_id) as topics_count',
4c79b5
4c79b5
			'FROM'		=> array(
4c79b5
				$table			=> 'i',
4c79b5
				TOPICS_TABLE	=> 't'
4c79b5
			),
4c79b5
4c79b5
			'WHERE'		=>	'i.topic_id = t.topic_id
4c79b5
				AND i.user_id = ' . $user->data['user_id'] . '
4c79b5
				AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
4c79b5
		);
4c79b5
		$sql = $db->sql_build_query('SELECT', $sql_array);
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$topics_count = (int) $db->sql_fetchfield('topics_count');
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if ($topics_count)
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'PAGINATION'	=> generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start),
4c79b5
				'PAGE_NUMBER'	=> on_page($topics_count, $config['topics_per_page'], $start),
4c79b5
				'TOTAL_TOPICS'	=> ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		if ($mode == 'subscribed')
4c79b5
		{
4c79b5
			$sql_array = array(
4c79b5
				'SELECT'	=> 't.*, f.forum_name',
4c79b5
4c79b5
				'FROM'		=> array(
4c79b5
					TOPICS_WATCH_TABLE	=> 'tw',
4c79b5
					TOPICS_TABLE		=> 't'
4c79b5
				),
4c79b5
4c79b5
				'WHERE'		=> 'tw.user_id = ' . $user->data['user_id'] . '
4c79b5
					AND t.topic_id = tw.topic_id
4c79b5
					AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
4c79b5
4c79b5
4c79b5
				'ORDER_BY'	=> 't.topic_last_post_time DESC'
4c79b5
			);
4c79b5
4c79b5
			$sql_array['LEFT_JOIN'] = array();
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$sql_array = array(
4c79b5
				'SELECT'	=> 't.*, f.forum_name, b.topic_id as b_topic_id',
4c79b5
4c79b5
				'FROM'		=> array(
4c79b5
					BOOKMARKS_TABLE		=> 'b',
4c79b5
				),
4c79b5
4c79b5
				'WHERE'		=> 'b.user_id = ' . $user->data['user_id'] . '
4c79b5
					AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
4c79b5
4c79b5
				'ORDER_BY'	=> 't.topic_last_post_time DESC'
4c79b5
			);
4c79b5
4c79b5
			$sql_array['LEFT_JOIN'] = array();
4c79b5
			$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
4c79b5
		}
4c79b5
4c79b5
		$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
4c79b5
4c79b5
		if ($config['load_db_lastread'])
4c79b5
		{
4c79b5
			$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
4c79b5
			$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
4c79b5
			$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
4c79b5
		}
4c79b5
4c79b5
		if ($config['load_db_track'])
4c79b5
		{
4c79b5
			$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
4c79b5
			$sql_array['SELECT'] .= ', tp.topic_posted';
4c79b5
		}
4c79b5
4c79b5
		$sql = $db->sql_build_query('SELECT', $sql_array);
4c79b5
		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
		$topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
4c79b5
4c79b5
			$topic_list[] = $topic_id;
4c79b5
			$rowset[$topic_id] = $row;
4c79b5
4c79b5
			$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
4c79b5
			$topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
4c79b5
4c79b5
			if ($row['topic_type'] == POST_GLOBAL)
4c79b5
			{
4c79b5
				$global_announce_list[] = $topic_id;
4c79b5
			}
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$topic_tracking_info = array();
4c79b5
		if ($config['load_db_lastread'])
4c79b5
		{
4c79b5
			foreach ($topic_forum_list as $f_id => $topic_row)
4c79b5
			{
4c79b5
				$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), ($f_id == 0) ? $global_announce_list : false);
4c79b5
			}
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			foreach ($topic_forum_list as $f_id => $topic_row)
4c79b5
			{
4c79b5
				$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		foreach ($topic_list as $topic_id)
4c79b5
		{
4c79b5
			$row = &$rowset[$topic_id];
4c79b5
4c79b5
			$forum_id = $row['forum_id'];
4c79b5
			$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
4c79b5
4c79b5
			$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
4c79b5
4c79b5
			// Replies
4c79b5
			$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
4c79b5
4c79b5
			if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
4c79b5
			{
4c79b5
				$topic_id = $row['topic_moved_id'];
4c79b5
			}
4c79b5
4c79b5
			// Get folder img, topic status/type related information
4c79b5
			$folder_img = $folder_alt = $topic_type = '';
4c79b5
			topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
4c79b5
4c79b5
			$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
4c79b5
4c79b5
			// Send vars to template
4c79b5
			$template->assign_block_vars('topicrow', array(
4c79b5
				'FORUM_ID'					=> $forum_id,
4c79b5
				'TOPIC_ID'					=> $topic_id,
4c79b5
				'FIRST_POST_TIME'			=> $user->format_date($row['topic_time']),
4c79b5
				'LAST_POST_SUBJECT'			=> $row['topic_last_post_subject'],
4c79b5
				'LAST_POST_TIME'			=> $user->format_date($row['topic_last_post_time']),
4c79b5
				'LAST_VIEW_TIME'			=> $user->format_date($row['topic_last_view_time']),
4c79b5
4c79b5
				'TOPIC_AUTHOR'				=> get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
				'TOPIC_AUTHOR_COLOUR'		=> get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
				'TOPIC_AUTHOR_FULL'			=> get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
				'U_TOPIC_AUTHOR'			=> get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
4c79b5
4c79b5
				'LAST_POST_AUTHOR'			=> get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
				'LAST_POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
				'LAST_POST_AUTHOR_FULL'		=> get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
				'U_LAST_POST_AUTHOR'		=> get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
4c79b5
4c79b5
				'S_DELETED_TOPIC'	=> (!$row['topic_id']) ? true : false,
4c79b5
				'S_GLOBAL_TOPIC'	=> (!$forum_id) ? true : false,
4c79b5
4c79b5
				'PAGINATION'		=> topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&t=$topic_id")),
4c79b5
				'REPLIES'			=> $replies,
4c79b5
				'VIEWS'				=> $row['topic_views'],
4c79b5
				'TOPIC_TITLE'		=> censor_text($row['topic_title']),
4c79b5
				'TOPIC_TYPE'		=> $topic_type,
4c79b5
				'FORUM_NAME'		=> $row['forum_name'],
4c79b5
4c79b5
				'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
4c79b5
				'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
4c79b5
				'TOPIC_ICON_IMG'		=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
4c79b5
				'TOPIC_ICON_IMG_WIDTH'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
4c79b5
				'TOPIC_ICON_IMG_HEIGHT'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
4c79b5
				'ATTACH_ICON_IMG'		=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
4c79b5
4c79b5
				'S_TOPIC_TYPE'			=> $row['topic_type'],
4c79b5
				'S_USER_POSTED'			=> (!empty($row['topic_posted'])) ? true : false,
4c79b5
				'S_UNREAD_TOPIC'		=> $unread_topic,
4c79b5
4c79b5
				'U_NEWEST_POST'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=unread") . '#unread',
4c79b5
				'U_LAST_POST'			=> $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
4c79b5
				'U_VIEW_TOPIC'			=> $view_topic_url,
4c79b5
				'U_VIEW_FORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
4c79b5
			));
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>