I have an implementation that goes against what you want, but to explain I’ll go by parts:
The final result would look like this: (in red is not allowed in green with permission)
Well you said that the part of the database is ready, but did not show then I will show how I set there in the database.
CREATE TABLE `tab_modulo` (
`mod_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'PK',
`mod_tipo` varchar(45) NOT NULL COMMENT 'MENU -> MENU DO SISTEMA\nMENU-SUB -> SUB-MENU DO SISTEMA\nMODULO -> MODULO DO SISTEMA\nMODULOUP -> MODULO QUE CONTEM NIVEIS DE ACESSO\nNIVELUP -> NIVEL DE CESSO DENTRO DE UM MODULO',
`mod_nome` text NOT NULL COMMENT 'tag para visualização no html',
`mod_apelido` varchar(45) NOT NULL COMMENT 'Nome do Menu/Sub-Menu, nome que aparece na interface permissões etc.',
`mod_ref` int(11) NOT NULL COMMENT 'Usado para referenciar os sub-menus a qual menu(mod_id) ele pertence',
`mod_atalho` char(1) DEFAULT NULL COMMENT 'tecla de atalho',
`mod_ordem` int(11) NOT NULL DEFAULT '0 para ficar em cima na ordenacao e valores positivos irão fazer descer o item na ordenacao',
PRIMARY KEY (`mod_id`)
) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=latin1 COMMENT='Modulos e Menus do sistema';
Understanding the concept:
- MENU - part that appears without passing the mouse ( this in gray image)
- SUB-MENU - Part where the modules are grouped ( sub-title if you prefer )
- MODULE - The page that will be given access ( has the checkbox ahead )
MODULE UP and LEVEL UP - Special permissions within a module ( appears as a sub-item of a module )
mysql> select * from tab_modulo limit 4;
+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+
| mod_id | mod_tipo | mod_nome | mod_apelido | mod_ref | mod_atalho | mod_ordem |
+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+
| 1 | MENU-SUB | <b>Carta Frete</b> | Carta Frete | 42 | c | 4 |
| 2 | MENU | <b>Financeiro</b> | Financeiro | 0 | f | 1 |
| 4 | MENU | <b>Administrador</b> | Administrador | 0 | a | 6 |
| 5 | MODULO | <a href="javascript:loadContent('#conteudo','consultaFrete.php');">Consulta Carta</a> | Consulta Carta | 1 | c | 0 |
+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+
I left an attribute with markings TAG when php is going to put the menu already right on the page, and an attribute with the tag-less description to generate the permissions list for me to keep checking/unchecking permissions.
in php I made a function to generate the menu like this:
private function construirMenuPermissoes(){
for ($i=0; $i <sizeof($this->objeto); $i++) {
if($this->objeto[$i]->mod_tipo == 'MENU'){ //ENTÃO ELE É UM MENU PRINCIPAL
$this->menus[] = $this->objeto[$i];
$mod_id = $this->objeto[$i]->mod_id;
$mod_apelido = $this->objeto[$i]->mod_apelido;
$mod_nome = $this->objeto[$i]->mod_nome;
$menu = "<div id='p$mod_id' mod_id='$mod_id' class='div-menu'><ul style='width: 180px;'>".
// "<li id='".$mod_apelido."'>".
"<legend class='ui-widget ui-widget-header ui-corner-all legend'>$mod_nome</legend>?".
"<ul id='browser' class='treeview ".$mod_apelido."' style='margin-top: -10px;'>"; //cria o menu no nivel principal
$itens = "";
$itens = $itens.$this->getSubNiveis2($mod_id);
echo $menu.$itens."</ul></ul></div>";
}
}
}
private function getSubNiveis2($mod_id){ //FUNCAO RECURSIVA USADA NO PERMISSOES.PHP
for ($i=0; $i < sizeof($this->objeto); $i++) {
$mod_apelido = $this->objeto[$i]->mod_apelido;
$mod_ref = $this->objeto[$i]->mod_ref;
$mod_tipo = $this->objeto[$i]->mod_tipo;
$id = $this->objeto[$i]->mod_id;
if( $mod_ref == $mod_id){
if($mod_tipo == 'MENU-SUB'){
$menu = @$menu."<li id='p".$id."' mod_id='$id' ><b>".$mod_apelido."</b><ul>";
$menu = @$menu.$this->getSubNiveis2($id)."</ul>"; //MOD_ID DO ARRAY NAO DO PARAMETRO
}
else if($mod_tipo == 'MODULOUP'){ // ACESSO ELEVADO DENTRO DE UM MODULO
$menu = @$menu."<li id='p".$id."' style='padding-bottom: 6px; font: bold 8pt Arial;'><b>".$mod_apelido.
"<input class='".$id."' type='checkbox' style='float: right; cursor: pointer;'/>".
"</b><ul>";
$menu = @$menu.$this->getSubNiveis2($id)."</ul>"; //MOD_ID DO ARRAY NAO DO PARAMETRO
}
else{
$menu = @$menu."<li id='p".$id.
"' style='padding-bottom: 6px; font: bold 8pt Arial;'>".$mod_apelido.
"<input class='".$id."' mod_ref='" . $mod_ref . "'
type='checkbox' style='float: right; cursor: pointer;'/>"."</li>";
}
}
}
return $menu;
}
Where $this->object is the array of all modules I have registered in the database. I hope it helped you, doubt the layout.
I answered without comment the part of the user groups, as you wrote that the logic and the database is already defined so I think that part of grouping users and giving the same access to this group is already solved, if you don’t let me know that I edit my post complementing this part
– SneepS NinjA