<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
head([]);
//
//
echo logs();
//
//
if(isset($_GET['complete'])){
$id = num($_GET['complete']);
//
$quest = DB::$dbs->queryFetch("SELECT * FROM `task_user` WHERE `id` = ? LIMIT 1", array($id)); 
//
$q = DB::$dbs->queryFetch("SELECT * FROM `task` WHERE `id` = ? LIMIT 1", array($quest['id_task'])); 
//
if($quest['coll'] >= $quest['max_coll'] && $quest['last'] < time()){
//
DB::$dbs->query("UPDATE `task_user` SET `coll` = ?, `last` = ? WHERE `id` = ? LIMIT 1", array(0,time()+86400*2,$quest['id']));
DB::$dbs->query("UPDATE `users` SET `diamond` = `diamond` + ?, `gold` = `gold` + ?, `silver` = `silver` + ?, `key` = `key` + ?, `stat_task` = `stat_task` + ? WHERE `id` = ? LIMIT 1", array(1,$q['gold'],exp_silver($q['silver']),$q['key'],1,$user['id']));
//
//
$medal2 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(31,$user['id']));
if($medal2['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal2['id']));
//
//
$medal3 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(32,$user['id']));
if($medal3['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal3['id']));
//
//
$medal4 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(33,$user['id']));
if($medal4['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal4['id']));
//
//
$medal5 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(34,$user['id']));
if($medal5['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal5['id']));
//
//
$medal6 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(35,$user['id']));
if($medal6['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal6['id']));
//
//
$medal7 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(36,$user['id']));
if($medal7['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal7['id']));
//
//
$medal8 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(37,$user['id']));
if($medal8['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal8['id']));
//
//
$medal9 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(38,$user['id']));
if($medal9['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal9['id']));
//
//
$medal10 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(39,$user['id']));
if($medal10['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal10['id']));
//
//
$medal11 = DB::$dbs->queryFetch("SELECT * FROM `medal_user` WHERE `id_task` = ? AND `id_user` = ? LIMIT 1", array(40,$user['id']));
if($medal11['check'] == 0)DB::$dbs->query("UPDATE `medal_user` SET `coll` = `coll` + ? WHERE `id` = ? LIMIT 1", array(1,$medal11['id']));

//
//
ok2("Вы забрали награду");
//
header('Location: ?');
exit();
}else{
header('Location: ?');
exit();
}
}
?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Ежедневные задания</span>
		        </center>
<?
//
//
$sql = DB::$dbs->query("SELECT * FROM `task_user` WHERE `id_user` = '".$user['id']."' ORDER BY `id_task` ASC, `last` ASC");
//
foreach ($sql as $sqlls => $im){
//
$quest = DB::$dbs->queryFetch("SELECT * FROM `task` WHERE `id` = ? LIMIT 1", array($im['id_task']));  
//
echo '<div class="menu-not2">';
//
if($im['last'] < time()){
//
?>
<? 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']); ?> 
<img src = "/css/img/diamond.png" width="16" height="16"> 1
<img src = "/css/img/key.png" width="16" height="16"> <?=$quest['key']; ?> 
</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'];
?>

</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']); ?> 
<img src = "/css/img/diamond.png" width="16" height="16"> 1
</font>
<br>
</font>
<font color="#32cd32">
Завершено на сегодня
</font>
<?
}
?>
</div>
<?
if($im['coll'] >= $quest['coll'] && $im['last'] < time()){
?>
<a href="?complete=<?=$im['id']; ?>"><div class="click">Получить награду</div></a>
<div class="stats2"></div>
<?
}
?>
<?
}
//
//
?>
</div>
</div>
<?
//
//
foot([]);
?>