<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$rproduct_clientid='';
$tripclientid='';$rcnt='';$client_main='';
$tyrenum_veh='';$rclient_code='';$rrate='';$rclient_name='';$rclient_id='';$rtown_id='';$rpackname='';$billtype='';
$cclient_name='';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

if(isset($_REQUEST['del']) && $_REQUEST['del']=='delete')
{
	$id = $_REQUEST['id'];
	$sql=mysql_query("delete from cf_cases where case_id='$id'");
	header("location:vehicle_cases.php?msg=You Have Successfully Deleted");
}
	
	
            $tablename='cf_cases';
   			//$sqlObj->tablename=$tablename;
		   
		    if(isset($_POST['save'])){	
			
			if(isset($_POST['case_no'])){
			$caseno=addslashes($_POST['case_no']);
			}	
			
			if(isset($_POST['vechicle_no'])){
			$vechicleno=addslashes($_POST['vechicle_no']);
			}
			
			
			if(isset($_POST['case_date'])){
				$casedate=date(('Y-m-d'),strtotime($_POST['case_date']));
				}
				
				if(isset($_POST['vehicle_status'])){
				$status=addslashes($_POST['vehicle_status']);
				}
				else
				{
				$status=0;
				}
			
			
				$fieldname='(case_name,case_date,case_veh_id,case_type,case_status)';
				$fieldvalue='"'.$caseno.'","'.$casedate.'","'.$vechicleno.'","vehicle","'.$status.'"';				
				$qsy= "insert into ".$tablename.$fieldname." values(".$fieldvalue.")";
				$CreateClient 	= mysql_query($qsy);
				header("location:vehicle_cases.php?msg=You Have Successfully Saved");
			}
			
			$vehid='';
			$casename='';
			$casedate='';
			$casestatus='';
			
			
				if(isset($_REQUEST['caseid'])){
					$caseid=mysql_escape_string($_REQUEST['caseid']);
					$rqry=mysql_query("SELECT *  FROM cf_cases where case_id='".$caseid."'");
					if($rqry && mysql_num_rows($rqry)>0)
					{
						while($sobj=mysql_fetch_object($rqry))
						{
							$vehid=$sobj->case_veh_id;
							$casename=$sobj->case_name;
							$casedate=$sobj->case_date;
							$casestatus=$sobj->case_status;
						}
					}
			}
			
			if(isset($_POST['Edit']))
			{
				
				if(isset($_POST['vechicle_no'])){
				$vechicleno=addslashes($_POST['vechicle_no']);
				}
				
				if(isset($_POST['case_no'])){
				$caseno=addslashes($_POST['case_no']);
				}	
				if(isset($_POST['case_date'])){
				$casedate=date(('Y-m-d'),strtotime($_POST['case_date']));
				}
				
				if(isset($_POST['vehicle_status'])){
				$status=addslashes($_POST['vehicle_status']);
				}
				else
				{
				$status=0;
				}
				
				
			
				$updata="case_name='".$caseno."',case_date='".$casedate."',case_veh_id='".$vechicleno."',case_status='".$status."'";
				$qsy= "update ".$tablename." set ".$updata." where case_id='".$caseid."'";
				$CreateClient 	= mysql_query($qsy);
				header("location:vehicle_cases.php?msg=You Have Successfully Saved");
					
			}
			
			$literid = '';		
			

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<!--<link href="css/styles.css" rel="stylesheet"  />
<link rel="stylesheet" href="css/datepick/themes/chosen.css">
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>-->


<link href="css/styles.css" rel="stylesheet"  />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/datepick/themes/chosen.css">
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/trippopup.js" type="text/javascript"></script>


<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>






<script>$(document).ready(function(){
$('#case_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});
</script>

<script src="js/addmoretown.js"></script>



<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

/*function showClient(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	   // document.getElementById("txtHinttwn").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_rate.php?str="+str,true);
xmlhttp.send();
}
*/

</script>

	<script type='text/javascript'>
	
function validationrate()
{
if(document.prodfrmname.client_subid.value=='')
	{
		alert("Enter Client Code");
		document.prodfrmname.client_subid.focus();
		return false;
	}
if(document.prodfrmname.rate.value=='')
	{
		alert("Enter rate");
		document.prodfrmname.rate.focus();
		return false;
	}
if(document.prodfrmname.townname.value=='')
	{
		alert("Enter Townname");
		document.prodfrmname.townname.focus();
		return false;
	}
	if(document.prodfrmname.clientname.value=='')
	{
		alert("Enter Client Name");
		document.prodfrmname.clientname.focus();
		return false;
	}
	if(document.prodfrmname.billtype.value=='')
	{
		alert("Enter Billtype");
		document.prodfrmname.billtype.focus();
		return false;
	}
	
}
function showtownvalued(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
  document.getElementById("txtHint").innerHTML='<img src="images/loading.gif" border="0">';
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_rate_town.php?str="+str,true);
xmlhttp.send();
}
//--client code dropdown
function showClientcode(str){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtcodeshow").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtcodeshow").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","clientajax_ratecode.php?str="+str,true);
xmlhttp.send();
}
</script>
<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}
.addimgs{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
cursor:hand;
cursor:pointer;
}
.addimgs a:hover{
color: #000;
}
.rimg{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
cursor:hand;
cursor:pointer;
}
.rimg a:hover{
color: #000;
}
.td-border-11 td{border:1px solid #ddd; padding:15px; font-size:13px;}

</style>
</head>

<body>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
 <div class="tabbedArea">
  
  <div class="tabBody">
   <h1>Add Vehicle Cases </h1>
   <form name="prodfrmname" method="post" action="">
   <?php
	if(!empty($casedate))
    {
		$casedt = date(('d-m-Y'),strtotime($casedate));
	}
	else
	{
		$casedt ='';
	}
	?>
<input type="hidden" id="divcnt" value="<?=$div?>" name="cnt"/>
   <div class="addEmp" style="margin-bottom:0px; border-bottom:0px solid;width:1000px;">
        <table width="85%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td valign="top">
            <!-- <div class="form1" style="min-width:600px;border-right:0px; "> -->
           <div class="form1"> 
		   
		   <div>  
		   <p class="input1">Vehicle No <span style="color:#FF3300">*</span></p>
               <select class="chzn-select restselect input3" name="vechicle_no" >
                    <option value="">Vehicle No</option>
                    <?php 
                            $sq_vechicle="select * from cf_vehicle";
                            $arr1=mysql_query($sq_vechicle);
                            while($resvechicle=mysql_fetch_array($arr1))
                            {
                        ?>
                    <option value="<?=$resvechicle['id']?>" <? if($resvechicle['id']==$vehid) {?>selected<? }?> >
                    <?=$resvechicle['vehiclenum']?>
                    </option>
                    <?php
                                }
                     ?>
                  </select>
     	   </div>
           
           <div>  
		   <p class="input1">Cases No <span style="color:#FF3300">*</span></p>
                <input name="case_no" class="input1 input3"  type="text" value="<?=$casename?>">  
     	   </div>
          

		   <div>
      			<p id="divshw" class="input1">Date<span style="color:#FF3300">*</span></p>
                <input name="case_date" id="case_date" class="input1 input3"  type="text" value="<?=$casedt?>">  
     	   </div>
		   
		   <div>
      			<p  class="input1" style="padding-top:20px;">Status<span style="color:#FF3300">*</span>
				<input type="checkbox" name="vehicle_status"  class="input1" <?php if($casestatus==1){?> checked <?php }?> value="1" > </p>
                 
     	   </div>	

            
          <div><table width="70%" border="0" cellspacing="0" cellpadding="10">
       <tr>
         <td colspan="2"><div class="searchField1">
         <?php
	 	if(isset($_REQUEST['caseid'])){
	  ?>	 
      <input name="Edit" type="submit" class="input1" value="Edit" onClick="return validationrate();"/>
      <?php }else { ?>   
     <input name="save" type="submit" class="input1" value="Save" onClick="return validationrate();"/>
	  <?php } ?>

        </div>
        </td>
          </tr>
        </table></div>
			
			</div>
        </td>
            <td valign="top">
<table width="130%" border="0" cellpadding="0" cellspacing="0" class="td-border-11">
  <tr style="font-weight:bold;">
    <td>No</td>
    <td>Vehicle No</td>
	<td>Case No</td>
    <td>Date</td>
	<td>Status</td>
    <td>Edit</td>
    <td>Delete</td>
  </tr>
  <?php 
  $i=1;
  $rqry="SELECT *  FROM cf_cases  join cf_vehicle on cf_cases.case_veh_id = cf_vehicle.id where case_type = 'vehicle' ";
			$sqry=mysql_query($rqry);
			if($sqry && mysql_num_rows($sqry)>0)
			{
				while($sobj=mysql_fetch_object($sqry))
				{
					$case_id=$sobj->case_id;
					$vehiclenum=$sobj->vehiclenum;
					$case_name=$sobj->case_name;
					$case_date=$sobj->case_date;
					$casestatus=$sobj->case_status;
					if($casestatus == 1)
					{
						$stat = 'Completed';
					}
					else
					{
						$stat = 'Pending';
					}
					
					
					?>
					<tr>
                    <td><?=$i?></td>
					 <td><?=$vehiclenum?></td>
                    <td><?=$case_name?></td>
					<td><?=date(('d-m-Y'),strtotime($case_date))?></td>
					<td><?=$stat?></td>
					<td><a href="vehicle_cases.php?caseid=<?php echo $case_id; ?>" style="color:#FF9900">Edit</a></td>
					<td class="tr_td_r" ><a href="vehicle_cases.php?del=delete&id=<?php echo $case_id; ?>" onClick="return confirm('Do you really want to delete this field?');"><img src="images/delete.png" title="Delete"></a></td> 
					</tr>
				<?php 
					$i++;
					}
				}
			
  ?>
  
</table>
</td>
          </tr>
        </table>
	<div id="div2">
	</div>
	
       

<div class="mand"><p>Fields marked <span style="color:#FF3300">*</span> are Mandatory</p></div>
</div>
   </form>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
  <?php 
	include("leftlink.php");
?>

</div>
</body>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>
</html>


		






