<?php
define('_IN_JOHNCMS', 1);
require('../incfiles/core.php');
header('Access-Control-Allow-Origin: *');

 if (($user_id == true) && !($user_id == false)) { 

switch($mod)
{
    case 'getchat':
	functions::get_chat(10);
	break;
    case 'sendchat':
	$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
	if(!$user_id) {
	    exit();
	}
	if(empty($msg)) {
	    exit();
	}
	elseif(mb_strlen($msg) > 150) {
	    exit();
	}
	mysql_query("INSERT INTO `chats` SET `user_id` = $user_id, `name` = '" . mysql_real_escape_string($datauser['name']) . "', `message`= '" . mysql_real_escape_string($msg) . "', `date` = '" . time() . "'");
	mysql_query("UPDATE `users` SET `balans` = `balans` +1 WHERE `id` = '".$user_id."';");
	break;
	default:
    echo 'Salomalekum '.$login.' sizga nima bor bu erda ?. Xabar kelsa men o\'zim sizni ogohlantiraman. Bu yerga vopshe kirishinigizni hojati yo. Agar yomon niyatda kirgan bolsangiz admin akamga xabar jo\'natib yubordim. U bu yerga kirganingizdan xabardor.';
	break;
} } else {
	echo 'Salomalekum mehmon sekin suring baydan. Saytning bu qismi juda klassno ximoya ostida!';
}
?>