<?
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

include('imageAdaptation.php');

$i=$_POST['img'];
$ua=$_POST['uagent'];

if ($i=='')
{
   $i='imgc/mirror.jpg';
}
list ($imwidth,$imheight)= getimagesize($i);


if ($ua=='')
{
   $ua=getUA();
}

$s = microtime(true);
$imgurl=convertImageUA($i,$ua);
$e = microtime(true);

$isMob=isMobile($ua);


if($isMob=='0')
{
	$devDetail='Not Mobile';
	$devD='Not Mobile';
	$convD='No conversion done.';
}
else
{
	list($devVendor,$devModel,$devColor)=getDevice($ua);
	if ($devVendor=='')
 		{
 		$devDetail='Device NOT detected';
 		}
 	else
   		$devDetail=$devVendor."-".$devModel;
   
	list($devRealwidth,$devRealheight)= getDeviceData($ua);
	list($format,$devwidth,$devheight,$resizeOption)= getCAP($ua);
	list($Rwidth,$Rheight)=setImageDimension($imwidth,$imheight,$devwidth,$devheight);
	$devD=$devRealwidth."X".$devRealheight;
	if ($devD=='0X0')
 		$devD='Screen Resolution not found from DeviceAtlas. So 120x120 is considered as default screen resolution.';
	$convD=$Rwidth."X".$Rheight;
}

$imgD=$imwidth."X".$imheight;

?>
<html>
<head><title>Simulate Image Rendering</title>
<style type="text/css">
body {
	margin: 0px;
	font-family: Arial,Helvetica, sans-serif;
	font-size: 0.5em;
}
#divred {width:100%; background-color: red; color: white; font-weight: bold; font-size: 5em; text-align: center;} 
#blank{}
</style>
</head>
<body>
<div id="divred">Simulator: Image Rendering API</div>
<div id="blank">
<form method="post" action="simulator.php">
<table>
<tr><td><b>Select Image:</b> </td><td><select name="img">
    <option value="imgc/mirror.jpg">Mirror</option>
    <option value="imgc/eye.jpg">Eye</option>
    <option value="imgc/france.jpg">France</option>
  </select><br></td></tr>
<tr><td><b>Select Handset:</b> </td><td><select name="uagent">
    <?
	$fp = fopen("testHandset.txt", 'r');
	$i=0;
	while( !feof($fp) )
	{
	$line = fgets($fp);
	if ($line!='')
	{
	  $pc = explode('|', $line);
	  
	  $modl=explode('-',$pc[0]);
	  
	  if ($modl[1]!=''){
	  	$selVal="";
	  	if ($ua==$pc[1])
	  	  $selVal=" SELECTED ";
	  //list($uaVendor,$uaModel,$uaColor)=getDevice($pc[1]);
	  //if ($uaColor>2){
	  ?>
	  <option value="<? echo $pc[1]; ?>" <? echo $selVal; ?>><? echo $pc[0]; ?></option>
	  <?
	//}
	}
	}
	}
?>
 </select></td></tr>
<tr><td></td><td><input type="submit" value="Check IT"></td></tr>
</table>
</form>
</div>
<table border=1>
<tr>
<td>

<img src="<?php echo $imgurl;?>"></td>
</tr>
<tr><td><b>Handset: </b><? echo $devDetail; ?></td></tr>
<tr><td><b>UA: </b><? echo $ua; ?></td></tr>

<tr>
<td><b><? print "Time taken: " . floor(($e - $s)*1000) . "ms\r\n";?></b></td>
</tr>
<tr>
<td><?php echo $imgurl; ?></td>
</tr>
<tr>
<td>
<table border=1>
<tr>
<td><b>Image(Main)</b></td>
<td><b>Device</b></td>
<td><b>Image(Resized)</b></td>
</tr>
<tr>
<td><?php echo $imgD;?></td>
<td><?php echo $devD;?></td>
<td><?php echo $convD;?></td>
</tr>
</table>
</td>
</tr>

<table>
</body>
</html>

