<?php
@session_start();
@ob_start();

include "header.php"; 
$objIms->client_alter();
?>
<script type="text/javascript">
	$(document).ready(function() {                
				$("#FORMNAME1").validate({
                    rules: {
					contact_no:"required number",
                   address:"required",
					},
		messages: {
			
					 supplier_name: "",
					 address: "",
					 contact_no:"",
					 contact_person: "",
					 
								
				},
		  });                
            });
//---auto search-----
</script>

<!-- Page wrapper  -->
        <div class="page-wrapper">
            <!-- Container fluid  -->
             <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row justify-content-center">
                    <div class="col-lg-6">
                        <div class="card">
						<h4>Add Client <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h4>
						<hr />
<?php  
if(isset($_REQUEST["uid"])){
$sql = "SELECT * FROM tbl_client WHERE md5(id) = '".$_REQUEST["uid"]."' and session_login_id = '".$_SESSION['login_id']."'";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
$client_name = $row["client_name"];
$address = $row["address"];
$contact_no = $row["contact_no"];
$contact_person = $row["contact_person"];
$email_id = $row["email_id"];
$tin_no = $row["tin_no"];
}
if((isset($_REQUEST["Edit"])) AND (isset($_REQUEST["uid"]))){
  $id_1 = $_REQUEST["uid"]; 
  $client_name1 = $_REQUEST["client_name"];
  $address1 = $_REQUEST["address"];
  $contact_no1 = $_REQUEST["contact_no"];
  $contact_person1 = $_REQUEST["contact_person"];
  $tin_no1 = $_REQUEST["tin_no"];
  $email1 = $_REQUEST["email"];
 $sql_update = "UPDATE tbl_client SET client_name ='$client_name1', address='$address1', contact_no='$contact_no1', contact_person = '$contact_person1', tin_no = '$tin_no1', email_id = '$email1' WHERE md5(id)= '$id_1' and session_login_id = '".$_SESSION['login_id']."'";
  $res_update =mysql_query($sql_update);
?>
<script type="text/javascript">
     alert('Success');
    location.href = "client_list.php";
</script>
<?php
}
?>
<?php
if(isset($_REQUEST["Save"])){
$client_name2 = $_REQUEST["client_name"];
  $address2 = $_REQUEST["address"];
  $contact_no2 = $_REQUEST["contact_no"];
  $contact_person2 = $_REQUEST["contact_person"];
  $tin_no2 = $_REQUEST["tin_no"];
  $email2 = $_REQUEST["email"];

$sql_ins = "INSERT INTO tbl_client (client_name, address, contact_no, contact_person, tin_no, email_id, session_login_id) VALUES ('$client_name2', '$address2', '$contact_no2', '$contact_person2', '$tin_no2', '$email2', '".$_SESSION['login_id']."')";
$res_ins = mysql_query($sql_ins);
    ?>
        <script>
        alert('Success');
        location.href='client_list.php';
        </script>
        <?php

}
?>

                                        <form method="post" id="FORMNAME1">
                                    	<?php  echo $objIms->error;?>
	
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Client Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="client_name" type ="text" class="form-control" maxlength="15" id="client_name" value="<?php echo $client_name; ?>" required="required" <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Address <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <textarea name="address" class="form-control" maxlength="50" id="address" <?php echo $address; ?> ><?php echo $objIms->address;?></textarea>
                                            </div>
                                        </div>
										
											<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact No <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="contact_no" type ="text"  class="form-control" id="contact_no" onkeypress="return validate(event)" value="<?php echo $contact_no; ?>" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>

									<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact Person Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="contact_person" type ="text" class="form-control" maxlength="15" id="contact_person" value="<?php echo $contact_person; ?>" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Email <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type ="email" name="email" id="email" class="form-control" required="" value="<?php echo $email_id; ?>"  <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">GSTin No <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="tin_no" type ="text" id="tin_no" class="form-control" required="" value="<?php echo $tin_no; ?>"  <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										 <div class="form-group row">
                                            <div class="col-lg-8 ml-auto">
                                <?php if(isset($_REQUEST["uid"]))  {?>
                                                <input type ="submit" name="Edit" value="Edit" class="btn btn-info"/><?php } else{ ?>
                                                <input type ="submit" name="Save" value="Save" class="btn btn-info"/><?php  } ?>
                                            </div>
                                        </div>
	
		
</form>

  </div>

                            </div>
						
                            
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>

<script type="text/javascript">
    function validate(key)
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('contact_no');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57))
{
    alert("no only allow")
return false;

}
else
{
//Condition to check textbox contains ten numbers or not
if (phn.value.length <10)
{
return true;
}
else
{
    alert("not greater than 10")
return false;

}
}
}
</script>
