1 (edited by slickplaid 2009-02-04 00:46)

Topic: Query Groups, Set Values, and Pass to Javascript UI

I'm trying to work out a way to:

  1. Set up an Admin Panel

    1. List out all user groups on my extension's admin panel (separate from the group permissions admin panel).

    2. Put all the groups in to an array(); I think this would be the easiest way to work with them. Let me know if it isnt...

    3. Allow the user to assign groups to four different permission levels. Most likely using a text field(permission level) & Label(group name) field they can just type 1-4 on each of them to set it.

    4. Store each of the values into the $forum_config['values']... somehow... Can I do something like "'o_extensionname_groupperm_'.$id" or something?

    5. Each permission level (0-3) would start off at the most restrictive (only admins, but can be changed by the user), then a little less restrictive, while still keeping the previous groups in it. (ie: group[0] = 'admins'; group[1] = 'admins, mods, privuser'; group[2] = 'admins, mods, privuser, default users'; group[3] = 'admins, mods, privuser, default users, guests';)

  2. Next, pass along certain values to a javascript ui

    1. Send which group(0-3) the user's group falls into via $_POST to the javascript.

    2. The user will be able to pick (from the javascript ui) a group(0-3) level that they can send messages but they can't receive or send messages higher than what is set in the admin panel (option will be grayed out).

I know how to call the proper hook to make the admin panel, but I'm clueless on how to list out all the user groups and allow the admin the ability to assign them to my groups for chat privileges(group(0-3)). I think once I can get them assigned, they'll be easy to send to the javascript via $_POST. Does that sound correct or am I making this too complicated? If you haven't already realized it, this is for a javascript chat extension and I'm trying to have different permission levels that can be selected when sending messages (never higher than what permissions their group is given in the admin panel) and then they can only receive up to their permission level, and anything they can receive is shown in different colors (so admin messages are red, next level down is orange, next level is green, lowest public level that everyone can see is black).

I can do the javascript for what I need, I just need help to know which functions built into PunBB to use in php since I'm not that accustomed to it yet.

Can anyone throw any bit of insight (mainly how to list out all the groups and store them in $forum_config with the selected values in my extensions admin panel in a way that if the groups are ever modified or removed in punbb, it won't cause problems with my extension or the javascript ui)? I'm going cross-eyed trying to look through all the functions in admin/groups.php without knowing exactly what I'm looking for.

Re: Query Groups, Set Values, and Pass to Javascript UI

So, basically, what's the command to list all of the user groups and their g_id's without having to query the SQL server for them?

Re: Query Groups, Set Values, and Pass to Javascript UI

There is no special function to get a user group, but you can get a group id using the global array $forum_user, key 'g_id'

Re: Query Groups, Set Values, and Pass to Javascript UI

So there is no way to print out a list of all the group ID's (not just the current user, which is what I'm getting from $forum_user['g_id']) and their associated group names?

Re: Query Groups, Set Values, and Pass to Javascript UI

There is one way to get it - by means of an SQL-query, group id and group names aren't cached. But you can cache them for your purposes in your extension.

Re: Query Groups, Set Values, and Pass to Javascript UI

This is kind of a noobish question but, can I just query the database since it's already connected or do I have to pull the $db_username $db_password and all that to connect?

And if it's already connected, would this work?

$result = mysql_query('SELECT g_id, g_title FROM '.$db_prefix.'groups');
if (!$result) {
    print('Invalid query: ' . mysql_error());
}

Re: Query Groups, Set Values, and Pass to Javascript UI

Okay, I think I've got it:

$dbhandle = mysql_connect($db_host, $db_username, $db_password) or print(mysql_error());
$selected = mysql_select_db($db_name,$dbhandle) or print(mysql_error());
$result = mysql_query('SELECT g_id, g_title FROM '.$db_prefix.'groups');
while ($row = mysql_fetch_array($result)) {
    print('ID:'.$row{'g_id'}.' Name:'.$row{'g_title'}.'<br />');
};

8

Re: Query Groups, Set Values, and Pass to Javascript UI

If you are making an extension, make sure to use the db layer functions and not the specific mysql_ ones.

Re: Query Groups, Set Values, and Pass to Javascript UI

Is there somewhere that has a reference on how to use those functions aside from looking through the source code at 10 different examples and trying to figure it out from there?

10 (edited by KeyDog 2009-02-04 23:14)

Re: Query Groups, Set Values, and Pass to Javascript UI

http://fluxbb.org/wiki/v1.3:developing_extensions

that maybe...

http://fluxbb.org/wiki/v1.3:developing_ … ry_builder

Re: Query Groups, Set Values, and Pass to Javascript UI

Thank you KeyDog. smile

Re: Query Groups, Set Values, and Pass to Javascript UI

This might be a long shot but I'm looking all over the place for how PunBB does it's $forum_config variable and keeps it updated.

Anyone know where to look?

Right now I've got this in the <install> portion of the addon:

$jchat_group_query = array(
    'SELECT'    => 'g_id, g_title',
    'FROM'        => 'groups'
);
$jchat_config = $forum_db->query_build($jchat_group_query) or error(__FILE__, __LINE__);
$jchat_config = mysql_fetch_array($jchat_config);

Is that all I need and it'll stay usable as $jchat_config['group_id'] to display group names throughout the script?

Sorry if my question is somewhat naive, I'm learning as I go along.

Re: Query Groups, Set Values, and Pass to Javascript UI

I'm getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/..removed../admin/settings.php(337) : eval()'d code on line 173

Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/..removed../admin/settings.php(337) : eval()'d code on line 175

What am I missing? Did I format that incorrectly?

14

Re: Query Groups, Set Values, and Pass to Javascript UI

This article should help you to work with query results.

Re: Query Groups, Set Values, and Pass to Javascript UI

Thank you, that's exactly what I needed.