<?
if($data['id']==User::a()->user['id'] && User::a()->user['present']!=0){
User::a()->user['present']=0;
if(User::a()->user['appPresent']>0)User::a()->user['appPresent']=0;
}
if(isset($_GET['delete'])){
$id = abs(intval($_GET['delete']));
$gift = DB::a()->d->query("SELECT * FROM `gifts` WHERE `id` = '".$id."'")->fetch();
if($gift===FALSE){
header('Location:/User/'.$data['id'].'/');
die();
}
if($gift['user']!=User::a()->user['id']){
header('Location:/User/'.$data['id'].'/');
die();
}
DB::a()->d->query("DELETE FROM `gifts` WHERE `id` = '".$id."'");
$_SESSION['info'] = "Подарок удален!";
header('Location:/User/'.User::a()->user['id'].'/Gifts/');
die();
}
$page = 1;
if(isset($_GET['page']))$page = abs(intval($_GET['page']));
if($page<1)$page= 1;
$start = $page * 10 - 10;
$count = DB::a()->d->query("SELECT * FROM `gifts` WHERE `user` = '".$data['id']."'")->fetchAll();
$count = count($count);
$pages = ($count-1)/10+1;
/*if($pages>0 && $page>$pages){
header('Location:/User/'.$data['id'].'/Gifts/');
die();
}*/
$gifts = DB::a()->d->query("SELECT `gifts`.*, ".User::a()->join."
FROM `gifts` JOIN `users`
ON `users`.`id` = `gifts`.`who` WHERE `gifts`.`user` = '".$data['id']."'
ORDER BY `gifts`.`id` DESC,`gifts`.`time` DESC LIMIT ".$start.",10")->fetchAll();
Template::a()->setTitle('Подарки '.$data['nick']);
Template::a()->set('data',$data);
Template::a()->set('page',$page);
Template::a()->set('count',$count);
Template::a()->set('gifts',$gifts);
Template::a()->display('user/gifts');
?>