<?php
	session_start();
	require('includes/config.php');
	print_r($_REQUEST);
	$userName 		= $_REQUEST['name'];
	$password 		= $_REQUEST['password'];
	$passwordSha1 	= sha1($password);
	$email 			= $_REQUEST['email'];
	$mobile 		= $_REQUEST['mobile'];
	$altMobile 		= $_REQUEST['altMobile'];
	$address 		= $_REQUEST['address'];
	$city 			= $_REQUEST['city'];
	$state 			= $_REQUEST['state'];
	$country 		= $_REQUEST['country'];
	$pincode 		= $_REQUEST['pincode'];
	$user_type_id 	= $_REQUEST['user_type_id'];
	$sub_cat_id 	= $_REQUEST['sub_cat_id'];
	$access_token 	= $_SESSION['access_token'];
	$last_logged_on	= $_SESSION['last_logged_on'];
	$loggedForm  	= "web";
	$created_at 	= date("Y-m-d H:i:s");
	$created_by		= $_SESSION['userid'];
	$user_id 		= "";
	$lower=strtolower($userName);
	$sqlUsers = "INSERT INTO users (sub_category_id,user_name,access_token,password,logged_from,last_logged_on,is_internal,created_at )	VALUES ('".$sub_cat_id."','".$lower."','".$access_token."','".$passwordSha1."','".$loggedForm."','".$last_logged_on."','1','".$created_at."')";
		if ($con->query($sqlUsers) === TRUE) {
		    echo "User Table record created successfully <br />";
		} else {
		    echo "User Table Error: " . $sqlUsers . "<br>" . $con->error;
		}
			$sql = "SELECT user_id,sub_category_id,user_name FROM users where  user_name ='".$userName."'";
				$result = $con->query($sql);
				if ($result->num_rows > 0) {
				    // output data of each row
				    while($row = $result->fetch_assoc()) {
						$user_id=$row["user_id"];
				    }
				} 
	$sqlUserDetail = "INSERT INTO user_details (user_id,name,address_line_one,address_line_two,city,state,country,phone,pincode,alternate_phone,email,created_at,created_by )VALUES ('".$user_id."','".$userName."','".$address."','".$address."','".$city."','".$state."','".$country."','".$mobile."','".$pincode."','".$altMobile."','".$email."','".$created_at."','".$user_id."')";
		if ($con->query($sqlUserDetail) === TRUE) {
		    echo "User Detail Table record created successfully <br />";
		} else {
		    echo "User Detail Table Error: " . $sqlUserDetail . "<br>" . $con->error;
		}
	$sqlUserRole = "INSERT INTO user_roles (user_id,role_id,created_at,created_by) VALUES ('".$user_id."','".$user_type_id."','".$created_at."','".$user_id."')";
		if ($con->query($sqlUserRole) === TRUE) {
		    echo "User Role Table record created successfully <br />";
		} else {
		    echo "User Role Table Error: " . $sqlUserRole . "<br>" . $con->error;
		}
?>