Show and hide DIV according to the user level

0

I need to display some div elements according to the logged-in user level. If the user is level one can only sample certain div 's. Here is the display:

<div id="hmn0" style="margin-top:0px;">
    <nav>
        <div id="acdnmenu" style="width:199px;height:390px;">
            <ul>
              <li id="v_sm">Administrativo
                    <ul>
                        <li><a href="./adm/cd_reqequip.php" target="main">Requisição de equipamentos</a></li>
                        <li><a href="./adm/cd_document.php" target="main">Documentações</a></li>
                        <li><a href="./cadastro.php" target="main">Cadastro</a></li>
                    </ul>
                </li>
                <li id="v_tt">Faturamento
                    <ul>
                        <li><a href="./faturamento/cd_guiahm.php" target="main">Honorário Médico</a></li>
                        <li><a href="./faturamento/cd_lancsessao.php" target="main">Lançar sessões</a></li>
                        <li><a href="./faturamento/cad_lancconta.php" target="main">Lançar na conta</a></li>
                        <li><a href="./faturamento/fat_unidade.php" target="main">Fatura por unidades</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
</div>
    
asked by anonymous 22.08.2017 / 19:50

2 answers

2

A very generic implementation could be:

function exibirDivDeAcordoComNivelDoUsuario(usuario) {
    if(usuario.nivel !== 1) {
        document.getElementById("hmn0").style.display = 'none';
    }
}
    
22.08.2017 / 19:56
1

As you did not specify in what server environment your website is, I'll give you a simple example in ASP (VBScript):

I create a Session with the user level when it logs in:

session("user_nivel") = 1

In HTML, I just show Level 1 what I want, like this:

<%if session("user_nivel") >= 2 then%>
<div>
  Esta div só é visível para nível 2 acima
</div>
<%end if%>

<%if session("user_nivel") = 1 then%>
<div>
  Esta div é visível somente para nível 1
</div>
<%end if%>

If you are using PHP, the idea is the same.

  

Do not do this in JavaScript because it can be circumvented. It is best that the    div is already missing from the server.

    
22.08.2017 / 20:50