ok

Mini Shell

Direktori : /proc/thread-self/root/home2/selectio/public_html/lilyexpresslive/software/admin/
Upload File :
Current File : //proc/thread-self/root/home2/selectio/public_html/lilyexpresslive/software/admin/customer-add.php

<?php 
require_once('header.php'); 
?>
<script type="text/javascript" language="javascript" >
	$(document).ready(function() {
		     

function branchDetails(){ // branch and Employee Details Set
   /*var branch = $("#branch").val();*/
        $.ajax({
          url: 'data-tables/custom-function.php',
          type: 'post',
          data: {type:'get_branch'},
          success: function(response)
          {
               var datas = JSON.parse(response)         
               $('#branch_id').empty();
                var tot = datas.length;
                  if(tot==0)
                  {
                          $('#branch_id')
                                        .append($("<option></option>")
                                      .attr("value", '')
                                      .text("Branch Not Available"));
                  }
                  else
                  {
                    $('#branch_id')
                                        .append($("<option></option>")
                                      .attr("value", '')
                                      .text("Select Branch"));
                  }
                  

                for (var index = 0; index < tot; index++) {
                     $('#branch_id')
                      .append($("<option></option>")
                    .attr("value", datas[index]['id'])
                    .text(datas[index]['branch_name']));
                                                 
                }   
          }
      });
}


function clientDetails(){ // branch and Employee Details Set
   var branch = $("#branch_id").val();

        $.ajax({
          url: 'data-tables/custom-function.php',
          type: 'post',
          data: {type:'get_client',branch_id:branch},
          success: function(response)
          {
               var datas = JSON.parse(response)         
               $('#client_id').empty();
                var tot = datas.length;
                  if(tot==0)
                  {
                          $('#client_id')
                                        .append($("<option></option>")
                                      .attr("value", '')
                                      .text("Client Not Available"));
                  }
                 
                for (var index = 0; index < tot; index++) {
                     $('#client_id')
                      .append($("<option></option>")
                    .attr("value", datas[index]['id'])
                    .text(datas[index]['client_name']));
                                                 
                }   
          }
      });
}





				branchDetails();
			  
			  $('#branch_id').on('change', function(){			    
			        clientDetails();			      
			  } );      
			} );
		</script>
<?php
if(isset($_POST['form1'])) {
	$valid = 1;

	if(empty($_POST['cust_name'])) {
		$valid = 0;
		$error_message .= 'Name can not be empty<br>';
	}

	if(empty($_POST['cust_code'])) {
		$valid = 0;
		$error_message .= 'Customer code can not be empty<br>';
	}

    	if(empty($_POST['cust_address'])) {
		$valid = 0;
		$error_message .= 'Address can not be empty<br>';
	}
        
        	if(empty($_POST['cust_state'])) {
		$valid = 0;
		$error_message .= 'State can not be empty<br>';
	}

	if(empty($_POST['cust_zip'])) {
		$valid = 0;
		$error_message .= 'Pincode can not be empty<br>';
	}
		if(empty($_POST['cust_city'])) {
		$valid = 0;
		$error_message .= 'City can not be empty<br>';
	}
		if(empty($_POST['client_id'])) {
		$valid = 0;
		$error_message .= 'Select the Client <br>';
	}

$code=$_POST['cust_code'];
	$statement = $pdo->prepare("SELECT * FROM tbl_customer where cust_code='$code'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                            if($result)
                            {
                                $valid=0;
                                $error_message .= 'Customer Code Alreay Exist<br>';
                            }
							

    if($valid==1)
    {
    
		$statement = $pdo->prepare("INSERT INTO tbl_customer (client_id,cust_code,cust_name,cust_address,cust_zip,cust_phone,cust_city,cust_state,destination_city) VALUES (?,?,?,?,?,?,?,?,?)");
		$statement->execute(array($_POST['client_id'],$_POST['cust_code'],$_POST['cust_name'],$_POST['cust_address'],$_POST['cust_zip'],$_POST['cust_phone'],$_POST['cust_city'],$_POST['cust_state'],$_POST['destination_city']));
			
		$success_message = 'Customer is added successfully!';

		unset($_POST['cust_code']);
		unset($_POST['cust_name']);
		unset($_POST['cust_address']);
		unset($_POST['cust_zip']);
		unset($_POST['cust_phone']);
		unset($_POST['cust_city']);
		unset($_POST['destination_city']);
    }
	
}
?>
<section class="content-header" style="background-color: white;">
	
	<div class="row">
		<div class="col-md-8" style="text-align: center;">
			<h4><i class="fa fa-user-plus"></i> Add Customer</h4>
		</div>
		<div class="col-md-4">
			<a href="customer.php" class="btn btn-danger btn-sm"><i class="fa fa-user-plus"></i> Back to Customer List</a>
		</div>
	</div>
</section>
<section class="content">

	<div class="row">
		<div class="col-md-12">

			<?php if($error_message): ?>
			<div class="callout callout-danger">
				<p>
					<?php echo $error_message; ?>
				</p>
			</div>
			<?php endif; ?>

			<?php if($success_message): ?>
			<div class="callout callout-success">
				<p><?php echo $success_message; ?></p>
			</div>
			<?php endif; ?>
			
			<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
				<div >
					<div class="box-body">
					    
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Select Branch <span>*</span></label>
							<div class="col-sm-6">
								<select class="form-control select2" name="branch_id" id="branch_id" required="">
							        <option value="">Select Branch</option>	        
							    </select>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Select Client <span>*</span></label>
							<div class="col-sm-6">
								<select class="form-control select2" name="client_id" id="client_id" required="">
							        <option value="">Select Branch First!!!</option>	        
							    </select>
							</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer Name <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_name" value="<?php if(isset($_POST['cust_name'])){echo $_POST['cust_name'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer Code <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_code" value="<?php if(isset($_POST['cust_code'])){echo $_POST['cust_code'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer City <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_city" value="<?php if(isset($_POST['cust_city'])){echo $_POST['cust_city'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer State <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_state" value="<?php if(isset($_POST['cust_state'])){echo $_POST['cust_state'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer Address <span>*</span></label>
							<div class="col-sm-6">
								<textarea class="form-control" name="cust_address" id="cust_address" style="height:100px;"><?php if(isset($_POST['cust_address'])){echo $_POST['cust_address'];} ?></textarea>
							</div>
							<div class="col-sm-4">
								<span id="remain" >110</span><span id="remain_txt" >characters remaining</span>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer Pincode <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_zip" value="<?php if(isset($_POST['cust_zip'])){echo $_POST['cust_zip'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Customer Mobile <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="cust_phone" value="<?php if(isset($_POST['cust_phone'])){echo $_POST['cust_phone'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Destination City </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="destination_city" value="<?php if(isset($_POST['destination_city'])){echo $_POST['destination_city'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label"></label>
							<div class="col-sm-6">
								<button type="submit" class="btn btn-success pull-left" name="form1">Submit</button>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>

</section>
<script>
    var maxchars = 110;

$('textarea').keyup(function () {
    var tlength = $(this).val().length;
    $(this).val($(this).val().substring(0, maxchars));
    var tlength = $(this).val().length;
    remain = maxchars - parseInt(tlength);
   
    if(remain<10){
         $('#remain').css('color','red');
         $('#remain_txt').css('color','red');
    }
    else{ $('#remain').css('color','green');
    $('#remain_txt').css('color','green');
    }
     $('#remain').text(remain);
});
</script>

<?php require_once('footer.php'); ?>

Zerion Mini Shell 1.0