File size: 2.72Kb
<?php
$title = 'Заявки в друзья';
include_once($_SERVER["DOCUMENT_ROOT"]."/inc/head.php");
if (isset($active) == true) {
echo '<div class="title">Заявки в друзья ('.$count_req.')</div>';
$stmt_num = $connect->prepare("select count(*) from `friend` where `status` = '0' and `user_to` = ? and `id` = ?");
$stmt = $connect->prepare("update `friend` set `status` = ? where `status` = '0' and `user_to` = ? and `id` = ?");
if (isset($_GET['yes'])) {
$stmt_num->execute(array($user['login'], $_GET['yes']));
$num = $stmt_num->fetchColumn();
if ($num > 0) {
$status = 1;
if ($stmt->execute(array($status, $user['login'], $_GET['yes']))) {
header('location: /friends/to');
} else {
echo '<div class="menu">Произошла ошибка!</div>';
}
} else {
header('location: /friends/to');
}
}
elseif (isset($_GET['no'])) {
$stmt_num->execute(array($user['login'], $_GET['no']));
$num = $stmt_num->fetchColumn();
if ($num > 0) {
$status = 2;
if ($stmt->execute(array($status, $user['login'], $_GET['no']))) {
header('location: /friends/to');
} else {
echo '<div class="menu">Произошла ошибка!</div>';
}
} else {
header('location: /friends/to');
}
}
$k_post = $count_req;
$k_page = k_page($k_post, 10);
$page = page($k_page);
$start = 10 * $page - 10;
$data = $connect->prepare("select * from `friend` where `status` = '0' and `user_to` = :user order by `id` desc limit :start, 10");
$data->bindValue(':user', $user['login']);
$data->bindValue(':start', $start, PDO::PARAM_INT);
$data->execute();
$sql = $data->fetchAll();
if ($count_req == 0) {
echo '<div class="menu">Заявок нет!</div>';
} else {
foreach ($sql as $row) {
echo '<div class="menu">Пользователь: '.(user($row['user_from'], 1) ? '<a href="/user/'.uid($row['user_from']).'" class="mlink">'.$row['user_from'].'</a>' : $row['user_from']).'<br/><div class="butt2"><a href="?yes='.$row['id'].'">Добавить в друзья</a><a href="?no='.$row['id'].'">Отклонить</a></div></div>';
}
if ($k_page > 1) navigation($k_page, $page);
}
if ($version == 'mobile') echo '<div class="forlink"><a href="/friends" class="links" ><img src="/img/friend.png" alt=""> Мои друзья ('.$count_friends.')</a></div>';
} else {
header('Location: /');
}
include_once($_SERVER["DOCUMENT_ROOT"]."/inc/foot.php");
?>