
<?php include('../config/constants.php');?>

<!-- login and sign up form-->
<!DOCTYPE html>
<html>
  <head>
    <title>
      
    </title>
    <link rel="stylesheet" type="text/css" href="signupcss.css">
  </head>
  <body>
    <div class="wrapper">
      <strong >Register Your Account In Just A Few Seconds</strong>
    </div>
    
    <div class="form">

  <!-- login -->
   


  <!-- sign up-->
  <div class="sign-up-form">
    <!-- cansel btn -->
     
    <!-- heading-->
    <strong>Sign Up</strong>
    <!-- inputs-->
    <form action="" method="post">
      <input type="text" name="fullname" placeholder="enter Your Fullname" required>
      <input type="text" name="username" placeholder="enter Your username" required>
      
      <input type="email" name="email"placeholder="enter your email" required>
      
      <input type="password" name="password" placeholder="enter password" required>
      <input type="password" name="confirm-password" placeholder="confirm  password" required>
      <!-- submit -->
      <input type="hidden" name="role"value="0">
      <input type="submit" name="harry"value="Signup1">
    </form>
    <div class="form-btns">
      <!-- forget password and sign up btn -->
      <a href="login.php"class="already-account">Already Have Account?</a>
       <!-- <a href="<?php //echo SITEURL;?>login.php" class="already-account">Already Have Account?</a> -->

    </div>

  </div>
</div>
<!-- insert data into db -->
<?php
   //process the value from form and save in the SQLiteDatabase
   //check whether the submit btn is clicked or not
   if(isset($_POST['harry'])){

     // Button clicked
     //get the data from form
     $fullname = $_POST['fullname'];
     $username = $_POST['username'];
     $email =  $_POST['email'];
     $role = $_POST['role'];

     $password = $_POST['password']; //pasword encryption with md5
     $confirmpassword = $_POST['confirm-password']; //pasword encryption with md5


      //$email = $_POST['email'];
      $sqlcheckemail = "SELECT * FROM tbl_user WHERE email='$email'";
      $resultcheck = $conn->query($sqlcheckemail);
      if ($resultcheck->num_rows > 0) {
        echo "A user with the same email already exists.";
      }
      else{
         if($password==$confirmpassword){
       function isValidPassword($password) {
       $hasCharacter = preg_match('/[a-zA-Z]/', $password);
       $hasNumber = preg_match('/\d/', $password);
       $hasSymbol = preg_match('/[!@#$%^&*()_+\-=\[\]{};\':"\\|,.<>\/?]/', $password);

        return ($hasCharacter && $hasNumber && $hasSymbol);
      }

        //$password = "Password1!";
      if (isValidPassword($password)) {
       echo "Valid password";
       $correctpwd = md5($password);
       $sql = "INSERT INTO tbl_user SET
          full_name = '$fullname',
          
          password = '$correctpwd',
          email = '$email',
          username = '$username'
       ";
       //execute query and save data in the database
       $res = mysqli_query($conn, $sql);
       //check whether the data is inserted or not and display appropriate message
        if($res==TRUE){
          // create session var to display message
         $_SESSION['add'] = "Account Created Successfully";
          //Redirect Page
         header('location:'.SITEURL.'shopping/login.php');

        }else{
          // create session var to display message
          $_SESSION['failed'] = "Failed To Create Account";
          //Redirect Page
          header('location:'.SITEURL.'shopping/signin.php');

        }
      } else {
       echo "Invalid password";
      }

       // sql to insert the data into the database
       
     }
      
    else{
       // create session var to display message
       $_SESSION['pwdmatch'] = "Password did not match";
       //Redirect Page
       header('location:'.SITEURL.'shopping/signin.php');

     }
   }
 }
   ?>
   
  </body>
</html>
