<?php


	// ===============================================
	// GD処理準備
	// 備考		：	
	// 更新		：	2010/09/08 KMK T.Teraoka
	// ===============================================
	//定数
	$posi_base_x = 40;
	$posi_base_y = 20;
	$x_item = 26;
	$y_item = 20;
	$recive_no_start = 200;


	$x_size = 1190 + 2;
//	$y_size = 650 + 1;
	$y_size = $posi_base_y * ($y_item + 1);


	$img = imagecreatetruecolor($x_size,$y_size);			//パレットの作成
	
	//$font1 = "/www/fonts/VL-Gothic-Regular.ttf";
	//$font1 = "/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf";
	//$font1 = "/www/ansys/config/fonts/vlgothic/VL-Gothic-Regular.ttf";
	$font1 = "/www/ansys/config/fonts/ipam.ttf";

	// 使用色の準備
	$Black = imagecolorallocate($img, 0,0,0);
	$White = imagecolorallocate($img, 255, 255, 255);
	$Red =  imagecolorallocate($img, 255, 0, 0);
	$Green =  imagecolorallocate($img, 0, 128, 0);
	$Blue = imagecolorallocate($img, 0, 0, 255);
	$LightBlue = imagecolorallocate($img, 0, 191, 255);
	$Orange = imagecolorallocate($img, 255, 165, 0);


	
	imagefilledrectangle($img,0,0,$x_size,$y_size,$White);
	imagefilledrectangle($img,0,0,$x_size,20,$LightBlue);
	imagerectangle($img,0,0,$x_size-1,$y_size-1,$Black);
	imageline($img,0,20,$x_size,20,$Black);
	
	$time = date("Y-m-d H:i:s" ,time());


//縦軸の作成
ImageTTFText ($img, 11, 0, 4, 45, $Black, $font1, "");

for($ax = 0;$ax < $x_item;$ax++)
{
	$x_plus =$ax *$posi_base_x;
	$recive_no = $recive_no_start + $ax;
	imageline($img,150 + $x_plus,0,150 + $x_plus,$y_size,$Black);
	ImageTTFText ($img, 11, 0, 158 + $x_plus, 15, $Black, $font1, $recive_no);
}



$output=null;
$retval=null;
exec('tail -n ' .$y_item .' /www/beacon/data/data.txt', $output, $retval);
//echo "Returned with status $retval and output:\n";

$ct = count($output);
//for($i =0;$i < $ct;$i++)
//{
//	$data_split = expload($output[$i],","
//	print $output[$i] ."<BR>";
//}

//横軸の作成
for($ay = 0;$ay < $y_item;$ay++)
{
	$y_plus =$ay *$posi_base_y;
	imageline($img,0,20 + $y_plus,$x_size,20 + $y_plus,$Black);
	
	$data_split[$ay] = explode(",",$output[$ay]);
	ImageTTFText ($img, 11, 0, 4, 35 + $y_plus , $Black, $font1, $data_split[$ay][0]);
	
	//データ表示
	$reciv_no = substr($data_split[$ay][2],10,3);
	$reciv_no_posi = ($reciv_no - $recive_no_start) * $posi_base_x;
	$beacon_no = substr($data_split[$ay][3],12,5);
	
	ImageTTFText ($img, 11, 0, 4, 35 + $y_plus , $Black, $font1, $data_split[$ay][0]);
	ImageTTFText ($img, 9, 0, 158 + $reciv_no_posi, 35 + $y_plus , $Black, $font1, $beacon_no);
}


//	imageline($img,40,30,40,$y_size,$Black);
//	imageline($img,80,30,80,$y_size,$Black);
//	imageline($img,120,30,120,$y_size,$Black);

/*
	imageline($img,150,30,150,$y_size,$Black);
	imageline($img,190,30,190,$y_size,$Black);
	imageline($img,240,30,240,$y_size,$Black);
	imageline($img,280,30,280,$y_size,$Black);

	ImageTTFText ($img, 11, 0, 154, 45, $Black, $font1, "200");
	ImageTTFText ($img, 11, 0, 194, 45, $Black, $font1, "201");
	ImageTTFText ($img, 11, 0, 234, 45, $Black, $font1, "202");
	ImageTTFText ($img, 11, 0, 274, 45, $Black, $font1, "203");
	ImageTTFText ($img, 11, 0, 314, 45, $Black, $font1, "204");
	ImageTTFText ($img, 11, 0, 354, 45, $Black, $font1, "205");

	ImageTTFText ($img, 11, 0, 4, 65, $Black, $font1, $time);
*/

	
	// 更新時間をマップに表示する
//	$up_check = date("Y-m-d H:i:s" ,time());
//	imagefilledpolygon($img, array(10, 10, 10, 20, 55, 20, 55, 10), 4, $White);
//	ImageTTFText ($img, 15, 0, 10, 20, $Black, $font1, $up_check);

/*

	for($i = 0;$i < $ct;$i++)
	{
		$row = pg_fetch_array($res,$i);
		$row2 = pg_fetch_array($res2,$i);
		$ii = $i * 20;


		imageline($img,0,50 + $ii ,802,50+ $ii,$Black);
		ImageTTFText ($img, 9, 0, 1, 65+ $ii, $Black, $font1, $row['device_id']);
		ImageTTFText ($img, 9, 0, 52, 65+ $ii, $Black, $font1, $row['gps_date']);
		ImageTTFText ($img, 9, 0, 202, 65+ $ii, $Black, $font1, $row['latitude']);
		ImageTTFText ($img, 9, 0, 352, 65+ $ii, $Black, $font1, $row['longitude']);
		
		
		if($jd2 <= abs($row2['gps_altitude']))
		{
			ImageTTFText ($img, 9, 0, 502, 65+ $ii, $Red, $font1, number_format($row2['gps_altitude'],2,".",""));
		}
		else if($jd1 <= abs($row2['gps_altitude']))
		{
			ImageTTFText ($img, 9, 0, 502, 65+ $ii, $Orange, $font1, number_format($row2['gps_altitude'],2,".",""));
		}
		else
		{
			ImageTTFText ($img, 9, 0, 502, 65+ $ii, $Black, $font1, number_format($row2['gps_altitude'],2,".",""));
		}

	}

*/
	// ===============================================
	// 描画した画像を保存 & パレットを削除
	// 備考		：	
	// 更新		：	2010/09/08 KMK T.Teraoka
	// ===============================================
	header('Content-Type: image/png');

//	imagepng($img, $imgFileName);
	imagepng($img);
	imagedestroy($img);
?>
