<?php
include('includes/config.php');
if (isset($_POST['reg']) && $_POST['reg'] == "ahkweb"  ) {
  
  $name = mysqli_real_escape_string($conn, $_POST['name']);
  $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
  $email = mysqli_real_escape_string($conn, $_POST['email']);
  $password = mysqli_real_escape_string($conn, $_POST['password']);
  $cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);

  if (!empty($password) && !empty($cpassword) && $mobile != "ADMIN" && $email != "ADMIN") {
    if ($password == $cpassword) {

      $fpassword = password_hash($cpassword, PASSWORD_DEFAULT);
      $checksql = mysqli_query($conn, "SELECT * FROM usertable WHERE emailid='$email' OR phone='$mobile'");
      if (
        !empty($name) &&
        !empty($mobile) &&
        !empty($email) &&
        !empty($password) &&
        !empty($cpassword)
      ) {
        if (mysqli_num_rows($checksql) == 0) {
    
          $sql = "INSERT INTO `usertable` (`phone`, `emailid`, `name`, `password`, `city`, `state`, `userid`, `status`, `profilepic`, `createdby`, `joineddate`, `joinedtime`, `usertype`, `walletamount`,`otp`) VALUES ('$mobile', '$email', '$name', '$fpassword', 'cc', 'sdds', '$mobile', 'verified', '', NULL, '', '', 'OPERATER', '0','');";
          $res = mysqli_query($conn,$sql);
          // 
          if($res){
            ?>
            <script>
              // alert('Your Account Register Successfully!, You can Login');
              $(function() {
        Swal.fire(
            'Success',
            'Register Successfully You can Login',
            'success'
        )
    });

  
  window.setTimeout(function() {
  window.location.href = "index.php";
  }, 1500);

    
            </script>
            <?php
          }else{
            ?>
            <script>
              // alert('Account Not Created ,Try Again!!');
              $(function(){
                Swal.fire(
                  'Opps!',
                  'Internet Server Error, Please Try Again Later!',
                  'error'
                )
    
              });
            </script>
            <?php
          }
          // 
        }else{
          ?>
          <script>
            // alert('Your  email or phone  already exist!');
            $(function() {
        Swal.fire(
            'Opps!',
            'Your  email or phone  already exist!',
            'error'
        )
    });
      
  window.setTimeout(function() {
  window.location.href = "index.php";
  }, 1500);
          </script>
          <?php
        }
      }else{
        ?>
        <script>
             $(function() {
        Swal.fire(
            'Opps!',
            'Please Fill All data',
            'error'
        )
    });
        </script>
        <?php
      }
    }else{
      // echo "Confirm Password Not Match";
      ?>
      <script>
           $(function() {
    Swal.fire(
        'Opps!',
        'Confirm Password Not Match!',
        'error'
    )
});
      </script>
      <?php
    }
  }else{
    ?>
      <script>
           $(function() {
    Swal.fire(
        'WOW trying to Cheat!!!',
        'You Are A Cheater  GET OUT!',
        'error'
    )
});
      </script>
      <?php

  }


}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo $ahkweb['name']; ?> | Registration</title>

    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700&display=fallback">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="./crs/plugins/fontawesome-free/css/all.min.css">

    <!-- icheck bootstrap -->
    <link rel="stylesheet" href="./crs/plugins/icheck-bootstrap/icheck-bootstrap.min.css">

    <!-- AdminLTE -->
    <link rel="stylesheet" href="./crs/dist/css/adminlte.min.css">

    <style>
        body.register-page {
            background: linear-gradient(135deg, #0f172a, #1e293b);
            min-height: 100vh;
        }

        .register-box {
            width: 450px;
        }

        .register-logo a {
            color: #ffffff;
            font-size: 32px;
            font-weight: 700;
            text-decoration: none;
        }

        .card {
            border: none;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 15px 40px rgba(0, 0, 0, .25);
        }

        .card-body {
            padding: 35px;
        }

        .login-box-msg {
            font-size: 20px;
            font-weight: 600;
            color: #111827;
            margin-bottom: 25px;
        }

        .form-control {
            height: 48px;
            border-radius: 8px;
        }

        .input-group-text {
            border-radius: 0 8px 8px 0;
        }

        .btn-primary {
            border-radius: 8px;
            font-weight: 600;
            height: 45px;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            transition: .3s;
        }

        .text-center-login {
            text-align: center;
            margin-top: 15px;
        }

        .text-center-login a {
            font-weight: 600;
            text-decoration: none;
        }

        @media(max-width:500px) {
            .register-box {
                width: 95%;
            }

            .card-body {
                padding: 25px;
            }
        }
    </style>
</head>

<body class="hold-transition register-page">

    <div class="register-box">

        <div class="register-logo">
            <a href="index.php">
                <b>General Public</b> Sign Up
            </a>
        </div>

        <div class="card">
            <div class="card-body register-card-body">

                <p class="login-box-msg">
                    Create Your New Account
                </p>

                <form action="" method="POST">

                    <div class="input-group mb-3">
                        <input type="text" name="name" class="form-control"
                            placeholder="Full Name" required>
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-user"></span>
                            </div>
                        </div>
                    </div>

                    <div class="input-group mb-3">
                        <input type="text" name="mobile" class="form-control"
                            placeholder="Mobile Number" maxlength="10" required>
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-phone"></span>
                            </div>
                        </div>
                    </div>

                    <div class="input-group mb-3">
                        <input type="email" name="email" class="form-control"
                            placeholder="Email Address" required>
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-envelope"></span>
                            </div>
                        </div>
                    </div>

                    <div class="input-group mb-3">
                        <input type="password" name="password"
                            class="form-control"
                            placeholder="Password" required>
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-lock"></span>
                            </div>
                        </div>
                    </div>

                    <div class="input-group mb-3">
                        <input type="password" name="cpassword"
                            class="form-control"
                            placeholder="Confirm Password" required>
                        <div class="input-group-append">
                            <div class="input-group-text">
                                <span class="fas fa-shield-alt"></span>
                            </div>
                        </div>
                    </div>

                    <input type="hidden" name="reg" value="ahkweb">

                    <div class="row">

                        <div class="col-8">
                            <div class="icheck-primary">
                                <input type="checkbox"
                                    id="agreeTerms"
                                    name="terms"
                                    value="agree"
                                    required>

                                <label for="agreeTerms">
                                    I agree to the
                                    <a href="#">Terms & Conditions</a>
                                </label>
                            </div>
                        </div>

                        <div class="col-4">
                            <button type="submit"
                                class="btn btn-primary btn-block">
                                Sign Up
                            </button>
                        </div>

                    </div>

                </form>

                <hr>

                <div class="text-center-login">
                    Already have an account?
                    <br>
                    <a href="general-public">
                        Click Here To Login
                    </a>
                </div>

            </div>
        </div>

    </div>

    <!-- jQuery -->
    <script src="./crs/plugins/jquery/jquery.min.js"></script>

    <!-- Bootstrap -->
    <script src="./crs/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- AdminLTE -->
    <script src="./crs/dist/js/adminlte.min.js"></script>

</body>

</html>

