MyBB Community Forums

Full Version: Set for only Admin able to see 'Board Statistics' ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to setup the home page so only Admin is able to see 'Board Statistics' (Forum Home Options > Show Small Stats Section > Yes) ?
Similar question at setup for only Admin able to see 'Who's Online' ?, but dont see way to edit 'index_boardstats' template or edit User Groups permissions for only Admin able to see 'Board Statistics'.
Thoughts ? Confused
open stats .php and make an if else statement to check $mybb->user['usergroup']
Thanks much for the reply.
Well I can get to stats.php...
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 * $Id: stats.php 5297 2010-12-28 22:01:14Z Tomm $
 */
...
But unfortunately my php experience ends about there, especially with 'if statements'. Blush
Guess it might be a good time to start learning, but could you get me started on this one with an example for this specific question ?
(2014-07-28, 04:30 AM)lumi Wrote: [ -> ]open stats .php and make an if else statement to check $mybb->user['usergroup']
assuming your admin group is gid 4 and you don't care what it looks like
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: stats.php 5297 2010-12-28 22:01:14Z Tomm $
 */

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'stats.php');

$templatelist = "stats,stats_thread";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;

// Load global language phrases
$lang->load("stats");

add_breadcrumb($lang->nav_stats);

$stats = $cache->read("stats");

if($stats['numthreads'] < 1 || $stats['numusers'] < 1)
{
	error($lang->not_enough_info_stats);
}

if($mybb->user['usergroup'] == "4"){

$plugins->run_hooks("stats_start");

$repliesperthread = my_number_format(round((($stats['numposts'] - $stats['numthreads']) / $stats['numthreads']), 2));
$postspermember = my_number_format(round(($stats['numposts'] / $stats['numusers']), 2));

// Get number of days since board start (might need improvement)
$query = $db->simple_select("users", "regdate", "", array('order_by' => 'regdate', 'limit' => 1));
$result = $db->fetch_array($query);
$days = (TIME_NOW - $result['regdate']) / 86400;
if($days < 1)
{
	$days = 1;
}
// Get "per day" things
$postsperday = my_number_format(round(($stats['numposts'] / $days), 2));
$threadsperday = my_number_format(round(($stats['numthreads'] / $days), 2));
$membersperday = my_number_format(round(($stats['numusers'] / $days), 2));

// Get forum permissions
$unviewableforums = get_unviewable_forums(true);
$fidnot = '1=1';
$unviewableforumsarray = array();
if($unviewableforums)
{
	$fidnot = "fid NOT IN ($unviewableforums)";
	$unviewableforumsarray = explode(',', $unviewableforums);
}

// Most replied-to threads
$most_replied = $cache->read("most_replied_threads");

if(!$most_replied)
{
	$cache->update_most_replied_threads();
	$most_replied = $cache->read("most_replied_threads", true);
}

if(!empty($most_replied))
{
	foreach($most_replied as $key => $thread)
	{
		if(!in_array("'{$thread['fid']}'", $unviewableforumsarray))
		{
			$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
			$numberbit = my_number_format($thread['replies']);
			$numbertype = $lang->replies;
			$thread['threadlink'] = get_thread_link($thread['tid']);
			eval("\$mostreplies .= \"".$templates->get("stats_thread")."\";");
		}
	}
}

// Most viewed threads
$most_viewed = $cache->read("most_viewed_threads");

if(!$most_viewed)
{
	$cache->update_most_viewed_threads();
	$most_viewed = $cache->read("most_viewed_threads", true);
}

if(!empty($most_viewed))
{
	foreach($most_viewed as $key => $thread)
	{
		if(!in_array("'{$thread['fid']}'", $unviewableforumsarray))
		{
			$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
			$numberbit = my_number_format($thread['views']);
			$numbertype = $lang->views;
			$thread['threadlink'] = get_thread_link($thread['tid']);
			eval("\$mostviews .= \"".$templates->get("stats_thread")."\";");
		}
	}
}

// Top forum
if(!empty($fidnot))
{
	$fidnot .= " AND";
}
$query = $db->simple_select("forums", "fid, name, threads, posts", "$fidnot type='f'", array('order_by' => 'posts', 'order_dir' => 'DESC', 'limit' => 1));
$forum = $db->fetch_array($query);
if(!$forum['posts'])
{
	$topforum = $lang->none;
	$topforumposts = $lang->no;
	$topforumthreads = $lang->no;
}
else
{
	$topforum = "<a href=\"".get_forum_link($forum['fid'])."\">{$forum['name']}</a>";
	$topforumposts = $forum['posts'];
	$topforumthreads = $forum['threads'];
}

// Today's top poster
$timesearch = TIME_NOW - 86400;
switch($db->type)
{
	case "pgsql":
		$query = $db->query("
			SELECT u.uid, u.username, COUNT(*) AS poststoday
			FROM ".TABLE_PREFIX."posts p
			LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
			WHERE p.dateline > $timesearch
			GROUP BY ".$db->build_fields_string("users", "u.")." ORDER BY poststoday DESC
			LIMIT 1
		");
		break;
	default:
		$query = $db->query("
			SELECT u.uid, u.username, COUNT(*) AS poststoday
			FROM ".TABLE_PREFIX."posts p
			LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
			WHERE p.dateline > $timesearch
			GROUP BY p.uid ORDER BY poststoday DESC
			LIMIT 1
		");
}
$user = $db->fetch_array($query);
if(!$user['poststoday'])
{
	$topposter = $lang->nobody;
	$topposterposts = $lang->no_posts;
}
else
{
	if(!$user['uid'])
	{
		$topposter = $lang->guest;
	}
	else
	{
		$topposter = build_profile_link($user['username'], $user['uid']);
	}
	$topposterposts = $user['poststoday'];
}

// What percent of members have posted?
$query = $db->simple_select("users", "COUNT(*) AS count", "postnum > 0");
$posters = $db->fetch_field($query, "count");
$havepostedpercent = my_number_format(round((($posters / $stats['numusers']) * 100), 2)) . "%";

$lang->todays_top_poster = $lang->sprintf($lang->todays_top_poster, $topposter, my_number_format($topposterposts));
$lang->popular_forum = $lang->sprintf($lang->popular_forum, $topforum, my_number_format($topforumposts), my_number_format($topforumthreads));

$stats['numposts'] = my_number_format($stats['numposts']);
$stats['numthreads'] = my_number_format($stats['numthreads']);
$stats['numusers'] = my_number_format($stats['numusers']);
$stats['newest_user'] = build_profile_link($stats['lastusername'], $stats['lastuid']);

$plugins->run_hooks("stats_end");
}

else{
	die('You are not permitted to view this page. Return: <a href="' . $mybb->settings["bburl"] . '">' . $mybb->settings["bburl"] . '</a>');
}
eval("\$stats = \"".$templates->get("stats")."\";");
output_page($stats);
?>
Thanks much for the example.
Looks like if add...

if($mybb->user['usergroup'] == "4")
{

...then only usergroup 4 (admin) should see all output of subsequent script until...

}
else{
    die('You are not permitted to view this page. Return: <a href="' . $mybb->settings["bburl"] . '">' . $mybb->settings["bburl"] . '</a>');
}

...kinda as I modified the 'code' below ?
But, it doesnt seem to make 'Board Statistics' disappear for any users.
Also, if it did disappear, would there be some kind of message displayed, and if so is that needed ?
Although, guess main question is, am I interpreting this correctly ?
Blush

(2014-07-28, 06:04 AM)lumi Wrote: [ -> ]assuming your admin group is gid 4 and you don't care what it looks like
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: stats.php 5297 2010-12-28 22:01:14Z Tomm $
 */

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'stats.php');

$templatelist = "stats,stats_thread";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;

// Load global language phrases
$lang->load("stats");

add_breadcrumb($lang->nav_stats);

$stats = $cache->read("stats");

if($stats['numthreads'] < 1 || $stats['numusers'] < 1)
{
	error($lang->not_enough_info_stats);
}

if($mybb->user['usergroup'] == "4"){

...all existing script between 'if' and 'else'...

}
else{
	die('You are not permitted to view this page. Return: <a href="' . $mybb->settings["bburl"] . '">' . $mybb->settings["bburl"] . '</a>');
}

eval("\$stats = \"".$templates->get("stats")."\";");
output_page($stats);
?>
your interpretation is perfect Smile
however your requirement needs modifying index.php file or index / index_stats template

lumi was referring to separate statistics page (like this) and your requirement is different

index.php file code segment for the Board Statistics starts with code like below
// Build the forum statistics to show on the index page.
if($mybb->settings['showindexstats'] != 0)


if you want to use the required condition in the templates then you can use template conditionals plugin
.
Thanks much for the clarification and learning experience with php 'if' !
Used the below at index.php and seems to work fine.
Hopefully the coding is correct.
Wondered about the dbl == signs, but T&E looks like that is necessary.
Also curious, how, if possible, might it be done if wanted to make it visible to more than 1 usergroup ?

// use 'if' below to make Board Statistics only viewable by Admin
if($mybb->user['usergroup'] == "4")
{

// Build the forum statistics to show on the index page.

if($mybb->settings['showindexstats'] != 0)
{
	// First, load the stats cache.
	$stats = $cache->read("stats");

	// Check who's the newest member.
	if(!$stats['lastusername'])
	{
		$newestmember = "no-one";
	}
	else
	{
		$newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']);
	}

	// Format the stats language.
	$lang->stats_posts_threads = $lang->sprintf($lang->stats_posts_threads, my_number_format($stats['numposts']), my_number_format($stats['numthreads']));
	$lang->stats_numusers = $lang->sprintf($lang->stats_numusers, my_number_format($stats['numusers']));
	$lang->stats_newestuser = $lang->sprintf($lang->stats_newestuser, $newestmember);

	// Find out what the highest users online count is.
	$mostonline = $cache->read("mostonline");
	if($onlinecount > $mostonline['numusers'])
	{
		$time = TIME_NOW;
		$mostonline['numusers'] = $onlinecount;
		$mostonline['time'] = $time;
		$cache->update("mostonline", $mostonline);
	}
	$recordcount = $mostonline['numusers'];
	$recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']);
	$recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']);

	// Then format that language string.
	$lang->stats_mostonline = $lang->sprintf($lang->stats_mostonline, my_number_format($recordcount), $recorddate, $recordtime);

	eval("\$forumstats = \"".$templates->get("index_stats")."\";");
}

// use } below to work with... if($mybb->user['usergroup'] == "4") { ...above
}

(2014-07-28, 09:08 AM).m. Wrote: [ -> ]your interpretation is perfect Smile
however your requirement needs modifying index.php file or index / index_stats template
lumi was referring to separate statistics page (like this) and your requirement is different
index.php file code segment for the Board Statistics starts with code like below
// Build the forum statistics to show on the index page.
if($mybb->settings['showindexstats'] != 0)

if you want to use the required condition in the templates then you can use template conditionals plugin
Change
// use 'if' below to make Board Statistics only viewable by Admin
if($mybb->user['usergroup'] == "4")
{

To

$allowedgroups = array(1,2,3,4);
if(in_array($mybb->user['usergroup'], $allowedgroups))
{

Each group id is separated by a comma in the array $allowedgroups.
.
Thanks much for the followup, very helpful !
Guess class is over Blush
Seems like Ive got the info needed for now and future use !
Take care all.

(2014-07-28, 06:46 PM)dragonexpert Wrote: [ -> ]Change
// use 'if' below to make Board Statistics only viewable by Admin
if($mybb->user['usergroup'] == "4")
{
To
$allowedgroups = array(1,2,3,4);
if(in_array($mybb->user['usergroup'], $allowedgroups))
{
Each group id is separated by a comma in the array $allowedgroups.
(2014-07-28, 06:46 PM)dragonexpert Wrote: [ -> ]Change
// use 'if' below to make Board Statistics only viewable by Admin
if($mybb->user['usergroup'] == "4")
{

To

$allowedgroups = array(1,2,3,4);
if(in_array($mybb->user['usergroup'], $allowedgroups))
{

Each group id is separated by a comma in the array $allowedgroups.

this would be better if you plan to allow groups like super mods to view it.