<?php
function sm_manage_account_details(){
    $html = "";
    global $wpdb;
    $wpdb_prefix = $wpdb->prefix;
    $idd = $_GET['id'];
    $account= $wpdb_prefix.'sm_accounts_management';
    $account_record = "SELECT * FROM $account WHERE id=$idd";
    $account_result = $wpdb->get_results($account_record);
    ?>
    <form method="post">
        <?php
			$sno=1;
            foreach($account_result as $row){
				$id = $row->id;
        ?>	
        <div class="row">
            <div class="col-lg-6 col-md-6 col-12">
                <label style="color:#fff;" for="email"><?php _e('Account Holder','investor_details'); ?></label><br>
                <input type="text" name="holder" class="form-control" aria-describedby="emailHelp" value="<?php echo $row->AccountHolder; ?>" required />
            </div>
                
            <div class="col-lg-6 col-md-6 col-12">
                <label style="color:#fff;" for="firstname"> <?php _e('IBAN','investor_details'); ?></label><br>
                <input class="form-control" type="text" value="<?php echo $row->IBAN; ?>" name="iban" required />
            </div>

        </div>
        <div class="row">
            <div class="col-lg-6 col-md-6 col-12 mt-3">
                <label style="color:#fff;" for="website"><?php _e('BIC','investor_details'); ?></label><br>
                <input class="form-control" type="text" value="<?php echo $row->BIC; ?>" name="bic">
            </div>

            <div class="col-lg-6 col-md-6 col-12 mt-3">
                <label style="color:#fff;" for="number"><?php _e('Bank Code','investor_details'); ?></label><br>
                <input class="form-control" type="number" value="<?php echo $row->BankCode; ?>" name="bcode">
            </div>
        </div>
 
		<div class="row">
            <div class="col-lg-6 col-md-6 col-12 mt-3">
                 <label style="color:#fff;" for="website"><?php _e('Bank Name','investor_details'); ?></label><br>
            <input class="form-control" type="text" value="<?php echo $row->BankName; ?>" name="bname">
            </div>

			<?php $result_status=$row->Status; ?>
            <div class="col-lg-6 col-md-6 col-12 mt-3">
                <label style="color:#fff;" for="number"><?php _e('Status','investor_details'); ?></label><br>
				<select class="form-control" name="status">
					<option><?php echo $result_status; ?></option>
					<?php if($result_status == 'In-Active'){ ?>
						<option><?php _e('Active', CIP_TXTDOMAIN); ?></option>
					<?php }
					else{
					?>
						<option><?php _e('In-Active', CIP_TXTDOMAIN); ?></option>
					<?php } ?>
				</select>
            </div>
        </div>

        <div class="mt-3">
            <label style="color:#fff;" for="website"><?php _e('Bank Address','investor_details'); ?></label><br>
            <textarea class="form-control" name="baddress"><?php echo $row->BankAddress; ?></textarea><br>
        </div>

        <div>
            <input type="submit" class="btn btn-primary" name="submit" value="Submit"/>
        </div>  

        <?php $sno=$sno+1;} ?>
    </form>
    <?php

    if(isset($_POST['submit'])){
        $holder=$_POST['holder'];
        $iban=$_POST['iban'];
		$status=$_POST['status'];
        $bic=$_POST['bic'];
        $bank_code=$_POST['bcode'];
        $bank_name=$_POST['bname'];
        $bank_address=$_POST['baddress'];
// 		echo $bank_address;

        $update_account = $wpdb->update( 
            $account, 
            array( 
                'AccountHolder'   => 	$holder,
				'Status'       	  => 	$status,
                'IBAN'       	  => 	$iban,
                'BIC'             => 	$bic,
                'BankCode'        => 	$bank_code,
                'BankName' 		  => 	$bank_name,
                'BankAddress'     => 	$bank_address,
            ), 
            array( 'ID' => $idd )
        );
        if($update_account){
            echo "Account Details updated Successfully.";
			$redirect_url = get_permalink( get_page_by_title( 'SM View Accounts' ) );
			header( "refresh:0;"); 
        }
        else{
            echo "Something Wrong";
        }

    }	
}