<?php if(isset($_SESSION['msg']) ){?>
	<div class="alert alert-info">                
	<h4>Info!</h4>
	<?php echo $_SESSION['msg']; unset($_SESSION['msg']); ?>
	</div> <?php }  ?> 
<?php
 if(isset($_REQUEST['submit']))
 {
	$name	                = ucwords(strtolower(mysql_real_escape_string($_POST['name'])));
	$c_name			        = mysql_real_escape_string($_POST['c_name']);
	$mobile_no	            = mysql_real_escape_string($_POST['mobile_no']);
	$email		            = mysql_real_escape_string($_POST['email']); 	
	$address	            = mysql_real_escape_string($_POST['address']);
	$state		            = mysql_real_escape_string($_POST['state']);
	$gst_no	            	= mysql_real_escape_string($_POST['gst_no']);
	$pan_no		            = mysql_real_escape_string($_POST['pan_no']); 
	mysql_query("insert into `tbl_clients` set `name`='$name',`c_name`='$c_name',`mobile_no`='$mobile_no',`email`='$email',`address`='$address',`state`='$state',`gst_no`='$gst_no',`pan_no`='$pan_no' ")or die(mysql_error());
	 $_SESSION['msg'] = 'Client Added Sucessfully!!';
	 header("location:home.php?page=client_registration");	 
 }
 if(isset($_REQUEST['update']))
 {
	$id		                = $_POST['id'];
	$name	                = ucwords(strtolower(mysql_real_escape_string($_POST['name'])));
	$c_name			        = mysql_real_escape_string($_POST['c_name']);
	$mobile_no	            = mysql_real_escape_string($_POST['mobile_no']);
	$email		            = mysql_real_escape_string($_POST['email']); 	
	$address	            = mysql_real_escape_string($_POST['address']);
	$state		            = mysql_real_escape_string($_POST['state']);
	$gst_no	            	= mysql_real_escape_string($_POST['gst_no']);
	$pan_no		            = mysql_real_escape_string($_POST['pan_no']); 
	mysql_query("update `tbl_clients` set `name`='$name',`c_name`='$c_name',`mobile_no`='$mobile_no',`email`='$email',`address`='$address',`state`='$state',`gst_no`='$gst_no',`pan_no`='$pan_no' where `id`='$id' ")or die(mysql_error());
	 $_SESSION['msg'] = 'Client Added Sucessfully!!';
	 header("location:home.php?page=client_registration");	 
 }
 ?>           
<div class="row-fluid" >
    <div class="span12">
        <div class="head clearfix">
            <div class="isw-ok"></div>
            <h1><?php if(isset($_REQUEST['page_id'])) { echo "Modify";}else {echo "Add";}?> Client</h1>
            
        </div>
        <div class="block-fluid">
            <form class="form-horizontal" onsubmit="return get_validation();" action="" method="post" enctype="multipart/form-data">
              <fieldset>
              <?php
			   if(isset($_REQUEST['page_id']))
			   {
				   $id            =       $_REQUEST['page_id'];
				   $modify_menu   =       mysql_query("SELECT * FROM `tbl_clients` WHERE `id` = '$id' ");
				   $show_modify   =       mysql_fetch_array($modify_menu);
			   }
			  ?>
              <input type="hidden" name="id" placeholder="Page Name" <?php if(isset($_REQUEST['page_id'])){?> required value="<?php echo $show_modify['id'];  ?>"<?php } ?> id="txt_name" autocomplete="off" />
                
                     <div class="row-form clearfix">
                        <div class="span3">
                        	<label>Client Name</label>
                        	<input type="text" name="name" placeholder="Client Name" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['name'];  ?>"<?php } ?> id="name" onkeyup="capital_letter('name');" required/>
                        </div>
                        <div class="span3">
                        	<label>Contact Persion</label>
                        	<input type="text" name="c_name" placeholder="Contact Persion" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['c_name'];  ?>"<?php } ?> id="c_name" onkeyup="capital_letter('c_name');" required/>
                        </div>
                        <div class="span3">
                        	<label>Mobile No.</label>
                        	<input type="text" name="mobile_no" placeholder="Mobile No." <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['mobile_no'];  ?>"<?php } ?> id="mobile_no" required/>
                        </div>
                        <div class="span3">
                        	<label>Email</label>
                        	<input type="text" name="email" autocomplete="off" placeholder="Email Address" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['email'];?>"<?php } ?> id="email" />
                        </div>
                     </div>
                     <div class="row-form clearfix">
                     <div class="span12">
                        	<label>Address</label>
                        	<input type="text" name="address" placeholder="Address" <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['address'];?>"<?php } ?> id="address"  onkeyup="capital_letter('address');"/>
                        </div>
                     </div>   
                     <div class="row-form clearfix">
                        <div class="span3">
                        	<label>State</label>
                            <select name="state" required>
                            <option value="">Select State</option>
                            <?php
							$st		= array();
							$sql_st	= mysql_query("SELECT * FROM `state` ORDER BY `state_name` ASC ")or die(mysql_error());
							while($row_st= mysql_fetch_array($sql_st))
							{
								$type = '';
								if(isset($_REQUEST['page_id'])&&($show_modify['state']==$row_st['id'])){ $type ='selected';}
								echo "<option value='".$row_st['id']."' $type>".$row_st['state_name']."</option>";
							}
							?>
                            </select>
                        </div>
                        <div class="span3">
                        	<label>GST No.</label>
                        	<input type="text" name="gst_no" placeholder="GST No." <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['gst_no'];  ?>"<?php } ?> id="gst_no"/>
                        </div>   
                        <div class="span3">
                        	<label>Pan No.</label>
                        	<input type="text" name="pan_no" placeholder="Pan No." <?php if(isset($_REQUEST['page_id'])){?>value="<?php echo $show_modify['pan_no'];  ?>"<?php } ?> id="pan_no"/>
                        </div>
                        
                     </div>
                <div class="row-form clearfix">
                    <div class="span3">&nbsp;</div>
                    <div class="span2"><input type="submit" name="<?php if(isset($_REQUEST['page_id'])){echo "update"; }else{ echo "submit";}?>" class="btn btn-block" value="<?php if(isset($_REQUEST['page_id'])){ echo "Update"; }else{ echo "Save";}?>"/></div>
                </div>
              </fieldset>
            </form>  
        </div> 
    </div>
</div> 
<script>
function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
function capital_letter(id)
{
    var arr 		  = $('#'+id).val().split(' ');
    var result 		  = "";
    for (var x=0; x<arr.length; x++)
        result+=arr[x].substring(0,1).toUpperCase()+arr[x].substring(1)+' ';
    $('#'+id).val(result.substring(0, result.length-1));
}
</script>   
<?php

	$menu		= mysql_query("SELECT * FROM `tbl_clients` WHERE 1 order by `id` ASC")or die(mysql_error());
	$count		= mysql_num_rows($menu);
?>     
<div class="row-fluid" >
<div class="span12">    
<div class="head clearfix">
<div class="isw-ok"></div>
<h1>View Client List</h1>
</div>   
<div class="block-fluid">
<table cellpadding="0" cellspacing="0" width="100%" class="table" id="example">
    <thead>
        <tr>
            <th>S.No.</th>
            <th>Name</th>
            <th>Contact Person</th>
            <th>Mobile No</th>
            <th>Address</th>
            <th>E-mail</th>
            <th>State</th>
            <th>GTS No</th>
            <th>PAN No</th>
            <th>Modify</th>
        </tr>
    </thead>                 
    <tbody>
        <?php
        $i=1;
        while($show_menu = mysql_fetch_array($menu)) 
        {
        ?>	
            <tr>
            <td><?php echo $i++; ?></td>
            <td><?php echo $show_menu['name']; ?></td>
            <td><?php echo $show_menu['c_name']; ?></td>
            <td><?php echo $show_menu['mobile_no']; ?></td>
            <td><?php echo $show_menu['address']; ?></td>
            <td><?php echo $show_menu['email']; ?></td>
            <td><?php echo state($show_menu['state']); ?></td>
            <td><?php echo $show_menu['gst_no']; ?></td>
            <td><?php echo $show_menu['pan_no']; ?></td>
            <td class="center" style="text-align:center">
                <a href="home.php?page=client_registration&page_id=<?php echo $show_menu['id'];?>"><img src="images/edit_new.png"  border="0" style="width: 20px;"/></a>
            </td> 
        </tr>
       <?php } ?>                
    </tbody>            
</table> 
</div>    
</div>
</div>            
<script>
$(document).ready(function() {
var table = $('#example').DataTable( {
"order": [[ 2, "asc" ]],
"pageLength": 50,stateSave: true,
fixedHeader: {
header: true,
footer: true
}
} );
table.on( 'order.dt search.dt', function () {
table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw(); } );
</script>