<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
head([]);
//
//
echo logs();
//
//
$id_us = num($_GET['id']);
		$users = DB::$dbs->queryFetch('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', [$id_us]);
		if(empty($users['id'])): header('location: /medal/?id='.$user['id']); exit; endif;
//
//
if(isset($_GET['complete'])){
$id = num($_GET['complete']);
//
$quest = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id` = ? LIMIT 1", array($id)); 
//
$q = DB::$dbs->queryFetch("SELECT * FROM `medal` WHERE `id` = ? LIMIT 1", array($quest['id_task'])); 
//
if($quest['coll'] >= $quest['max_coll']){
//
DB::$dbs->query("UPDATE `medal_user` SET `coll` = ?, `check` = ? WHERE `id` = ? LIMIT 1", array(0,1,$quest['id']));
//
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ?, `stat_task2` = `stat_task2` + ? WHERE `id` = ? LIMIT 1", array($q['gold'],exp_silver($q['silver']),1,$user['id']));
//
ok2("Вы забрали награду");
//
header('Location: ?id='.$user['id']);
exit();
}else{
header('Location: ?id='.$user['id']);
exit();
}
}
?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Достижения - <?=$users['name'];?></span>
		        </center>
<?
//
$sql = DB::$dbs->query("SELECT * FROM `medal_user` WHERE `id_user` = '".$users['id']."' ORDER BY `coll` DESC, `check` ASC");
//
foreach ($sql as $sqlls => $im){
//
$quest = DB::$dbs->queryFetch("SELECT * FROM `medal` WHERE `id` = ? LIMIT 1", array($im['id_task']));  
//
echo '<div class="menu-us">';
//
if($im['check'] == 0){
//
?>
<? echo $quest['name']; ?>
<span style="float: right;">
<font color="#777777">
<? if($im['coll'] >= $quest['coll']) echo "".$quest['coll']." из ".$quest['coll'].""; else echo "".$im['coll']." из ".$quest['coll'].""; 
?>
</font>
</span>
<br>
<font color="#999999">
<img src = "/css/img/gold.png" width="16" height="16"> <?=$quest['gold']; ?> 
<img src = "/css/img/silver.png" width="16" height="16"> <?=exp_silver($quest['silver']); ?>
</font>
<br>
<div class="stat-e">
<div class="stat-e2" style="width: <? echo ''.round($im['coll']/$quest['coll']*100,1).''; ?>%">
</div>
</div>
<?
}else{
?>
<font color="#777777">
<? echo $quest['name']; ?>
<span style="float: right;">
<? 
echo $quest['coll']." из ".$quest['coll'];
?>
</font>
</span>
<br>
<font color="#999999">
<img src = "/css/img/gold.png" width="16" height="16"> <?=$quest['gold']; ?> 
<img src = "/css/img/silver.png" width="16" height="16"> <?=exp_silver($quest['silver']); ?>
</font>

<?
}
?>
</div>
<?
if($im['coll'] >= $quest['coll'] && $users['id'] == $user['id']){
?>
<a href="?id=<?=$im['id_user'];?>&complete=<?=$im['id'];?>"><div class="click">Получить награду</div></a>
<div class="stats2"></div>
<?
}
?>
<?
}
//
//
?>
</div>
</div>
<?
//
//
foot([]);
?>