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

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

$page = "Own Account Transfer Confirmation";
$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['user_login']);


if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$amnt = clean_data($_POST['tfAmt']);
$amount = str_replace( ',', '', $amnt );
if ($_POST['fmAcc'] == ""){ store_msg("Select Account to transfer from", "danger"); redirect(OWNTRANSFER);}
elseif ($_POST['toAcc'] == ""){ store_msg("Select Account to transfer to", "danger"); redirect(OWNTRANSFER);}
elseif ($_POST['fmAcc'] == $_POST['toAcc']){ store_msg("You can't transfer to same account", "danger"); redirect(OWNTRANSFER);}
elseif ($_POST['tfAmt'] == ""){ store_msg("Enter amount to transfer", "danger"); redirect(OWNTRANSFER);}
elseif (get_currency($_POST['fmAcc']) != get_currency($_POST['toAcc'])){ store_msg("Accounts do not have the same currency denomination", "danger"); redirect(OWNTRANSFER);}
elseif (!acc_active($_POST['fmAcc'], 'active')){ store_msg("Transfer from account is inactive", "danger"); redirect(OWNTRANSFER);}
elseif (!acc_active($_POST['toAcc'], 'active')){ store_msg("Transfer to account is inactive", "danger"); redirect(OWNTRANSFER);}
elseif (!security_answer($_SESSION['user_login'], $_POST['uSeca'])){ store_msg("Incorrect answer to security question", "danger"); redirect(OWNTRANSFER);}
elseif (!sufficient_balance($_POST['fmAcc'], $amount)){ store_msg("Insufficient Balance", "danger"); redirect(OWNTRANSFER);}


else{
$fromacc = clean_data($_POST['fmAcc']);
$toacc = clean_data($_POST['toAcc']);
}
}

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 require_once('topbar.php'); ?>


    <?php
    $notify = get_alerts($_SESSION['user_login'], 'all');
    foreach($notify as $ntfy){
    echo "<div class=\"alert alert-warning\" role=\"alert\">
    <strong>".date('l jS F Y', strtotime($ntfy['alrt_date']))."</strong><br>".$ntfy['alrt_cnt']."
    </div>";
    }
    ?>

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


    <div class="padding">
      <div class="p-x-lg">
        <div class="row">
        <div class="col-lg-8 offset-lg-2">
          <div class="box">
            <div class="box-header">
              <h2>Confirm Transfer</h2>
              <small>Review the details of your transfer.</small>
            </div>
            <div class="box-divider m-a-0"></div>
            <div class="box-body p-v-md">
            <form id="Ownotp" method="post" action="<?php echo OWNOTP ?>" enctype="multipart/form-data" ui-jp="parsley">

              <div class="p-a">
                <div class="streamline b-l m-b">
                    <div class="sl-item b-info">
                        <div class="sl-content">
                            <p>YOU HAVE INITIATED AN OWN ACCOUNT TRANSFER:</p>
                        </div>
                    </div>
                    <div class="sl-item b-info">
                        <div class="sl-icon">
                            <i class="material-icons text-info">&#xe0b2;</i>
                        </div>
                        <div class="sl-content">
                            <div class="sl-date text-muted">FROM ACCOUNT NUMBER:</div>
                            <p><?php echo $fromacc; ?></p>
                        </div>
                    </div>
                    <div class="sl-item b-success">
                        <div class="sl-icon">
                            <i class="material-icons text-info">&#xe0b5;</i>
                        </div>
                        <div class="sl-content">
                                <div class="sl-date text-muted">TO ACCOUNT NUMBER:</div>
                                <p><?php echo $toacc; ?></p>
                        </div>
                    </div>
                    <div class="sl-item b-success">
                        <div class="sl-icon">
                            <i class="material-icons text-info">&#xe877;</i>
                        </div>
                        <div class="sl-content">
                                <div class="sl-date text-muted">AMOUNT:</div>
                                <p class="text-success"><?php echo get_currency($fromacc); ?><strong><?php echo number_format($amount,2); ?></p>
                        </div>
                    </div>
                    <div class="sl-item b-muted">
                        <div class="sl-content">
                            <p class="text-muted">Click cancel below to cancel transfer or transfer to complete transfer</p>
                        </div>
                    </div>
                </div>
              </div>

              <div class="row row-sm">
                <div class="col-sm-12">
                    <input name="fmAcc" type="hidden" value="<?php echo $fromacc; ?>">
                    <input name="toAcc" type="hidden" value="<?php echo $toacc; ?>">
                    <input name="tfAmt" type="hidden" value="<?php echo $amount; ?>">
                    <button type="submit" name="confirm" value="confirm" class="btn rounded btn-outline main mainbd p-x-md">Transfer</button>
                    <a href="<?php echo OWNTRANSFER ?>" class="btn rounded btn-outline b-danger text-danger p-x-md">Cancel</a>
                </div>
              </div>
            </form>
            </div>
          </div>
        </div>
        </div>
      </div>
    </div>


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



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

  </div>
<!-- build:js scripts/app.html.js -->
<!-- jQuery -->
  <script src="libs/jquery/jquery/dist/jquery.js"></script>

<!-- Bootstrap -->
  <script src="libs/jquery/tether/dist/js/tether.min.js"></script>
  <script src="libs/jquery/bootstrap/dist/js/bootstrap.js"></script>
  <script src="scripts/jquery.maskMoney.js"></script>
  <script>
    $(function() {
        $("#tfAmt").maskMoney();
    });
  </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.lazyload.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-screenfull.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>
