<?php

session_start();
include('script/condb.php');

if(isset($_POST['currency'])){
	
$convertto =$_POST['uomsec'];

/*$querysel="select * from uom_converter WHERE uom_name= '$convertto' ";
	
$result =mysqli_query($con, $querysel);
while($row=mysqli_fetch_assoc($result)){
	$lenght=$row['uom_length'];
	$area=$row['uom_area'];
	$cubic=$row['uom_cubic'];
	$sand=$row['uom_sand'];
	$cement=$row['uom_cement'];
	$gravel=$row['uom_gravel'];
}*/
	$sel2 ="select * FROM upline_app_materials where material_type='Block' ";
	$result2 =mysqli_query($con,$sel2);
	while($row2=mysqli_fetch_assoc($result2)){
		
		$convertfrm=$row2['material_uom'];
		$width=$row2['material_width'];
		$height=$row2['material_height'];
		
			}
	//m to inches converter
	if($convertfrm=='m' && $convertto=='in'){
		$finalheightconvert =39.3701;
		$finalwidthconvert= 39.3701;
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
	} 
	// inches to m converter
	if($convertfrm=='in' && $convertto=='m'){
		$finalheightconvert = 39.3701;
		$finalwidthconvert= 39.3701;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))/'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))/'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	//m to cm  converter
	
	 if($convertfrm=='m' && $convertto=='cm'){
		$finalheightconvert =100;
		$finalwidthconvert= 100;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	//cm to inches converter 
	if($convertfrm=='cm' && $convertto=='in'){
		$finalheightconvert =0.3937;
		$finalwidthconvert= 0.3937;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	// inches to cm convert
	
	if($convertfrm=='in' && $convertto=='cm'){
		$finalheightconvert =2.54;
		$finalwidthconvert= 2.54;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	////////////////////////////////////
	//cm to yd converter
	
	 if($convertfrm=='cm' && $convertto=='yd'){
		$finalheightconvert = 0.010936133;
		$finalwidthconvert= 0.010936133;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	//yd to cm converter
	
	 if($convertfrm=='yd' && $convertto=='cm'){
		$finalheightconvert = 91.44;
		$finalwidthconvert= 91.44;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	
	// m to yd converter
	if($convertfrm=='m' && $convertto=='yd'){
		$finalheightconvert = 0.9144;
		$finalwidthconvert= 0.9144;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))/'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))/'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	// yd to m converter
	
	if($convertfrm=='yd' && $convertto=='m'){
		$finalheightconvert = 0.9144;
		$finalwidthconvert= 0.9144;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	// in to yd converter
	
	if($convertfrm=='in' && $convertto=='yd'){
		$finalheightconvert = 36;
		$finalwidthconvert= 36;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))/'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))/'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	// yd to in converter
	
	if($convertfrm=='yd' && $convertto=='in'){
		$finalheightconvert = 36;
		$finalwidthconvert= 36;
		
		$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(4,2))*'$finalwidthconvert', material_height=CAST(material_height as DECIMAL(4,2))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}
		
		
	}
	
	//var_dump($convertfrm, $convertto);
	/*echo( $convertfrm);
		echo($convertto);*/
	//$me =
/*echo '<script language ="javascript" type= "text/javascript"> alert("Unit of Measuremnent is  '.$uom.' and the sand value is '.$sand.' "); location.href="view-mat.php";</script>';*/
//CAST(material_width as int) * value
	/*$sql= "UPDATE upline_app_materials SET material_width=CAST(material_width as DECIMAL(5,4))*'$finalwidthconvert', material_height=CAST(material_height as DECIMelseAL(5,4))*'$finalheightconvert', material_uom='$convertto' WHERE material_type='Block' ";
	$checkmate=mysqli_query($con, $sql);
	if($checkmate){
		echo '<script language ="javascript" type= "text/javascript"> alert("Conversion successful "); location.href="view-mat.php";</script>';
	}*/
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
	
</body>
</html>