<?php

require '../system/start.php';
require '../system/functions.php';
reg();
$query = mysql_fetch_assoc(mysql_query("select `id`,`login` from `users` where `id` = '".int($_GET['id'])."'"));
$str['mesto'] = 'Друзья';
$str['block'] = $set['site'].' / Друзья';
include '../style/'.$style.'/head.php';

if (!$query)
{
	echo '<div class="on">Пользователь не найден!</div>';
	include '../style/'.$style.'/foot.php';
	exit;
}
switch($act)
{
	default:
	$zapros = mysql_query("select * from `friends` where `id_user` = ".$query['id']." order by `id_user` limit ".$page.",".$set['str']."");
	$total = mysql_result(mysql_query("select count(*) from `friends` where `id_user` = ".$query['id'].""),0);
	if($total == 0)
	{
		echo '<div class="on">У пользователя нет друзей!</div>';
	}
echo '<div class="block2">';
echo 'Всего друзей ('.mysql_result(mysql_query("select count(*) from `friends` where `id_user` = ".$query['id'].""),0).')<br/>';
	if($user['id'] == $query['id']):
echo '<a href="../pages/fapl.php">Приглашённые в друзья ('.mysql_result(mysql_query("select count(*) from `friend_application` where `id_adder` = '".$query['id']."'"),0).')</a><br/>';
endif;
echo '</div>';
	while($e = mysql_fetch_assoc($zapros)) {
		$row = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $e['id_added'] . "'"));
		$i++;
		echo ($i % 2) ? '<div class="forum1"><div class="row4">' : '<div class="forum2"><div class="row4">' ;
	
		if(empty($row['foto'])) {
			echo '<img src="../style/'.$style.'/'.$row['gender'].'.png"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
		} elseif(!empty($row['foto'])) {
			echo '<img src="../files/avatars/'.$row['foto'].'"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
		}
		
		if ($row['gender'] == 1)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/m.png" alt="" />';
		if ($row['gender'] == 2)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/w.png" alt="" />';
		
		echo $pol . ' <a href="../p/'.$row['login'].'">'.$row['login'].'</a>';
		echo status($row['id']);
		echo'<br/>';



	echo '<div class="ftext">';
              if($user['id'] != $row['id']):
              echo  '<a href="../pages/mail.php?act=send&amp;login='.$row['login'].'"><img align="right" class="ico" src="../style/'.$style.'/ico/mess.png" alt="" /></a>';
              endif;
              
	echo 'Имя: '.$row['name'].'<br/>';
    if(!empty($row['birthday_day']) and !empty($row['birthday_month']) and !empty($row['birthday_year'])) 
 		echo 'Возраст: '.age($row['birthday_day'], $row['birthday_month'], $row['birthday_year']).' лет<br/>'; 

	if(!empty($row['city'])) 
	 	echo 'Город:  '.$row['city'].'<br />'; 
 
	if(!empty($row['rate'])) 
		echo '	Рейтинг: '.$row['rate'].'<br/>';
	else
		echo '	Рейтинг: 0<br/>';

	echo '
		</div>
		<div class="clear"></div>
		</div>';
	
	$status = mysql_fetch_assoc(mysql_query("SELECT * FROM `statuses` WHERE `user` = '" . $row['id'] . "' ORDER by `time` DESC LIMIT 1"));
	if ($status['text'])
	echo'<div class="status"><b><!-- clear --></b>
	'.text($status['text']); 
	echo'</div>';
	echo'</div>';

	}
	if($total > $set['str'])
	{
		pages($page, $total, 'friend.php?id='.$query['id'].'&amp;', $set['str']);
	}
	break;
	case 'add':
	if(mysql_result(mysql_query("select count(*) from `friends` where `id_user` = ".$user['id']." and `id_added` = ".$query['id'].""),0) == 0 and mysql_result(mysql_query("select count(*) from `friend_application` where `id_user` = ".$user['id']." and `id_adder` = ".$query['id'].""),0) == 0)
	{
		mysql_query("insert into `friend_application`(id_user,id_adder,time) values(".$user['id'].",".$query['id'].",".time().")");
		echo '<div class="on">Пользователю успешно отправлена ваша заявка!</div>';
	}
	else
	{
		echo '<div class="on">Вы уже подавали заявку этому пользователю в друзья или он у вас списке!</div>';
	}
	break;
	case 'delete':
   	if(mysql_result(mysql_query("select count(*) from `friends` where `id_user` = ".$user['id']." and `id_added` = ".$query['id'].""),0) == 0)
	{
		echo '<div class="on">Этого пользователя не существует у вас в друзьях!</div>';
	}
	else
	{
		mysql_query("delete from `friends` where `id_user` = ".$user['id']." and `id_added` = ".$query['id']."");
		echo '<div class="on">Пользователь успешно удален из вашего списка друзей!</div>';
	}
	break;
}
include '../style/'.$style.'/foot.php'; ?>