Файл: moduls/friends.php
Строк: 122
<?php
include_once'../system/xcms_core.php';$title='Друзья';
if($_COOKIE['style']=='web')require_once '../system/web_head.php'; else require_once '../system/head.php';
if($user){
switch($act){
case 'add':
$q=$db->query("select `id` from `user` where `id`='$id'")->fetch(PDO::FETCH_ASSOC);
if($q['id'] and $id!==$user['id']){
$w=$db->query("select * from `friend` where `user1`='$user[id]' and `user2`='$id'")->fetch(PDO::FETCH_ASSOC);
$e=$db->query("select * from `friend` where `user2`='$user[id]' and `user1`='$id'")->fetch(PDO::FETCH_ASSOC);
if(!$w and !$e){
$db->query("insert into `friend` set `user1`='$user[id]', `user2`='$id', `status`='1', `time`='$time'");
$db->query("insert into `friend` set `user2`='$user[id]', `user1`='$id', `status`='2', `time`='$time'");
$db->query("insert into `notice` set `to`='$id', `text`='Пользователь <a href="/profile$user[id]">$user[login]</a> хочет добавить вас в друзья', `time`='$time', `status`='1'");
echo '<div class="menu">Отправили заявку → <a href="/profile'.$id.'">Далее</a></div>';
}else{echo'<div class="menu">Ошибка</div>';}
}
echo back('/friends');
break;
case 'in':
$nw1=$db->query("SELECT COUNT(*) as count FROM `friend` where `user2`='$user[id]' and `status`='1'");$nw1->setFetchMode(PDO::FETCH_ASSOC);$nw=$nw1->fetch();
if($nw['count']){
$k_page=k_page($nw['count'],$set[p_str]);$page=page($k_page);$start=$set[p_str]*$page-$set[p_str];
$sql=$db->query("select * from `friend` where `user2`='$user[id]' and `status`='1' order by `id` desc limit $start, $set[p_str]");
while($res=$sql->fetch(PDO::FETCH_ASSOC)){
$q=$db->query("select `avatar`,`login` from `user` where `id`='$res[user1]'")->fetch(PDO::FETCH_ASSOC);
echo'<div class="menu">'.avatar($q['avatar']).' <a href="/profile'.$res['user1'].'">'.$q['login'].'</a> <a href="/friends/pod/'.$res['id'].'">[Добавить]</a><br />'.clock($res['time']).'</div>';
}
if ($k_page>1)str('/friends/in/',$k_page,$page);
}else{echo'<div class="menu">Заявок нет</div>';}
echo back('/friends');
break;
case 'out':
$nw1=$db->query("SELECT COUNT(*) as count FROM `friend` where `user1`='$user[id]' and `status`='1'");$nw1->setFetchMode(PDO::FETCH_ASSOC);$nw=$nw1->fetch();
if($nw['count']){
$k_page=k_page($nw['count'],$set['p_str']);$page=page($k_page);$start=$set['p_str']*$page-$set['p_str'];
$sql=$db->query("select * from `friend` where `user1`='$user[id]' and `status`='1' order by `id` desc limit $start, $set[p_str]");
while($res=$sql->fetch(PDO::FETCH_ASSOC)){
$q=$db->query("select `avatar`,`login` from `user` where `id`='$res[user2]'")->fetch(PDO::FETCH_ASSOC);
echo'<div class="menu">'.avatar($q['avatar']).' <a href="/profile'.$res['user2'].'">'.$q['login'].'</a><br />'.clock($res['time']).'</div>';
}
if ($k_page>1)str('/friends/out/',$k_page,$page);
}else{echo'<div class="menu">Заявок нет</div>';}
echo back('/friends');
break;
case 'pod':
$q=$db->query("select * from `friend` where `id`='$id'")->fetch(PDO::FETCH_ASSOC);
if($q and $q['status']>0){
if($q['user2']==$user['id']){
$w=$db->query("select * from `friend` where `user1`='$q[user1]' and `user2`='$q[user2]'")->fetch(PDO::FETCH_ASSOC);
$e=$db->query("select * from `friend` where `user2`='$q[user1]' and `user1`='$q[user2]'")->fetch(PDO::FETCH_ASSOC);
if($w and $e){
$db->prepare("update `friend` set `status`='0' where `id`='$w[id]'")->execute();
$db->prepare("update `friend` set `status`='0' where `id`='$e[id]'")->execute();
echo'<div class="menu">Подтвердили → <a href="/friends">Далее</a></div>';
}else{echo'<div class="menu">Ошибка</div>';}
}else{echo'<div class="menu">Ошибка</div>';}
}else{echo'<div class="menu">Ошибка</div>';}
echo back('/friends');
break;
case 'my':
$nw1=$db->query("SELECT COUNT(*) as count FROM `friend` where `user1`='$user[id]' and `status`='0'");$nw1->setFetchMode(PDO::FETCH_ASSOC);$nw=$nw1->fetch();
if($nw['count']){
$k_page=k_page($nw['count'],$elem);$page=page($k_page);$start=$elem*$page-$elem;
$sql=$db->query("select * from `friend` where `user1`='$user[id]' and `status`='0'");
while($res=$sql->fetch(PDO::FETCH_ASSOC)){
$q=$db->query("select `login` from `user` where `id`='$res[user2]'")->fetch(PDO::FETCH_ASSOC);
echo'<div class="menu"><a href="/profile'.$res['user2'].'">'.$q['login'].'</a> <a href="/friends/del/'.$res['user2'].'" style="float:right;">[Удалить]</a></div>';
}
if ($k_page>1)str('/friends/list/',$k_page,$page);
}else{echo'<div class="menu">У вас нет друзей</div>';}
echo back('/friends');
break;
case 'del':
$q=$db->query("select * from `user` where `id`='$id'")->fetch(PDO::FETCH_ASSOC);
if($q){
$w=$db->query("select * from `friend` where `user1`='$user[id]' and `user2`='$id'")->fetch(PDO::FETCH_ASSOC);
$e=$db->query("select * from `friend` where `user2`='$user[id]' and `user1`='$id'")->fetch(PDO::FETCH_ASSOC);
if($w and $e){
if($w['status']!==2){
$db->exec("delete from `friend` where `id`='$w[id]'");
$db->exec("delete from `friend` where `id`='$e[id]'");
echo'<div class="menu">Удалили → <a href="/friends">Далее</a></div>';
}else{echo'<div class="menu">Ошибка</div>';}
}else{echo'<div class="menu">Ошибка</div>';}
}else{echo'<div class="menu">Ошибка</div>';}
echo back('/friends');
break;
default:
echo'<div class="touch">
<div class="menu"><a href="/friends/in">Входящие заявки</a></div>
<div class="menu"><a href="/friends/out">Исходящие заявки</a></div>
<div class="menu"><a href="/friends/list">Мои друзья</a></div>
</div>';
echo back('/');
}
}
if($_COOKIE['style']=='web')require_once '../system/web_foot.php'; else require_once '../system/foot.php';
?>