<?php
require 'config.php';
$align = 'left';
$title = 'Фотогаллерея';
aut();
head();
who_add(0, 'enter');

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($mod) {
default:
$p_all = mysql_result(mysql_query("SELECT COUNT(*) FROM users WHERE photo != '' ORDER BY vote_photo DESC"), 0);
$p_boys = mysql_result(mysql_query("SELECT COUNT(*) FROM users WHERE photo != '' AND sex = '1' ORDER BY vote_photo DESC"), 0);
$p_girls = mysql_result(mysql_query("SELECT COUNT(*) FROM users WHERE photo != '' AND sex = '0' ORDER BY vote_photo DESC"), 0);

echo '<center><b>Фото Жителей Чата!</b><br/>--===--<br/>
В галерее оцениваются только ЛИЧНЫЕ фото.<br/>
Все иные картинки и аватары, на усмотрение Администрации, будут удалены<br/>--===--<br/>
Все фотки (<b><a href="?mod=all">' . $p_all . '</a></b>)<br/>-=-<br/>
Парни (<b><a href="?mod=boys">' . $p_boys . '</a>)</b><br/>-~-<br/>
Девушки (<b><a href="?mod=girls">' . $p_girls . '</a>)</b><br/>-=-<br/>';
echo gb.'<a href="'.H.'enter">Прихожая</a></center>'.div;
foot();
exit();
break;

//Все фотки
case all:
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != ''"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Пока фоток нет.<br/>';
}
$view=mysql_query("SELECT * FROM `users` WHERE `photo` != '' ORDER BY `photo` DESC LIMIT $start, $max");
$num_k=$start+1;
while($q = $db->sql_fetchrow($view))
{
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $num_k++.') <b>' . nik($q['user']) . '</b><br/><a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a><br/> (' . $siz . '/' . $W . 'x' . $H . ')<br/>---<br/>';
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mod=all&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
break;


//Парни
case boys:
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != '' AND `sex` = '1'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Пока фоток нет.<br/>';
}
$view=mysql_query("SELECT * FROM `users` WHERE `photo` != '' AND `sex` = '1' ORDER BY `photo` DESC LIMIT $start, $max");
$num_k=$start+1;
while($q = $db->sql_fetchrow($view))
{
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $num_k++.') <b>' . nik($q['user']) . '</b><br/><a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="*"/></a><br/>(' . $siz . '/' . $W . 'x' . $H . ')<br/>---<br/>';
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mod=boys&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
break;


//Девки
case girls:
if (empty($user['max']))
$user['max']=10;
$max = $user['max'];
$k_post=$db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != '' AND `sex` = '0'"),0);
$k_page=k_page($k_post,$max);
$page=page($k_page);
$start=$max*$page-$max;
if($k_post==0)
{
echo 'Пока фоток нет.<br/>';
}
$view=mysql_query("SELECT * FROM `users` WHERE `photo` != '' AND `sex` = '0' ORDER BY `photo` DESC LIMIT $start, $max");
$num_k=$start+1;
while($q = $db->sql_fetchrow($view))
{
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $num_k++.') <b>' . nik($q['user']) . '</b><br/>
<a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&amp;width='.$set['set_prev'].'&amp;height=0" alt="**"/></a><br/>(' . $siz . '/' . $W . 'x' . $H . ')<br/>---<br/>';
}
if ($k_page>1)
{
echo '<dl><dt></dt></dl>'.str('?mod=girls&amp;',$k_page,$page).'<dl><dt></dt></dl>';
}
break;


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