<?php
define('_IN_JOHNCMS', 1);
$textl='Homiylar'; 
require_once("../incfiles/core.php");
require_once("../incfiles/head.php");
require_once("manfunc.php"); 

if(!$club_id)
{
	echo'Sizga klub kerakmi!';
}
else
{
	if(isset($_GET['new']))
	{
		$new = intval($_GET['new']);
		
		$sql = mysql_query("SELECT * FROM `fman_spons` WHERE `id`='$new' LIMIT 1");
		if(mysql_num_rows($sql))
		{
		
			$b = mysql_fetch_assoc($sql);
				
			if($b['pay']>$dataclub['budj'])
			{
				echo'Sizga kontraktni imzolash uchun mablag` yetishmaydi!<br/><a href="spons.php">Orqaga</a>';
			}
			else
			{
				mysql_query("DELETE FROM `fman_clubs_spons` WHERE `club_id`='$club_id'");
				mysql_query("INSERT INTO `fman_clubs_spons` SET `club_id`='$club_id', `sid`='$new'");
				mysql_query("UPDATE `fman_clubs` SET `budj`=`budj`-'$b[pay]',`spons`='$b[plus]' where `id`='$club_id' limit 1");
				echo'<div class="list2">Siz homiy bilan kontrakt imzoladingiz <b>'.$b['name'].'</b>!</div><div class="menu"><a href="spons.php">Orqaga</a></div>';
			}
		}
		else
		{
			echo'<div class="list2">Bunday homiy yo`q!</div><div class="menu"><a href="spons.php">orqaga</a></div>';
		}
	}
	elseif(isset($_GET['club']))
	{
		$club = intval($_GET['club']);
		
		$sql = mysql_query("SELECT `name` FROM `fman_clubs` WHERE `id`='$club' LIMIT 1");
		if(mysql_num_rows($sql))
		{
			$datac = mysql_fetch_assoc($sql);
			echo'<div class="phdr"><b>'.$datac['name'].' homiylari</b></div>';
			$sql = mysql_query("SELECT `fman_clubs_spons`.*,`fman_spons`.* FROM `fman_clubs_spons` LEFT JOIN `fman_spons` ON `fman_spons`.`id`=`fman_clubs_spons`.`sid` WHERE `club_id`='$club'");
			if(mysql_num_rows($sql))
			{
				echo
				'
					<table cellpadding="2" rules="rows" style="border:1px solid grey;margin:3px;">
				';
				
				
				while($b = mysql_fetch_assoc($sql))
				{
					echo'<tr><td><img width="100" height="50" src="spons/'.$b['pic'].'" /></td><td><b>'.$b['name'].', $'.$b['pay'].'</b><br/>O`yin uchun foyda: <b>$'.$b['plus'].'</b></td></tr>';
				}
				
				echo'</table>';
			}
			else
			{
				echo'Klubda <b>'.$datac['name'].'</b> homiy yo`q!';
			}
		}
		else
		{
			echo'Bunday klub yo`q!';
		}
		
	}	
	else
	{
		$new = intval($_GET['new']);
		$sql = mysql_query("SELECT *,(select count(*) from `fman_clubs_spons` where `fman_clubs_spons`.`sid`=`fman_spons`.`id` and `fman_clubs_spons`.`club_id`='$club_id') as `yes` FROM `fman_spons` HAVING `yes`='0'");
		if(mysql_num_rows($sql))
		{
			echo
			'
				<div class="phdr"><b>Mavjud qarshi hujumlar</b></div>
				<table cellpadding="2" rules="rows" style="border:1px solid grey;margin:3px;">
			';
			
			
			while($b = mysql_fetch_assoc($sql))
			{
				echo'<tr><td><img width="100" height="50" src="spons/'.$b['pic'].'" /></td><td><b>'.$b['name'].', $'.$b['pay'].'</b><br/>O`yin uchun foyda: <b>$'.$b['plus'].'</b><br/><a href="spons.php?new='.$b['id'].'"><button>Kontrakt</button></a></td></tr>';
			}
			
			echo'</table>';

			$sql = mysql_query("SELECT `fman_clubs_spons`.*,`fman_spons`.* FROM `fman_clubs_spons` LEFT JOIN `fman_spons` ON `fman_spons`.`id`=`fman_clubs_spons`.`sid` WHERE `club_id`='$club_id' limit 1");
			if(mysql_num_rows($sql))
			{
			echo
			'
				<div class="phdr"><b>Mening homiyim</b></div>
				<table cellpadding="2" rules="rows" style="border:1px solid grey;margin:3px;">
			';
				
				
				$b = mysql_fetch_assoc($sql);
				
				echo'<tr><td><img width="100" height="50" src="spons/'.$b['pic'].'" /></td><td><b>'.$b['name'].', $'.$b['pay'].'</b><br/>O`yin uchun foyda: <b>$'.$b['plus'].'</b></td></tr>';
				
				echo'</table>';
			}				
			
		}
	}	
	echo"<div class='phdr'><a href='index.php'>Futbol menejer</a></div>";	
}

require_once("../incfiles/end.php"); 
?>