Файл: gallery.php
Строк: 37
<?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;
}
$do = isset($_GET['do']) ? $_GET['do'] : NULL;
switch($do) {
default:
if (isset($_POST['add'])) {
$prev = (int)$_POST['prev'];
mysql_query("UPDATE users SET set_prev = '$prev' WHERE id = '$user[id]'");
header('Location: photo_gallery?');
}
$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);
$p_random = mysql_query("SELECT photo, user FROM users WHERE vote_photo > 0 AND photo != '' ORDER BY vote_photo DESC LIMIT 10");
echo '<b>Фотки юзеров чата!</b>
<br/>---<br/>
<a href="?do=all">Все фотки</a> (' . $p_all . ')<br/>
<a href="?do=boys">Парни</a> (' . $p_boys . ')<br/>
<a href="?do=girls">Девушки</a> (' . $p_girls . ')
<br/>---<br/>
10 лучших фото:<br/>';
while($vw = mysql_fetch_array($p_random)) {
echo '<img src="resize.php?img='.$vw[0].'&width='.$user['set_prev'].'&height=0" alt="*"/>' . nik($vw[1]) . '<br/>';
}
echo '<br/>---<br/>
Предпросмотр: (' . $user['set_prev'] . 'x' . $user['set_prev'] . ')<br/>
<form method="POST" action="?">
<select name="prev">
<option value="20">20*20</option>
<option value="40">40*40</option>
<option value="60">60*60</option>
<option value="120">120*120</option>
</select>
<input type="submit" name="add" value="OK"/>
</form>';
break;
case all:
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$start = ($page - 1) * 5;
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != ''"), 0);
$all = ceil($all/5);
$all = $all > 5 ? 5 : $all;
$view = mysql_query("SELECT * FROM `users` WHERE `photo` != '' ORDER BY `photo` DESC LIMIT ".abs(intval($start)).", 5");
if (mysql_affected_rows() != false) {
$i = $start + 1;
while($q = mysql_fetch_assoc($view)) {
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $i++ . ') <b>' . nik($q['user']) . '</b> (' . $siz . '/' . $W . 'x' . $H . ')<br/>
<a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&width='.$user['set_prev'].'&height=0" alt="*"/></a>
<br/>---<br/>';
}
} else {
echo '(пусто)<br/>';
}
for($i = 1; $i <= $all; $i++)
{
echo $pr=(($i == 1 || $i == $all || abs($i-$page) < 2) ? ($i == $page ? " [$i] " : ' <b><a href="?do=all&page='.$i.'">'.$i.'</a></b>') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
break;
case boys:
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$start = ($page - 1) * 5;
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != '' AND `sex` = '1'"), 0);
$all = ceil($all/5);
$all = $all > 5 ? 5 : $all;
$view = mysql_query("SELECT * FROM `users` WHERE `photo` != '' AND `sex` = '1' ORDER BY `photo` DESC LIMIT ".abs(intval($start)).", 5");
if (mysql_affected_rows() != false) {
$i = $start + 1;
while($q = mysql_fetch_assoc($view)) {
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $i++ . ') <b>' . nik($q['user']) . '</b> (' . $siz . '/' . $W . 'x' . $H . ')<br/>
<a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&width='.$user['set_prev'].'&height=0" alt="*"/></a>
<br/>---<br/>';
}
} else {
echo '(пусто)<br/>';
}
for($i = 1; $i <= $all; $i++)
{
echo $pr=(($i == 1 || $i == $all || abs($i-$page) < 2) ? ($i == $page ? " [$i] " : ' <b><a href="?do=boys&page='.$i.'">'.$i.'</a></b>') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
break;
case girls:
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$start = ($page - 1) * 5;
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `photo` != '' AND `sex` = '0'"), 0);
$all = ceil($all/5);
$all = $all > 5 ? 5 : $all;
$view = mysql_query("SELECT * FROM `users` WHERE `photo` != '' AND `sex` = '0' ORDER BY `photo` DESC LIMIT ".abs(intval($start)).", 5");
if (mysql_affected_rows() != false) {
$i = $start + 1;
while($q = mysql_fetch_assoc($view)) {
$size = getimagesize($q['photo']);
$W = $size[0];
$H = $size[1];
$siz = filesize($q['photo']);
$siz = get_size($siz);
echo $i++ . ') <b>' . nik($q['user']) . '</b> (' . $siz . '/' . $W . 'x' . $H . ')<br/>
<a href="'.$q['photo'].'"><img src="resize.php?img='.$q['photo'].'&width='.$user['set_prev'].'&height=0" alt="*"/></a>
<br/>---<br/>';
}
} else {
echo '(пусто)<br/>';
}
for($i = 1; $i <= $all; $i++)
{
echo $pr=(($i == 1 || $i == $all || abs($i-$page) < 2) ? ($i == $page ? " [$i] " : ' <b><a href="?do=girls&page='.$i.'">'.$i.'</a></b>') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
break;
}
echo gb.'<a href="'.H.'enter">Прихожая</a>'.div;
foot();
?>