<?php
session_start();
require_once('includes/config.php');
		$userID 		= $_SESSION['userid'];
		$id 			= $_REQUEST['id'];
		$name			= $_REQUEST['name'];
		$email			= $_REQUEST['email'];
		$phone			= $_REQUEST['mobile'];
		$altMobile		= $_REQUEST['altMobile'];	
		$city			= $_REQUEST['city'];	
		$state			= $_REQUEST['state'];	
		$country		= $_REQUEST['country'];	
		$pincode		= $_REQUEST['pincode'];	
		$address		= $_REQUEST['address'];	
		$user_type_id	= $_REQUEST['user_type_id'];
		$sub_cat_id		= $_REQUEST['sub_cat_id'];	
        $updated_at     = date("Y-m-d H:i:s");
        $lower=strtolower($name);
	$user_edit = mysqli_query($con, "UPDATE users SET user_name ='".$lower."', sub_category_id = '".$sub_cat_id."',updated_at='".$updated_at."' WHERE user_id = '".$id."'");
	
	$user_details_edit = mysqli_query($con, "UPDATE user_details SET name ='".$name."', email = '".$email."', phone = '".$phone."', alternate_phone ='".$altMobile."',city= '".$city."', state='".$state."', country = '".$country."',pincode= '".$pincode."', address_line_one = '".$address."' WHERE user_id = '".$id."'");

	$user_role_edit = mysqli_query($con, "UPDATE user_roles SET role_id ='".$user_type_id."' WHERE user_id = '".$id."'");

    if( $user_edit && $user_details_edit && $user_role_edit ) {
		$message = "A record with id ". $key ." has been updated";
		echo json_encode( ['code' => 200,'data' => $message, 'url' => $call_back ] );exit;
	}else{
		$message = "A record with id ". $key ." update failed";
		echo json_encode( ['code' => 405 , 'data' => $message, 'url' => $call_back ] );exit;	
	}

?>