$mode = $_POST['mode']; // default the last message id to 0 $id = 0; // create a new Chat instance $chat = new Chat(); // if the operation is SendAndRetrieve if ($mode == 'SendAndRetrieveNew') { // retrieve the action parameters used to add a new message $name = $_POST['name']; $message = $_POST['message']; $color = $_POST['color']; $id = $_POST['id']; // check if we have valid values if ($name != '' && $message != '' && $color != '') { // post the message to the database $chat->postMessage($name, $message, $color); } } elseif ($mode == 'DeleteAndRetrieveNew') { // delete all existing messages $chat->deleteMessages(); } elseif ($mode == 'RetrieveNew') { // get the id of the last message retrieved by the client $id = $_POST['id']; } // Clear the output if (ob_get_length()) { ob_clean(); } // Headers are sent to prevent browsers from caching header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
<?php require_once "chat.class.php"; //Include chat class $chat = new Chat(); //Create object of class chat $id = 0; //Default value of id //If request is to send message if (isset($_POST['json_sendMessage'])) { $json_decode = json_decode($_POST['json_sendMessage']); $name = $json_decode->name; $message = $json_decode->message; $id = $json_decode->id; if ($name != '' && $message != '') { $chat->postMessage($name, $message); //Call post message function } } else { if (isset($_POST['json_requestNewMessages'])) { $chat->CreateTable(); //Create table if not exist $json_decode = json_decode($_POST['json_requestNewMessages']); $id = $json_decode->id; } } if (ob_get_length()) { ob_clean(); } //Clear buffer for previous content header('Cache-Control: no-cache, must-revalidate');
$to = -1; } elseif ($to_sklon > 0) { $ptype = 3; $to = $to_sklon; } elseif ($to_clan > 0) { $ptype = 2; $to = $to_clan; } elseif ($too > 0) { $ptype = 1; $to = $too; } else { $ptype = 0; $to = 0; } $message = iconv("Windows-1251", "UTF-8//IGNORE", $message); $say = $chat->postMessage($message, $color, $to, $user_id, $channel, $ptype); $message = iconv("UTF-8", "Windows-1251//IGNORE", $message); if (strpos("{$message}", "Нафаня, ") === 0) { $selpech = myquery("select count(*) from game_chat_nakaz where town=0 AND user_id='{$user_id}' and date_zak>'" . time() . "'"); $userpech = 0; if ($selpech != false and mysql_num_rows($selpech) > 0) { $userpech = mysql_result($selpech, 0, 0); } if ($userpech == 0) { include 'bot/index.php'; } } } } } if (ob_get_length()) {