<?php
	
	include_once __DIR__ . '/include/common.php';
	include_once __DIR__ . '/include/general_functions.php';
	include_once __DIR__ . '/include/utils.php';	
	include_once __DIR__ . '/include/user.php';
	
	if ( ! @$user)
			redirect('/');
	
	$params	=	[];
	$params['title']	=	'Зал славы';
	
	ob_start();
	
	include_once __DIR__ . '/include/header.php';
	
	?>
	<div class='title'>Зал славы</div>
	<?php
	
	$sql	=
		'SELECT
				*
			FROM
				`users`
		';
	
	$items	=	@mysql_num_rows(@mysql_query($sql));
	$items_per_page	=	10;
	$pages	=	c_page($items, $items_per_page);
	$page	=	page($pages);
	$sql	.=	'
			ORDER BY
				`str`+`dex`+`life`+`protection`	DESC,
				`level`	DESC,
				`id`	DESC,
				`lastActive`	DESC';
		
	$at		=	($page	-	1)	*	$items_per_page;
	$sql	.=	sprintf(
		'
			LIMIT
				%d, %d',
		$at,
		$items_per_page
	);
	$query	=	@mysql_query($sql);
	if ($items != 0)
	{
		
		$place	=	$page	*	$items_per_page	-	$items_per_page;
		
	?>
	<div class='container'>
	<?php
		while	(
			$info	=	@mysql_fetch_assoc($query)
		)
		{
			
			/*@mysql_query(sprintf(
				'INSERT INTO
						`duel`
						(`uid`)
						VALUES
						(%d)',
				$info['id']
			));*/
			
			++$place;
			
			if ($place	==	1)
			{
				
				$equip	=	[];
					
				for	(
						$i	=	1;
						$i	<	9;
						++$i
					)
				{
					
					if ($info[ $i ] != 0)
					{
						
						$item	=	get_user_item(
							$info['id'],
							$info[ $i ]
						);
						
						$equip[ $i ]	=	$item['shop_id'];
						
					}
					
				}
				
	?>
	
	<table>
		<tr>
		<td style="vertical-align:	middle;"><a href='/user/<?=$info['id']?>'><img src="/manekenImage/<?=$info['sex']?>/<?=(isset ($equip[1]) ? $equip[1] : 0)?>/<?=(isset ($equip[2]) ? $equip[2] : 0)?>/<?=(isset ($equip[3]) ? $equip[3] : 0)?>/<?=(isset ($equip[4]) ? $equip[4] : 0)?>/<?=(isset ($equip[5]) ? $equip[5] : 0)?>/<?=(isset ($equip[6]) ? $equip[6] : 0)?>/<?=(isset ($equip[7]) ? $equip[7] : 0)?>/<?=(isset ($equip[8]) ? $equip[8] : 0)?>" alt='' /></a></td>
		<td style="	vertical-align:	top;
					padding:	0px	0px 0px 2px;">
			<img src='/images/icon/align/<?=$info['align']?>.png' alt=''/> <b><?=$info['login']?></b>
			<div style='padding:	6px 0px;'></div>
			<img src="/images/icon/str.png" alt="" /> Сила: <?=$info['str']?>			<br />
			<img src="/images/icon/agi.png" alt="" /> Ловкость: <?=$info['dex']?>		<br />
			<img src="/images/icon/def.png" alt="" /> Броня: <?=$info['protection']?>	<br />
			<img src="/images/icon/vit.png" alt="" /> Жизнь: <?=$info['life']?>
		</td>
	</tr></table>
	
	<?php
			}
				
			$sum	=	$info['str']	+	$info['dex']	+	$info['life']	+	$info['protection']
				
	?>
	
	<!--<b><?=$place?>.</b>--><?=player($info['id'])?><br />
	<img src='/images/icon/2hit.png' alt='' /> <b><?=$sum?></b><br />
	
	<?php
		}
		
		if ($pages > 1)
		{
	?>
	
	<div style='padding:	6px 0px;'></div>
	
	<?php
			pagenation(
				'/rating/',
				$pages,
				$page
			);
			
		}
	?>
	</div>
	<?php
	}
	else
	{
	?>
		
	<?php
	}
	?>
	</div>
	<?php	
	include_once __DIR__ . '/include/footer.php';
	
	setContentType('text/html; charset=UTF-8');
	render(
		__DIR__ . '/include/template.php',
		ob_get_clean(),
		$params
	);
	
	?>
