Файл: favorit.php
Строк: 29
<?
include_once 'system/sys.php';
include_once 'system/funcs.php';
if(!$cms->us['id']){
header('location: /');
exit;
}
$posts = DB::$dbs->querySingle("SELECT count(id) from `favorit` where `kem` = ?",array($cms->us['id']));
verh('Избранные','Избранные вами ('.$posts.' чел.)');
# Добавляем в избранные
if(isSet($_GET['u'])){
$u = $func->num($_GET['u']);
if($u){
$fis = DB::$dbs->queryFetch("SELECT * from `favorit` where `kem` = ? and `us` = ?",array($cms->us['id'],$u));
$fus = DB::$dbs->queryFetch("SELECT * from `us` where `id` = ?",array($u));
if($fus['id'] && $fus['id']!=$cms->us['id'] && !$fis['id']){
DB::$dbs->query('insert into `favorit` (`us`,`kem`) values (?,?)',array($u,$cms->us['id']));
echo '<div class="lst"><b>'.$fus['nick'].'</b> добавлен в избранное!</div>';
}
}
}
$num = 10;
if($posts==0){
echo'<div class="list1">Избранных нет!</div>';
}else{
$total = intval(($posts - 1) / $num) + 1;
$page = abs(intval($_GET['page']));
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
# Удаляем из избранных
if(isSet($_GET['del'])){
$del = $func->num($_GET['del']);
if(!empty($del)){
$favorit = DB::$dbs->queryFetch("SELECT * from `favorit` where `kem` = ? and `id` = ?",array($cms->us['id'],$del));
if($favorit['id']){
DB::$dbs->query("DELETE from `favorit` where `id` = ?",array($del));
}
}
header('location: ?');
}
$list = DB::$dbs->query("SELECT * from `favorit` where `kem` = ? limit $start,$num",array($cms->us['id']));
while($favorit = $list->fetch()){
echo'<div class="lst">'.$func->uNick($favorit['us']).' [<a href="/favorit.php?del='.$favorit['id'].'">x</a>]</div>';
}
echo '<div class="lst">';
$func->page('?');
echo '</div>';
}
echo '<div class="list1"><a href="/kab">Личный кабинет</a></div>';
niz();
?>