<?
include_once("valida_sessao.php");
protegePagina();
include_once("adm_head.php");
?>

<span class="dir">Adicionar novo Usuário</span>
</div>
<div id="conteudo">

<?php
include_once("config.php");

if (isset($_POST['submit'])) {

$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$nome = $_POST['nome'];
$email = $_POST['email'];
$adm_usuarios = $_POST['adm_usuarios'];
$adm_conteudo = $_POST['adm_conteudo'];
$adm_conteudo_pub = $_POST['adm_conteudo_pub'];
$adm_galeria = $_POST['adm_galeria'];
$adm_banner = $_POST['adm_banner'];
$adm_video = $_POST['adm_video'];
$adm_newsletter = $_POST['adm_newsletter'];

$alt_func = $_SESSION['usuarioNome'];

   include_once("utf8.php");   

	$busca = mysqli_query($conn, "SELECT usuario FROM usuarios WHERE USUARIO='$usuario'");
	if((mysqli_num_rows($busca) == 0)AND($senha)){   
	   $insere = "INSERT INTO usuarios (usuario,senha,nome,email,adm_usuarios,adm_conteudo,adm_conteudo_pub,adm_galeria,adm_banner,adm_video,adm_newsletter,alt_func)
	   VALUES ('$usuario',md5('$senha'),'$nome','$email','$adm_usuarios','$adm_conteudo','$adm_conteudo_pub','$adm_galeria','$adm_banner','$adm_video','$adm_newsletter','$alt_func')";
	   mysqli_query($conn, $insere);
	   //mysql_close($conn);
   
   		echo "<p class=\"sucesso\">Adicionado Com Sucesso!</p>";  
	} else {
		echo "<p class=\"erro\">Usuário não adicionado: Login ".$usuario." já utilizado!</p>";
	}
}

?>

<form name="frmusuario" method="POST" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="return valida_usuario(this);">
<table align="center" cellspacing="0" cellpadding="0">
		  <tr>
            <td>
            <img src="imagem/importante.gif" />
            Usuário <br />
            <input type="text" name="usuario" size="40" maxlength="30" />
            </td>
          </tr>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Senha <br />
            <input type="password" name="senha" size="40" maxlength="30" />
            </td>
          </tr>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Nome <br />
            <input type="text" name="nome" size="40" maxlength="50">
            </td>
          </tr>
          <tr>
            <td>
            E-mail <br />
            <input type="text" name="email" size="40" maxlength="50">
            </td>
          </tr>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Usuários? <br />
            <select name="adm_usuarios">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
		  <?php if(mysqli_query($conn, "SELECT * FROM ctd_blocos")) { ?>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Conteúdo? <br />
            <select name="adm_conteudo">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Publicação de Conteúdo? <br />
            <select name="adm_conteudo_pub">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
		  <?php }
		  if(mysqli_query($conn, "SELECT * FROM glr_galeria")) { ?>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Galerias? <br />
            <select name="adm_galeria">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
		  <?php }
		  if(mysqli_query($conn, "SELECT * FROM bnr_ban_imagens")) { ?>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Banners? <br />
            <select name="adm_banner">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
          <? }
		  if(mysqli_query($conn, "SELECT * FROM vds_videos")) { ?>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Videos? <br />
            <select name="adm_video">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
          <? }
		  if(mysqli_query($conn, "SELECT * FROM nlt_emails")) { ?>
          <tr>
            <td>
            <img src="imagem/importante.gif" />
            Administra Newsletter? <br />
            <select name="adm_newsletter">
              <option value="0">Não</option>
              <option value="1">Sim</option>
            </select>
            </td>
          </tr>
          <? } ?>
          <tr>
            <td align="center">
              <input type="button" value="Voltar" name="voltar" onclick="location.href='usuario_adm.php'">
              <input type="submit" value="Salvar" name="submit"></td>
          </tr> 
</table>
</form>
<? include_once("adm_foot.php"); ?>