File "sheet.php"

Full path: /www/ansys/qgis/004_iwakuni/output/sheet.php
File size: 7.46 KiB (7642 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

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

//===============================================
//	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 = 7;
$APPLICATION_ID = 13;

$CONST_NAME = "コンクリート品質管理システム -岩国飛行場(H23)駐機場(B)等舗装工事-";

//===============================================
//	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("このページを直接開くことはできません");
	$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の型式で入力して下さい");
	}
	
	//================================================
	//	日付をチェックする
	//	備考		:	
	//	更新		:	2013/06/17 KMK-Teraoka
	//================================================
	$targetDate = explode(",", date("Y,m,d", strtotime($txtYmd)));
	if (!checkdate($targetDate[1], $targetDate[2], $targetDate[0]))
		throw new Exception("存在しない日付です[". $targetDate[0]. "年". $targetDate[1]. "月". $targetDate[2]. "日]");
	
	$plsFname = $targetDate[0]. "年". $targetDate[1]. "月";
	
	//================================================
	//	データの読み込み
	//	備考		:	
	//	更新		:	2013/06/17 KMK-Teraoka
	//================================================
	$totalCount = 0;
	$contentsLength = 0;
	$outputArray = array();
	
	$selConcData = "SELECT * FROM qgis.quality_of_concrete";
	$selConcData .= " WHERE const_id='". $CONST_ID. "'";
	$selConcData .= " AND iptdatetime >= '". $dateY. "-". $dateM. "-". $dateD. " 00:00:00'";
	$selConcData .= " AND iptdatetime <= '". $dateY. "-". $dateM. "-". $dateD. " 23:59:59'";
	$selConcData .= " ORDER BY iptdatetime";
	$selConcData .= ";";
	//print $selConcData;
	if (!($resConcData = pg_query($conn, $selConcData)))
	{
		throw new Exception("データ取得に失敗<br />". $resConcData. "<br />". pg_last_error(). "<br />");
	}
	
	$totalCount = pg_num_rows($resConcData);
	for($iCount = 0; $iCount < $totalCount; $iCount++)
	{
		$rowConcData = pg_fetch_assoc($resConcData, $iCount);
		$outputArray[$iCount]["iptdatetime"] = $rowConcData["iptdatetime"];
		$outputArray[$iCount]["car_number"] = $rowConcData["car_number"];
		$outputArray[$iCount]["slump"] = $rowConcData["slump"];
		$outputArray[$iCount]["amount_air"] = $rowConcData["amount_air"];
		$outputArray[$iCount]["unit_water"] = $rowConcData["unit_water"];
		$outputArray[$iCount]["concrete_temp"] = $rowConcData["concrete_temp"];
		$outputArray[$iCount]["temperature"] = $rowConcData["temperature"];
		$outputArray[$iCount]["chloride_ion"] = $rowConcData["chloride_ion"];
	}
	
	//================================================
	//	データの出力
	//	備考		:	
	//	更新		:	2013/06/17 KMK-Teraoka
	//================================================
	$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("\"". "スランプ[cm]". "\"", "Shift-JIS", "UTF-8");
	$output .= ",";
	$output .= mb_convert_encoding("\"". "空気量[%]". "\"", "Shift-JIS", "UTF-8");
	$output .= ",";
	$output .= mb_convert_encoding("\"". "単位水量[kg/m3]". "\"", "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("\"". "塩化物イオン量[kg/m3]". "\"", "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]["car_number"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["slump"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["amount_air"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["unit_water"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["concrete_temp"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["temperature"]. "\"", "Shift-JIS", "UTF-8");
		$output .= ",";
		$output .= mb_convert_encoding("\"". $outputArray[$iCount]["chloride_ion"]. "\"", "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=\"". "./list_to_csv.php". "\" style=\"display:inline\">";
	print "<a href=\"javascript:topForm_2.submit()\">戻る</a>";
	print "</form>";
	print "<br />";
	print "</font>";
	
	print "</body>";
	print "</html>";
}
?>

PHP File Manager