<?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="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Фотоальбом </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li typeof="v:Breadcrumb"><a href="/gallery" rel="v:url" property="v:title">Фотоальбом</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title">Галерея '.$arr['nick'].'</span></li></ol></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';

echo '<div class="catSides"><a href="/"><i class="md-format-list-bulleted"></i> Главная </a> - <a href="/gallery">Список альбомов</a> - Галерея '.$arr['nick'].'</div>';

if ($b['id'] == $arr['id']) echo '<ul class="nav nav-pills nav-stacked"><li><a href="upload.html?id=0"><i class="md-apps"></i> Добавить изображение</a></ul>';
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'].'">Изменить</a> | <a href="del_foto.html?id='.$a['id'].'">Удалить</a>':NULL);
$R = $a['rat'];
echo '<div class="row text_box">&#187; Название '.$a['name'].'<br/><br/><div class="image"><a href="/'.$a['path'].'"><img width="380" height="250" src="/'.$a['path'].'" alt="not found"/></a></div><br/>&#187; Добавлено: '.vr($a['time']).'<br/>&#187; <a href="rating.html?id='.$a['id'].'">Оценка</a>: '.($R == 0 ? 'Не оценено': $R).'<br/>&#187; <a href="comm.html?id='.$a['id'].'">Комментарии</a>: '.DB::$dbs->querySingle("SELECT COUNT(id) FROM album_comm WHERE fid = ?", [$a['id']]).$ED.$A.'</div>';
}
}
if ($k_page>1) {
str('personal.html?id='.$id.'&', $k_page,$page);
}

///Подключаем меню
$title->GetMenu();


///Подключаем футер
$title->GetFooter();
?>