<?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");
Debug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
	Stopwatch::start();
}

//===============================================
//	CommonUtilities
//	備考		：	
//	更新		：	2012/11/27 KMK-Teraoka
//===============================================
$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$CONSTRUCTION_ID= "7";

print "<!DOCTYPE html>";
print "<html>";
print "<head>";
print "<meta charset=\"utf-8\">";
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/ansys/common/css/style.css\">";
print "<link rel=\"shortcut icon\" href=\"/ansys/common/favicon/favicon.ico\">";
print "<title>";
print "品質項目入力";
print "</title>";
print "</head>";
print "<body>";
try
{
	//================================================
	//	データベース接続
	//	備考		：	
	//	更新		：	2012/11/27 KMK-Teraoka
	//================================================
	$conn = pg_connect("
		host	=	". $HOST. "
		dbname	=	". $DB. "
		user	=	". $USER. "
		password=	". $PASS. "
	");
	if (!$conn)
	{
		throw new Exception("データベースへの接続に失敗しました");
	}
	
	//===============================================
	//	POST、GETパラメータの受け取り
	//	備考		：	
	//	更新		：	2012/11/27 KMK-Teraoka
	//===============================================
	if (DEBUG_MODE == 1)
	{
		extract($_POST);
		extract($_GET);
		Debug::writes($_POST);
	}
	$btnRegist = isset($_POST["btnRegist"]) ? htmlspecialchars($_POST["btnRegist"]) : "";
	if (strcmp($btnRegist, "登録") == 0)
	{
		$txtYmd = isset($_POST["txtYmd"]) ? htmlspecialchars($_POST["txtYmd"]) : "";
		if (mb_strlen($txtYmd) == 8)
		{
			$dateY = substr($txtYmd, 0, 4);
			$dateM = substr($txtYmd, 4, 2);
			$dateD = substr($txtYmd, 6, 2);
		}
		else
		{
			throw new Exception("年月日はYYYYmmddの型式で入力して下さい");
		}
		$txtHi = isset($_POST["txtHi"]) ? htmlspecialchars($_POST["txtHi"]) : "";
		if (mb_strlen($txtHi) == 4)
		{
			$dateH = substr($txtHi, 0, 2);
			$dateI = substr($txtHi, 2, 2);
		}
		else
		{
			throw new Exception("時分はHHiiの型式で入力して下さい");
		}
		
		$txtCarNumber = isset($_POST["txtCarNumber"]) ? htmlspecialchars($_POST["txtCarNumber"]) : "";
		if (strcmp($txtCarNumber, "") == 0)
			throw new Exception("車番が指定されていません");
		
		$txtSlump = isset($_POST["txtSlump"]) ? htmlspecialchars($_POST["txtSlump"]) : "";
		
		$txtAmountAir = isset($_POST["txtAmountAir"]) ? htmlspecialchars($_POST["txtAmountAir"]) : "";
		
		$txtUnitWater = isset($_POST["txtUnitWater"]) ? htmlspecialchars($_POST["txtUnitWater"]) : "";
		
		$txtConcreteTemp = isset($_POST["txtConcreteTemp"]) ? htmlspecialchars($_POST["txtConcreteTemp"]) : "";
		
		$txtTemperature = isset($_POST["txtTemperature"]) ? htmlspecialchars($_POST["txtTemperature"]) : "";
		
		$txtChlorideIon = isset($_POST["txtChlorideIon"]) ? htmlspecialchars($_POST["txtChlorideIon"]) : "";
		
		
		// データベース登録
		$insConcData = "INSERT INTO qgis.quality_of_concrete";
		$insConcData .= "(const_id, upddatetime, regdatetime, iptdatetime, car_number, slump, amount_air, unit_water, concrete_temp, temperature, chloride_ion)";
		$insConcData .= " VALUES (";
		$insConcData .= "'". $CONSTRUCTION_ID. "'";
		$insConcData .= ", current_timestamp";
		$insConcData .= ", current_timestamp";
		$insConcData .= ", '". $dateY. "-". $dateM. "-". $dateD. " ". $dateH. ":". $dateI. ":00". "'";
		$insConcData .= ", '". $txtCarNumber. "'";
		$insConcData .= ", '". $txtSlump. "'";
		$insConcData .= ", '". $txtAmountAir. "'";
		$insConcData .= ", '". $txtUnitWater. "'";
		$insConcData .= ", '". $txtConcreteTemp. "'";
		$insConcData .= ", '". $txtTemperature. "'";
		$insConcData .= ", '". $txtChlorideIon. "'";
		$insConcData .= ");";
		
		//print $insConcData;
		$resConcData = pg_query($conn, $insConcData);
		print "<font color=\"red\">登録しました</font>";
	}
	if (strcmp($txtYmd, "") == 0)
		$txtYmd = date("Ymd");
	if (strcmp($txtHi, "") == 0)
		$txtHi = date("Hi");
	if (strcmp($txtSlump, "") == 0)
		$txtSlump = "";
	if (strcmp($txtAmountAir, "") == 0)
		$txtAmountAir = "";
	if (strcmp($txtUnitWater, "") == 0)
		$txtUnitWater = "";
	if (strcmp($txtConcreteTemp, "") == 0)
		$txtConcreteTemp = "";
	if (strcmp($txtTemperature, "") == 0)
		$txtTemperature = "";
	if (strcmp($txtChlorideIon, "") == 0)
		$txtChlorideIon = "";
	//===============================================
	//	表示部分
	//	備考		：	
	//	更新		：	2013/08/01 KMK-Teraoka
	//===============================================
	print "<center><b>品質管理項目</b></center>";
	print "<hr />";
	
	print "<form action=\"". $_SERVER["PHP_SELF"]. "\" method=\"post\" style=\"display:inline\">";
	
	print "<table border=\"0\">";
		print "<tr>";
			print "<td>日付</td>";
			print "<td>時刻</td>";
		print "</tr>";
		
		print "<tr>";
			print "<td><input type=\"text\" name=\"txtYmd\" value=\"". $txtYmd. "\" maxlength=\"8\" style=\"ime-mode:disabled;width:60px;\"></td>";
			print "<td><input type=\"text\" name=\"txtHi\" value=\"". $txtHi. "\" maxlength=\"4\" style=\"ime-mode:disabled;width:30px;\"></td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">車番</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtCarNumber\" value=\"". $txtCarNumber. "\" maxlength=\"4\" style=\"ime-mode:disabled;width:60px\"></td>";
		print "</tr>";
		print "<tr style=\"height:4px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">・スランプ</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtSlump\" value=\"". $txtSlump. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;cm</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">・空気量</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtAmountAir\" value=\"". $txtAmountAir. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;%</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">・単位水量</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtUnitWater\" value=\"". $txtUnitWater. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;kg/㎥</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		//temperature
		print "<tr>";
			print "<td colspan=\"2\">・コンクリート温度</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtConcreteTemp\" value=\"". $txtConcreteTemp. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;℃</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">・外気温</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtTemperature\" value=\"". $txtTemperature. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;℃</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
		
		print "<tr>";
			print "<td colspan=\"2\">・塩化物イオン量</td>";
		print "</tr>";
		print "<tr>";
			print "<td colspan=\"2\"><input type=\"text\" name=\"txtChlorideIon\" value=\"". $txtChlorideIon. "\" style=\"ime-mode:disabled;width:90px\">&nbsp;kg/㎥</td>";
		print "</tr>";
		print "<tr style=\"height:2px;\"></tr>";
	print "</table>";
	
	print "<input type=\"submit\" name=\"btnRegist\" value=\"登録\" id=\"submit_button\">";
	print "</form>";
	
	print "</body>";
}
catch(Exception $exc)
{
	print "<font color=\"#FF0000\">";
	print "【スクリプトエラー】<br />";
	print $exc->getMessage(). "<br />";
	print "</font>";
	
	print "<br />";
	
	print "<a href=\"". $_SERVER["PHP_SELF"]. "\">戻る</a>";
}

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

print "</body>";
print "</html>";
?>
