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

    if (isset($_POST['komisen'])) {

    /// CASH
        $k1 = mysqli_real_escape_string($con, $_POST['k1']);
        $k2 = mysqli_real_escape_string($con, $_POST['k2']);
        $k3 = mysqli_real_escape_string($con, $_POST['k3']);
        $k4 = mysqli_real_escape_string($con, $_POST['k4']);
        $k5 = mysqli_real_escape_string($con, $_POST['k5']);
        $mp = mysqli_real_escape_string($con, $_POST['mp']);
        $pv = mysqli_real_escape_string($con, $_POST['pv']);

        $upd = mysqli_query($con, "UPDATE komisen SET lvl1='".$k1."', lvl2='".$k2."', lvl3='".$k3."', lvl4='".$k4."', lvl5='".$k5."', maksima='".$mp."', nilaipin='".$pv."'");
    
    /// CARWASH    
        $k1_cw = mysqli_real_escape_string($con, $_POST['k1_carwash']);
        $k2_cw = mysqli_real_escape_string($con, $_POST['k2_carwash']);
        $k3_cw = mysqli_real_escape_string($con, $_POST['k3_carwash']);
        $k4_cw = mysqli_real_escape_string($con, $_POST['k4_carwash']);
        $k5_cw = mysqli_real_escape_string($con, $_POST['k5_carwash']);
        $mp_cw = mysqli_real_escape_string($con, $_POST['mp_carwash']);
        $pv_cw = mysqli_real_escape_string($con, $_POST['pv_carwash']);
     
        $upd_cw = mysqli_query($con, "UPDATE komisen_carwash SET lvl1_cw='".$k1_cw."', lvl2_cw='".$k2_cw."', lvl3_cw='".$k3_cw."', lvl4_cw='".$k4_cw."', lvl5_cw='".$k5_cw."', maksima_cw='".$mp_cw."', nilaipin_cw='".$pv_cw."'");
        
    /// POLISH    
        $k1_t = mysqli_real_escape_string($con, $_POST['k1_travel']);
        $k2_t = mysqli_real_escape_string($con, $_POST['k2_travel']);
        $k3_t = mysqli_real_escape_string($con, $_POST['k3_travel']);
        $k4_t = mysqli_real_escape_string($con, $_POST['k4_travel']);
        $k5_t = mysqli_real_escape_string($con, $_POST['k5_travel']);
        $mp_t = mysqli_real_escape_string($con, $_POST['mp_travel']);
        $pv_t = mysqli_real_escape_string($con, $_POST['pv_travel']);
        
        $upd_t = mysqli_query($con, "UPDATE komisen_travel SET lvl1_t='".$k1_t."', lvl2_t='".$k2_t."', lvl3_t='".$k3_t."', lvl4_t='".$k4_t."', lvl5_t='".$k5_t."', maksima_t='".$mp_t."', nilaipin_t='".$pv_t."'");

    /// REPAIRING
        $k1_c = mysqli_real_escape_string($con, $_POST['k1_cash']);
        $k2_c = mysqli_real_escape_string($con, $_POST['k2_cash']);
        $k3_c = mysqli_real_escape_string($con, $_POST['k3_cash']);
        $k4_c = mysqli_real_escape_string($con, $_POST['k4_cash']);
        $k5_c = mysqli_real_escape_string($con, $_POST['k5_cash']);
        $mp_c = mysqli_real_escape_string($con, $_POST['mp_cash']);
        $pv_c = mysqli_real_escape_string($con, $_POST['pv_cash']);
        
        $upd_c = mysqli_query($con, "UPDATE komisen_cash SET lvl1_c='".$k1_c."', lvl2_c='".$k2_c."', lvl3_c='".$k3_c."', lvl4_c='".$k4_c."', lvl5_c='".$k5_c."', maksima_c='".$mp_c."', nilaipin_c='".$pv_c."'");
    
    /// ACCESSORIES
        $k1_acc = mysqli_real_escape_string($con, $_POST['k1_accessories']);
        $k2_acc = mysqli_real_escape_string($con, $_POST['k2_accessories']);
        $k3_acc = mysqli_real_escape_string($con, $_POST['k3_accessories']);
        $k4_acc = mysqli_real_escape_string($con, $_POST['k4_accessories']);
        $k5_acc = mysqli_real_escape_string($con, $_POST['k5_accessories']);
        $mp_acc = mysqli_real_escape_string($con, $_POST['mp_accessories']);
        $pv_acc = mysqli_real_escape_string($con, $_POST['pv_accessories']);

        $upd_acc = mysqli_query($con, "UPDATE komisen_accessories SET lvl1_acc='".$k1_acc."', lvl2_acc='".$k2_acc."', lvl3_acc='".$k3_acc."', lvl4_acc='".$k4_acc."', lvl5_acc='".$k5_acc."', maksima_acc='".$mp_acc."', nilaipin_acc='".$pv_acc."'");

/// INSURANCE
        $k1_ins = mysqli_real_escape_string($con, $_POST['k1_insurance']);
        $k2_ins = mysqli_real_escape_string($con, $_POST['k2_insurance']);
        $k3_ins = mysqli_real_escape_string($con, $_POST['k3_insurance']);
        $k4_ins = mysqli_real_escape_string($con, $_POST['k4_insurance']);
        $k5_ins = mysqli_real_escape_string($con, $_POST['k5_insurance']);
        $mp_ins = mysqli_real_escape_string($con, $_POST['mp_insurance']);
        $pv_ins = mysqli_real_escape_string($con, $_POST['pv_insurance']);

        $upd_ins = mysqli_query($con, "UPDATE komisen_insurance SET lvl1_ins='".$k1_ins."', lvl2_ins='".$k2_ins."', lvl3_ins='".$k3_ins."', lvl4_ins='".$k4_ins."', lvl5_ins='".$k5_ins."', maksima_ins='".$mp_ins."', nilaipin_ins='".$pv_ins."'");


        
        $sl         = mysqli_real_escape_string($con, $_POST['sl']);
        $set_limit  = mysqli_query($con, "UPDATE setting SET sponsor_limit='".$sl."'");    
    
        
    }

    $kms        = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen"));
    $kms_cw     = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen_carwash"));
    $kms_t      = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen_travel"));
    $kms_c      = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen_cash"));
    $kms_acc    = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen_accessories"));
    $kms_ins    = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM komisen_insurance"));
    $spl        = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM setting"));
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12 ">
                     <h2><i class="fa fa-cogs"></i> Setting</h2>                          
                    </div>
                </div>
<? if ($upd) { ?>
    <script>
    window.setTimeout(function() {
        $(".alert").fadeTo(500, 0).slideUp(500, function(){
            $(this).remove();
        });
    }, 2000);
    </script>

    <div class="alert alert-info">
        Commission settings saved.
    </div>


<? } ?>
                 <!-- /. ROW  -->
                 <hr />
               <div class="row">
                <div class="col-md-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Level Commission
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <form role="form" method="post">
                                        
                                            <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-usd fa-2x text-primary"></i> </h4><p style="text-align:center;"> CASH </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1" value="<?= $kms[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2" value="<?= $kms[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3" value="<?= $kms[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4" value="<?= $kms[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5" value="<?= $kms[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp" value="<?= $kms[6] ?>" type="text" placeholder="Max Payout" />
                                                </div>
                                            </div>
                                            
                                            <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-tint fa-2x text-primary"></i></h4><p style="text-align:center;"> CAR WASH </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1_carwash" value="<?= $kms_cw[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2_carwash" value="<?= $kms_cw[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3_carwash" value="<?= $kms_cw[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4_carwash" value="<?= $kms_cw[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5_carwash" value="<?= $kms_cw[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp_carwash" value="<?= $kms_cw[6] ?>" type="textr" placeholder="Max Payout" />
                                                </div>
                                                    <input class="form-control" name="pv_carwash" value="<?= $kms_cw[7] ?>" type="hidden" placeholder="MYR" />
                                            </div> 
                                            
                                            <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-star-half-stroke fa-2x text-primary"></i></h4><p style="text-align:center;"> POLISH & WAX </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1_travel" value="<?= $kms_t[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2_travel" value="<?= $kms_t[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3_travel" value="<?= $kms_t[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4_travel" value="<?= $kms_t[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5_travel" value="<?= $kms_t[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp_travel" value="<?= $kms_t[6] ?>" type="text" placeholder="Max Payout" />
                                                </div>
                                                <input class="form-control" name="pv_travel" value="<?= $kms_t[7] ?>" type="hidden" placeholder="MYR" />
                                            </div>
                                            
                                            
                                            <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-wrench fa-2x text-primary"></i></h4><p style="text-align:center;"> REPARING </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1_cash" value="<?= $kms_c[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2_cash" value="<?= $kms_c[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3_cash" value="<?= $kms_c[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4_cash" value="<?= $kms_c[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5_cash" value="<?= $kms_c[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp_cash" value="<?= $kms_c[6] ?>" type="text" placeholder="Max Payout" />
                                                </div>
                                                <input class="form-control" name="pv_cash" value="<?= $kms_c[7] ?>" type="hidden" placeholder="MYR" />
                                            </div>

                                            <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-magic fa-2x text-primary"></i></h4> <p style="text-align:center;"> ACCESSORIES </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1_accessories" value="<?= $kms_acc[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2_accessories" value="<?= $kms_acc[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3_accessories" value="<?= $kms_acc[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4_accessories" value="<?= $kms_acc[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5_accessories" value="<?= $kms_acc[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp_accessories" value="<?= $kms_acc[6] ?>" type="text" placeholder="Max Payout" />
                                                </div>
                                                <input class="form-control" name="pv_accessories" value="<?= $kms_acc[7] ?>" type="hidden" placeholder="MYR" />
                                            </div>                                            

                                           <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-shield fa-2x text-primary"></i></h4> <p style="text-align:center;"> Insurance </p>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Level 1 Commission</label>
                                                    <input class="form-control" name="k1_insurance" value="<?= $kms_ins[1] ?>" step=".01" type="number" placeholder="Level 1" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 2 Commission</label>
                                                    <input class="form-control" name="k2_insurance" value="<?= $kms_ins[2] ?>" step=".01" type="number" placeholder="Level 2" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 3 Commission</label>
                                                    <input class="form-control" name="k3_insurance" value="<?= $kms_ins[3] ?>" step=".01" type="number" placeholder="Level 3" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 4 Commission</label>
                                                    <input class="form-control" name="k4_insurance" value="<?= $kms_ins[4] ?>" step=".01" type="number" placeholder="Level 4" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Level 5 Commission</label>
                                                    <input class="form-control" name="k5_insurance" value="<?= $kms_ins[5] ?>" step=".01" type="number" placeholder="Level 5" />
                                                </div>
                                                <div class="form-group">
                                                    <label>Maximum Payout</label>
                                                    <input class="form-control" name="mp_insurance" value="<?= $kms_ins[6] ?>" type="text" placeholder="Max Payout" />
                                                </div>
                                                <input class="form-control" name="pv_insurance" value="<?= $kms_ins[7] ?>" type="hidden" placeholder="MYR" />
                                            </div>
                                          
                                        <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-sitemap fa-2x text-primary"></i></h4>
                                                <hr>
                                                <div class="form-group">
                                                    <label>Sponsor Limit</label>
                                                    <input class="form-control" name="sl" value="<?= $spl[1] ?>" type="text" placeholder="max sponsor" />
                                                </div>
                                        </div>
                                        <div class="col-md-3 col-sm-12" style="background-color:#FAFAFA; padding:20px; margin:10px; border: 2px solid #EEEEEE;">
                                                <h4 class="text-center"><i class="fa fa-key fa-2x text-primary"></i></h4>
                                                <hr>
                                                <div class="form-group">
                                                    <label>PIN Value (RM)</label>
                                                    <input class="form-control" name="pv" value="<?= $kms[7] ?>" type="text" placeholder="MYR" />
                                                </div>
                                        </div>
                                        <div class="col-md-12 col-sm-12" style="padding:20px; margin:10px; ">
                                        <button type="submit" name="komisen" class="btn btn-primary">Save</button>
                                        </div>
                                    </form>
                                    <br />
                                </div>
                            </div>
                        </div>
                    </div>
                     <!-- End Form Elements -->
                </div>

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