<?
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']=''.$gallery['name'].''; // название альбома

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']>=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']<250){echo '<div class="msg"><b>Оценка 5+ стоит 250 монет у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-250)."' 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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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/icons/5.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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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 `ocenka` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '[url=/info.php?id=$user[id]/][b]$user[nick][/b][/url] оценил Вашу фотографию   \n [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='mytitle'>\n";
echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a><br/>\n";
echo "$foto[name]\n";
echo "</div>\n";
echo "<div class=\"dnev\">\n";
echo "<a href='/foto/$ank[id]/$gallery[id]/komm/$foto[id]/'><font color='#8b8b88'><u>Комментарии</u> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '$foto[id]'"),0).")</font></a><br />\n";
echo "</div>\n";
echo "<span style=\"color:$ank[mcolor]\">\n";
if ($foto['opis']!=null)
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($foto['opis']))))))))."<br />\n";
echo "</span>\n";
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 "<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/>";

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 "<a href=\"?id=$foto[id]&amp;rating=upigis\" title=\"Отдать положительный голос\"><font color='red'>Оценить на <b><span style=\"color:$ank[mcolor]\">5+</span></b>!</font></a> ";
else
if (isset($user) && $user['id']!=$ank['id'])echo "Ваша оценка 5+!\n";
echo "</div>\n";
echo "<div class=\"dnev\">\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 "</div>\n";
echo "<div class=\"dnev\">\n";
echo "<img src='/style/icons/5.png' alt='' class='icon'/> \n";
echo "<span style=\"color:$ank[mcolor]\">$foto[rating5]</span>";
echo " <img src='/style/img/reiting.gif' alt='' class='icon'/> \n";
echo "<span style=\"color:$ank[mcolor]\">$foto[rating]</span>";

echo "</div>\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 "<div class='fotoname'>\n";
echo "Другие фото альбома <span style=\"color:$ank[mcolor]\">$gallery[name]</span>\n";
echo "</div>\n";
include_once 'inc/show_gallary.php';


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