vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   List members of additional usergroup (https://vborg.vbsupport.ru/showthread.php?t=267098)

Spyike 07-19-2011 08:24 PM

List members of additional usergroup
 
I am attempting to have a page which lists all users in a usergroup (additional usergrou). I realize I am able to do so via ACP, but I wish to have this list accessible to moderators.

I have the following code below, but am not sure where lies the error.. any help is appreciated.


Code:

<?php
$groupid = 43;
$users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                  WHERE usergroupid = $groupid");
$str = '';
$sep = '';
while ($user = $vbulletin->db->fetch_array($users))
{
    $str .= $sep . $user['username'];
    $sep = ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users); 
echo "Market Banned: $str"; 
?>


kh99 07-19-2011 08:33 PM

What happens, do you just get no user names? Is 43 a secondary user group, by any chance? If so I think you'd want

Code:

WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids)

Spyike 07-19-2011 09:09 PM

Quote:

Originally Posted by kh99 (Post 2222592)
What happens, do you just get no user names? Is 43 a secondary user group, by any chance? If so I think you'd want

Code:

WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids)

It is an additional usergroup, the error I receive is:
Fatal error: Call to a member function query_read() on a non-object in mban.php on line 3

Will report back with your edit.

Edit:
Code:

<?php
$groupid = 43;
$users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                  WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids);
$str = '';
$sep = '';
while ($user = $vbulletin->db->fetch_array($users))
{
    $str .= $sep . $user['username'];
    $sep = ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users); 
echo "Market Banned: $str"; 
?>

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in mban.php on line 9

kh99 07-19-2011 09:19 PM

The error you were getting is because the db object isn't defined, which usually is because $vbulletin isn't in scope. The new error is because you're missing a close quote on the query string. Try this:

PHP Code:

<?php 
global $vbulletin;

$groupid 43;
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)";
$str '';
$sep '';
while (
$user $vbulletin->db->fetch_array($users))
{
    
$str .= $sep $user['username'];
    
$sep ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users);  
echo 
"Market Banned: $str";  
?>


That assumes that what you posted is only part of a page (like it's included or it's plugin code or something). If you're trying to make a stand-alone page then you need to inlucde global.php. (If you are trying to make a page you might want to look at this: https://vborg.vbsupport.ru/showthread.php?t=228112).

Spyike 07-19-2011 09:52 PM

Quote:

Originally Posted by kh99 (Post 2222616)
The error you were getting is because the db object isn't defined, which usually is because $vbulletin isn't in scope. The new error is because you're missing a close quote on the query string. Try this:

PHP Code:

<?php 
global $vbulletin;

$groupid 43;
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)";
$str '';
$sep '';
while (
$user $vbulletin->db->fetch_array($users))
{
    
$str .= $sep $user['username'];
    
$sep ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users);  
echo 
"Market Banned: $str";  
?>


That assumes that what you posted is only part of a page (like it's included or it's plugin code or something). If you're trying to make a stand-alone page then you need to inlucde global.php. (If you are trying to make a page you might want to look at this: https://vborg.vbsupport.ru/showthread.php?t=228112).

I am just looking to have a page that displays those users so moderators can have it readily available if needed. I have created the template and page as shown in the tutorial you linked; however, I am not sure where to place the original code snipped you posted above as I cannot put it in the template itself. Would I need to create a plugin and include that in the template? If so, what hook do I need to use and what would I do?
Thanks

kh99 07-19-2011 10:02 PM

You should be able to take this part of the code:

PHP Code:

$groupid 43
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user 
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"
$str ''
$sep ''
while (
$user $vbulletin->db->fetch_array($users)) 

    
$str .= $sep $user['username']; 
    
$sep ', '

// $str is comma separated list of users in $groupid 
$vbulletin->db->free_result($users); 


and put it where the tutorial says "// ###### YOUR CUSTOM CODE GOES HERE #####". Then instead of using echo, you'd probably want to register $str as a variable in your template like:

HTML Code:

$templater->register('str', $str);
(you can see where these go in the example code), and then use it in a tag in the template like {vb:raw str}.

Spyike 07-19-2011 10:26 PM

Quote:

Originally Posted by kh99 (Post 2222633)
You should be able to take this part of the code:

PHP Code:

$groupid 43
$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user 
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"
$str ''
$sep ''
while (
$user $vbulletin->db->fetch_array($users)) 

    
$str .= $sep $user['username']; 
    
$sep ', '

// $str is comma separated list of users in $groupid 
$vbulletin->db->free_result($users); 


and put it where the tutorial says "// ###### YOUR CUSTOM CODE GOES HERE #####". Then instead of using echo, you'd probably want to register $str as a variable in your template like:

HTML Code:

$templater->register('str', $str);
(you can see where these go in the example code), and then use it in a tag in the template like {vb:raw str}.

Now getting a syntax error :/

marketbanned.php contents vvv
Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'mban');
define('CSRF_PROTECTION', true); 
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('mbanned',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits = construct_navbits(array('' => 'Market Banned Users'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Market Banned Users';
$groupid = 43;
$users = $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user
                  WHERE usergroupid = $groupid OR FIND_IN_SET($groupid, membergroupids)";
$str = '';
$sep = '';
while ($user = $vbulletin->db->fetch_array($users))
{
    $str .= $sep . $user['username'];
    $sep = ', ';
}
// $str is comma separated list of users in $groupid
$vbulletin->db->free_result($users); 
$templater->register('str', $str);

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater = vB_Template::create('mbanned');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

?>

mbanned template contents vv
Code:

{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
   
    {vb:raw header}
   
    {vb:raw navbar}
   
    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
   
    <h2 class="blockhead">Title</h2>
    <div class="blockbody">
      <div class="blockrow">
    {vb:raw str}.
      </div>
    </div>
   
    {vb:raw footer}
  </body>
</html>


kh99 07-19-2011 10:33 PM

My fault, there's a missing ')' on the query line so it should be

PHP Code:

$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user  
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"); 


also, you want to move your $templater->register('str', $str) down to where the other $templater->register() lines are.

Spyike 07-20-2011 12:20 AM

Quote:

Originally Posted by kh99 (Post 2222644)
My fault, there's a missing ')' on the query line so it should be

PHP Code:

$users $vbulletin->db->query_read("SELECT username FROM ".TABLE_PREFIX."user  
                   WHERE usergroupid = 
$groupid OR FIND_IN_SET($groupid, membergroupids)"); 


also, you want to move your $templater->register('str', $str) down to where the other $templater->register() lines are.

Worked fabulously! Thank you!

Lastly, instead of seperating these users with commas , how would I go about doing so with line breaks rather than ' , ' ? I also attempted to add a conditional to the template to only display the str output to certain usergroups, but it was unsuccessful. Would the condition need to be done in the PHP file rather than in the template?

Thanks again for all your help

HMBeaty 07-20-2011 12:22 AM

Quote:

Originally Posted by Spyike (Post 2222684)
Worked fabulously! Thank you!

Lastly, instead of seperating these users with commas , how would I go about doing so with line breaks rather than ' , ' ? I also attempted to add a conditional to the template to only display the str output to certain usergroups, but it was unsuccessful. Would the condition need to be done in the PHP file rather than in the template?

Thanks again for all your help

Pretty sure using
HTML Code:

<br />
would work

--------------- Added [DATE]1311128579[/DATE] at [TIME]1311128579[/TIME] ---------------

so just change
PHP Code:

$sep ', '

to
PHP Code:

$sep '<br />'



All times are GMT. The time now is 11:20 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02758 seconds
  • Memory Usage 1,818KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (3)bbcode_html_printable
  • (8)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete