<?php
/*Онлайн игра Football Manager под DCMS версии 6.6.4

 *ВНИМАНИЕ!!! Данный скрипт нельзя распространять, нельзя продавать, менять и т.д.

 *Автор скрипта: Doctor

 *Тех поддержка: 

 *icq: 624552318

 *e-mail: dudringvala@yahoo.com

 *skype: isevgio

 */
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';
$set['title']='FM Тренер';
include_once '../sys/inc/thead.php';
title();
err();
aut();
include_once 'online.php';

if (!isset($user) && !isset($_GET['id'])){header("Location: index.php?".SID);exit;}
if (isset($user))$ank['id']=$user['id'];
if (isset($_GET['id']))$ank['id']=intval($_GET['id']);
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$ank[id]' LIMIT 1"),0)==0){header("Location: index.php?".SID);exit;}
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank[id] LIMIT 1"));
$klubi=mysql_fetch_array(mysql_query("SELECT * FROM `fm_club` WHERE `id_user` = '$ank[id]' LIMIT 1"));
$cena = mysql_fetch_array(mysql_query("SELECT * FROM `fm_admin` WHERE `id` = '1' LIMIT 1"));

if (isset($_GET['dar']) && $user['id']==$ank['id'])
{
$gam=mysql_fetch_array(mysql_query("SELECT * FROM `fm_coach` WHERE `id_club` = '$klubi[id]' LIMIT 1"));
if ($klubi['id']!=$gam['id_club'])$err='Это не ваш Тренер!';
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `id` = '$gam[id]' and `timedar` > '".($time-3600)."'"),0)==1)$err='Только один раз в час!';
if (!isset($err))
{
mysql_query("UPDATE `fm_coach` SET `timedar` = '$time' WHERE `id` = '$gam[id]'");
mysql_query("UPDATE `fm_club` SET `var` = '".($klubi['var'] + 5)."' WHERE `id_user` = '$ank[id]'");
msg('Успешно дал советы!');
}
}

$fasi=$cena['coach'];
if (isset($_GET['set']) && isset($_POST['nick']) && $user['id']==$ank['id'])
{

if ($user['fm_money']<$fasi)$err="У вас нет $fasi Долларов!";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `id_club` = '$klubi[id]'"),0)==1)$err='У вас уже есть Тренер!';
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `name` = '".mysql_real_escape_string(esc($_POST['nick']))."'"),0)!=0)$err='Имя тренера уже занято!';
if (strlen2($_POST['nick'])<3)$err='Короткое Имя!';
if (strlen2($_POST['nick'])>32)$err='Имя не должно быть длиннее 32-х символов!';
if (ereg("\=|\+|\{|\}|\(|\)|\^|\%|\\$|#|@|!|&|\~|'|\"|:|;|`|,|\.|\?|<|>",$_POST['nick']))$err='Имя тренера присутствуют запрещенные символы!';
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_club` WHERE `id_user` = '$ank[id]'"),0)==0)$err='У вас нет Клубa!';

if (!isset($err))
{
$nick=mysql_real_escape_string(esc($_POST['nick']));
mysql_query("INSERT INTO `fm_coach` (`id_club`, `name`, `time`) VALUES  ('".$klubi['id']."', '$nick', '$time') ");
mysql_query("UPDATE `user` SET `fm_money` = '".($user['fm_money']-$fasi)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Вы успешно купили тренера!');
}
}
err();


if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `id_club` = '$klubi[id]'"),0)==0 && $user['id']==$ank['id'])
{
echo "<div class='menu'>Имя тренера:<br />\n";
echo "<form method='post' action='coach.php?set'><div>\n";
echo "<input type='text' name='nick' value='' maxlength='32' /><input class='doctor' type='submit' name='save' value='Купить' />\n";
echo "</div>\n";
echo "</form>\n";
echo "<br />*Стоимость $fasi$";
echo "</div>";
}
else
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `id_club` = '$klubi[id]' LIMIT 1"),0)==0){header("Location: index.php?".SID);exit;}
$coach=mysql_fetch_array(mysql_query("SELECT * FROM `fm_coach` WHERE `id_club` = '$klubi[id]' LIMIT 1"));
if (isset($_GET['del']) && $user['id']==$ank['id'])
{
echo "<div class='menu'>\n";
echo "Удалить тренер?\n";
echo "[<a href='club.php?del=$coach[id]'>Да</a>][<a href='coach.php?'>Нет</a>]<br />\n";
echo "</div>\n";
}
echo'<div class="frends2"><center><img src="icon/b_vrat.jpg" width="128" height="150" alt="Karson" /></center></div>';
echo "<div class='frends2'>";
echo "Владелец: <a href='/info.php?id=$ank[id]'>$ank[nick]</a><br />";
echo "Имя: <b>$coach[name]</b>\n";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_coach` WHERE `id` = '$coach[id]' and `timedar` > '".($time-3600)."'"),0)==1){$feri='green';}else{$feri='red';}
if ($user['id']==$ank['id'])echo "[<a href='coach.php?dar'><b><span style='color:$feri'>о</span></b></a>]\n";


if ($user['id']==$ank['id'])echo "[<a href='coach.php?del'><b><span style='color:#FF0000'>x</span></b></a>]\n";
echo "<br />Клуб:\n";
$klubi2=mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_club` WHERE `id` = '$klubi[id]'"),0);
if ($klubi2==1){echo "<a href='club.php?id=$ank[id]'>$klubi[name]</a><br />";}
else 
{
if ($user['id']==$ank['id']){echo "<a href='club.php'>Купить</a><br />";}else{echo "У него нет!<br />";}
}
echo "Игроки:\n";
$gamers=mysql_result(mysql_query("SELECT COUNT(*) FROM `fm_gamers` WHERE `id_club` = '$klubi[id]'"),0);
if ($gamers==0){echo "У него нет!<br />";}
else 
{
echo "[<a href='gamers.php?id=$ank[id]'>$gamers</a>]<br />";
}
echo "Уровень: $coach[level]<br/>";
echo "Работает с: ".vremja($coach["time"])."<br/>";
echo "</div>";
}
echo "<div class='foot'>";
echo "&#171; <a href='index.php'>Назад</a><br/>";
echo "</div>";

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

?>