File "history.php"

Full path: /www/ansys/rctm/002_hitachinaka_2/map/history.php
File size: 14.13 KiB (14471 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php

function retShipSimbol($point_, $direction_, $mapDegree_)
{
	$ret = -1;
	if ($direction_ == -1)
		return -1;
	
	$ret = array();
	$ret[0]["x"] = $point_["x"];
	$ret[0]["y"] = $point_["y"];
	
	$ret[1]["x"] = floor($point_["x"] + (25 * cos(deg2rad($direction_ - 90 - $mapDegree_))));
	$ret[1]["y"] = floor($point_["y"] + (25 * sin(deg2rad($direction_ - 90 - $mapDegree_))));
	
	$ret[2]["x"] = floor($point_["x"] + (12 * cos(deg2rad($direction_ - 90 - $mapDegree_))));
	$ret[2]["y"] = floor($point_["y"] + (12 * sin(deg2rad($direction_ - 90 - $mapDegree_))));
	
	$ret[3]["x"] = floor($point_["x"] + (8 * cos(deg2rad($direction_ - 90 + 120 - $mapDegree_))));
	$ret[3]["y"] = floor($point_["y"] + (8 * sin(deg2rad($direction_ - 90 + 120 - $mapDegree_))));
	
	$ret[4]["x"] = floor($point_["x"] + (8 * cos(deg2rad($direction_ - 90 - 120 - $mapDegree_))));
	$ret[4]["y"] = floor($point_["y"] + (8 * sin(deg2rad($direction_ - 90 - 120 - $mapDegree_))));
	
	return $ret;
}

function deleteFile($dir)
{
	if (!$handle=opendir($dir))
		return;
	while($filename=readdir($handle))
	{
		if(!preg_match("/^\./", $filename))
		{
			if (!unlink("$dir/$filename"));
			return;
		}
	}
}


//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//	自動でクラスを参照する
//	関数名	:	__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");
Debug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
	Stopwatch::start();
}

//===============================================
//	CommonUtilities
//	備考		:	
//	更新		:	2012/11/29 KMK-Teraoka
//===============================================
$SCRIPT_TITLE = "船舶位置管理システム -船舶航行履歴確認-";
$PENTA_OCEAN = "五洋・大本特定建設工事共同企業体";
$TAIL_PENTA_OCEAN = "penta-ocean";

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

$CONST_ID = 6;
$APPLICATION_ID = 9;
$MAP_NAME = "./scmap/orig.png";
$ZOOM_MAP_DEGREE = 36.029;

//===============================================
//	POST or GET 取得
//	備考		:	
//	更新		:	2013/06/17 KMK-Teraoka
//===============================================
$btnSearch = isset($_POST["btnSearch"]) ? htmlspecialchars($_POST["btnSearch"]) : "";
$selTerminal = isset($_POST["selTerminal"]) ? htmlspecialchars($_POST["selTerminal"]) : "";

$txtStartY = isset($_POST["txtStartY"]) ? htmlspecialchars($_POST["txtStartY"]) : "";
$txtStartM = isset($_POST["txtStartM"]) ? htmlspecialchars($_POST["txtStartM"]) : "";
$txtStartD = isset($_POST["txtStartD"]) ? htmlspecialchars($_POST["txtStartD"]) : "";
$txtStartH = isset($_POST["txtStartH"]) ? htmlspecialchars($_POST["txtStartH"]) : "";
$txtStartI = isset($_POST["txtStartI"]) ? htmlspecialchars($_POST["txtStartI"]) : "";
$startDatetime = $txtStartY. "-". $txtStartM . "-". $txtStartD. " ". $txtStartH. ":". $txtStartI. ":". "00";

$txtEndY = isset($_POST["txtEndY"]) ? htmlspecialchars($_POST["txtEndY"]) : "";
$txtEndM = isset($_POST["txtEndM"]) ? htmlspecialchars($_POST["txtEndM"]) : "";
$txtEndD = isset($_POST["txtEndD"]) ? htmlspecialchars($_POST["txtEndD"]) : "";
$txtEndH = isset($_POST["txtEndH"]) ? htmlspecialchars($_POST["txtEndH"]) : "";
$txtEndI = isset($_POST["txtEndI"]) ? htmlspecialchars($_POST["txtEndI"]) : "";
$endDatetime = $txtEndY. "-". $txtEndM . "-". $txtEndD. " ". $txtEndH. ":". $txtEndI. ":". "00";

//===============================================
//	HTML-HEAD-
//	備考		:	
//	更新		:	2012/10/18 KMK-Teraoka
//===============================================
print "<html>";
print "<head>";
print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/ansys/config/css/style.css\">";
print "<link rel=\"shortcut icon\" href=\"/ansys/config/favicon.ico\">";
print "<title>". $SCRIPT_TITLE. "</title>";
print "</head>";

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

print "<center>";
print "<font size=\"3\">";
print "<b>";
print "". $SCRIPT_TITLE. "<br>";
print "</b>";
print "</font>";
print "</center>";

try
{
	// tmpディレクトリ内のファイルを削除
	deleteFile("./tmp");
	
	$_log = new Log($LOG_FILE);
	
	//================================================
	//	データベース接続
	//	備考		:	
	//	更新		:	2012/11/29 KMK-Teraoka
	//================================================
	$conn = pg_connect("
		host	=	". $HOST. "
		dbname	=	". $DB. "
		user	=	". $USER. "
		password=	". $PASS. "
	");
	if (!$conn)
	{
		throw new Exception("データベースへの接続に失敗しました");
	}
	
	if (strcmp($btnSearch, "検索") == 0)
	{
		// ===============================================
		// 画像情報の取得
		// 備考		:	
		// 更新		:	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]);
		
		// ===============================================
		// 基準点情報
		// 備考		:	
		// 更新		:	2012/11/29 KMK-Teraoka
		// ===============================================
		$ltLon = 139.793416;						//経度(左上)
		$ltLat =  35.592797;						//緯度(左上)
		$rbLon = 139.981100;						//経度(右下)
		$rbLat =  35.666697;						//緯度(右下)
		
		$ltX =  149;								// 左上X座標
		$ltY =  486;								// 左上Y座標
		$rbX = 1010;								// 右下X座標
		$rbY =   71;								// 右下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座標の倍率を求める
		
		// ===============================================
		// 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);
		
		// ===============================================
		// 位置を取得する
		// 備考		:	
		// 更新		:	2012/11/29 KMK T.Teraoka
		// ===============================================
		$selTermName = "SELECT terminal_name FROM qgis.ts_terminal";
		$selTermName .= " WHERE const_id='". $CONST_ID. "'";
		$selTermName .= " AND app_id='". $APPLICATION_ID. "'";
		$selTermName .= " AND android_id='". $selTerminal. "'";
		$selTerm .= ";";
		if (!($resTermName = pg_query($conn, $selTermName)))
		{
			throw new Exception("データ取得に失敗<br />". $resTerm. "<br />". pg_last_error(). "<br />");
		}
		$rowTermName = pg_fetch_array($resTermName, 0, PGSQL_ASSOC);
		$terminalName = $rowTermName["terminal_name"];
		
		
		$selHisTerm = "SELECT * FROM qgis.ts_his_measure";
		$selHisTerm .= " WHERE const_id='". $CONST_ID. "'";
		$selHisTerm .= " AND app_id='". $APPLICATION_ID. "'";
		$selHisTerm .= " AND android_id='". $selTerminal. "'";
		$selHisTerm .= " AND mesdatetime >= '". $startDatetime. "'";
		$selHisTerm .= " AND mesdatetime <= '". $endDatetime. "'";
		$selHisTerm .= " ORDER BY mesdatetime";
		$selHisTerm .= ";";
		if (!($resHisTerm = pg_query($conn, $selHisTerm)))
		{
			throw new Exception("データ取得に失敗<br />". $resHisTerm. "<br />". pg_last_error(). "<br />");
		}
		$shipCol = imagecolorallocate($img, 255, 165, 0);
		
		$baseUtcSec = "";
		$writeDateFlag = 0;
		
		$row = pg_num_rows($resHisTerm);
		for($iCount = 0; $iCount < $row; $iCount++)
		{
			$rowHisTerm = pg_fetch_array($resHisTerm, $iCount, PGSQL_ASSOC);
			
			if ($iCount == 0)
			{
				$baseUtcSec = strtotime($rowHisTerm["mesdatetime"]);
				$writeDateFlag = 1;
			}
			else
			{
				if ((strtotime($rowHisTerm["mesdatetime"]) - $baseUtcSec) > 900)
				{
					$baseUtcSec = strtotime($rowHisTerm["mesdatetime"]);
					$writeDateFlag = 1;
				}
			}
			if (0 != strcmp($rowHisTerm["lat"], "") && 0 != strcmp($rowHisTerm["lon"], ""))
			{
				$point = array();
				$point["x"] = ($rowHisTerm["lon"] - $ltLon) / $spX + $ltX;
				$point["y"] = ($ltLat - $rowHisTerm["lat"]) / $spY + $ltY;
				if ($iCount < $row - 1)
				{
					$ellipSize = 1;
					imagefilledellipse($img, $point["x"], $point["y"], $ellipSize, $ellipSize, $shipCol);
				}
				else
				{
					$shipSimbol = retShipSimbol($point, $rowHisTerm["direction"], 0);
					if ($shipSimbol == -1)
					{
						$ellipSize = 8;
						imagefilledellipse($img, $point["x"], $point["y"], $ellipSize, $ellipSize, $shipCol);
					}
					else
					{
						imageline($img, $shipSimbol[0]["x"], $shipSimbol[0]["y"], $shipSimbol[1]["x"], $shipSimbol[1]["y"], $shipCol);
						imageline($img, $shipSimbol[2]["x"], $shipSimbol[2]["y"], $shipSimbol[3]["x"], $shipSimbol[3]["y"], $shipCol);
						imageline($img, $shipSimbol[3]["x"], $shipSimbol[3]["y"], $shipSimbol[4]["x"], $shipSimbol[4]["y"], $shipCol);
						imageline($img, $shipSimbol[4]["x"], $shipSimbol[4]["y"], $shipSimbol[2]["x"], $shipSimbol[2]["y"], $shipCol);
					}
					$length = strlen($terminalName);
					imagefilledrectangle($img, $point["x"] + 5, $point["y"] - 45, $point["x"] + 5 + ($length * 8), $point["y"] - 22, $White);
					imagerectangle($img, $point["x"] + 5, $point["y"] - 45, $point["x"] + 5 + ($length * 8), $point["y"] - 22, $shipCol);
					ImageTTFText($img, 12, 0, $point["x"] + 15, $point["y"] - 27, $Black, $font1, $terminalName);
				}
				if ($writeDateFlag == 1)
				{
					$viewTime = explode(" ", $rowHisTerm["mesdatetime"]);
					$length = strlen($viewTime[1]);
					imagefilledrectangle($img, $point["x"] + 5, $point["y"] - 45, $point["x"] + 5 + ($length * 8), $point["y"] - 22, $White);
					imagerectangle($img, $point["x"] + 5, $point["y"] - 45, $point["x"] + 5 + ($length * 8), $point["y"] - 22, $shipCol);
					ImageTTFText($img, 12, 0, $point["x"] + 6, $point["y"] - 27, $Black, $font1, $viewTime[1]);
					
					$writeDateFlag = 0;
				}
			}
		}
		
		// ===============================================
		// 描画した画像を保存 & パレットを削除
		// 備考		:	
		// 更新		:	2010/09/08 KMK T.Teraoka
		// ===============================================
		imagepng($img, $imgFileName);
		imagedestroy($img);
		imagedestroy($src);
		
		// ===============================================
		// 上で保存した画像を表示
		// 備考		:	
		// 更新		:	2010/09/08 KMK T.Teraoka
		// ===============================================
		print "<img src=\"". $imgFileName. "?t=$now_t\" galleryimg=\"no\" width=\"881\" height=\"590\">";
		}
	else
	{
		$startSec = 3600;
		$startDate = explode(",", date("Y,m,d,H,i,s", time() - $startSec));
		$endDate = explode(",", date("Y,m,d,H,i,s", time()));
		
		print "<form action=\"". $_SERVER['PHP_SELF']. "\" method=\"post\" style=\"display:inline\">";
		
		print "開始&nbsp;";
		print "<input type=\"text\" name=\"txtStartY\" value=\"". $startDate["0"]. "\" style=\"width:30px\">&nbsp;年";
		print "&nbsp;<input type=\"text\" name=\"txtStartM\" value=\"". $startDate["1"]. "\" style=\"width:20px\">&nbsp;月";
		print "&nbsp;<input type=\"text\" name=\"txtStartD\" value=\"". $startDate["2"]. "\" style=\"width:20px\">&nbsp;日";
		print "&nbsp;<input type=\"text\" name=\"txtStartH\" value=\"". $startDate["3"]. "\" style=\"width:20px\">&nbsp;時";
		print "&nbsp;<input type=\"text\" name=\"txtStartI\" value=\"". $startDate["4"]. "\" style=\"width:20px\">&nbsp;分";
		
		print "<br />";
		print "終了&nbsp;";
		print "<input type=\"text\" name=\"txtEndY\" value=\"". $endDate["0"]. "\" style=\"width:30px\">&nbsp;年";
		print "&nbsp;<input type=\"text\" name=\"txtEndM\" value=\"". $endDate["1"]. "\" style=\"width:20px\">&nbsp;月";
		print "&nbsp;<input type=\"text\" name=\"txtEndD\" value=\"". $endDate["2"]. "\" style=\"width:20px\">&nbsp;日";
		print "&nbsp;<input type=\"text\" name=\"txtEndH\" value=\"". $endDate["3"]. "\" style=\"width:20px\">&nbsp;時";
		print "&nbsp;<input type=\"text\" name=\"txtEndI\" value=\"". $endDate["4"]. "\" style=\"width:20px\">&nbsp;分";
		
		print "<br />";
		
		$selTerm = "SELECT * FROM qgis.ts_terminal";
		$selTerm .= " WHERE const_id='". $CONST_ID. "'";
		$selTerm .= " AND app_id='". $APPLICATION_ID. "'";
		$selTerm .= " ORDER BY terminal_name";
		$selTerm .= ";";
		if (!($resTerm = pg_query($conn, $selTerm)))
		{
			throw new Exception("データ取得に失敗<br />". $resTerm. "<br />". pg_last_error(). "<br />");
		}
		print "<select name=\"selTerminal\">";
		$row = pg_num_rows($resTerm);
		for($iCount = 0; $iCount < $row; $iCount++)
		{
			$rowTerm = pg_fetch_array($resTerm, $iCount, PGSQL_ASSOC);
			print "<option value=\"". $rowTerm["android_id"]. "\">". $rowTerm["terminal_name"]. "</option>";
		}
		print "</select>";
		print "<br />";
		print "<input type=\"submit\" name=\"btnSearch\" value=\"検索\">";
		print "</form>";
	}
}
catch(Exception $exc)
{
	$_log->write($exc->getMessage(). "\n");
}

// 戻る
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