View file Informator/informator.php

File size: 4.02Kb
<?php
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

only_reg();
$set['title']='Информатор';
include_once 'sys/inc/thead.php';
title();

define('separator', '<div style="border-radius: 70em/1em; border: 1px solid #0000FF;"></div>');
$cfg = parse_ini_file('informator.ini');

echo 'Здравствуй! Тебя приветсвует <b>' . $cfg['nick'] . '</b>!<br/>
	  Здесь ты можешь узнать интересующую тебя информацию касательно <b>' . $_SERVER['HTTP_HOST'] . '</b>.<br/>
	  <form method="post" action="?">
	  <textarea name="quest" placeholder="Введи свой вопрос..."></textarea>
	  <br/>
	  <input type="submit" name="ok" value="Отправить"/>
	  </form>' . separator;

if (isset($_POST['ok']))
{
	$quest = trim(mysql_real_escape_string(br(htmlspecialchars($_POST['quest'], ENT_QUOTES))));
	if (!empty($quest))
	{
		$an = mysql_fetch_assoc(mysql_query("SELECT answer FROM infobook WHERE keyword REGEXP '^[$quest]+$' LIMIT 1"));
		if (!empty($an['answer']))
		{
			mysql_query("DELETE FROM informator WHERE id_user = '$user[id]' OR user_id = '$user[id]'");
			mysql_query("INSERT INTO informator SET id_user = '$user[id]', user_id = '0', msg = '$quest', time = '" . time() . "'");
				if ($cfg['interval'] == 0)
				{
					mysql_query("INSERT INTO informator SET id_user = '0', user_id = '$user[id]', msg = '$an[answer]', time = '" . time() . "'");
				}
				else
				{
					$_SESSION['intrM'] = $an['answer'];
					$_SESSION['intr'] = time() + mt_rand($cfg['interval'], ($cfg['interval'] * 2));
				}
			if (isset($_SESSION['try_info'])) unset($_SESSION['try_info']);
		}
		else
		{
			$answer = 'Вопрос не распознан! Сформулируйте еще раз и попробуйте снова, в противном случае вы будете забанены.';
			mysql_query("DELETE FROM informator WHERE id_user = '$user[id]' OR user_id = '$user[id]'");
			mysql_query("INSERT INTO informator SET id_user = '$user[id]', user_id = '0', msg = '$quest', time = '" . time() . "'");
				if ($cfg['interval'] == 0)
				{
					mysql_query("INSERT INTO informator SET id_user = '0', user_id = '$user[id]', msg = '$answer', time = '" . time() . "'");
				}
				else
				{
					$_SESSION['intrM'] = $answer;
					$_SESSION['intr'] = time() + mt_rand($cfg['interval'], ($cfg['interval'] * 2));
				}
			$_SESSION['try_info']++;
		}
		header('location: ?');
	}
	else header('location: ?');
}

if ($_SESSION['try_info'] >= $cfg['try'])
{
	$timeban = $time;
	$timeban += $cfg['ban'] * 60;
	$timeban = min($timeban, $time + 3600 * 24);
	$prich = $cfg['reason'];
	mysql_query("INSERT INTO `ban` (`id_user`, `id_ban`, `prich`, `time`) VALUES ('$user[id]', '0', '$prich', '$timeban')");
	unset($_SESSION['try_info']);
}

if (!isset($_SESSION['intr'])) $_SESSION['intr'] = 0;
if ($_SESSION['intr'] != 0 && $_SESSION['intr'] < time())
{
	mysql_query("INSERT INTO informator SET id_user = '0', user_id = '$user[id]', msg = '$_SESSION[intrM]', time = '" . time() . "'");
	unset($_SESSION['intr']);
	unset($_SESSION['intrM']);
	header('location: ?');
}

$count = mysql_result(mysql_query("SELECT COUNT(id) FROM informator WHERE id_user = '$user[id]' OR user_id = '$user[id]'"), 0);
if ($count != false)
{
	$sql = mysql_query("SELECT * FROM informator WHERE id_user = '$user[id]' OR user_id = '$user[id]' ORDER BY id DESC");
	while($q = mysql_fetch_assoc($sql))
	{
		$who = get_user($q['id_user']);
		$WHO = ($q['id_user'] == 0) ? $cfg['nick'] : $who['nick'];
		echo $WHO . ' <small>[' . date('d.m.y в H:i:s', $q['time']) . ']</small> &gt; ' . $q['msg'] . '<br/>- - -<br/>';
	}
}
else echo 'Пусто...<br/>';

include_once 'sys/inc/tfoot.php';
?>