<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark">
    <a class="navbar-brand" href="#">
        <img src="<?php echo $sgturl.'img/sgt.png' ?>" width="30" height="30" class="d-inline-block align-top" alt="">
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="<?php echo $sgturl.'home.php'; ?>">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Unidade</a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="<?php echo $sgturl.'unid/unid_list_comp.php'; ?>">Listar Computadores</a>
                    <a class="dropdown-item" href="<?php echo $sgturl.'unid/unid_list_mon.php'; ?>">Listar Monitores</a>
                    <a class="dropdown-item" href="<?php echo $sgturl.'unid/unid_list_eqp.php'; ?>">Listar Equipamentos</a>
                </div>
            </li>
            <?php
                if ($nivel < 3) {
                    echo '<li class="nav-item dropdown">';
                        echo '<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Painel de Controle</a>';
                        echo '<div class="dropdown-menu">';
                            echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Usuários</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'user/list_user.php">Listar</a>';
                                    if ($nivel == 1) { echo '<a class="dropdown-item" href="'.$sgturl.'user/cad_user.php">Cadastrar</a>';}
                                echo '</div>';
                            echo '</div>';
                            echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Tabelas de Seleção</a>';    
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Clok RAM</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_clok.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_clok.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Marcas</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_marc.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_marc.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Modelos</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_mod.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_mod.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Office</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_off.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_off.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Placas de Vídeo</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_vid.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_vid.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Processadores</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_proc.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_proc.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Sistemas</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_sis.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_sis.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Tipos</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_tipo.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_tipo.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Tipos de HD</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_tipo_hd.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_tipo_hd.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                            echo '</div>';
                        echo '</div>';
                        echo '<div class="dropdown-submenu">';
                        echo '<a class="dropdown-item" href="#">Unidades</a>';
                        echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                        echo '<a class="dropdown-item" href="'.$sgturl.'selc/list_unid.php">Listar</a>';
                        echo '<a class="dropdown-item" href="'.$sgturl.'selc/cad_unid.php">Cadastrar</a>';
                        echo '</div>';
                        echo '</div>';
                        echo '<div class="dropdown-submenu">';
                        echo '<a class="dropdown-item" href="#">Dispositivos</a>';
                        echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                        echo '<div class="dropdown-submenu">';
                        echo '<a class="dropdown-item" href="#">Computadores</a>';
                        echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                        echo '<a class="dropdown-item" href="'.$sgturl.'comp/list_comp.php">Listar</a>';
                        echo '<a class="dropdown-item" href="'.$sgturl.'comp/cad_comp.php">Cadastrar</a>';
                        echo '</div>';
                        echo '</div>';
                        echo '<div class="dropdown-submenu">';
                        echo '<a class="dropdown-item" href="#">Monitores</a>';
                        echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                        echo '<a class="dropdown-item" href="'.$sgturl.'mon/list_mon.php">Listar</a>';
                        echo '<a class="dropdown-item" href="'.$sgturl.'mon/cad_mon.php">Cadastrar</a>';
                        echo '</div>';
                        echo '</div>';
                        echo '<div class="dropdown-submenu">';
                        echo '<a class="dropdown-item" href="#">Equipamentos</a>';
                        echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                        echo '<a class="dropdown-item" href="'.$sgturl.'eqp/list_eqp.php">Listar</a>';
                        echo '<a class="dropdown-item" href="'.$sgturl.'eqp/cad_eqp.php">Cadastrar</a>';
                        echo '</div>';
                        echo '</div>';
                        echo '</div>';
                        echo '</div>';
                            if ($nivel == 1) {
                                echo '<div class="dropdown-submenu">';
                                    echo '<a class="dropdown-item" href="#">DB</a>';
                                    echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                        echo '<a class="dropdown-item" href="'.$sgturl.'conf/list_db.php">Listar DB</a>';
                                        echo '<a class="dropdown-item" href="'.$sgturl.'conf/db.php">Query</a>';
                                        echo '<a class="dropdown-item" href="'.$sgturl.'conf/list_log.php?p=1">Listar Logs</a>';
                                    echo '</div>';
                                echo '</div>';
                                echo '<div class="dropdown-submenu">';
                                    echo '<a class="dropdown-item" href="#">Configurações</a>';
                                    echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                        echo '<a class="dropdown-item" href="'.$sgturl.'conf/rodape.php">Rodapé</a>';
                                    echo '</div>';
                                echo '</div>';
                            }
                        echo '</div>';
                    echo '</li>';
                }
                if ($nivel < 5) {
                    echo '<li class="nav-item dropdown">';
                        echo '<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Ferramentas</a>';
                        echo '<div class="dropdown-menu">';
                            echo '<a class="dropdown-item" href="'.$sgturl.'func/list_func.php">Listar Funcionarios</a>';
                            echo '<a class="dropdown-item" href="'.$sgturl.'canal/list_local.php">Listar Locais</a>';
                            echo '<a class="dropdown-item" href="'.$sgturl.'setor/list_setor.php">Listar Setores</a>';
                            echo '<a class="dropdown-item" href="'.$sgturl.'sw/list_vlan.php">Listar VLANs</a>';
                        echo '</div>';
                    echo '</li>';
                    echo '<li class="nav-item dropdown">';
                        echo '<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Documentação</a>';
                        echo '<div class="dropdown-menu">';
                            echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Telefonia</a>';
                                echo '<div class="dropdown-menu">';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'tel/list_tel.php">Listar VoIP</a>';
                                    if ($nivel == 1) {
                                        echo '<a class="dropdown-item" href="'.$sgturl.'tel/list_voip_cap.php">Grupo de Captura</a>';
                                        echo '<a class="dropdown-item" href="'.$sgturl.'tel/list_voip_pin.php">Listar PINs</a>';
                                    }
                                echo '</div>';
                            echo '</div>';
                            if ($nivel == 1) {
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Rede</a>';
                                echo '<div class="dropdown-menu">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'ip/list_ip_dhcp.php">DHCP</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'ip/list_ip_unid.php">Listar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'ip/cad_ip_unid.php">Cadastrar</a>';
                                echo '</div>';
                                echo '</div>';
                            } else {
                                echo '<a class="dropdown-item" href="'.$sgturl.'ip/list_ip_unid.php">Rede</a>';
                            }
                            if ($nivel == 1) {
                                echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Chaves</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                echo '<a class="dropdown-item" href="'.$sgturl.'doc/cad_cha.php">Cadastrar</a>';
                                echo '<a class="dropdown-item" href="'.$sgturl.'doc/list_cha.php">Listar</a>';
                                echo '</div>';
                                echo '</div>';
                            } else {
                                echo '<a class="dropdown-item" href="'.$sgturl.'doc/list_cha.php">Listar Chaves</a>';
                            }
                            echo '<a class="dropdown-item" href="'.$sgturl.'doc/list_key.php">Senhas</a>';
                            echo '<div class="dropdown-submenu">';
                                echo '<a class="dropdown-item" href="#">Passo a Passo</a>';
                                echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'doc/cad_pp.php">Cadastrar</a>';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'doc/list_pp.php">Listar</a>';
                                echo '</div>';
                            echo '</div>';
                            echo '<a class="dropdown-item" href="'.$sgturl.'canal/list_canal.php">Canais</a>';
                            if ($nivel < 5) {
                                echo '<div class="dropdown-submenu">';
                                    echo '<a class="dropdown-item" href="#">Switches</a>';
                                    echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'sw/cad_sw.php">Cadastrar</a>';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'sw/list_sw.php">Listar</a>';
                                    echo '</div>';
                                    echo '</div>';
                                    echo '<div class="dropdown-submenu">';
                                    echo '<a class="dropdown-item" href="#">Ocorrências</a>';
                                    echo '<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'oc/cad_oc_comp.php">Registrar Computadores</a>';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'oc/cad_oc_mon.php">Registrar Monitores</a>';
                                    echo '<a class="dropdown-item" href="'.$sgturl.'oc/cad_oc_eqp.php">Registrar Equipamentos</a>';
                                    echo '</div>';
                                echo '</div>';
                            }
                        echo '</div>';
                    echo '</li>';
                }
            ?>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Help Desk<?php echo $hp; ?></a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href=<?php echo '"'.$sgturl.'hd/list_hd.php"'; ?>>Ver Chamados<?php echo $hp; ?></a>
                    <a class="dropdown-item" href=<?php echo '"'.$sgturl.'hd/hd_abre.php"'; ?>>Abrir Chamado</a>
                    <a class="dropdown-item" href=<?php echo '"'.$sgturl.'hd/ver_hd.php?p=1"'; ?>>Buscar</a>
                    <?php
                    if ($nivel < 3) {
                    echo '<a class="dropdown-item" href="'.$sgturl.'hd/list_pro.php">Produtos</a>';
                    echo '<a class="dropdown-item" href="'.$sgturl.'hd/list_hd_user.php">HD - Usuários</a>';
                    }
                    ?>
                </div>
            </li>
            <?php
                if ($nivel < 3) {
                $busca_sgt_versao = $pdo_sgt->prepare("SELECT * FROM tb_conf WHERE conf='versao'");
                $busca_sgt_versao->execute();
                $dados_sgt_versao = $busca_sgt_versao->fetch(PDO::FETCH_ASSOC);
                if ($dados_sgt_versao['var1'] != 0) {
                    echo '<li class="nav-item">
                        <a class="nav-link active" href="http://sgt.eti.br/downloads/" target="_blank">Nova Versão</a>
                    </li>';
                }
                }
            ?>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">SGT</a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="http://sgt.eti.br/" target="_blank">Site do SGT</a>
                    <a class="dropdown-item" href=<?php echo '"'.$sgturl.'README.txt"'; ?> target="_blank">Sobre SGT</a>
                    <a class="dropdown-item" href=<?php echo '"'.$sgturl.'LICENSE.txt"'; ?> target="_blank">Licença</a>
                </div>
            </li>
        </ul>
        <?php
            if($unid_temp < 2){
                echo '<span class="navbar-text mr-2">';
                    echo 'Unidade:';
                echo '</span>';
                echo '<form class="form-inline my-2 my-lg-0" name="id" id="id" action="'.$sgturl.'alt_master_.php" method="POST">';
                    echo '<div class="form-row align-items-center">';
                        echo '<div class="col-auto">';
                            echo '<input style="display: none" type="text" readonly name="id" value="'.$id_temp.'" />';
                            echo '<select class="custom-select form-control form-control-sm" name="unidade_user_temp" id="unidade_user_temp">';
                                include "conectar.php";
                                $busca_uni = $pdo_sgt->prepare("SELECT * FROM tb_unidades ORDER BY id");
                                $busca_uni->execute();
                                while (@$linha = $busca_uni->fetch(PDO::FETCH_ASSOC)){
                                    $valor = $linha[@id]; 
                                    echo "<option value = \"$valor\""; if($unid_master == $valor){echo ' selected';} echo ">$linha[unidade]</option>";
                                }
                            echo '</select>';
                        echo '</div>';
                        echo '<div class="col-auto">';
                            echo '<input class="btn btn-outline-secondary" type="submit" name="ok" value="Alterar" />';
                        echo '</div>';
                    echo '</div>';
                echo '</form>';
            } 
        ?>
        <ul class="navbar-nav">
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <?php echo $_SESSION['usuarioNome']." ".$_SESSION['usuarioSobrenome'] ?>
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="<?php echo $sgturl.'user/meu_user.php?id='.$id_temp ?>">Editar</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="<?php echo $sgturl.'logout_.php' ?>">Sair</a>
                </div>
            </li>
        </ul>
    </div>
</nav>
