<?php
$mc = mysql_connect('localhost', '79998786090', '1122334455') or die('<center>Через несколько минут игра будет снова доступна.</center>');
mysql_query('SET NAMES `utf8`', $mc);
mysql_select_db('79998786090', $mc) or die('Идет обновление. ');


##################
##### СЕССИИ #####
##################
session_start();
ob_start();
######################
##### ФИЛЬТРАЦИИ #####
######################


















if (isset($_GET['ref'])) {
    $_SESSION['ref'] = intval($_GET['ref']);
}

function online($user) {
    $user = mysql_query("SELECT * FROM `users` WHERE `id` = '" . $user . "' LIMIT 1");
    $user = mysql_fetch_assoc($user);
    if ($user['online'] > time() - 18000) {
        $online = color('lime') . "онлайн</font>";
    } else {
        $online = color('red') . "оффлайн </font>";
    }
    return $online;
}

function getCountDiamondRef($level = 0) {
    $diamond = 100;
    if ($level == 1) {
        $diamond = 200;
    } else if ($level == 2) {
        $diamond = 500;
    }
    return $diamond;
}

function checkRefPrize($check = 0) {
    $text = 'Вы ничего не получали.';
    if ($check == 1) {
        $text = 'Вы получили 100 алмазов.';
    } else if ($check == 2) {
        $text = 'Вы получили 200 алмазов.';
    } else if ($check == 3) {
        $text = 'Вы получили 500 алмазов.';
    }
    return $text;
}

function getDay($id) {
    $user = mysql_query("SELECT * FROM `users` WHERE `id` = '" . intval($id) . "' LIMIT 1");
    $user = mysql_fetch_assoc($user);

    $checkDay = date('j');
    $checkDayBack = $checkDay - 1;

    if ($checkDayBack == 0 || $checkDayBack == $user['present_day']) {
        if ($user['_day'] > 10) {
            $user['_day'] = 10;
        }

        $gold = 300 * $user['_day'];
        $diamond = 30 * $user['_day'];

        if ($user['_day'] + 1 > 10) {
            $next_gold = 300 * 10;
            $next_diamond = 30 * 10;
        } else {
            $next_gold = 300 * ($user['_day'] + 1);
            $next_diamond = 30 * ($user['_day'] + 1);
        }
    } else if ($checkDayBack != $user['present_day']) {
        $gold = 300;
        $diamond = 30;

        $next_gold = 300 * 2;
        $next_diamond = 30 * 2;
    }

    if ($checkDay != $user['present_day']) {
        if ($checkDayBack == 0 || $checkDayBack == $user['present_day']) {
            mysql_query("UPDATE `users` SET `_day` = `_day` + '1', `almaz` = `almaz` + '" . $diamond . "', `gold` = `gold` + '" . $gold . "', `present_day` = '" . (date("j")) . "' WHERE `id` = '" . $user['id'] . "'");
        } else if ($checkDayBack != $user['present_day']) {
            mysql_query("UPDATE `users` SET `_day` = '1', `almaz` = `almaz` + '" . $diamond . "', `gold` = `gold` + '" . $gold . "', `present_day` = '" . (date("j")) . "' WHERE `id` = '" . $user['id'] . "'");
        }

        $_SESSION['msg'] = 'Вы получили ежедневную награду: <img src="/images/icons/gold.png"> ' . $gold . ' и <img src="/images/icons/almaz.png"> ' . $diamond . ' <br>
Приходите завтра и получите <img src="/images/icons/gold.png"> ' . $next_gold . ' и <img src="/images/icons/almaz.png"> ' . $next_diamond;
        header('Location: /main');
        exit();
    }
}

//function ava($user) {
//$ava = "<img style='background: radial-gradient(ellipse at left,#313131 0%,#000 100%);' width='70px' height='70px' class='round'  src='/images/avatar/$user[sex]/$user[avatar].jpg' >";
//return $ava;
//}

function href($dir, $file) {
    $href = '<a  href ="/' . $dir . '' . $file . '" alt="*" />';
    return $href;
}

function div($dir) {
    $div = '<div class ="' . $dir . '">';
    return $div;
}

function span($dir) {
    $span = '<span class ="' . $dir . '">';
    return $span;

}

function color($dir) {
    $color = '<font color ="' . $dir . '">';
    return $color;

}

function getTimeOrc() {
    $time_battle = array(
        strtotime(date("Y-m-d 21:00:00")), // 0
        strtotime("+1 day", strtotime(date("Y-m-d 09:00:00")))
    );

    if (time() > strtotime(date("Y-m-d 21:00:00"))) {
        $start = $time_battle[1];
    } else {
        $start = $time_battle[0];
    }
    return $start;
}

function text($m) {
    $m = mysql_real_escape_string(htmlspecialchars(stripslashes(trim($m))));
    return $m;
}

function num($m) {
    $m = intval($m);
    $m = abs($m);
    return $m;
} 


/* Фильтрует цифры */
################
##### КУКИ #####
################
if (isset($_COOKIE['login']) && isset($_COOKIE['password'])) {
    $login = text($_COOKIE['login']);
    $password = text($_COOKIE['password']);

    $dbs = mysql_query("SELECT * FROM `users` WHERE `login` = '" . $login . "' and `password` = '" . $password . "' LIMIT 1");
    $user = mysql_fetch_assoc($dbs);

    if (isset($user['id'])) {
        if ($user['login'] != $login or $user['password'] != $password) {
            setcookie('login', '', time() - 86400 * 31);
            setcookie('password', '', time() - 86400 * 31);
        }
    }

    $users = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login` = '" . $login . "' and `password`='" . $password . "' LIMIT 1"));

    if (isset($user['id']) && $users['login'] != $login or $users['password'] != $password) {
        setcookie('login', '', time() - 86400 * 31);
        setcookie('password', '', time() - 86400 * 31);
    }


    $auction = mysql_fetch_assoc(mysql_query("SELECT * FROM `auction` WHERE `id` = '1'"));

    $auction = $auction['id'];
    $myLogin = $user['login'];
    $myID = $user['id'];
    $__str = round($user['str'] / 6);
    $___str = round($user['str'] / 4);
    $_str = rand($__str, $___str);
    $__def = round($user['def'] / 12);
    $___def = round($user['def'] / 7);
    $_def = rand($__def, $___def);
    if ($user['health'] < 0) {
        $user['health'] = 0;
    }

    define('H', $_SERVER['DOCUMENT_ROOT']);


    require_once H . '/system/clan_bonus.php';

    mysql_query("update `users` set `online` = '" . time() . "', `ip` = '" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "' where (`id` = '" . $myID . "')");


    $my_ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban` WHERE `id_user` = '" . $user['id'] . "' "));
    if ($my_ban != null && $_SERVER['REQUEST_URI'] != '/uban') {
        header("Location:/uban");
        exit();
    }


    $LinkKey = md5(rand(1, 10000));
    $boss_user = mysql_query("SELECT * FROM `boss_user` WHERE `id_user` = '" . $myID . "' ORDER BY `id` LIMIT 1");
    $boss_user = mysql_fetch_array($boss_user);
    if (!$boss_user) {
        mysql_query("INSERT INTO `boss_user` SET `id_user` = '$myID', `id_boss` = '1'");
        mysql_query("UPDATE `boss_user` SET  `kol`='3' WHERE `id_user`='" . $myID . "' LIMIT 1");

        header('Location: ?');
        exit();
    }
    //Приключение
    if ($boss_user['win_kol'] == 5) {
        mysql_query("update `users` set    `adventure_id` = '" . ($user['adventure_id'] + 1) . "'  where (`id` = '" . $myID . "')");
        mysql_query("UPDATE `boss_user` SET  `win_kol`='0' WHERE `id_user`='" . $myID . "' LIMIT 1");
    }

    //Приключение
    if ($boss_user['kol'] <= 0) {
        mysql_query("UPDATE `boss_user` SET  `kol`='3' WHERE `id_user`='" . $myID . "' LIMIT 1");
        mysql_query("update `boss_user` set `last` = '" . (time() + 60 * 60) . "' where (`id_user` = '" . $myID . "')");
    }
    //Обновление героя
    if ($user['up_time'] < time()) {
        mysql_query("UPDATE `users` SET   `up_time` = '" . (time() + 86000) . "'  WHERE `id` = '" . $user['id'] . "'");
    }


    if (($auction['limit'] * $auction['day']) > time()) {
        mysql_query("UPDATE `auction` SET    `name`='0'  WHERE `id`='1' LIMIT 1");


    }

    if ($user['avatars'] == '0') {
        mysql_query("UPDATE `users` SET `avatars`= '1'  WHERE `id` = '" . $user['id'] . "'");
    }
    $batle = mysql_query("SELECT * FROM `bashna` WHERE `id` = '1' ORDER BY `id` LIMIT 1");
    $batle = mysql_fetch_array($batle);
    $OrkUser = mysql_fetch_assoc(mysql_query("SELECT * FROM `ork_user` WHERE `id_user`='" . $myID . "' LIMIT 1"));

    if ($OrkUser['TakeReward'] == '1' and $batle['resp_boss'] < time()) {
        $i = 0;

        mysql_query(" UPDATE `ork_user` SET `TakeReward` = '0'  WHERE  `id_user` = '" . $myID . "'");
        mysql_query(" UPDATE `ork_user` SET  `gold` = '0' , `almaz` = '0'  ,  `exp` = '0'   WHERE  `id_user` = '" . $myID . "'");
        mysql_query(" UPDATE `ork_user` SET `dmg` = '0'  WHERE  `id_user` = '" . $myID . "'");
    }

    $fights = mysql_fetch_assoc(mysql_query("SELECT * FROM `fights` WHERE `id_user`='" . $myID . "' LIMIT 1"));

    if (($_SERVER['PHP_SELF']) != '/fights.php' and $_SERVER['PHP_SELF'] != '/battle_ork.php' and $fights['status'] != 0) {
        mysql_query("UPDATE  `fights` SET `status` = '0' ,  `exit`='" . (time() + 900) . "'  WHERE  `id_user`='" . $myID . "'");

    }

    if ($fights['BonusStrTime'] < time() and $fights['BonusStrStatus'] == 1) {
        mysql_query('UPDATE `fights` SET  `BonusStrStatus` = "0"  WHERE `id_user` = "' . $myID . '"');
        mysql_query('UPDATE `users` SET `str` = "' . ($user['str'] - 100) . '" WHERE `id` = "' . $myID . '"');

    }

    if ($fights['BonusHpTime'] < time() and $fights['BonusHpStatus'] == 1) {
        mysql_query('UPDATE `fights` SET  `BonusHpStatus` = "0"  WHERE `id_user` = "' . $myID . '"');
        mysql_query('UPDATE `users` SET `max_health` = "' . ($user['max_health'] - 100) . '" WHERE `id` = "' . $myID . '"');

    }
    $arena = mysql_fetch_assoc(mysql_query("SELECT * FROM `arena` WHERE `id_user`='" . $myID . "' LIMIT 1"));
    if ($arena['rating'] < 0) {
        mysql_query("UPDATE  `arena` SET `rating` = '0'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");
    }
    if ($user['trust'] > 100) {
        mysql_query("UPDATE  `users` SET `trust` = '100'   WHERE  `id`='" . $myID . "' LIMIT 1 ");
    }

    if ($arena['koll'] <= 50 and $arena['last'] < time()) {
        mysql_query("UPDATE  `arena` SET `koll` = '50' ,`last`='" . (time() + 3600) . "'   WHERE  `id_user`='" . $myID . "' LIMIT 1 ");

    }


    mysql_query("UPDATE `arena` SET  `UserName`='$user[login]', `avatars`='$user[avatars]'  ,  `UserSex`='$user[sex]'  WHERE `id_user`='" . $myID . "' LIMIT 1");


    $campaign = mysql_query("SELECT * FROM `campaign` WHERE `id_user` = '" . $myID . "' ORDER BY `id` LIMIT 1");
    $campaign = mysql_fetch_array($campaign);

    switch ($user['class']) {
        case 1:
            $StatusClass = color('green') . " Варвар </font>";
            $BonusStr = 20;
            $BonusDef = 25;
            $BonusHp = 25;
            $ClassImg = "<img src='/images/class/barbarian.jpg' width='85px'>";
            break;

        case 2:
            $StatusClass = color('orange') . " Разбойник </font>";
            $BonusStr = 35;
            $BonusDef = 10;
            $BonusHp = 15;
            $ClassImg = "<img src='/images/class/robber.jpg' width='85px'>";

            break;

        case 3:

            $StatusClass = color('gold') . " Рыцарь </font>";
            $BonusStr = 50;
            $BonusDef = 25;
            $BonusHp = 15;
            $ClassImg = "<img src='/images/class/knight.jpg' width='85px'>";

            break;
        default:
            $StatusClass = color('tomato') . " Не выбран </font>";
            $BonusStr = 0;
            $BonusDef = 0;
            $BonusHp = 0;
    }


    $ClassHp = ceil($user['max_health'] * $BonusHp / 100);
    $ClassStr = ceil($user['str'] * $BonusStr / 100);
    $ClassDef = ceil($user['def'] * $BonusDef / 100);
}



































###################
##### ФУНКЦИИ #####
###################




function nick($id){
	$id=intval($id);
	if(mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `id` = '$id'"),0)>0){
		$us=mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1"));
		return'<a href="/hero/'.$us['id'].'#'.$r.'"><img src="/icons/'.$us['sex'].'.png"> '.hsc($us['login']).', '.$us['level'].' ур.</a>';
	} else {
		return' [Аккаунт удален] ';
	}
}









   function hsc($text){
	return htmlspecialchars($text);
}

function icons_user($user){
global $db;
$user = mysql_query("SELECT * FROM `users` WHERE `id` = '".$user."' LIMIT 1");
$user = mysql_fetch_array($user);
if($user['online'] > time()-18000){
$image = "<img src='/images/icons/".($user['sex'] == 'w' ? 'w' : '')."$user[side].png' width='15px'>";
}else{
$image = "<img src='/images/icons/".($user['sex'] == 'w' ? 'w' : '')."$user[side].png' style='opacity: 0.3;' width='15px'>";
}
return $image;
}















function gradient($text, $hexfrom, $hexto){
$text = iconv('utf-8','windows-1251',$text);
$colorsteps = strlen($text);
$fromrgb['r'] = hexdec(substr($hexfrom, 0, 2));
$fromrgb['g'] = hexdec(substr($hexfrom, 2, 2));
$fromrgb['b'] = hexdec(substr($hexfrom, 4, 2));
$torgb['r'] = hexdec(substr($hexto, 0, 2));
$torgb['g'] = hexdec(substr($hexto, 2, 2));
$torgb['b'] = hexdec(substr($hexto, 4, 2));
$steprgb['r'] = ($fromrgb['r'] - $torgb['r']) / ($colorsteps - 1);
$steprgb['g'] = ($fromrgb['g'] - $torgb['g']) / ($colorsteps - 1);
$steprgb['b'] = ($fromrgb['b'] - $torgb['b']) / ($colorsteps - 1);
for($i = 0; $i <= $colorsteps; $i++){
$rgb['r'] = floor($fromrgb['r'] - ($steprgb['r'] * $i));
$rgb['g'] = floor($fromrgb['g'] - ($steprgb['g'] * $i));
$rgb['b'] = floor($fromrgb['b'] - ($steprgb['b'] * $i));
$hexrgb['r'] = sprintf('%02x', ($rgb['r']));
$hexrgb['g'] = sprintf('%02x', ($rgb['g']));
$hexrgb['b'] = sprintf('%02x', ($rgb['b']));
$color = implode(null, $hexrgb);
$return .= '<font color="'.$color.'">'.$text[$i].'</font>';
}
return iconv('windows-1251','utf-8',$return);
}


















function text_msg($msg) {
    $bbcode = array();
    $bbcode['/\n/isU'] = '<br>';
    global $ank;
    if ($ank['access'] >= 1) {
        $bbcode['/\[url=(.+)\](.+)\[\/url\]/isU'] = "<a href='$1'>$2</a>";
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[img=(.*)](.*)\[\/img\]/isU'] = "<img src='$1'/>";
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[center\](.+)\[\/center\]/isU'] = '<center>$1</center>';
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[u\](.+)\[\/u\]/isU'] = '<u>$1</u>';
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[i\](.+)\[\/i\]/isU'] = '<i>$1</i>';
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[b\](.+)\[\/b\]/isU'] = '<b>$1</b>';
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[url=(.+)\](.+)\[\/url\]/isU'] = "<a href='$1'>$2</a>";
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[q\](.+)\[\/q\]/isU'] = "<q>$1</q>";
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[a\](.+)\[\/a\]/isU'] = "<a>$1</a>";
    }
    if ($ank['access'] >= 1) {
        $bbcode['/\[(.+)\](.+)\[\/(.+)\]/isU'] = "<font color='$1'>$2</font>";
    }
    if (count($bbcode)) {
        $msg = preg_replace(array_keys($bbcode), array_values($bbcode), $msg);
    }
    if ($ank['access'] == 3) {
        $msg = "<font color='#32CD32'>$msg</span>";
    }
    if ($ank['access'] == 2) {
        $msg = "<font color='#6A5ACD'>$msg</span>";
    }
    if ($ank['access'] == 1) {
        $msg = "<font color='#EEE8AA'>$msg</font>";
    }
    if ($ank['access'] == 0) {
        $msg = "<span class='white'>$msg</span>";
    }

    $msg = str_replace(array(':chit'), '<img src="/images/smiles/1.gif" alt="*"/>', $msg);
    $msg = str_replace(array(":krut"), '<img src="/images/smiles/2.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':nono'), '<img src="/images/smiles/nono.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':roza'), '<img src="/images/smiles/roza.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':palm'), '<img src="/images/smiles/5.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':ha'), '<img src="/images/smiles/6.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':-D'), '<img src="/images/smiles/7.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':crazy'), '<img src="/images/smiles/crazy.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':klass'), '<img src="/images/smiles/8.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':grust'), '<img src="/images/smiles/9.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':-)'), '<img src="/images/smiles/10.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':P'), '<img src="/images/smiles/11.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':son'), '<img src="/images/smiles/12.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':mig'), '<img src="/images/smiles/13.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':aaa'), '<img src="/images/smiles/14.gif" alt="*"/>', $msg);
    $msg = str_replace(array(':hi'), '<img src="/images/smiles/hi.gif" alt="*"/>', $msg);
   $string = str_replace(array('Гг','Гг'), '<img src="/images/smiles/gg.gif" alt="*"/>',      $string);
$string = str_replace(array('.ппц.','ппц'), '<img src="/images/smiles/ppc.gif" alt="*"/>',      $string);
$string = str_replace(array('.гы.','гы)'), '<img src="/images/smiles/gi.gif" alt="*"/>',      $string);
$string = str_replace(array(':ы)',':ыы'), '<img src="/images/smiles/i.gif" alt="*"/>',      $string);
$string = str_replace(array('дану',':дану'), '<img src="/images/smiles/dany.gif" alt="*"/>',      $string);
$string = str_replace(array('.рукалицо.','.1.'), '<img src="/images/smiles/ruka.gif" alt="*"/>',      $string);
$string = str_replace(array('=)'),'<img src="/images/smiles/happy.gif" alt="*"/>',        $string);
$string = str_replace(array('=('),'<img src="/images/smiles/buhoj.gif" alt="*"/>',          $string);
$string = str_replace(array('плачу'),'<img src="/images/smiles/pla.png" alt="*"/>',          $string);
$string = str_replace(array(':сердце'),'<img src="/images/smiles/lub.png" alt="*"/>',          $string);
$string = str_replace(array(':)'),'<img src="/images/smiles/).gif" alt="*"/>',        $string);
$string = str_replace(array('лецон'),'<img src="/images/smiles/ka.png" alt="*"/>',        $string);
$string = str_replace(array(':('),'<img src="/images/smiles/(.gif" alt="*"/>',        $string);
$string = str_replace(array(':D'),'<img src="/images/smiles/D.gif" alt="*"/>',        $string);
$string = str_replace(array(';)'),'<img src="/images/smiles/hi.gif" alt="*"/>',        $string);
$string = str_replace(array(':оу'),'<img src="/images/smiles/oy.gif" alt="*"/>',          $string);
$string = str_replace(array(':love'),'<img src="/images/smiles/love.gif" alt="*"/>',        $string);
$string = str_replace(array(':ок',':ок'), '<img src="/images/smiles/tt.png" alt="*"/>',      $string);
$string = str_replace(array(':xaxa'),'<img src="/images/smiles/xaxa.gif" alt="*"/>',        $string);
$string = str_replace(array(':w'),'<img src="/images/smiles/w.gif" alt="*"/>',        $string);
$string = str_replace(array(':zloy'),'<img src="/images/smiles/zlo.gif" alt="*"/>',        $string);
$string = str_replace(array(':str'),'<img src="/images/smiles/str.gif" alt="*"/>',          $string);
$string = str_replace(array(':vopr'),'<img src="/images/smiles/vopros.gif" alt="*"/>',        $string);
$string = str_replace(array(':cofe'),'<img src="/images/smiles/cofe.gif" alt="*"/>',        $string);
$string = str_replace(array(':prelest'),'<img src="/images/smiles/prelest.gif" alt="*"/>',        $string);
$string = str_replace(array(':uch'),'<img src="/images/smiles/lamer.gif" alt="*"/>',        $string);
$string = str_replace(array(':zubch'),'<img src="/images/smiles/zubch.gif" alt="*"/>',          $string);
$string = str_replace(array(':mister'),'<img src="/images/smiles/mister.gif" alt="*"/>',        $string);
$string = str_replace(array(':yo'),'<img src="/images/smiles/pank.gif" alt="*"/>',        $string);
$string = str_replace(array(':poka'),'<img src="/images/smiles/poka.gif" alt="*"/>',        $string);
$string = str_replace(array(':rzhu'),'<img src="/images/smiles/rzhu.gif" alt="*"/>',        $string);
$string = str_replace(array(':ок',':ок'), '<img src="/images/smiles/tt.gif" alt="*"/>',      $string);

$string = str_replace(array(':rules'),'<img src="/images/smiles/rules.gif" alt="*"/>',        $string);
$string = str_replace(array(':roza'),'<img src="/images/smiles/roza.gif" alt="*"/>',        $string);
$string = str_replace(array(':plak'),'<img src="/images/smiles/plak.gif" alt="*"/>',        $string);
$string = str_replace(array(':pivo'),'<img src="/images/smiles/pivo.gif" alt="*"/>',        $string);
$string = str_replace(array(':vpr'),'<img src="/images/smiles/vpr.gif" alt="*"/>',        $string);
$string = str_replace(array(':ura'),'<img src="/images/smiles/ura.gif" alt="*"/>',        $string);
$string = str_replace(array(':podarok'),'<img src="/images/smiles/podarok.png" alt="*"/>',        $string);
$string = str_replace(array('12341'),'<img src="/images/smiles/12341.png" width="100%" alt="*"/>',        $string);
$string = str_replace(array(':be'),'<img src="/images/smiles/be.gif" alt="*"/>',        $string);
$string = str_replace(array(':povar'),'<img src="/images/smiles/povar.gif" alt="*"/>',        $string);
$string = str_replace(array(':kur'),'<img src="/images/smiles/kur.gif" alt="*"/>',        $string);
$string = str_replace(array(':haha'),'<img src="/images/smiles/haha.gif" alt="*"/>',        $string);
$string = str_replace(array(':vinsent'),'<img src="/images/smiles/vinsent.gif" alt="*"/>',        $string);
$string = str_replace(array(':not'),'<img src="/images/smiles/not.gif" alt="*"/>',        $string);
$string = str_replace(array(':nooo'),'<img src="/images/smiles/facepalm.gif" alt="*"/>',        $string);
$string = str_replace(array(':nono'),'<img src="/images/smiles/nono.gif" alt="*"/>',        $string);
$string = str_replace(array(':nezn'),'<img src="/images/smiles/neznaju.gif" alt="*"/>',        $string);
$string = str_replace(array(':mafiya'),'<img src="/images/smiles/mafiya.gif" alt="*"/>',        $string);
$string = str_replace(array(':romashki'),'<img src="/images/smiles/romashki.gif" alt="*"/>',        $string);
$string = str_replace(array(':music'),'<img src="/images/smiles/ar.gif" alt="*"/>',        $string);
$string = str_replace(array(':gitara'),'<img src="/images/smiles/gitara.gif" alt="*"/>',        $string);
$string = str_replace(array(':aaa'),'<img src="/images/smiles/aaa.gif" alt="*"/>',        $string);
$string = str_replace(array(':mjach'),'<img src="/images/smiles/mjach.gif" alt="*"/>',        $string);
$string = str_replace(array(':nea'),'<img src="/images/smiles/nea.gif" alt="*"/>',        $string);
$string = str_replace(array(':hi'),'<img src="/images/smiles/privet.gif" alt="*"/>',        $string);
$string = str_replace(array(':pobeda'),'<img src="/images/smiles/pobeda.gif" alt="*"/>',        $string);
$string = str_replace(array(':kovyr'),'<img src="/images/smiles/kovyr.gif" alt="*"/>',        $string);
$string = str_replace(array(':klass'),'<img src="/images/smiles/klass.gif" alt="*"/>',        $string);
$string = str_replace(array(':kiss'),'<img src="/images/smiles/kiss.gif" alt="*"/>',        $string);
$string = str_replace(array(':king'),'<img src="/images/smiles/king.gif" alt="*"/>',        $string);
$string = str_replace(array(':jester'),'<img src="/images/smiles/jester.gif" alt="*"/>',        $string);
$string = str_replace(array(':mash'),'<img src="/images/smiles/mash.gif" alt="*"/>',        $string);
$string = str_replace(array(':help'),'<img src="/images/smiles/help.gif" alt="*"/>',        $string);
$string = str_replace(array(':hello'),'<img src="/images/smiles/hello.gif" alt="*"/>',        $string);
$string = str_replace(array(':gy'),'<img src="/images/smiles/gy.gif" alt="*"/>',        $string);
$string = str_replace(array(':gum'),'<img src="/images/smiles/ochki.gif" alt="*"/>',        $string);
$string = str_replace(array(':zzz'),'<img src="/images/smiles/zzz.gif" alt="*"/>',        $string);
$string = str_replace(array(':gbita'),'<img src="/images/smiles/gbita.gif" alt="*"/>',        $string);
$string = str_replace(array(':fingal'),'<img src="/images/smiles/fingal.gif" alt="*"/>',        $string);
$string = str_replace(array(':8'),'<img src="/images/smiles/8.gif" alt="*"/>',        $string);
$string = str_replace(array(':dz'),'<img src="/images/smiles/dz.gif" alt="*"/>',        $string);
$string = str_replace(array(':chit'),'<img src="/images/smiles/chit.gif" alt="*"/>',        $string);
$string = str_replace(array(':druzhba'),'<img src="/images/smiles/druzhba.gif" alt="*"/>',        $string);
$string = str_replace(array(':drazn'),'<img src="/images/smiles/drazn.gif" alt="*"/>',        $string);
$string = str_replace(array(':]'),'<img src="/images/smiles/[.gif" alt="*"/>',        $string);
$string = str_replace(array(':-P'),'<img src="/images/smiles/P.gif" alt="*"/>',        $string);
$string = str_replace(array(':cop'),'<img src="/images/smiles/cop.gif" alt="*"/>',        $string);
$string = str_replace(array(':cool'),'<img src="/images/smiles/cool.gif" alt="*"/>',        $string);
$string = str_replace(array(':shtanga'),'<img src="/images/smiles/shtanga.gif" alt="*"/>',        $string);
$string = str_replace(array(':bravo'),'<img src="/images/smiles/bravo.gif" alt="*"/>',        $string);
$string = str_replace(array(':boks'),'<img src="/images/smiles/boks.gif" alt="*"/>',        $string);
$string = str_replace(array(':bita'),'<img src="/images/smiles/bita.gif" alt="*"/>',        $string);
$string = str_replace(array(':oy'),'<img src="/images/smiles/oy.gif" alt="*"/>',        $string);
$string = str_replace(array(':music'),'<img src="/images/smiles/ar.gif" alt="*"/>',        $string);
$string = str_replace(array(':shamp'),'<img src="/images/smiles/shamp.gif" alt="*"/>',        $string);
















    // Определяемм слава которые нарушают правила
    $msg = str_replace(array(
        'блять',
        'наху',
        'ебан',
        'хуй',
        'бля',
        'гавно',
        'хрень',
        'пидор',
        'чмо',
        'пизда',
        'гандон',
        '.ru',
        '.mobi',
        '.com'
    ), '<font color="red">       (~)</font>', $msg);

    return $msg;
}








function bbpanel($form, $field) {
	return '<script language="JavaScript" type="text/javascript">
	function tag(text1, text2) {
	if ((document.selection)) {
		document.' . $form . '.' . $field . '.focus();
		document.' . $form . '.document.selection.createRange().text = text1+document.' . $form . '.document.selection.createRange().text+text2;
	} else if(document.forms[\'' . $form . '\'].elements[\'' . $field . '\'].selectionStart!=undefined) {
		var element = document.forms[\'' . $form . '\'].elements[\'' . $field . '\'];
		var str = element.value;
		var start = element.selectionStart;
		var length = element.selectionEnd - element.selectionStart;
		element.value = str.substr(0, start) + text1 + str.substr(start, length) + text2 + str.substr(start + length);
	} else 
		document.' . $form . '.' . $field . '.value += text1+text2;
	}
	</script>
<a href="javascript:tag(\':chit \',\'\')"><img src="/images/smiles/1.gif" alt="*"/></a>
 <a href="javascript:tag(\':krut \',\'\')"><img src="/images/smiles/2.gif" alt="*"/></a>
 <a href="javascript:tag(\':nono \',\'\')"><img src="/images/smiles/nono.gif" alt="*"/></a>
 <a href="javascript:tag(\':roza \',\'\')"><img src="/images/smiles/roza.gif" alt="*"/></a>
 <a href="javascript:tag(\':palm \',\'\')"><img src="/images/smiles/5.gif" alt="*"/></a>
 <a href="javascript:tag(\':ha \',\'\')"><img src="/images/smiles/6.gif" alt="*"/></a>
 <a href="javascript:tag(\':-D \',\'\')"><img src="/images/smiles/7.gif" alt="*"/></a>
 <a href="javascript:tag(\':crazy \',\'\')"><img src="/images/smiles/crazy.gif" alt="*"/></a>
</br>
 <a href="javascript:tag(\':klass \',\'\')"><img src="/images/smiles/8.gif" alt="*"/></a>
 <a href="javascript:tag(\':grust \',\'\')"><img src="/images/smiles/9.gif" alt="*"/></a>
 <a href="javascript:tag(\':-) \',\'\')"><img src="/images/smiles/10.gif" alt="*"/></a>
 <a href="javascript:tag(\':P \',\'\')"><img src="/images/smiles/11.gif" alt="*"/></a>
 <a href="javascript:tag(\':son \',\'\')"><img src="/images/smiles/12.gif" alt="*"/></a>
 <a href="javascript:tag(\':mig \',\'\')"><img src="/images/smiles/13.gif" alt="*"/></a>
 <a href="javascript:tag(\':aaa \',\'\')"><img src="/images/smiles/14.gif" alt="*"/></a>
 <a href="javascript:tag(\':hi \',\'\')"><img src="/images/smiles/hi.gif" alt="*"/></a>
 
';
}



















function msg($sms) {
    echo '<div class="header"> ' . $sms . ' </div>';
}

function fight($sms) {
    echo '<div class="header"> ' . $sms . ' </div>';
}


function ico($dir, $file) {
    $img = '<img src="/images/' . $dir . '/' . $file . '" width="15px" alt="*" />';
    return $img;
}


function main($dir, $file) {
    $img = '<img src="/images/' . $dir . '/' . $file . '" width="25px" alt="*" />';
    return $img;
}

function img($dir, $file) {
    $img = '<img src="/images/' . $dir . '/' . $file . '"   width="50px" alt="*" />';
    return $img;
}

function spell($dir, $file) {
    $img = '<img src="/images/' . $dir . '/' . $file . '"  style="opacity: 0.3;"  width="50px" alt="*" />';
    return $img;
}


function item($dir, $file) {
    $img = '<img src="/images/' . $dir . '/' . $file . '"   width="50px" alt="*" />';
    return $img;
}

function tl($tl) {
    $d = 3600 * 24;
    $day = floor($tl / $d);
    $tl = $tl - ($d * $day);
    $hour = floor($tl / 3600);
    $tl = $tl - (3600 * $hour);
    $minute = floor($tl / 60);
    $tl = $tl - (60 * $minute);
    $second = floor($tl);
    $dayt = "" . ($day > 0 ? "$day д. " : null) . "";
    $hourt = "" . ($hour > 0 ? "$hour ч. " : null) . "";
    $minutet = "" . ($minute > 0 ? "$minute м. " : null) . "";
    $secondt = "" . ($second > 0 ? "$second с. " : null) . "";
    if ($day > 0) {
        $minutet = NULL;
        $secondt = NULL;
    }
    if ($hour > 0 && $day == 0) {
        $secondt = NULL;
        $dayt = NULL;
    }

    return "$dayt$hourt$minutet$secondt";
} /* Вывод оставшегося времени */

function vremja($time = NULL) {
    if ($time == NULL) {
        $time = time();
    }
    $timep = "" . date("j M yг. в H:i", $time) . "";
    $time_p[0] = date("j n Y", $time);
    $time_p[1] = date("H:i", $time);

    if ($time_p[0] == date("j n Y")) {
        $timep = date("H:i:s", $time);
    }
    if ($time_p[0] == date("j n Y", time() - 60 * 60 * 24)) {
        $timep = "Вчера в $time_p[1]";
    }

    $timep = str_replace("Jan", "Янв", $timep);
    $timep = str_replace("Feb", "Фев", $timep);
    $timep = str_replace("Mar", "Мар", $timep);
    $timep = str_replace("May", "Мая", $timep);
    $timep = str_replace("Apr", "Апр", $timep);
    $timep = str_replace("Jun", "Июня", $timep);
    $timep = str_replace("Jul", "Июля", $timep);
    $timep = str_replace("Aug", "Авг", $timep);
    $timep = str_replace("Sep", "Сент", $timep);
    $timep = str_replace("Oct", "Окт", $timep);
    $timep = str_replace("Nov", "Нояб", $timep);
    $timep = str_replace("Dec", "Дек", $timep);
    return $timep;
} /* Вывод времени */

function noauth() {
    global $user;
    if (isset($user['id'])) {
        header('Location: /main');
        exit;
    }
}

function auth() {
    global $user;
    if (!isset($user['id'])) {
        header('Location: /');
        exit;
    }
}

function access($access = 0) {
    global $user;
    if ($user['access'] < $access) {
        header('Location: /main');
        exit;
    }
}


function page($k_page = 1) { // Выдает текущую страницу
    $page = 1;
    if (isset($_GET['page'])) {
        if ($_GET['page'] == 'end') {
            $page = intval($k_page);
        } elseif (is_numeric($_GET['page'])) {
            $page = intval($_GET['page']);
        }
    }
    if ($page < 1) {
        $page = 1;
    }
    if ($page > $k_page) {
        $page = $k_page;
    }
    return $page;
}

function k_page($k_post = 0, $k_p_str = 10) { // Высчитывает количество страниц
    if ($k_post != 0) {
        $v_pages = ceil($k_post / $k_p_str);
        return $v_pages;
    } else {
        return 1;
    }
}

function str($link = '?', $k_page = 1, $page = 1) { // Вывод номеров страниц (только на первый взгляд кажется сложно ;))
    if ($page < 1) {
        $page = 1;
    }
    echo "<div class=\"\">\n";
    if ($page != 1) {
        echo "<span class=><a  c href=\"" . $link . "page=" . ($page - 1) . "\" title='Предыдущая страница (№" . ($page - 1) . ")'></a></span> ";
    } else {
        echo "";
    }
    echo "  ";
    if ($page != $k_page) {
        echo " <span class=''><a class='cb_ttl' href=\"" . $link . "page=" . ($page + 1) . "\" title='Следующая страница (№" . ($page + 1) . ")'></a></span>";
    } else {
        echo "";
    }
    echo "<br />\n";
    if ($page != 1) {
        echo "<span class=><a href=\"" . $link . "page=1\" title='Первая страница'>&lt;&lt;</a></span> ";
    }
    if ($page != 1) {
        echo "<span class=><a href=\"" . $link . "page=1\" title='Страница №1'>1</a></span>";
    } else {
        echo "<span class='white'>1</span>";
    }
    for ($ot = - 3; $ot <= 3; $ot ++) {
        if ($page + $ot > 1 && $page + $ot < $k_page) {
            if ($ot == - 3 && $page + $ot > 2) {
                echo "  ..";
            }
            if ($ot != 0) {
                echo " <span class=><a class '' href=\"" . $link . "page=" . ($page + $ot) . "\" title='Страница №" . ($page + $ot) . "'>" . ($page + $ot) . "</a></span>";
            } else {
                echo " <span class='white'> " . ($page + $ot) . "</span>";
            }
            if ($ot == 3 && $page + $ot < $k_page - 1) {
                echo " ";
            }
        }
    }

    if ($page != $k_page) {
        echo " <span class=><a href=\"" . $link . "page=end\" title='Страница №$k_page'>$k_page</a></span>";
    } elseif ($k_page > 1) {
        echo " <span class='white'>$k_page</span>";
    }
    if ($page != $k_page) {
        echo " <span class=><a class='cb_ttl' href=\"" . $link . "page=end\" title='Последняя страница'> &gt;&gt;</a></span>";
    }

    echo "</div>\n";
}

function n_f($i, $tip = 0) {

    if ($tip == 1) {

        $i = number_format($i, 0, '', '\'');
    } else {

        if ($i >= 100000 && $i < 1000000) {

            $i = number_format($i, 0, '', '.');

            $i = round($i, 1) . 'k';

        } elseif ($i >= 1000000 && $i < 1000000000) {

            $i = number_format($i, 0, '', '.');

            $i = round($i, 1) . 'm';

        } else {

            $i = number_format($i, 0, '', '\'');

        }
    }
    return $i;

}

function skill($skill) {
    switch ($skill) {
        case 0:
            $class = 0;
            break;
        case 1:
            $class = 1;
            break;
        case 10:
            $class = 2;
            break;
        case 26:
            $class = 3;
            break;
        case 48:
            $class = 4;
            break;
        case 100:
            $class = 5;
            break;
    }
    return $class;
}

$random = rand(4999, 6999);

function user($uid, $colon) {
    $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . num($uid) . "' "));
    return $user[$colon];
}

function isTimer($var) {
    $timer = $var - time();
    $isDay = floor($timer / 86400);
    $isHour = floor($timer / 3600);
    $isMin = floor($timer / 60);
    $hourOs = $isHour - ($isDay * 24); // Остаток часов от дня
    $minOs = $isMin - ($isHour * 60); // Остаток минут от часов
    $secOs = $timer - ($isMin * 60); // остаток секунд от часов
    if ($isDay > '0') {
        $day = $isDay . " д ";
    }
    if ($hourOs > '0') {
        $hour = $hourOs . " ч ";
    }
    if ($minOs > '0') {
        $minute = $minOs . " м ";
    }
    if ($secOs > '0') {
        $sec = $secOs . " с ";
    }
    $times = $day . $hour . $minute . $sec;
    return $times;
}
