<?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['update'])) {
      $user         = mysqli_real_escape_string($con, $_POST['ww']);
      $password     = mysqli_real_escape_string($con, $_POST['xx']);
      $nama         = mysqli_real_escape_string($con, $_POST['aa']);
      $kp           = mysqli_real_escape_string($con, $_POST['bb']);
      $telefon      = mysqli_real_escape_string($con, $_POST['cc']);
      $email        = mysqli_real_escape_string($con, $_POST['dd']);
      $alamat       = mysqli_real_escape_string($con, $_POST['ee']);
      $bandar       = mysqli_real_escape_string($con, $_POST['ff']);
      $poskod       = mysqli_real_escape_string($con, $_POST['gg']);
      $negeri       = mysqli_real_escape_string($con, $_POST['hh']);
      $bank         = mysqli_real_escape_string($con, $_POST['ii']);
      $noakaun      = mysqli_real_escape_string($con, $_POST['jj']);
      $naakaun      = mysqli_real_escape_string($con, $_POST['kk']);
      $bnama        = mysqli_real_escape_string($con, $_POST['ll']);
      $bkp          = mysqli_real_escape_string($con, $_POST['mm']);
      $brelation    = mysqli_real_escape_string($con, $_POST['nn']);
      $id           = mysqli_real_escape_string($con, $_POST['oo']);
      $BPacc_no     = mysqli_real_escape_string($con, $_POST['bp_acc_no']);
      $BPacc_name   = mysqli_real_escape_string($con, $_POST['bp_acc_name']);

      if (empty($password)) {
        //
        mysqli_query($con, "UPDATE ahli SET nama='$nama', kp='$kp', alamat='$alamat', bandar='$bandar', poskod='$poskod', negeri='$negeri', telefon='$telefon', email='$email', username='$user', bank='$bank', naakaun='$naakaun', noakaun='$noakaun', bnama='$bnama', bkp='$bkp', brelation='$brelation', bp_acc_no ='$BPacc_no', bp_acc_name ='$BPacc_name' WHERE id='".$id."'");
      } else {
       // $qq = "UPDATE ahli SET nama='$nama', kp='$kp', alamat='$alamat', bandar='$bandar', poskod='$poskod', negeri='$negeri', telefon='$telefon', email='$email', username='$user', password='$password', bank='$bank', naakaun='$naakaun', noakaun='$noakaun', bnama='$bnama', bkp='$bkp', brelation='$brelation' bp_acc_no ='$BPacc_no', bp_acc_name ='$BPacc_name' WHERE id='".$id."'";
       // echo '<script>alert("'.$qq.'");</script>';
        mysqli_query($con, "UPDATE ahli SET nama='$nama', kp='$kp', alamat='$alamat', bandar='$bandar', poskod='$poskod', negeri='$negeri', telefon='$telefon', email='$email', username='$user', password='$password', bank='$bank', naakaun='$naakaun', noakaun='$noakaun', bnama='$bnama', bkp='$bkp', brelation='$brelation', bp_acc_no ='$BPacc_no', bp_acc_name ='$BPacc_name' WHERE id='".$id."'");
      }
    

    }
        
        
        $id = mysqli_real_escape_string($con, $_GET['id']);


    if (isset($_GET['r']) == "m") {
                    $result = mysqli_query($con, "SELECT * FROM merchant WHERE id='".$id."'");
    }   else    {
                    $result = mysqli_query($con, "SELECT * FROM ahli WHERE id='".$id."'");
    }

        $rows = mysqli_fetch_array($result);        
    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>Profile</h2>                          
                    </div>
                </div>
            <hr />

			<div class="row">
                <div class="col-md-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Profile
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-md-6">

                                    <form role="form" method="post">
                                        <div class="form-group">
                                            <label>Username</label>
                                            <input class="form-control" name="ww" value="<?= $rows['username'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>Password</label>
                                            <input class="form-control" type="password" name="xx" />
                                            <p class="help-block">leave it blank if you want to keep the current password</p>
                                        </div>                                    
                                        <hr>
                                        <h3>Biodata</h3>
                                        <div class="form-group">
                                            <label>Name</label>
                                            <input class="form-control" placeholder="Full Name" name="aa" value="<?= $rows['nama'] ?>" />
                                        </div>
<?php
    if (isset($_GET['r']) == "m") {
?>
                                        <div class="form-group">
                                            <label>R.O.C</label>
                                            <input class="form-control" name="bb"   value="<?= $rows['roc'] ?>" readonly />
                                        </div>
<?php
    }   else    {
?>
                                        <div class="form-group">
                                            <label>MyKad</label>
                                            <input class="form-control" name="bb"   value="<?= $rows['kp'] ?>" readonly />
                                        </div>
<?php
        }
?> 
                                        <div class="form-group">
                                            <label>Phone</label>
                                            <input class="form-control" placeholder="your mobile phone no." name="cc" value="<?= $rows['telefon'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>Email</label>
                                            <input class="form-control" type="email" placeholder="valid email only" name="dd" value="<?= $rows['email'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>Address</label>
                                            <input class="form-control" placeholder="without city, postcode, state" name="ee" value="<?= $rows['alamat'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>City</label>
                                            <input class="form-control" name="ff" value="<?= $rows['bandar'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>Postcode</label>
                                            <input class="form-control" name="gg" value="<?= $rows['poskod'] ?>" />
                                        </div>                                                                                
                                        <div class="form-group">
                                            <label>State</label>
                                            <input class="form-control" name="hh" value="<?= $rows['negeri'] ?>" />
                                        </div>

                                </div>
                                <div class="col-md-6">
                                    <div class="row">
                                            <div class="col-md-12 col-sm-12 col-xs-12">
                                                <div class="panel panel-primary text-center no-boder " style="color:white; background-color: #626BCB;">
                                                    <div class="panel-body">
                                                        <h1><?= $rows['pakej'] ?></h1>
                                                    </div>
                                                    <div class="panel-footer " style="color:white; background-color: #3842A8;">
                                                        Package
                                                    </div>
                                                </div>
                                            </div>
                                    </div>
                                    <h3><img src="bigpay.png" style="width:100px; height:auto;" /> Details</h3>
                                        <div class="form-group">
                                            
                                        </div>
                                        <div class="form-group">
                                            <label>Account No.</label>
                                            <input class="form-control" placeholder="BigPAY account no." name="bp_acc_no" value="<?= $rows['bp_acc_no'] ?>" />
                                        </div>                                        
                                        <div class="form-group">
                                            <label>Account Name</label>
                                            <input class="form-control" placeholder="BigPAY account name" name="bp_acc_name" value="<?= $rows['bp_acc_name'] ?>" />
                                        </div>
                                    <hr>
                                    <h3>Bank Details</h3>
                                        <div class="form-group">
                                            <label>Bank Name</label>
                                            <input class="form-control" name="ii" value="<?= $rows['bank'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>Account No.</label>
                                            <input class="form-control" placeholder="bank account no." name="jj" value="<?= $rows['noakaun'] ?>" />
                                        </div>                                        
                                        <div class="form-group">
                                            <label>Account Name</label>
                                            <input class="form-control" placeholder="your mobile phone no." name="kk" value="<?= $rows['naakaun'] ?>" />
                                        </div>
                                    <hr>
                                    <h3>Beneficiary</h3>
                                        <div class="form-group">
                                            <label>Full Name</label>
                                            <input class="form-control" placeholder="" name="ll" value="<?= $rows['bnama'] ?>" />
                                        </div>
                                        <div class="form-group">
                                            <label>MyKad</label>
                                            <input class="form-control" placeholder="your beneficiary MyKad no." name="mm" value="<?= $rows['bkp'] ?>" />
                                        </div>                                        
                                        <div class="form-group">
                                            <label>Relationship</label>
<?
$a = $b = $c = $d = "";
$s = " selected";
switch ($rows['brelation']) {

    case "p":
    $a = $s;
    break;

    case "s":
    $b = $s;
    break;

    case "c":
    $c = $s;
    break;

    case "o":
    $d = $s;
    break;

    default:
    $d = $s;
}
?>                                            
                                            <select class="form-control" name="nn">
                                                <option<?= $a ?>>Parent</option>
                                                <option<?= $b ?>>Spouse</option>
                                                <option<?= $c ?>>Children</option>
                                                <option<?= $d ?>>Others</option>
                                            </select>
                                        </div>
                                        <input type="hidden" name="oo" value="<?= $id ?>" />
                                        <button type="submit" name="update" class="btn btn-primary">Update</button>

                                    </form>

                                </div>                                
                            </div>
                        </div>
                    </div>
                     <!-- End Form Elements -->
                </div>

			</div>


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