<?php
	session_start();
	include "connect.php";	
	if(isset($_SESSION['Master_login'])){ header("location:home.php");}
	
	if(isset($_POST['Login']) && $_POST['Login']=='Master')
	{        
		$name=$_POST['name'];
		$username=$_POST['username'];
		$referral_id = "";
		$user_refferal_name = "";
		if($_POST['referral_id'] == ""){
			$referral_id = 999999;
		}else{
		$referral_id = $_POST['referral_id'];
		}
		$country=$_POST['country'];
		$email_id=$_POST['email_id'];
		$mobile=$_POST['mobile'];
		$pan_no=$_POST['pan_no'];
		$password=md5($_POST['password']);
		$dd = $_POST['password'];
		 $b2 = '';
		 for($i = 0; $i < 8; $i++){
	 $b2 .= mt_rand(0,9);
	 }
//echo "SELECT * FROM `user_tbl` WHERE user_name = '$username'";
	 $query1 = mysqli_query($conn,"SELECT * FROM `user_tbl` WHERE user_name = '$username'");
		$row1 = mysqli_fetch_array($query1);
		$num1 = mysqli_num_rows($query1);
		if($num1 == 0){
		 $query = mysqli_query($conn,"SELECT * FROM `user_tbl` WHERE user_unique_id = '$referral_id'"); 
		$num = mysqli_num_rows($query);
		if($num == 0){
			
		 echo "<script>alert('Dose not exist Referral Id!');   window.location = 'signup.php'; </script>";	
		}else{
		$row = mysqli_fetch_array($query);
		$user_refferal_name = $row['user_name'];
		$checkLogin=mysqli_query($conn,"INSERT INTO `user_tbl`(`id`, `user_unique_id`, `user_refferal_code`, `user_refferal_name`, 
		`user_name`, `password`, `country`, `email_id`, `mobile_no`, `pan_no`, `name`) VALUES 
		(NULL,'$b2','$referral_id','$user_refferal_name','$username','$password',
		'$country','$email_id','$mobile','$pan_no','$name')");
		if($checkLogin){
			 echo "<script>alert('Welcome Member! \\n \\n Your user name: $username  \\n Password: $dd ');   window.location = 'index.php'; </script>";		
				//header("location:home.php");			
		}else{
			 header("location:index.php?err");			 
		}
			
		}
		}else{
		 echo "<script>alert('Exist Member!');   window.location = 'signup.php'; </script>";		
		}
	}
$wr='<div class="alert alert-warning alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Warning!</strong> Profile is not active.</div>';
//$success='<div class="alert alert-success alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Success!</strong> Login is successfull.</div>';
$err='<div class="alert alert-danger alert-dismissible" role="alert" style="margin-top: -18px; padding: 10px;"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true" style="margin-left:-50px; color:white;">&times;</span><span class="sr-only">Close</span></button><strong>Wrong!</strong> Invalid credentials.</div>';
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>:: DOCHCARE  | Sign Up ::</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">  
  <link rel="stylesheet" href="assets/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="assets/bower_components/Ionicons/css/ionicons.min.css">  
  <link rel="stylesheet" href="assets/dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="assets/plugins/iCheck/square/blue.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic"> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
$(document).ready(function(){
  //  $("input").keyup(function(){
    //    var txt = $("input").val();
      //  $.post("fetch_ajax_customer.php", {suggest: "SELECT * FROM `customer_details`   ORDER BY `customer_details`.`id` DESC "}, function(result){ // fetch_ajax_sql.php
     //       $("tbody").html(result);
      //  });
   // }); 
  
   
	

 
 $('#pan_no').on('blur' , function() {
var panVal = $('#pan_no').val();
var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;
if(panVal !="" ){
if(regpan.test(panVal)){
  // valid pan card number
} else {
  alert('invalid pan card number .'); // invalid pan card number
  //$("#pan_no").focus();
}
}	
 });

	
    $("#mobile").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        alert('Enter numerical numbers only.');
	   return false;
            
    }
   });
   
   $(function() {
    $('#email_id').on('blur' , function() {
        // Your code here
		 if($('#email_id').val() != ""){
		validmail();
		 }
    });
  });
 
 
   	
});


function validmail(){
	var txt =  document.getElementById("email_id").value; 
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt))
  {
    return (true);
  }else{
    alert("You have entered an invalid email address!")
    //$("#email_id").focus();
  }
}  

</script>  
</head>
<body class="hold-transition login-page" style="height:auto; background-image: radial-gradient(white, #20B2AA);" >
<div class="login-box">
  <div class="login-logo">
    <a href="#"><b>DOCHCARE</b></a>
  </div> 
  <div class="login-box-body" style="box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}">
    <p class="login-box-msg">Sign Up</p>
	 <div id="response"><?php if(isset($_GET['wr'])){ echo $wr; } ?><?php if(isset($_GET['err'])){ echo $err; } ?></div>
     <form id="frm_login" role="form" action="" method="POST">
		<input type="hidden" name="Login" id="Login" value="Master" />
	 <div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
		<input type="text" name="name" class="form-control" placeholder="Name" required autocomplete="off">
	</div>    <br/>
	<div class="input-group"> 
		<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
		<input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off">
	</div><br/>
	<div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
		<input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
	</div>  <br/>  
	<div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-qrcode"></i></span>
		<input type="text" name="referral_id" class="form-control" placeholder="Referral ID" autocomplete="off">
	</div><br/>
	<div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
		<input type="text" name="email_id" id="email_id" class="form-control" placeholder="Email id" autocomplete="off">
	</div><br/>
	<div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
		<input type="text" name="mobile" id="mobile" maxlength="10" class="form-control" placeholder="Mobile" >
	</div><br/>
	<div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-book"></i></span>
		<input type="text" name="pan_no" id="pan_no" class="form-control" placeholder="Pan No." autocomplete="off">
	</div><br/><div class="input-group">
		<span class="input-group-addon"><i class="glyphicon glyphicon-flag"></i></span>
		<input type="text" name="country" class="form-control" placeholder="Country" autocomplete="off">
	</div><br/>
	    
      <div class="row">         
        <div class="col-xs-4">
          <button id="ret" type="submit" class="btn btn-primary btn-block btn-flat pull-left">Sign Up</button>
        </div>    
      </div><div class="input-group"><br>
	   <a href="index.php">Already have an account? Click here for sign in</a>
	   </div>
    </form>     
  </div>  
</div>
<script src="assets/bower_components/jquery/dist/jquery.min.js"></script>
<script src="assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="assets/plugins/iCheck/icheck.min.js"></script>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' /* optional */
    });
  });
</script>
</body>
</html>