Jump to the post that solved this thread.
Solved: 7 Years, 11 Months ago Display all members of a usergroup on a custom page?
#1
Solved: 7 Years, 11 Months ago
I've got PageManager installed and I would like to display all users of a certain usergroup on a custom page. What's the PHP Code I need to use to display all the members of that particular usergroup on that page?

Help would be appreciated as I'm stuck here. 

I tried looking around on Google but I couldn't find anything about it.

Thanks! Big Grin

Bumpy bump
Reply
#2
Solved: 7 Years, 11 Months ago
* Bumping this as I'm curious as well.

I'm going to assume automatically that you'll have to use PHP and NOT use the MyBB templates, so it may work better as a plugin UNLESS you're okay with that page not displaying like the rest of the forum.

I know it would require pulling users from the database, so I'm curious what the function would be as well.
Reply
#3
Solved: 7 Years, 11 Months ago
It's not a big deal Wink

I attached a simple PageManager page with a desired list.
You can change the listed user group member by editing the query "usergroup IN ('2', '4') parameters.

Simple import the page on PageManager in ACP

.xml   usergroupmembers.xml (Size: 1.76 KB / Downloads: 339)
Reply
#4
Solved: 7 Years, 11 Months ago
(2017-02-07, 08:56 PM)SvePu Wrote: It's not a big deal Wink

I attached a simple PageManager page with a desired list.
You can change the listed user group member by editing the query "usergroup IN ('2', '4') parameters.

Simple import the page on PageManager in ACP

I will try this.

Edit: Doesn't even work. Shows a blank page.
Reply
#5
Solved: 7 Years, 11 Months ago
(2017-02-08, 03:07 AM)Rory Mercury Wrote: I will try this.

Edit: Doesn't even work. Shows a blank page.

Do you have enabled the imported page on PageManager ??
Reply
#6
Solved: 7 Years, 11 Months ago
<?xml version="1.0" encoding="UTF-8"?>
<pagemanager version="1.5.2" xmlns="http://mods.mybb.com/view/page-manager">
	<page>
		<name><![CDATA[UserGroupMember]]></name>
		<url><![CDATA[usergroupmembers]]></url>
		<template><![CDATA[PD9waHANCg0KZ2xvYmFsICRoZWFkZXJpbmNsdWRlLCAkaGVhZGVyLCAkdGhlbWUsICRmb290ZXIsICRkYjsNCg0KJGFsdGJnID0gYWx0X3Ryb3coKTsNCiR1c2VybGlzdCA9ICcnOw0KJHF1ZXJ5ID0gJGRiLT5zaW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z4NCnskZm9vdGVyfQ0KPC9ib2R5Pg0KPC9odG1sPic7DQoNCiR0ZW1wbGF0ZT1zdHJfcmVwbGFjZSgiXCciLCAiJyIsIGFkZHNsYXNoZXMoJHRlbXBsYXRlKSk7DQoNCmFkZF9icmVhZGNydW1iKCRwYWdlc1snbmFtZSddKTsNCg0KZXZhbCgiXCRwYWdlPVwiIi4kdGVtcGxhdGUuIlwiOyIpOw0KDQpvdXRwdXRfcGFnZSgkcGFnZSk7DQoNCj8+]]></template>
		<checksum>dccc8f86d3ec270dd2cb622b5dda3e80</checksum>
	</page>
</pagemanager>

This is what it looks like for me, is it supposed to look like that?
Reply
#7
Solved: 7 Years, 11 Months ago
Import the xml file with PageManager plugin and you'll see the clear code.....exported page XMLs are encoded.

But here also is the script for the PM page (without using MyBB Templates):
<?php

global $headerinclude, $header, $theme, $footer, $db;

$altbg = alt_trow();
$userlist = '';
$query = $db->simple_select("users", "*", "usergroup IN ('2','4')", array("order_by" => 'username', "order_dir" => 'ASC'));
 
 while($users = $db->fetch_array($query))
 {
 $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
 
 $userlist .= '<tr><td class="'.$altbg.'">'.$username.'</td></tr>';
 $altbg = alt_trow();
 }

$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder">
<thead>
<tr>
<td class="thead">
<strong>'.$pages['name'].'</strong>
</td>
</tr>
</thead>
<tbody>
{$userlist}
</tbody>
</table>
<br />
{$footer}
</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>
Reply
#8
Solved: 7 Years, 11 Months ago
Out of curiosity, would this work as a page outside of the page manager?

And would it be possible to add usergroup names and the numbers of how many accounts are in that particular usergroup?
Reply
#9
Solved: 7 Years, 11 Months ago
A single page would look like that:
<?php
define("IN_MYBB", 1);
require_once "./global.php";

$altbg = alt_trow();
$userlist = '';
$num = 1;
$query = $db->query("SELECT g.title AS groupname, u.*
 FROM ".TABLE_PREFIX."users u
 LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=u.usergroup)
 WHERE usergroup IN ('2')
 ORDER BY username ASC");
 
 while($users = $db->fetch_array($query))
{
 $usergroupname = htmlspecialchars_uni($users['groupname']);
 $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
 $userlist .= '<tr><td style="text-align:center;" class="'.$altbg.'">'.$num.'</td><td class="'.$altbg.'">'.$username.'</td></tr>';
 $altbg = alt_trow();
 $num++;
}
 
add_breadcrumb("Member of Usergroup: {$usergroupname}", "usergroupmember.php");

$pagetemplate = "<html>
<head>
<title>".$settings['bbname']." - UsergroupMember</title>
{$headerinclude}
<style type=\"text/css\">
.center{
 vertical-align: middle;
 text-align:center;
}
</style>
</head>
<body>
{$header}
<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
 <thead>
 <tr>
 <td class=\"thead\" colspan=\"2\"><strong>Usergroup: {$usergroupname}</strong></td>
 </tr>
 </thead>
 <tbody>
 <tr>
 <td class=\"tcat\" width=\"5%\" style=\"text-align:center;\" ><strong>Nr.</strong></td>
 <td class=\"tcat\"><strong>User</strong></td>
 </tr>
 {$userlist}
 <tr>
 <td class=\"tfoot\" colspan=\"2\"></td>
 </tr>
 </tbody>
</table>
{$footer}
</body>
</html>";

$pagetemplate = str_replace("\\'", "'", addslashes($pagetemplate));

eval("\$page = \"".$pagetemplate."\";");

output_page($page); 
?>


Attached Files
.php   usergroupmember.php (Size: 1.73 KB / Downloads: 116)
Reply
#10
Solved: 7 Years, 11 Months ago
Doesn't work?
<?php
define("IN_MYBB", 1);
require_once "./global.php";

$altbg = alt_trow();
$userlist = '';
$num = 1;
$query = $db->query("SELECT g.title AS groupname, u.*
 FROM ".TABLE_PREFIX."users u
 LEFT JOIN ".TABLE_PREFIX."usergroups g ON (g.gid=u.usergroup)
 WHERE usergroup IN ('12','13','14','15','16')
 ORDER BY username ASC");
 
 while($users = $db->fetch_array($query))
{
 $usergroupname = htmlspecialchars_uni($users['groupname']);
 $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
 $userlist .= '<tr><td style="text-align:center;" class="'.$altbg.'">'.$num.'</td><td class="'.$altbg.'">'.$username.'</td></tr>';
 $altbg = alt_trow();
 $num++;
}
 
add_breadcrumb("Member of Usergroup: {$usergroupname}", "usergroupmember.php");

$pagetemplate = "<html>
<head>
<title>".$settings['bbname']." - UsergroupMember</title>
{$headerinclude}
<style type=\"text/css\">
.center{
 vertical-align: middle;
 text-align:center;
}
</style>
</head>
<body>
{$header}
<table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
 <thead>
 <tr>
 <td class=\"thead\" colspan=\"2\"><strong>Usergroup: {$usergroupname}</strong></td>
 </tr>
 </thead>
 <tbody>
 <tr>
 <td class=\"tcat\" width=\"5%\" style=\"text-align:center;\" ><strong>Nr.</strong></td>
 <td class=\"tcat\"><strong>User</strong></td>
 </tr>
 {$userlist}
 <tr>
 <td class=\"tfoot\" colspan=\"2\"></td>
 </tr>
 </tbody>
</table>
{$footer}
</body>
</html>";

$pagetemplate = str_replace("\\'", "'", addslashes($pagetemplate));

eval("\$page = \"".$pagetemplate."\";");

output_page($page); 
?>
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)