<?php
require_once('WebToPay.php');
require_once('config.php');
try
{
$response = WebToPay::checkResponse($_GET, array('sign_password' => '938abaff15ddc97965b156b23136c1c9'));
$sms_id = $_GET['id'];
$transaction = $_GET['transaction'];
$amount = $_GET['amount'];
$time = date("Y/m/d H: i: s");
$sms = mysql_escape_string(htmlspecialchars($_GET['sms'], ENT_QUOTES));
$from_nr = $_GET['from'];
$operator = $_GET['operator'];
$key = $_GET['key'];
$category = explode(" ", $sms);
$sms = ereg_replace("".$category[0]." ".$category[1]." ", "", $sms);
if( strtolower($category[1]) == 'kodas' ){
$kodas = substr(uniqid(mt_rand(), TRUE), 0, 5);
mysql_query("INSERT INTO `kodai` (`kodas`,`nr`,`operator`,`amount`, `sms_id`) VALUES ('$kodas', '$from_nr', '$operator', '$amount', '$sms_id')");
echo 'OK Jusu kodas: '.$kodas.'.'.$web_adress;
/*
$row_next = mysql_fetch_array(mysql_query("SHOW TABLE STATUS LIKE 'sms'"));
$category = $category[1];
*/
/*
mysql_query("INSERT INTO sms SET sms_id='$sms_id', transaction='$transaction', amount='$amount', time='$time', sms='$sms', from_nr='$from_nr', operator='$operator', category='$category'");
echo "Skelbimas patalpintas.\n Skelbimo adresas: ".$web_adress."skelbimas-".$row_next["Auto_increment"]."\n Saugos kodas: ".substr($transaction, 0, 3)."".$sms_id."";
*/
}elseif( ( $category[1]=="m" || $category[1]=="v" || $category[1]=="k" || $category[1]=="M" || $category[1]=="V" || $category[1]=="K" ) AND $category[2] == NULL ){
$random_row = mysql_fetch_row(mysql_query("SELECT * FROM sms WHERE category='".$category[1]."' ORDER BY RAND() LIMIT 1"));
if($random_row['0']!=NULL){
@mysql_query("INSERT INTO sms_nr SET sms_id='$sms_id', transaction='$transaction', amount='$amount', time='$time', sms='$sms', from_nr='$from_nr', operator='$operator', skelbimo_id='".$random_row['0']."'");
echo "OK Atsitiktinio skelbimo adresas: ".$web_adress."skelbimas-".$random_row['0']."\n Autoriaus(-es) telefono numeris: ".$random_row['5']."";
}else{
echo "OK Klaida, siuo metu skelbimu nera!";
}
}elseif(is_numeric($category[1]) && $category[1]>"" && $category[1]>0){
$total = mysql_fetch_array(mysql_query("SELECT count(id) FROM sms WHERE id='".$category[1]."'"));
$total = $total[0];
if($total==1){
$row = mysql_fetch_array(mysql_query("SELECT * FROM sms WHERE id='".$category[1]."' LIMIT 1"));
$skelbimo_id = $category[1];
mysql_query("INSERT INTO sms_nr SET sms_id='$sms_id', transaction='$transaction', amount='$amount', time='$time', sms='$sms', from_nr='$from_nr', operator='$operator', skelbimo_id='$skelbimo_id'");
echo "OK Skelbimo adresas: ".$web_adress."skelbimas-".$category[1]."\n Autoriaus(-es) telefono numeris: ".$row['from_nr']."";
}else{
echo "OK Klaida, blogas skelbimo ID!";
}
}elseif($category[1]=="meile" || $category[1]=="MEILE"){
$love = "".$category[2]." myli ".$category[3]." ".rand(60,100)."%";
echo "OK $love\n Nepamirsk stebinti maloniomis staigmenomis savo mylimo zmogaus!";
mysql_query("INSERT INTO sms_nr SET sms_id='$sms_id', transaction='$transaction', amount='$amount', time='$time', sms='$sms', from_nr='$from_nr', operator='$operator', meiles_sk='$love'");
}else{
echo "OK Klaida, paslauga neteikiama!";
}
}
catch (exception $e)
{
echo get_class($e) . ': ' . $e->getMessage();
}
?>