<?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";    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                     <h2>Merchant Registration</h2>                          
                    </div>
                </div>
            <hr />

<script type="text/javascript">
    function ValidateUsername() {
        var username = document.getElementById("txtUsername").value;
        var lblError = document.getElementById("lblError");
        lblError.innerHTML = "";
        var expr = /^[a-zA-Z0-9_]*$/;
        if (!expr.test(username)) {
            lblError.innerHTML = "Only Alphabets, Numbers, Underscore allowed in Username.";
            event.preventDefault(); // tambahan
        }
    }
</script>

<?php
            // Check Number Sponsor - Limit Sponsor (Limitkan Sponsor) 
            
            $s_limit_sql = mysqli_fetch_array(mysqli_query($con, "SELECT sponsor_limit FROM setting"));
            $s_limit = $s_limit_sql['sponsor_limit'];
            
            $s_num_sql = mysqli_num_rows(mysqli_query($con, "SELECT id FROM ahli WHERE penaja = '".$_SESSION['aidi']."'"));
            $s_num = $s_num_sql;

            if ($s_limit == 0) {
                $dis = "";
            }
            else    {
                if ($s_num >= $s_limit) {
                    $dis = "disabled";
                    noTis("danger", "Notice ", " Your account reach a maximum sponsor limit."); 
                }   
                else {
                    $dis = "";
                } 
            }
           

?>
			<div class="row">
                <div class="col-md-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Register New Merchant 	
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <form role="form" method="post" action="register.php" onsubmit="return ValidateUsername();">

                                        <div class="form-group">
                                            <label>Company Name</label>
                                            <input class="form-control" name="a" placeholder="Company Name" required <?= $dis; ?>/>
                                        </div>
                                         <div class="form-group">
                                            <label>Company ROB / ROC</label>
                                            <input class="form-control" name="d" placeholder="Company ROB/ROC." required <?= $dis; ?>/>
                                        </div>
                                         <div class="form-group">
                                            <label>Contact Person</label>
                                            <input class="form-control" name="f" placeholder="Contact Person." required <?= $dis; ?>/>
                                        </div>
                                        <div class="form-group">
                                            <label>Phone</label>
                                            <input class="form-control" name="b" placeholder="Mobile phone no." required <?= $dis; ?>/>
                                        </div>
                                        <div class="form-group">
                                            <label>Email</label>
                                            <input class="form-control" name="c" type="email" placeholder="Valid email only" required <?= $dis; ?>/>
                                        </div>
                                        <div class="form-group">
                                            <label>Username</label>
                                            <input class="form-control" name="e" placeholder="Login Name" id="txtUsername" required <?= $dis; ?>/>
                                            <span id="lblError" style="color: red"></span>
                                        </div>


                                        <button type="submit" id="btnValidate" name="reg_merchant" class="btn btn-primary" <?= $dis; ?>>Register</button>

                                    </form>

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

			</div>
			
			
<?
		
?>

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