<?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 {
    include "_header2.php";
    include "_navtop.php";
    include "_navside.php";
    include "_functions.php";
    require "conn.php";

    $mwallet        = MsumWall("masuk", "mwallet") - MsumWall("keluar", "mwallet");
    $mwallet_masuk  = MsumWall("masuk", "mwallet");
    $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>Redeem</h2>
                    </div>
                </div>
            <hr />

            <div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Redeem History
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Date</th>
                                            <th>Description</th>
                                            <th>Receipt</th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?
$c = 1;  

    // CASH BONUS    
        $sql = "SELECT * FROM mwallet WHERE userid ='".$_SESSION['aidi']."' ORDER BY tarikh DESC";
        $result = mysqli_query($con, $sql);

        while ($row = mysqli_fetch_array($result)) {
            
            $ahli_sql       = "SELECT * FROM merchant WHERE id ='".$row[3]."' ";
            $ahli_result    = mysqli_query($con, $ahli_sql);
            while ( $ahli           = mysqli_fetch_array($ahli_result)) {
?>
                                        <tr >
                                            <td><?= $c++ ?>
                                            <td><?= $row[1] ?></td>
                                            <td><?= "Total Redeem RM".$row[5]." at <span class='text-danger'>".strtoupper($ahli[1])."</span>" ?></td>
                                            <td><a style="text-decoration:none;" target="_blank" href="paymerchant.php?r=<?= $row[7] ?>"><?= $row[7] ?></a></td>
                                        </tr>
 <?     
            }
        } 
 ?> 
 
 
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>        
    </div>
             <!-- /. PAGE INNER  -->
            </div>
<?
    include "_footer2.php";
}
?>
