<?php
//print_R($_POST);
require 'sql.php';
if(isset($_POST['btn_registrar'])){
  foreach ($_POST as $key => $value) {
    $_POST[$key] = addslashes($value); 
  }

  if(isset($_POST['senha1']) && !empty($_POST['senha1'])){
    if(isset($_POST['senha2']) && !empty($_POST['senha2'])){
      if($_POST['senha1'] == $_POST['senha2']){

        $nome = $_POST['nome'];
        $sobrenome = $_POST['sobrenome'];
        $senha = hash("whirlpool",$_POST['senha1']);
        $email = $_POST['email'];

        $checar = mysql_query('SELECT * FROM user WHERE email="'.$email.'"');
        $numr = mysql_num_rows($checar);
        echo $numr;
        if($numr === 0){
        mysql_query("INSERT INTO `user` (`email`, `password`, `nome`, `sobrenome`, `status`, `level`) VALUES ('$email', '$senha', '$nome', '$sobrenome', '1', '0')");
        $id_user = mysql_insert_id();
        mysql_query("INSERT INTO `planos` (`ip_perso`, `id_user`, `dias_restantes`) VALUES ('1', $id_user, '60')");
        header('Location: login.php?registrado');

        $subject = 'Registro';
        $message = '
        Mensagem de Registro
        ';
        $headers[] = 'MIME-Version: 1.0';
        $headers[] = 'Content-type: text/html; charset=iso-8859-1';
        $headers[] = 'To: '.$_POST['nome'].' <'.$_POST['email'].'>';
        $headers[] = 'From: PainelDNS <noreply@paineldns.com>';
        mail($_POST['email'], $subject, $message, implode("\n", $headers));



        die();
        }else{
          header('Location: signup.php?emailuso');
          die();
        }
      }else{
        header('Location: signup.php?senhasdiferentes');
        die();
      }
    }else{
      header('Location: signup.php?confirmesenha');
      die();
    }
  }else{
      header('Location: signup.php?digitesenha');
      die();
  }





}

?>

<!DOCTYPE html>
<html lang="pt_BR">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <link rel="shortcut icon" href="inc/img/favicon.png">

    <title>Painel DNS | Registro</title>
    <link href="inc/css/bootstrap.min.css" rel="stylesheet">
    <link href="inc/css/bootstrap-reset.css" rel="stylesheet">
    <link href="inc/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="inc/css/style.css" rel="stylesheet">
    <link href="inc/css/style-responsive.css" rel="stylesheet" />

   
    <!--[if lt IE 9]>
    <script src="inc/js/html5shiv.js"></script>
    <script src=inc/"js/respond.min.js"></script>
    <![endif]-->
</head>

  <body class="login-body">

    <div class="container">

      <form class="form-signin" action="" method="POST">
        <h2 class="form-signin-heading">Área do cliente</h2>


<?php
      if (isset($_GET['confirmesenha'])){
      echo'
        <div class="alert alert-danger alert-dismissable">
        Confirme a sua Senha
        </div>';
      }


      if (isset($_GET['digitesenha'])){
      echo'
        <div class="alert alert-danger alert-dismissable">
        Digite uma Senha
        </div>';}

      if (isset($_GET['senhasdiferentes'])){
      echo'
        <div class="alert alert-danger alert-dismissable">
        As senhas precisam ser iguais!!
        </div>';}



      if (isset($_GET['emailuso'])){
      echo'
        <div class="alert alert-danger alert-dismissable">
        Esse email ja esta em uso :)
        </div>';}

            ?>


        <div class="login-wrap">
          <input type="text" class="form-control" name="nome" placeholder="Nome">
          <input type="text" class="form-control" name="sobrenome" placeholder="Sobrenome">
            <input type="text" class="form-control" name="email" placeholder="seuemail@email.com" autofocus>
            <input type="password" class="form-control" name="senha1" placeholder="Senha">
            <input type="password" class="form-control" name="senha2" placeholder="Repita a Senha">
            <label class="checkbox">
                <input type="checkbox" value="remember-me"> Manter Conectado
                <span class="pull-right">
                    <a href="login.php"> Ja tem uma conta?</a>

                </span>
            </label>
            <button class="btn btn-lg btn-login btn-block" name="btn_registrar" type="submit">Registrar</button>
           </form>
        </div>

    </div>

    <script src="inc/js/jquery.js"></script>
    <script src="inc/js/bootstrap.min.js"></script>
    <script type="text/javascript">
!function(t){var e=t.createElement("script");e.type="text/javascript",e.charset="utf-8",
e.src="https://static.moxchat.it/visitor-widget-loader/8l2M1lJ2RX.js",e.async=!0;
var a=t.getElementsByTagName("script")[0];a.parentNode.insertBefore(e,a);
}(document);
    </script>

  </body>
</html>
