as there are multiple reuqest to handle multipe group permission (like requested in post)
https://forums.appgini.com/phpbb/viewto ... f=6&t=2799
I would like to provide an interim possibility to handle the switching of a user between multiple groups.
First you create a groups table in AppGini with user as varchar (size as you need for your user, should be at least 20 as this is the default in AppGini for the MemberID).
groupname as varchar (size as you need for your user, should be at least 20 as this is the default in AppGini for the GroupName).
Next you generate you application.
In the hooks/groups.php file you modify the groups_init function to:
Code: Select all
function groups_init(&$options, $memberInfo, &$args){
$users=sqlvalue("SELECT GROUP_CONCAT(memberID SEPARATOR ';;') FROM membership_users GROUP BY NULL");
file_put_contents("hooks/groups.user.csv", print_r($users, TRUE));
$groups=sqlvalue("SELECT GROUP_CONCAT(name SEPARATOR ';;') FROM membership_groups GROUP BY NULL");
file_put_contents("hooks/groups.groupname.csv", print_r($groups, TRUE));
return TRUE;
}
Code: Select all
<?php
if(!defined('PREPEND_PATH')) define('PREPEND_PATH', '');
$user=getLoggedMemberID();
$memberinfo=getMemberInfo();
$maingroup=$memberinfo["group"];
if ($user == "guest") return;
$query = "SELECT groupname from groups where user='".$user."' and groupname != '".$maingroup."'";
$result = sql($query,$eo);
$output="'";
$count = $result->num_rows;
if ($count > 0 ) {
while($row = db_fetch_assoc($result)) {
$output .= "<li><a href=\"change_group.php?User=".$user."&Group=".$row['groupname']."\"> <small><em>".$row['groupname']."</em></small></a></li>";
}
}
else {
$output .= "<li> <small>No additional groups available</small> </a> </li>";
}
$output .="'";
?>
<script type="text/javascript">
var list=<?php echo $output; ?>;
$j('nav .navbar-collapse').append( '<ul class="nav navbar-nav">' +
'<li class="dropdown">' +
'<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="User_Group"><span id="User_Group-count" class="label label-pill label-danger count" style="border-radius:10px;"><?php echo " ".$count; ?></span> <span> <i class="glyphicon glyphicon-user" style="font-size:18px;"></i></span><?php echo " ".$maingroup; ?></a>' +
'<ul class="dropdown-menu" role=menu id="User_Group-text"></ul>' +
'</li>' +
'</ul>' );
$j('#User_Group-text').html(list);
</script>
Code: Select all
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");
$group = $_REQUEST['Group'];
sqlvalue("UPDATE membership_users set groupID=(select groupID from membership_groups where name = '".$group."')");
header("Location: ".$_SERVER['HTTP_REFERER']);
Hope that helps