File "recv_r.php"
Full path: /www/haneda/qr/recv/recv_r.php
File size: 2.97 KiB (3046 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", "1");
cDebug::setMode(DEBUG_MODE);
if (DEBUG_MODE == 1)
{
cStopwatch::start();
}
$LOG_FILE = "./log/recv.log";
$mLog = new cLog($LOG_FILE);
$HOST = "192.168.100.153";
$DB = "pntdb";
$USER = "postgres";
$PASS = "am#71ZJ*";
$TABLE = "qr.work_data";
$REGISTRANT_TABLE = "qr.registrant_data";
$FILE_OUTPUT_PATH = "/www/haneda/qr/registrant.txt";
//================================================
// データベース接続
// 備考 :
// 更新 : 2012/10/19 KMK-Teraoka
//================================================
$conn = pg_connect("
host = ". $HOST. "
dbname = ". $DB. "
user = ". $USER. "
password= ". $PASS. "
");
extract($_GET['data']);
$data = isset($_GET['data']) ? htmlspecialchars($_GET['data']) : "";
$DATA = explode("," ,$data);
$mLog->writeLog($data. "\n");
//変数にデータをセット
$DataDate = substr($DATA[0],"0","4") ."-" .substr($DATA[0],"4","2") ."-" .substr($DATA[0],"6","2") ." " ."00:00:00";
$DataTimeZone = substr($DATA[0],"8","1");
$DataTimeZone = (!strcmp(substr($DATA[0],"8","1"),"A")) ? 0 : 1;
$DataRegistrant = urldecode($DATA[1]);
$INSERT = "INSERT INTO " .$TABLE ." (registrant_name, date, time_zone, work_flag, upddatetime, regdatetime) ";
$INSERT .= "VALUES (";
$INSERT .= "'" .$DataRegistrant ."'";
$INSERT .= "," ."'" .$DataDate ."'";
$INSERT .= "," .$DataTimeZone;
$INSERT .= "," ."0";
$INSERT .= "," ."current_timestamp ,current_timestamp";
$INSERT .= ")";
$res = pg_query($conn,$INSERT) OR DIE(pg_last_error() ."<BR>" .$INSERT);
//登録者が新規の場合、データベースに追加
$SELECT = "SELECT * FROM " .$REGISTRANT_TABLE ." WHERE name='" .$DataRegistrant ."'";
$res = pg_query($conn,$SELECT);
if(!pg_num_rows($res))
{
$insert = "INSERT INTO " .$REGISTRANT_TABLE ." (name,upddatetime, regdatetime)";
$insert .= " VALUES ('" .$DataRegistrant ."'," ."current_timestamp, current_timestamp)";
$res_i = pg_query($conn,$insert) or die(pg_last_error() .$insert ."<BR>");
$select = "SELECT * FROM " .$REGISTRANT_TABLE ;
$res = pg_query($conn,$select);
$fp = fopen($FILE_OUTPUT_PATH,"w");
for($i = 0;$i < pg_num_rows($res);$i++)
{
$row = pg_fetch_array($res,$i);
fwrite($fp,$row['name'] ."\n");
}
fclose($fp);
}
else
{
$select = "SELECT * FROM " .$REGISTRANT_TABLE ;
$res = pg_query($conn,$select);
$fp = fopen($FILE_OUTPUT_PATH,"w");
for($i = 0;$i < pg_num_rows($res);$i++)
{
$row = pg_fetch_array($res,$i);
fwrite($fp,$row['name'] ."\n");
}
fclose($fp);
}
?>