session_start();
include("config.php");
include("header.php");
$menu_type = "normal";
include("menu.php");
if(isset($_SESSION['name'])){
$query = mysql_query("SELECT * FROM users WHERE name='".$_SESSION['name']."'");
$row = mysql_fetch_assoc($query);
$credits = $row['credits'];
if(isset($_POST['check'])){
$query = mysql_query("SELECT * FROM vouchers WHERE code='".$_POST['code']."'");
$nums = mysql_num_rows($query);
if ($nums == 1){
$row = mysql_fetch_assoc($query);
$amount = $row['amount'];
mysql_query("UPDATE users SET credits=credits+".$amount." WHERE name='".$_SESSION['name']."'");
mysql_query("DELETE FROM vouchers WHERE code='".$_POST['code']."'") or die(mysql_error());
echo "Code Correct
";
$creditsnew = $credits + $amount;
echo "You have ".$creditsnew." credits now.";
//Socket Part
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,"127.0.0.1","90") or die("Can't find the host.");
$packet = "XXCREDITS".$_SESSION['name']."".$creditsnew."";
$packet_len = strlen($packet);
$packet_len = B64EncodeLenght($packet_len);
socket_write($socket,"@".$packet_len."".$packet."");
//Socket Part
}else{
echo "ERROR: Invalid Code";
}
}else{
?>