File "terminals_regist.php"
Full path: /www/ansys/terminals/terminals_regist.php
File size: 5.8 KiB (5938 bytes)
MIME-type: text/x-php
Charset: utf-8
<?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/10/25 KMK-Teraoka
//===============================================
$HOST = "192.168.100.153";
$DB = "ansys";
$USER = "postgres";
$PASS = "am#71ZJ*";
$TERMINAL_TABLE = "apc_common.terminals";
$VIEW_LIST = array(
"0" => array("head" => "工事ID", "object" => "id", "type" => "0", "control" => "-"),
"1" => array("head" => "工事名称", "object" => "const_name", "type" => "1", "control" => "txtConstName"),
"2" => array("head" => "工事開始日時", "object" => "start_at", "type" => "2", "control" => "txtStartAt"),
"3" => array("head" => "工事終了日時", "object" => "end_at", "type" => "2", "control" => "txtEndAt"),
"4" => array("head" => "備考", "object" => "remarks", "type" => "1", "control" => "txtRemarks"),
"5" => array("head" => "更新日時", "object" => "upddatetime", "type" => "3", "control" => "-"),
);
$LOG_FILE = "./log/terminals_regist.log";
try
{
$_log = new Log($LOG_FILE);
//================================================
// データベース接続
// 備考 :
// 更新 : 2012/10/25 KMK-Teraoka
//================================================
$conn = pg_connect("
host = ". $HOST. "
dbname = ". $DB. "
user = ". $USER. "
password= ". $PASS. "
");
if (!$conn)
{
throw new Exception("データベースへの接続に失敗しました");
}
//===============================================
// POST、GETパラメータの受け取り
// 備考 :
// 更新 : 2012/10/25 KMK-Teraoka
//===============================================
if (DEBUG_MODE == 1)
{
extract($_POST);
extract($_GET);
Debug::writes($_POST);
}
$androidId = isset($_POST["android_id"]) ? htmlspecialchars($_POST["android_id"]) : "";
$androidVersion = isset($_POST["android_version"]) ? htmlspecialchars($_POST["android_version"]) : "";
$buildModel = isset($_POST["build_model"]) ? htmlspecialchars($_POST["build_model"]) : "";
$simStatus = isset($_POST["sim_status"]) ? htmlspecialchars($_POST["sim_status"]) : "";
if (strcmp($simStatus, "5") == 0)
{
$phoneNo = isset($_POST["phone_no"]) ? htmlspecialchars($_POST["phone_no"]) : "";
$simOperator = isset($_POST["sim_operator"]) ? htmlspecialchars($_POST["sim_operator"]) : "";
}
$remarks = isset($_POST["remarks"]) ? htmlspecialchars($_POST["remarks"]) : "";
$_log->write("ANDROID_ID->". $androidId. "\n");
$_log->write("ANDROID_VERSION->". $androidVersion. "\n");
$_log->write("BUILD_MODEL->". $buildModel. "\n");
$_log->write("SIM_STATUS->". $simStatus. "\n");
$_log->write("PHONE_NO->". $phoneNo. "\n");
$_log->write("SIM_OPERATOR->". $simOperator. "\n");
$_log->write("REMARKS->". $remarks. "\n");
if (strcmp($androidId, "") == 0 || strcmp($simStatus, "") == 0)
{
throw new Exception("登録条件を満たしていません");
}
//===============================================
// 登録済み端末であるか調べる
// 備考 :
// 更新 : 2012/10/25 KMK-Teraoka
//===============================================
$selChk = "SELECT count(*) as count FROM ". $TERMINAL_TABLE. "";
$selChk .= " WHERE android_id='". $androidId. "'";
$selChk .= " AND del_flg='f'";
$selChk .= ";";
if (!($resChk = pg_query($conn, $selChk)))
{
throw new Exception("データ登録に失敗しました\n". $selChk. "\n". pg_last_error());
}
$rowChk = pg_fetch_array($resChk, 0, PGSQL_ASSOC);
if (strcmp($rowChk["count"], "1") == 0)
{
$updFlg = 1;
}
//===============================================
// データベースへ登録、更新
// 備考 :
// 更新 : 2012/10/25 KMK-Teraoka
//===============================================
if ($updFlg != 1)
{
$insData = "INSERT INTO ". $TERMINAL_TABLE. "";
$insData .= " (android_id, android_version, model, sim_status, sim_operator, phone_no, remarks, del_flg, upddatetime, regdatetime)";
$insData .= " VALUES";
$insData .= " ('". $androidId. "', '". $androidVersion. "', '". $buildModel. "', '". $simStatus. "', '". $simOperator. "', '". $phoneNo. "', '". $remarks. "', 'f', current_timestamp, current_timestamp)";
$insData .= ";";
if (!($resData = pg_query($conn, $insData)))
{
throw new Exception("データ登録に失敗しました\n". $insData. "\n". pg_last_error());
}
}
else
{
$updData = "UPDATE ". $TERMINAL_TABLE. " SET";
$updData .= " android_version='". $androidVersion. "'";
$updData .= ", model='". $buildModel. "'";
$updData .= ", sim_status='". $simStatus. "'";
$updData .= ", sim_operator='". $simOperator. "'";
$updData .= ", phone_no='". $phoneNo. "'";
$updData .= ", remarks='". $remarks. "'";
$updData .= ", upddatetime=current_timestamp";
$updData .= " WHERE android_id='". $androidId. "'";
$updData .= ";";
if (!($resData = pg_query($conn, $updData)))
{
throw new Exception("データ更新に失敗しました\n". $updData. "\n". pg_last_error());
}
}
}
catch(Exception $exc)
{
$_log->write($exc->getMessage(). "\n");
}
//===============================================
// Postgresql終了処理
// 備考 :
// 更新 : 2012/10/19 KMK-Teraoka
//===============================================
pg_close($conn);
?>