<?php $render('header', ['loggedUser'=>$loggedUser, 'title'=>$titlePage]); ?>
<?=$render('sidebar', [
  'loggedUser'=>$loggedUser, 
  'pageActive'=>$pageActive,
  'permissions'=>$permissions
]);?>

<!-- Content System -->
<div class="content-wrapper">
  <div class="pages">
    <h3>Usuários</h3>
    <div class="users">
      <div class="bar-top">
        <a href="<?=$base;?>/adduser" class="btn btn-primary mr" style="width: 200px;">Adicionar Novo Usuário</a>
        <!-- Pesquisas -->

        <div class="right">
          <!-- End Busca por status -->
          <div class="right one">
            <form method="POST" action="<?=$base;?>/users">
              <select class="form-control" name="filter[searchType]" id="option">
                <option value="clear">Limpar</option>
                <option value="1" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 1)?'selected':''; ?> >Ativo</option>
                <option value="2" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 2)?'selected':''; ?> >Inativo</option>
              </select>
              <!-- End Busca por status -->

              <!-- Busca por digitação -->
              <div class="right two">
                <!--Blue select-->
                <select class="form-control" name="filter[opt]" id="opt">
                  <option <?= ($arrayInfo['filter']['opt'] == 'name')?'selected':''; ?> value="name">Nome</option>
                  <option <?= ($arrayInfo['filter']['opt'] == 'email')?'selected':''; ?> value="email">E-mail</option>
                  <option <?= ($arrayInfo['filter']['opt'] == 'cpf')?'selected':''; ?> value="cpf">CPF</option>
                </select>
                <input type="text" name="filter[tag]" value="<?= $arrayInfo['filter']['tag'] ?>" class="form-control" placeholder="Digite aqui..." id="busca">
              </div>
              <!-- End Busca por digitação -->

              <button type="submit" class="proccess">PROCESSAR</button>
            </form>
          </div>      
        </div>

      </div>
      <!-- Message -->

      <?php if(!empty($error)): ?>
        <div class="alert <?=$error['alertType'];?>" role="alert">
          <?php echo $error['msg']; ?>
        </div>
      <?php endif; ?>

      <!-- /Message -->

      <table class="table table-hover">
        <tbody>
          <tr>
            <th scope="col">Status</th>
            <th scope="col">Nome</th>
            <th scope="col">E-mail</th>
            <th scope="col">Fone</th>
            <th scope="col">Tipo</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($arrayInfo['usersList'] as $user): ?>
            <tr>
              <td>
                <?= ($user['status'] == 1)?'Ativo':'Inativo'; ?>
              </td>
              <td><?= $user['name']; ?></td>
              <td><?= $user['email']; ?></td>
              <td><?= $user['phone']; ?></td>
              <td><?= $user['group_name']; ?></td>
              <td>
                <a href="<?=$base;?>/edituser&u=<?= $user['id']?>" class="btn btn-info mbt">Editar</a>
                <a href="<?=$base;?>/deleteuser&u=<?= $user['id']?>" class="btn btn-danger" onclick="return confirm('Tem certeza que deseja excluir?')">Excluir</a>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>

      <nav aria-label="...">
        <ul class="pagination pagination-sm">
          <?php if($arrayInfo['p'] > 1): ?>
            <li class="page-item"><a class="page-link" href="<?= $base; ?>/users?p=<?= ($arrayInfo['p']-1); ?><?= $arrayInfo['op']; ?>"><</a></li>
          <?php endif; ?>

          <li class="page-item">
            <form method="GET" id="form-pagination">
              <input type="text" name="p" value="<?= $arrayInfo['p']; ?>" class="form-control input-pagination">
            </form>
          </li>

          <?php if($arrayInfo['p'] != $arrayInfo['p_count'] && !empty($arrayInfo['p_count'])): ?>
            <li class="page-item"><a class="page-link" href="<?= $base; ?>/users?p=<?= ($arrayInfo['p']+1); ?><?= $arrayInfo['op']; ?>">></a></li>
          <?php endif; ?>
        </ul>
      </nav>
    </div>
    <script src="<?=$base;?>/assets/js/users.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

<?=$render('footer');?>