<?php
session_start();
include ('private/mysql.php');
include ('tmp/head.php');



switch($sd){
default:

    $num = 10; 
	$page = (int)mysql_real_escape_string(htmlspecialchars(strip_tags($_GET['page'])));
	$result = mysql_query("SELECT * FROM `medal` WHERE `user`='$uid'") or die(mysql_error()); 
	$posts = mysql_num_rows($result); 
	$total = intval(($posts - 1) / $num) + 1; 
	$page = intval($page); 
	if(empty($page) or $page < 0) $page = 1; 
    if($page > $total) $page = $total; 
	$start = $page * $num - $num; 

$q = mysql_query("SELECT * FROM `medal` WHERE `user`='$uid' ORDER BY `id` LIMIT $start, $num");
$e = mysql_num_rows($q);
if($e=='0'){
    
    echo "У вас пока нет медалей.";
    
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        echo "<a href='?sd=info&id=$w[id]'><img src='img/medal/$w[img]'></a>&nbsp;&nbsp;&nbsp;";
        
    }
    
}
    echo "<hr>";
	if ($page != 1) $pervpage = '<a href=?page=1>««</a> 
                               <a href=?page='. ($page - 1) .'>«</a> '; 
	if ($page != $total) $nextpage = ' <a href=?page='. ($page + 1) .'>»</a> 
                                   <a href=?page=' .$total. '>»»</a>'; 
	if($page - 2 > 0) $page2left = ' <a href=?page='. ($page - 2) .'>'. ($page - 2) .'</a> | '; 
	if($page - 1 > 0) $page1left = '<a href=?page='. ($page - 1) .'>'. ($page - 1) .'</a> | '; 
	if($page + 2 <= $total) $page2right = ' | <a href=?page='. ($page + 2) .'>'. ($page + 2) .'</a>'; 
	if($page + 1 <= $total) $page1right = ' | <a href=?page='. ($page + 1) .'>'. ($page + 1) .'</a>'; 

	echo $pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage; 



break;


case 'view':

    $num = 10; 
	$page = (int)mysql_real_escape_string(htmlspecialchars(strip_tags($_GET['page'])));
	$result = mysql_query("SELECT * FROM `medal` WHERE `user`='$id'") or die(mysql_error()); 
	$posts = mysql_num_rows($result); 
	$total = intval(($posts - 1) / $num) + 1; 
	$page = intval($page); 
	if(empty($page) or $page < 0) $page = 1; 
    if($page > $total) $page = $total; 
	$start = $page * $num - $num; 

$q = mysql_query("SELECT * FROM `medal` WHERE `user`='$id' ORDER BY `id` LIMIT $start, $num");
$e = mysql_num_rows($q);
if($e=='0'){
    
    echo "У игрока нет медалей.";
    
}else{
    
    While($w = mysql_fetch_assoc($q)){
        
        echo "<a href='?sd=info&id=$w[id]'><img src='img/medal/$w[img]'></a>&nbsp;&nbsp;&nbsp;";
        
    }
    
}
    echo "<hr>";
	if ($page != 1) $pervpage = '<a href=?sd=view&id='.$id.'&page=1>««</a> 
                               <a href=?sd=view&id='.$id.'&page='. ($page - 1) .'>«</a> '; 
	if ($page != $total) $nextpage = ' <a href=?sd=view&id='.$id.'&page='. ($page + 1) .'>»</a> 
                                   <a href=?sd=view&id='.$id.'&page=' .$total. '>»»</a>'; 
	if($page - 2 > 0) $page2left = ' <a href=?sd=view&id='.$id.'&page='. ($page - 2) .'>'. ($page - 2) .'</a> | '; 
	if($page - 1 > 0) $page1left = '<a href=?sd=view&id='.$id.'&page='. ($page - 1) .'>'. ($page - 1) .'</a> | '; 
	if($page + 2 <= $total) $page2right = ' | <a href=?sd=view&id='.$id.'&page='. ($page + 2) .'>'. ($page + 2) .'</a>'; 
	if($page + 1 <= $total) $page1right = ' | <a href=?sd=view&id='.$id.'&page='. ($page + 1) .'>'. ($page + 1) .'</a>'; 

	echo $pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage; 

break;


case 'info':
$q = mysql_query("SELECT * FROM `medal` WHERE `id`='$id'");
$e = mysql_num_rows($q);
if($e=='0'){
    header('Location: main.php');
    exit;
}
$w = mysql_fetch_assoc($q);

echo "<figure class='img'><img src='img/medal/$w[img]'><figcaption>$w[name]</figcaption></figure><br>";

echo "<div class='info'>$w[text]</div>";

break;



}
include ('tmp/foot.php');
?>