<?php

include_once 'connect.php';

?>
<nav class="navbar brb navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <!-- botão abre/fecha menu -->
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-menu-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="fa fa-reorder"></span>
      </button>
      <!-- logo -->
      <a class="navbar-brand" href="#"> 
        <img alt="Logo" title="Logo" style="max-height: 30px;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAA81BMVEX///9VPnxWPXxWPXxWPXxWPXxWPXxWPXz///9hSYT6+vuFc6BXPn37+vz8+/z9/f2LeqWMe6aOfqiTg6uXiK5bQ4BZQX9iS4VdRYFdRYJfSINuWI5vWY9xXJF0YJR3Y5Z4ZZd5ZZd6Z5h9apq0qcW1qsW1q8a6sMqpnLyrn76tocCvpMGwpMJoUoprVYxeRoJjS4abjLGilLemmbrDutDFvdLPx9nX0eDa1OLb1uPd1+Td2OXe2eXh3Ofj3+nk4Orl4evp5u7u7PLv7fPx7/T08vb08/f19Pf29Pj39vn6+fuEcZ9YP35aQn/8/P1ZQH5fR4PINAOdAAAAB3RSTlMAIWWOw/P002ipnAAAAPhJREFUeF6NldWOhEAUBRvtRsfdfd3d3e3/v2ZPmGSWZNPDqScqqaSBSy4CGJbtSi2ubRkiwXRkBo6ZdJIApeEwoWMIS1JYwuZCW7hc6ApJkgrr+T/eW1V9uKXS5I5GXAjW2VAV9KFfSfgJpk+w4yXhwoqwl5AIGwp4RPgdK3XNHD2ETYiwe6nUa18f5jYSxle4vulw7/EtoCdzvqkPv3bn7M0eYbc7xFPXzqCrRCgH0Hsm/IjgTSb04W0i7EGjz+xw+wR6oZ1MnJ9TWrtToEx+4QfcZJ5X6tnhw+nhvqebdVhZUJX/oFcKvaTotUcvUnY188ue/n38AunzPPE8yg7bAAAAAElFTkSuQmCC">
      </a>
    </div>

    <!-- div do menu -->
    <div class="collapse navbar-collapse" id="main-menu-collapse">
      <ul class="nav navbar-nav">
        <!-- elemento span é posicionado na esquerda automaticamente -->
        <li class="dropdown">
          <!-- se quiser um ícone a direita, usar outro elemento inline, como "i" ou "b" por exemplo -->
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Módulos <i class="caret"></i></a>
          <ul class="dropdown-menu">
            <?php
            $sql = 'select * from modulos where st_ativo=1';
            $stmt = mysqli_prepare($conexao, $sql);
            if ($stmt) {
              mysqli_stmt_execute($stmt);
              $modulos = my_fetch_assoc_stmt($stmt);
              mysqli_stmt_close($stmt);
            } else {
              echo '<!-- ' . $sql . PHP_EOL . mysqli_error($conexao) . ' -->';
              $modulos = array();
            }
            foreach($modulos as $modulo) {
              echo '<li><a href="#">' . $modulo['ds_modulo'] . '</a></li>' . PHP_EOL;
            }
            ?>
          </ul>
        </li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Configurações <i class="caret"></i></a>
          <ul class="dropdown-menu">
            <?php
            $sql = 'select * from funcionalidades where st_ativo=1 and st_global=1';
            $stmt = mysqli_prepare($conexao, $sql);
            if ($stmt) {
              mysqli_stmt_execute($stmt);
              $modulos = my_fetch_assoc_stmt($stmt);
              mysqli_stmt_close($stmt);
            } else {
              echo '<!-- ' . $sql . PHP_EOL . mysqli_error($conexao) . ' -->';
              $modulos = array();
            }
            foreach($modulos as $modulo) {
              // TODO montar o link usando o id do módulo listado
              echo '<li><a href="#">' . $modulo['ds_funcionalidade'] . '</a></li>' . PHP_EOL;
            }
            ?>
          </ul>
        </li>
        <!-- TODO link do desktop vai usar o módulo corrente -->
        <li><a href="#"><span class="icon-c"></span> Desktop</a></li>
        <li><a href="#"><span class="icon-c"></span> Arena</a></li>
        
        
        
        <?php
        /*
        ?>
        <li class="<?php echo basename($_SERVER['SCRIPT_FILENAME']) === 'index.php' ? 'active' : ''; ?>"><a href="index.php"><span class="fa fa-tachometer"></span> Em branco <span class="sr-only">(current)</span></a></li>
        <li class="<?php echo basename($_SERVER['SCRIPT_FILENAME']) === 'lista.php' ? 'active' : ''; ?>"><a href="lista.php"><span class="fa fa-list"></span> Lista <span class="sr-only">(current)</span></a></li>
        <li class="<?php echo basename($_SERVER['SCRIPT_FILENAME']) === 'form.php' ? 'active' : ''; ?>"><a href="form.php"><span class="fa fa-pencil"></span> Formulário <span class="sr-only">(current)</span></a></li>
        <li><a href="#"><span class="icon-c"></span> Link</a></li>
        <li class="dropdown">
          <!-- se quiser um ícone a direita, usar outro elemento inline, como "i" ou "b" por exemplo -->
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <i class="caret"></i></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
        <?php
        //*/
        ?>
      </ul>
      <!-- outra área de navegação na direita, pode ser informações do usuário, links para perfil, logout, etc -->
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="fa fa-user"></span>Usuário <i class="caret"></i></a>
          <ul class="dropdown-menu">
            <li><img src="http://lorempixel.com/image_output/people-q-c-150-150-10.jpg" class="img-responsive center-block" /></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
      <!-- form de pesquisa na direita -->
      <form class="navbar-form navbar-right" id="form-atalho" >
        <div class="form-group">
          <select id="menu-atalho" class="" >
            <option></option>
              <?php
              $sql = 'select * from funcionalidades where st_ativo=1';
              $stmt = mysqli_prepare($conexao, $sql);
              if ($stmt) {
                mysqli_stmt_execute($stmt);
                $modulos = my_fetch_assoc_stmt($stmt);
                mysqli_stmt_close($stmt);
              } else {
                echo '<!-- ' . $sql . PHP_EOL . mysqli_error($conexao) . ' -->';
                $modulos = array();
              }
              foreach($modulos as $modulo) {
                // TODO montar o link usando o id do módulo listado
                echo '<option value="' . $modulo['ds_path_funcionalidade'] . '">' . $modulo['ds_funcionalidade'] . '</option>' . PHP_EOL;
              }
              ?>
            </ul>
          </select>
           <input type="text" class="form-control" placeholder="pesquisa..." /> 
        </div>
      </form>
    </div><!-- /.navbar-collapse -->
  </div>
</nav>