<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();




 

$error = "";
//$tablename='cf_client';

	if(isset($_POST['update_id'])){
		/*Updating */
		$id = $_POST['update_id'];
		
	}
	

	else if(isset($_GET['delete_id'])){
		/*Delete a record */
		$id = $_GET['delete_id'];
		$res = mysql_query("delete from tbl_upload_file where id='$id'");
		header("Location:upload_file_list.php");
	}


	else if(isset($_POST['banksubmit'])){
		
		$vehicle_or_others_rad = $_POST['vehicle_or_others_rad'];
		$description = $_POST['description'];
		
		if(isset($_FILES['imageUp'])) {
	
			$validExtensions = array("jpeg","jpg","png");
			$fileOldName = $_FILES['imageUp']['name'];
			$location = $_FILES['imageUp']['tmp_name'];
			
			$extension = end(explode(".",$fileOldName));
			if(in_array($extension,$validExtensions))
			{
				$newName = rand().rand().".".$extension;
				move_uploaded_file($location,"up/".$newName);
				if($vehicle_or_others_rad=="0")
				{
					$vehicle_id = $_POST['chooseVehicle'];	
					$query = "insert into tbl_upload_file (vehicle_others,vehicle_id,description,image) values($vehicle_or_others_rad,'$vehicle_id','$description','$newName')";
				}
				else {
					 $query = "insert into tbl_upload_file (vehicle_others,description,image) values($vehicle_or_others_rad,'$description','$newName')";
				}
				
				mysql_query($query);
				//echo "<script>alert('Added');</script>";
				$error =  "added";
			}
			else {
				//echo "<script>alert('invalid file type');</script>";
				$error =  "invalid file type";
			}
		}
		
	
	}


		
			


?>
<!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 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>




<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];}
}
//-->


</script>


<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}
</style>
</head>

<body>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
 <div class="tabbedArea">
  
  <div class="tabBody">
   <h1>Add Files</h1>
   <a style='float:right;padding:10px;margin-right:30px;background-color:rgb(7, 183, 151);' href='upload_file_list.php' >List All</a> <br>
	  
   <form name="addNewForm" enctype='multipart/form-data' method="post" action="add_upload_file.php">
   
   <div class="addEmp" style="margin-bottom:0px; border-bottom:0px solid;width:1000px;">
        <table width="40%" border="0" cellspacing="20" cellpadding="10">
          <tr>
				<td>
					Vehicle / others 
				</td>
				<td> 
					<label>Vehicle <input type='radio' id='vehicle_rad' checked value='0' name='vehicle_or_others_rad'></label>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label>Others <input type='radio' id='others_rad' value='1' name='vehicle_or_others_rad'></label>
				</td>
			</tr>
			<?php 
			
				$vehicles = mysql_query("select * from cf_vehicle");
			
			?>
			<tr id='vehicleChooseRow'>
				<td>
					Choose Vehicle 
				</td>
				<td> 
					<select class='input1 input3' id='chooseVehicle' name='chooseVehicle'>
						<option value='-1'> Choose Vehicle </option>
						<?php 
							while($row=mysql_fetch_array($vehicles))
							{
						?>
						<option value='<?php echo $row['id'];?>'> <?php echo $row['vehiclenum'];?> </option>
						<?php 
							}
						?>
				</td>
			
			</tr>
			<tr>
				<td> Description </td>
				<td>
					<textarea name='description' id='description' class='input1 input3'></textarea>
				</td>
			</tr>
			
			<tr>
				<td> Image </td>
				<td>
					<input type='file' name='imageUp' id='imageUp' class='input1 input3'>
				</td>
			</tr>	
			
           <tr>
            <td colspan="2"><div class="searchField1">
        

     <input name="banksubmit" type="submit" class="input1"  style='padding:10px;height:34px;margin-top:20px;background-color:rgb(7, 183, 151);' value="Save" />
    

   
		 
		 <a style='margin-left:20px;float:right;padding:10px;margin-right:30px;margin-top:20px;background-color:rgb(7, 183, 151);' href='add_upload_file.php' >Cancel</a> <br>
		 
        </div>
        </td>
          </tr>
        </table>
 

 
 <?php 
 
 echo $error;
 
 ?>
 
 
<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");
?>


<script>

$(document).ready(function(){
	
	
	$("[name='vehicle_or_others_rad']").click(function(){
		
		if($(this).val()==0) {
			
			$("#vehicleChooseRow").show();
		}
		else 
			$("#vehicleChooseRow").hide();
		
	});
	
});



</script>

</div>
</body>
</html>


		






