<?php
define('_IN_JOHNCMS', 1);
$headmod = 'manager';
$textl='O`rtoqlik o`yini o`tkazish.';
require_once("../incfiles/core.php");
require_once("../incfiles/head.php");
require_once("manfunc.php");

if($id)
{
	$q=mysql_query("select * from fman_clubs where id=$id;");
	$a=mysql_fetch_array($q);

	$qu=mysql_query("select * from users where id=$a[user_id];");
	$udata=mysql_fetch_array($qu);
echo"<h2 align='center'>$textl Jamoa $a[name]</h2>";
	if($_POST[otkl])
	{
		$cid=intval($_POST[club_id]);
		if($a[id]==$club_id)
		{
			$wtext=' <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> jamoasining rahbariyati sizning o`rtoqlik o`yini o`tkazish to`g`risidagi taklifingizni rad etdi.';
			mysql_query("insert into `privat` set `user`='$_POST[name]', `text`='$wtext', `time`='$realtime', `author`='Futbol menejer', `type`='in', `chit`='no', `temka`='Sizning taklifigiz rad etildi!'");

			$usid=$_POST[usid];
			$qus=mysql_query("select text from privat where id=$usid;");
			$aus=mysql_fetch_array($qus);
			$atext=str_replace('<input type="submit" name="prin" value="Qabul qilish"/><br/><input type="submit" name="otkl" value="Rad etish"/>','',$aus[text]);
			mysql_query("update privat set text='$atext' where id=$usid");
			echo"<div class='menu'>Harakat ijobiy bajarildi! Siz o`rtqolik o`yini to`g`risidagi taklifni rad etdingiz!</div>";
		}
	}
	else
	{
		if($_POST[prin])
		{

			$cid=intval($_POST[club_id]);

			$pole=$_POST[pole];

			$tm=$realtime+600;
			$res1=mysql_result(mysql_query("select count(*) from fman_matches where (id1=$club_id or id2=$club_id) and time<".($tm+600)." and time>".($tm-600).";"),0);
			$res2=mysql_result(mysql_query("select count(*) from fman_matches where (id1=$cid or id2=$cid) and time<".($tm+600)." and time>".($tm-600).";"),0);
			if($res1 || $res2)$e='Xato! O`yin o`tkazish mumkin emas, chunki jamoalardan biri parallel o`yin o`tkazayabdi.';
			if($a[id]!=$club_id)$e='Xato!';
			if($e)echo"<div class='rmenu'>$e</div>"; else{
			$wtext=' <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> jamoasining rahbariyati sizning o`rtoqlik o`yini o`tkazish to`g`risidagi taklifni qabul qildi. O`yin  '.functions::display_date($tm).' o`tkaziladi.';
			mysql_query("insert into `privat` set `user`='".functions::check($_POST[name])."', `text`='$wtext', `time`='$realtime', `author`='Futbol menejer', `type`='in', `chit`='no', `temka`='Sizning taklifingiz qabul qilindi!'");
			$qc1=mysql_query("select * from fman_clubs where id=$cid;");
			$cdata=mysql_fetch_array($qc1);
			if($pole==1){$kom1=$cdata[name]; $id1=$cid; $kom2=$club_name; $id2=$club_id;}
			if($pole==2){$kom2=$cdata[name]; $id2=$cid; $kom1=$club_name; $id1=$club_id;}
			mysql_query("insert into fman_matches set time=$tm, turn='tm', tur=1, end=0, kom1='$kom1', id1=$id1, kom2='$kom2', id2=$id2, sc1=0, sc2=0");

			$usid=(int)$_POST[usid];
			$qus=mysql_query("select text from privat where id=$usid;");
			$aus=mysql_fetch_array($qus);
			$atext=str_replace('<input type="submit" name="prin" value="Qabul qilish"/><br/><input type="submit" name="otkl" value="Rad etish"/>','',$aus[text]);
			mysql_query("update privat set text='$atext' where id=$usid");
			echo"<div class='menu'>Harakat ijobiy bajarildi! $kom1 - $kom2 jamoalari o`rtasida o`rtoqlik o`yini ".functions::display_date($tm)." o`tkaziladi.</div>";
			}
		}
		else
		{
			if(!$_POST[submit])
			{
				echo"<form action='tm.php?id=$id' method='post'><div class='menu'>
Qayerda o`yin o`tkazishni xohlashingizni ko`rsating:<br/>
				<input type='radio' name='pole' value='1' checked='checked'/> Uyda<br/>
				<input type='radio' name='pole' value='2'/> Safarda<br/>
				<input type='submit' name='submit' value='Jo`natish'/></div></form>";
			}
			else
			{
				if($_POST[pole]==2)$pole1="Uyda";

				if($_POST[pole]==1)$pole1="Safarda";
$wtext='Sizga <a href="/man/club.php?id='.$club_id.'">'.$club_name.'</a> jamoasi rahbariyatidan ('.$pole1.') o`rtoqlik o`yini o`tkazish to`g`risida taklif tushdi. Siz taklifni qabul qilishingiz yoki rad etishingiz mumkin. O`yin taklif qabul qilingach 10 daqiqadan so`ng boshlanadi.<form action="/man/tm.php?id='.$id.'" method="post"><input type="hidden" name="pole" value="'.$_POST[pole].'"/><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="Rad etish"/></form>';
				mysql_query("insert into `privat` set `user`='$udata[name]', `text`='$wtext', `time`='$realtime', `author`='Futbol menejeri', `type`='in', `chit`='no', `temka`='O`rtoqlik o`yini o`tkazish taklifi'");

				$usid=mysql_insert_id();
				$qus=mysql_query("select text from privat where id=$usid;");
				$aus=mysql_fetch_array($qus);
				$atext=str_replace('<input type="hidden" name="club_id" value="'.$club_id.'"/>','<input type="hidden" name="club_id" value="'.$club_id.'"/><input type="hidden" name="usid" value="'.$usid.'"/>',$aus[text]);
				mysql_query("update privat set text='$atext' where id=$usid");
				echo"<div class='menu'>Sizning taklifingiz jamoa rahbariyatiga jonatildi! Javobni ichki pochta orqali kuting.</div>";
			}
		}
	}
	echo"<div class='phdr'><a href='club.php?id=$id'>$a[name]</a><br/><a href='index.php'>Futbol menejer</a></div>";
}
require_once("../incfiles/end.php"); 
?>