<?   
include './system/common.php'; 
include './system/functions.php';
include './system/user.php';
    
if(!$user) { 
header('location: /'); 
exit;}


$act = isset($_GET['act']) ? $_GET['act'] : null;
switch($act)
{
default: //Главнвя
$title = 'Подарки';
include './system/h.php';  
echo '<div class="title">'.$title.'</div>';

?>

<?
if(isset($_GET['id'])){$id=intval($_GET['id']);}else{$id=$user['id'];}


$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `gifts_user` WHERE `komy` = '.$id.' '),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;

if($count > 0) {
$q = mysql_query('SELECT * FROM `gifts_user` WHERE `komy` = '.$id.' ORDER BY `id` DESC LIMIT '.$start.' , '.$max.'');
 while($row = mysql_fetch_array($q)) {
 

echo'<div class="empty_block">
<table> <tbody><tr>
<td width="14%">
<img src="/images/gifts/'.$row['img'].'.png" alt=""/>
</td><td> ';
 if($row['privacy'] == '2' AND $row['komy'] != $user['id']){echo'<font color="#fff"> Неизвестный </font>'; }else{ echo'<a href="/user/'.$row['user'].'">'.nick($row['user']).'</a>';}
 if($row['privacy'] == '2' AND $row['komy'] != $user['id']){if($row['text']){echo'<br><font color="#fff"> Текст скрытый </font>'; }}else{ if($row['text']){ echo'</br><font color="'.color($row['user']).'">'.$row['text'].'</font>'; }}
 echo'<br>'._times(time() - $row['time']).'
 </td></tr>
</tbody></table>
</div><div class="line"></div>';
}
  
  
echo ''.pages('?').'';  	


}else{
echo '<div class="empty_block item_center"> Подарков нет </div>';

}
echo'
<div class="line"></div>
<div class="block_link"><a href="/user/'.$id.'/"><img src="/images/ico/png/back.png" alt="*"/> Вернуться </a></div>
<div class="line"></div>';
break;


case 'choose_gifts':
$title = 'Выбери подарок';
include './system/h.php';  
echo '<div class="title">'.$title.'</div>';
$id = abs(intval($_GET['id']));

if($id == $user['id']) { 
header('location: /gifts/'.$id.'/'); 
exit;}

echo'<div class="empty_block item_center">';
if(isset($_GET['tip'])){
$tip=abs(intval($_GET['tip']));
}
if(@$tip > 3  or !isset($_GET['tip']) ){$tip=0;}

$q = mysql_query('SELECT * FROM `gifts` WHERE `tip` = "'.$tip.'" ORDER BY `id` DESC');
 while($row = mysql_fetch_array($q)) {
echo'<a href="/mail/'.$id.'?gift='.$row['id'].'"><img src="/images/gifts/'.$row['img'].'.png" alt=""/></a>';
}
  
  
  

echo'</div>
 <div class="line"></div>
 <div class="empty_block">
		<a href="/choose_gifts/'.$id.'?tip=0"><img src="/images/gifts/section/romantic.png" alt=""/>Романтика</a> </br>
		<a href="/choose_gifts/'.$id.'?tip=1"><img src="/images/gifts/section/friendship.png" alt=""/>Дружба</a>  </br>
		<a href="/choose_gifts/'.$id.'?tip=2"><img src="/images/gifts/section/fiesta.png" alt=""/>Праздники</a>   </br>
		<a href="/choose_gifts/'.$id.'?tip=3"><img src="/images/gifts/section/sport.png" alt=""/>Спорт</a>
 </div><div class="line"></div>';
break;

}
include './system/f.php';

?>