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

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

$page = "Edit Account Information";
$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['updtAct']) && $_POST['updtAct'] == 'updtAct')
{
$usernumber = clean_data($_POST['usrNo']);
if ($_POST['usrAc'] == "") { store_msg("No Account selected", "danger"); redirect(PROFILE.'?user='.$usernumber);}
elseif ($_POST['accSts'] == "") { store_msg("Select Account Status", "danger"); redirect(EDITACCOUNT);}
elseif ($_POST['acctyp'] == "") { store_msg("Account Type is required", "danger"); redirect(EDITACCOUNT);}
elseif ($_POST['accCur'] == "") { store_msg("Select Currency", "danger"); redirect(EDITACCOUNT);}
//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']);
$active = clean_data($_POST['accSts']);
$accstatus = clean_data($_POST['accSts']);
$type = clean_data($_POST['acctyp']);
$currency = clean_data($_POST['accCur']);
$code1 = clean_data($_POST['usrCd1']);
$code2 = clean_data($_POST['usrCd2']);
$code3 = clean_data($_POST['usrCd3']);
$regip = $_SERVER['REMOTE_ADDR'];
$status = "1";

dbconnect();
$stmt = $pdo->prepare('UPDATE '.ACCS_TABLE_NAME.' SET acc_code1 = :code1, acc_code2 = :code2, acc_code3 = :code3, acc_status = :status, currency = :currency, acc_type = :type WHERE acc_no = :accno AND user_number = :usernumber LIMIT 1');
$stmt->execute(array(':code1' => $code1, ':code2' => $code2, ':code3' => $code3, ':status' => $accstatus, ':currency' => $currency, ':type' => $type, ':accno' => $acc, ':usernumber' => $usernumber));

log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $acc, 'Account Information Successfully Updated');
store_msg("Account Information Successfully Updated", "success");
redirect(PROFILE.'?user='.$usernumber);

}
}

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
        $accnumber = clean_data($_GET['account']);
        if (!empty($accnumber)) {
        $sql = "SELECT * FROM `".ACCS_TABLE_NAME."` WHERE acc_no='{$accnumber}'";
        $stmt = $pdo->query($sql);
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
    ?>


    <?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 col-lg-12">
          <form id="chngPass" method="post" action="" enctype="multipart/form-data" ui-jp="parsley">
            <h5>Edit Account Information</h5>
            <small>Complete and submit form to edit account information</small>
            <h6 class="_400 m-t-lg">Account Information</h6>
            <hr>
            <div class="row row-sm">
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" value="<?php echo $row['acc_no']; ?>" name="usrAc" class="md-input" disabled="disabled">
                  <label>Account Number</label>
                </div>
              </div>
              <div class="col-sm-6">
                <div class="md-form-group">
                  <input type="text" name="acctyp" value="<?php echo $row['acc_type']; ?>" 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 .'" '.(($row['currency'] == $Cur)?'selected="selected"':'').'>'. $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" <?php if($row['acc_status'] == 'active'){echo 'selected="selected"';} ?>>Active</option>
                    <option value="inactive" <?php if($row['acc_status'] == 'inactive'){echo 'selected="selected"';} ?>>Inactive</option>
                    <option value="on-hold" <?php if($row['acc_status'] == 'on-hold'){echo 'selected="selected"';} ?>>On Hold</option>
                    <option value="suspended" <?php if($row['acc_status'] == 'suspended'){echo 'selected="selected"';} ?>>Suspended</option>
                    <option value="dormant" <?php if($row['acc_status'] == 'dormant'){echo 'selected="selected"';} ?>>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="'.$row['acc_code1'].'" 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="'.$row['acc_code2'].'" 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="'.$row['acc_code3'].'" name="usrCd3" class="md-input" data-parsley-error-message="'.CODE3_NAME.' is required" required>
                  <label>'.CODE3_NAME.'</label>
                </div>
              </div>
              ';}else{ echo '';} ?>
            </div>
            <div class="row row-sm">
            <input type="hidden" name="usrAc" value="<?php echo $row['acc_no']; ?>" />
            <input type="hidden" name="usrNo" value="<?php echo $row['user_number']; ?>" />
            <button type="submit" name="updtAct" value="updtAct" class="btn rounded btn-outline main mainbd p-x-md">Update</button>
            </div>
          </form>
      </div>


      </div>

    </div>

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


    <!-- ############ 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.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>
