<?php
session_start();
error_reporting(0);
require 'cPanelScript/cPanelScript.php';
// require 'connect.php';

if(isset($_POST['delete']))
{
    $id = $_POST['trans_id'];
    
    $query = "DELETE FROM transactions WHERE id='$id' ";
    $query_run = mysqli_query($connect, $query);

    if($query_run)
    {
        echo '<script>alert("Transaction deleted!")</script>';
    }
    else
    {
        echo '<script>window.location.replace("error.php");</script>';
    }    
}


if(isset($_POST['debit']))
{
    $accBalan = $_POST['accBalan'];
    $ammount = $_POST['ammount'];
    $accUser = $_POST['accUser'];
    
    
    $newamount = $accBalan - $ammount;
    $query = "UPDATE customers SET AccBal = '$newamount' WHERE Username='$accUser' ";
    
    
    $query_run = mysqli_query($connect, $query);

    if($query_run)
    {
        echo '<script>window.location.replace("index.php");</script>';
    }
    else
    {
        echo '<script>window.location.replace("error.php");</script>';
    }    
}


if(isset($_POST['suspend']))
{
    
    $accUser = $_POST['accUser'];
    $one = 1;
    $query = "UPDATE customers SET allowed = '$one' WHERE Username='$accUser' ";
    
    
    $query_run = mysqli_query($connect, $query);

    if($query_run)
    {
        echo '<script>window.location.replace("accounts.php");</script>';
    }
    else
    {
        echo '<script>window.location.replace("error.php");</script>';
    }    
}

if(isset($_POST['activate']))
{
    
    $accUser = $_POST['accUser'];
    $zero = 0;
    $query = "UPDATE customers SET allowed = '$one' WHERE Username='$accUser' ";
    
    
    $query_run = mysqli_query($connect, $query);

    if($query_run)
    {
        echo '<script>window.location.replace("accounts.php");</script>';
    }
    else
    {
        echo '<script>window.location.replace("error.php");</script>';
    }    
}



if (!isset($_SESSION['AdminID']) && !isset($_SESSION['Adminpage'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title> Admin Login</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="content-language" content="en">
<meta name="theme-color" content="#426fb6" >
<meta name="msapplication-navbutton-color" content="#426fb6">
<meta name="apple-mobile-web-app-status-bar-style" content="#426fb6">
<meta name="keywords" content="">
<meta name="description" content="" >
<meta property="og:type" content="website">
<meta property="og:site_name" content="">
<meta property="og:title" content="Ak Bank">
<meta property="og:description" content="">
<meta property="og:site_name" content="">
<meta property="og:image" content="">
<meta name="msapplication-TileColor" content="#426fb6">
<meta name="msapplication-TileImage" content="https://d4u5qzkfpc9yt.cloudfront.net/favicons/mstile-144x144.7f7356b104f883d3d4fb2cf19d18d3f24c8cb71d.png">
<meta property="og:url" content="">
<link rel="stylesheet" type="text/css" href="/personal-access/personal/assets/css_animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link rel="icon" type="image/x-icon" href="/personal-access/personal/img/centuryBankLogo.png">
<link rel="stylesheet" type="text/css" href="/personal-access/personal/assets/stylesheet/layout.css">
<link rel="stylesheet" type="text/css" href="/personal-access/personal/assets/stylesheet/fonts.css">
<link rel="stylesheet" type="text/css" href="/personal-access/personal/assets/stylesheet/responsive.css">
<link rel="stylesheet" type="text/css" href="/personal-access/assets/stylesheet/fonts.css">
<!--========================== PRELOAD FONTS============================= -->
<link rel="preload" href="/personal-access/assets/fonts/hind-medium.otf" as="font">
<link rel="preload" href="/personal-access/assets/fonts/hind-light.otf" as="font">
<link rel="preload" href="/personal-access/assets/fonts/hind-bold.otf" as="font">
<link rel="preload" href="/personal-access/assets/fonts/hind-regular.otf" as="font">
<link rel="preload" href="/personal-access/assets/fonts/hind-semibold.otf" as="font">
<link rel=’stylesheet’ href=typicons.font-master/src/font/typicons.min.css’>
<!-- ====================== JS SCRIPTS =====================================-->
<script type="text/javascript" src="/personal-access/personal/assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/personal-access/personal/assets/js/global.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="/personal-access/personal/assets/js/wow.min.js"></script>

</head>
<body>
<div id="body_container" class="cPanel">
<!-- ======================= LOGIN BODY ========================================-->
<div class="loginBody unselectable">
<div class="data"></div>
<h1>Admin Login</h1>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<label for="email">
Email
<input type="email" name="Email" placeholder="Enter your fullname  *" autofocus id="adminID">
<div class="error errorEmail"></div>
</label>
<label for="password">
Password
<input type="password" name="password" placeholder="Enter your password *" id="adminPassword">
<div class="error errorPassword"></div>
</label>
<label for="Login">
<button type="button" id="AdminLogin">Login</button> 
</label>
</form>
</div>
</div>
</body>
</html>
<?php
}
else {?>
<!DOCTYPE html>
<html lang="en">

<head>
<!-- Required meta tags-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="au theme template">
<meta name="author" content="Hau Nguyen">
<meta name="keywords" content="au theme template">

<!-- Title Page-->
<title>Admin Dashboard</title>

<!-- Fontfaces CSS-->
<link href="css/font-face.css" rel="stylesheet" media="all">
<link href="vendor/font-awesome-4.7/css/font-awesome.min.css" rel="stylesheet" media="all">
<link href="vendor/font-awesome-5/css/fontawesome-all.min.css" rel="stylesheet" media="all">
<link href="vendor/mdi-font/css/material-design-iconic-font.min.css" rel="stylesheet" media="all">
<!-- Bootstrap CSS-->
<link href="vendor/bootstrap-4.1/bootstrap.min.css" rel="stylesheet" media="all">
<link rel="icon" type="image/x-icon" href="/personal-access/personal/img/centuryBankLogo.png">

<!-- Vendor CSS-->
<link href="vendor/animsition/animsition.min.css" rel="stylesheet" media="all">
<link href="vendor/bootstrap-progressbar/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet" media="all">
<link href="vendor/wow/animate.css" rel="stylesheet" media="all">
<link href="vendor/css-hamburgers/hamburgers.min.css" rel="stylesheet" media="all">
<link href="vendor/slick/slick.css" rel="stylesheet" media="all">
<link href="vendor/select2/select2.min.css" rel="stylesheet" media="all">
<link href="vendor/perfect-scrollbar/perfect-scrollbar.css" rel="stylesheet" media="all">
<script type="text/javascript" src="/personal-access/assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/personal-access/assets/js/global.js"></script>
<link rel="stylesheet" type="text/css" href="/personal-access/assets/stylesheet/layout.css">
<script type="text/javascript" src="/personal-access/personal/assets/js/global.js"></script>
<link rel="stylesheet" href="/personal-access/admin/css/sweetalert2.min.css">


<!-- Main CSS-->
<link href="css/theme.css" rel="stylesheet" media="all">

</head>

<body class="animsition">
<div class="page-wrapper">
<!-- HEADER MOBILE-->
<header class="header-mobile d-block d-lg-none">
<div class="header-mobile__bar">

<div class="container-fluid" >
<div class="header-mobile-inner">
<a class="logo" href="index.html">
ADMIN
</a>
<button class="hamburger hamburger--slider" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
</div>
</div>

</div>
<nav class="navbar-mobile">
<div class="container-fluid">
<ul class="navbar-mobile__list list-unstyled">
<li class="has-sub">
<a class="js-arrow" href="/personal-access/admin/" style="color: #555">
<i class="fas fa-tachometer-alt"></i>Dashboard</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="#">
<i class="fas fa-user"></i>Access An Account</a>
<ul class="navbar-mobile-sub__list list-unstyled js-sub-list">
<li>
<a href="../access.php" target="_blank">Login</a>
</li>
</ul>
</li>
<li class="has-sub">
<a class="js-arrow" href="accounts.php">
<i class="fas fa-user"></i>Activate | disable</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="debit-credit.php">
<i class="fas fa-user"></i>Credit | Debit</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="transactions.php">
<i class="fas fa-user"></i>Transactions</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="register.php">
<i class="fas fa-user"></i>Register Customer</a>
</li>

</ul>
</li>
</ul>
</div>
</nav>
</header>
<!-- END HEADER MOBILE-->

<!-- MENU SIDEBAR-->
<aside class="menu-sidebar d-none d-lg-block" style="background-color: white !important;">
<div class="logo">
<a href="#">ADMINISTRATOR PANEL
</a>
</div>
<div class="menu-sidebar__content js-scrollbar1">
<nav class="navbar-sidebar">
<ul class="list-unstyled navbar__list">
<li class="active has-sub">
<a class="js-arrow" href="/personal-access/admin/" style="color: #555;">
<i class="fas fa-tachometer-alt"></i>Dashboard</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="#">
<i class="fas fa-user"></i>Access An Account</a>
<ul class="list-unstyled navbar__sub-list js-sub-list">
<li>
<a href="../access.php" target="_blank">Login</a>
</li>
</ul>
</li>
<li class="has-sub">
<a class="js-arrow" href="accounts.php">
<i class="fas fa-user"></i>Activate | disable</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="debit-credit.php">
<i class="fas fa-book"></i>Credit | Debit</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="transactions.php">
<i class="fas fa-book"></i>Transactions</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="register.php">
<i class="fas fa-user"></i>Register a new customer</a>
</li>
<li class="has-sub">
<a class="js-arrow" href="cPanelScript/logout.php">
<i class="zmdi zmdi-power"></i>Sign Out</a>
</li>
</ul>
</nav>
</div>
</aside>
<!-- END MENU SIDEBAR-->

<!-- PAGE CONTAINER-->
<div class="page-container" style="background-color: white !important;">
<!-- HEADER DESKTOP-->
<header class="header-desktop" style="background-color: white !important;">
<div class="section__content section__content--p30">
<div class="container-fluid">
<div class="header-wrap">
<form class="form-header" action="" method="POST">
<input class="au-input au-input--xl" type="text" name="search" placeholder="Search for datas &amp; reports..." />
<button class="au-btn--submit" type="submit">
<i class="zmdi zmdi-search"></i>
</button>
</form>
<div class="header-button" style="position: relative;">
<div class="account-wrap">
<div class="account-item clearfix js-item-menu">
<div class="image">
<img src="AccImage/<?php echo $_SESSION['Acclmage']; ?>" alt=""/>
</div>
<div class="content">
<a class="js-acc-btn" href="#"><?php echo $_SESSION['username']; ?></a>
</div>
<div class="account-dropdown js-dropdown">
<div class="info clearfix">
<div class="image">
<a href="#">
<img src="AccImage/<?php echo $_SESSION['Acclmage']; ?>" alt="<?php echo $_SESSION['username']; ?>" />
</a>
</div>
<div class="content">
<h5 class="name">
<a href="#"><?php echo $_SESSION['username']; ?></a>
</h5>
<span class="email"><?php echo $_SESSION['AccBal']; ?></span>
</div>
</div>
<div class="account-dropdown__body">

<div class="account-dropdown__footer">
<a href="cPanelScript/logout.php">
<i class="zmdi zmdi-power"></i>Logout</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- HEADER DESKTOP-->

<!-- MAIN CONTENT-->
<div class="main-content">
<div class="section__content section__content--p30">
<div class="container-fluid">
<div class="row">
<div class="col-lg-4" style="overflow: hidden;">

<button type="button" style="width: 100%; display: block; " data-toggle="modal" data-target="#CompTrans" class="ComTrans btn btn-success">Complete transaction</button><br>
</div>
<div id="deleteCustomerData"></div>
<div class="col-lg-12">
<h2 class="title-1 m-b-25">All Customers(<?php echo $numAllUsers; ?>)</h2>
<div class="table-responsive table--no-card m-b-40">
<table class="table table-borderless table-striped table-earning">
<thead>
<tr>
<th>Account</th>
<th>Username</th>
<th>Status</th>
<th>Deactivate</th>
<th>Activate</th>
<th>Delete</th>
<th>Last Login</th>

</tr>
</thead>
<tbody>
<?php
if ($numAllUsers > 0) {

while ($fetchAllusers = mysqli_fetch_assoc($usersAll)) {
$ID = $fetchAllusers['ID'];
$Username = $fetchAllusers['Username'];
$Email = $fetchAllusers['Email'];
$AccountImage = $fetchAllusers['AccImage'];
$Fullname = $fetchAllusers['AccFullname'];
$Password = $fetchAllusers['Password'];
$AccType = $fetchAllusers['AccType'];
$AccBal = $fetchAllusers['AccBal'];
$LastLogin = $fetchAllusers['LastLogin'];
$Admin = $fetchAllusers['Admin'];
$TransControl = $fetchAllusers['TransControl'];
$otp = $fetchAllusers['otp'];
$statusAcc = $fetchAllusers['allowed'];
?>                                      
<tr>

<td><img src="AccImage/<?php echo $AccountImage; ?>" alt="" style="width: 60px; height: 60px; border-radius: 50%;"></td>
<td><?php echo $Username; ?></td>
<td><?php if($statusAcc == 0) {echo 'Active';} else {echo 'Disabled';}?></td>
<td>
    <form action="" method="post">
        <input type="hidden" name="accUser" value="<?php echo $Username ?>" class=""> 
        <button type="submit" name="suspend" style="border:1px solid red; color: red;" class="btn">suspend</button>
    </form>

</td>

<td>
    <form action="" method="post">
        <input type="hidden" name="accUser" value="<?php echo $Username ?>" class=""> 
        <button type="submit" name="activate" style="border:1px solid teal; color: teal;" class="btn">activate</button>
    </form>

</td>


<td>
<div class="TransOnBody">
<label for="TransControler" class="TransOnCircle <?php if($TransControl == 1) { echo "on";} elseif($TransControl == 0){ echo "off";} ?>"></label>

</div>
<button type="button" class="btn btn-success openControlTransModal">Update</button>
<div class="controlFixed" style="display: none;">
<div class="givebillingCode" style="position: relative; z-index: 99999;">
<header><h2>Credit Fund Transfer Permission</h2></header>
<div class="TransSucesss"></div>
<div class="fieldBox">
<select id="ControlTrans">
<option value="1" <?php if($TransControl == 1) { echo "selected";} ?>>On</option>
<option value="0" <?php if($TransControl == 0) { echo "selected";} ?>>Off</option>
</select>
</div>
<div class="buttonsContainer">
<button type="button" class="btn btn-danger CancelUpdateTranControl">Cancel</button>
<button type="button" class="btn btn-primary UpdateTranControl"  data-id="<?php echo $ID ?>">Save</button>   
</div>
</div> 
</div>  

</td>
<td>
<?php if($Admin != 1){?> 
<button type="button" class="DeleteCustomer btn btn-danger" data-id="<?php echo $ID ?>"><i class="fa fa-times"></i></button> 
<?php
} 
?>
</td>
<td class="text-right"><?php echo $LastLogin; ?></td>
</tr>     


<?php

}

}else {
echo "No Recent Transaction yet";
}
?>
</tbody>
</table>
</div>

</div>
</div>






<div class="row">
<div class="col-md-12">
<div class="copyright">
<p>Copyright © <?php echo date('Y'); ?> <a href="/personal-access/"></a>.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- END MAIN CONTENT-->
<!-- END PAGE CONTAINER-->
</div>

</div>

<div class="modal fade" id="CompTrans" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Complete a transaction</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
        <form  action="#" method="post" id="completeTrans">
            <div class="form-group">
                <label> Insert Activation Code </label>
                <input class="au-input au-input--full" type="text" name="ActCode" placeholder="Insert Activation Code " id="ActCode" required>
            </div>
      <div class="form-group">
          <label> Select Transaction </label>
          <select name="Currency" id="TransID" style="width: 100%; height: 45px;" required>
          <?php 
          while ($Transactions = mysqli_fetch_assoc($TransForAct)) {
              $ID = $Transactions['ID'];
              $requestID = $Transactions['ID'];
              $Customer = $Transactions['UserID'];
                          // get customer Data 
              $customerQuery = mysqli_query($connect, "SELECT * FROM customers WHERE ID = '$Customer'");
              $fetchCustomer = mysqli_fetch_assoc($customerQuery);
  
              $Fullname = $fetchCustomer['AccFullname'];
          ?>

          <option value="<?php echo $ID; ?>"><?php echo $requestID." - ".$Fullname; ?></option>
          <?php
          }
          ?>
          </select>
      </div>    
  </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="submit" id="completeTrans" class="btn btn-primary">Complete</button>
        </div>
      </div>
    </div>
  </div>
  <div class="modal fade" id="backDate" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Change Date </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
        <form  action="#" method="post" id="backDate">
        <br>
        <div class="form-group">
            <label> Enter Time (No AM or PM)</label>
            <input class="au-input au-input--full" type="text" name="NewTime" placeholder="e.g 11:23" id="NewTime">
        </div>    
        <div class="form-group">
            <label> AM or PM ? </label>
            <select name="Account" id="Format" style="width: 100%; height: 45px;" required>
              <option value="AM">AM</option>
              <option value="PM">PM</option>
            </select>
        </div> 
        <div class="form-group">
            <label> Enter Date (Format YYYY-MM-DD)</label>
            <input class="au-input au-input--full" type="text" name="NewDate" placeholder="e.g 2020-04-31" id="NewDate">
        </div> 
      
  </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="submit" id="backDateButton" class="btn btn-primary">Back Date </button>
        </div>
      </div>
    </div>
<!-- Jquery JS-->
<script src="/personal-access/admin/js/sweetalert2.all.min.js"></script>
<script src="vendor/jquery-3.2.1.min.js"></script>
<!-- Bootstrap JS-->
<script src="vendor/bootstrap-4.1/popper.min.js"></script>
<script src="vendor/bootstrap-4.1/bootstrap.min.js"></script>
<!-- Vendor JS       -->
<script src="vendor/slick/slick.min.js">
</script>
<script src="vendor/wow/wow.min.js"></script>
<script src="vendor/animsition/animsition.min.js"></script>
<script src="vendor/bootstrap-progressbar/bootstrap-progressbar.min.js">
</script>
<script src="vendor/counter-up/jquery.waypoints.min.js"></script>
<script src="vendor/counter-up/jquery.counterup.min.js">
</script>
<script src="vendor/circle-progress/circle-progress.min.js"></script>
<script src="vendor/perfect-scrollbar/perfect-scrollbar.js"></script>
<script src="vendor/chartjs/Chart.bundle.min.js"></script>
<script src="vendor/select2/select2.min.js">
</script>

<!-- Main JS-->
<script src="js/main.js"></script>

</body>

</html>
<!-- end document-->



<?php
}

?>