<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
$array = DB::$dbs->query("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$id]);
if ($array-> rowCount() == 0) {
header('location: /');
die();
}
$arr = $array -> fetch();
$title->SetTitle('Галерея '.$arr['nick']);
$title->GetHeader();
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: <a href="/gallery"style="text-decoration:none; color:white;">Галерея</a> :: '.$arr['nick'].'</div></div></div>';
if ($b['id'] == $arr['id']) echo '<div class="list-group-item media"><span class="label label-danger">Новое</span><a href="upload.html?id=0">  Добавить изображение</a></div>';

if (isset($_GET['ava'])) {
$av = DB::$dbs->queryFetch("SELECT * FROM album_foto WHERE id = ? LIMIT 1", [abs((int)$_GET['ava'])]);

if ($av['path'] == $b['ava']) {
err('Это фото уже стоит у Вас на аватаре!');
} elseif ($av['user_id'] != $b['id']) {
header('location: /');
} else {
DB::$dbs->query("UPDATE blogger SET ava = ? WHERE id = ? LIMIT 1", [$av['path'],$b['id']]);
header('location: personal.html?id='.$id);
die();
}
}
$k_foto = DB::$dbs->querySingle("SELECT COUNT(id) FROM album_foto WHERE user_id = ? AND cid = ?", [$id,0]);
$num = 10;
$k_page = k_page($k_foto, $num);
$page = page($k_page);
$start = $num*$page-$num;
$sql = DB::$dbs->query("SELECT * FROM album_foto WHERE user_id = ? AND cid = ? ORDER BY time DESC LIMIT $start,$num", [$id,0]);
if ($sql->rowCount() == 0) {
err('Изображений нет');
} else {
while($a = $sql -> fetch()) {
$A = (($a['user_id'] == $b['id'] && $a['path'] != $arr['ava']) ? ' | <a href="personal.html?id='.$id.'&ava='.$a['id'].'">На аватар</a>':NULL);
$ED = (($a['user_id'] == $b['id'] && $b['level'] > 2) ? '<br/><a href="edit_foto.html?id='.$a['id'].'"class="btn btn-primary">Редактировать</a>  <a href="del_foto.html?id='.$a['id'].'"class="btn btn-primary">Удалить</a>':NULL);
$R = $a['rat'];
echo '<div class="list-group-item media">&#187; Название:  '.$a['name'].'<br/><br/><a href="/'.$a['path'].'"><img src="/'.$a['path'].'" width="380" height="250"  alt="not found"/></a><br/><br/>&#187; Автор: '.Nick($a['user_id']).'<br/>&#187; Добавлено: '.vr($a['time']).'<br/>';
if ($b == true){ echo'&#187; <a href="rating.html?id='.$a['id'].'">Оценка</a>: '.($R == 0 ? 'Не оценено': $R).'<br/>'; }
echo'&#187; <a href="comm.html?id='.$a['id'].'">Комментарии</a>: '.DB::$dbs->querySingle("SELECT COUNT(id) FROM album_comm WHERE fid = ?", [$a['id']]).$ED.'</div>';
}
}
if ($k_page>1) {
str('personal.html?id='.$id.'&', $k_page,$page);
}
$title->GetMenu();
$title->GetFooter();
?>