MyBB Community Forums

Full Version: Enhanced Account Switcher | Accountlist only show x groups?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Out of curiosity is there a way to not show certain usergroups in the accountlist.php that comes with the Enhanced Account Switcher plugin?

For example:

I have these usergroups: 
Owner
Admin
Registered
Pending
Inactive

I do NOT want this usergroup to show in accountlist.php:
Inactive

So in the end, these usergroups will be the only ones to show in accountlist.php:
Owner
Admin
Registered
Pending
If a master account is in a usergroup you want to hide, in accountlist.php find (~lines 216-218)
$master = get_user($master_acc);
if (!empty($master['uid']))
{

 
and add below:

if (is_member(X, $master['uid'])) continue;


Replace X with the group-id of your Inactive group.
If it's in the Inactive group, the master account and all it's attached accounts are not displayed now in the accountlist.

For the attached accounts find (~lines 267-268)
if ($account['as_uid'] == $master_acc)
{

and add below:
if (is_member(X, $account['uid'])) continue;

Replace X with the group-id of your Inactive group again.
Now if an attached account is in the Inactive group, it's hidden in the accountlist.
You are a saint! Thank you!

I will test this out as soon as possible. Smile
Would it be possible to add in more than just one group ID?

Say an inactive group and a pending group?
Yes, instead of
if (is_member(X, $account['uid'])) continue; 

use:
if (is_member(array(X,Y,Z), $account['uid'])) continue; 

Just replace X,Y;Z with the ID's of your groups.
Thank you much for all the help!!
Alrighty, so I finally got around to putting this coding in but unfortunately when I put it in it made the accountlist.php page not even show at all.

So I must be doing something wrong.

Added this in:
$master = get_user($master_acc);
			if (!empty($master['uid']))
			{
			if (is_member(11, $master['uid'])) continue; 
				$profilefield = ' ';
				$hidden = 0;
				// Hide users with privacy setting enabled

And this:
if ($account['as_uid'] == $master_acc)
				{
				if (is_member(11, $account['uid'])) continue; 
					$profilefield = ' ';
					// Hide users with privacy setting enabled
Your code seems correct.
Did you edit something else in accountlist.php?
If it's not working, please attach your accountlist.php here.
I made one slight edit so now the page will actually appear but no one shows up on the list:
<?php
/**
 * Enhanced Account Switcher for MyBB 1.8
 * Copyright (c) 2012-2017 doylecc
 * http://mybbplugins.tk
 *
 * based on the Plugin:
 * Account Switcher 1.0 by Harest
 * Copyright (c) 2011 Harest
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

define("KILL_GLOBALS", 1);
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'accountlist.php');
define("EAS_PROFILEFIELD", 1);
//define("NO_ONLINE", 1); // Remove from online list

$templatelist = 'accountswitcher_accountlist,accountswitcher_accountlist_master,accountswitcher_accountlist_attached,accountswitcher_accountlist_shared,accountswitcher_accountlist_endbit,accountswitcher_profilefield,accountswitcher_avatar,accountswitcher_profilefield_head,accountswitcher_profilefield_attached';

require_once "./global.php";

// Deny guest access
if ($mybb->user['uid'] == 0)
{
	error_no_permission();
}

// Redirect back if accountlist disabled
if ($mybb->settings['aj_list'] != 1)
{
	redirect("index.php", $lang->aj_list_disabled);
}

// Load language file
$lang->load("accountswitcher");

// Add breadcrumb navigation
add_breadcrumb("Member Character Index");

// Declare variables
$masters = $masters_uid = $masters_ad = $masters_smod = $masters_mod = $masters_reg = $masters_share = $masters_shared = $masters_attached = array();
$count = 0;
$accountlist = $accountlist_masterbit = $masterlink = $attachedlink = $profile_head = $profilefield_attached = $profile_field = $profile_name = $viewableby = $as_accountlist_hidden = '';
$colspan_head = 'colspan="2"';
$colspan = '';
$master_width = 'width="50%"';
$avadims = 'width="auto" height="44"';
$tb_row = '</tr>';

// Incoming results per page?
$mybb->input['perpage'] = $mybb->get_input('perpage', MyBB::INPUT_INT);
if ($mybb->input['perpage'] > 0 && $mybb->input['perpage'] <= 50)
{
	$per_page = $mybb->input['perpage'];
}
else
{
	$per_page = $mybb->input['perpage'] = 35;
}

// Page
$page = $mybb->get_input('page', MyBB::INPUT_INT);
if ($page && $page > 0)
{
	$start = ($page - 1) * $per_page;
}
else
{
	$start = 0;
	$page = 1;
}

// If profile field enabled, change colspans and get user fields
if ($mybb->settings['aj_profilefield'] == 1 && (int)$mybb->settings['aj_profilefield_id'] > 0)
{
	$colspan_head = 'colspan="4"';
	$colspan = 'colspan="2"';
	$tb_row = '';
}

// Load account data from cache
$accounts = $eas->accountswitcher_cache;

if (is_array($accounts))
{
	// Find all master accounts
	foreach ($accounts as $key => $account)
	{
		$masters_uid[] = $account['as_uid'];
	}

	$masters_uid = array_unique($masters_uid);
	$masters_uid = array_values($masters_uid);

	// Sort Master Accounts by usergroup: 1. Admins, 2. Super-Mods, 3. Mods, 4. Other
	if (isset($mybb->settings['aj_sortgroup']) && $mybb->settings['aj_sortgroup'] == 1)
	{
		foreach ($masters_uid as $master_uid)
		{
			if (is_member(4, $master_uid) && $master_uid != 0) {
				$masters_ad[] = $master_uid;
			} elseif (is_member(3, $master_uid) && $master_uid != 0) {
				$masters_smod[] = $master_uid;
			} elseif (is_member(6, $master_uid) && $master_uid != 0) {
				$masters_mod[] = $master_uid;
			} elseif ($master_uid != 0) {
				$masters_reg[] = $master_uid;
			} else {
				$masters_share[] = $master_uid;
			}
		}
	}
	else
	{
		foreach ($masters_uid as $master_uid)
		{
			if ($master_uid != 0) {
				$masters_attached[] = $master_uid;
			} else {
				$masters_shared[] = $master_uid;
			}
		}
	}

	// Sort master accounts by username
	if (isset($mybb->settings['aj_sortuser']) && $mybb->settings['aj_sortuser'] == 'uname')
	{
		$m_ad_username = $m_smod_username = $m_mod_username = $m_username = $m_ad_uid = $m_smod_uid = $m_mod_uid = $m_uid =array();
		// Sort by group and username
		if (isset($mybb->settings['aj_sortgroup']) && $mybb->settings['aj_sortgroup'] == 1)
		{
			if (is_array($masters_ad))
			{
				foreach ($masters_ad as $key => $master_ad)
				{
					$master_admin = get_user($master_ad);
					$m_ad_uid[$key] = $master_admin['uid'];
					$m_ad_username[$key] = $master_admin['username'];
				}
				array_multisort($m_ad_username, SORT_ASC, $m_ad_uid, SORT_ASC, $masters_ad);
			}
			if (is_array($masters_smod))
			{
				foreach ($masters_smod as $key => $master_smod)
				{
					$master_super = get_user($master_smod);
					$m_smod_uid[$key] = $master_super['uid'];
					$m_smod_username[$key] = $master_super['username'];
				}
				array_multisort($m_smod_username, SORT_ASC, $m_smod_uid, SORT_ASC, $masters_smod);
			}
			if (is_array($masters_mod))
			{
				foreach ($masters_mod as $key => $master_mod)
				{
					$master_md = get_user($master_mod);
					$m_mod_uid[$key] = $master_md['uid'];
					$m_mod_username[$key] = $master_md['username'];
				}
				array_multisort($m_mod_username, SORT_ASC, $m_mod_uid, SORT_ASC, $masters_mod);
			}
			if (is_array($masters_reg))
			{
				foreach ($masters_reg as $key => $master_user)
				{
					$master = get_user($master_user);
					$m_uid[$key] = $master['uid'];
					$m_username[$key] = $master['username'];
				}
				array_multisort($m_username, SORT_ASC, $m_uid, SORT_ASC, $masters_reg);
			}
		}
		else // Sort all by username
		{
			if (is_array($masters_attached))
			{
				foreach ($masters_attached as $key => $master_uid)
				{
					$master = get_user($master_uid);
					$m_uid[$key] = $master['uid'];
					$m_username[$key] = $master['username'];
				}
				array_multisort($m_username, SORT_ASC, $m_uid, SORT_ASC, $masters_attached);
			}
		}
	}
	// Sort Master Accounts by usergroup: 1. Admins, 2. Super-Mods, 3. Mods, 4. Other
	if (isset($mybb->settings['aj_sortgroup']) && $mybb->settings['aj_sortgroup'] == 1)
	{
		$masters = array_merge($masters_ad, $masters_smod, $masters_mod, $masters_reg, $masters_share);
	}
	else
	{
		$masters = array_merge($masters_attached, $masters_shared);
	}

	// Count all master accounts
	$num_masters = count($masters);
	// Show only number of master acounts per page
	$masters = array_slice($masters, $start, $per_page);

	if (is_array($masters))
	{
		foreach ($masters as $master_acc)
		{
			$master = get_user($master_acc);
			if (!empty($master['uid']))
			{
			if (is_member(array(2,5,10,11), $account['uid'])) continue;
				$profilefield = '&nbsp;';
				$hidden = 0;
				// Hide users with privacy setting enabled
				if (($mybb->usergroup['cancp'] != 1 && $mybb->user['uid'] != $master['uid'] && $mybb->settings['aj_privacy'] == 1 && $master['as_privacy'] == 1)
				&& (($mybb->user['as_uid'] > 0 && $mybb->user['as_uid'] != $master['uid'])
				|| ($mybb->user['as_uid'] == 0 && $mybb->user['uid'] != $master['as_uid'])))
				{
					$masterAvatar = $eas->attached_avatar($mybb->settings['default_avatar'], $mybb->settings['useravatardims']);
					$masterlink = $masterAvatar.$lang->aj_hidden_master;
				}
				else
				{
					// Display master account
					$attachedPostUser = htmlspecialchars_uni($master['username']);
					$masterAvatar = $eas->attached_avatar($master['avatar'], $master['avatardimensions']);
					$masterlink = '&nbsp;&nbsp;<span style="font-weight: bold;" title="Master Account">'.build_profile_link(format_name($attachedPostUser, $master['usergroup'], $master['displaygroup']), (int)$master['uid']).'</span>';
					// Get profile field
					if ($mybb->settings['aj_profilefield'] == 1 && (int)$mybb->settings['aj_profilefield_id'] > 0)
					{
						$master_width = 'width="28%"';
						$profile_field = $eas->get_profilefield($master['uid']);
					}
				}
				$accountlist_masterbit .= eval($templates->render('accountswitcher_accountlist_master'));
			}
			else
			{
				// Display shared account
				if ($account['as_buddyshare'] != 0)
				{
					$lang->as_isshared = $lang->as_isshared_buddy;
				}
				if ($mybb->settings['aj_profilefield'] == 1 && (int)$mybb->settings['aj_profilefield_id'] > 0)
				{
					$profilefield = '&nbsp;';
					$profile_field = eval($templates->render('accountswitcher_profilefield'));
				}
				$accountlist_masterbit .= eval($templates->render('accountswitcher_accountlist_shared'));
			}

			// Sort accounts by first, secondary, shared accounts and by uid or username
			$accounts = $eas->sort_attached();

			// Get all attached accounts
			foreach ($accounts as $key => $account)
			{
				if ($account['as_uid'] == $master_acc)
				{
				if (is_member(array(2,5,10,11), $account['uid'])) continue; 
					$profilefield = '&nbsp;';
					// Hide users with privacy setting enabled
					if ($mybb->usergroup['cancp'] != 1 && $mybb->user['uid'] != $account['uid'] && $mybb->settings['aj_privacy'] == 1 && $account['as_privacy'] == 1)
					{
						if (($mybb->user['as_uid'] != 0 && $mybb->user['as_uid'] != $account['as_uid'] && $mybb->user['as_uid'] != $account['uid'])
						|| ($mybb->user['as_uid'] == 0 && $mybb->user['uid'] != $account['as_uid']))
						{
							++$hidden;
							continue;
						}
					}
					++$count;
					if ($count > 0)
					{
						// Display attached account
						$attachedPostUser = htmlspecialchars_uni($account['username']);
						if ($mybb->settings['aj_sharestyle'] == 1 && $account['as_share'] != 0)
						{
							$attachedbit = eval($templates->render('accountswitcher_shared_accountsbit'));
						}
						elseif ($mybb->settings['aj_secstyle'] == 1 && $account['as_sec'] != 0 && $account['as_share'] == 0)
						{
							$user_sec_reason = htmlspecialchars_uni($account['as_secreason']);
							$attachedbit = eval($templates->render('accountswitcher_sec_accountsbit'));
						}
						else
						{
							$attachedbit = format_name($attachedPostUser, (int)$account['usergroup'], (int)$account['displaygroup']);
						}
						$attachedAvatar = $eas->attached_avatar($account['avatar'], $account['avatardimensions']);
						$attachedlink = $attachedAvatar.'&nbsp;&nbsp;'.build_profile_link($attachedbit, (int)$account['uid']);
						// Get profile field
						if ($mybb->settings['aj_profilefield'] == 1 && (int)$mybb->settings['aj_profilefield_id'] > 0)
						{
							$profile_field = $eas->get_profilefield($account['uid'], true);
						}
						$accountlist_masterbit .= eval($templates->render('accountswitcher_accountlist_attached'));
					}
				}
			}
			// Show number of hidden attached accounts
			if ($hidden > 0)
			{
				$as_accountlist_hidden = '<tr><td class="trow1" style="padding: 8px 0 0 65px;">'.$lang->sprintf($lang->aj_hidden, $hidden).'</td></tr>';
				$accountlist_masterbit .= eval($templates->render('accountswitcher_accountlist_endbit'));
			}
			else
			{
				$as_accountlist_hidden = '';
				$accountlist_masterbit .= eval($templates->render('accountswitcher_accountlist_endbit'));
			}
		}
	}

	// Multipage
	$search_url = htmlspecialchars_uni("accountlist.php?perpage={$mybb->input['perpage']}");
	$multipage = multipage($num_masters, $per_page, $page, $search_url);
}

// Output accountlist
$accountlist .= eval($templates->render('accountswitcher_accountlist'));

output_page($accountlist);
2 is the ID of the "Registered" group. If your master accounts are no admins or mods etc., no user is shown in the accountlist now.
Pages: 1 2