Exemplo n.º 1
0
/**
* MCP Front Panel
*/
function mcp_front_view($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth, $module;
    global $phpbb_dispatcher;
    // Latest 5 unapproved
    if ($module->loaded('queue')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
        $post_list = array();
        $forum_names = array();
        $forum_id = request_var('f', 0);
        $template->assign_var('S_SHOW_UNAPPROVED', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql_ary = array('SELECT' => 'COUNT(post_id) AS total', 'FROM' => array(POSTS_TABLE => 'p'), 'WHERE' => $db->sql_in_set('p.forum_id', $forum_list) . '
					AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)));
            /**
             * Allow altering the query to get the number of unapproved posts
             *
             * @event core.mcp_front_queue_unapproved_total_before
             * @var	int		sql_ary						Query to get the total number of unapproved posts
             * @var	array	forum_list					List of forums to look for unapproved posts
             * @since 3.1.5-RC1
             */
            $vars = array('sql_ary', 'forum_list');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_queue_unapproved_total_before', compact($vars)));
            $sql = $db->sql_build_query('SELECT', $sql_ary);
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $sql = 'SELECT forum_id, forum_name
					FROM ' . FORUMS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list);
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $forum_names[$row['forum_id']] = $row['forum_name'];
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
						AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . '
					ORDER BY post_time DESC, post_id DESC';
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $post_list[] = $row['post_id'];
                }
                $db->sql_freeresult($result);
                if (empty($post_list)) {
                    $total = 0;
                }
            }
            /**
             * Alter list of posts and total as required
             *
             * @event core.mcp_front_view_queue_postid_list_after
             * @var	int		total						Number of unapproved posts
             * @var	array	post_list					List of unapproved posts
             * @var	array	forum_list					List of forums that contain the posts
             * @var	array	forum_names					Associative array with forum_id as key and it's corresponding forum_name as value
             * @since 3.1.0-RC3
             */
            $vars = array('total', 'post_list', 'forum_list', 'forum_names');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_queue_postid_list_after', compact($vars)));
            if ($total) {
                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.post_attachment, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
					WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
						AND t.topic_id = p.topic_id
						AND p.poster_id = u.user_id
					ORDER BY p.post_time DESC, p.post_id DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('unapproved', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&mode=approve_details&f=' . $row['forum_id'] . '&p=' . $row['post_id']), 'U_MCP_FORUM' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&mode=forum_view&f=' . $row['forum_id']), 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&mode=topic_view&f=' . $row['forum_id'] . '&t=' . $row['topic_id']), 'U_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']), 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']), 'AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']), 'U_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']), 'FORUM_NAME' => $forum_names[$row['forum_id']], 'POST_ID' => $row['post_id'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_TIME' => $user->format_date($row['post_time']), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
                }
                $db->sql_freeresult($result);
            }
            $s_hidden_fields = build_hidden_fields(array('redirect' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main' . ($forum_id ? '&f=' . $forum_id : ''))));
            $template->assign_vars(array('S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_MCP_QUEUE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue"), 'L_UNAPPROVED_TOTAL' => $user->lang('UNAPPROVED_POSTS_TOTAL', (int) $total), 'S_HAS_UNAPPROVED_POSTS' => $total != 0));
        }
    }
    // Latest 5 reported
    if ($module->loaded('reports')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
        $template->assign_var('S_SHOW_REPORTS', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(r.report_id) AS total
				FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
				WHERE r.post_id = p.post_id
					AND r.pm_id = 0
					AND r.report_closed = 0
					AND ' . $db->sql_in_set('p.forum_id', $forum_list);
            /**
             * Alter sql query to count the number of reported posts
             *
             * @event core.mcp_front_reports_count_query_before
             * @var	int		sql				The query string used to get the number of reports that exist
             * @var	array	forum_list		List of forums that contain the posts
             * @since 3.1.5-RC1
             */
            $vars = array('sql', 'forum_list');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_count_query_before', compact($vars)));
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $sql_ary = array('SELECT' => 'r.report_time, p.post_id, p.post_subject, p.post_time, p.post_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', TOPICS_TABLE => 't', USERS_TABLE => array('u', 'u2'), POSTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = p.forum_id')), 'WHERE' => 'r.post_id = p.post_id
						AND r.pm_id = 0
						AND r.report_closed = 0
						AND r.reason_id = rr.reason_id
						AND p.topic_id = t.topic_id
						AND r.user_id = u.user_id
						AND p.poster_id = u2.user_id
						AND ' . $db->sql_in_set('p.forum_id', $forum_list), 'ORDER_BY' => 'p.post_time DESC, p.post_id DESC');
                /**
                 * Alter sql query to get latest reported posts
                 *
                 * @event core.mcp_front_reports_listing_query_before
                 * @var	int		sql_ary						Associative array with the query to be executed
                 * @var	array	forum_list					List of forums that contain the posts
                 * @since 3.1.0-RC3
                 */
                $vars = array('sql_ary', 'forum_list');
                extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_listing_query_before', compact($vars)));
                $sql = $db->sql_build_query('SELECT', $sql_ary);
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('report', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&p=' . $row['post_id'] . "&i=reports&mode=report_details"), 'U_MCP_FORUM' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . "&i={$id}&mode=forum_view"), 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id'] . "&i={$id}&mode=topic_view"), 'U_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']), 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'POST_TIME' => $user->format_date($row['post_time']), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
                }
                $db->sql_freeresult($result);
            }
            $template->assign_vars(array('L_REPORTS_TOTAL' => $user->lang('REPORTS_TOTAL', (int) $total), 'S_HAS_REPORTS' => $total != 0));
        }
    }
    // Latest 5 reported PMs
    if ($module->loaded('pm_reports') && $auth->acl_get('m_pm_report')) {
        $template->assign_var('S_SHOW_PM_REPORTS', true);
        $user->add_lang(array('ucp'));
        $sql = 'SELECT COUNT(r.report_id) AS total
			FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
			WHERE r.post_id = 0
				AND r.pm_id = p.msg_id
				AND r.report_closed = 0';
        $result = $db->sql_query($sql);
        $total = (int) $db->sql_fetchfield('total');
        $db->sql_freeresult($result);
        if ($total) {
            include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
            $sql_ary = array('SELECT' => 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, p.message_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', USERS_TABLE => array('u', 'u2'), PRIVMSGS_TABLE => 'p'), 'WHERE' => 'r.pm_id = p.msg_id
					AND r.post_id = 0
					AND r.report_closed = 0
					AND r.reason_id = rr.reason_id
					AND r.user_id = u.user_id
					AND p.author_id = u2.user_id', 'ORDER_BY' => 'p.message_time DESC');
            $sql = $db->sql_build_query('SELECT', $sql_ary);
            $result = $db->sql_query_limit($sql, 5);
            $pm_by_id = $pm_list = array();
            while ($row = $db->sql_fetchrow($result)) {
                $pm_by_id[(int) $row['msg_id']] = $row;
                $pm_list[] = (int) $row['msg_id'];
            }
            $db->sql_freeresult($result);
            $address_list = get_recipient_strings($pm_by_id);
            foreach ($pm_list as $message_id) {
                $row = $pm_by_id[$message_id];
                $template->assign_block_vars('pm_report', array('U_PM_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'r=' . $row['report_id'] . "&i=pm_reports&mode=pm_report_details"), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'PM_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_PM_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_SUBJECT' => $row['message_subject'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'PM_TIME' => $user->format_date($row['message_time']), 'RECIPIENTS' => implode(', ', $address_list[$row['msg_id']]), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $row['message_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
            }
        }
        $template->assign_vars(array('L_PM_REPORTS_TOTAL' => $user->lang('PM_REPORTS_TOTAL', (int) $total), 'S_HAS_PM_REPORTS' => $total != 0));
    }
    // Latest 5 logs
    if ($module->loaded('logs')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        if (!empty($forum_list)) {
            $log_count = false;
            $log = array();
            view_log('mod', $log, $log_count, 5, 0, $forum_list);
            foreach ($log as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'TIME' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'U_VIEW_TOPIC' => !empty($row['viewtopic']) ? $row['viewtopic'] : '', 'U_VIEWLOGS' => !empty($row['viewlogs']) ? $row['viewlogs'] : ''));
            }
        }
        $template->assign_vars(array('S_SHOW_LOGS' => !empty($forum_list) ? true : false, 'S_HAS_LOGS' => !empty($log) ? true : false));
    }
    $template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.{$phpEx}"));
    make_jumpbox(append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&mode=forum_view'), 0, false, 'm_', true);
}
Exemplo n.º 2
0
/**
* View message folder
* Called from ucp_pm with mode == 'view' && action == 'view_folder'
*/
function view_folder($id, $mode, $folder_id, $folder)
{
    global $user, $template, $auth, $db, $cache;
    global $phpbb_root_path, $config, $phpEx;
    $submit_export = isset($_POST['submit_export']) ? true : false;
    $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']);
    if (!$submit_export) {
        $user->add_lang('viewforum');
        // Grab icons
        $icons = $cache->obtain_icons();
        $color_rows = array('marked', 'replied');
        // only show the friend/foe color rows if the module is enabled
        $zebra_enabled = false;
        $_module = new p_master();
        $_module->list_modules('ucp');
        $_module->set_active('zebra');
        $zebra_enabled = $_module->active_module === false ? false : true;
        unset($_module);
        if ($zebra_enabled) {
            $color_rows = array_merge($color_rows, array('friend', 'foe'));
        }
        foreach ($color_rows as $var) {
            $template->assign_block_vars('pm_colour_info', array('IMG' => $user->img("pm_{$var}", ''), 'CLASS' => "pm_{$var}_colour", 'LANG' => $user->lang[strtoupper($var) . '_MESSAGE']));
        }
        $mark_options = array('mark_important', 'delete_marked');
        // Minimise edits
        if (!$auth->acl_get('u_pm_delete') && ($key = array_search('delete_marked', $mark_options))) {
            unset($mark_options[$key]);
        }
        $s_mark_options = '';
        foreach ($mark_options as $mark_option) {
            $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>';
        }
        // We do the folder moving options here too, for template authors to use...
        $s_folder_move_options = '';
        if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX) {
            foreach ($folder as $f_id => $folder_ary) {
                if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id) {
                    continue;
                }
                $s_folder_move_options .= '<option' . ($f_id != PRIVMSGS_INBOX ? ' class="sep"' : '') . ' value="' . $f_id . '">';
                $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']);
                $s_folder_move_options .= ($folder_ary['unread_messages'] ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>';
            }
        }
        $friend = $foe = array();
        // Get friends and foes
        $sql = 'SELECT *
			FROM ' . ZEBRA_TABLE . '
			WHERE user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $friend[$row['zebra_id']] = $row['friend'];
            $foe[$row['zebra_id']] = $row['foe'];
        }
        $db->sql_freeresult($result);
        $template->assign_vars(array('S_MARK_OPTIONS' => $s_mark_options, 'S_MOVE_MARKED_OPTIONS' => $s_folder_move_options));
        // Okay, lets dump out the page ...
        if (sizeof($folder_info['pm_list'])) {
            $address_list = array();
            // Build Recipient List if in outbox/sentbox - max two additional queries
            if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) {
                $address_list = get_recipient_strings($folder_info['rowset']);
            }
            foreach ($folder_info['pm_list'] as $message_id) {
                $row =& $folder_info['rowset'][$message_id];
                $folder_img = $row['pm_unread'] ? 'pm_unread' : 'pm_read';
                $folder_alt = $row['pm_unread'] ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES';
                // Generate all URIs ...
                $view_message_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode=view&amp;f={$folder_id}&amp;p={$message_id}");
                $remove_message_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode=compose&amp;action=delete&amp;p={$message_id}");
                $row_indicator = '';
                foreach ($color_rows as $var) {
                    if ($var != 'friend' && $var != 'foe' && $row['pm_' . $var] || ($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]) {
                        $row_indicator = $var;
                        break;
                    }
                }
                // Send vars to template
                $template->assign_block_vars('messagerow', array('PM_CLASS' => $row_indicator ? 'pm_' . $row_indicator . '_colour' : '', 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'MESSAGE_AUTHOR' => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'U_MESSAGE_AUTHOR' => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'FOLDER_ID' => $folder_id, 'MESSAGE_ID' => $message_id, 'SENT_TIME' => $user->format_date($row['message_time']), 'SUBJECT' => censor_text($row['message_subject']), 'FOLDER' => isset($folder[$row['folder_id']]) ? $folder[$row['folder_id']]['folder_name'] : '', 'U_FOLDER' => isset($folder[$row['folder_id']]) ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'folder=' . $row['folder_id']) : '', 'PM_ICON_IMG' => !empty($icons[$row['icon_id']]) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '', 'PM_ICON_URL' => !empty($icons[$row['icon_id']]) ? $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '', 'FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'PM_IMG' => $row_indicator ? $user->img('pm_' . $row_indicator, '') : '', 'ATTACH_ICON_IMG' => $auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_PM_DELETED' => $row['pm_deleted'] ? true : false, 'S_PM_REPORTED' => isset($row['report_id']) ? true : false, 'S_AUTHOR_DELETED' => $row['author_id'] == ANONYMOUS ? true : false, 'U_VIEW_PM' => $row['pm_deleted'] ? '' : $view_message_url, 'U_REMOVE_PM' => $row['pm_deleted'] ? $remove_message_url : '', 'U_MCP_REPORT' => isset($row['report_id']) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $row['report_id']) : '', 'RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? implode(', ', $address_list[$message_id]) : ''));
            }
            unset($folder_info['rowset']);
            $template->assign_vars(array('S_SHOW_RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? true : false, 'S_SHOW_COLOUR_LEGEND' => true, 'REPORTED_IMG' => $user->img('icon_topic_reported', 'PM_REPORTED'), 'S_PM_ICONS' => $config['enable_pm_icons'] ? true : false));
        }
    } else {
        $export_type = request_var('export_option', '');
        $enclosure = request_var('enclosure', '');
        $delimiter = request_var('delimiter', '');
        if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === '')) {
            $template->assign_var('PROMPT', true);
        } else {
            // Build Recipient List if in outbox/sentbox
            $address_temp = $address = $data = array();
            if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) {
                foreach ($folder_info['rowset'] as $message_id => $row) {
                    $address_temp[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
                    $address[$message_id] = array();
                }
            }
            foreach ($folder_info['pm_list'] as $message_id) {
                $row =& $folder_info['rowset'][$message_id];
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $sql = 'SELECT p.message_text, p.bbcode_uid
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
					WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\tAND t.folder_id = {$folder_id}\n\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\tAND p.msg_id = {$message_id}";
                $result = $db->sql_query_limit($sql, 1);
                $message_row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $_types = array('u', 'g');
                foreach ($_types as $ug_type) {
                    if (isset($address_temp[$message_id][$ug_type]) && sizeof($address_temp[$message_id][$ug_type])) {
                        if (!isset($address[$message_id][$ug_type])) {
                            $address[$message_id][$ug_type] = array();
                        }
                        if ($ug_type == 'u') {
                            $sql = 'SELECT user_id as id, username as name
								FROM ' . USERS_TABLE . '
								WHERE ';
                        } else {
                            $sql = 'SELECT group_id as id, group_name as name
								FROM ' . GROUPS_TABLE . '
								WHERE ';
                        }
                        $sql .= $db->sql_in_set($ug_type == 'u' ? 'user_id' : 'group_id', array_map('intval', array_keys($address_temp[$message_id][$ug_type])));
                        $result = $db->sql_query($sql);
                        while ($info_row = $db->sql_fetchrow($result)) {
                            $address[$message_id][$ug_type][$address_temp[$message_id][$ug_type][$info_row['id']]][] = $info_row['name'];
                            unset($address_temp[$message_id][$ug_type][$info_row['id']]);
                        }
                        $db->sql_freeresult($result);
                    }
                }
                // There is the chance that all recipients of the message got deleted. To avoid creating
                // exports without recipients, we add a bogus "undisclosed recipient".
                if (!(isset($address[$message_id]['g']) && sizeof($address[$message_id]['g'])) && !(isset($address[$message_id]['u']) && sizeof($address[$message_id]['u']))) {
                    $address[$message_id]['u'] = array();
                    $address[$message_id]['u']['to'] = array();
                    $address[$message_id]['u']['to'][] = $user->lang['UNDISCLOSED_RECIPIENT'];
                }
                decode_message($message_row['message_text'], $message_row['bbcode_uid']);
                $data[] = array('subject' => censor_text($row['message_subject']), 'sender' => $row['username'], 'date' => $user->format_date($row['message_time'], PHP_VERSION >= 5 ? 'c' : "Y-m-d\\TH:i:s+00:00", true), 'to' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? $address[$message_id] : '', 'message' => $message_row['message_text']);
            }
            switch ($export_type) {
                case 'CSV':
                case 'CSV_EXCEL':
                    $mimetype = 'text/csv';
                    $filetype = 'csv';
                    if ($export_type == 'CSV_EXCEL') {
                        $enclosure = '"';
                        $delimiter = ',';
                        $newline = "\r\n";
                    } else {
                        $newline = "\n";
                    }
                    $string = '';
                    foreach ($data as $value) {
                        $recipients = $value['to'];
                        $value['to'] = $value['bcc'] = '';
                        if (is_array($recipients)) {
                            foreach ($recipients as $values) {
                                $value['bcc'] .= isset($values['bcc']) && is_array($values['bcc']) ? ',' . implode(',', $values['bcc']) : '';
                                $value['to'] .= isset($values['to']) && is_array($values['to']) ? ',' . implode(',', $values['to']) : '';
                            }
                            // Remove the commas which will appear before the first entry.
                            $value['to'] = substr($value['to'], 1);
                            $value['bcc'] = substr($value['bcc'], 1);
                        }
                        foreach ($value as $tag => $text) {
                            $cell = str_replace($enclosure, $enclosure . $enclosure, $text);
                            if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false) {
                                $string .= $enclosure . $text . $enclosure . $delimiter;
                            } else {
                                $string .= $cell . $delimiter;
                            }
                        }
                        $string = substr($string, 0, -1) . $newline;
                    }
                    break;
                case 'XML':
                    $mimetype = 'application/xml';
                    $filetype = 'xml';
                    $string = '<?xml version="1.0"?>' . "\n";
                    $string .= "<phpbb>\n";
                    foreach ($data as $value) {
                        $string .= "\t<privmsg>\n";
                        if (is_array($value['to'])) {
                            foreach ($value['to'] as $key => $values) {
                                foreach ($values as $type => $types) {
                                    foreach ($types as $name) {
                                        $string .= "\t\t<recipient type=\"{$type}\" status=\"{$key}\">{$name}</recipient>\n";
                                    }
                                }
                            }
                        }
                        unset($value['to']);
                        foreach ($value as $tag => $text) {
                            $string .= "\t\t<{$tag}>{$text}</{$tag}>\n";
                        }
                        $string .= "\t</privmsg>\n";
                    }
                    $string .= '</phpbb>';
                    break;
            }
            header('Pragma: no-cache');
            header("Content-Type: {$mimetype}; name=\"data.{$filetype}\"");
            header("Content-disposition: attachment; filename=data.{$filetype}");
            echo $string;
            exit;
        }
    }
}
Exemplo n.º 3
0
    function main($id, $mode)
    {
        global $auth, $db, $user, $template, $cache;
        global $config, $phpbb_root_path, $phpEx, $action;
        include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
        include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
        $start = request_var('start', 0);
        $this->page_title = 'MCP_PM_REPORTS';
        switch ($action) {
            case 'close':
            case 'delete':
                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                $report_id_list = request_var('report_id_list', array(0));
                if (!sizeof($report_id_list)) {
                    trigger_error('NO_REPORT_SELECTED');
                }
                if (!function_exists('close_report')) {
                    include $phpbb_root_path . 'includes/mcp/mcp_reports.' . $phpEx;
                }
                close_report($report_id_list, $mode, $action, true);
                break;
        }
        switch ($mode) {
            case 'pm_report_details':
                $user->add_lang(array('posting', 'viewforum', 'viewtopic', 'ucp'));
                $report_id = request_var('r', 0);
                $sql = 'SELECT r.pm_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
					FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
					WHERE r.report_id = ' . $report_id . '
						AND rr.reason_id = r.reason_id
						AND r.user_id = u.user_id
						AND r.post_id = 0
					ORDER BY report_closed ASC';
                $result = $db->sql_query_limit($sql, 1);
                $report = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$report_id || !$report) {
                    trigger_error('NO_REPORT');
                }
                $pm_id = $report['pm_id'];
                $report_id = $report['report_id'];
                $pm_info = get_pm_data(array($pm_id));
                if (!sizeof($pm_info)) {
                    trigger_error('NO_REPORT_SELECTED');
                }
                $pm_info = $pm_info[$pm_id];
                write_pm_addresses(array('to' => $pm_info['to_address'], 'bcc' => $pm_info['bcc_address']), (int) $pm_info['author_id']);
                $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
                if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])])) {
                    $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
                    $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
                }
                // Process message, leave it uncensored
                $message = $pm_info['message_text'];
                if ($pm_info['bbcode_bitfield']) {
                    include_once $phpbb_root_path . 'includes/bbcode.' . $phpEx;
                    $bbcode = new bbcode($pm_info['bbcode_bitfield']);
                    $bbcode->bbcode_second_pass($message, $pm_info['bbcode_uid'], $pm_info['bbcode_bitfield']);
                }
                $message = bbcode_nl2br($message);
                $message = smiley_text($message);
                if ($pm_info['message_attachment'] && $auth->acl_get('u_pm_download')) {
                    $sql = 'SELECT *
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE post_msg_id = ' . $pm_id . '
							AND in_message = 1
						ORDER BY filetime DESC';
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $attachments[] = $row;
                    }
                    $db->sql_freeresult($result);
                    if (sizeof($attachments)) {
                        $update_count = array();
                        parse_attachments(0, $message, $attachments, $update_count);
                    }
                    // Display not already displayed Attachments for this post, we already parsed them. ;)
                    if (!empty($attachments)) {
                        $template->assign_var('S_HAS_ATTACHMENTS', true);
                        foreach ($attachments as $attachment) {
                            $template->assign_block_vars('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
                        }
                    }
                }
                $template->assign_vars(array('S_MCP_REPORT' => true, 'S_PM' => true, 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id), 'S_CAN_VIEWIP' => $auth->acl_getf_global('m_info'), 'S_POST_REPORTED' => $pm_info['message_reported'], 'S_USER_NOTES' => true, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id), 'U_MCP_REPORTER_NOTES' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']), 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=notes&amp;mode=user_notes&amp;u=' . $pm_info['author_id']), 'U_MCP_WARN_REPORTER' => $auth->acl_get('m_warn') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=warn&amp;mode=warn_user&amp;u=' . $report['user_id']) : '', 'U_MCP_WARN_USER' => $auth->acl_get('m_warn') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=warn&amp;mode=warn_user&amp;u=' . $pm_info['author_id']) : '', 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 'MINI_POST_IMG' => $user->img('icon_post_target', 'POST'), 'RETURN_REPORTS' => sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=pm_reports' . ($pm_info['message_reported'] ? '&amp;mode=pm_reports' : '&amp;mode=pm_reports_closed') . '&amp;start=' . $start) . '">', '</a>'), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 'REPORT_DATE' => $user->format_date($report['report_time']), 'REPORT_ID' => $report_id, 'REPORT_REASON_TITLE' => $reason['title'], 'REPORT_REASON_DESCRIPTION' => $reason['description'], 'REPORT_TEXT' => $report['report_text'], 'POST_AUTHOR_FULL' => get_username_string('full', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']), 'POST_AUTHOR' => get_username_string('username', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']), 'U_POST_AUTHOR' => get_username_string('profile', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']), 'REPORTER_FULL' => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']), 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']), 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']), 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $pm_info['message_subject'] ? $pm_info['message_subject'] : $user->lang['NO_SUBJECT'], 'POST_DATE' => $user->format_date($pm_info['message_time']), 'POST_IP' => $pm_info['author_ip'], 'POST_IPADDR' => $auth->acl_getf_global('m_info') && request_var('lookup', '') ? @gethostbyaddr($pm_info['author_ip']) : '', 'POST_ID' => $pm_info['msg_id'], 'U_LOOKUP_IP' => $auth->acl_getf_global('m_info') ? $this->u_action . '&amp;r=' . $report_id . '&amp;pm=' . $pm_id . '&amp;lookup=' . $pm_info['author_ip'] . '#ip' : ''));
                $this->tpl_name = 'mcp_post';
                break;
            case 'pm_reports':
            case 'pm_reports_closed':
                $user->add_lang(array('ucp'));
                $sort_days = $total = 0;
                $sort_key = $sort_dir = '';
                $sort_by_sql = $sort_order_sql = array();
                mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total);
                $limit_time_sql = $sort_days ? 'AND r.report_time >= ' . (time() - $sort_days * 86400) : '';
                if ($mode == 'pm_reports') {
                    $report_state = 'p.message_reported = 1 AND r.report_closed = 0';
                } else {
                    $report_state = 'r.report_closed = 1';
                }
                $sql = 'SELECT r.report_id
					FROM ' . PRIVMSGS_TABLE . ' p, ' . REPORTS_TABLE . ' r ' . ($sort_order_sql[0] == 'u' ? ', ' . USERS_TABLE . ' u' : '') . ($sort_order_sql[0] == 'r' ? ', ' . USERS_TABLE . ' ru' : '') . "\n\t\t\t\t\tWHERE {$report_state}\n\t\t\t\t\t\tAND r.pm_id = p.msg_id\n\t\t\t\t\t\t" . ($sort_order_sql[0] == 'u' ? 'AND u.user_id = p.author_id' : '') . '
						' . ($sort_order_sql[0] == 'r' ? 'AND ru.user_id = r.user_id' : '') . "\n\t\t\t\t\t\tAND r.post_id = 0\n\t\t\t\t\t\t{$limit_time_sql}\n\t\t\t\t\tORDER BY {$sort_order_sql}";
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
                $i = 0;
                $report_ids = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $report_ids[] = $row['report_id'];
                    $row_num[$row['report_id']] = $i++;
                }
                $db->sql_freeresult($result);
                if (sizeof($report_ids)) {
                    $sql = 'SELECT p.*, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id
						FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
						WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . "\n\t\t\t\t\t\t\tAND r.pm_id = p.msg_id\n\t\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\t\tAND ru.user_id = r.user_id\n\t\t\t\t\t\tORDER BY {$sort_order_sql}";
                    $result = $db->sql_query($sql);
                    $pm_list = $pm_by_id = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $pm_by_id[(int) $row['msg_id']] = $row;
                        $pm_list[] = (int) $row['msg_id'];
                    }
                    $db->sql_freeresult($result);
                    if (sizeof($pm_list)) {
                        $address_list = get_recipient_strings($pm_by_id);
                        foreach ($pm_list as $message_id) {
                            $row = $pm_by_id[$message_id];
                            $template->assign_block_vars('postrow', array('U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=pm_reports&amp;mode=pm_report_details&amp;r={$row['report_id']}"), 'PM_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour']), 'PM_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour']), 'PM_AUTHOR' => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour']), 'U_PM_AUTHOR' => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour']), 'REPORTER_FULL' => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), 'REPORTER' => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), 'U_REPORTER' => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), 'PM_SUBJECT' => $row['message_subject'] ? $row['message_subject'] : $user->lang['NO_SUBJECT'], 'PM_TIME' => $user->format_date($row['message_time']), 'REPORT_ID' => $row['report_id'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'RECIPIENTS' => implode(', ', $address_list[$row['msg_id']])));
                        }
                    }
                }
                // Now display the page
                $template->assign_vars(array('L_EXPLAIN' => $mode == 'pm_reports' ? $user->lang['MCP_PM_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_PM_REPORTS_CLOSED_EXPLAIN'], 'L_TITLE' => $mode == 'pm_reports' ? $user->lang['MCP_PM_REPORTS_OPEN'] : $user->lang['MCP_PM_REPORTS_CLOSED'], 'S_PM' => true, 'S_MCP_ACTION' => $this->u_action, 'S_CLOSED' => $mode == 'pm_reports_closed' ? true : false, 'PAGINATION' => generate_pagination($this->u_action . "&amp;st={$sort_days}&amp;sk={$sort_key}&amp;sd={$sort_dir}", $total, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($total, $config['topics_per_page'], $start), 'TOTAL' => $total, 'TOTAL_REPORTS' => $total == 1 ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total)));
                $this->tpl_name = 'mcp_reports';
                break;
        }
    }
Exemplo n.º 4
0
/**
* MCP Front Panel
*/
function mcp_front_view($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth, $module;
    // Latest 5 unapproved
    if ($module->loaded('queue')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
        $post_list = array();
        $forum_names = array();
        $forum_id = request_var('f', 0);
        $template->assign_var('S_SHOW_UNAPPROVED', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(post_id) AS total
				FROM ' . POSTS_TABLE . '
				WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
					AND post_approved = 0';
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $global_id = $forum_list[0];
                $sql = 'SELECT forum_id, forum_name
					FROM ' . FORUMS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list);
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $forum_names[$row['forum_id']] = $row['forum_name'];
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
						AND post_approved = 0
					ORDER BY post_time DESC';
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $post_list[] = $row['post_id'];
                }
                $db->sql_freeresult($result);
                if (empty($post_list)) {
                    $total = 0;
                }
            }
            if ($total) {
                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id, f.forum_solve_text, f.forum_solve_color, f.forum_allow_solve, t.topic_solved
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_TABLE . ' f
					WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
						AND t.topic_id = p.topic_id
						AND p.poster_id = u.user_id
						AND f.forum_id = p.forum_id
					ORDER BY p.post_time DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $global_topic = $row['forum_id'] ? false : true;
                    if ($global_topic) {
                        $row['forum_id'] = $global_id;
                    }
                    $template->assign_block_vars('unapproved', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']), 'U_MCP_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']) : '', 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=topic_view&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'U_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']) : '', 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']), 'U_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']), 'FORUM_NAME' => !$global_topic ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'], 'POST_ID' => $row['post_id'], 'TOPIC_TITLE' => $row['topic_solved'] && $row['forum_allow_solve'] && !$global_topic ? $row['topic_title'] . ($row['forum_solve_text'] ? ($row['forum_solve_color'] ? '<span style="color: #' . $row['forum_solve_color'] . '">' : '') . $row['forum_solve_text'] . ($row['forum_solve_color'] ? '</span>' : '') : $user->img('icon_topic_solved_list', 'TOPIC_SOLVED')) : $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_TIME' => $user->format_date($row['post_time'])));
                }
                $db->sql_freeresult($result);
            }
            $s_hidden_fields = build_hidden_fields(array('redirect' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main' . ($forum_id ? '&amp;f=' . $forum_id : ''))));
            $template->assign_vars(array('S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_MCP_QUEUE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue")));
            if ($total == 0) {
                $template->assign_vars(array('L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POSTS_ZERO_TOTAL'], 'S_HAS_UNAPPROVED_POSTS' => false));
            } else {
                $template->assign_vars(array('L_UNAPPROVED_TOTAL' => $total == 1 ? $user->lang['UNAPPROVED_POST_TOTAL'] : sprintf($user->lang['UNAPPROVED_POSTS_TOTAL'], $total), 'S_HAS_UNAPPROVED_POSTS' => true));
            }
        }
    }
    // Latest 5 reported
    if ($module->loaded('reports')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
        $template->assign_var('S_SHOW_REPORTS', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(r.report_id) AS total
				FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
				WHERE r.post_id = p.post_id
					AND r.pm_id = 0
					AND r.report_closed = 0
					AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')';
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $global_id = $forum_list[0];
                $sql = $db->sql_build_query('SELECT', array('SELECT' => 'r.report_time, p.post_id, p.post_subject, p.post_time, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name, f.forum_solve_text, f.forum_solve_color, f.forum_allow_solve, t.topic_solved', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', TOPICS_TABLE => 't', USERS_TABLE => array('u', 'u2'), POSTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = p.forum_id')), 'WHERE' => 'r.post_id = p.post_id
						AND r.pm_id = 0
						AND r.report_closed = 0
						AND r.reason_id = rr.reason_id
						AND p.topic_id = t.topic_id
						AND r.user_id = u.user_id
						AND p.poster_id = u2.user_id
						AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')', 'ORDER_BY' => 'p.post_time DESC'));
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $global_topic = $row['forum_id'] ? false : true;
                    if ($global_topic) {
                        $row['forum_id'] = $global_id;
                    }
                    $template->assign_block_vars('report', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"), 'U_MCP_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . "&amp;i={$id}&amp;mode=forum_view") : '', 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . "&amp;i={$id}&amp;mode=topic_view"), 'U_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']) : '', 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'FORUM_NAME' => !$global_topic ? $row['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['topic_solved'] && $row['forum_allow_solve'] && !$global_topic ? ($row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT']) . '&nbsp;&nbsp;' . ($row['forum_solve_text'] ? ($row['forum_solve_color'] ? '<span style="color: #' . $row['forum_solve_color'] . '">' : '') . $row['forum_solve_text'] . ($row['forum_solve_color'] ? '</span>' : '') : $user->img('icon_topic_solved_list', 'TOPIC_SOLVED')) : ($row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT']), 'REPORT_TIME' => $user->format_date($row['report_time']), 'POST_TIME' => $user->format_date($row['post_time'])));
                }
            }
            if ($total == 0) {
                $template->assign_vars(array('L_REPORTS_TOTAL' => $user->lang['REPORTS_ZERO_TOTAL'], 'S_HAS_REPORTS' => false));
            } else {
                $template->assign_vars(array('L_REPORTS_TOTAL' => $total == 1 ? $user->lang['REPORT_TOTAL'] : sprintf($user->lang['REPORTS_TOTAL'], $total), 'S_HAS_REPORTS' => true));
            }
        }
    }
    // Latest 5 reported PMs
    if ($module->loaded('pm_reports') && $auth->acl_getf_global('m_report')) {
        $template->assign_var('S_SHOW_PM_REPORTS', true);
        $user->add_lang(array('ucp'));
        $sql = 'SELECT COUNT(r.report_id) AS total
			FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
			WHERE r.post_id = 0
				AND r.pm_id = p.msg_id
				AND r.report_closed = 0';
        $result = $db->sql_query($sql);
        $total = (int) $db->sql_fetchfield('total');
        $db->sql_freeresult($result);
        if ($total) {
            include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
            $sql = $db->sql_build_query('SELECT', array('SELECT' => 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', USERS_TABLE => array('u', 'u2'), PRIVMSGS_TABLE => 'p'), 'WHERE' => 'r.pm_id = p.msg_id
					AND r.post_id = 0
					AND r.report_closed = 0
					AND r.reason_id = rr.reason_id
					AND r.user_id = u.user_id
					AND p.author_id = u2.user_id', 'ORDER_BY' => 'p.message_time DESC'));
            $result = $db->sql_query_limit($sql, 5);
            $pm_by_id = $pm_list = array();
            while ($row = $db->sql_fetchrow($result)) {
                $pm_by_id[(int) $row['msg_id']] = $row;
                $pm_list[] = (int) $row['msg_id'];
            }
            $address_list = get_recipient_strings($pm_by_id);
            foreach ($pm_list as $message_id) {
                $row = $pm_by_id[$message_id];
                $template->assign_block_vars('pm_report', array('U_PM_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'r=' . $row['report_id'] . "&amp;i=pm_reports&amp;mode=pm_report_details"), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'PM_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_PM_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_SUBJECT' => $row['message_subject'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'PM_TIME' => $user->format_date($row['message_time']), 'RECIPIENTS' => implode(', ', $address_list[$row['msg_id']])));
            }
        }
        if ($total == 0) {
            $template->assign_vars(array('L_PM_REPORTS_TOTAL' => $user->lang['PM_REPORTS_ZERO_TOTAL'], 'S_HAS_PM_REPORTS' => false));
        } else {
            $template->assign_vars(array('L_PM_REPORTS_TOTAL' => $total == 1 ? $user->lang['PM_REPORT_TOTAL'] : sprintf($user->lang['PM_REPORTS_TOTAL'], $total), 'S_HAS_PM_REPORTS' => true));
        }
    }
    // Latest 5 logs
    if ($module->loaded('logs')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        if (!empty($forum_list)) {
            // Add forum_id 0 for global announcements
            $forum_list[] = 0;
            $log_count = 0;
            $log = array();
            view_log('mod', $log, $log_count, 5, 0, $forum_list);
            foreach ($log as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'TIME' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'U_VIEW_TOPIC' => !empty($row['viewtopic']) ? $row['viewtopic'] : '', 'U_VIEWLOGS' => !empty($row['viewlogs']) ? $row['viewlogs'] : ''));
            }
        }
        $template->assign_vars(array('S_SHOW_LOGS' => !empty($forum_list) ? true : false, 'S_HAS_LOGS' => !empty($log) ? true : false));
    }
    $template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.{$phpEx}"));
    make_jumpbox(append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view'), 0, false, 'm_', true);
}