<?php
session_start();
$key = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
if (isset($_SESSION['aW1iZXN0cmEuY29tLm15']) <> $key) {
    header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']); // cara baru !
} else {
    require "conn.php";
    include "_header.php";
    include "_navtop.php";
    include "_navside.php";
    include "_functions.php";

    $cwallet = sumWall("masuk", "cwallet") - sumWall("keluar", "cwallet");
    $cwallet_travel = sumWall("masuk", "cwallet_travel") - sumWall("keluar", "cwallet_travel");
    $cwallet_cash = sumWall("masuk", "cwallet_cash") - sumWall("keluar", "cwallet_cash");
    $limit = 100;

    if ($cwallet >= $limit) {
        $link = "request_withdraw.php";
    } else {
        $link = "#";
    }

    $result = mysqli_query($con, "SELECT SUM(amaun) FROM withdraw WHERE userid='".$_SESSION['aidi']."'");
    $withdraw = mysqli_fetch_array($result);
    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>Dashboard</h2>
                        <h5>Welcome <?= $_SESSION['namapenuh'] ?> , Love to see you back. </h5>
                    </div>
                </div>
                 <!-- /. ROW  -->

                 <!-- /. ROW  -->
                <hr />
                
<?
if ($_SESSION['username'] <> "admin") {
?>

                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <h4>Cash Bonus</h4>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="panel panel-back noti-box" >
                            <span class="icon-box bg-primary set-icon" >
                                <i class="fa fa-usd" ></i>
                            </span>
                            <div class="text-box small" >
                                <p class="main-text"><span class="small" style="font-size:15px; padding-right:10px;">RM </span><?= number_format($cwallet,2) ?></p>
                                <p class="text-muted">Available Balance</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <h4>Redemption Bonus</h4>
                    </div>
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-primary set-icon">
                                <i class="fa fa-tint"></i>
                            </span>
                        <div class="text-box small" >
                            <p class="main-text"><span class="small" style="font-size:15px; padding-right:10px;">RM </span><?= number_format($cwallet,2) ?></p>
                            <p class="text-muted">Car Wash</p>
                        </div>
                        </div>
                    </div>

                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-primary set-icon">
                                <i class="fa fa-star-half-o"></i>
                            </span>
                        <div class="text-box small" >
                            <p class="main-text"><span class="small" style="font-size:15px; padding-right:10px;">RM </span><?= number_format($cwallet_travel,2) ?></p>
                            <p class="text-muted">Car Polish & Wax</p>
                        </div>
                        </div>
                    </div>
                    
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-primary set-icon">
                                <i class="fa fa-wrench"></i>
                            </span>
                        <div class="text-box small" >
                            <p class="main-text"><span class="small" style="font-size:15px; padding-right:10px;">RM </span><?= number_format($cwallet_cash,2) ?></p>
                            <p class="text-muted">Car Repairing</p>
                        </div>
                        </div>
                    </div>
                    
                    <div class="col-md-6 col-sm-12 col-xs-12">
                        <div class="panel panel-back noti-box">
                            <span class="icon-box bg-primary set-icon">
                                <i class="fa fa-magic"></i>
                            </span>
                        <div class="text-box small" >
                            <p class="main-text"><span class="small" style="font-size:15px; padding-right:10px;">RM </span><?= number_format(0,2) ?> </p>
                            <p class="text-muted">Car Accessories</p>
                        </div>
                        </div>
                    </div>

            </div>
                 <!-- /. ROW  -->
                <hr />
<? } 



date_default_timezone_set("Asia/Kuala_Lumpur");

// kiraan 60 hari utk ahli lembab lagi tak produktif
$dwnln = mysqli_num_rows(mysqli_query($con, "SELECT id FROM ahli WHERE penaja = '".$_SESSION['aidi']."'"));

if ($dwnln  == 0) {

  $sql = "SELECT DATE_ADD(tarikh, INTERVAL 2 MONTH) FROM `ahli` WHERE id = ".$_SESSION['aidi'];
  $expired = mysqli_fetch_array(mysqli_query($con, $sql))[0];

  $tarikh = new DateTime($expired);
  $lani = new DateTime();

  $beza = $tarikh->diff($lani)->format("%a days, %h hours, %i minutes");

/*
$datetime1 = new DateTime();
$datetime2 = new DateTime($expired);
$interval = $datetime1->diff($datetime2);
$beza = $interval->format('%a days');
*/
?>
                <div class="row">
                    <div class="col-md-4">
                    <div class="panel panel-primary text-center no-boder bg-color-red">
                        <div class="panel-body">
                            <i class="fa fa-power-off fa-5x"></i>
                            <h4><?= $beza ?></h4>
                        </div>
                        <div class="panel-footer back-footer-red">
                            Account Expired : <?= date("d-m-Y", strtotime($expired)) ?>

                        </div>
                        </div>
                    </div>
                </div>
<? } ?>
    </div>
             <!-- /. PAGE INNER  -->
            </div>
         <!-- /. PAGE WRAPPER  -->
        </div>
<?
    include "_footer.php";
}
?>