include("../inc/egg.config.php");
require_once("kzkey1.php");
extract($_POST);
$idmc = htmlspecialchars($_POST["idmc"]);
$kzkey = new Kidzo(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$kunci = "12ADx9522Xc";
$agen_id = $kzkey->decrypt($idmc, $kunci);
//$agen_id='1234';
if (!$format) {
$format = "xml";
}
$sql = "select * from tbl_agen_id where id='$agen_id' and status='Production'";
$sql1 = mysql_query($sql);
$rowdata = mysql_num_rows($sql1);
//tidak ada agen
if ($rowdata == "0") {
if ($format == "xml") {
ob_start();
header("Content-Type:text/xml");
echo "";
echo "
Unknown
";
ob_end_flush();
} else { //json
$sites = array();
$sites[] = array('nama_merchant' => "Unknown");
echo json_encode($sites);
}
$respons = "Merchant Unknown";
} else { //Jika ada nama agen terdaftar
$data = mysql_fetch_array($sql1);
extract($data);
//Format tanggal harus yyyy-mm-dd
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $tdate)) {
//Jika format sudah benar, check ke database lokal
// URL Quota Kidzania
$url = 'http://202.72.220.153:9988/mc_checkquota_hodp.php';
$params = array(
'na' => $nama_agen, // NAMA AGEN
'tgl' => $tdate
);
$params_string = http_build_query($params);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post
$resp = curl_exec($ch);
//Close connection
curl_close($ch);
$xml = simplexml_load_string($resp);
if ($format == "xml") {
ob_start();
header("Content-Type:text/xml");
echo "";
echo "
$nama_agen
";
foreach ($xml->info as $info) {
echo "";
$tanggal = $info->tanggal;
echo "" . $tanggal . "";
// $shift = $info->shift;
echo "" . $info->shift . "";
// $sesi = $info->sesi;
echo "" . $info->sesi . "";
// $code = $info->code;
echo "" . $info->jamsesi . "";
echo "" . $info->code . "";
//$status = $info->status;
echo "" . $info->status . "";
echo "" . $info->category . "";
//$quota_anak = $info->quota_anak;
echo "" . $info->quota_anak . "";
//$quota_dewasa = $info->quota_dewasa;
echo "" . $info->quota_dewasa . "";
//}
echo "" . $info->price_toddler_normal . "";
echo "" . $info->price_toddler_normal_one . "";
echo "" . $info->diskon_toddler . "";
echo "" . $info->price_toddler . "";
echo "" . $info->price_toddler_one . "";
//$price_anak = $info->price_anak;
echo "" . $info->price_anak_normal . "";
echo "" . $info->price_anak_normal_one . "";
echo "" . $info->diskon_anak . "";
echo "" . $info->price_anak . "";
echo "" . $info->price_anak_one . "";
//$price_dewasa = $info->price_dewasa;
echo "" . $info->price_dewasa_normal . "";
echo "" . $info->price_dewasa_normal_one . "";
echo "" . $info->diskon_dewasa . "";
echo "" . $info->price_dewasa . "";
echo "" . $info->price_dewasa_one . "";
echo "";
}
echo "";
ob_end_flush();
} else { //json
include_once 'convert_xml_to_json.php';
$arrayData = xmlToArray($xml);
header('Content-type: application/json');
echo json_encode($arrayData);
}
//$respons = "OK : $tanggal";
include_once 'convert_xml_to_json.php';
$arrayData = xmlToArray($xml);
$respons = json_encode($arrayData);
} else { // Jika format tanggalnya salah
if ($format == "xml") {
ob_start();
header("Content-Type:text/xml");
echo "";
echo "
$nama_agen
0005
Format tanggal salah
";
ob_end_flush();
} else { // json
$sites = array();
$sites[] = array('nama_merchant' => $nama_agen, 'id_merchant' => $id, 'code' => "0005", 'status' => "Format tanggal salah");
echo json_encode($sites);
}
$respons = "Format tanggal salah : $tdate";
}
}
$date = date("Y-m");
$logfile = "/var/log/resv/mc_dev_log" . $date . ".log";
// jika file log belum ada, buat dulu
if (!file_exists($logfile)) {
$fp = fopen($logfile, 'w'); #buat file dengan akses tulis penuh
chmod($logfile, 0777);
// fclose($fp);
} else {
$fp = fopen($logfile, 'a+'); #akses file dengan modus buka/tulis
chmod($logfile, 0777);
}
$var_info = print_r($_POST, true);
//$ipaddress = $_SERVER['REMOTE_ADDR'] . " - " .$_SERVER['HTTP_X_FORWARDED_FOR'];
// Function to get the client ip address
function get_client_ip_server()
{
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if ($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if ($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if ($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if ($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if ($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$filename = $_SERVER['SCRIPT_FILENAME'];
$timestamp = date('m/d/Y H:i:s');
fwrite($fp, $filename . ' ---------');
fwrite($fp, '[' . $timestamp . ']: ' . $ipaddress . ' : ' . $nama_agen . ' POST : ' . $var_info . "\r\n");
fwrite($fp, 'Kz Reply : ' . $respons . "\r\n");
fwrite($fp, '----------------------------------------------------------------------------' . $timestamp . "\r\n\n");
fclose($fp);