<?
if (!isset($user) && !isset($_GET['id_user'])){header("Location: /foto/?".SID);exit;}
if (isset($user))$ank['id']=$user['id'];
if (isset($_GET['id_user']))$ank['id']=$_GET['id_user'];

$ank=get_user($ank['id']);
if (!$ank){header("Location: /foto/?".SID);exit;}


$gallery['id']=intval($_GET['id_gallery']);

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery` WHERE `id` = '$gallery[id]' AND `id_user` = '$ank[id]' LIMIT 1"),0)==0){header("Location: /foto/$ank[id]/?".SID);exit;}
$gallery=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '$gallery[id]' AND `id_user` = '$ank[id]' LIMIT 1"));

$foto['id']=intval($_GET['id_foto']);

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id` = '$foto[id]' LIMIT 1"),0)==0){header("Location: /foto/$ank[id]/$gallery[id]/?".SID);exit;}
$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '$foto[id]'  LIMIT 1"));

$set['title']=$ank['nick'].' - '.$gallery['name'].' - '.$foto['name']; // заголовок страницы
if ($foto['opis']!=NULL){
$stringg = mb_substr($foto['opis'],0,100,'utf-8');
$stringg=htmlspecialchars(mysql_real_escape_string(trim($stringg)));


}

if($foto['name']!=NULL)
{
$set['meta_keywords']=''.$foto['name'].'';
}
$set['meta_description']=''.$stringg.'';
include_once '../sys/inc/thead.php';
title();
if (user_access('foto_foto_edit') && $ank['level']>$user['level'] || isset($user) && $ank['id']==$user['id'])
include 'inc/gallery_show_foto_act.php';





if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=50 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
{
if (isset($_GET['rating']) && $_GET['rating']=='down'){
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']-1)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш отрицательный отзыв принят');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
elseif(isset($_GET['rating']) && $_GET['rating']=='up'){
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+1)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш положительный отзыв принят');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
}



err();
aut();

echo "<div style='text-align: left;'>\n";


if ($set['web'])
{
echo "<img class='show_foto' src='/foto/foto640/$foto[id].$foto[ras]' alt='$foto[name]' /><br />\n";
}
else
{
echo "<img class='show_foto' src='/foto/foto128/$foto[id].$foto[ras]' alt='$foto[name]' /><br />\n";
}

echo "<span class=\"ank_n\">Рейтинг:</span> ";
if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=50 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
echo "[<a href=\"?id=$foto[id]&amp;rating=down\" title=\"Отдать отрицательный голос\">-</a>] ";
echo "<span class=\"ank_d\">$foto[rating]</span>";
if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=50 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
echo " [<a href=\"?id=$foto[id]&amp;rating=up\" title=\"Отдать положительный голос\">+</a>]";
echo "<br />\n";

if ($foto['opis']!=null)
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($foto['opis']))))))))."<br />\n";
echo "</div>\n";
echo "<a href='/foto/foto0/$foto[id].$foto[ras]' title='Скачать оригинал'>";
echo "Скачать фото";
echo " (".size_file(filesize(H.'sys/gallery/foto/'.$foto['id'].'.jpg')).")";
echo "</a><br />\n";
echo "<a href='/foto/$ank[id]/$gallery[id]/komm/$foto[id]/'>Комментарии (".mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '$foto[id]'"),0).")</a><br />\n";







echo " </br><div class='rowup'> Другие фото альбома</br>";


$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_gallery` = '$gallery[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if ($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет фотографий\n";
echo "  </td>\n";
echo "   </tr>\n";

}


$q=mysql_query("SELECT * FROM `gallery_foto` WHERE `id_gallery` = '$gallery[id]' ORDER BY RAND() DESC LIMIT 4");
while ($post = mysql_fetch_assoc($q))
{

if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";
echo "<img src='/foto/foto48/$post[id].$post[ras]' alt='Фото_$post[id]' />";
}
elseif ($set['set_show_icon']==1)
{

}

echo "<a href='/foto/$ank[id]/$gallery[id]/$post[id]/'> <img src='/foto/foto128/$post[id].$post[ras]' alt='Фото_$post[id]' width='45' height='45'  /></a>";







}






echo "</div><div class=\"foot\">\n";


if (user_access('foto_foto_edit') && $ank['level']>$user['level'] || isset($user) && $ank['id']==$user['id'])
include 'inc/gallery_show_foto_form.php';

echo "&laquo;<a href='/foto/$ank[id]/$gallery[id]/'>К фотографиям</a><br />\n";
echo "&laquo;<a href='/foto/$ank[id]/'>К фотоальбомам</a><br />\n";

echo "</div>\n";
include_once '../sys/inc/tfoot.php';
exit;
?>