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

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

$page = "Code1 Page";
$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 (code1_used($_SESSION['user_number'], $_SESSION['trans_acc'])){
    redirect(CODE2);
}

if (isset($_POST['authorize']) && $_POST['authorize'] == 'authorize')
{
    if ($_POST['authCode'] == ''){ store_msg("Enter ".CODE1_NAME."", "danger"); redirect(CODE1);}
    elseif (code1_check($_POST['authCode'], $_SESSION['user_number'], $_SESSION['trans_acc'])){ set_code1($_SESSION['user_number'], $_SESSION['trans_acc']); store_msg("".CODE1_NAME." Accepted", "success");
    log_info($_SERVER['REMOTE_ADDR'], $_SESSION['user_login'], $_SESSION['trans_acc'], 'Transfer attempt correct '.CODE1_NAME.'');
    redirect(AUTHORIZING);
    }
    else{
        store_msg("Invalid ".CODE1_NAME."", "danger"); redirect(CODE1);
    }
}

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-6 offset-lg-3">
          <div class="box">
            <div class="box-header">
              <h2><?php echo CODE1_NAME ?></h2>
              <small>Your transfer requires <?php echo CODE1_NAME ?>.</small>
            </div>
            <div class="box-divider m-a-0"></div>
            <div class="box-body p-v-md">
            <form id="AuthCode" method="post" action="" enctype="multipart/form-data" ui-jp="parsley">
              <div class="row row-sm">
                <div class="col-sm-12">
                    <div class="md-form-group float-label">
                      <input type="text" name="authCode" class="md-input" data-parsley-error-message="<?php echo CODE1_NAME ?> required" required>
                      <label><?php echo CODE1_NAME ?></label>
                    </div>
                </div>
              </div>
              <div class="row row-sm">
                <div class="col-sm-12">
                    <button type="submit" name="authorize" value="authorize" class="btn rounded btn-outline main mainbd p-x-md">Transfer</button>
                </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>
