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

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

$page = "Pending Transfers";
$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 (isset($_POST['delTrans']) && $_POST['delTrans'])
{
$transid = clean_data($_POST['delTrans']);
$transnumber = clean_data($_POST['transnumber']);
$usernumber = $_SESSION['user_number'];

$stmt = $pdo->prepare('DELETE FROM '.TRANF_TABLE_NAME.' WHERE tranf_id = :transid AND trans_number = :transnumber LIMIT 1');
if ($stmt->execute(array(':transid' => $transid, ':transnumber' => $transnumber))) {
    log_info($_SERVER['REMOTE_ADDR'], $_SESSION['user_login'], $transnumber, 'Successfully Deleted a Pending Transaction');
    store_msg("Transaction Deleted Successfully", "success"); redirect(PENDINGTRANSFER);
}else{
    store_msg("Delete Transaction Error", "danger"); redirect(PENDINGTRANSFER);
}
}

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="row">
        <div class="col-sm-12">
          <div class="box">
            <div class="box-header">
              <h2>Pending Transfers</h2>
              <small>Incomplete transfers to other Banks, click to resume or cancel transaction.</small>
            </div>
            <div class="table-responsive">
                <table class="table table-striped b-t">
                  <thead>
                    <tr>
                      <th>Transaction Date</th>
                      <th>Source Account</th>
                      <th>Beneficiary</th>
                      <th>Memo</th>
                      <th>Amount</th>
                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
        				$pending = pending_transfers($_SESSION['user_number']);
                        if (empty($pending)) {
                        echo '<tr><td colspan="6">No records found</td></tr>';
                        }else{
        				foreach($pending as $trans)
        				{
        				echo '
                        <tr '.(($trans['status'] == '1')?'style="background-color: #C3E4C4 !important"':'style="background-color: #FBC0BC !important"').'>
                          <td>'.date('jS F Y', strtotime($trans['atmpt_date'])).'</td>
                          <td>'.$trans['acc_no'].'</td>
                          <td>'.$trans['rcv_name'].' ('.$trans['rcv_acc'].' - '.$trans['rcv_bk'].' '.$trans['rcv_country'].')</td>
                          <td>'.$trans['purpose'].'</td>
                          <td>'.get_currency($trans['acc_no']).''.number_format($trans['atmpt_amt'],2).'</td>
                          <td>
                          <form id="DelTransForm" method="post" action="" onsubmit="return confirm(\'Are you sure you want to delete this pending transaction?\');">
                            <input type="hidden" name="transnumber" value="'.$trans['trans_number'].'" />
                            <button type="submit" name="delTrans" value="'.$trans['tranf_id'].'" class="nav-link label danger">Delete</button>
                          </form>
                          <form id="ConTransForm" method="post" action="'.PENDINGCONFIRM.'" onsubmit="return confirm(\'Are you sure you want to continue this pending transaction?\');">
                            <input type="hidden" name="fmAcc" value="'.$trans['acc_no'].'" />
                            <input type="hidden" name="trnsNo" value="'.$trans['trans_number'].'" />
                            <input type="hidden" name="tfAmt" value="'.$trans['atmpt_amt'].'" />
                            <button type="submit" name="transfer" value="transfer" class="nav-link label success">Continue</button>
                          </form>
                          </td>
                        </tr>
        				';
        				}
                        }
        			?>
                  </tbody>
                </table>
            </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>
<!-- 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>
