<?php
include_once ('./core/base.php');
falseauth();

$header = 'Дневник';
include_once ('./core/head.php');

$_GET['place'] = fl($_GET['place']);
$_GET['type'] = fl($_GET['type']);

echo '<div class="b"><div class="title">Дневник</div>';

switch($_GET['action']){

default:

echo '<center><div class="btn_small_pressed">Активные</div> <a class="btn_small" href="/diary/finished/">Завершённые</a></center>';

$count = $base -> query("SELECT * FROM `users_quests` WHERE `user` = '".$u['id']."' AND `status` = 'active'") -> num_rows;
$k_page = k_page($count,10);
$page = page($k_page);
$start = 10 * $page-10;
$sql = $base->query("SELECT * FROM `users_quests` WHERE `user` = '".$u['id']."' AND `status` = 'active' ORDER BY `id` DESC LIMIT $start,10");
if($count > 0){
	while($quest = $sql -> fetch_assoc()){
		echo ''.quest($quest['id']).'';
	}
	if($count > '10'){
		echo str('?',$k_page,$page);
	}
}else{
	echo '<br/><center>Нет активных заданий.</center><br/>';
}

break;

case 'finished':

echo '<center><a class="btn_small" href="/diary/">Активные</a> <div class="btn_small_pressed">Завершённые</div></center>';

$count = $base->query("SELECT * FROM `users_quests` WHERE `user` = '".$u['id']."' AND `status` = 'finished'") -> num_rows;
$k_page = k_page($count,10);
$page = page($k_page);
$start = 10*$page-10;
$sql = $base->query("SELECT * FROM `users_quests` WHERE `user` = '".$u['id']."' AND `status` = 'finished' ORDER BY `id` DESC LIMIT $start,10");
if($count > 0){
	while($quest = $sql->fetch_assoc()){
		echo ''.quest($quest['id']).'';
	}
	if($count > '10'){
		echo str('?',$k_page,$page);
	}
}else{
	echo '<br/><center>Нет завершённых заданий.</center><br/>';
}

break;

}

echo '<a class="btn" href="javascript:history.go(-1)"><img src="/images/icons/back.png"> Назад</a>';

echo '</div>';

include_once ('./core/foot.php');
?>