<?php

include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
 Error_Reporting(E_ALL & ~E_NOTICE);
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';

$set['title']='Фотоконкурс'; // заголовок страницы
include_once '../sys/inc/thead.php';

title();
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['closed']==0)
{
if (isset($user) & $user['rating']<=0)
{
if ($user['pol']==0){echo "Извини <b>красавица,</b> \n";} else {echo "<b>Извини братан,</b> \n";}
echo "но чтобы попасть в фотоконкурс нужно иметь хотябы <b>10</b> % рейтинга<br/>У вас <b>$user[rating]</b> % рейтинга\n";
}
else
{
err();
Error_Reporting(E_ALL & ~E_NOTICE);
/*
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==0)
{
echo "<div class=aut><center><b>Конкурс завершен!!!</b></center></div>";
echo '<div align="center">Результаты конкурса:</div>';
echo '<div class=menu_razd><b><u>Девушки</u></b></div><table class="post">';
$q_women=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='0' ORDER BY rating DESC LIMIT 3");
while ($ank_women = mysql_fetch_array($q_women)){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank_women[name] LIMIT 3"));


echo '<span style="color:'.$ank['ncolor'].'">'.online($ank['id']).''.$ank['nick'].'</span></a> '.$ank_women['rating'].' % рейтинга<br/>';

echo "<img src='/sys/foto/$ank_women[id].jpg'  width='60' height='50'><br />\n";

}


echo '</div>';



echo '<div class=menu_razd><b><u>Парни</u></b></div><table class="post">';
$q_men=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='1' ORDER BY rating DESC LIMIT 3");
while ($ank_men = mysql_fetch_array($q_men)){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank_men[name] LIMIT 3"));

echo '<span style="color:'.$ank['ncolor'].'">'.$ank['nick'].'</span></a> '.$ank_men['rating'].' % рейтинга<br/>';


echo "<img src='/sys/foto/$ank_men[id].jpg'  width='60' height='50'><br />\n";

}

echo '</div>';

}
else
{
*/
$mode = htmlspecialchars(trim($_GET['mode']));
switch($mode)
{
default:
$all_women = mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `id_foto` = '0'"), 0);
$all_men = mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `id_foto` = '1'"), 0);
$d=mysql_result(mysql_query("SELECT `d` FROM `foto_conf` WHERE `id` = '1' LIMIT 1",$db), 0);
$m=mysql_result(mysql_query("SELECT `m` FROM `foto_conf` WHERE `id` = '1' LIMIT 1",$db), 0);
$g=mysql_result(mysql_query("SELECT `g` FROM `foto_conf` WHERE `id` = '1' LIMIT 1",$db), 0);
echo "<div class='aut'><center><img src='/style/icons/clock.png' alt='' class='icon'/> Дата окончания <b>".$d.".".$m.".".$g."!</b></center></div>";
echo "<div class='menu_razd'>";
$nazvanie=mysql_result(mysql_query("SELECT `nazvanie` FROM `foto_conf` WHERE `id` = '1' LIMIT 1",$db), 0);
$k_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` ",$db), 0);
$k_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `time` > '".(time()-86400)."'",$db), 0);
if ($k_n==0)$k_n=NULL;
else $k_n='/+'.$k_n;
echo "".$nazvanie."<br/> участвуют <font color='red'>$k_p$k_n</font> обитателей";
echo "</div>";
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==1)
{
echo "<div class='tmn'>";
echo "Началось голосование!<br/>\n";
echo "</div>";
}

$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==0)
{
echo "<div class='tmn'>";
echo "Открыт прием фотографий на конкурс!<br/>\n";
echo "</div>";
}

echo "<img src='/style/icons/uk.png' alt='' class='icon'/>\n";
echo " <a href='/forum/1/144/'>Обсуждения/Вопросы</a><br />";
echo "<img src='/style/icons/gal.png' alt='' class='icon'/>\n";
echo " <a href='foto_rules.php'>Правила участия</a><br />";
echo "<img src='/foto_konkurs/crown.png' alt='' class='icon'/>\n";
echo " <a href='nagrada.php'>Награды</a><br />";
echo "<img src='/style/icons/many.gif' alt='' class='icon'/>\n";
echo " <a href='cena.php'>Стоимость оценок</a><br />";
echo '<div class="menu_razd">Случайные фото конкурса:</div>';

$q_women=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='0' ORDER BY rand() LIMIT 1");

while ($ank_women = mysql_fetch_array($q_women)){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank_women[name] LIMIT 1"));
echo ' <a href="index.php?mode=info&amp;id='.$ank_women['id'].'">';
echo "<img src='/sys/foto/$ank_women[id].jpg'  width='65' height='50'>\n";
echo '</a>';

$q_men=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='1' ORDER BY rand() LIMIT 1");
while ($ank_men = mysql_fetch_array($q_men)){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank_men[name] LIMIT 1"));
echo ' <a href="index.php?mode=info&amp;id='.$ank_men['id'].'">';

echo "<img src='/sys/foto/$ank_men[id].jpg'  width='65' height='50'>\n";

echo '</a>';

$q_men=mysql_query("SELECT * FROM `foto` ORDER BY rand() LIMIT 1");
while ($ank_men = mysql_fetch_array($q_men)){
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank_men[name] LIMIT 1"));
echo ' <a href="index.php?mode=info&amp;id='.$ank_men['id'].'">';

echo "<img src='/sys/foto/$ank_men[id].jpg'  width='65' height='50'>\n";

echo '</a>';

}
}
}

echo '</div>';
echo '<div class="rekl">';
echo "<img src='/foto_konkurs/woman.gif' alt=''/>";
	echo ' <a href="index.php?mode=all_women">Девушки</a> ('.$all_women.' фото)<br />';
	echo "<img src='/foto_konkurs/men.gif' alt=''/>";
	echo ' <a href="index.php?mode=all_men">Парни</a> ('.$all_men.' фото)<br/>';

echo '</div>';
break;

case 'all_women':

$asc='DESC';
$order='id';

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `id_foto`='0'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==1)
{
echo "<div class='tmn'>";
echo 'Прием фото окончен, началось голосование!';
echo '</div>';
}
if($k_post==0){
echo 'Нет девушек учавствующих в конкурсе';
}
$q=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='0' ORDER BY rand() LIMIT $start, $set[p_str]");
while($ank = mysql_fetch_array($q)){
$an=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank[name] LIMIT 1"));
{
echo "<div class='linechat'>";
echo "<img src='/foto_konkurs/woman.gif' alt='' class='icon'/>\n";
echo ' <a href="/info.php?id='.$an['id'].'"><span style="color:'.$an['ncolor'].'"><b>'.$an['nick'].'</b></span></a><br/>';



{
echo '<a href="index.php?mode=info&amp;id='.$ank['id'].'">';
echo "<img src='/sys/foto/$ank[id].jpg' width='70' height='70'><br />\n";
echo '</a>';
if (user_access('adm_rekl')){
echo '[<a href="delete.php?id='.$ank['id'].'"><span style="color:red">Удалить участника</span></a>]';
}}
echo "<div class='hello'>";
echo ''.$ank['opis'].'<br/>';
echo "</div>\n";
echo '</div>';
}}

echo '</div>';
if($k_page>1){
str('ixdex.php?mode=all_women&amp;',$k_page,$page);
}
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==0)
{
if (isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `name` = '$user[id]'"), 0)==0){
if ($user['pol']==0){
echo "<br/><img src='/style/icons/gal.png' alt='' class='icon'/>\n";
echo '<a href="addfoto.php"><b>Принять участие</b></a><br/>';}}
}

echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo '<a href="index.php">Назад</a><br/>';
break;

case 'all_men':
$asc='DESC';
$order='id';

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `id_foto`='1'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==1)
{
echo "<div class='tmn'>";
echo 'Прием фото окончен, началось голосование!';
echo '</div>';
}
if($k_post==0){
echo 'Нет парней учавствующих в конкурсе';
}
$q=mysql_query("SELECT * FROM `foto` WHERE `id_foto`='1' ORDER BY rand() LIMIT $start, $set[p_str]");
while($ank = mysql_fetch_array($q)){
$an=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank[name] LIMIT 1"));
{
echo "<div class='linechat'>";
echo "<img src='/foto_konkurs/men.gif' alt='' class='icon'/>\n";
echo ' <a href="/info.php?id='.$an['id'].'"><span style="color:'.$an['ncolor'].'"><b>'.$an['nick'].'</b></span></a><br/>';

{
echo '<a href="index.php?mode=info&amp;id='.$ank['id'].'">';
echo "<img src='/sys/foto/$ank[id].jpg' width='70' height='70'><br />\n";
echo '</a>';
if (user_access('adm_rekl')){
echo '[<a href="delete.php?id='.$ank['id'].'"><span style="color:red">Удалить участника</span></a>]';
}}
echo "<div class='hello'>";
echo '<span class="ank_d">'.$ank['opis'].'</span>';
echo "</div>\n";
echo "</div>\n";
}}

echo '</div>';
if($k_page>1){
str('ixdex.php?mode=all_men&amp;',$k_page,$page);
}
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==0)
{
if (isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `foto` WHERE `name` = '$user[id]'"), 0)==0){
if ($user['pol']==1){
echo "<br/><img src='/style/icons/gal.png' alt='' class='icon'/>\n";
echo '<a href="addfoto.php"><b>Принять участие</b></a><br/>';}}
}

echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo '<a href="index.php">Назад</a><br/>';
break;

case 'info':
$ank['id']=intval($_GET['id']);
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `name` = $ank[id] LIMIT 1"));
$q=mysql_query("SELECT * FROM `foto` WHERE `id` = '".intval($_GET['id'])."'");
while ($foto = mysql_fetch_array($q))
{
if (isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `foto_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
{
if(isset($_GET['rating']) && $_GET['rating']=='1'){
if($user['balls']<50){echo '<div class="menu_razd"><font color="red">Оценка +1 стоит 50 LM у Вас нет столько LaFeS MoNeY <br/>Заработайте и приходите!</font></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-50)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `foto` SET `rating` = '".($foto['rating']+1)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш голос на +1 (-50LM)');
$foto=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
if(isset($_GET['rating']) && $_GET['rating']=='2'){
if($user['balls']<75){echo '<div class="menu_razd"><font color="red">Оценка +2 стоит 75 LM у Вас нет столько LaFeS MoNeY <br/>Заработайте и приходите!</font></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-75)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `foto` SET `rating` = '".($foto['rating']+2)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш голос на +2 (-75LM)');
$foto=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
if(isset($_GET['rating']) && $_GET['rating']=='3'){
if($user['balls']<100){echo '<div class="menu_razd"><font color="red">Оценка +3 стоит 100 LM у Вас нет столько LaFeS MoNeY <br/>Заработайте и приходите!</font></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-100)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `foto` SET `rating` = '".($foto['rating']+3)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш голос на +3 (-100LM)');
$foto=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
if(isset($_GET['rating']) && $_GET['rating']=='4'){
if($user['balls']<200){echo '<div class="menu_razd"><font color="red">Оценка +4 стоит 200 LM у Вас нет столько LaFeS MoNeY <br/>Заработайте и приходите!</font></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-200)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `foto` SET `rating` = '".($foto['rating']+4)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш голос на +4 (-200LM)');
$foto=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
if(isset ($_GET['rating']) && $_GET['rating']=='5'){
if($user['balls']<300){echo '<div class="menu_razd"><font color="red">Оценка +5 стоит 300 LM у Вас нет столько LaFeS MoNeY <br/>Заработайте и приходите!</font></div>';
}
else
{
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-300)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `foto` SET `rating` = '".($foto['rating']+5)."' WHERE `id` = '$foto[id]' LIMIT 1",$db);
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`) values('$user[id]', '$foto[id]')",$db);
msg ('Ваш голос на +5 (-300LM)');
$foto=mysql_fetch_array(mysql_query("SELECT * FROM `foto` WHERE `id` = $foto[id] LIMIT 1"));}
}
}

echo "<img src='/sys/foto/$foto[id].jpg' alt=''/><br />\n";
echo "<div class='rekl_main'>";

$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==1)
{
echo "<img src='/style/icons/konkurs16.png' alt='' class='icon'/> Рейтинг: ";
echo "<font color='red'>$foto[rating]</font><br/>";
if (isset($user) && $user['id']!=$foto['name'] && $user['balls']>=50 && $user['rating']>=0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `foto_rating` WHERE `id_user` = '$user[id]' AND `id_foto` = '$foto[id]'"), 0)==0)
{
echo " <a href=\"?mode=info&amp;id=$foto[id]&amp;rating=1\" title=\"Отдать положительный голос\"><img src='/style/ocenki/1.png' alt='' class='icon'/></a> ";
echo " <a href=\"?mode=info&amp;id=$foto[id]&amp;rating=2\" title=\"Отдать положительный голос\"><img src='/style/ocenki/2.png' alt='' class='icon'/></a> ";
echo " <a href=\"?mode=info&amp;id=$foto[id]&amp;rating=3\" title=\"Отдать положительный голос\"><img src='/style/ocenki/3.png' alt='' class='icon'/></a> ";
echo " <a href=\"?mode=info&amp;id=$foto[id]&amp;rating=4\" title=\"Отдать положительный голос\"><img src='/style/ocenki/4.png' alt='' class='icon'/></a> ";
echo " <a href=\"?mode=info&amp;id=$foto[id]&amp;rating=5\" title=\"Отдать положительный голос\"><img src='/style/ocenki/5.png' alt='' class='icon'/></a>";
echo "<br />\n";

}
}
}
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['set_konkurs']==0)
{
echo "<img src='/style/icons/rules.png' alt='' class='icon'/> Голосование еще не началось!";
}
echo "</div>\n";
echo "<div class='aut'>";
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo '<a href="index.php">Назад</a>';
echo "</div>\n";
}
}
}
$fot=mysql_fetch_array(mysql_query("SELECT * FROM `foto_conf`"));
if ($fot['closed']==1)
{
echo "<div class='p_t'>";
echo "<img src='/style/icons/rules.png' alt='' class='icon'/> Нет активных конкурсов! Свои идеи по поводу проведения конкурсов просьба писать на форум!";
echo "</div>\n";
}
include_once '../sys/inc/tfoot.php';
?>