<?php
define('_IN_JOHNCMS', 1);
$headmod = 'manager';
$textl='$a[name]'; 
require_once("../incfiles/core.php");
require_once("../incfiles/head.php");
require_once("manfunc.php"); 

$q=mysql_query("select * from fman_players where id=$id;");
$a=mysql_fetch_array($q);

if($_POST[stavka])
{
	if($a[trans_time]>=time())
	{
		$cena=($_POST[cena]*500000)+$a[cena];
		if($dataclub[budj]>=$cena)
		{
			if($realtime>($a[trans_time]-60))$a[trans_time]=$a[trans_time]+180;
			mysql_query("update fman_players set cena=$cena, zarplat=$club_id, trans_time=$a[trans_time] where id=$a[id]");
			$q=false; $a=false;
			$q=mysql_query("select * from fman_players where id=$id;");
			$a=mysql_fetch_array($q);
			$er="Sizning stavkangiz qabul qilindi!";
		}
		else 
			$er="Sizda stavka uchun yetarli mablag` yo`q!";
	}
	else
		$er="Stavkalar qabul qilish vaqti tugadi!";
}
if($er)echo"<div class='bmenu'>$er</div>";

$qt=mysql_query("select * from fman_clubs where id=$a[team_id];");
if($qt)$tdata=mysql_fetch_array($qt);

$qu=mysql_query("select * from users where id=$tdata[user_id];");
if($qu)$udata=mysql_fetch_array($qu);

$market=(1000000*$a[rait])+(($a[u]+$a[vyn]+$a[ig]+$a[otb]+$a[drib]+($a[gk]*4)+$a[f]+$a[toch]+$a[priem]+$a[pas])*500000);

switch($act)
{
	default:
	echo"<div class='phdr'>$a[name]</div>";
		$zarplat=round($market/800);
	echo"<table border='0' cellpadding='0' cellspacing='0' width='100%'><tbody>
<tr><th rowspan='6' class='tab_f' width='140px'><img src='$a[foto]' alt='$a[name]' style='max-height:120px; max-width:115px;'/></th></tr>
<tr><td class='list2' style='padding: 7px;'><b>Yoshi:</b> $a[age]</td></tr>
<tr><td class='list2' style='padding: 7px;'><b>Pozitsiya:</b>".strtr($a[ampl],array(10=>'Hujumchi (Н)',1=>'Darvozabon (D)',2=>'Chap Qanot Himoyachisi (CHQH)',3=>'Markaziy Himoyachi (MH)',4=>'O`ng Qanot Himoyachisi (O`QH)',5=>'Tayancha Yarim Himoyachisi (TYH)',6=>'Chap Qanot Yarimhimoyachisi (CHQY)',7=>'Markaziy Yarim Himoyachi (MYH)',8=>'O`ng Qanot Yarimhimoyachisi (O`QY)',9=>'Hujumkor Yarim Himoyachi (HY)'))."</td></tr>
<tr><td class='list2' style='padding: 7px;'><b>Iqtidor:</b> $a[rait]</td></tr>
<tr><td class='list2' style='padding: 7px;'><b>Tajriba bal:</b> $a[ball]</td></tr>";

if($a[team_id]) echo"<tr><td class='list2' style='padding: 7px;'><b>Klub:</b> <a href='club.php?id=$a[team_id]'> $tdata[name]</a></td></tr>";
echo"</tbody></table>";


echo"<div class='phdr'>Xarakteristika</div>";
echo"<table class='table' width='100%' cellspacing='1' cellpadding='6'>
	<tr class='list2'><td>Fuqaroligi</td><td align='center' width='20%'>$a[nationality]</td></tr>
	<tr class='list2'><td>Ampula</td><td align='center' width='20%'>".strtr($a[ampl],array(10=>'Hujumchi',1=>'Darvozabon',2=>'Chap Qanot Himoyachisi',3=>'Markaziy Himoyachi',4=>'O`ng Qanot Himoyachisi',5=>'Tayancha Yarim Himoyachisi',6=>'Chap Qanot Yarimhimoyachisi',7=>'Markaziy Yarim Himoyachi',8=>'O`ng Qanot Yarimhimoyachisi',9=>'Hujumkor Yarim Himoyachi'))."</td></tr>
	<tr class='list2'><td>Tajriba bal</td><td align='center' width='20%'>$a[ball]</td></tr>
	<tr class='list2'><td>Bo'yi</td><td align='center' width='20%'>$a[height]</td></tr>
	<tr class='list2'><td>Maoshi</td><td align='center' width='20%'>$".number_format($zarplat,0,'.',' ')."/virt. hafta</td></tr>
	<tr class='list2'><td>Transfer narxi</td><td align='center' width='20%'>$".number_format($market,0,'.',' ')."</td></tr></table>";
$uri=$a[$nav]+1;
$nbi=$uri*40;
	
	echo"<div class='phdr'>Ko'rsatkichlari</div>";
	for($i=1;$i<11;$i++){
	$nav=strtr($i,array(1=>'u',2=>'vyn',3=>'drib',4=>'pas',5=>'priem',6=>'otb',7=>'ig',8=>'f',9=>'toch',10=>'gk'));
	$navr=strtr($i,array(1=>'<img src="/man/skill/speed.png"> Tezlik',2=>'<img src="/man/skill/vr.png"> Chidamlilik',3=>'<img src="/man/skill/dribl.png"> Dribling',4=>'<img src="/man/skill/pas.png"> Pаs',5=>'<img src="/man/skill/vr.png"> Usul',6=>'<img src="/man/skill/opeka.png"> Jamoa',7=>'<img src="/man/skill/golova.png"> Bosh b.n o`yin',8=>'<img src="/man/skill/tehn.png"> Zarba kuchi',9=>'<img src="/man/skill/udar.png"> Zarba aniqligi',10=>'<img src="/man/skill/reakcia.png"> Darvozabonlik qobilyati'));
	echo"<div class='list2'>$navr: $a[$nav]"; if($club_id==$a[team_id])echo" <a href='player.php?act=pod&amp;nav=$nav&amp;id=$id'>[<i class='fa fa-arrow-circle-o-up'></i> UP]</a>"; echo"</div>";}

	if($a[trans])
	{
		echo"<div class='phdr'>O`yinchini sotish. Аuksion</div>
		<div class='menu'>Stavkani oshirish: ".functions::display_date($a[trans_time])."</div>
		<div class='menu'>Hozirgi stavka: <b>$".number_format($a[cena],0,'.',' ')."</b>";
		if($a[zarplat])
		{
			$qw=mysql_query("select * from fman_clubs where id=$a[zarplat];");
			$wd=mysql_fetch_array($qw);
			if($a[zarplat]!=$club_id)echo" [<a href='club.php?id=$a[zarplat]'>$wd[name]</a>]"; else echo" [<b>$wd[name]</b>]";
		}
		echo"</div>";
		if($club_id && $realtime<$a[trans_time])
		{
			echo"<div class='menu'><form action='player.php?id=$id' method='post'>Siz ko`tarishni hohlagan stavka summasi:<br/><select name='cena'>";
			for($i=1;$i<21;$i++)echo"<option value='$i'>".($i*500000)."</option>";
			echo"</select><br/><input type='submit' name='stavka' value='Stavka qilish'/></form>[<a href='player.php?id=$id&amp;mytime=$realtime'>sahifani yangilash</a>]</div>";
		}
	}
	if($club_id && !$a[trans] || $club_id==$a[team_id])
		echo"<div class='phdr'>Harakat</div><div class='menu'>";

	if($club_id==$a[team_id])
	{
echo"<a href='list-of-players.php?id=$a[team_id]&amp;act=uvol&amp;pid=$a[id]'>Bo`shatish</a><br/>";
if($a[trans]!=1)echo"<a href='list-of-players.php?id=$a[team_id]&amp;act=trans&amp;pid=$a[id]'>Sotish</a><br/>";
	}
	else
	{
if(!$a[trans])echo"<a href='player.php?id=$id&amp;act=buy'>Sotib olish</a><br/>";
	}
if($rights>=7)echo"<a href='admplayer.php?id=$id'>O`zgartirish</a><br/>";
	if($club_id && !$a[trans] || $club_id==$a[team_id])echo"</div>";
	break;
	
	
	case 'pod':
$nav=$_GET[nav];
$ur=$a[$nav]+1;

$nb=$ur*40;
if($nav=="gk")$nb=$ur*80;
if ($ur>=0 && $ur < 21) {
if($a[ball]<$nb) echo"<div class='menu'>Futbolchining kuchini $ur ga oshirildi, futbochining tarjiba ballaridan $nb olib tashlandi!</div>"; else{
mysql_query("update fman_players set ".$nav."=".($a[$nav]+1).", ball=".($a[ball]-$nb)." where id=$a[id]");
echo"<div class='menu'>Siz o`yinchining bu iqtidorini $ur gacha ko`tardingiz, buning uchun $nb tajriba ballari sarf etdingiz!</div>";}
echo"<div class='phdr'><a href='player.php?id=$a[id]'>$a[name]</a></div>";
} else {
	echo"<div class='menu'>Futbolchining iqtidorini 20 dan oshira olmaysiz!</div>";
}

break;
case 'buy':
	

	if($_POST[otkl])
	{
		$cid=intval($_POST[club_id]);
		$cena=intval($_POST[cena]);
		if($a[team_id]==$club_id)
		{
			$wtext=' <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> klubi rahbariyati sizning  <a href="/man/player.php?id='.$id.'">'.$a[name].'</a> ni <b>$'.number_format($cena,0,'.',' ').'</b> ga transfer to`g`risidagi taklifingizni rad etdi.';
			mysql_query("insert into `privat` set `user`='".functions::check($_POST['name'])."', `text`='$wtext', `time`='$realtime', `author`='Futbol menejer', `type`='in', `chit`='no', `temka`='Transferingiz amalga oshmadi!'");
			echo"<div class='menu'>Harakat ijobiy bajarildi! Siz futbolchingiz transferi to`g`risidagi taklifni rad etdingiz!</div>";
		}
	}
	else
	{
		if($_POST[prin])
		{
			$cid=intval($_POST[club_id]);
			$cena=intval($_POST[cena]);
			
			if($a[team_id]!=$club_id || $a[trans])$e='Xato! O`yinchi tranferda yoki u jamoani almashtirgan.';
			if($e)echo"<div class='rmenu'>$e</div>"; 
			else
			{
				$qcw=mysql_query("select * from fman_clubs where id=$cid;");
				$ddata=mysql_fetch_array($qcw);
				$etext = '<a href="club.php?id='.$cid.'">'.$ddata['name'].'</a> klubi rahbariyati futbolchingiz <a href="/man/player.php?id='.$a['id'].'">'.$a['name'].'</a>ni transfer qildi. Transfer summasi <b>$'.number_format($cena,0,"." , " ").'</b> ni tashkil etdi.';
				$atext = 'Sizning klubingizga <a href="club.php?id='.$a['team_id'].'">'.$tdata['name'].'</a> klubidan <a href="player.php?id='.$a['id'].'">'.$a['name'].'</a> transfer qilindi. Transfer summasi <b>$'.number_format($cena,0,".", " ").'</b> ni tashkil etdi.';
				mysql_query("insert into fman_news set time=$realtime, pl_id=0, club_id=$a[team_id], text='$etext'");
				mysql_query("insert into fman_news set time=$realtime, pl_id=0, club_id=$cid, text='$atext'");
				$wtext=' <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> klubi rahbariyati sizning <a href="/man/player.php?id='.$id.'">'.$a[name].'</a>ni transfer qilish to`g`risidagi taklifingizni qabul qildi. Transfer summasi <b>$'.number_format($cena,0,'.',' ').'</b>.';
				mysql_query("insert into `privat` set `user`='$_POST[name]', `text`='$wtext', `time`='$realtime', `author`='Futbol Menejer', `type`='in', `chit`='no', `temka`='Transferingiz muvoffaqiyatli amalga oshdi'");
				mysql_query("update fman_players set team_id=$cid where id=$id");
				mysql_query("update fman_clubs set budj=".($tdata[budj]+$cena)." where id=$tdata[id]");
				mysql_query("update fman_clubs set budj=".($ddata[budj]-$cena)." where id=$ddata[id]");

				mysql_query("insert into fman_news set time='$realtime', pl_id='$id', name='$a[name]', id1='$club_id', id2='$ddata[id]', cena='$cena', club_id='0'");
				echo"<div class='menu'>Harakat ijobiy bajarildi! Siz o`yinchini sotdingiz! Zarur ma`lumotni jamoa jurnalidan topishingiz mumkin.</div>";
			}
		}
		else
		{
			if(!$_POST[submit])
			{
				echo"<div class='phdr'>O`yinchi sotib olish $a[name]</div>
				<form action='player.php?id=$id&amp;act=buy' method='post'><div class='menu'>
				Jamoa rahbariyatiga sizning taklifingiz (minimum $".$market."):<br/>
				<input type='text' name='market' value='$market'/><br/>
				<input type='submit' name='submit' value='Yuborish'/></div></form>";
			}
			else
			{
				$cena=intval($_POST[market]);
				if(!is_numeric($cena) || $cena<$market)$e="Xato! Taklifning minimal summasi $".$market."!";
				if($dataclub[budj]<$cena)$e="Xato! Sizda bu o`yinchini sotib olish uchun mablag` yetishmaydi!";
				
				if($e)
					echo"<div class='rmenu'>$e</div>"; 
				else
				{
					$wtext='Sizga <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> jamoasidan <a href="/man/player.php?id='.$id.'">'.$a[name].'</a> ni  <b>$'.number_format($cena,0,'.',' ').'</b> ga sotib olish to`g`risida taklif tushdi. Siz taklifni qabul qilishingiz yoki rad etishingiz mumkin.<form action="/man/player.php?id='.$id.'&amp;act=buy" method="post"><input type="hidden" name="cena" value="'.$cena.'"/><input type="hidden" name="club_id" value="'.$club_id.'"/><input type="hidden" name="name" value="'.$login.'"/><input type="submit" name="prin" value="Qabul qilish"/><br/><input type="submit" name="otkl" value="Bekor qilish"/></form>';
					mysql_query("insert into `privat` set `user`='$udata[name]', `text`='$wtext', `time`='$realtime', `author`='Futbol menejer', `type`='in', `chit`='no', `temka`='Futbolchini sotib olish taklifi'");
					echo"<div class='menu'>Sizning taklifinigiz jamoa rahbariyatiga jo`natildi! Javobni ichki pochta orqali kuting.</div>";
				}
			}
		}
	}
	echo"<div class='phdr'><a href='player.php?id=$a[id]'>$a[name]</a></div>";
	break;
} 
echo"<div class='phdr'><a href='club.php?id=$a[team_id]'>$tdata[name]</a><br/>
<a href='index.php'>Futbol Menejer</a></div>";
require_once("../incfiles/end.php"); ?>