<?php
session_start();
include 'include/db.php';
include 'include/functions.php';
include 'get_user_info.php';

if(isset($_REQUEST['id']) && $_REQUEST['id'] !='')
{
	
$id=trim($_REQUEST['id']);
$name=mysqli_real_escape_string($conn,$_REQUEST['edit_user_name']);
$dob=mysqli_real_escape_string($conn,$_REQUEST['edit_user_dob']);
$gender=isset($_REQUEST['gender']) ? $_REQUEST['gender'] : '';
$address=mysqli_real_escape_string($conn,$_REQUEST['edit_user_address']);
$email=mysqli_real_escape_string($conn,$_REQUEST['edit_user_email']);
$ac=mysqli_real_escape_string($conn,$_REQUEST['edit_user_ac']);
$adhar=mysqli_real_escape_string($conn,$_REQUEST['edit_user_adher']);
$pan=mysqli_real_escape_string($conn,$_REQUEST['edit_user_pan']);
$holder_name=mysqli_real_escape_string($conn,$_REQUEST['edit_user_holder']);
$ifsc=mysqli_real_escape_string($conn,$_REQUEST['edit_user_ifsc']);
$nominee=mysqli_real_escape_string($conn,$_REQUEST['edit_user_nominee']);
$password=mysqli_real_escape_string($conn,$_REQUEST['password']);
$transaction_pwd = mysqli_real_escape_string($conn,$_REQUEST['transaction_pwd']);

$upd_pwd = '';
if(isset($password) && $password !='')
{
	$upd_pwd.= ",user_pwd= '".base64_encode($password)."'";
}
if(isset($transaction_pwd) && $transaction_pwd !='')
{
	$upd_pwd.= ",transaction_pwd= '".$transaction_pwd."'";
}


$query="update registration set user_name='$name', user_address='$address', user_email='$email', gender='$gender', dob='$dob', modified_date=NOW()
 $upd_pwd where LOWER(unique_user_id)='".strtolower($id)."' ";
//echo $query; die;
$connection=mysqli_query($conn,$query);
if($connection)
{
	$bank = get_bank_details($got_unique_id);
	if(!empty($bank) && $bank !='')
	{
		$sql = "UPDATE bank_details SET ac='$ac', adhar='$adhar', pan= '$pan', holder_name='$holder_name', ifsc='$ifsc', nominee = '$nominee' WHERE LOWER(user_unique_id) = '".strtolower($id)."' ";
	}
	else
	{
		$sql = "INSERT INTO `bank_details`(`user_unique_id`, `ac`, `adhar`, `pan`, `holder_name`, `ifsc`, `nominee`) VALUES ('".strtoupper($id)."','$ac','$adhar','$pan','$holder_name','$ifsc','$nominee')";
	}
	$con = mysqli_query($conn, $sql);
	
    if($_SESSION['account_type']=='admin')
    {
        echo '<script> alert("Updated successfully"); window.location="list_user.php"; </script>';
    }
    else
    {
        echo '<script> alert("Updated successfully"); window.location="profile.php"; </script>';
    }
}
else
{
    echo 'Sorry, Not updated';
}

}
else
{
	echo '<script> alert("Sorry, something went wrong"); window.location="profile.php"; </script>';
}



?>