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
(2013-01-03, 06:39 PM)pavemen Wrote: [ -> ]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



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;
	}
	

Thank you for this, I would really like this to be built into myBB in a future version. Or something that makes it this easy.
(2013-01-03, 06:39 PM)pavemen Wrote: [ -> ]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

Pretty sure I already said that. Twice.

And you can actually gain access to the form object as a setting in a plugin by utilizing the PHP type without the need to make any edits to core files (which I also mentioned).

Making the changes through patches is more work for the user. I'll share my method for generating the boxes solely in plugins when I'm next at a computer. It's not eloquent, but it works for the most part.
i did not read your first reply as saying the functions were actually there, just really close to being there, "practically built into MyBB" you said.

for some reason I did not see you last post and i originally replied via the quote button so I never made it to the end of the page, then once I replied, I ignored the posts above it since i thought I had read it all
I actually do this quite often with plugins. It isn't that hard to generate but it would be handy if it did exist in the core.
Pages: 1 2