Файл: moduls/friends/index.php
Строк: 151
<?php
/**
* @package Prime Social
* @link http://primesocial.ru
* @copyright Copyright (C) 2016 Prime Social
* @author BoB | http://primesocial.ru/about
*/
require_once('../../core/start.php');
check_auth();
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".FRIENDS." WHERE (`id_user` = ? OR `id_friend` = ?) AND (`status` = ?) ", array($user['user_id'],$user['user_id'], 1));
$all2 = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".FRIENDS." WHERE (`id_user` = ?) AND (`status` = ?) ", array($user['user_id'], 0));
$all3 = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".FRIENDS." WHERE (`id_friend` = ?) AND (`status` = ?) ", array($user['user_id'], 0));
switch ($select) {
default:
switch ($_GET['list']) {
/* Mening dustlarim */
default:
head('Mening do`stlarim '.$all.'');
if ($_GET['list'] != 'friend') {
echo DIV_LI . '<a href="'.HOME.'/friends/my_appl/">Chiquvchi takliflar</a> '.$all2.' / ';
echo '<a href="'.HOME.'/friends/user_appl/">Kiruvchi takliflar</a> '.$all3.'' . CLOSE_DIV;
}
if ($all == 0) {
echo DIV_BLOCK . 'Do`stlar ro`yhati bo`sh.' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT `id`, `id_user`, `id_friend` FROM ".FRIENDS." WHERE (`id_user` = ? OR `id_friend` = ?) AND (`status` = ?) ", array($user['user_id'],$user['user_id'], 1));
while($friend = $sql -> fetch()){
if ($friend['id_friend'] == $user['user_id']) {
$a = $friend['id_user'];
} else {
$a = $friend['id_friend'];
}
echo DIV_LI . userLink($a) . ' <a href="'.HOME.'/friends/delete/'.$a.'/">[x]</a>' . CLOSE_DIV;
}
}
$array = array('Do`stlar');
nav($array);
break;
/* Chiquvchi takliflarim */
case 'my_appl':
head('Chiquvchi takliflar');
if ($_GET['list'] != 'friend') {
echo DIV_LI . ' <a href="'.HOME.'/friends/">Mening do`stlarim</a> '.$all.'';
echo ' / <a href="'.HOME.'/friends/user_appl/">Kiruvchi takliflar</a> '.$all3.'' . CLOSE_DIV;
}
if ($all2 == 0) {
echo DIV_BLOCK . 'Takliflar yo`q.' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT `id_friend` FROM ".FRIENDS." WHERE (`id_user` = ?) AND (`status` = ?) ", array($user['user_id'], 0));
while($friend = $sql -> fetch()){
echo '<div class="lines"> '. userLink($friend['id_friend']) . ' <a href="'.HOME.'/friends/delete/'.$friend['id_friend'].'">[Rad etish]</a></div>';
}
}
$array = array('Do`stlar', 'Chiquvchi takliflar');
nav($array);
break;
case 'user_appl':
head('Kiruvchi takliflar');
if ($_GET['list'] != 'friend') {
echo DIV_LI . '<a href="'.HOME.'/friends/">Mening do`stlarim</a> '.$all.' / <a href="'.HOME.'/friends/my_appl/">Chiquvchi takliflar</a> '.$all2.'' . CLOSE_DIV;
}
if ($all3 == 0) {
echo DIV_BLOCK . 'Takliflar yo`q.' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT `id_user` FROM ".FRIENDS." WHERE (`id_friend` = ?) AND (`status` = ?) ", array($user['user_id'], 0));
while($friend = $sql -> fetch()){
echo DIV_LI . userLink($friend['id_user']) . ' <a href="'.HOME.'/friends/add/'.$friend['id_user'].'/">[Qabul qilish]</a> <a href="'.HOME.'/friends/otkl/'.$friend['id_user'].'/">[Rad etish]</a>' . CLOSE_DIV;
}
}
$array = array('Do`stlar', 'Kiruvchi takliflar');
nav($array);
break;
}
break;
case 'add':
$id = abs(intval($_GET['friend']));
$ank = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array($id));
if (empty($ank)) {
head('Foydalanuvchi baza ma`lumotlarida topilmadi');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>Foydalanuvchi topilmadi</b>' . CLOSE_DIV;
exit();
}
if ($ank['user_id'] == $user['user_id']) {
head('Siz o`zingizni do`slaringiz orasiga qo`shib bilmaysiz');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>Siz o`zingizni do`slaringiz oasiga qo`shib bilmaysiz</b>' . CLOSE_DIV;
exit();
}
$sql = DB::$dbs->queryFetch("SELECT * FROM ".FRIENDS." WHERE (`id_user` = ? AND `id_friend` = ?) OR (`id_friend` = ? AND `id_user` = ?) LIMIT 1 ",array($ank['user_id'], $user['user_id'], $user['user_id'], $ank['user_id']));
if ($sql['id'] && $sql['status'] == 1) {
$err .= 'Foydalanuvchi ' . $ank['nick'] . ' do`stlaringiz orasida bor.<br />';
} else {
if (($sql['id'] && $sql['status'] == 0) && $sql['id_friend'] == $user['user_id']) {
DB::$dbs->query("UPDATE ".FRIENDS." SET `status` = ? WHERE (`id_user` = ? AND `id_friend` = ?)",array(1, $sql['id_user'], $user['user_id']));
$ank = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array($sql['id_user']));
$msg = 'Foydalanuvchu ' . $ank['nick'] . ' taklifi muvaffaqiyatli qabul qilindi';
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> do`stlik taklifingizni qabul qildi';
lenta($lenta, $ank['user_id']);
} else {
DB::$dbs->query("INSERT INTO ".FRIENDS." SET `id_user` = ?, `id_friend` = ? ",array($user['user_id'], $ank['user_id']));
$msg = 'Siz foydalanuvchi ' . $ank['nick'] . ' ga do`stlik taklifini muvaffaqiyatli jo`natdingiz!';
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> sizga <a href="'.HOME.'/friends/user_appl/"><b>do`stlashish</b></a>ni taklif qilyapti';
lenta($lenta, $ank['user_id']);
}
head('Do`stlashish');
echo DIV_BLOCK . $msg . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/friends/">Do`stlar</a> / <b>Do`stlashish</b>' . CLOSE_DIV;
}
break;
case 'otkl':
$id = abs(intval($_GET['friend']));
$ank = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array($id));
if (empty($ank)) {
head('Foydalanuvchi topilmadi');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>Foydalanuvchi topilmadi</b>' . CLOSE_DIV;
exit();
}
if ($ank['user_id'] == $user['user_id']) {
head('O`zingizni do`stlaringiz orasiga qo`shib bilmaysiz');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>O`zingizni do`stlaringiz orasiga qo`shib bilmaysiz</b>' . CLOSE_DIV;
exit();
}
$sql = DB::$dbs->queryFetch("SELECT `id`, `status` FROM ".FRIENDS." WHERE (`id_user` = ? AND `id_friend` = ? AND `status` = ?) LIMIT 1 ",array($ank['user_id'], $user['user_id'], 0));
if ($sql['id'] && $sql['status'] == 0) {
DB::$dbs->query("DELETE FROM ".FRIENDS." WHERE `id` = ? ",array($sql['id']));
} else {
echo 'Xatolik';
exit();
}
if (isset($_GET['anceta'])) {
header("Location: ".HOME."/id".$ank['user_id']);
} else {
header("Location: ".HOME."/friends/");
}
break;
case 'delete':
$id = abs(intval($_GET['friend']));
$ank = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array($id));
if (empty($ank)) {
head('Foydalanuvchi topilmadi');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>Foydalanuvchi topilmadi</b>' . CLOSE_DIV;
exit();
}
if ($ank['user_id'] == $user['user_id']) {
head('O`zingizni do`stlaringiz orasiga qo`shib bilmaysiz');
echo 'Xatolik!<br />';
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <b>O`zingizni do`stlaringiz orasiga qo`shib bilmaysiz</b>' . CLOSE_DIV;
exit();
}
$sql = DB::$dbs->queryFetch("SELECT * FROM ".FRIENDS." WHERE (`id_user` = ? AND `id_friend` = ?) OR (`id_friend` = ? AND `id_user` = ?)LIMIT 1",array($ank['user_id'], $user['user_id'], $ank['user_id'], $user['user_id']));
if($sql['id'] && $sql['status'] == 1) {
DB::$dbs->query("DELETE FROM ".FRIENDS." WHERE `id` = ? ",array($sql['id']));
} else {
$sql2 = DB::$dbs->queryFetch("SELECT * FROM ".FRIENDS." WHERE (`id_user` = ? AND `id_friend` = ?) LIMIT 1",array($user['user_id'], $ank['user_id']));
if($sql2['id'] && $sql2['status'] == 0) {
DB::$dbs->query("DELETE FROM ".FRIENDS." WHERE `id` = ? LIMIT 1",array($sql2['id']));
}
}
if (isset($_GET['anceta'])) {
header("Location: ".HOME."/id".$ank['user_id']);
} else {
header("Location: ".HOME."/friends/");
}
break;
}
require_once('../../core/stop.php');
?>