 <?php
 if(isset($_REQUEST['update']))
 {
	$id                     = $_POST['id'];
	$state_name	            = mysql_real_escape_string($_POST['state_name']);
	$state_code             = mysql_real_escape_string($_POST['state_code']);
	$st_mobile		        = mysql_real_escape_string($_POST['st_mobile']);
	$gst_no	                = strtoupper(mysql_real_escape_string($_POST['gst_no'])); 	
	$st_address	            = mysql_real_escape_string($_POST['st_address']); 
	$backend_mail           = mysql_real_escape_string($_POST['backend_mail']); 

	mysql_query("update `state` set `state_name`='$state_name', `state_code`='$state_code', `backend_mail`='$backend_mail', `gst_no`='$gst_no', `st_address`='$st_address', `st_mobile`='$st_mobile' where `id`='$id'") or die(mysql_error());	
	$_SESSION['msg'] = 'State Details Updated Sucessfully!!';
	 header("location:home.php?page=state_list");	 
 }
 
 if(isset($_REQUEST['submit']))
 {
	$state_name	            = mysql_real_escape_string($_POST['state_name']);
	$state_code             = mysql_real_escape_string($_POST['state_code']);
	$st_mobile		        = mysql_real_escape_string($_POST['st_mobile']);
	$gst_no	                = strtoupper(mysql_real_escape_string($_POST['gst_no'])); 	
	$st_address	            = mysql_real_escape_string($_POST['st_address']); 
	$backend_mail           = mysql_real_escape_string($_POST['backend_mail']); 

	mysql_query("insert into `state` set `state_name`='$state_name', `state_code`='$state_code', `backend_mail`='$backend_mail', `gst_no`='$gst_no', `st_address`='$st_address', `st_mobile`='$st_mobile'") or die(mysql_error());	
	$_SESSION['msg'] = 'State Details Updated Sucessfully!!';
	 header("location:home.php?page=state_list");	 
 }
 ?>           
<div class="row-fluid" >
    <div class="span12">
        <div class="head clearfix">
            <div class="isw-ok"></div>
            <h1><?php if(isset($_REQUEST['st_id'])) { echo "Modify";}else {echo "Add";}?> State</h1>
            <h1 style="float: right; margin-right: 10px;"><a href="home.php?page=state_list" style="color:#FFF;">State List</a></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['st_id']))
			   {
				   $id            =       $_REQUEST['st_id'];
				   $modify_menu   =       mysql_query("SELECT * FROM `state` WHERE `id` = '$id'");
				   $show_modify   =       mysql_fetch_array($modify_menu);
			   }
			  ?>
              <input type="hidden" name="id" placeholder="Page Name" <?php if(isset($_REQUEST['st_id'])){?> required value="<?php echo $show_modify['id'];  ?>"<?php } ?> id="txt_name" autocomplete="off" />
                
                     <div class="row-form clearfix">
                        <div class="span3">
                        	<label>State Name</label>
                        	<input type="text" name="state_name" placeholder="State Name" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['state_name'];?>"<?php } ?> autocomplete="off" id="state_name" required/>
                        </div>
                        <div class="span3">
                        	<label>State Code</label>
                        	<input type="text" name="state_code" placeholder="State Code" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['state_code'];  ?>"<?php } ?> id="state_code" required/>
                        </div>
                        <div class="span3">
                        	<label>Mobile No</label>
                        	<input type="text" name="st_mobile" placeholder="State Mobile No" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['st_mobile'];  ?>"<?php } ?> id="st_mobile"/>
                        </div>
                        <div class="span3">
                        	<label>GST No</label>
                        	<input type="text" name="gst_no" placeholder="State GST No" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['gst_no'];  ?>"<?php } ?> id="gst_no" required/>
                        </div>
                        </div>
                        <div class="row-form clearfix">
                        <div class="span12">
                        	<label>Address</label>
                        	<input type="text" name="st_address" autocomplete="off" required placeholder="State Address" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['st_address'];?>"<?php } ?> id="st_address" />
                        </div>
                        
                     </div>
                     	<div class="row-form clearfix">
                        <div class="span12">
                        	<label>Backend Email Address</label>
                        	<input type="text" name="backend_mail" placeholder="State Email Address" <?php if(isset($_REQUEST['st_id'])){?>value="<?php echo $show_modify['backend_mail'];?>"<?php } ?> id="backend_mail" />
                        </div>
                        
                     </div>
                     
                <div class="row-form clearfix">
                    <div class="span3">&nbsp;</div>
                    <div class="span2"><input type="submit" name="<?php if(isset($_REQUEST['st_id'])){echo "update"; }else{ echo "submit";}?>" class="btn btn-block" value="<?php if(isset($_REQUEST['st_id'])){ echo "Update"; }else{ echo "Save";}?>"/></div>
                </div>
              </fieldset>
            </form>  
        </div> 
    </div>
</div> 
<script>
function get_validation()
{
	var account_no 	  = $("#account_no").val();
	var re_account_no = $("#re_account_no").val();
	$("#branch_ifsc_err").html("");	
	$("#gender_err").html("");	
	var branch_ifsc   = $("#branch_ifsc").val();	
	var cs 			  = branch_ifsc.length;
	var no_5		  = branch_ifsc.substring(4,5);
	if($('input[name=gender]:checked').length<=0)
	{
	 	$("#gender_err").html("Please Select Gender !!!!!!!!!!");	
		return false;
	}
	if(cs<11)
	{
		$("#branch_ifsc_err").html("Please Enter Minimum 11 ");	
		$("#branch_ifsc").focus();		
		return false;
	}
	if(no_5!=0)
	{		
		$("#branch_ifsc_err").html("Please Enter Right Ifsc Code ");	
		$("#branch_ifsc").focus();		
		return false;
	}
	if(account_no!=re_account_no)
	{
		alert("Account No Does'nt Match !!!!!!!!");	
		$("#re_account_no").focus();
		return false;
	}
//return get_emp_code();
}

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));
}
function get_hus_fat()
{
	var marital_st = $('#marital_st').val();
	var radioValue = $("input[name='gender']:checked").val();
	if(marital_st=='')
	{
       alert("Please Select Marital Status !!!!");
	}
	if(radioValue=='')
	{
       alert("Please Select Gender !!!!");
	}
	if( (marital_st=='MARRIED') && (radioValue=='Female'))
	{
	 	document.getElementById("fname_label").innerHTML="Husband's Name";
	}
	else if( (marital_st=='UN MARRIED') && (radioValue=='Female'))
	{
		document.getElementById("fname_label").innerHTML="Father's Name";
	}
	else if( radioValue=='Male')
	{
		document.getElementById("fname_label").innerHTML="Father's Name";
	}
}
function get_month_test(val_val,month_name)
{
	if(val_val=='Distributer')	
	{
		$("."+month_name+"_id").css("display","block");
	}
	else
	{
		$("."+month_name+"_id").css("display","none");
	}
}
function get_emp_code()
{
	var emp_code   = $("#emp_code").val();
	if (emp_code == '') {
		alert("Please Enter Employee Code !!!");
		return;
	} else {
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				alert(xmlhttp.responseText)
				if(xmlhttp.responseText==0)
				{
					return true;
				}
				else
				{
					alert("Employee Code Already Exists !!!!!!");
					$("#emp_code").focus();
					return false;
				}
			}
		}
		xmlhttp.open("GET","ajax/gte_chk_emp_code.php?emp_code="+emp_code,true);
		xmlhttp.send();
	///	return false;
	}
}
</script>   