<?php
require 'config.php';
aut();
who_add(0,'enter');
$align='center';
$title=''.$set['name_kon'].'';
head();

if($set['fotooff']!=1){echo 'Типа самый умный?:)';
}else{

function get_size($size)
{
if ($size < 1024) $size = $size.' бт.';
if ($size > 1024 and $size < 1048576) $size = round($size / 1024, 1).' кб.';
if ($size >= 1048576) $size = round(($size / 1024) / 1024, 1).' мб.';
return $size;
}

switch(check($_GET['mode']))
{
default:

$all_women = mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `id_foto` = '0' and `mod` = '1'"), 0);
$all_men = mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `id_foto` = '1' and `mod` = '1'"), 0);
echo '<b><a href="/foto_rules.php"> Правила участия</a></b><br/>- - -<br/><a href="foto.php?mode=all_women">Девушки</a> ('.$all_women.' фото)<br/>- - - -<br/><a href="foto.php?mode=all_men">Парни</a> ('.$all_men.' фото)<br/>- - - - -<br/>'.$set['name_1'].'<br/>';


$q_women=mysql_query("SELECT * FROM `kon_foto` WHERE `id_foto`='0' AND `mod`='1' ORDER BY rating DESC LIMIT 1");
while($ank_women = mysql_fetch_assoc($q_women))
{
if(!empty($ank_women['id']))
{
$ank=mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank_women['name']."' LIMIT 1"));
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo '<hr/>Лучшая девушка<br/><a href="'.$ank[id].'"><img src="resize.php?img='.H.$ank_women['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/>
<a href="foto.php?mode=info&amp;id='.$ank_women['id'].'">'.$ank['user'].'</a> (<a href="foto.php?mode=rat&amp;id='.$ank_women['id'].'">'.$ank_women['rating'].'</a>)<br/>'.$ank_women['opis'].'<br/>';
}
}
echo '<hr/>';
$q_men=mysql_query("SELECT * FROM `kon_foto` WHERE `id_foto`='1' AND `mod`='1' ORDER BY rating DESC LIMIT 1");
while($ank_men = mysql_fetch_assoc($q_men))
{
if(!empty($ank_men['id']))
{
$ank=mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank_men['name']."' LIMIT 1"));
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo ''.$set['name_1'].'<br/><a href="'.$ank[id].'"><img src="resize.php?img='.H.$ank_men['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/><a href="foto.php?mode=info&amp;id='.$ank_men['id'].'">'.$ank['user'].'</a> (<a href="foto.php?mode=rat&amp;id='.$ank_men['id'].'">'.$ank_men['rating'].'</a>)<br/>'.$ank_men['opis'].'<br/><hr/>';
}
}
if(mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `name` = '".$user['id']."'"),0)==0)
{
echo '<a href="kon_addfoto.php"><b>Принять участие</b></a><br/>-=*=-<br/>';
}
if(mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `name` = '".$user['id']."'"),0)==1)
{
echo '<a href="?mode=dell"><b>Удалить свое фото</b></a><br/>-=*=-<br/>';
}
if($user['level']==9){echo '<a href="?mode=mod"><b>Управление конкурсом</b></a><br/>-=**=-<br/>
<a href="?mode=users"><b>Управление учасниками</b></a><br/>-=***=-<br/>';}
break;


//Удаление фото
case dell:
$to = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `name`='".$user['id']."'"));
$msg = 'Ваше фото в [url=/foto]конкурсе[/url] успешно удалено';
mysql_query ("INSERT INTO `privat` (user,user_id,to_user,to_id,time,msg)VALUES ('".$user_system."','0','".$to['name']."','".$to['name']."','$time','$msg')");
mysql_query("DELETE FROM `kon_foto` WHERE `name` = '".$user['id']."'");
unlink (H.$to['path'].'');
header('Location: ?');
exit;
break;


//Все Девушки
case all_women:
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `id_foto`='0' AND `mod`='1'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Нет девушек учавствующих в конкурсе.<br/>';
}
$q=mysql_query("SELECT * FROM `kon_foto` WHERE `id_foto`='0' AND `mod`='1' ORDER BY `id` DESC LIMIT $start, $max");
while($ank = mysql_fetch_array($q))
{
$an=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank['name']."' LIMIT 1"));
{
echo '<a href="'.$an[id].'"><img src="resize.php?img='.H.$ank['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/>
<a href="foto.php?mode=info&amp;id='.$ank['id'].'">'.$an['user'].'</a><br/>'.$ank['opis'].'<br/><hr/>';
}
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mode=all_women&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
if(mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `name` = '".$user['id']."'"),0)==0)
{
echo '<a href="kon_addfoto.php"><b>Принять участие</b></a><br/>';
}
echo '-==-<br/><a href="foto.php">Назад</a><br/>';
break;


//Все Парни
case all_men:
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `id_foto`='1' AND `mod`='1'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Нет парней учавствующих в конкурсе.<br/>';
}
$q=mysql_query("SELECT * FROM `kon_foto` WHERE `id_foto`='1' AND `mod`='1' ORDER BY `id` DESC LIMIT $start, $max");
while($ank = mysql_fetch_array($q))
{
$an=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank['name']."' LIMIT 1"));
{
echo '<a href="'.$an[id].'"><img src="resize.php?img='.H.$ank['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/>
<a href="foto.php?mode=info&amp;id='.$ank['id'].'">'.$an['user'].'</a><br/>'.$ank['opis'].'<br/><hr/>';
}
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mode=all_men&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
if(mysql_result(mysql_query("SELECT count(*) FROM `kon_foto` WHERE `name` = '".$user['id']."'"),0)==0)
{
echo '<a href="kon_addfoto.php"><b>Принять участие</b></a><br/>';
}
echo '-==-<br/><a href="foto.php">Назад</a><br/>';
break;


 //Инфо участника
case info:
if(isset($_GET['err']))
{
$err=intval($_GET['err']);
if($err==1)echo '<b>Ссылку перепутал?гг</b><br />';
elseif($err==2)echo '<b>Вы уже голосовали!</b><br />';
}
if(isset($_GET['id']))$id=intval($_GET['id']);
$foto = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `id` = '".$id."' AND `mod`='1'"));
if($foto['mod']==1)
{
if(isset($_GET['rating']))
{
$rat=intval($_GET['rating']);
if($rat == 0 or $rat > 5)
{
header('Location: ?mode=info&id='.$foto['id'].'&err=1');
exit;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `foto_rating` WHERE `id_user` = '".$user['id']."' AND `id_foto` = '".$foto['id']."'"),0)==1)
{
header('Location: ?mode=info&id='.$foto['id'].'&err=2');
exit;
}
mysql_query("UPDATE `kon_foto` SET `rating` = '".($foto['rating']+$rat)."' WHERE `id` = '".$foto['id']."' LIMIT 1");
mysql_query("INSERT INTO `foto_rating` (`id_user`, `id_foto`, `rat`) values('".$user['id']."', '".$foto['id']."', '".$rat."')");
}
echo '<img src="resize.php?img='.H.$foto['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/><a href="'.H.$foto['path'].'">Скачат фото</a><br/>
<br/>Рейтинг: <a href="?mode=rat&amp;id='.$foto['id'].'">'.$foto['rating'].'</a><br/>';
if (isset($user) && $user['id']!=$foto['name'] && $user['posts']>=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="Отдать положительный голос">+1</a>|
<a href="?mode=info&amp;id='.$foto['id'].'&amp;rating=2" title="Отдать положительный голос">+2</a>|
<a href="?mode=info&amp;id='.$foto['id'].'&amp;rating=3" title="Отдать положительный голос">+3</a>|
<a href="?mode=info&amp;id='.$foto['id'].'&amp;rating=4" title="Отдать положительный голос">+4</a>|
<a href="?mode=info&amp;id='.$foto['id'].'&amp;rating=5" title="Отдать положительный голос">+5</a>
<br/>';
}
}
else
{
echo '<b>Фото еще не прошло модерацию!</b><br />';
}
echo '<a href="/foto.php">Назад</a><br/>';
break;

//Модероция фото
case mod:
levels(9);
if(isset($_GET['err']))
{
$err=intval($_GET['err']);
if($err==1)echo '<b>Не выбран юзер!</b><br />';
elseif($err==2)echo '<b>Фото допущено!</b><br />';
elseif($err==3)echo '<b>Фото не допущено!</b><br />';
}
if(isset($_GET['dopysk']))
{
$dop=intval($_GET['dopysk']);
$ids=intval($_GET['ids']);
if(empty($ids))
{
header('Location: ?mode=mod&amp;err=1');
exit;
}
if($dop==2)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `id`='".$ids."'"),0)==1)
{
$to = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `id`='".$ids."'"));
$msg = 'Администратор '.$user['user'].' недопустил(а) ваше фото для участия в [url=/foto]конкурсе[/url]';
mysql_query ("INSERT INTO `privat` (user,user_id,to_user,to_id,time,msg)VALUES ('".$user_system."','0','".$to['name']."','".$to['name']."','$time','$msg')");
mysql_query("DELETE FROM `kon_foto` WHERE `id` = '".$ids."'");
unlink (H.$to['path'].'');
header('Location: ?mode=mod&amp;err=3');
exit;
}
}
if($dop==1)
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `id`='".$ids."'"),0)==1)
{
if(mysql_query("UPDATE `kon_foto` SET `mod` = '1' WHERE `id` = '".$ids."'"))
{
$to = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `id`='".$ids."'"));
$msg = 'Администратор '.$user['user'].' допустил(а) ваше фото для участия в [url=/foto]конкурсе[/url]';
mysql_query ("INSERT INTO `privat` (user,user_id,to_user,to_id,time,msg)VALUES ('".$user_system."','0','".$to['name']."','".$to['name']."','$time','$msg')");
header('Location: ?mode=mod&amp;err=2');
exit;
}
}
}
}
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `mod`='0'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Нет желающих участвовать.<br/>';
}
$q=mysql_query("SELECT * FROM `kon_foto` WHERE `mod`='0' ORDER BY `id` DESC LIMIT $start, $max");
while($ank = mysql_fetch_array($q))
{
$an=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank['name']."' LIMIT 1"));
{
echo '<a href="'.$ank[id].'"><img src="resize.php?img='.H.$ank['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/>
<a href="foto.php?mode=info&amp;id='.$ank['id'].'">'.$an['user'].'</a><br/>'.$ank['opis'].'<br/>[<a href="?mode=mod&amp;dopysk=1&amp;ids='.$ank['id'].'">Допустить</a>][<a href="?mode=mod&amp;dopysk=2&amp;ids='.$ank['id'].'">Не допустить</a>]<br/>- - -<br/><br/>';
}
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mode=mod&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
echo '<br/>-==-<br/><a href="foto.php">Назад</a><br/>';
break;


//Участники конкурса
case users:
levels(9);
if($_GET['x']==1)
{
$ids=intval($_GET['id']);
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `id`='".$ids."'"),0)==1)
{
$to = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `id`='".$ids."'"));
mysql_query("DELETE FROM `kon_foto` WHERE `id` = '".$ids."'");
unlink (H.$to['path'].'');
header('Location: ?mode=users');
exit;
}
}
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `kon_foto` WHERE `mod`='1'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Никого нет :(.<br/>';
}
$q=mysql_query("SELECT * FROM `kon_foto` WHERE `mod`='1' ORDER BY `id` DESC LIMIT $start, $max");
while($ank = mysql_fetch_array($q))
{
$an=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$ank['name']."' LIMIT 1"));
{
$del='<a href="?mode=users&amp;x=1&id='.$ank['id'].'"><b>[DELETE]</b></a>';
$edit='<a href="?mode=edit&amp;id='.$ank['id'].'"><b>[EDIT]</b></a>';
echo menu.$del.$edit.div.'<a href="'.$ank[id].'"><img src="resize.php?img='.H.$ank['path'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a></img><br/><a href="foto.php?mode=info&amp;id='.$ank['id'].'">'.$an['user'].'</a><br/>'.$ank['opis'].'<br/>-~-<br/>';
}
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mode=all_men&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
echo '<a href="foto">Назад</a><br />';
break;


//Редактирование учасника
case edit:
levels(9);
if(isset($_GET['id']))$ids=intval($_GET['id']);
if(isset($_GET['err']))
{
$err=intval($_GET['err']);
if($err==1)echo '<b>Пустое описание!</b><br />';
elseif($err==2)echo '<b>Описание сохранено!</b><br />';
}
$e = mysql_fetch_assoc(mysql_query("SELECT * FROM `kon_foto` WHERE `id`='".$ids."'"));
if(empty($act))
{
echo '<form action="?mode=edit&amp;id='.$e['id'].'&amp;act=act" method="post"><br />
Описание:<br />
<input name="txt" type="text" value="'.$e['opis'].'"><br />
<input type="submit" value="Сохранить">
</form>';
}
if($act=='act')
{
$txt=check($_POST['txt']);
if(empty($txt))
{
header('Location: ?mode=edit&id='.$e['id'].'&err=1');
exit;
}
mysql_query("UPDATE `kon_foto` SET `opis`='".$txt."' WHERE `id`='".$e['id']."'");
header('Location: ?mode=edit&id='.$e['id'].'&err=2');
}
break;


//Рейтинг
case rat:
$ids=intval($_GET['id']);
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `foto_rating` WHERE `id_foto`='".$ids."'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Никого нет :(.<br/>';
}
$q=mysql_query("SELECT * FROM `foto_rating` WHERE `id_foto`='".$ids."' ORDER BY `id` DESC LIMIT $start, $max");
while($ank = mysql_fetch_array($q))
{
echo nik($ank['id_user']).' '.$ank['rat'].'<br/>-~-<br/>';
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mode=rat&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
echo '<a href="foto">Назад</a><br/>';
break;

}
}
echo gb.'<a href="'.H.'enter">Прихожая</a><br/>'.div;
foot();
?>