I have an implementation that goes against what you want, but to explain I go in parts:
The end result would look like this: (red is not allowed in green with permission)
Wellyousaidthatthepartofthedatabaseisready,butitdidnotshowsoI'llshowyouhowIputitthereinthedatabase.
CREATETABLE'tab_modulo'('mod_id'int(11)NOTNULLAUTO_INCREMENTCOMMENT'PK','mod_tipo'varchar(45)NOTNULLCOMMENT'MENU->MENUDOSISTEMA\nMENU-SUB->SUB-MENUDOSISTEMA\nMODULO->MODULODOSISTEMA\nMODULOUP->MODULOQUECONTEMNIVEISDEACESSO\nNIVELUP->NIVELDECESSODENTRODEUMMODULO','mod_nome'textNOTNULLCOMMENT'tagparavisualizaçãonohtml','mod_apelido'varchar(45)NOTNULLCOMMENT'NomedoMenu/Sub-Menu,nomequeaparecenainterfacepermissõesetc.','mod_ref'int(11)NOTNULLCOMMENT'Usadoparareferenciarossub-menusaqualmenu(mod_id)elepertence','mod_atalho'char(1)DEFAULTNULLCOMMENT'tecladeatalho','mod_ordem'int(11)NOTNULLDEFAULT'0paraficaremcimanaordenacaoevalorespositivosirãofazerdesceroitemnaordenacao',PRIMARYKEY('mod_id'))ENGINE=InnoDBAUTO_INCREMENT=116DEFAULTCHARSET=latin1COMMENT='ModuloseMenusdosistema';
Understandingtheconcept:
- MENU-partthatappearswithoutmouseover(thisisgrayintheimage)
- SUB-MENU-Partwherethemodulesaregrouped(sub-titleifyouprefer)
- MODULE-Thepagethatwillbegivenaccess(hasthecheckboxinfront)
UPMODULEandUPLEVEL-Specialpermissionswithinamodule(appearsasifitwereasub-itemofamodule)
mysql>select*fromtab_modulolimit4;+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+|mod_id|mod_tipo|mod_nome|mod_apelido|mod_ref|mod_atalho|mod_ordem|+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+|1|MENU-SUB|<b>CartaFrete</b>|CartaFrete|42|c|4||2|MENU|<b>Financeiro</b>|Financeiro|0|f|1||4|MENU|<b>Administrador</b>|Administrador|0|a|6||5|MODULO|<ahref="javascript:loadContent('#conteudo','consultaFrete.php');">Consulta Carta</a> | Consulta Carta | 1 | c | 0 |
+--------+----------+---------------------------------------------------------------------------------------+----------------+---------+------------+-----------+
I left an attribute with TAG tags for when php is put on the page the menu is already set, and the one attribute with the tagless description to generate the list of permissions for me to be tagging / 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 the modules I have registered in the database. I hope it has helped you, you doubt the provision.