Размер файла: 11.85Kb
<?php
// by mides, 1da.su
$title = 'Фотогалерея';
require_once 'system/sys.php';
require_once 'system/header.php';
$config['onpage'] = 4;
$type = 'photos';
switch ($act) {
default:
echo '<div class="title">Фотогалерея</div><div class="list">';
echo '<a href="?act=my&id='.$u['id'].'">Мой альбом</a> / <a href="?act=photo_add">Добавить фото</a><br /><br />';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos`"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$gallery_r = mysql_query("SELECT * FROM `photos` ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while ($gallery = mysql_fetch_assoc($gallery_r)) {
if (!isset($num) ) $num = 1;
$num++;
$row_class = (!($num % 2)) ? 'row1' : 'row2';
if ($gallery['rating'] > 0) {
$rating = '<b><font color="green">+'.$gallery['rating'].'</font></b>';
} elseif ($gallery['rating'] < 0) {
$rating = '<b><font color="red">'.$gallery['rating'].'</font></b>';
} else {
$rating = '<b>'.$gallery['rating'].'</b>';
}
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos_comm` WHERE `id_photos` = '$gallery[id]'"), 0);
echo '<div class="'.$row_class.'"><img src="inc/gallery.gif"> <a href="?act=view&id='.$gallery['id'].'"><b>'.$gallery['name'].'</b></a> ('.$rating.')<br /><a href="?act=view&id='.$gallery['id'].'"><img src="inc/gallery/'.$gallery['file'].'" width="150" height="100" alt="'.$gallery['name'].'" /></a><br />Добавлено: '.login($gallery['id_user']).' ('.date('d.m.y, H:i', $gallery['time']).')<br /><a href="?act=comm&id='.$gallery['id'].'">Комментарии</a> ('.$comm.')</div>';
}
} else {
echo 'Не загружено ни одного фото.<br />';
}
navig($page, '?', $pages);
if ($u['id']) echo '<br /><a href="">Все альбомы</a> / <a href="?act=top">Топ фото</a>';
nav_main();
break;
case 'top':
echo '<div class="title"><a href="?">Фотогалерея</a> > TOP фото</div><div class="list">';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos`"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$gallery_r = mysql_query("SELECT * FROM `photos` ORDER BY `rating` DESC LIMIT $begin, $config[onpage]");
while ($gallery = mysql_fetch_assoc($gallery_r)) {
if (!isset($num) ) $num = 1;
$num++;
$row_class = (!($num % 2)) ? 'row1' : 'row2';
if ($gallery['rating'] > 0) {
$rating = '<b><font color="green">+'.$gallery['rating'].'</font></b>';
} elseif ($gallery['rating'] < 0) {
$rating = '<b><font color="red">'.$gallery['rating'].'</font></b>';
} else {
$rating = '<b>'.$gallery['rating'].'</b>';
}
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos_comm` WHERE `id_photos` = '$gallery[id]'"), 0);
echo '<div class="'.$row_class.'"><img src="inc/gallery.gif"> <a href="?act=view&id='.$gallery['id'].'"><b>'.$gallery['name'].'</b></a> ('.$rating.')<br /><a href="?act=view&id='.$gallery['id'].'"><img src="inc/gallery/'.$gallery['file'].'" width="150" height="100" alt="'.$gallery['name'].'" /></a><br />Добавлено: '.login($gallery['id_user']).' ('.date('d.m.y, H:i', $gallery['time']).')<br /><a href="?act=comm&id='.$gallery['id'].'">Комментарии</a> ('.$comm.')</div>';
}
} else {
echo 'Пусто.<br />';
}
navig($page, '?act=my&id='.$id.'&', $pages);
if ($u['id']) echo '<br /><a href="?">Фотогалерея</a> / <a href="">Все альбомы</a>';
nav_main();
break;
case 'my':
echo '<div class="title"><a href="?">Фотогалерея</a> > by '.login($id).'</div><div class="list">';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos` WHERE `id_user` = '$id'"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$gallery_r = mysql_query("SELECT * FROM `photos` WHERE `id_user` = '$id' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while ($gallery = mysql_fetch_assoc($gallery_r)) {
if (!isset($num) ) $num = 1;
$num++;
$row_class = (!($num % 2)) ? 'row1' : 'row2';
if ($gallery['rating'] > 0) {
$rating = '<b><font color="green">+'.$gallery['rating'].'</font></b>';
} elseif ($gallery['rating'] < 0) {
$rating = '<b><font color="red">'.$gallery['rating'].'</font></b>';
} else {
$rating = '<b>'.$gallery['rating'].'</b>';
}
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos_comm` WHERE `id_photos` = '$gallery[id]'"), 0);
echo '<div class="'.$row_class.'"><img src="inc/gallery.gif"> <a href="?act=view&id='.$gallery['id'].'"><b>'.$gallery['name'].'</b></a> ('.$rating.')<br /><a href="?act=view&id='.$gallery['id'].'"><img src="inc/gallery/'.$gallery['file'].'" width="150" height="100" alt="'.$gallery['name'].'" /></a><br />Добавлено: '.login($gallery['id_user']).' ('.date('d.m.y, H:i', $gallery['time']).')<br /><a href="?act=comm&id='.$gallery['id'].'">Комментарии</a> ('.$comm.')</div>';
}
} else {
echo 'Пусто.<br />';
}
navig($page, '?act=my&id='.$id.'&', $pages);
if ($u['id']) echo '<br /><a href="">Все альбомы</a> / <a href="?act=top">Топ фото</a>';
nav_main();
break;
case 'photo_add':
if (!$u['id']) redirect('login.php');
if ($ok) {
if ($_FILES['file']['name'] and $_POST['name']) {
if (ext($_FILES['file']['name']) == 'jpg' or ext($_FILES['file']['name']) == 'gif') {
$file = check(basename($_FILES['file']['name']));
$file_loaded = $u['id'].'_'.$file;
if (!mysql_num_rows(mysql_query("SELECT `id` FROM `photos` WHERE `file` = '$file_loaded'"))) {
$name = check($_POST['name']);
$desc = check($_POST['desc']);
copy($_FILES['file']['tmp_name'], 'inc/gallery/'.$file_loaded);
mysql_query("INSERT INTO `photos` SET `id_user` = '$u[id]', `name` = '$name', `desc` = '$desc', `time` = '".TIME."', `file` = '$file_loaded'");
$last_id = mysql_insert_id();
redirect('?act=view&id='.$last_id);
} else {
error('Файл уже существует.');
nav('?act=photo_add');
}
} else {
error('Неверный формат файла. Можно только .jpg и .gif');
nav('?act=photo_add');
}
} else {
error('Вы не указали название или не прикрепили фото.');
nav('?act=photo_add');
}
} else {
tp('<a href="?">Фотогалерея</a>');
echo '<form action="?act=photo_add&ok=1" method="post" enctype="multipart/form-data">
Прикрепить фото*:<br /><input name="file" type="file" size="file" /><br />
Название(max50)*:<br /><input name="name" type="text" maxlength="50" /><br />
Описание:<br /><textarea name="desc" cols="" rows="4"></textarea><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?');
}
break;
case 'view':
$gallery = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '$id'"));
if ($gallery['id']) {
tp('<a href="?">Фотогалерея</a> > '.$gallery['name']);
echo '<a href="inc/gallery/'.$gallery['file'].'"><img src="inc/gallery/'.$gallery['file'].'" width="150" alt="'.$gallery['name'].'" /></a><br />';
if ($gallery['desc']) echo bb($gallery['desc']).'<br />';
if ($gallery['rating'] > 0) {
$rating = '<b><font color="green">+'.$gallery['rating'].'</font></b>';
} elseif ($gallery['rating'] < 0) {
$rating = '<b><font color="red">'.$gallery['rating'].'</font></b>';
} else {
$rating = '<b>'.$gallery['rating'].'</b>';
}
echo 'Рейтинг: '.$rating;
$query_r = mysql_query("SELECT `id` FROM `voting` WHERE `type` = 'gallery' and `id_who` = '$u[id]' and `id_for` = '$id'");
$query = mysql_num_rows($query_r);
if ($u['id'] and $u['id'] != $gallery['id_user'] and !$query) {
echo ' <a href="?act=vote&id='.$gallery['id'].'&type=1"><img src="inc/minus.png"></a> <a href="?act=vote&id='.$gallery['id'].'&type=2"><img src="inc/plus.png"></a>';
} else {
echo ' <img src="inc/minus.png"> <img src="inc/plus.png">';
}
echo '<br />Добавлено: <a href="profile.php?id='.$gallery['id_user'].'">'.login($gallery['id_user']).'</a> ('.date('d.m.y, H:i', $gallery['time']).')<br />';
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `photos_comm` WHERE `id_photos` = '$gallery[id]'"), 0);
echo '<a href="?act=comm&id='.$gallery['id'].'">Комментарии</a> ('.$comm.')<br />';
echo '<br />Скопировать адрес:<br /><input name="file" type="text" value="http://'.$config['copy'].'/gallery.php?act=view&id='.$gallery['id'].'" /><br />';
echo 'BB-код для форума:<br /><input name="bb_code" type="text" value="[url=http://'.$config['copy'].'/gallery.php?act=view&id='.$gallery['id'].']'.$gallery['name'].'[/url]" /><br />';
//if ($u['access'] > 1) echo '<br />- <a href="?act=photo_edit&id='.$gallery['id'].'">Редактировать</a><br />';
if ($u['access'] == 3) echo '- <a href="?act=photo_del&id='.$gallery['id'].'">Удалить</a><br />';
nav('?');
} else {
error('Выбранное фото не существует.');
nav('?');
}
break;
case 'vote':
$photo_r = mysql_query("SELECT `id_user` FROM `photos` WHERE `id` = '$id'");
$photo = mysql_fetch_assoc($photo_r);
if ($photo['id_user'] and $photo['id_user'] != $u['id']) {
$query = mysql_query("SELECT `id` FROM `voting` WHERE `type` = 'gallery' and `id_who` = '$u[id]' and `id_for` = '$id'");
if (!mysql_num_rows($query)) {
$type = abs(intval($_GET['type']));
switch ($type) {
case '1': $value = -1; break;
default: $value = 1; break;
}
mysql_query("UPDATE `photos` SET `rating` = (`rating`+$value) WHERE `id` = '$id'");
mysql_query("UPDATE `users` SET `karma` = (`karma`+$value) WHERE `id` = '$photo[id_user]'");
mysql_query("INSERT INTO `voting` SET `type` = 'gallery', `id_who` = '$u[id]', `id_for` = '$id'");
}
}
header('location: ?act=view&id='.$id);
exit;
break;
case 'photo_del':
if ($u['access'] == 3) {
$photo = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '$id'"));
if ($photo['id']) {
if (isset($_GET['ok'])) {
unlink('inc/gallery/'.$photo['file']);
mysql_query("DELETE FROM `photos` WHERE `id` = '$photo[id]'");
header('location: ?');
exit;
} else {
tp('Подтверждение');
echo 'Вы действительно хотите удалить фото "'.$photo['name'].'"?<br />
<form action="?act=photo_del&id='.$id.'&ok=1" method="post">
<input name="submit" type="submit" value="Yeah" />
</form>';
nav2('?act=view&id='.$photo['id'], 'К фото');
}
} else {
error('Фото не существует.');
nav('?');
}
} else {
header('location: ?');
exit;
}
break;
case 'comm':
require_once 'system/comm.php';
break;
case 'comm_add':
require_once 'system/comm_add.php';
break;
case 'comm_reply':
require_once 'system/comm_reply.php';
break;
case 'comm_edit':
require_once 'system/comm_edit.php';
break;
case 'comm_del':
require_once 'system/comm_del.php';
break;
}
require_once 'system/tail.php';
?>