MyBB Community Forums

Full Version: Get Group ID's without going to PHPMYADMIN?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Every time I code custom plugins / scripts for my site.
I always have to go into PHPMYADMIN to get group ids.

I know I can easily just make a small php script to print all the Usergroups and GID's.

But maybe there should be a way for admins to see that info in AdminCP?
ACP > Users & Groups > Groups > *usergroup*

/admin/index.php?module=user-groups&action=edit&gid=2

The gid parameter is the id of the group.
Ohh never thought of looking at the url while editing a group. Thanks.
Just hover. If you have a good browser you'll likely see link in hover.
Might be a good idea to display this somewhere else. A lot of plugins are using GIDs for right management.
Agree, GID, UID, FID etc should all be visible somewhere. Yes, you can use the URL but this is not really an elegant solution.
(2013-01-03, 03:14 PM)Lennart Sauter Wrote: [ -> ]A lot of plugins are using GIDs for right management.

With a little trickery the plugin could automatically create a select-box which lists all of the available groups on that forum (the function is practically built into MyBB, you just need to make it work inside the settings page). I never understood why certain developers opted for the lazy route of forcing the admin to manually find out the GIDs and then place them into a comma-separated list, which is tedious to maintain when you're working with quite a lot of groups.

A hacky solution isn't elegant by any stretch of the imagination, but it works without the need to edit any of the core MyBB admin files.

Ideally since these types of data are used quite a lot, MyBB should have a setting-type which does the work for you (as well as one for a list of forums, which is also already built), but not everything is perfect.
Quote:I never understood why certain developers opted for the lazy route of forcing the admin to manually find out the GIDs and then place them into a comma-separated list, which is tedious to maintain when you're working with quite a lot of groups.

Actually that's a good idea for a built in setting function. It could be a setting "type". You could do FID and GID which will create a selectable box with appropriate html. And you could do FIDm (multiple select) or FIDs (single select).

If MyBB built that into the system I think it would save some serious headaches for devs and admin end-users.
(2013-01-03, 04:37 PM)labrocca Wrote: [ -> ]If MyBB built that into the system I think it would save some serious headaches for devs and admin end-users.

Indeed. There's already built-in methods through the Form object for stuff like that, which are meant to be used in custom Admin pages.

The methods basically allow select boxes to be generated that are automatically filled in with the usergroups or forums (generate_group_select and generate_forum_select, respectively) and accept custom options for multiselect, so I'd assume porting them over for use as a setting-type would be pretty trivial.

It can already be done with through plugins by using the PHP setting-type as I mentioned, but the method is really hacky and results in some pretty ugly code. The code can be hidden away with functions, but it's still a lot of messing around.
here is my Patches export that makes the edits to the groups page in the ACP. it adds the group id and the group's formatting

[attachment=28184]

btw, the functions you are asking for are already in the ACP. Not useful for front-end plugins, but i the ACP you can use these

edit: as part of the $form object

	/**
	 * Generate a forum selection box.
	 *
	 * @param string The name of the selection box.
	 * @param mixed Array/string of the selected items.
	 * @param array Array of options (pid, main_option, multiple)
	 * @param boolean Is this our first iteration of this function?
	 * @return string The built select box.
	 */
	function generate_forum_select($name, $selected, $options=array(), $is_first=1)
	{
		global $fselectcache, $forum_cache, $selectoptions;
		
		if(!$selectoptions)
		{
			$selectoptions = '';
		}
		
		if(!$options['depth'])
		{
			$options['depth'] = 0;
		}
		
		$options['depth'] = intval($options['depth']);
		
		if(!$options['pid'])
		{
			$pid = 0;
		}
		
		$pid = intval($options['pid']);
		
		if(!is_array($fselectcache))
		{
			if(!is_array($forum_cache))
			{
				$forum_cache = cache_forums();
			}
	
			foreach($forum_cache as $fid => $forum)
			{
				$fselectcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
			}
		}
		
		if($options['main_option'] && $is_first)
		{
			$select_add = '';
			if($selected == -1)
			{
				$select_add = " selected=\"selected\""; 
			}
			
			$selectoptions .= "<option value=\"-1\"{$select_add}>{$options['main_option']}</option>\n";
		}
		
		if(is_array($fselectcache[$pid]))
		{
			foreach($fselectcache[$pid] as $main)
			{
				foreach($main as $forum)
				{
					if($forum['fid'] != "0" && $forum['linkto'] == '')
					{
						$select_add = '';
	
						if(!empty($selected) && ($forum['fid'] == $selected || (is_array($selected) && in_array($forum['fid'], $selected))))
						{
							$select_add = " selected=\"selected\"";
						}
						
						$sep = '';
						if(isset($options['depth']))
						{
							$sep = str_repeat("&nbsp;", $options['depth']);
						}
						
						$style = "";
						if($forum['active'] == 0)
						{
							$style = " style=\"font-style: italic;\"";
						}

						$selectoptions .= "<option value=\"{$forum['fid']}\"{$style}{$select_add}>".$sep.htmlspecialchars_uni(strip_tags($forum['name']))."</option>\n";
	
						if($forum_cache[$forum['fid']])
						{
							$options['depth'] += 5;
							$options['pid'] = $forum['fid'];
							$this->generate_forum_select($forum['fid'], $selected, $options, 0);
							$options['depth'] -= 5;
						}
					}
				}
			}
		}
		
		if($is_first == 1)
		{
			if(!isset($options['multiple']))
			{
				$select = "<select name=\"{$name}\"";
			}
			else
			{
				$select = "<select name=\"{$name}\" multiple=\"multiple\"";
			}
			if(isset($options['class']))
			{
				$select .= " class=\"{$options['class']}\"";
			}
			if(isset($options['id']))
			{
				$select .= " id=\"{$options['id']}\"";
			}
			if(isset($options['size']))
			{
				$select .= " size=\"{$options['size']}\"";
			}
			$select .= ">\n".$selectoptions."</select>\n";
			$selectoptions = '';
			return $select;
		}
	}
	
	/**
	 * Generate a group selection box.
	 *
	 * @param string The name of the selection box.
	 * @param mixed Array/string of the selected items.
	 * @param array Array of options (class, id, multiple)
	 * @return string The built select box.
	 */
	function generate_group_select($name, $selected=array(), $options=array())
	{
		global $cache;
		
		$select = "<select name=\"{$name}\"";
		
		if(isset($options['multiple']))
		{
			$select .= " multiple=\"multiple\"";
		}
		
		if(isset($options['class']))
		{
			$select .= " class=\"{$options['class']}\"";
		}
		
		if(isset($options['id']))
		{
			$select .= " id=\"{$options['id']}\"";
		}
		
		if(isset($options['size']))
		{
			$select .= " size=\"{$options['size']}\"";
		}
		
		$select .= ">\n";
		
		$groups_cache = $cache->read('usergroups');
		foreach($groups_cache as $group)
		{
			$selected_add = "";
			if(is_array($selected))
			{
				if(in_array($group['gid'], $selected))
				{
					$selected_add = " selected=\"selected\"";
				}
			}
			
			$select .= "<option value=\"{$group['gid']}\"{$selected_add}>".htmlspecialchars_uni(strip_tags($group['title']))."</option>";
		}
		
		$select .= "</select>";
		
		return $select;
	}
	
Pages: 1 2