<?php 

require '../system/start.php'; 
require '../system/functions.php'; 
reg(); 
$str['mesto'] = 'Заявки в друзья'; 
$str['block'] = $set['site'].' / Заявки в друзья'; 
include '../style/'.$style.'/head.php'; 
switch($act) 
{ default: 
$query = mysql_query("select * from `friend_application` where `id_adder` = ".$user['id']." order by `id` desc limit ".$page.",".$set['str'].""); 
$total = mysql_result(mysql_query("select count(*) from `friend_application` where `id_adder` = ".$user['id'].""),0); 
if($total == 0) 
{  echo '<div class="on">Заявок еще нет!</div>'; } 
else 
{ 
while($row = mysql_fetch_assoc($query)) 
{  $i++; 
 echo ($i%2) ? '<div class="forum1">' : '<div class="forum2">'; 
 $u = mysql_fetch_assoc(mysql_query("select `login` from `users` where `id` = ".$row['id_user']."")); 
 echo '<img class="ico" src="/style/'.$style.'/ico/personal.gif" alt="" /> <a href="/p/'.$u['login'].'">'.$u['login'].'</a><br/> 
 [<a href="fapl.php?act=add&amp;id='.$row['id'].'">добавить в друзья</a>] | [<a href="fapl.php?act=delete&amp;id='.$row['id'].'">удалить заявку</a>]</div>'; 
} 
if($total > $set['str']) 
{ 
 pages($page, $total, 'fapl.php?', $set['str']); 
} 
} 
break; 
case 'add': 
$acheck = mysql_fetch_assoc(mysql_query("select * from `friend_application` where `id` = ".int($_GET['id'])."")); 
if (!$acheck) 
{ 
 echo '<div class="on">Заявка не найдена!</div>'; 
 include '../style/'.$style.'/foot.php'; 
 exit; 
} 
if ($acheck['id_adder'] != $user['id']) 
{ 
 echo '<div class="on">Вы не имеете права редактировать чужие заявки!</div>'; 
 include '../style/'.$style.'/foot.php'; 
 exit; 
} 
mysql_query("insert into `friends`(id_user,id_added) values(".$user['id'].",".$acheck['id_user'].")"); 
mysql_query("insert into `friends`(id_user,id_added) values(".$acheck['id_user'].",".$user['id'].")"); 
mysql_query("delete from `friend_application` where `id` = ".$acheck['id'].""); 
echo '<div class="on">Пользователь успешно добавлен в ваш список друзей!</div>'; 
break; 
case 'delete': 
$ucheck = mysql_fetch_assoc(mysql_query("select `id`,`login` from `users` where `id` = '".int($_GET['id'])."'")); 
if (empty($ucheck['id'])) 
{ 
 echo '<div class="on">Пользователь не найден!</div>'; 
 include '../style/'.$style.'/foot.php'; 
 exit; 
} 
$acheck = mysql_fetch_assoc(mysql_query("select * from `friend_application` where `id` = ".int($_GET['id'])."")); 
if (!$acheck) 
{ 
 echo '<div class="on">Заявка не найдена!</div>'; 
 include '../style/'.$style.'/foot.php'; 
 exit; 
} 
if ($acheck['id_adder'] != $user['id']) 
{ 
 echo '<div class="on">Вы не имеете права редактировать чужие заявки!</div>'; 
 include '../style/'.$style.'/foot.php'; 
 exit; 
} 
mysql_query("delete from `friend_application` where `id` = ".$acheck['id'].""); 
echo '<div class="on">Заявка успешно удалена!</div>'; 
break; 
} 
include '../style/'.$style.'/foot.php'; 
?>
