<?php
include('connect.php');
if ((($_SERVER['REMOTE_ADDR']=='203.150.230.41') or ($_SERVER['REMOTE_ADDR']=='203.150.230.79')) and ($_POST[cutrue_code]==$cutrue_code)) {
$sql ="select TOP 1 id from [dbo].[cutrue] where account_id='$_POST[account_id]' and serial='$_POST[serial]' and status='1' order by id ASC ";
$result = mssql_query($sql);
$row = mssql_fetch_array($result);
$id = $row[id];
if ($_POST[amount]>0) { $refill="NO"; } else { $refill="YES"; }
$new_amount = $card_value[$_POST[amount]];
switch ($_POST[status]) {
case "เข้าสู่ระบบ" : $st = 0;break;
case "กำลังดำเนินการ" : $st = 1;break;
case "สำเร็จ" : $st = 2;break;
case "ไม่สำเร็จ" : $st = 3;break;
case "ใช้ไปแล้ว" : $st = 4;break;
}
//--- ส่วนเพิ่ม all in one
//--- POINT
if ($point_active==1) {
$sql = "update [dbo].[$point_table] set $login_account_id_field='$_POST[account_id]'";
foreach ($point as $point_field=>$card) {
foreach ($card as $card_value=>$val) {
if ($card_value==$_POST[amount]) {
$sql .= ",$point_field=$point_field+".$val."";
$new_amount = $val;
}
}
}
$sql .= " where $login_account_id_field='$_POST[account_id]'";
mssql_query($sql);
}
$sql = "update [dbo].[cutrue] set status='$st',amount='$_POST[amount]',refill_amount='$new_amount',refill='YES' where id='$id'";
if (mssql_query($sql)) { echo "REFILL OK"; } else { echo "FAILED UPDATE DB"; }
if (mssql_num_rows($result)>1) {
$sql = "update [dbo].[cutrue] set status='4',refill='YES' where id!='$row[id]' and account_id='$_POST[account_id]' and serial='$_POST[serial]' and status='1'";
mssql_query($sql);
}
}
//echo $sql;
?>