<?
include_once('_incl_data/__config.php');
define('GAME',true);
include_once('_incl_data/class/__db_connect.php');
include_once('_incl_data/class/__user.php');
define('LOWERCASE',3);
define('UPPERCASE',1);

	$uplogin = explode('&',$_SERVER['QUERY_STRING']);
	$uplogin = $uplogin[0];
	$uplogin = preg_replace('/%20/'," ",$uplogin);	
	if(!isset($_GET['id']))
	{
		$_GET['id'] = 0;
	}	
	if(!isset($upLogin)){ $upLogin = ''; }
	$utf8Login = '';
	$utf8Login2 = '';
	$utf8Login  = iconv("utf-8", "windows-1251",$uplogin);	
	if($uplogin == 'delete' || $utf8Login == 'delete' || $utf8Login2 == 'delete') {
		
	}else{
		$clan = mysql_fetch_array(mysql_query('SELECT `u`.* FROM `clan` AS `u` WHERE (`u`.`id`="'.mysql_real_escape_string($_GET['id']).'" OR `u`.`id`="'.mysql_real_escape_string($uplogin).'" OR `u`.`name`="'.mysql_real_escape_string($uplogin).'") LIMIT 1'));
	}	
	if(!isset($clan['id']))	{
		die('<html><head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
		<meta http-equiv="Content-Language" content="ru">
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
		<TITLE>Произошла ошибка</TITLE></HEAD><BODY text="#FFFFFF"><p><font color=black>
		Произошла ошибка: <pre>Указанный клан не найден...</pre>
		<b><p><a href = "javascript:window.history.go(-1);">Назад</b></a>
		<HR>
		<p align="right">(c) <a href="index.html">'.$c['title'].'</a></p>
		'.$c['counters'].'
		</body></html>');
	}	
	
	$xu = mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `users` WHERE `real` = 1 AND `clan` = "'.$clan['id'].'" LIMIT 1'));
	$xu = 0 + $xu[0];
	$r1 = mysql_fetch_array(mysql_query('SELECT * FROM `aaa_clan_reting_list` WHERE `clan` = "'.$clan['id'].'" AND `date` = "'.date('dmY').'" LIMIT 1'));
	$r2 = mysql_fetch_array(mysql_query('SELECT * FROM `aaa_clan_reting_list` WHERE `clan` = "'.$clan['id'].'" AND `date` != "'.date('dmY').'" ORDER BY `id` DESC LIMIT 1'));
	
	$vid = '';
	if( isset($r2['pos']) ) {
		if( $r2['pos'] < $r1['pos'] ) {
			$vid = '<span style=\'color:red;\'>-'.($r1['pos']-$r2['pos']).'</span>';
		}elseif( $r2['pos'] > $r1['pos'] ) {
			$vid = '<span style=\'color:green;\'>+'.($r2['pos']-$r1['pos']).'</span>';
		}
	}
	
	$clan_info = mysql_fetch_array(mysql_query('SELECT * FROM `clan_info` WHERE `id` = "'.$clan['id'].'" LIMIT 1'));
	if( $clan_info['info'] == '' ) {
		$clan_info['info'] = '<i>Информация о клане отсутствует.</i>';
	}
	
	$vid1 = '';
	if( isset($r2['pos']) ) {
		if( round($r2['global']/(15678+$r2['level']),3) < round($r1['global']/(15678+$r1['level']),3) ) {
			$vid1 = '&nbsp;<sup><span style=\'color:green;\'>+'.(round($r1['global']/(15678+$r1['level']),3) - round($r2['global']/(15678+$r2['level']),3)).'</span></sup>';
		}elseif( round($r2['global']/(15678+$r2['level']),3) > round($r1['global']/(15678+$r1['level']),3) ) {
			$vid1 = '&nbsp;<sup><span style=\'color:red;\'>-'.(round($r2['global']/(15678+$r2['level']),3) - round($r1['global']/(15678+$r1['level']),3)).'</span></sup>';
		}
	}
	
	$vid2 = '';
	if( isset($r2['pos']) ) {
		if( $r2['exp_real'] < $r1['exp_real'] ) {
			$vid2 = '&nbsp;<sup><span style=\'color:green;\'>+'.($r1['exp_real']-$r2['exp_real']).'</span></sup>';
		}elseif( $r2['exp_real'] > $r1['exp_real'] ) {
			$vid2 = '&nbsp;<sup><span style=\'color:red;\'>-'.($r2['exp_real']-$r1['exp_real']).'</span></sup>';
		}
	}
	
	$vid3 = '';
	if( isset($r2['pos']) ) {
		if( $r2['win'] < $r1['win'] ) {
			$vid3 = '&nbsp;<sup><span style=\'color:green;\'>+'.($r1['win']-$r2['win']).'</span></sup>';
		}elseif( $r2['win'] > $r1['win'] ) {
			$vid3 = '&nbsp;<sup><span style=\'color:red;\'>-'.($r2['win']-$r1['win']).'</span></sup>';
		}
	}
	
	$vid4 = '';
	if( isset($r2['pos']) ) {
		if( $r2['lose'] < $r1['lose'] ) {
			$vid4 = '&nbsp;<sup><span style=\'color:red;\'>+'.($r1['lose']-$r2['lose']).'</span></sup>';
		}elseif( $r2['lose'] > $r1['lose'] ) {
			$vid4 = '&nbsp;<sup><span style=\'color:green;\'>-'.($r2['lose']-$r1['lose']).'</span></sup>';
		}
	}
	
	$vid5 = '';
	if( isset($r2['pos']) ) {
		if( $r2['nich'] < $r1['nich'] ) {
			$vid5 = '&nbsp;<sup><span style=\'color:red;\'>+'.($r1['nich']-$r2['nich']).'</span></sup>';
		}elseif( $r2['nich'] > $r1['nich'] ) {
			$vid5 = '&nbsp;<sup><span style=\'color:green;\'>-'.($r2['nich']-$r1['nich']).'</span></sup>';
		}
	}

		$timday=strtotime('now 00:00:00');
		$clanw = mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `battle` WHERE  `type` = 250 AND `time_over` > "'.$timday.'" AND ((`team_win`=1 AND `clan1` = "'.$clan['id'].'") OR (`team_win`=2 AND `clan2` = "'.$clan['id'].'")) LIMIT 1'));
		$clanw = $clanw[0];
		
		$clanl = mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `battle` WHERE  `type` = 250 AND `time_over` > "'.$timday.'" AND ((`team_win`=2 AND `clan1` = "'.$clan['id'].'") OR (`team_win`=1 AND `clan2` = "'.$clan['id'].'")) LIMIT 1'));
		$clanl = $clanl[0];
		
		$clanwar = mysql_query('SELECT * FROM `clan_wars` WHERE (`clan1`="'.$clan['id'].'" OR `clan2`="'.$clan['id'].'") AND `time_finish` > "'.time().'"');
		$clwe = "";
		while($clanwa = mysql_fetch_array($clanwar))
			{
				if ($clanwa['clan1'] == $clan['id']) 
				{
					$clw = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "'.$clanwa['clan2'].'" LIMIT 1'));
					
					$clwe .= '<img style="vertical-align:bottom" src="https://img.new-combats.com/i/clan/'.$clw['name'].'.gif"><b>'.$clw['name'].' </b>';
				}
				else
				{
					$clw = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "'.$clanwa['clan1'].'" LIMIT 1'));
					$clwe .= '<img style="vertical-align:bottom" src="https://img.new-combats.com/i/clan/'.$clw['name'].'.gif"><b>'.$clw['name'].' </b>';
					
				}
			}
		
		
		
	
?>
<HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>Информация о клане <?=$clan['name']?></title>
<meta content="text/html; charset=windows-1251" http-equiv=Content-type>
<link href="https://img.new-combats.com/i/move/design3.css" rel="stylesheet" type="text/css">
<link href="https://img.new-combats.com/css/main.css" rel="stylesheet" type="text/css">
<link href="/res/css/style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery.js"></script>
<META Http-Equiv=Cache-Control Content="no-cache, max-age=0, must-revalidate, no-store">
<meta http-equiv=PRAGMA content=NO-CACHE>
<META Http-Equiv=Expires Content=0>
</HEAD>
<body style="margin:10px; margin-top:5px; background-repeat:no-repeat; background-position: top right" bgcolor=e2e0e0>
<div id="main" style="margin: 5px 5px 0 5px;">
<table width=100%><tr>
  <td style="background: #C7C7C7; border: 1px solid #A6A5A3; padding: 4px 20px 4px 20px;">
    <h3 style="width: 250px; float: left;"><?=$clan['name']?></h3>
    <h3 style="width: 250px; float: right;"><a href="/rating_clans#<?=$clan['id']?>" target="_blank">Позиция: <?=(0+$r1['pos'])?></a> <sup><?=$vid?></sup></h3>
    <h3>Рейтинг: <?=round($r1['global']/(15678+$r1['level']),3).$vid1?></sup></h3>
  </td>
</tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top">
    <div style="padding-right:60px;">
    <fieldset id="aboutclan" style="border: 1px solid white; display: block; float:left; clear: left; width:100%;min-height:20px; padding:10px; margin-top:15px;">
    <legend style='font-weight:bold; color:#8F0000;'>Информация о Клане <?=$clan['name']?></legend>
    <?=$clan_info['info']?>
	</fieldset>
	<fieldset id="aboutclan" style="border: 1px solid white; display: block; float:left; clear: left; width:100%;min-height:20px; padding:10px; margin-top:15px;">
   <legend style='font-weight:bold; color:#8F0000;'>Клан сайт:</legend> <a href="<?=$clan['site'];?>" target="_blank"> <?=$clan['site'];?> </a>
	
	</fieldset>
    
    <fieldset id="statclan" style="border: 1px solid white; display: block; float:left; clear: left; width:100%;min-height:100px; padding: 10px; margin-top:15px;margin-bottom: 15px;">
    <legend style='font-weight:bold; color:#8F0000;'>Статистика Клана</legend>
    <table width="100%" cellpadding="0" cellspacing="0">
    <tr><td width="150"><b>Рейтинг:</b></td>
    <td><?=round($r1['global']/(15678+$r1['level']),3).$vid1?></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    <tr><td width="150"><b>Опыт:</b></td>
    <td><?=number_format($r1['exp_real'], 0, ",", " ").$vid2?></td></tr>
    <tr><td width="150"><b>Позиция:</b></td><td><span title="Позиция клана в общем рейтинге"><a href="/rating_clans#<?=$clan['id']?>" target="_blank"><?=(0+$r1['pos'])?></a></span> <sup title="Изменение позиции клана за день"><?=$vid?></sup></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    <tr><td colspan="2"><b><font color=green>Статистика персонажей:</font></b></td></tr>
    <tr><td width="150"><b>Побед:</b></td>
    <td><?=number_format($r1['win'], 0, ",", " ").$vid3?></td></tr>
    <tr><td width="150"><b>Поражений:</b></td>
    <td><?=number_format($r1['lose'], 0, ",", " ").$vid4?></td></tr>
    <tr><td width="150"><b>Ничьих:</b></td>
      <td><?=number_format($r1['nich'], 0, ",", " ").$vid5?></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    <tr><td colspan="2"><b><font color=#A00>Статистика войн:</font></b></td></tr>
    <tr><td width="150"><b>Текущие войны:</b></td>
	  <td><span><? echo $clwe;?></span></td></tr>
	<tr><td width="150"><b>Побед:</b></td>
      <td><span><? echo $clanw;?></span></td></tr>
    <tr><td width="150"><b>Поражений:</b></td>
    <td><span><? echo $clanl;?></span></td></tr>
	<tr><td colspan="2">&nbsp;</td></tr>
    <tr><td width="150"><b>Ожидаемый рейтинг:</b></td><td><span><?echo ($clanw-$clanl)*10000;?></span></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    <tr><td width="150"><b>Дата регистрации:</b></td><td><span title="Дата регистрации клана"><?=date('d.m.Y',$clan['time_reg'])?></span></td></tr>
    </table>
    </fieldset>
    </div>
    </td>
    <td width="400" align="left" valign="top">    
    <div style="width:390px;display: block;">     
    <fieldset id="clansostav" style="width:390px; border: 1px solid white; display: block; clear:right; float: right; padding: 10px;margin-top:15px;">
    <legend style='font-weight:bold; color:#8F0000;'>Состав</legend>
    
    <?
	$sp = mysql_query('SELECT * FROM `users` WHERE `clan` = "'.$clan['id'].'" AND `clan_prava` = "glava" ORDER BY `login` ASC');
	$html = '';
	while( $pl = mysql_fetch_array($sp) ) {
		if( $pl['online'] < time() - 520 ) {
			$html .= '<div style="color:grey">';
		}else{
			$html .= '<div>';
		}
		$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align'].'.gif"> ';
		if( $pl['align2'] > 0 ) {
			$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align2'].'.gif"> ';
		}
		$html .= '<img src="https://img.new-combats.com/i/clan/'.$clan['name'].'.gif"> ';
		$html .= '<b>'.$pl['login'].'</b> ['.$pl['level'].']';
		$html .= ' <a href="/info/'.$pl['id'].'" target="_blank"><img src="https://img.new-combats.com/i/inf_capitalcity.gif"></a>';
		$html .= ' <small>- <font color=#008080><b>Глава клана</b></font></small>';
		if( $pl['online'] < time() - 520 ) {
			$html .= '&nbsp; <sup><i>не в игре</i></sup></div>';
		}else{
			$html .= '</div>';
		}
	}
	
	$html .= '<br>';
	
	$sp = mysql_query('SELECT * FROM `users` WHERE `clan` = "'.$clan['id'].'" AND `clan_prava` != "glava" AND `online` > "'.(time()-520).'" ORDER BY `login` ASC');
	while( $pl = mysql_fetch_array($sp) ) {
		$html .= '<div>';
		$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align'].'.gif"> ';
		if( $pl['align2'] > 0 ) {
			$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align2'].'.gif"> ';
		}
		$html .= '<img src="https://img.new-combats.com/i/clan/'.$clan['name'].'.gif"> ';
		$html .= '<b>'.$pl['login'].'</b> ['.$pl['level'].']';
		$html .= ' <a href="/info/'.$pl['id'].'" target="_blank"><img src="https://img.new-combats.com/i/inf_capitalcity.gif"></a>';
		$html .= ' <small>- '.$pl['mod_zvanie'].'</small>';
		$html .= '</div>';
	}
	$sp = mysql_query('SELECT * FROM `users` WHERE `clan` = "'.$clan['id'].'" AND `clan_prava` != "glava" AND `online` <= "'.(time()-520).'" ORDER BY `login` ASC');
	while( $pl = mysql_fetch_array($sp) ) {
		$html .= '<div style="color:grey">';
		$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align'].'.gif"> ';
		if( $pl['align2'] > 0 ) {
			$html .= '<img src="https://img.new-combats.com/i/align/align'.$pl['align2'].'.gif"> ';
		}
		$html .= '<img src="https://img.new-combats.com/i/clan/'.$clan['name'].'.gif"> ';
		$html .= '<b>'.$pl['login'].'</b> ['.$pl['level'].']';
		$html .= ' <a href="/info/'.$pl['id'].'" target="_blank"><img src="https://img.new-combats.com/i/inf_capitalcity.gif"></a>';
		$html .= ' <small>- '.$pl['mod_zvanie'].'</small>';
		$html .= '&nbsp; <sup><i>не в игре</i></sup></div>';
	}
	echo $html;
	unset($html);
	?>
    
    <br />Всего: <b><?=(0+$xu)?></b>
    </fieldset>
    </div>    
    </td>
  </tr>
  </table>
</div>
</body>
</HTML>
