File "view_OLD.php"

Full path: /www/ansys/qgis/2015_crun/OLD/view_OLD.php
File size: 17.5 KiB (17917 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//	自動でクラスを参照する
//	関数名	:	__autoload()
//	備考	:	参照先は./class/XXX.phpとする
//	更新	:	2012/10/19 KMK-Teraoka
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
function __autoload($className)
{
	$fPath = "./class/" . str_replace("_", "/", $className) . ".php";
	require_once $fPath;
}

//===============================================
//	DEBUG_MODE
//	備考		:	
//	更新		:	2012/10/19 KMK-Teraoka
//===============================================
define("DEBUG_MODE", "0");
cDebug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
	cStopwatch::start();
}

//===============================================
//	CommonUtilities
//	備考		:	
//	更新		:	2012/11/29 KMK-Teraoka
//===============================================
$SCRIPT_TITLE = "運行管理システム 東京国際空港C誘導路中央部他地盤改良工事";
$PENTA_OCEAN = "五洋建設株式会社";
$TAIL_PENTA_OCEAN = "penta-ocean";

$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$LOG_FILE = "./log/view_position.log";

$CONST_ID = 9;
$APPLICATION_ID = 16;
$MAP_NAME = "./map/haneda2.png";

$VIEW_LIST = array(
	"0"		=>	array("head"	=>	"id",			"object"	=>	"android_id",		"width"		=>	"12%"),
	"1"		=>	array("head"	=>	"端末名称",		"object"	=>	"terminal_name",	"width"		=>	"12%"),
	"2"		=>	array("head"	=>	"緯度",			"object"	=>	"lat",				"width"		=>	"10%"),
	"3"		=>	array("head"	=>	"経度",			"object"	=>	"lon",				"width"		=>	"10%"),
	"4"		=>	array("head"	=>	"精度",			"object"	=>	"acc",				"width"		=>	"8%"),
	"5"		=>	array("head"	=>	"速度",			"object"	=>	"spd",				"width"		=>	"8%"),
	"6"		=>	array("head"	=>	"測位時間",		"object"	=>	"mesdatetime",		"width"		=>	"20%"),
	"7"		=>	array("head"	=>	"更新時間",		"object"	=>	"upddatetime",		"width"		=>	"20%"),
);

//===============================================
//	HTML-HEAD-
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
print "<html>";
print "<head>";
//print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";
print "<meta http-equiv=\"Refresh\" content=\"6000\">";
print "<title>". $SCRIPT_TITLE. "</title>";
print "<style type=\"text/css\">";
print "html {font-size: 80%; font-family:\"MS ゴシック\"; overflow-y:scroll;}";
print "table {font-size: 100%; font-family:\"MS ゴシック\"; text-align:center;}";
print "input {font-size: 100%; font-family:\"MS ゴシック\";}";
print "select {font-size: 100%; font-family:\"MS ゴシック\";}";
print "pre {font-size: 100%; font-family:\"MS ゴシック\";}";
print "</style>";

print "<SCRIPT LANGUAGE='JavaScript'>";
print "function RefreshImg(filen)";
print "{";
print "uniq = new Date();";
print "uniq = \"?\"+uniq.getTime();";
print "newImage = document.imgToLoad.src;";
print "index = newImage.indexOf(\"?\", 0);";
print "		    if (index > 0)";
print "		        {";
print "		            newImage = newImage.substr(0, index);";
print "		        }";
print "		    document.imgToLoad.src = filen+uniq;";
print "}";
print "</SCRIPT>";


print "</head>";

//===============================================
//	HTML-BODY部開始-
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
print "<body>";

//for(;;)
//{

try
{
	$mLog = new cLog($LOG_FILE);
	
	// ===============================================
	// 画像情報の取得
	// 備考		:	
	// 更新		:	2012/11/29 KMK-Teraoka
	// ===============================================
	$imgSize = getimagesize($MAP_NAME);
	//$imgFileName = "./tmp/". $CONST_ID. "_". $APPLICATION_ID. "_". md5(uniqid(rand(), true)) .image_type_to_extension($imgSize[2]);
	$imgFileName = "view_map.php";
		
	// ===============================================
	// 基準点情報
	// 備考		:	
	// 更新		:	2012/11/29 KMK-Teraoka
	// ===============================================
//	$ltLon = 4562.620;						//経度(左上)
//	$ltLat = 2861.367;						//緯度(左上)
//	$rbLon = 5838.176;						//経度(右下)
//	$rbLat = 2489.424;						//緯度(右下)
	
//	$ltX = 279;								// 左上X座標
//	$ltY = 287;								// 左上Y座標
//	$rbX = 901;								// 右下X座標
//	$rbY = 468;								// 右下Y座標

	$ltLon = 1776.520;						//経度(左上)
	$ltLat = 2223.108;						//緯度(左上)
	$rbLon = 5822.263;						//経度(右下)
	$rbLat = 3694.629;						//緯度(右下)
	
	$ltX = 350;								// 左上X座標
	$ltY = 434;								// 左上Y座標
	$rbX = 1361;								// 右下X座標
	$rbY = 66;								// 右下Y座標


	
	$diffX = $rbX - $ltX;					// X座標ピクセルの差を求める
	$diffY = $rbY - $ltY;					// Y座標ピクセルの差を求める
	
	$spX = number_format(($rbLon - $ltLon) / $diffX, 10);		// X座標の倍率を求める
	$spY = number_format(($ltLat - $rbLat) / $diffY, 10);		// Y座標の倍率を求める
	
	// ■
	// 座標変換の為の準備
	$angle = pi() * (-59.884236) / 180.0;
	cPos2Loc::init(9);
	
	// ===============================================
	// GD処理準備
	// 備考		:	
	// 更新		:	2010/09/08 KMK T.Teraoka
	// ===============================================
	$src = ImageCreateFromPNG($MAP_NAME);						//パレットへ貼り付ける画像指定(地図画像)
	$img = imagecreatetruecolor($imgSize[0],$imgSize[1]);			//パレットの作成
	imagecopy($img, $src, 0, 0, 0, 0, $imgSize[0], $imgSize[1]);	//画像をパレットへ貼り付け
	
	$font1 = "/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf";
	imagesetthickness($img, $THIC);
	
	// 使用色の準備
	$Black = imagecolorallocate($img, 0,0,0);
	$White = imagecolorallocate($img, 255, 255, 255);
	
	// 更新時間をマップに表示する
	$up_check = date("H:i:s" ,time());
	imagefilledpolygon($img, array(10, 10, 10, 20, 55, 20, 55, 10), 4, $White);
	ImageTTFText ($img, 8, 0, 10, 20, $Black, $font1, $up_check);
	
	//================================================
	//	データベース接続
	//	備考		:	
	//	更新		:	2012/11/29 KMK-Teraoka
	//================================================
	$conn = pg_connect("
		host	=	". $HOST. "
		dbname	=	". $DB. "
		user	=	". $USER. "
		password=	". $PASS. "
	");
	if (!$conn)
	{
		throw new Exception("データベースへの接続に失敗しました");
	}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ===============================================
	// エリア判定
	// 備考		:	
	// 更新		:	2014/02/07 K.Kikuchi
	// ===============================================

	$AreaJudge[0] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[0] .= "(1399385346,369000000),";
	$AreaJudge[0] .= "(1399385346,369100000),";
	$AreaJudge[0] .= "(1399385348,369000000),";
	$AreaJudge[0] .= "(1399385348,369100000)";
	$AreaJudge[0] .= ")' ORDER BY terminal_name;";

	$ResPoint[0] = pg_query($conn, $AreaJudge[0]) or die("SQL ERROR!!<br />". $AreaJudge[0].pg_last_error());
	$CountPoint[0] = pg_num_rows($ResPoint[0]);

	$AreaJudge[1] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[1] .= "(1399388303,369000000),";
	$AreaJudge[1] .= "(1399388303,369100000),";
	$AreaJudge[1] .= "(1399388305,369000000),";
	$AreaJudge[1] .= "(1399388305,369100000)"; 
	$AreaJudge[1] .= ")' ORDER BY terminal_name;";
	
	$ResPoint[1] = pg_query($conn, $AreaJudge[1]) or die("SQL ERROR!!<br />". $AreaJudge[1].pg_last_error());
	$CountPoint[1] = pg_num_rows($ResPoint[1]);

	$AreaJudge[2] = "SELECT * FROM qgis.ts_terminal WHERE const_id = 9 AND NOT android_id ='7d0d4dc45397b57e' AND NOT point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1399385346,369000000),";
	$AreaJudge[2] .= "(1399385346,369100000),";
	$AreaJudge[2] .= "(1399385348,369000000),";
	$AreaJudge[2] .= "(1399385348,369100000))'";
	$AreaJudge[2] .= "AND NOT point(lon*10000000,lat*10000000) @ polygon '(";
	$AreaJudge[2] .= "(1399388303,369000000),";
	$AreaJudge[2] .= "(1399388303,369100000),";
	$AreaJudge[2] .= "(1399388305,369000000),";
	$AreaJudge[2] .= "(1399388305,369100000))'"; 
	$AreaJudge[2] .= " ORDER BY terminal_name;";

	$ResPoint[2] = pg_query($conn, $AreaJudge[2]) or die("SQL ERROR!!<br />". $AreaJudge[2].pg_last_error());
	$CountPoint[2] = pg_num_rows($ResPoint[2]);

	$AreaCount = count($AreaJudge);

	for($a = 0;$a < $AreaCount;$a++)
	{
		$row_ = array();
		for($h=0;$h < $CountPoint[$a];$h++)
		{
			$row_ = pg_fetch_array($ResPoint[$a],$h);
			if(!$Judge[$row_['terminal_name']]) $Judge[$row_['terminal_name']] = $a + 1;
			//print $row_['terminal_name'] ."<br>";
		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






	// ===============================================
	// 位置を取得する
	// 備考		:	
	// 更新		:	2012/11/29 KMK T.Teraoka
	// ===============================================
	$selTerm = "SELECT * FROM qgis.ts_terminal";
	$selTerm .= " WHERE const_id='". $CONST_ID. "'";
	$selTerm .= " AND app_id='". $APPLICATION_ID. "'";
	$selTerm .= " AND NOT terminal_name = 'haneda_test'";
//	$selTerm .= " AND android_id='17ce47ebbb69e091'";
//	$selTerm .= " OR android_id='2550f5978ffbcca7'";
//	$selTerm .= " OR android_id='444117a90e1f3a0'";
//	$selTerm .= " OR android_id='62f9075986d6b0e7'";
//	$selTerm .= " ORDER BY android_id";
	$selTerm .= " ORDER BY terminal_name";

	$selTerm .= ";";
	$mLog->writeLog($selTerm. "\n");
	if (!($resTerm = pg_query($conn, $selTerm)))
	{
		throw new Exception("データ取得に失敗<br />". $resTerm. "<br />". pg_last_error(). "<br />");
	}
	
	$row = pg_num_rows($resTerm);
	
	for($iCount = 0; $iCount < $row; $iCount++)
	{
		$rowTerm = pg_fetch_array($resTerm, $iCount, PGSQL_ASSOC);
		
		if (0 != strcmp($rowTerm["lat"], "") && 0 != strcmp($rowTerm["lon"], ""))
		{
			// ■
			// 座標変換
			//$lon = 139.7917966;
			//$lat =  35.5407766;
			//$local = cPos2Loc::convert($lat, $lon);
			
			
			//print $iCount. ",";
			switch($iCount)
			{
			case 0:
				$rowTerm["lat"] = "35.551515";
				$rowTerm["lon"] = "139.793429";
				break;
			case 1:
				$rowTerm["lat"] = "35.566020";
				$rowTerm["lon"] = "139.771083";
				break;
//			case 2:
//				$rowTerm["lat"] = "35.5336";
//				$rowTerm["lon"] = "139.793306";
//				break;
			case 2:
				$rowTerm["lat"] = "35.533667";
				$rowTerm["lon"] = "139.79327";
				break;
			case 3:
				$rowTerm["lat"] = "35.534515";
				$rowTerm["lon"] = "139.793003";
				break;
			default:
				continue;
			}
			
			
			$local = cPos2Loc::convert($rowTerm["lat"], $rowTerm["lon"]);
			$hanedaLoc = array();
			$hanedaLoc["0"] = $local["0"] - 738.0151;
			$hanedaLoc["1"] = $local["1"] +1092.2038;
			
			$hanedaLoc2 = array();
			$hanedaLoc2["0"] = 2000 + ($hanedaLoc["0"] * cos($angle)) - ($hanedaLoc["1"] * sin($angle));
			$hanedaLoc2["1"] = 2000 + ($hanedaLoc["1"] * cos($angle)) + ($hanedaLoc["0"] * sin($angle));
			
			$posX = ($hanedaLoc2["1"] - $ltLon) / $spX + $ltX;
			$posY = ($ltLat - $hanedaLoc2["0"]) / $spY + $ltY;
			
			// 現在位置の描画
			/*
			switch($iCount % 4)
			{
			case 0:
				$col = imagecolorallocate($img, 255, 0, 0);
				break;
			case 1:
				$col = imagecolorallocate($img, 250, 100, 0);
				break;
			case 2:
				$col = imagecolorallocate($img, 0, 100, 255);
				break;
			case 3:
				$col = imagecolorallocate($img, 0, 255, 0);
				break;
			}
			*/
			
			switch($Judge[$rowTerm["terminal_name"]])
			{
				case 1:
					$col = imagecolorallocate($img, 0, 0, 255);
					break;

				case 2:
					$col = imagecolorallocate($img, 0, 128, 0);
					break;

				case 3:
					$col = imagecolorallocate($img, 255, 0, 0);
					break;

	    			default:
					$col = imagecolorallocate($img, 255, 255, 255);
			}
			
			$ellipSize = 8;
			//print $posX. ",". $posY;
			Imagefilledellipse($img, $posX, $posY, $ellipSize, $ellipSize, $col);
			if($Judge[$rowTerm["terminal_name"]] == 0) Imageellipse($img, $posX, $posY, $ellipSize, $ellipSize, $col);
			// 端末番号表示の吹き出し
			imagefilledrectangle($img, $posX + 5, $posY - 23, $posX + 22, $posY - 7, imagecolorallocate($img, 255, 255, 255));
			imagerectangle($img, $posX + 5, $posY - 23, $posX + 22, $posY - 7, imagecolorallocate($img, 0, 0, 0));
			
			//$sepName = substr($rowTerm["terminal_name"], 0, 3);
			
			$sepName = sprintf("%02d",$rowTerm["terminal_name"] - 150);
			
			imagettftext($img, 8, 0, $posX + 8, $posY - 11, imagecolorallocate($img, 0, 0, 0), $font1, mb_convert_encoding($sepName, "SJIS", "UTF8"));
		}
	}
	
	// ===============================================
	// 描画した画像を保存 & パレットを削除
	// 備考		:	
	// 更新		:	2010/09/08 KMK T.Teraoka
	// ===============================================
//	header('Content-Type: image/png');

//	imagepng($img, $imgFileName);
//	imagepng($img);
//	imagedestroy($img);
//	imagedestroy($src);
	
	/*
	//
	//===============================================
	//	一覧の取得
	//	備考		:	
	//	更新		:	2012/10/18 KMK-Teraoka
	//===============================================
	$selList = "SELECT * FROM qgis.ts_terminal";
	$selList .= " WHERE const_id='". $CONST_ID. "'";
	$selList .= " AND app_id='". $APPLICATION_ID. "'";
	$selTerm .= " AND android_id='17ce47ebbb69e091'";
	$selTerm .= " OR android_id='2550f5978ffbcca7'";
	$selTerm .= " OR android_id='444117a90e1f3a0'";
	$selTerm .= " OR android_id='62f9075986d6b0e7'";
	$selList .= " ORDER BY android_id";
	$selList .= ";";
	cDebug::dPrint($selList);
	if (!($resList = pg_query($conn, $selList)))
	{
		throw new DBException("一覧の取得に失敗<br />". $selList. "<br />". pg_last_error(). "<br />");
	}
	*/
	/*
	//===============================================
	//	一覧の表示
	//	備考		:	
	//	更新		:	2012/10/18 KMK-Teraoka
	//===============================================
	print "<table width=\"100%\" border=\"0\" bgcolor=\"#000000\" cellspacing=\"0\" cellpadding=\"0\">";
	print "<tr>";
	print "<td>";
	print "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\">";
	print "<tr bgcolor=\"#99CCFF\">";
	for($iCount = 0; $iCount < count($VIEW_LIST); $iCount++)
	{
		print "<th style=\"width:". $VIEW_LIST[$iCount]["width"]. ";height:25px;\">";
		print $VIEW_LIST[$iCount]["head"];
		print "</th>";
	}
	print "</tr>";
	
	for($iCount = 0; $iCount < pg_num_rows($resList); $iCount++)
	{
		$rowList = pg_fetch_array($resList, $iCount, PGSQL_ASSOC);
		print "<tr bgcolor=\"#FFFFFF\">";
		for($jCount = 0; $jCount < count($VIEW_LIST); $jCount++)
		{
			print "<td style=\"height:25px;\">";
			if (strcmp($rowList[$VIEW_LIST[$jCount]["object"]], "") != 0)
			{
				print $rowList[$VIEW_LIST[$jCount]["object"]];
			}
			else
			{
				print "&nbsp;";
			}
			print "</td>";
		}
		print "</tr>";
	}
	print "</table>";
	print "</td>";
	print "</tr>";
	print "</table>";
	*/


//var_dump($Judge);







	// ===============================================
	// 上で保存した画像を表示
	// 備考		:	
	// 更新		:	2010/09/08 KMK T.Teraoka
	// ===============================================
	print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">";
	print "<tr bgcolor=\"#FFFFFF\">";
//	print "<td align=\"left\">";
	print "<td >";	
//	print "<img src=\"". $imgFileName. "?t=$now_t\" galleryimg=\"no\" width=\"881\" height=\"590\">";
//	print "<img src=\"". $imgFileName. "?t=$now_t\" galleryimg=\"no\" width=\"755\" height=\"455\">";
	print "<IMG SRC='" .$imgFileName ."?t=" .time() ."' ALT='LiveCamera' name=imgToLoad onload='setTimeout(\"RefreshImg(" .$imgFileName .")\", 3000)' onerror='setTimeout(\"RefreshImg(" .$imgFileName .")\", 5000)' onabort='setTimeout(\"RefreshImg(" .$imgFileName .")\", 10000)' id=imgToLoad naturalsizeflag=0  width=\"755\" height=\"455\">";
	print "</td>";
	print "<td>";
	print "<table border=\"0\">";
	print "<tr><td  align=\"left\"  valign=\"top\" colspan=\"4\">";
	print "<font color=\"#0000FF\">●&nbsp;&nbsp;施工場所</font><br />";
	print "<font color=\"#008000\">●&nbsp;&nbsp;ヤード</font><br />";
	print "<font color=\"#FF0000\">●&nbsp;&nbsp;その他範囲内</font><br />";
	print "<font color=\"#000000\">◯&nbsp;&nbsp;通信なし</font><br />";
	print "<br />";
	print "<HR>";
	print "</td></tr>";
	print "<tr>";
	//print "<td align=\"left\" valign=\"top\">";
	for($iCount = 0; $iCount < $row; $iCount++)
	{
		$rowTerm = pg_fetch_array($resTerm, $iCount, PGSQL_ASSOC);
		if($iCount % 25 == 0)	print "<td align=\"left\" valign=\"top\">";
		$Data = sprintf("%02d", $rowTerm["terminal_name"] - 150);
		
		switch($Judge[$rowTerm["terminal_name"]])
		{
			case 1:
				print "<font color=\"#0000FF\">●</font>";
				break;

			case 2:
				print "<font color=\"#008000\">●</font>";
				break;

			case 3:
				print "<font color=\"#FF0000\">●</font>";
				break;

    			default:
				print "◯";
		}

		
		print $Data ."&nbsp;&nbsp;<br />";
		
		if(($iCount+1) % 25 == 0)	print "</td>";

	}
	print "</tr>";
	print "</table>";
	print "</td>";

	print "</tr>";
	print "</table>";

}
catch(Exception $exc)
{
	$mLog->writeLog($exc->getMessage(). "\n");
}
//sleep(3000);
//}



// 戻る
print "<br />";
print "<a href=\"./index.php\">戻る</a>";

//===============================================
//	Postgresql終了処理
//	備考		:	
//	更新		:	2012/10/19 KMK-Teraoka
//===============================================
pg_close($conn);

//===============================================
//	HTML終了処理
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
print "</body>";
print "</html>";

?>

PHP File Manager