<?php
session_start();
if((!isset ($_SESSION['login']) == true) and (!isset ($_SESSION['password']) == true))
{
  unset($_SESSION['login']);
  unset($_SESSION['senha']);
  header('location:/?error=1');
  }

$email = $_SESSION['login'];
  
date_default_timezone_set('America/Sao_Paulo');
$error = $_GET['error'];

include('/home/worksmidiacom/cvprov/config/cvprov.config.php');

$sql = $conecta->query("SELECT nome_site FROM config_site WHERE id = '1'");
while ($consulta = $sql->fetch_assoc())
{$nome_site = $consulta['nome_site'];}

$sql1 = $conecta->query("SELECT id, nome FROM usuarios WHERE email = '".$email."'");
while ($consulta1 = $sql1->fetch_assoc())
{$id_user = utf8_encode($consulta1['id']);
 $nome_user = $consulta1['nome'];}

$menu = 2;

?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title><?php echo $nome_site; ?> - Painel de Controle</title>
	<link rel="icon" type="image/x-icon" href="https://www.noharbar.com.br/site/visuais/assets/images/favicon.ico" />
    <link rel="stylesheet" href="<?php echo URL_BASE; ?>controle/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo URL_BASE; ?>controle/fonts/ionicons.min.css">
    <link rel="stylesheet" href="<?php echo URL_BASE; ?>controle/css/Login-Form-Dark.css">
    <link rel="stylesheet" href="<?php echo URL_BASE; ?>controle/css/styles.css">
	<link rel="preconnect" href="https://fonts.googleapis.com">
	<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Ubuntu&display=swap" rel="stylesheet">
	
	<style>
	body {
		font-family: 'Ubuntu', sans-serif;
	}
	
	.espacoInicial {
		height: 70px;
		-webkit-box-shadow: 0px 6px 5px 0px rgba(0,0,0,0.75);
		-moz-box-shadow: 0px 6px 5px 0px rgba(0,0,0,0.75);
		box-shadow: 0px 6px 5px 0px rgba(0,0,0,0.75);
	}
	
	.bgMenu {
		    position: relative;
			background-color: #64635d;
			border-radius: 4px;
			color: #fff;
			padding: 10px 60px;
			margin: 20px 0px;
	}
	
	.nav-pills .nav-link.active, .nav-pills .show>.nav-link {
		color: #64635d;
		background-color: #ffffff;
	}
	
	.boxInformation {
		width: 80%;
		border: 1px solid #ccc;
		border-radius: 8px;
		padding: 12px 42px;
	}
	
	#time-to-dead {
		background-color: #ffffff98;
		position: absolute;
		left: 50%;
		top: 0;
		margin-left: -450px;
		margin-right: 250px;
		margin-top: 200px;
		width: 900px;
		height: 750px;
		border: 1px solid #f0f0f0;
		border-radius: 6px;
		z-index: 997;
		-webkit-box-shadow: 0px 10px 13px 0px rgba(0,0,0,0.75);
		-moz-box-shadow: 0px 10px 13px 0px rgba(0,0,0,0.75);
		box-shadow: 0px 10px 13px 0px rgba(0,0,0,0.75);
	}
	
	.loading {
		position: relative;
		width: 200px;
		height: 200px;
		top: 0;
		left: 50%;
		margin-top: 200px;
		margin-left: -100px;
	}
	</style>
	
</head>

<body>

    <div class="espacoInicial login-dark">
		
    </div>
	<?php
	include("menu.php");
	
	if(!isset($_GET['mes']))
	{$_GET['mes'] = date("m");
	 $_GET['ano'] = date("Y");}
	?>
	
	<?php
	if($_GET['e'] == 1){
	?>
	<div class="container">
        <div class="row">
			<div class="col-md-12">
				<div class="alert alert-success" role="alert">
				  <i class="fas fa-check-circle"></i> A senha do usuário foi alterada com sucesso!!!
				</div>
			</div>
		</div>
	</div>
	<?php
	}
	if($_GET['e'] == 2){
	?>
	<div class="container">
        <div class="row">
			<div class="col-md-12">
				<div class="alert alert-danger" role="alert">
				  <i class="fas fa-times-circle"></i> As senhas não conferem! Por favor, refaça o processo.
				</div>
			</div>
		</div>
	</div>
	<?php
	}
	if($_GET['e'] == 3){
	?>
	<div class="container">
        <div class="row">
			<div class="col-md-12">
				<div class="alert alert-warning" role="alert">
				  <i class="fas fa-exclamation-triangle"></i> O perfil do usuário escolhido foi excluído do sistema.
				</div>
			</div>
		</div>
	</div>
	<?php
	}
	if($_GET['e'] == 4){
	?>
	<div class="container">
        <div class="row">
			<div class="col-md-12">
				<div class="alert alert-success" role="alert">
				  <i class="fas fa-check-circle"></i> O usuário foi inserido com sucesso!!!
				</div>
			</div>
		</div>
	</div>
	<?php
	}
	?>
	
	<div class="container">
        <div class="row">
			<div class="col-md-12">
				<table class="table table-bordered table-striped">
				  <thead>
					<tr>
					  <th scope="col" style="width: 40%; text-align: center;">Nome</th>
					  <th scope="col" style="width: 40%; text-align: center;">E-mail</th>
					  <th scope="col" style="width: 20%;"> </th>
					</tr>
				  </thead>
				  <tbody>
					<?php
					$sql2 = $conecta->query("SELECT * FROM usuarios WHERE email != '".$email."'");
					while ($consulta2 = $sql2->fetch_assoc()){
					$sql3 = $conecta->query("SELECT COUNT(usuario) AS verif_admin FROM mapa_grupo WHERE usuario = '".$consulta2['id']."' AND grupo = '1'");
					while ($consulta3 = $sql3->fetch_assoc())
					{$verif_admin_list = $consulta3['verif_admin'];}
					?>
					<tr>
					  <th scope="row"><?php echo $consulta2['nome']; ?></th>
					  <td><?php echo $consulta2['email']; ?></td>
					  <td class="text-right">
					  <?php
					  if($verif_admin_list > 0){
					  ?>
					  <i class="fas fa-shield-alt text-warning"></i>&nbsp;&nbsp;
					  <?php
					  }
					  ?>
					  <a data-toggle="modal" data-target="#password-<?php echo $consulta2['id']; ?>">
					  <i class="fas fa-key text-primary"></i></a>&nbsp;&nbsp;
					  <a data-toggle="modal" data-target="#delete-<?php echo $consulta2['id']; ?>">
					  <i class="fas fa-trash-alt text-danger"></i></a>
					  </td>
					</tr>
					
					<!-- Modal da Troca de Senha -->
	
					<div class="modal fade" id="password-<?php echo $consulta2['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
					  <div class="modal-dialog" role="document">
						<div class="modal-content">
						  <div class="modal-header">
							<h5 class="modal-title" id="exampleModalLabel">Alterar Senha de <?php echo $consulta2['nome']; ?></h5>
							<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
							  <span aria-hidden="true">&times;</span>
							</button>
						  </div>
						  <div class="modal-body">
							<form action="<?php echo URL_BASE; ?>controle/alt_config.php" method="GET">
							  <div class="form-row">
								<div class="col-6">
								  <input type="password" name="password1" class="form-control" placeholder="Digite a Nova Senha">
								  <input type="hidden" name="id" value="<?php echo $consulta2['id']; ?>">
								  <input type="hidden" name="step" value="0">
								</div>
								<div class="col-6">
								  <input type="password" name="password2" class="form-control" placeholder="Confirme a Nova Senha">
								</div>
							  </div>
							  <div class="form-row">
								<div class="col-12">
								  <br><br>
								  <label>Solicitar Troca de Senha?</label><br>
								  <input type="radio" name="alterar" value="1" CHECKED> SIM&nbsp;&nbsp;&nbsp;&nbsp;
								  <input type="radio" name="alterar" value="0"> NÃO
								</div>
							  </div>
							
						  </div>
						  <div class="modal-footer">
							<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fas fa-times-circle"></i> Fechar</button>
							<button type="submit" class="btn btn-success"><i class="fas fa-check-circle"></i> Alterar</button>
							</form>
						  </div>
						</div>
					  </div>
					</div>
					
					<!-- Modal da Exclusão -->
	
					<div class="modal fade" id="delete-<?php echo $consulta2['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
					  <div class="modal-dialog" role="document">
						<div class="modal-content">
						  <div class="modal-header">
							<h5 class="modal-title" id="exampleModalLabel">Excluir perfil de <?php echo $consulta2['nome']; ?></h5>
							<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
							  <span aria-hidden="true">&times;</span>
							</button>
						  </div>
						  <div class="modal-body">
							<form action="<?php echo URL_BASE; ?>controle/alt_config.php" method="GET">
							  <div class="form-row">
								<div class="col-12">
								  <label>Tem certeza que deseja excluir esse perfil?</label><br>
								  <input type="hidden" name="id" value="<?php echo $consulta2['id']; ?>">
								  <input type="hidden" name="step" value="1">
								</div>
							  </div>
							
						  </div>
						  <div class="modal-footer">
							<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fas fa-times-circle"></i> Fechar</button>
							<button type="submit" class="btn btn-success"><i class="fas fa-check-circle"></i> Confirmar</button>
							</form>
						  </div>
						</div>
					  </div>
					</div>
					
					<?php
					}
					?>
					<tr>
					  <td colspan="3">
						<a data-toggle="modal" class="text-success" data-target="#inserir" style="cursor: pointer;">
						<i class="fas fa-plus-circle"></i> Inserir Usuário
						</a>
					  </td>
					</tr>
				  </tbody>
				</table>
			</div>
		</div>
	</div>
	
					<!-- Modal de Inserção de Usuário -->
	
					<div class="modal fade" id="inserir" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
					  <div class="modal-dialog" role="document">
						<div class="modal-content">
						  <div class="modal-header">
							<h5 class="modal-title" id="exampleModalLabel">Inserir Usuário</h5>
							<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
							  <span aria-hidden="true">&times;</span>
							</button>
						  </div>
						  <div class="modal-body">
							<form action="<?php echo URL_BASE; ?>controle/alt_config.php" method="GET">
							  <div class="form-row">
								<div class="col-12">
								  <input type="text" name="nome" class="form-control" placeholder="Digite o Nome">
								</div>
							  </div>
							  <div class="form-row">
								<div class="col-12">
								  <br><br>
								  <input type="email" name="email" class="form-control" placeholder="Digite o E-mail">
								  <br><br>
								</div>
							  </div>
							  <div class="form-row">
								<div class="col-6">
								  <input type="password" name="password1" class="form-control" placeholder="Digite a Nova Senha">
								  <input type="hidden" name="step" value="2">
								</div>
								<div class="col-6">
								  <input type="password" name="password2" class="form-control" placeholder="Confirme a Nova Senha">
								</div>
							  </div>
							  <div class="form-row">
								<div class="col-12">
								  <br><br>
								  <label>Tipo de Usuário</label><br>
								  <select name="grupo" class="form-control">
								  <?php
								  $sql4 = $conecta->query("SELECT * FROM grupos");
								  while ($consulta4 = $sql4->fetch_assoc()){
								  ?>
								  <option value="<?php echo $consulta4['id']; ?>"><?php echo $consulta4['descricao']; ?></option>
								  <?php
								  }
								  ?>
								  </select>
								</div>
							  </div>
							  <div class="form-row">
								<div class="col-12">
								  <br><br>
								  <label>Solicitar Troca de Senha?</label><br>
								  <input type="radio" name="alterar" value="1" CHECKED> SIM&nbsp;&nbsp;&nbsp;&nbsp;
								  <input type="radio" name="alterar" value="0"> NÃO
								</div>
							  </div>
							
						  </div>
						  <div class="modal-footer">
							<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fas fa-times-circle"></i> Fechar</button>
							<button type="submit" class="btn btn-success"><i class="fas fa-check-circle"></i> Inserir</button>
							</form>
						  </div>
						</div>
					  </div>
					</div>
	
	<script src="https://kit.fontawesome.com/4e2ec11868.js"></script>
	<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    <script id="bs-live-reload" data-sseport="49720" data-lastchange="1588443735284" src="/js/livereload.js"></script>
</body>

</html>