<?
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']; // заголовок страницы

include_once '../sys/inc/thead.php';
title();
aut();
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']>=0 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery5_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
{
if(isset($_GET['rating']) && $_GET['rating']=='upigis'){
if($user['balls']<0){echo '<div class="msg"><b>Оценка 5+ стоит 250 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-0)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating5` = '".($foto['rating5']+1)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+15)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery5_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию [url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [img]http://$_SERVER[HTTP_HOST]/style/5i.png[/img] в фотоальбоме [b]$gallery[name][/b] (максимальная оценка)\n', '$time')");
///
mysql_query("INSERT INTO `gallery_foto` (`id_foto`, `id_user`, `time`, `msg`) values('$foto[id]', '$user[id]', '$time', '".my_esc($msg)."')");
///
msg ('Ваша оценка 5+ (-250 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
////
}
}

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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'){
if($user['balls']<5){echo '<div class="msg"><b>Оценка +1 стоит 5 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-5)."' WHERE `id` = '$user[id]' LIMIT 1");
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);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]1[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 1 (-5 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
elseif(isset($_GET['rating']) && $_GET['rating']=='up'){
if($user['balls']<10){echo '<div class="msg"><b>Оценка +2 стоит 10 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-10)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+2)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию [url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]2[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 2 (-10 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
/////////////////////////////////////
elseif(isset($_GET['rating']) && $_GET['rating']=='upi'){
if($user['balls']<20){echo '<div class="msg"><b>Оценка +3 стоит 20 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-20)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+3)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию [url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]3[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 3 (-20 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
/////////////////////////////////////
elseif(isset($_GET['rating']) && $_GET['rating']=='upig'){
if($user['balls']<50){echo '<div class="msg"><b>Оценка +4 стоит 50 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-50)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+4)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию [url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]4[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 4 (-50 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
//////////////////////////////////////
elseif(isset($_GET['rating']) && $_GET['rating']=='upigi'){
if($user['balls']<100){echo '<div class="msg"><b>Оценка +5 стоит 100 баллов у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-100)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+5)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `gallery_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
mysql_query("INSERT INTO `lenta` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/id$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию [url=/foto/$ank[id]/$gallery[id]/$foto[id]/][img]http://$_SERVER[HTTP_HOST]/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]5[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 5 (-100 баллов)');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
/////
}
}


err();
echo "<div class='pa'>";
echo "<img src='/icons/down.png' alt='' /> Другие фото альбома $gallery[name]<br/>\n";

include_once 'inc/show_gallary.php';
echo "</div>\n";
echo "<div class='faz'>";
echo " <img src='/style/icons/6.png' alt='' /> \n";
echo "$foto[rating5]";
echo " <img src='/icons/label.png' alt='' /> - \n";
echo "<b>$foto[rating]</b><br/>";





if ($foto['opis']!=null)echo "<font color='gray'>Описание:</font> ".esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($foto['opis']))))))))."<br />\n";
else 
echo "<font color='#8e908e'>Описание отсутствует</font><br/>\n";

echo "<a href='/foto/foto0/$foto[id].$foto[ras]' title='Скачать оригинал'>";
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 "</a>\n";
echo "<img src='/icons/mnen.png'> <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 "</div>\n";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery5_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)

echo "<div class='dop_menu'><a href=\"?id=$foto[id]&amp;rating=upigis\" title=\"Отдать положительный голос\"><img src='/style/icons/6.png' alt='' /> Макс. оценка</a><br/>";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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 "<div class='pa'><font color='black'><a href=\"?id=$foto[id]&amp;rating=upigi\" title=\"Отдать положительный голос\"> <font color='black'>+5</font></a> |";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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=upig\" title=\"Отдать положительный голос\"><font color='black'>+4</font></a> |";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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=upi\" title=\"Отдать положительный голос\"><font color='black'>+3</font></a> |";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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=\"Отдать положительный голос\"><font color='black'>+2</font></a> |";

if (isset($user) && $user['id']!=$ank['id'] && $user['balls']>=0 && $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=\"Отдать положительный голос\"><font color='black'>+1</font></a> </font><br/></div>";
echo '</div>';

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



echo "<div class='dop_menu'>\n";
echo "<img src='/icons/169.png' alt='' /> <a href='/foto/'>Вернуться в альбомы</a>\n";
echo "</div>\n";	


include_once '../sys/inc/tfoot.php';
exit;
?>