<?php session_start();
if(empty($_SESSION['id'])):
header('Location:index.php');
endif;

include('dist/dbcon.php');
	date_default_timezone_set('Asia/Manila');

	$date = date("Y-m-d");
	$fullname = $_POST['fullname'];
	$typelogin = $_POST['typelogin'];
	$email = $_POST['email'];
	$password = $_POST['password'];
	$address = $_POST['address'];
	$id=$_SESSION['id'];
	if($typelogin == 4){
	    $status="active";
	}else{
	    $status="inactive";
	}
	


	
		$query=mysqli_query($con,"select * from users where email='$email'")or die(mysqli_error());
		$row=mysqli_num_rows($query);
		
		if($row == 1){
		    	echo "<script>alert('Sorry Email is Already Taken');</script>";
	            echo "<script>document.location='register.php'</script>";  
		}elseif($row == 0){
		
	
	
  mysqli_query($con,"INSERT INTO users(fullname,email,password,status,remarks,type,address) 
	VALUES('$fullname','$email','$password','$status','Users','$typelogin','$address')")or die(mysqli_error($con));

if($typelogin == 4){
	   
	   	echo "<script>alert('Hydrocheck Successfully Register your ACCOUNTS');</script>";
	echo "<script>document.location='login.php'</script>";  
	   
	   
	}else{
	   	echo "<script>alert('Hydrocheck Need Approval of Admin for your ACCOUNTS');</script>";
	echo "<script>document.location='login.php'</script>";  
	}
	
		}
	
?>