<?php
session_start();
require_once('../config/config.php');
require_once('../class/functions.php');
dbconnect();

if (!is_admin()) {
    redirect(LOGIN);
}

$page = "Account Profile";
$geo = ip2location($_SERVER['REMOTE_ADDR']);
$country = $geo->country;
$city = $geo->city;
visit_log($_SERVER['REMOTE_ADDR'], $country, $city, $_SERVER['HTTP_USER_AGENT'], getBrowser($_SERVER['HTTP_USER_AGENT']), getOS($_SERVER['HTTP_USER_AGENT']), $page, $_SESSION['admin_login']);


if (isset($_POST['addTrn']) && $_POST['addTrn'] == 'addTrn')
{
if ($_POST['fmAcc'] == ""){ store_msg("Select Account to add transaction to", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif ($_POST['tdate'] == ""){ store_msg("Enter transaction date", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif ($_POST['type'] == ""){ store_msg("Selection transaction type", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif ($_POST['details'] == ""){ store_msg("Enter transaction details", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif ($_POST['amount'] == ""){ store_msg("Enter transaction amount", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif (!valid_date($_POST['tdate'])){ store_msg("Invalid date format, use:YYYY-MM-DD", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
elseif ($_POST['type'] == "debit" && !sufficient_balance($_POST['fmAcc'], $_POST['amount'])){ store_msg("Insufficient Balance", "danger"); redirect(PROFILE.'?user='.$_GET['user']);}
else{

$date = clean_data($_POST['tdate']);
$details = clean_data($_POST['details']);
$type = clean_data($_POST['type']);
$amnt = clean_data($_POST['amount']);
$usernumber = clean_data($_POST['usernumber']);
$usernames = clean_data($_POST['usernames']);
$currency = clean_data($_POST['currency']);
$account = clean_data($_POST['fmAcc']);
$amount = str_replace( ',', '', $amnt );
$transnumber = trans_number();
$status = "1";


if ($type == 'credit'){

dbconnect();
$stmt = $pdo->prepare('INSERT INTO '.TRANS_TABLE_NAME.' (trans_number, user_number, acc_no, acc_name, currency, trans_date, trans_details, trans_status, credit) VALUES (:transnumber, :usernumber, :accountno, :usernames, :currency, :date, :details, :status, :credit)');

$stmt->execute(array(':transnumber' => $transnumber, ':usernumber' => $usernumber, ':accountno' => $account, ':usernames' => $usernames, ':currency' => $currency, ':date' => $date, ':details' => $details, ':status' => $status, ':credit' => $amount));
if ($pdo->lastInsertId()) {

$creditsms = credit_sms();
$creditemail = credit_email();


	if (isset($_POST['sndEml'])) {

	// Send EMAIL
	$message = "
	<html>
	<head>
	<title>".WEB_NAME."</title>
	</head>
	<body>
	<img src=".LOGO_URL." alt=".WEB_NAME."/><br><br>
	<p>".strtoupper($creditemail).":<br><br>
	TRANSACTION DATE: ".date('jS F Y', strtotime($date))." <br>
	SOURCE ACCOUNT: ".$account." <br>
	AMOUNT: ".$currency."".$amount." <br>
	DETAILS: ".$details."<br>
	</p><br><br><br>
	===========
	<p>".WEB_NAME."</p>
	</body>
	</html>
	";

    $email = get_email($usernumber);
    $subject = "TRANSACTION NOTIFICATION CREDIT";
    //send_email($fromname, $fromemail, $toemail, $subject, $message)
    send_email(WEB_NAME, WEB_EMAIL, $email, $subject, $message);
	}


	if (isset($_POST['sndSms']) && USE_SMS) {
	//send SMS to User
    $phone = clean_phone(user_phone($usernumber));
    $sms_cnt = ''.strtoupper($creditsms).' DATE '.$date.' ACCOUNT '.$account.', AMOUNT '.$currency.' '.number_format($amount,2).' DETAILS '.$details.'';
    sms_scryba($phone, $sms_cnt);
    }

log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $usernames, 'Transaction Succesfully Added');
store_msg("Transaction Succesfully Added", "success"); redirect(PROFILE.'?user='.$_GET['user']);
}else{
store_msg("Add Transaction Error", "danger"); redirect(PROFILE.'?user='.$_GET['user']);
}

}else{
dbconnect();
$stmt = $pdo->prepare('INSERT INTO '.TRANS_TABLE_NAME.' (trans_number, user_number, acc_no, acc_name, currency, trans_date, trans_details, trans_status, debit) VALUES (:transnumber, :usernumber, :accountno, :usernames, :currency, :date, :details, :status, :debit)');

$stmt->execute(array(':transnumber' => $transnumber, ':usernumber' => $usernumber, ':accountno' => $account, ':usernames' => $usernames, ':currency' => $currency, ':date' => $date, ':details' => $details, ':status' => $status, ':debit' => $amount));
if ($pdo->lastInsertId()) {

$debitsms = debit_sms();
$debitemail = debit_email();


	if (isset($_POST['sndEml'])) {

	// Send EMAIL
	$message = "
	<html>
	<head>
	<title>".WEB_NAME."</title>
	</head>
	<body>
	<img src=".LOGO_URL." alt=".WEB_NAME."/><br><br>
	<p>".strtoupper($debitemail).":<br><br>
	TRANSACTION DATE: ".date('jS F Y', strtotime($date))." <br>
	SOURCE ACCOUNT: ".$account." <br>
	AMOUNT: ".$currency."".$amount." <br>
	DETAILS: ".$details."<br>
	</p><br><br><br>
	===========
	<p>".WEB_NAME."</p>
	</body>
	</html>
	";

    $email = get_email($usernumber);
    $subject = "TRANSACTION NOTIFICATION DEBIT";
    //send_email($fromname, $fromemail, $toemail, $subject, $message)
    send_email(WEB_NAME, WEB_EMAIL, $email, $subject, $message);
	}


	if (isset($_POST['sndSms']) && USE_SMS) {
	//send SMS to User
    $phone = clean_phone(user_phone($usernumber));
    $sms_cnt = ''.strtoupper($debitsms).' DATE '.$date.' ACCOUNT '.$account.', AMOUNT '.$currency.''.number_format($amount,2).' DETAILS '.$details.'';
    sms_scryba($phone, $sms_cnt);
    }

log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $usernames, 'Transaction Succesfully Added');
store_msg("Transaction Succesfully Added", "success"); redirect(PROFILE.'?user='.$_GET['user']);
}else{
store_msg("Add Transaction Error", "danger"); redirect(PROFILE.'?user='.$_GET['user']);
}
}

}
}


if (isset($_POST['addAcc']) && $_POST['addAcc'] == 'addAcc')
{
if ($_POST['usrAc'] == "") { store_msg("Account Number is required", "danger"); redirect(ACTIVATE);}
elseif (acc_exist($_POST['usrAc'])) { store_msg("Account Number already exist", "danger"); redirect(ACTIVATE);}
elseif ($_POST['accSts'] == "") { store_msg("Select Account Status", "danger"); redirect(ACTIVATE);}
elseif ($_POST['acctyp'] == "") { store_msg("Account Type is required", "danger"); redirect(ACTIVATE);}
elseif ($_POST['accCur'] == "") { store_msg("Select Currency", "danger"); redirect(ACTIVATE);}
//elseif (!empty($_POST['usrCd1'])) { $code1 = clean_data($_POST['usrCd1']);}
//elseif (!empty($_POST['usrCd2'])) { $code2 = clean_data($_POST['usrCd2']);}
//elseif (!empty($_POST['usrCd3'])) { $code3 = clean_data($_POST['usrCd3']);}
else{
$acc = clean_data($_POST['usrAc']);
$accstatus = clean_data($_POST['accSts']);
$type = clean_data($_POST['acctyp']);
$currency = clean_data($_POST['accCur']);
$usernumber = clean_data($_POST['usernumber']);
$usernames = clean_data($_POST['usernames']);
$code1 = clean_data($_POST['usrCd1']);
$code2 = clean_data($_POST['usrCd2']);
$code3 = clean_data($_POST['usrCd3']);
$regip = $_SERVER['REMOTE_ADDR'];

$stmt = $pdo->prepare('INSERT INTO '.ACCS_TABLE_NAME.' (user_number, acc_no, acc_name, acc_code1, acc_code2, acc_code3, acc_status, currency, acc_type, reg_ip, registered) VALUES (:usernumber, :accno, :accname, :code1, :code2, :code3, :status, :currency, :type, :regip, NOW())');

if ($stmt->execute(array(':usernumber' => $usernumber, ':accno' => $acc, ':accname' => $usernames, ':code1' => $code1, ':code2' => $code2, ':code3' => $code3, ':status' => $accstatus, ':currency' => $currency, ':type' => $type, ':regip' => $regip))){

log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $acc, 'New Account Successfully Activated');
store_msg("New Account Added Successfully", "success");
redirect(PROFILE.'?user='.$usernumber);
}else{
store_msg("Add New Account Error", "danger"); redirect(PROFILE.'?user='.$usernumber);
}

}
}


if (isset($_POST['delTrn']) && $_POST['delTrn'] == 'delTrn')
{
    $transno = clean_data($_POST['transNo']);
    if (delete_trans($transno)) {
		log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $transno, 'Transaction Successfully Deleted');
		store_msg("Transaction Successfully Deleted", "success"); redirect(PROFILE.'?user='.$_GET['user']);
	}else{
    store_msg("Transaction Delete Error", "danger"); redirect(PROFILE.'?user='.$_GET['user']);
    }
}


if (isset($_POST['delAcc']) && $_POST['delAcc'] == 'delAcc')
{
    $accountno = clean_data($_POST['accNo']);
    if (delete_acc($accountno)) {
		log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $accountno, 'Account Successfully Deleted');
		store_msg("Account Successfully Deleted", "success"); redirect(PROFILE.'?user='.$_GET['user']);
	}else{
    store_msg("Account Delete Error", "danger"); redirect(PROFILE.'?user='.$_GET['user']);
    }
}

require_once('head.php');
?>

<body>
  <div class="app" id="app">

<!-- ############ LAYOUT START-->
  <!-- aside -->
  <?php require_once('aside.php'); ?>
  <!-- / aside -->



  <!-- content -->
  <div id="content" class="app-content box-shadow-z3" role="main">

    <?php require_once('header.php'); ?>

    <?php require_once('footer.php'); ?>

    <div ui-view class="app-body" id="view">
    <!-- ############ PAGE START-->

    <?php
        $usernumber = clean_data($_GET['user']);
        if (!empty($usernumber) && number_exist($usernumber)) {
        $sql = "SELECT * FROM `".USERS_TABLE_NAME."` WHERE user_number='{$usernumber}' or user_id='{$usernumber}'";
        $stmt = $pdo->query($sql);
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
    ?>


    <div class="item">
        <div class="item-bg">
          <img src="../users/<?php echo user_photo($row['user_login']); ?>" class="blur opacity-3">
        </div>
        <div class="p-a-md">
          <div class="row m-t">
            <div class="col-sm-10">
              <a href class="pull-left m-r-md">
                <span class="avatar w-96">
                  <img src="../users/<?php echo user_photo($row['user_login']); ?>">
                  <?php if($row['user_online'] == '1'){echo '<i class="on b-white"></i>';} ?>
                </span>
              </a>
              <div class="clear m-b">
                <p class="text-md profile-status">Account holder details</p>
                <h3 class="m-a-0 m-b-xs"><?php echo $row['user_names']; ?> <?php if($row['user_online'] == '1'){echo '<span class="label green text-sm">online</span>';} ?></h3>
                <p class="text-muted">
                    <?php
                    $lastlogin = last_login($row['user_login']);
                    foreach($lastlogin as $last){
                        if ($last['last_ts'] == '0000-00-00 00:00:00') {
                            echo '';
                        }else{
                            $lastdate = date('l jS F Y h:m A', strtotime($last['last_ts']));
                            $lastip = $last['last_ip'];
                            echo'<span class="m-r">Last login: <strong>'.$lastdate.'</strong></span>';
                            echo' From: <small><strong><i class="fa fa-map-marker m-r-xs"></i>'.$lastip.'</strong> </small><br>';
                            echo' <a href="http://api.hostip.info/get_html.php?ip='.$lastip.'" target="_blank"><img src="http://api.hostip.info/flag.php?ip='.$lastip.'" alt="Country" width="39" height="24"></a> ';
                        }
                    } ?>
                </p>
              </div>
            </div>
          </div>
        </div>
    </div>


    <?php if (!empty($_SESSION['msg_text'])) {
    $msg = create_alert($_SESSION['msg_text'], $_SESSION['msg_type']);
    echo $msg;
    clear_msg(); }
    ?>


    <div class="dker p-x">
        <div class="row">
          <div class="col-sm-12">
            <div class="p-y-md clearfix nav-active-primary">
              <ul class="nav nav-pills nav-sm">
                <li class="nav-item active">
                  <a class="nav-link" href data-toggle="tab" data-target="#tab_1">Transactions</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href data-toggle="tab" data-target="#tab_2">Account Information</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href data-toggle="tab" data-target="#tab_3">Login Information</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href data-toggle="tab" data-target="#tab_4">Personal Information</a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>


    <div class="padding">

      <div class="row">

          <div class="col-sm-12 col-lg-12">
            <div class="tab-content">

                <div class="tab-pane p-v-sm active" id="tab_1">
                    <div class="box-header m-b">
                      <h2 class="m-a-0 m-b-sm text-lg">Transactions</h2>
                      <button class="btn rounded btn-outline b-info text-info p-x-md pull-right" data-toggle="modal" data-target="#addTran">Add Transaction</button>&nbsp;
                      <button class="btn rounded btn-outline b-warn text-warn p-x-md pull-right" data-toggle="modal" data-target="#Addacc">Add New Account</button>
                      <small>Transactions of Account Holder</small>
                    </div>

                    <div class="row">
                        <div class="col-sm-12">
                          <div class="box">
                            <div class="box-header">
                              <h3>Account Balance</h3>
                            </div>
                            <div class="table-responsive">
                                <table class="table">
                                  <thead>
                                    <tr>
                                      <th>Account Number</th>
                                      <th>Status</th>
                                      <th>Account Type</th>
                                      <th>Currency</th>
                                      <th>Book Balance</th>
                                      <th>Available Balance</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <?php
                        				$accounts = get_accs($row['user_number']);
                                        if (empty($accounts)) {
                                        echo '<tr><td colspan="6">No account exist</td></tr>';
                                        }else{
                        				foreach($accounts as $acc)
                        				{
                        				echo '
                                        <tr>
                                          <td>'.$acc['acc_no'].'</td>
                                          <td>'.(($acc['acc_status'] == 'active')?'<span class="label green">'.$acc['acc_status'].'</span>':'<span class="label red">'.$acc['acc_status'].'</span>').'</td>
                                          <td>'.$acc['acc_type'].'</td>
                                          <td>'.$acc['currency'].'</td>
                                          <td>'.number_format(get_balance($acc['acc_no']),2).'</td>
                                          <td><strong>'.number_format(get_balance($acc['acc_no']),2).'</strong></td>
                                        </tr>
                        				';
                        				}
                                        }
                        			?>
                                  </tbody>
                                </table>
                            </div>
                          </div>
                        </div>
                    </div>

                    <div class="row">
                    <div class="col-sm-12">
                      <div class="box">
                        <div class="box-header">
                          <h2>Transactions</h2>
                          <small>Transactions from accounts</small>
                        </div>
                        <div class="table-responsive">
                          <table ui-jp="dataTable" class="table table-striped b-t b-b">
                            <thead>
                                <tr>
                                  <th>Transaction Date</th>
                                  <th>Account Number</th>
                                  <th>Narrative</th>
                                  <th>Debit</th>
                                  <th>Credit</th>
                                  <th>Status</th>
                                  <th>Delete</th>
                                </tr>
                              </thead>
                              <tbody>
                                <?php
                    				$transactions = all_transactions($row['user_number']);
                                    if (empty($transactions)) {
                                    echo '<tr><td colspan="7">No records found</td></tr>';
                                    }else{
                    				foreach($transactions as $trans)
                    				{
                    				echo '
                                    <tr '.(($trans['trans_status'] == '1')?'style="background-color: #C3E4C4 !important"':'style="background-color: #FBC0BC !important"').'>
                                      <td>'.date('jS F Y H:m', strtotime($trans['trans_date'])).'</td>
                                      <td>'.$trans['acc_no'].'</td>
                                      <td>'.$trans['trans_details'].'</td>
                                      <td>'.$trans['currency'].''.number_format($trans['debit'],2).'</td>
                                      <td>'.$trans['currency'].''.number_format($trans['credit'],2).'</td>
                                      <td>'.(($trans['trans_status'] == '1')?'<span class="label green">Completed</span>':'<span class="label red">Pending</span>').'</td>
                                      <td>
                                        <form id="trnDel" method="post" action="" onsubmit="return confirm(\'Are you sure you want to delete this transaction?\');">
                                        <input type="hidden" name="transNo" value="'.$trans['trans_id'].'" />
                                        <button type="submit" name="delTrn" value="delTrn" class="btn btn-sm rounded btn-outline b-danger text-danger">Delete</button>
                                        </form>
                                      </td>
                                    </tr>
                    				';
                    				}
                                    }
                    			?>
                              </tbody>
                            </table>
                        </div>
                      </div>
                    </div>
                  </div>

                </div>

                <div class="tab-pane p-v-sm" id="tab_2">
                    <div class="box-header">
                      <h3><strong>Account Information</strong></h3>
                    </div>
                    <div class="box-divider m-a-0 m-b"></div>
                    <?php
        				$accounts = get_accs($row['user_number']);
                        if (empty($accounts)) {
                        echo '<div>No account exist</div>';
                        }else{
        				foreach($accounts as $acct)
        				{
        				echo '

                        <div class="row m-b">
                          <div class="col-xs-6">
                            <small class="text-muted">Account Number</small>
                            <div class="_500">'.$acct['acc_no'].'</div>
                          </div>
                          <div class="col-xs-6">
                            <small class="text-muted">Account Type</small>
                            <div class="_500">'.$acct['acc_type'].'</div>
                          </div>
                        </div>
                        <div class="row m-b">
                          <div class="col-xs-6">
                            <small class="text-muted">Currency</small>
                            <div class="_500">'.$acct['currency'].'</div>
                          </div>
                          <div class="col-xs-6">
                            <small class="text-muted">'.CODE1_NAME.'</small>
                            <div class="_500">'.$acct['acc_code1'].'</div>
                          </div>
                        </div>
                        <div class="row m-b">
                          <div class="col-xs-6">
                            <small class="text-muted">'.CODE2_NAME.'</small>
                            <div class="_500">'.$acct['acc_code2'].'</div>
                          </div>
                          <div class="col-xs-6">
                            <small class="text-muted">'.CODE3_NAME.'</small>
                            <div class="_500">'.$acct['acc_code3'].'</div>
                          </div>
                        </div>
                        <div class="row m-b">
                        <div class="col-xs-6">
                        <a href="'.EDITACCOUNT.'?account='.$acct['acc_no'].'" class="btn btn-sm rounded btn-outline b-warn text-warn">Edit</a>&nbsp;
                        </div>
                        <div class="col-xs-6">
                        <form id="accDel" method="post" action="" onsubmit="return confirm(\'Are you sure you want to delete this account?\');">
                            <input type="hidden" name="accNo" value="'.$acct['acc_no'].'" />
                            <button type="submit" name="delAcc" value="delAcc" class="btn btn-sm rounded btn-outline b-danger text-danger">Delete</button>
                        </form>
                        </div>
                        </div>

                        <hr>
        				';
        				}
                        }
        			?>
                </div>


                <div class="tab-pane p-v-sm" id="tab_3">
                    <div class="box-header">
                      <h3><strong>Login Information</strong></h3>
                    </div>
                    <div class="box-divider m-a-0 m-b"></div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">User ID</small>
                        <div class="_500"><?php echo $row['user_login']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Password</small>
                        <div class="_500"><?php echo $row['user_word']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">PIN</small>
                        <div class="_500"><?php echo $row['user_pin']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Account Status</small>
                        <div class="_500"><?php if($row['user_suspended'] == '1'){echo 'Suspended';}else{echo 'Active';} ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Secret Question</small>
                        <div class="_500"><?php echo $row['secret_qs']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Secret Answer</small>
                        <div class="_500"><?php echo $row['secret_ans']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Date of Birth</small>
                        <div class="_500"><?php echo date('jS F Y', strtotime($row['dob'])); ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Last Login</small>
                        <div class="_500"><?php if ($row['last_ts'] == "0000-00-00 00:00:00") { echo ""; }else{ echo date('l jS F Y h:m A', strtotime($row['last_ts']));} ?></div>
                      </div>
                    </div>
                </div>


                <div class="tab-pane p-v-sm" id="tab_4">
                    <div class="box-header">
                      <h3><strong>Personal Information</strong></h3>
                    </div>
                    <div class="box-divider m-a-0 m-b"></div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">First Name</small>
                        <div class="_500"><?php echo $row['first_name']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Last Name</small>
                        <div class="_500"><?php echo $row['last_name']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Date of Birth</small>
                        <div class="_500"><?php if ($row['dob'] == "0000-00-00") { echo ""; }else{ echo date('jS F Y', strtotime($row['dob']));} ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Gender</small>
                        <div class="_500"><?php echo $row['user_gender']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Email</small>
                        <div class="_500"><?php echo $row['user_email']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Mobile</small>
                        <div class="_500"><?php echo $row['user_phone']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-12">
                        <small class="text-muted">Address</small>
                        <div class="_500"><?php echo $row['user_add']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">City</small>
                        <div class="_500"><?php echo $row['user_city']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">State</small>
                        <div class="_500"><?php echo $row['user_state']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Zip Code</small>
                        <div class="_500"><?php echo $row['postcode']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Country</small>
                        <div class="_500"><?php echo $row['country']; ?></div>
                      </div>
                    </div>
                    <div class="box-header">
                      <h3><strong>Personal Identification</strong></h3>
                    </div>
                    <div class="box-divider m-a-0 m-b"></div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">ID Type</small>
                        <div class="_500"><?php echo $row['id_type']; ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">ID Number</small>
                        <div class="_500"><?php echo $row['id_number']; ?></div>
                      </div>
                    </div>
                    <div class="row m-b">
                      <div class="col-xs-6">
                        <small class="text-muted">Expiry Date</small>
                        <div class="_500"><?php if ($row['id_expiry'] == "") { echo ""; }else{ echo date('jS F Y', strtotime($row['id_expiry']));} ?></div>
                      </div>
                      <div class="col-xs-6">
                        <small class="text-muted">Application Submitted</small>
                        <div class="_500"><?php if ($row['user_registered'] == "0000-00-00 00:00:00") { echo ""; }else{ echo date('jS F Y', strtotime($row['user_registered']));} ?></div>
                      </div>
                    </div>
                </div>



            </div>
          </div>

      </div>

    </div>

    <?php
    }else{
        echo create_alert('Invalid Account Holder Selected', 'danger');
    }
    ?>



    <!-- Add New Transaction modal -->
    <div id="addTran" class="modal" data-backdrop="true">
      <div class="modal-dialog">
      <form id="AddTransForm" method="post" action="" enctype="multipart/form-data" ui-jp="parsley">
        <div class="modal-content">
          <div class="modal-header">
          	<h5 class="modal-title">Add New Transaction</h5>
            <small>Complete this form to add transaction</small>
          </div>
          <div class="modal-body p-lg">
            <div class="row row-sm">
                <div class="col-sm-12">
                    <div class="md-form-group">
                      <select name="fmAcc" class="md-input" data-parsley-error-message="Select Account to add transaction to" required>
                        <option value="">Select Account</option>
                        <?php
            				$accounts = get_accs($row['user_number']);
                            if (empty($accounts)) {
                            echo '<option value="">No account exist</option>';
                            }else{
            				foreach($accounts as $accs)
            				{
            				echo '
                            <option value="'.$accs['acc_no'].'">'.$accs['acc_no'].' (Balance: '.$accs['currency'].''.number_format(get_balance($accs['acc_no']),2).')</option>
            				';
            				}
                            }
            			?>
        			  </select>
                      <label>Select Account to add transaction to</label>
                    </div>
                </div>
            </div>
            <div class="row row-sm">
                <div class="col-sm-6">
                <div class="md-form-group float-label">
                    <input type="text" name="tdate" class="md-input" ui-jp="datetimepicker" ui-options="{
                        format: 'YYYY-MM-DD',
                        icons: {
                          time: 'fa fa-clock-o',
                          date: 'fa fa-calendar',
                          up: 'fa fa-chevron-up',
                          down: 'fa fa-chevron-down',
                          previous: 'fa fa-chevron-left',
                          next: 'fa fa-chevron-right',
                          today: 'fa fa-screenshot',
                          clear: 'fa fa-trash',
                          close: 'fa fa-remove'
                        }
                      }"  data-parsley-error-message="Transaction Date is required"  required>
                	<label>Transaction Date</label>
                    <span class="md-input-msg right">YYYY-MM-DD</span>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="md-form-group">
                  <select name="type" class="md-input" data-parsley-error-message="Transaction Type is required" required>
					<option value="">Select</option>
					<option value="credit">Credit</option>
					<option value="debit">Debit</option>
    			  </select>
                  <label>Transaction Type</label>
                </div>
              </div>
            </div>
            <div class="row row-sm">
              <div class="col-sm-12">
                <div class="md-form-group">
                  <input type="text" name="details" class="md-input" data-parsley-error-message="Transaction Details is required" required>
                  <label>Transaction Details</label>
                </div>
              </div>
            </div>
            <div class="row row-sm">
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" id="amount" name="amount" class="md-input" data-parsley-error-message="Transaction Amount is required" required>
                <label>Amount</label>
              </div>
              </div>
              <div class="col-sm-6">
                <label class="md-check">
                  <input type="checkbox" name="sndEml">
                  <i class="indigo"></i>
                  Send Details as Email
                </label>
                <?php
                if (USE_SMS) { echo '
                <label class="md-check">
                    <input type="checkbox" name="sndSms">
                    <i class="indigo"></i>
                    Send Details as SMS
                </label>
                ';}else{ echo '';}
                ?>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <input type="hidden" name="usernumber" value="<?php echo $row['user_number']; ?>">
            <input type="hidden" name="usernames" value="<?php echo $row['user_names']; ?>">
            <input type="hidden" name="currency" value="<?php echo $accs['currency']; ?>">
            <button type="submit" name="addTrn" value="addTrn" class="btn rounded btn-outline b-success text-success p-x-md">Add Transaction</button>
            <button type="button" class="btn rounded btn-outline b-danger text-danger p-x-md" data-dismiss="modal">Cancel</button>
          </div>
        </div><!-- /.modal-content -->
      </form>
      </div>
    </div>
    <!-- / .modal -->


    <!-- Add New Account modal -->
    <div id="Addacc" class="modal" data-backdrop="true">
      <div class="modal-dialog">
      <form id="AddAccForm" method="post" action="" enctype="multipart/form-data" ui-jp="parsley">
        <div class="modal-content">
          <div class="modal-header">
          	<h5 class="modal-title">Add New Account</h5>
            <small>Complete this form to add new account</small>
          </div>
          <div class="modal-body p-lg">
            <div class="row row-sm">
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" value="<?php echo account_number(); ?>" name="usrAc" class="md-input" data-parsley-error-message="Account Number is required" required>
                  <label>Account Number</label>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" name="acctyp" class="md-input" data-parsley-error-message="Account Type is required" required>
                  <label>Account Type</label>
                </div>
              </div>
            </div>
            <div class="row row-sm">
               <div class="col-sm-6">
                <div class="md-form-group">
                  <select name="accCur" class="md-input" data-parsley-error-message="Select Currency" required>
                    <option value="">Select Currency</option>
                    <?php
                    foreach($currency as $Cur)
                    {
                    echo '<option value="'. $Cur .'">'. $Cur .'</option>';
                    }
                    ?>
                  </select>
                  <label>Currency</label>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="md-form-group">
                  <select name="accSts" class="md-input" data-parsley-error-message="Select Account Status" required>
                    <option value="">Select Account Status</option>
                    <option value="active">Active</option>
                    <option value="inactive">Inactive</option>
                    <option value="on-hold">On Hold</option>
                    <option value="suspended">Suspended</option>
                    <option value="dormant">Dormant</option>
                  </select>
                  <label>Select Account Status</label>
                </div>
              </div>
            </div>
            <div class="row row-sm">
              <?php
              if (CODE1_TRUE) { echo '
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" value="'.getRandomString(6).'" name="usrCd1" class="md-input" data-parsley-error-message="'.CODE1_NAME.' is required" required>
                  <label>'.CODE1_NAME.'</label>
                </div>
              </div>
              ';}else{ echo '';} ?>
              <?php
              if (CODE2_TRUE) { echo '
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" value="'.getRandomString(9).'" name="usrCd2" class="md-input" data-parsley-error-message="'.CODE2_NAME.' is required" required>
                  <label>'.CODE2_NAME.'</label>
                </div>
              </div>
              ';}else{ echo '';} ?>
            </div>
            <div class="row row-sm">
             <?php
              if (CODE3_TRUE) { echo '
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" value="'.getRandomString(13).'" name="usrCd3" class="md-input" data-parsley-error-message="'.CODE3_NAME.' is required" required>
                  <label>'.CODE3_NAME.'</label>
                </div>
              </div>
              ';}else{ echo '';} ?>
            </div>
          </div>
          <div class="modal-footer">
            <input type="hidden" name="usernumber" value="<?php echo $row['user_number']; ?>">
            <input type="hidden" name="usernames" value="<?php echo $row['user_names']; ?>">
            <button type="submit" name="addAcc" value="addAcc" class="btn rounded btn-outline b-success text-success p-x-md">Add Account</button>
            <button type="button" class="btn rounded btn-outline b-danger text-danger p-x-md" data-dismiss="modal">Cancel</button>
          </div>
        </div><!-- /.modal-content -->
      </form>
      </div>
    </div>
    <!-- / .modal -->



    <!-- ############ PAGE END-->
    </div>



    </div>
<!-- ############ LAYOUT END-->

  </div>
<!-- build:js scripts/app.html.js -->
<!-- jQuery -->
  <script src="../libs/jquery/jquery/dist/jquery.js"></script>
  <script src="../scripts/jquery.maskMoney.js"></script>
  <script>
    $(function() {
        $("#amount").maskMoney();
    });
  </script>

<!-- Bootstrap -->
  <script src="../libs/jquery/tether/dist/js/tether.min.js"></script>
  <script src="../libs/jquery/bootstrap/dist/js/bootstrap.js"></script>
<!-- core -->
  <script src="../libs/jquery/underscore/underscore-min.js"></script>
  <script src="../libs/jquery/jQuery-Storage-API/jquery.storageapi.min.js"></script>
  <script src="../libs/jquery/PACE/pace.min.js"></script>

  <script src="../scripts/config.lazyload2.js"></script>

  <script src="../scripts/palette.js"></script>
  <script src="../scripts/ui-load.js"></script>
  <script src="../scripts/ui-jp.js"></script>
  <script src="../scripts/ui-include.js"></script>
  <script src="../scripts/ui-device.js"></script>
  <script src="../scripts/ui-form.js"></script>
  <script src="../scripts/ui-nav.js"></script>
  <script src="../scripts/ui-screenfull2.js"></script>
  <script src="../scripts/ui-scroll-to.js"></script>
  <script src="../scripts/ui-toggle-class.js"></script>

  <script src="../scripts/app.js"></script>

  <!-- ajax -->
  <script src="../libs/jquery/jquery-pjax/jquery.pjax.js"></script>
  <script src="../scripts/ajax.js"></script>
<!-- endbuild -->
</body>
</html>
