File "sheet_shipping.php"
Full path: /www/ansys/qgis/004_iwakuni/output/sheet_shipping.php
File size: 9.04 KiB (9255 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 addWhere($now_, $add_)
{
$ret = "";
if (strcmp($now_, "") == 0)
$ret .= " WHERE ". $add_;
else
$ret .= $now_. " AND ". $add_;
return $ret;
}
//===============================================
// CommonUtilities
// 備考 :
// 更新 : 2013/03/12 KMK-Teraoka
//===============================================
$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$LOG_FILE = "./log/output.log";
$CONSTRUCTION_TABLE = "qgis.concrete_shipping_record";
$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
//================================================
if (DEBUG_MODE == 1)
{
extract($_POST);
extract($_GET);
Debug::writes($_POST);
}
$btnPrint = isset($_POST["btnPrint"]) ? htmlspecialchars($_POST["btnPrint"]) : "";
if (strcmp($btnPrint, "csv出力") != 0)
throw new Exception("このページを直接開くことはできません");
$txtSearchObj = isset($_POST["txtSearchObj"]) ? htmlspecialchars($_POST["txtSearchObj"]) : "";
$searchRecordDate = isset($_POST["searchRecordDate"]) ? htmlspecialchars($_POST["searchRecordDate"]) : "";
$fnamePls = "";
if (strcmp($searchRecordDate, "all") != 0)
$fnamePls = $searchRecordDate;
else
$fnamePls = "all_data";
$rdioSortRecordDate = isset($_POST["rdioSortRecordDate"]) ? htmlspecialchars($_POST["rdioSortRecordDate"]) : "";
if (strcmp($rdioSortRecordDate, "") == 0)
$rdioSortRecordDate = "降順";
//===============================================
// 端末名称の取得
// 備考 :
// 更新 : 2013/09/18 KMK-Teraoka
//===============================================
$terminals = array();
$selectTerminal = "SELECT android_id, terminal_name FROM qgis.ts_terminal";
$selectTerminal .= " WHERE const_id='". $CONST_ID. "'";
$selectTerminal .= " AND app_id='". $APPLICATION_ID. "'";
$selectTerminal .= " AND android_id!='d033ad24ea7c5d77'";
$selectTerminal .= " AND android_id!='198903985b36c4b2'";
$selectTerminal .= " AND android_id!='b606848df7aa45ce'";
$selectTerminal .= " AND android_id!='74b6c682dbe5c270'";
$selectTerminal .= " ORDER BY terminal_name";
$selectTerminal .= ";";
Debug::write($selectTerminal);
if (!($resTerminalName = pg_query($conn, $selectTerminal)))
{
throw new Exception("端末名称の取得に失敗<br />". $selectTerminal. "<br />". pg_last_error(). "<br />");
}
$numTerminalName = pg_num_rows($resTerminalName);
for($iCount = 0; $iCount < $numTerminalName; $iCount++)
{
$rowTerminalName = pg_fetch_array($resTerminalName, $iCount, PGSQL_ASSOC);
$terminals[$iCount]["android_id"] = $rowTerminalName["android_id"];
$terminals[$iCount]["terminal_name"] = $rowTerminalName["terminal_name"];
}
//===============================================
// WHERE句の作成
// 備考 :
// 更新 : 2012/10/18 KMK-Teraoka
//===============================================
$whereObj = "";
if (strcmp($searchRecordDate, "all") != 0)
{
$whereObj = addWhere($whereObj, "record_date >= '". $searchRecordDate. " 00:00:00'");
$whereObj = addWhere($whereObj, "record_date <= '". $searchRecordDate. " 23:59:59'");
}
if (strcmp($txtSearchObj, "") != 0)
{
$searchId = "";
for($iCount = 0; $iCount < $numTerminalName; $iCount++)
if (strcmp($txtSearchObj, $terminals[$iCount]["terminal_name"]) == 0)
$searchId = $terminals[$iCount]["android_id"];
$whereObj = addWhere($whereObj, "android_id='". $searchId. "'");
}
Debug::write($whereObj);
//===============================================
// ORDER句の作成
// 備考 :
// 更新 : 2012/10/18 KMK-Teraoka
//===============================================
if (strcmp($rdioSortRecordDate, "昇順") == 0)
$orderObj = " ORDER BY record_date ASC";
else
$orderObj = " ORDER BY record_date DESC";
//================================================
// データの読み込み
// 備考 :
// 更新 : 2013/09/24 KMK-Teraoka
//================================================
$totalCount = 0;
$contentsLength = 0;
$outputArray = array();
$selList = "SELECT * FROM ". $CONSTRUCTION_TABLE. "";
if (strcmp($whereObj, "") != 0)
{
$selList .= $whereObj;
}
if (strcmp($orderObj, "") != 0)
{
$selList .= $orderObj;
}
$selList .= ";";
Debug::write($selList);
if (!($resList = pg_query($conn, $selList)))
{
throw new Exception("一覧の取得に失敗<br />". $selList. "<br />". pg_last_error(). "<br />");
}
$totalCount = pg_num_rows($resList);
for($iCount = 0; $iCount < $totalCount; $iCount++)
{
$rowList = pg_fetch_assoc($resList, $iCount);
$outputArray[$iCount]["record_date"] = date("Y-m-d H:i", strtotime($rowList["record_date"]));
for($jCount = 0; $jCount < $numTerminalName; $jCount++)
if (strcmp($terminals[$jCount]["android_id"], $rowList["android_id"]) == 0)
$outputArray[$iCount]["terminal_name"] = $terminals[$jCount]["terminal_name"];
if (strcmp($rowList["status"], "1") == 0)
$outputArray[$iCount]["status"] = "出荷";
else
$outputArray[$iCount]["status"] = "搬入";
$outputArray[$iCount]["regdatetime"] = $rowList["regdatetime"];
}
//================================================
// データの出力
// 備考 :
// 更新 : 2013/06/17 KMK-Teraoka
//================================================
$output = "";
$output .= mb_convert_encoding("\"". $CONST_NAME. "\"", "Shift-JIS", "UTF-8");
$output .= "\r\n";
if (strcmp($searchRecordDate, "all") != 0)
$output .= mb_convert_encoding("\"". $targetDate[0]. "年". $targetDate[1]. "月". $targetDate[2]. "日". "\"", "Shift-JIS", "UTF-8");
else
$output .= mb_convert_encoding("\"". "**年". "**月". "**日". "\"", "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]["record_date"]. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $outputArray[$iCount]["terminal_name"]. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $outputArray[$iCount]["status"]. "\"", "Shift-JIS", "UTF-8");
$output .= ",";
$output .= mb_convert_encoding("\"". $outputArray[$iCount]["regdatetime"]. "\"", "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("コンクリート運搬記録_". $fnamePls. ".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/shipping_list.php". "\" style=\"display:inline\">";
print "<a href=\"javascript:topForm_2.submit()\">戻る</a>";
print "</form>";
print "<br />";
print "</font>";
print "</body>";
print "</html>";
}
?>