Foren / Cotonti / Patches / Group type setting

User group can only be set as maingroup, subgroup or both.

GHengeveld
#1 11. April 2009, 03:50
This will add an option in user group settings. You can limit the group type a group can be set as. For example, you can have both regular users and Premium users. Normally, you would be able to set Premium user as Main group. With this patch you can disallow setting this group as main group, so it can only be set as a subgroup. This will make sure your Premium users are always inside the Users main group (or another Main group option).
This is especially useful if you have a lot of different groups and multiple website administrators (with the right to edit a user's group).

1. Adding database column
Run the following SQL query on your database:
ALTER TABLE 'sed_groups' ADD 'grp_type' VARCHAR(4) NOT NULL DEFAULT 'both';

2. Adding language items
Inside system/lang/xx/admin.lang.php on line 358, add:
$L['adm_rights_grouptype'] = 'Can be set as';
$L['adm_rights_grouptype_both'] = 'Main and sub group';
$L['adm_rights_grouptype_sub'] = 'Sub group only';

3. New group selectbox
In system/core/admin/admin.users.inc.php on line 255, add:
$adminmain .= "<tr><td>".$L['adm_rights_grouptype']." :</td><td>";
$adminmain .= "<select name=\"ntype\">";
$adminmain .= "<option value=\"both\">".$L['adm_rights_grouptype_both']."</option>";
$adminmain .= "<option value=\"sub\">".$L['adm_rights_grouptype_sub']."</option>";
$adminmain .= "</select>";
$adminmain .= "</td></tr>";

On line 47, add:
$ntype = sed_import('ntype','P','TXT');

On line 50 there should be an SQL query, replace it with:
$sql = (!empty($ntitle)) ? sed_sql_query("INSERT INTO $db_groups (grp_alias, grp_level, grp_disabled, grp_hidden,  grp_maintenance, grp_type, grp_title, grp_desc, grp_icon, grp_pfs_maxfile, grp_pfs_maxtotal, grp_ownerid) VALUES ('".sed_sql_prep($nalias)."', ".(int)$nlevel.", ".(int)$ndisabled.", ".(int)$nhidden.",  ".(int)$nmtmode.", '".sed_sql_prep($ntype)."', '".sed_sql_prep($ntitle)."', '".sed_sql_prep($ndesc)."', '".sed_sql_prep($nicon)."', ".(int)$nmaxsingle.", ".(int)$nmaxtotal.", ".(int)$usr['id'].")") : '';

4. Edit group selectbox
On line 81, add:
$rtype = sed_import('rtype','P','TXT');
$rtype = sed_sql_prep($rtype);

Somewhere around line 88 there should be an SQL query, replace it with:
$sql = (!empty($rtitle)) ? sed_sql_query("UPDATE $db_groups SET grp_title='$rtitle', grp_desc='$rdesc', grp_icon='$ricon', grp_alias='$ralias', grp_level='$rlevel', grp_pfs_maxfile='$rmaxfile', grp_pfs_maxtotal='$rmaxtotal', grp_disabled='$rdisabled', grp_hidden='$rhidden', grp_maintenance='$rmtmode', grp_type='$rtype' WHERE grp_id='$g'") : '';

On line 170, add:
$selected_both = ($row['grp_type'] == 'both') ? ' selected="selected"' : '';
$selected_sub = ($row['grp_type'] == 'sub') ? ' selected="selected"' : '';
	
$adminmain .= "<tr><td>".$L['adm_rights_grouptype']." :</td>";
$adminmain .= "<td><select name=\"rtype\">";
$adminmain .= "<option value=\"both\"$selected_both>".$L['adm_rights_grouptype_both']."</option>";
$adminmain .= "<option value=\"sub\"$selected_sub>".$L['adm_rights_grouptype_sub']."</option>";
$adminmain .= "</select></td></tr>";

5. Modifying groups selection
In system/functions.php, on line 1249, find sed_build_groupsms(). Replace the entire function with:

function sed_build_groupsms($userid, $edit=FALSE, $maingrp=0)
{
	global $db_groups, $db_groups_users, $sed_groups, $L, $usr;

	$sql = sed_sql_query("SELECT gru_groupid FROM $db_groups_users WHERE gru_userid='$userid'");
	while ($row = sed_sql_fetcharray($sql))
	{
		$member[$row['gru_groupid']] = TRUE;
	}
	
	$sql = sed_sql_query("SELECT grp_id, grp_type FROM $db_groups");
	$onlysub[] = '';
	while ($row = sed_sql_fetcharray($sql))
	{
		if ($row['grp_type'] == 'sub') $onlysub[] = $row['grp_id'];
	}

	foreach($sed_groups as $k => $i)
	{
		$checked = ($member[$k]) ? "checked=\"checked\"" : '';
		$checked_maingrp = ($maingrp==$k) ? "checked=\"checked\"" : '';
		
		$readonly = (!$edit || $usr['level'] < $sed_groups[$k]['level'] || $k==SED_GROUP_GUESTS || $k==SED_GROUP_INACTIVE || $k==SED_GROUP_BANNED || ($k==SED_GROUP_TOPADMINS && $userid==1)) ? "disabled=\"disabled\"" : '';
		$readonly_maingrp = (!$edit || $usr['level'] < $sed_groups[$k]['level'] || $k==SED_GROUP_GUESTS || ($k==SED_GROUP_INACTIVE && $userid==1) || ($k==SED_GROUP_BANNED && $userid==1) || in_array($k, $onlysub)) ? "disabled=\"disabled\"" : '';

		if ($member[$k] || $edit)
		{
			if (!($sed_groups[$k]['hidden'] && !sed_auth('users', 'a', 'A')))
			{
				$res .= "<input type=\"radio\" class=\"radio\" name=\"rusermaingrp\" value=\"$k\" ".$checked_maingrp." ".$readonly_maingrp." /> \n";
				$res .= "<input type=\"checkbox\" class=\"checkbox\" name=\"rusergroupsms[$k]\" ".$checked." $readonly />\n";
				$res .= ($k == SED_GROUP_GUESTS) ? $sed_groups[$k]['title'] : "<a href=\"".sed_url('users', 'gm='.$k)."\">".$sed_groups[$k]['title']."</a>";
				$res .= ($sed_groups[$k]['hidden']) ? ' ('.$L['Hidden'].')' : '';
				$res .= "<br />";
			}
		}
	}

	return $res;
}
[/][/]

Dieser Beitrag wurde von Koradhil (am 26. April 2009, 23:36, vor 14 Jahre) bearbeitet
Trustmaster
#2 27. April 2009, 12:08
This could be useful together with right-less groups

UPD:

So far we found these types of groups usable:
  • Normal group
  • Hidden group
  • Sub group only
  • Right-less status group

I think there should be just one field (grp_type) in the sed_groups table for all of them and group type should be selectable with a dropdown in Admin. Then scripts will check this field and implement appropriate behavior depending on group type.

What do you think?
May the Source be with you!

Dieser Beitrag wurde von Trustmaster (am 27. April 2009, 23:54, vor 14 Jahre) bearbeitet
pieter
#3 28. April 2009, 02:05
Hidden group is in seditio only for hidding the group.

I was looking once how to hide users from a specific group.

eg all banned users.
It is nice to keep them for there IP and usernames. But also nice to get them out of the user list, to see all normal users.

Maybe an idea to think about when you change some stuff of the usersgroups.
... can we help you ...
Trustmaster
#4 28. April 2009, 12:27
Interestingly, there is an Enabled/Disabled (grp_disabled) option for groups but it is not used anywhere at all. Probably we could just use it so "Disabled" groups don't show at all or something.
May the Source be with you!
GHengeveld
#5 3. Mai 2009, 02:17
I thınk dısabled shouldnt be put ın grp_type because you could have both hıdden and sub-only.
Enabled dısabled ıs ınterestıng we could do more wıth that.

Pardon my spellıng, usıng a turkısh keyboard ıs quıte trıcky... (ım on vacatıon ın alanya)