File "output.php"
Full path: /www/ansys/rctm/002_hitachinaka/output/transport/output.php
File size: 9.24 KiB (9462 bytes)
MIME-type: text/x-php
Charset: utf-8
<?php
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
// 自動でクラスを参照する
// 関数名 : __autoload()
// 備考 : 参照先は./class/XXX.phpとする
// 更新 : 2013/03/12 KMK-Teraoka
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
function __autoload($className)
{
$fPath = "./class/" . str_replace("_", "/", $className) . ".php";
require_once $fPath;
}
function getSide($p_, $a_, $b_)
{
$x = "lon";
$y = "lat";
$exter = $p_[$x] * ($a_[$y] - $b_[$y]) + $a_[$x] * ($b_[$y] - $p_[$y]) + $b_[$x] * ($p_[$y] - $a_[$y]);
if (0 < $exter)
return 1;
else if (0 > $exter)
return -1;
else
return 0;
}
function insideArea($point_, $area_)
{
$totalSide = 0;
$linkNum = count($area_);
$bIndex = 0;
for($iCount = 0; $iCount < $linkNum; $iCount++)
{
if ($linkNum > $iCount + 1)
$bIndex = $iCount + 1;
else
$bIndex = 0;
$side = getSide($point_, $area_[$iCount], $area_[$bIndex]);
if ($side == 0)
return 1;
else
$totalSide += $side;
}
if (abs($totalSide) == $linkNum)
return 1;
return 0;
}
//===============================================
// CommonUtilities
// 備考 :
// 更新 : 2013/03/12 KMK-Teraoka
//===============================================
$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$LOG_FILE = "./log/output.log";
$CONST_ID = 6;
$APPLICATION_ID = 9;
$HIS_TABLE = "qgis.ts_his_measure";
$CONST_NAME = "東京湾中央防波堤外側地区航路・泊地(-16m)浚渫工事";
$COUNT_START_HI = "04:00";
$COUNT_END_HI = "21:00";
$FUNABASHI_ROUTE_LAT = 35.59561081;
$FUNABASHI_ROUTE_LON = 139.9843314;
$COUNT_AREA = array(
array("lat" => 35.62678039, "lon" => 140.0013295),
array("lat" => 35.63562604, "lon" => 140.0137459),
array("lat" => 35.62880063, "lon" => 140.0254795),
array("lat" => 35.62017771, "lon" => 140.0109185)
);
// Debug
//$COUNT_AREA = array(
// array("lat" => 35.585232, "lon" => 139.804459),
// array("lat" => 35.581812, "lon" => 139.800081),
// array("lat" => 35.579438, "lon" => 139.804716),
// array("lat" => 35.582580, "lon" => 139.808836)
//);
$LADING = 1500;
//===============================================
// DEBUG_MODE
// 備考 :
// 更新 : 2013/03/12 KMK-Teraoka
//===============================================
define("DEBUG_MODE", "0");
Debug::setMode(DEBUG_MODE);
try
{
//================================================
// データベース接続
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$conn = pg_connect("
host = ". $HOST. "
dbname = ". $DB. "
user = ". $USER. "
password= ". $PASS. "
");
if (!$conn)
throw new Exception("データベースへの接続に失敗しました");
//================================================
// パラメータの取得
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$btnPrint = isset($_POST["btnPrint"]) ? htmlspecialchars($_POST["btnPrint"]) : "";
if (strcmp($btnPrint, "csv出力") != 0)
throw new Exception("このページを直接開くことはできません");
$txtTargetM = isset($_POST["txtTargetM"]) ? htmlspecialchars($_POST["txtTargetM"]) : "";
if (strcmp($txtTargetM, "") == 0)
throw new Exception("月が指定されていません");
$txtTargetD = isset($_POST["txtTargetD"]) ? htmlspecialchars($_POST["txtTargetD"]) : "";
if (strcmp($txtTargetD, "") == 0)
throw new Exception("日が指定されていません");
//================================================
// 日付をチェックする
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$targetDate = explode(",", date("Y,". $txtTargetM. ",". $txtTargetD. "", time()));
if (!checkdate($targetDate[1], $targetDate[2], $targetDate[0]))
throw new Exception("存在しない日付です[". $targetDate[0]. "年". $targetDate[1]. "月". $targetDate[2]. "日]");
$startDate = $targetDate[0]. "-". $targetDate[1]. "-". $targetDate[2]. " ". $COUNT_START_HI. ":00";
$endDate = $targetDate[0]. "-". $targetDate[1]. "-". $targetDate[2]. " ". $COUNT_END_HI. ":00";
$plsFname = $targetDate[1]. "月". $targetDate[2]. "日";
//================================================
// 船名を取得
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$id2ShipName = array();
$selectShipName = "SELECT android_id, terminal_name FROM qgis.ts_terminal";
$selectShipName .= " WHERE const_id='". $CONST_ID. "'";
$selectShipName .= " AND app_id='". $APPLICATION_ID. "'";
$selectShipName .= ";";
if (!($resShipname = pg_query($conn, $selectShipName)))
throw new Exception("データ取得に失敗<br />". $resShipname. "<br />". pg_last_error(). "<br />");
$row = pg_num_rows($resShipname);
for($iCount = 0; $iCount < $row; $iCount++)
{
$rowShipName = pg_fetch_assoc($resShipname, $iCount);
$id2ShipName[$rowShipName["android_id"]] = $rowShipName["terminal_name"];
}
//================================================
// データの読み込み
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$totalCount = 0;
$contentsLength = 0;
$outputArray = array();
$selectHis = "SELECT android_id, lat, lon, mesdatetime FROM ". $HIS_TABLE. "";
$selectHis .= " WHERE const_id='". $CONST_ID. "'";
$selectHis .= " AND app_id='". $APPLICATION_ID. "'";
$selectHis .= " AND mesdatetime >= '". $startDate. "'";
$selectHis .= " AND mesdatetime <= '". $endDate. "'";
$selectHis .= " AND android_id != '2acd01dea6f08879'";
$selectHis .= " AND android_id != 'a237b48012d8873e'";
$selectHis .= " AND android_id != '26f784b2293665d0'";
$selectHis .= " ORDER BY android_id, mesdatetime";
$selectHis .= ";";
if (!($resHis = pg_query($conn, $selectHis)))
{
throw new Exception("データ取得に失敗<br />". $resHis. "<br />". pg_last_error(). "<br />");
}
$alon = "";
$routePass = 0;
$row = pg_num_rows($resHis);
for($iCount = 0; $iCount < $row; $iCount++)
{
$rowHis = pg_fetch_assoc($resHis, $iCount);
if ($routePass == 0)
{
if ($rowHis["lon"] >= $FUNABASHI_ROUTE_LON && $alon < $FUNABASHI_ROUTE_LON)
{
$routePass = 1;
}
}
if ($routePass == 1)
{
if (insideArea(array("lat" => $rowHis["lat"], "lon" => $rowHis["lon"]), $COUNT_AREA) == 1)
{
$outputArray[$totalCount]["mesdatetime"] = $rowHis["mesdatetime"];
$outputArray[$totalCount]["shipname"] = $id2ShipName[$rowHis["android_id"]];
$totalCount++;
$routePass = 0;
}
}
$alon = $rowHis["lon"];
}
//================================================
// データの出力
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
usort($outputArray, create_function('$a,$b', 'return(strtotime($a[\'mesdatetime\']) > strtotime($b[\'mesdatetime\']));'));
$output = "";
$output .= mb_convert_encoding("\"". $CONST_NAME. "\"", "Shift-JIS", "UTF-8");
$output .= "\r\n";
$output .= mb_convert_encoding("\"". $targetDate[0]. "年". $targetDate[1]. "月". $targetDate[2]. "日". "\"", "Shift-JIS", "UTF-8");
$output .= "\r\n";
$output .= mb_convert_encoding("\"". "No". "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". "時刻". "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". "船舶名". "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". "積載". "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". "日合計". "\"", "Shift-JIS", "UTF-8");
$output .= "\r\n";
for($iCount = 0; $iCount < $totalCount; $iCount++)
{
$output .= mb_convert_encoding("\"". ($iCount + 1). "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $outputArray[$iCount]["mesdatetime"]. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $outputArray[$iCount]["shipname"]. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $LADING. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". ($LADING * ($iCount + 1)). "\"", "Shift-JIS", "UTF-8");
$output .= "\r\n";
}
if (DEBUG_MODE == 0)
{
$length = mb_strlen($output);
header("Content-Type: application/octet-stream");
header("Content-Disposition: inline; filename=\"". mb_convert_encoding("運搬帳票_". $plsFname.".csv", "Shift-JIS", "UTF-8"). "\"");
header("Content-Length: ". $length. "");
header("Pragma:no-cache");
header("Cache-Control:nocache");
print $output;
}
else
{
print $output;
}
}
catch(Exception $exc)
{
print "<html>";
print "<head>";
print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";
print "<title>". "船舶位置管理システム -運搬帳票ダウンロード-". "</title>";
print "</head>";
print "<body>";
print "<font color=\"#FF0000\">";
print "【スクリプトエラー】<br />";
print $exc->getMessage(). "<br />";
print "</font>";
print "<font size=\"3\">";
print "<form name=\"topForm_2\" method=\"post\" action=\"". "../../index.php". "\" style=\"display:inline\">";
print "<a href=\"javascript:topForm_2.submit()\">トップ画面へ戻る</a>";
print "</form>";
print "<br />";
print "</font>";
print "</body>";
print "</html>";
}
?>