<?php
include("seguranca.php"); // Inclui o arquivo com o sistema de segurança  
protegePagina(); // Chama a função que protege a página 
?>
<?php
include "conexao.php";
?>
<!DOCTYPE html>
<html lang="en">
    <head>        
        <!-- META SECTION -->
        <title>Portal dos Patrocinadores - Sistema Administrativo</title>            
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        
        <link rel="icon" href="favicon.ico" type="image/x-icon" />
        <!-- END META SECTION -->
        
        <!-- CSS INCLUDE -->        
        <link rel="stylesheet" type="text/css" id="theme" href="css/theme-default.css"/>
        <!-- EOF CSS INCLUDE -->                                     

    <!-- START SCRIPTS -->
        <!-- START PLUGINS -->
        <script type="text/javascript" src="js/plugins/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery/jquery-ui.min.js"></script>
        <script type="text/javascript" src="js/plugins/bootstrap/bootstrap.min.js"></script>        
        <!-- END PLUGINS -->

        <!-- THIS PAGE PLUGINS -->
        <script type='text/javascript' src='js/plugins/icheck/icheck.min.js'></script>
        <script type="text/javascript" src="js/plugins/mcustomscrollbar/jquery.mCustomScrollbar.min.js"></script>
        
        <script type="text/javascript" src="js/plugins/datatables/jquery.dataTables.min.js"></script>    
        

        <!-- END PAGE PLUGINS -->         

        <!-- START TEMPLATE -->
        <script type="text/javascript" src="js/plugins.js"></script>        
        <script type="text/javascript" src="js/actions.js"></script>        

<script src="js/valor.js"></script>

    </head>
    <body>
        <!-- START PAGE CONTAINER -->
        <div class="page-container">
            
        	<?php include 'topo.php'; ?>
            <!-- END PAGE SIDEBAR -->

		
            
            <!-- PAGE CONTENT --><!-- END X-NAVIGATION VERTICAL -->                     
                
                <!-- START BREADCRUMB -->
                <!-- END BREADCRUMB -->                
                <!-- PAGE CONTENT WRAPPER -->
                <div class="page-content-wrap">
                
                
                <div class="col-md-12">
                

          <form action="add_usuario_admin.php" method="post" enctype="multipart/form-data" target="_self">
                

                            <div class="panel panel-default">
                                <div class="panel-heading">                                
                                    <h3 class="panel-title">Cadastro Usuário Admin</h3>
                                    <ul class="panel-controls">
                                        <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
								        <li><a href="#" class="panel-fullscreen"><span class="fa fa-expand"></span></a></li>
                                    </ul>
                                    
                                                                    
                                </div>
                                <div class="panel-body">



             <div class="col-md-12">
              <div class="form-group">
                <label>Nome</label>
                <input type="text" name="nome" class="form-control" placeholder="Nome" id="nome" required="required" />         
              </div>
            </div>

             <div class="col-md-6">
              <div class="form-group">
                <label>Usuário</label>
                <input type="text" name="usuario" class="form-control" placeholder="Usuário" id="usuario" required="required" />         
              </div>
            </div>

             <div class="col-md-6">
              <div class="form-group">
                <label>Senha</label>
                <input type="password" name="senha" class="form-control" placeholder="Senha" id="senha" required="required" />         
              </div>
            </div>
			

            <div class="col-md-12">
              <div class="form-group">
                <label>Foto</label>
               	   <input type="file" name="arquivo" />
              </div>
            </div>
			

                                </div>
                                
					<div class="panel-footer">
					   <button type="submit" class="btn btn-primary pull-right"><span class="fa fa-plus"></span> Adicionar</button>
				    </div>

                                
                            </div>


				</form>




                            <!-- START DEFAULT DATATABLE -->
                            <div class="panel panel-default">
                                <div class="panel-heading">                                
                                    <h3 class="panel-title">Usuários Admin</h3>

                                    <ul class="panel-controls">
                                        <li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
								        <li><a href="#" class="panel-fullscreen"><span class="fa fa-expand"></span></a></li>
                                    </ul>                                
                                </div>
                                <div class="panel-body">
                                    <div class="table-responsive">
                                        <table class="table datatable">
                <thead>
                <tr>
                    <th>Nome</th>
                    <th>Usuário</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                  </tr>
                </thead>
                <tbody>
				<?php
				$sql_consult2 = $sqli->query("SELECT * FROM usuarios_admin ORDER BY nome ASC");
				while ($dados = $sql_consult2->fetch_assoc()) {
				$id = $dados['id'];
				
				if($dados['nivel'] == 1) { $nivel = "Editor"; }
				if($dados['nivel'] == 2) { $nivel = "Administrador"; }
				
				?>
                <tr>
                    <td><?php echo $dados['nome'] ?></td>
                    <td><?php echo $dados['usuario'] ?></td>
                    <td><a data-toggle="modal" data-target="#pop_edita_<?php echo $id ?>"><button class="btn btn-sm btn-primary"><span class="fa fa-search"></span></button></a>
                    </td>
                    <td><a data-toggle="modal" data-target="#pop_excluir_<?php echo $id ?>"><button class="btn btn-sm btn-primary"><span class="fa fa-trash-o"></span></button></a>
                    </td>
                </tr>
                
                
  	<div class="modal modal-primary" id="pop_excluir_<?php echo $id ?>">
 		<form action="delete_usuario_admin.php" method="post" enctype="multipart/form-data" target="_self">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span></button>
                <h4 class="modal-title">Excluir Usuário</h4>
              </div>
              <div class="modal-body">

			  <div class="row">

			 <div class="col-md-12">
             	<p>Tem certeza que deseja excluir o usuário <?php echo $dados['nome'] ?>?</p>
             </div>

			 <input type="hidden" value="<?php echo $id ?>" name="id" id="id" />

           </div>
              </div>
              <div class="modal-footer">
                <input type="submit" class="btn btn-primary pull-right" value="Sim" />
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Não</button>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
                 </form>
        </div>
                
                
        
  	<div class="modal modal-primary" id="pop_edita_<?php echo $id ?>">
 		<form action="atualizar_usuario_admin.php" method="post" enctype="multipart/form-data" target="_self">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">×</span></button>
                <h4 class="modal-title">Editar Usuário</h4>
              </div>
              <div class="modal-body">

			  <div class="row">

			 <input type="hidden" value="<?php echo $id ?>" name="id" id="id" />

             <div class="col-md-12">
              <div class="form-group">
                <label>Nome</label>
                <input type="text" name="nome" class="form-control" placeholder="Nome" id="nome" required="required" value="<?php echo $dados['nome'] ?>" />         
              </div>
            </div>

             <div class="col-md-6">
              <div class="form-group">
                <label>Usuário</label>
                <input type="text" name="usuario" class="form-control" placeholder="Usuário" id="usuario" required="required"  value="<?php echo $dados['usuario'] ?>"/>         
              </div>
            </div>

             <div class="col-md-6">
              <div class="form-group">
                <label>Senha</label>
                <input type="password" name="senha" class="form-control" placeholder="Senha" id="senha" required="required" value="<?php echo $dados['senha'] ?>" />         
              </div>
            </div>

		<?php if($dados['foto'] != '') { ?>
		<div class="col-md-4">
		<img src="<?php echo $dados['foto'] ?>" class="img-responsive" /><br />
		<a href="del_foto_usuario_produtor.php?id=<?php echo $dados['id'] ?>&id_produtor=<?php echo $_GET['id'] ?>" class="btn btn-primary" /><i class="fa fa-trash"></i> Excluir</a>
		</div>
		<?php } ?>			
			
            <div class="col-md-12">
              <div class="form-group">
                <label>Atualizar Imagem</label>
               	   <input type="file" name="arquivo" />
				   <input type="hidden" name="arquivo_antigo" value="<?php echo $dados['foto'] ?>" />
              </div>
            </div>			
			
           </div>
              </div>
              <div class="modal-footer">
                <input type="submit" class="btn btn-primary pull-right" value="Atualizar" />
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
                 </form>
        </div>

             
                  <?php
					}
					?>
                </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <!-- END DEFAULT DATATABLE -->

				
                </div>


                </div>
                <!-- END PAGE CONTENT WRAPPER -->                
            </div>            
            <!-- END PAGE CONTENT -->
        </div>
        <!-- END PAGE CONTAINER -->

        
        <!-- END TEMPLATE -->
    <!-- END SCRIPTS -->         
    </body>
</html>
