1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/ucp/ucp_main.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,835 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package ucp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* ucp_main
1.24 +* UCP Front Panel
1.25 +* @package ucp
1.26 +*/
1.27 +class ucp_main
1.28 +{
1.29 + var $p_master;
1.30 + var $u_action;
1.31 +
1.32 + function ucp_main(&$p_master)
1.33 + {
1.34 + $this->p_master = &$p_master;
1.35 + }
1.36 +
1.37 + function main($id, $mode)
1.38 + {
1.39 + global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
1.40 +
1.41 + switch ($mode)
1.42 + {
1.43 + case 'front':
1.44 +
1.45 + $user->add_lang('memberlist');
1.46 +
1.47 + $sql_from = TOPICS_TABLE . ' t ';
1.48 + $sql_select = '';
1.49 +
1.50 + if ($config['load_db_track'])
1.51 + {
1.52 + $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id
1.53 + AND tp.user_id = ' . $user->data['user_id'] . ')';
1.54 + $sql_select .= ', tp.topic_posted';
1.55 + }
1.56 +
1.57 + if ($config['load_db_lastread'])
1.58 + {
1.59 + $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id
1.60 + AND tt.user_id = ' . $user->data['user_id'] . ')';
1.61 + $sql_select .= ', tt.mark_time';
1.62 + }
1.63 +
1.64 + $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
1.65 + $folder = 'global_read';
1.66 + $folder_new = 'global_unread';
1.67 +
1.68 + // Get cleaned up list... return only those forums not having the f_read permission
1.69 + $forum_ary = $auth->acl_getf('!f_read', true);
1.70 + $forum_ary = array_unique(array_keys($forum_ary));
1.71 +
1.72 + // Determine first forum the user is able to read into - for global announcement link
1.73 + $sql = 'SELECT forum_id
1.74 + FROM ' . FORUMS_TABLE . '
1.75 + WHERE forum_type = ' . FORUM_POST;
1.76 +
1.77 + if (sizeof($forum_ary))
1.78 + {
1.79 + $sql .= ' AND ' . $db->sql_in_set('forum_id', $forum_ary, true);
1.80 + }
1.81 + $result = $db->sql_query_limit($sql, 1);
1.82 + $g_forum_id = (int) $db->sql_fetchfield('forum_id');
1.83 + $db->sql_freeresult($result);
1.84 +
1.85 + $sql = "SELECT t.* $sql_select
1.86 + FROM $sql_from
1.87 + WHERE t.forum_id = 0
1.88 + AND t.topic_type = " . POST_GLOBAL . '
1.89 + ORDER BY t.topic_last_post_time DESC';
1.90 +
1.91 + $topic_list = $rowset = array();
1.92 + // If the user can't see any forums, he can't read any posts because fid of 0 is invalid
1.93 + if ($g_forum_id)
1.94 + {
1.95 + $result = $db->sql_query($sql);
1.96 +
1.97 + while ($row = $db->sql_fetchrow($result))
1.98 + {
1.99 + $topic_list[] = $row['topic_id'];
1.100 + $rowset[$row['topic_id']] = $row;
1.101 + }
1.102 + $db->sql_freeresult($result);
1.103 + }
1.104 +
1.105 + $topic_tracking_info = array();
1.106 + if ($config['load_db_lastread'])
1.107 + {
1.108 + $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list);
1.109 + }
1.110 + else
1.111 + {
1.112 + $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list);
1.113 + }
1.114 +
1.115 + foreach ($topic_list as $topic_id)
1.116 + {
1.117 + $row = &$rowset[$topic_id];
1.118 +
1.119 + $forum_id = $row['forum_id'];
1.120 + $topic_id = $row['topic_id'];
1.121 +
1.122 + $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
1.123 +
1.124 + $folder_img = ($unread_topic) ? $folder_new : $folder;
1.125 + $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
1.126 +
1.127 + if ($row['topic_status'] == ITEM_LOCKED)
1.128 + {
1.129 + $folder_img .= '_locked';
1.130 + }
1.131 +
1.132 + // Posted image?
1.133 + if (!empty($row['topic_posted']) && $row['topic_posted'])
1.134 + {
1.135 + $folder_img .= '_mine';
1.136 + }
1.137 +
1.138 + $template->assign_block_vars('topicrow', array(
1.139 + 'FORUM_ID' => $forum_id,
1.140 + 'TOPIC_ID' => $topic_id,
1.141 + 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.142 + 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.143 + 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.144 + 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
1.145 + 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
1.146 + 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
1.147 + 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
1.148 + 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.149 + 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.150 + 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.151 + 'TOPIC_TITLE' => censor_text($row['topic_title']),
1.152 + 'TOPIC_TYPE' => $topic_type,
1.153 +
1.154 + 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
1.155 + 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
1.156 + 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', '') : '',
1.157 +
1.158 + 'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false,
1.159 + 'S_UNREAD' => $unread_topic,
1.160 +
1.161 + 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.162 + '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'],
1.163 + 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.164 + 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&t=$topic_id&view=unread") . '#unread',
1.165 + 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$g_forum_id&t=$topic_id"))
1.166 + );
1.167 + }
1.168 +
1.169 + if ($config['load_user_activity'])
1.170 + {
1.171 + if (!function_exists('display_user_activity'))
1.172 + {
1.173 + include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.174 + }
1.175 + display_user_activity($user->data);
1.176 + }
1.177 +
1.178 + // Do the relevant calculations
1.179 + $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400));
1.180 + $posts_per_day = $user->data['user_posts'] / $memberdays;
1.181 + $percentage = ($config['num_posts']) ? min(100, ($user->data['user_posts'] / $config['num_posts']) * 100) : 0;
1.182 +
1.183 + $template->assign_vars(array(
1.184 + 'USER_COLOR' => (!empty($user->data['user_colour'])) ? $user->data['user_colour'] : '',
1.185 + 'JOINED' => $user->format_date($user->data['user_regdate']),
1.186 + 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
1.187 + 'WARNINGS' => ($user->data['user_warnings']) ? $user->data['user_warnings'] : 0,
1.188 + 'POSTS' => ($user->data['user_posts']) ? $user->data['user_posts'] : 0,
1.189 + 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day),
1.190 + 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage),
1.191 +
1.192 + 'OCCUPATION' => (!empty($row['user_occ'])) ? $row['user_occ'] : '',
1.193 + 'INTERESTS' => (!empty($row['user_interests'])) ? $row['user_interests'] : '',
1.194 +
1.195 +// 'S_GROUP_OPTIONS' => $group_options,
1.196 +
1.197 + 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&sr=posts') : '',
1.198 + ));
1.199 +
1.200 + break;
1.201 +
1.202 + case 'subscribed':
1.203 +
1.204 + include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.205 +
1.206 + $user->add_lang('viewforum');
1.207 +
1.208 + add_form_key('ucp_front_subscribed');
1.209 +
1.210 + $unwatch = (isset($_POST['unwatch'])) ? true : false;
1.211 +
1.212 + if ($unwatch)
1.213 + {
1.214 + if (check_form_key('ucp_front_subscribed'))
1.215 + {
1.216 + $forums = array_keys(request_var('f', array(0 => 0)));
1.217 + $topics = array_keys(request_var('t', array(0 => 0)));
1.218 + $msg = '';
1.219 +
1.220 + if (sizeof($forums) || sizeof($topics))
1.221 + {
1.222 + $l_unwatch = '';
1.223 + if (sizeof($forums))
1.224 + {
1.225 + $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . '
1.226 + WHERE ' . $db->sql_in_set('forum_id', $forums) . '
1.227 + AND user_id = ' . $user->data['user_id'];
1.228 + $db->sql_query($sql);
1.229 +
1.230 + $l_unwatch .= '_FORUMS';
1.231 + }
1.232 +
1.233 + if (sizeof($topics))
1.234 + {
1.235 + $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
1.236 + WHERE ' . $db->sql_in_set('topic_id', $topics) . '
1.237 + AND user_id = ' . $user->data['user_id'];
1.238 + $db->sql_query($sql);
1.239 +
1.240 + $l_unwatch .= '_TOPICS';
1.241 + }
1.242 + $msg = $user->lang['UNWATCHED' . $l_unwatch];
1.243 + }
1.244 + else
1.245 + {
1.246 + $msg = $user->lang['NO_WATCHED_SELECTED'];
1.247 + }
1.248 + }
1.249 + else
1.250 + {
1.251 + $msg = $user->lang['FORM_INVALID'];
1.252 + }
1.253 + $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed") . '">', '</a>');
1.254 + meta_refresh(3, append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=subscribed"));
1.255 + trigger_error($message);
1.256 + }
1.257 +
1.258 + $forbidden_forums = array();
1.259 +
1.260 + if ($config['allow_forum_notify'])
1.261 + {
1.262 + $forbidden_forums = $auth->acl_getf('!f_read', true);
1.263 + $forbidden_forums = array_unique(array_keys($forbidden_forums));
1.264 +
1.265 + $sql_array = array(
1.266 + 'SELECT' => 'f.*',
1.267 +
1.268 + 'FROM' => array(
1.269 + FORUMS_WATCH_TABLE => 'fw',
1.270 + FORUMS_TABLE => 'f'
1.271 + ),
1.272 +
1.273 + 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
1.274 + AND f.forum_id = fw.forum_id
1.275 + AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true),
1.276 +
1.277 + 'ORDER_BY' => 'left_id'
1.278 + );
1.279 +
1.280 + if ($config['load_db_lastread'])
1.281 + {
1.282 + $sql_array['LEFT_JOIN'] = array(
1.283 + array(
1.284 + 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
1.285 + 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
1.286 + )
1.287 + );
1.288 +
1.289 + $sql_array['SELECT'] .= ', ft.mark_time ';
1.290 + }
1.291 + else
1.292 + {
1.293 + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
1.294 + $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
1.295 + }
1.296 +
1.297 + $sql = $db->sql_build_query('SELECT', $sql_array);
1.298 + $result = $db->sql_query($sql);
1.299 +
1.300 + while ($row = $db->sql_fetchrow($result))
1.301 + {
1.302 + $forum_id = $row['forum_id'];
1.303 +
1.304 + if ($config['load_db_lastread'])
1.305 + {
1.306 + $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
1.307 + }
1.308 + else
1.309 + {
1.310 + $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'];
1.311 + }
1.312 +
1.313 + $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false;
1.314 +
1.315 + // Which folder should we display?
1.316 + if ($row['forum_status'] == ITEM_LOCKED)
1.317 + {
1.318 + $folder_image = ($unread_forum) ? 'forum_unread_locked' : 'forum_read_locked';
1.319 + $folder_alt = 'FORUM_LOCKED';
1.320 + }
1.321 + else
1.322 + {
1.323 + $folder_image = ($unread_forum) ? 'forum_unread' : 'forum_read';
1.324 + $folder_alt = ($unread_forum) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
1.325 + }
1.326 +
1.327 + // Create last post link information, if appropriate
1.328 + if ($row['forum_last_post_id'])
1.329 + {
1.330 + $last_post_time = $user->format_date($row['forum_last_post_time']);
1.331 + $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'];
1.332 + }
1.333 + else
1.334 + {
1.335 + $last_post_time = $last_post_url = '';
1.336 + }
1.337 +
1.338 + $template->assign_block_vars('forumrow', array(
1.339 + 'FORUM_ID' => $forum_id,
1.340 + 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt),
1.341 + 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'),
1.342 + 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
1.343 + 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
1.344 + 'FORUM_NAME' => $row['forum_name'],
1.345 + 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
1.346 + 'LAST_POST_SUBJECT' => $row['forum_last_post_subject'],
1.347 + 'LAST_POST_TIME' => $last_post_time,
1.348 +
1.349 + 'LAST_POST_AUTHOR' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.350 + 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.351 + 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.352 + 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
1.353 +
1.354 + 'U_LAST_POST' => $last_post_url,
1.355 + 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
1.356 + );
1.357 + }
1.358 + $db->sql_freeresult($result);
1.359 + }
1.360 +
1.361 + // Subscribed Topics
1.362 + if ($config['allow_topic_notify'])
1.363 + {
1.364 + if (empty($forbidden_forums))
1.365 + {
1.366 + $forbidden_forums = $auth->acl_getf('!f_read', true);
1.367 + $forbidden_forums = array_unique(array_keys($forbidden_forums));
1.368 + }
1.369 + $this->assign_topiclist('subscribed', $forbidden_forums);
1.370 + }
1.371 +
1.372 + $template->assign_vars(array(
1.373 + 'S_TOPIC_NOTIFY' => $config['allow_topic_notify'],
1.374 + 'S_FORUM_NOTIFY' => $config['allow_forum_notify'],
1.375 + ));
1.376 +
1.377 + break;
1.378 +
1.379 + case 'bookmarks':
1.380 +
1.381 + if (!$config['allow_bookmarks'])
1.382 + {
1.383 + $template->assign_vars(array(
1.384 + 'S_NO_DISPLAY_BOOKMARKS' => true)
1.385 + );
1.386 + break;
1.387 + }
1.388 +
1.389 + include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.390 +
1.391 + $user->add_lang('viewforum');
1.392 +
1.393 + if (isset($_POST['unbookmark']))
1.394 + {
1.395 + $s_hidden_fields = array('unbookmark' => 1);
1.396 + $topics = (isset($_POST['t'])) ? array_keys(request_var('t', array(0 => 0))) : array();
1.397 + $url = $this->u_action;
1.398 +
1.399 + if (!sizeof($topics))
1.400 + {
1.401 + trigger_error('NO_BOOKMARKS_SELECTED');
1.402 + }
1.403 +
1.404 + foreach ($topics as $topic_id)
1.405 + {
1.406 + $s_hidden_fields['t'][$topic_id] = 1;
1.407 + }
1.408 +
1.409 + if (confirm_box(true))
1.410 + {
1.411 + $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . '
1.412 + WHERE user_id = ' . $user->data['user_id'] . '
1.413 + AND ' . $db->sql_in_set('topic_id', $topics);
1.414 + $db->sql_query($sql);
1.415 +
1.416 + meta_refresh(3, $url);
1.417 + $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>');
1.418 + trigger_error($message);
1.419 + }
1.420 + else
1.421 + {
1.422 + confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields));
1.423 + }
1.424 + }
1.425 + $forbidden_forums = $auth->acl_getf('!f_read', true);
1.426 + $forbidden_forums = array_unique(array_keys($forbidden_forums));
1.427 +
1.428 + $this->assign_topiclist('bookmarks', $forbidden_forums);
1.429 +
1.430 + break;
1.431 +
1.432 + case 'drafts':
1.433 +
1.434 + $pm_drafts = ($this->p_master->p_name == 'pm') ? true : false;
1.435 + $template->assign_var('S_SHOW_DRAFTS', true);
1.436 +
1.437 + $user->add_lang('posting');
1.438 +
1.439 + $edit = (isset($_REQUEST['edit'])) ? true : false;
1.440 + $submit = (isset($_POST['submit'])) ? true : false;
1.441 + $draft_id = ($edit) ? intval($_REQUEST['edit']) : 0;
1.442 + $delete = (isset($_POST['delete'])) ? true : false;
1.443 +
1.444 + $s_hidden_fields = ($edit) ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : '';
1.445 + $draft_subject = $draft_message = '';
1.446 + add_form_key('ucp_draft');
1.447 +
1.448 + if ($delete)
1.449 + {
1.450 + if (check_form_key('ucp_draft'))
1.451 + {
1.452 + $drafts = array_keys(request_var('d', array(0 => 0)));
1.453 +
1.454 + if (sizeof($drafts))
1.455 + {
1.456 + $sql = 'DELETE FROM ' . DRAFTS_TABLE . '
1.457 + WHERE ' . $db->sql_in_set('draft_id', $drafts) . '
1.458 + AND user_id = ' . $user->data['user_id'];
1.459 + $db->sql_query($sql);
1.460 + }
1.461 + $msg = $user->lang['DRAFTS_DELETED'];
1.462 + unset($drafts);
1.463 + }
1.464 + else
1.465 + {
1.466 + $msg = $user->lang['FORM_INVALID'];
1.467 + }
1.468 + $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
1.469 + meta_refresh(3, $this->u_action);
1.470 + trigger_error($message);
1.471 + }
1.472 +
1.473 + if ($submit && $edit)
1.474 + {
1.475 + $draft_subject = utf8_normalize_nfc(request_var('subject', '', true));
1.476 + $draft_message = utf8_normalize_nfc(request_var('message', '', true));
1.477 + if (check_form_key('ucp_draft'))
1.478 + {
1.479 + if ($draft_message && $draft_subject)
1.480 + {
1.481 + $draft_row = array(
1.482 + 'draft_subject' => $draft_subject,
1.483 + 'draft_message' => $draft_message
1.484 + );
1.485 +
1.486 + $sql = 'UPDATE ' . DRAFTS_TABLE . '
1.487 + SET ' . $db->sql_build_array('UPDATE', $draft_row) . "
1.488 + WHERE draft_id = $draft_id
1.489 + AND user_id = " . $user->data['user_id'];
1.490 + $db->sql_query($sql);
1.491 +
1.492 + $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
1.493 +
1.494 + meta_refresh(3, $this->u_action);
1.495 + trigger_error($message);
1.496 + }
1.497 + else
1.498 + {
1.499 + $template->assign_var('ERROR', ($draft_message == '') ? $user->lang['EMPTY_DRAFT'] : (($draft_subject == '') ? $user->lang['EMPTY_DRAFT_TITLE'] : ''));
1.500 + }
1.501 + }
1.502 + else
1.503 + {
1.504 + $template->assign_var('ERROR', $user->lang['FORM_INVALID']);
1.505 + }
1.506 + }
1.507 +
1.508 + if (!$pm_drafts)
1.509 + {
1.510 + $sql = 'SELECT d.*, f.forum_name
1.511 + FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f
1.512 + WHERE d.user_id = ' . $user->data['user_id'] . ' ' .
1.513 + (($edit) ? "AND d.draft_id = $draft_id" : '') . '
1.514 + AND f.forum_id = d.forum_id
1.515 + ORDER BY d.save_time DESC';
1.516 + }
1.517 + else
1.518 + {
1.519 + $sql = 'SELECT * FROM ' . DRAFTS_TABLE . '
1.520 + WHERE user_id = ' . $user->data['user_id'] . ' ' .
1.521 + (($edit) ? "AND draft_id = $draft_id" : '') . '
1.522 + AND forum_id = 0
1.523 + AND topic_id = 0
1.524 + ORDER BY save_time DESC';
1.525 + }
1.526 + $result = $db->sql_query($sql);
1.527 +
1.528 + $draftrows = $topic_ids = array();
1.529 +
1.530 + while ($row = $db->sql_fetchrow($result))
1.531 + {
1.532 + if ($row['topic_id'])
1.533 + {
1.534 + $topic_ids[] = (int) $row['topic_id'];
1.535 + }
1.536 + $draftrows[] = $row;
1.537 + }
1.538 + $db->sql_freeresult($result);
1.539 +
1.540 + if (sizeof($topic_ids))
1.541 + {
1.542 + $sql = 'SELECT topic_id, forum_id, topic_title
1.543 + FROM ' . TOPICS_TABLE . '
1.544 + WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids));
1.545 + $result = $db->sql_query($sql);
1.546 +
1.547 + while ($row = $db->sql_fetchrow($result))
1.548 + {
1.549 + $topic_rows[$row['topic_id']] = $row;
1.550 + }
1.551 + $db->sql_freeresult($result);
1.552 + }
1.553 + unset($topic_ids);
1.554 +
1.555 + $template->assign_var('S_EDIT_DRAFT', $edit);
1.556 +
1.557 + $row_count = 0;
1.558 + foreach ($draftrows as $draft)
1.559 + {
1.560 + $link_topic = $link_forum = $link_pm = false;
1.561 + $insert_url = $view_url = $title = '';
1.562 +
1.563 + if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id']))
1.564 + {
1.565 + $link_topic = true;
1.566 + $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id']);
1.567 + $title = $topic_rows[$draft['topic_id']]['topic_title'];
1.568 +
1.569 + $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']);
1.570 + }
1.571 + else if ($auth->acl_get('f_read', $draft['forum_id']))
1.572 + {
1.573 + $link_forum = true;
1.574 + $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']);
1.575 + $title = $draft['forum_name'];
1.576 +
1.577 + $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']);
1.578 + }
1.579 + else if ($pm_drafts)
1.580 + {
1.581 + $link_pm = true;
1.582 + $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&d=" . $draft['draft_id']);
1.583 + }
1.584 +
1.585 + $template_row = array(
1.586 + 'DATE' => $user->format_date($draft['save_time']),
1.587 + 'DRAFT_MESSAGE' => ($submit) ? $draft_message : $draft['draft_message'],
1.588 + 'DRAFT_SUBJECT' => ($submit) ? $draft_subject : $draft['draft_subject'],
1.589 + 'TITLE' => $title,
1.590 +
1.591 + 'DRAFT_ID' => $draft['draft_id'],
1.592 + 'FORUM_ID' => $draft['forum_id'],
1.593 + 'TOPIC_ID' => $draft['topic_id'],
1.594 +
1.595 + 'U_VIEW' => $view_url,
1.596 + 'U_VIEW_EDIT' => $this->u_action . '&edit=' . $draft['draft_id'],
1.597 + 'U_INSERT' => $insert_url,
1.598 +
1.599 + 'S_LINK_TOPIC' => $link_topic,
1.600 + 'S_LINK_FORUM' => $link_forum,
1.601 + 'S_LINK_PM' => $link_pm,
1.602 + 'S_HIDDEN_FIELDS' => $s_hidden_fields
1.603 + );
1.604 + $row_count++;
1.605 +
1.606 + ($edit) ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row);
1.607 + }
1.608 +
1.609 + if (!$edit)
1.610 + {
1.611 + $template->assign_var('S_DRAFT_ROWS', $row_count);
1.612 + }
1.613 +
1.614 + break;
1.615 + }
1.616 +
1.617 +
1.618 + $template->assign_vars(array(
1.619 + 'L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)],
1.620 +
1.621 + 'S_DISPLAY_MARK_ALL' => ($mode == 'watched' || ($mode == 'drafts' && !isset($_GET['edit']))) ? true : false,
1.622 + 'S_HIDDEN_FIELDS' => (isset($s_hidden_fields)) ? $s_hidden_fields : '',
1.623 + 'S_UCP_ACTION' => $this->u_action,
1.624 +
1.625 + 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
1.626 + 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
1.627 + ));
1.628 +
1.629 + // Set desired template
1.630 + $this->tpl_name = 'ucp_main_' . $mode;
1.631 + $this->page_title = 'UCP_MAIN_' . strtoupper($mode);
1.632 + }
1.633 +
1.634 + /**
1.635 + * Build and assign topiclist for bookmarks/subscribed topics
1.636 + */
1.637 + function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array())
1.638 + {
1.639 + global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx;
1.640 +
1.641 + $table = ($mode == 'subscribed') ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE;
1.642 + $start = request_var('start', 0);
1.643 +
1.644 + // Grab icons
1.645 + $icons = $cache->obtain_icons();
1.646 +
1.647 + $sql_array = array(
1.648 + 'SELECT' => 'COUNT(t.topic_id) as topics_count',
1.649 +
1.650 + 'FROM' => array(
1.651 + $table => 'i',
1.652 + TOPICS_TABLE => 't'
1.653 + ),
1.654 +
1.655 + 'WHERE' => 'i.topic_id = t.topic_id
1.656 + AND i.user_id = ' . $user->data['user_id'] . '
1.657 + AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
1.658 + );
1.659 + $sql = $db->sql_build_query('SELECT', $sql_array);
1.660 + $result = $db->sql_query($sql);
1.661 + $topics_count = (int) $db->sql_fetchfield('topics_count');
1.662 + $db->sql_freeresult($result);
1.663 +
1.664 + if ($topics_count)
1.665 + {
1.666 + $template->assign_vars(array(
1.667 + 'PAGINATION' => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start),
1.668 + 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
1.669 + 'TOTAL_TOPICS' => ($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))
1.670 + );
1.671 + }
1.672 +
1.673 + if ($mode == 'subscribed')
1.674 + {
1.675 + $sql_array = array(
1.676 + 'SELECT' => 't.*, f.forum_name',
1.677 +
1.678 + 'FROM' => array(
1.679 + TOPICS_WATCH_TABLE => 'tw',
1.680 + TOPICS_TABLE => 't'
1.681 + ),
1.682 +
1.683 + 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
1.684 + AND t.topic_id = tw.topic_id
1.685 + AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
1.686 +
1.687 +
1.688 + 'ORDER_BY' => 't.topic_last_post_time DESC'
1.689 + );
1.690 +
1.691 + $sql_array['LEFT_JOIN'] = array();
1.692 + }
1.693 + else
1.694 + {
1.695 + $sql_array = array(
1.696 + 'SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id',
1.697 +
1.698 + 'FROM' => array(
1.699 + BOOKMARKS_TABLE => 'b',
1.700 + ),
1.701 +
1.702 + 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . '
1.703 + AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true),
1.704 +
1.705 + 'ORDER_BY' => 't.topic_last_post_time DESC'
1.706 + );
1.707 +
1.708 + $sql_array['LEFT_JOIN'] = array();
1.709 + $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id');
1.710 + }
1.711 +
1.712 + $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
1.713 +
1.714 + if ($config['load_db_lastread'])
1.715 + {
1.716 + $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']);
1.717 + $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']);
1.718 + $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
1.719 + }
1.720 +
1.721 + if ($config['load_db_track'])
1.722 + {
1.723 + $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']);
1.724 + $sql_array['SELECT'] .= ', tp.topic_posted';
1.725 + }
1.726 +
1.727 + $sql = $db->sql_build_query('SELECT', $sql_array);
1.728 + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1.729 +
1.730 + $topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
1.731 + while ($row = $db->sql_fetchrow($result))
1.732 + {
1.733 + $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
1.734 +
1.735 + $topic_list[] = $topic_id;
1.736 + $rowset[$topic_id] = $row;
1.737 +
1.738 + $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
1.739 + $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
1.740 +
1.741 + if ($row['topic_type'] == POST_GLOBAL)
1.742 + {
1.743 + $global_announce_list[] = $topic_id;
1.744 + }
1.745 + }
1.746 + $db->sql_freeresult($result);
1.747 +
1.748 + $topic_tracking_info = array();
1.749 + if ($config['load_db_lastread'])
1.750 + {
1.751 + foreach ($topic_forum_list as $f_id => $topic_row)
1.752 + {
1.753 + $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);
1.754 + }
1.755 + }
1.756 + else
1.757 + {
1.758 + foreach ($topic_forum_list as $f_id => $topic_row)
1.759 + {
1.760 + $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
1.761 + }
1.762 + }
1.763 +
1.764 + foreach ($topic_list as $topic_id)
1.765 + {
1.766 + $row = &$rowset[$topic_id];
1.767 +
1.768 + $forum_id = $row['forum_id'];
1.769 + $topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
1.770 +
1.771 + $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
1.772 +
1.773 + // Replies
1.774 + $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
1.775 +
1.776 + if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
1.777 + {
1.778 + $topic_id = $row['topic_moved_id'];
1.779 + }
1.780 +
1.781 + // Get folder img, topic status/type related information
1.782 + $folder_img = $folder_alt = $topic_type = '';
1.783 + topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
1.784 +
1.785 + $view_topic_url_params = "f=$forum_id&t=$topic_id";
1.786 + $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
1.787 +
1.788 + // Send vars to template
1.789 + $template->assign_block_vars('topicrow', array(
1.790 + 'FORUM_ID' => $forum_id,
1.791 + 'TOPIC_ID' => $topic_id,
1.792 + 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
1.793 + 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
1.794 + 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
1.795 + 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
1.796 +
1.797 + 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.798 + 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.799 + 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.800 + 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
1.801 +
1.802 + 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.803 + 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.804 + 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.805 + 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
1.806 +
1.807 + 'S_DELETED_TOPIC' => (!$row['topic_id']) ? true : false,
1.808 + 'S_GLOBAL_TOPIC' => (!$forum_id) ? true : false,
1.809 +
1.810 + 'PAGINATION' => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&t=$topic_id")),
1.811 + 'REPLIES' => $replies,
1.812 + 'VIEWS' => $row['topic_views'],
1.813 + 'TOPIC_TITLE' => censor_text($row['topic_title']),
1.814 + 'TOPIC_TYPE' => $topic_type,
1.815 + 'FORUM_NAME' => $row['forum_name'],
1.816 +
1.817 + 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
1.818 + 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
1.819 + 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
1.820 + 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
1.821 + 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
1.822 + 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
1.823 + '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']) : '',
1.824 +
1.825 + 'S_TOPIC_TYPE' => $row['topic_type'],
1.826 + 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false,
1.827 + 'S_UNREAD_TOPIC' => $unread_topic,
1.828 +
1.829 + 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread',
1.830 + 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
1.831 + 'U_VIEW_TOPIC' => $view_topic_url,
1.832 + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
1.833 + ));
1.834 + }
1.835 + }
1.836 +}
1.837 +
1.838 +?>
1.839 \ No newline at end of file