
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form-login")) {
  $insertSQL = sprintf("INSERT INTO adminlogin (nome_usuario, email, apelido, senha, tipousuario) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nome'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['apelido'], "text"),
                       GetSQLValueString(md5($_POST['senha']), "text"),
                       GetSQLValueString($_POST['Tipo_usuarios'], "text"));

  mysql_select_db($database_admin, $admin);
  $Result1 = mysql_query($insertSQL, $admin) or die(mysql_error());

  $insertGoTo = "../../login/login_admin.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>


<div id="login_cadastro">
<h2><div class="login_top">NOVO CADASTRO</div><!--FIM LOGIN TOP --></h2>

                                 <div class="login_form">
                                 <form ACTION="<?php echo $editFormAction; ?>" method="POST" name="form-login" id="form-login">
                                 <div class="login_form_input">
                                 <div class="input-group">
                                 <span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
                                 <input name="nome" type="text" class="form-control" id="nome" placeholder="Nome" aria-describedby="basic-addon1" required>
                                 </div>
                                 </div>
                                 <div class="login_form_input">
                                 <div class="input-group">
                                 <span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-envelope"></i></span>
                                 <input name="email" type="email" class="form-control" id="email" placeholder="Email" aria-describedby="basic-addon1" required>
                                 </div>
                                 </div>
                                 <div class="login_form_input">
                                 <div class="input-group">
                                 <span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
                                 <input name="apelido" type="text" class="form-control" id="apelido" placeholder="(Nome)Apelido" aria-describedby="basic-addon1" required>
                                 </div>
                                 </div>
                                 <div class="login_form_input">
                                 <div class="input-group">
                                 <span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-eye-open"></i></span>
                                 <input name="senha" type="password" class="form-control" id="senha" placeholder="Senha" aria-describedby="basic-addon1" required>
                                 </div>
                                 </div>
                                 <div class="login_form_input type checkbox">
                                 <p></p>
                                <select name="Tipo_usuarios">
                                  <option value="Admin">Admin</option>
                                  <option value="Usuario">Usuario</option>
                                </select>
                                 <p></p>
                                 </div>
                                 <input name="botao_login" type="submit" class="login_form_butt" value="Enviar" >
                                 <input type="hidden" name="MM_insert" value="form-login">
                                 </form>
                                 
                                 
</div><!--FIM LOGIN FORM -->
</div><!--FIM LOGIN CONTEUDO -->                                 

