<?
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'].' - '.$foto['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 `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 LM у Вас нет столько денег!</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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]+1[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 1');$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 LM у Вас нет столько денег!</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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]+2[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 2');$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 LM у Вас нет столько денег!</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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]+3[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 3');$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 LM у Вас нет столько денег!</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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]+4[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 4');$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 LM у Вас нет столько денег!</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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [red][b]+5[/b][/red] в фотоальбоме [b]$gallery[name][/b]', '$time')");
msg ('Ваша оценка 5');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
/////
}
elseif(isset($_GET['rating']) && $_GET['rating']=='upigis'){
if($user['balls']<250){echo '<div class="msg"><b>Оценка 5+ стоит 250 LM у Вас нет столько денег!</b></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-250)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `gallery_foto` SET `rating` = '".($foto['rating']+15)."' 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://lafes.ru/foto/foto48/$foto[id].$foto[ras][/img][/url] на [img]http://lafes.ru/style/icons/5.png[/img] в фотоальбоме [b]$gallery[name][/b] \n + 15 % рейтинга к фото!', '$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 LM');$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = $foto[id] LIMIT 1"));}
////
}
}




err();
echo "<div class=\"tmn\"><center>\n";
echo "Фото\n";
echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a>\n";
echo "</center></div>\n";
echo "<div style='text-align: center;'>\n";
echo "<div class='dnev'>";
echo "<font color='#4d4c4c'>";
if ($foto['opis']!=null)
echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($foto['opis']))))))))."<br />\n";
else 
echo "Описания нет =(<br/>\n";
echo "</font>\n";
echo "</div>\n";
echo "<div class='gmenu'>";
echo "<center>\n";
echo "<img src='/style/icons/votes.png' alt='' class='icon'/> <span class=\"ank_n\"></span> ";
echo "<font color='red'>$foto[rating]</font>";
echo " <img src='/style/icons/chat.gif' alt='' class='icon'/> <a href='/foto/$ank[id]/$gallery[id]/komm/$foto[id]/'><font color='#4d4c4c'><u>".mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '$foto[id]'"),0)."</u></font></a>\n";
echo "</center></div>\n";
echo "<a href='/foto/foto0/$foto[id].$foto[ras]' title='Скачать оригинал'>";
if ($set['web'])
{
echo "<img class='show_foto' src='/foto/foto0/$foto[id].$foto[ras]' alt='$foto[name]' /><br />\n";
}
else
{
echo "<img class='show_foto' src='/foto/foto0/$foto[id].$foto[ras]' alt='$foto[name]' /><br />\n";
}
echo "</a>\n";
echo "<div class='gmenu'><center>";
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=upigis\" title=\"Отдать положительный голос\"><img src='/style/ocenki/15.gif' alt='' class='icon'/></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=upigi\" title=\"Отдать положительный голос\"><font color='red'><img src='/style/ocenki/5.png' alt='' class='icon'/></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=\"Отдать положительный голос\"><img src='/style/ocenki/4.png' alt='' class='icon'/></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=\"Отдать положительный голос\"><img src='/style/ocenki/3.png' alt='' class='icon'/></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=\"Отдать положительный голос\"><img src='/style/ocenki/2.png' alt='' class='icon'/></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=\"Отдать положительный голос\"><img src='/style/ocenki/1.png' alt='' class='icon'/></a> ";

if (user_access('foto_foto_edit') && $ank['level']>$user['level'] || isset($user) && $ank['id']==$user['id'])

include 'inc/gallery_show_foto_form.php';
echo "</center>\n";
echo "</div>\n";
echo "<div class='aut'><center>";
echo "Другие фото альбома\n";
echo "</center></div>\n";
include_once 'inc/show_gallary.php';

echo "<div class=\"p_t\">\n";

echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='/foto/$ank[id]/'>К фотоальбомам</a><br />\n";

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