<?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";

?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>Merchant List</h2>
                    </div>
                </div>

                 <!-- /. ROW  -->
                <hr />                
            <div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             List of all merchants
                        </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>Login ID</th>
                                            <th>Company Name</th>
                                            <th>Company Reg No.</th>
                                            <th>Services</th>
                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?
    $c = 1;
    $sql = "SELECT id, username, nama, roc, status, carwash, polish, repair, accessories, insurance FROM merchant ";
    $result = mysqli_query($con, $sql);

    while ($row = mysqli_fetch_array($result)) {
        
        if (($row[5]) == 1) { $s1 = "text-primary"; } else { $s1 = "text-secondary"; } 
        if (($row[6]) == 1) { $s2 = "text-primary"; } else { $s2 = "text-secondary"; } 
        if (($row[7]) == 1) { $s3 = "text-primary"; } else { $s3 = "text-secondary"; } 
        if (($row[8]) == 1) { $s4 = "text-primary"; } else { $s4 = "text-secondary"; } 
        if (($row[9]) == 1) { $s5 = "text-primary"; } else { $s5 = "text-secondary"; } 
        
        
?>
                                        <tr class="even">
                                            <td><?= $c++ ?>
                                            <td><code><?= $row[1] ?></code></td>
                                            <td><?= $row[2] ?></td>
                                            <td><?= $row[3] ?></td>
                                            <td>
                                                <i class="fa fa-tint fa-1x              <?= $s1 ?>"                 title="Carwash"         style="padding-right:5px;"></i>
                                                <i class="fa fa-star-half-stroke fa-1x  <?= $s2 ?>"                 title="Polish"          style="padding-right:5px;"></i>
                                                <i class="fa fa-wrench fa-1x            <?= $s3 ?>"                 title="Repair"          style="padding-right:5px;"></i>
                                                <i class="fa fa-magic fa-1x             <?= $s4 ?>"                 title="Accessories"     style="padding-right:5px;"></i>
                                                <i class="fa fa-shield fa-1x            <?= $s5 ?>"                 title="Insurance"       style="padding-right:5px;"></i>
                                            </td>
                                            <td><a href="#" class="btn btn-success btn-xs">Active</a></td>
                                            <td><a href="edit_merchant.php?id=<?= $row[0] ?>&r=m" class="btn btn-primary btn-xs"><i class="fa fa-edit "></i> Edit</a></td>
                                        </tr>
 <? } ?>
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>          
    </div>
             <!-- /. PAGE INNER  -->
            </div>
<?
    include "_footer2.php";
}
?>
