View file album/photo.php

File size: 7.51Kb
<?php
include '../system/inc/connect.php';
include '../system/inc/core.php' ;
$title = 'Просмотр фотографии';
include '../system/inc/header.php';
if(!$user){
	header('Location: /index.php');
}
//конец шапки

$photo['id'] = num($_GET['num']);
$q = mysql_query("SELECT * FROM `album_photo` WHERE `id` = '$photo[id]'");
$photo = mysql_fetch_assoc($q);
if(!mysql_num_rows($q)){
	message('Фотографии не существует, или она была удалена<br /><a href="index.php?id=' .$u['id']. '"> Назад </a>');
	include '../system/inc/footer.php';
	exit;
}

if($photo['user'] != $user['id']){
	echo '<div class="red">
Фотография '; user($photo['user']);
	echo ' / <a href="index.php?id='. $photo['user'] .'">Назад</a>
</div>';
}
else
{
	echo '<div class="red">
Моя фотография / <a href="index.php?id='. $photo['user'] .'">Назад</a>
</div>';
}

$al = mysql_fetch_assoc(mysql_query
("SELECT * FROM `album` WHERE `id` = '$photo[album]'"));
if($al['closed'] == 1 && $al['user'] != $user['id'] && $user['level'] < 4){
	if(!isset($_SESSION['pas']) || $_SESSION['pas'] != $al['pass']){
		header("Location: album.pro.php?num=$al[id]&iau=$photo[user]");
	}
}
if(isset($_GET['down'])){
	$nam = input($_GET['file']);
	if(!is_file('photo/'.$nam.'')){
		echo 'ERROR!!!! NOT FILE SERVER!!!';
	} else {
		if($user['id'] != $photo['user']){
			mysql_query("UPDATE `album_photo` SET `down` = '$photo[down]'+'1' WHERE `id` = '$photo[id]' && `name` = '$nam'");
		}
		header("Location: photo/$nam");
	}
}

if($photo['user'] == $user['id'] && isset($_GET['dell_photo'])){
	if($photo['name'] == $user['avatar']){
		message('Данная фотография установлена на ваш аватaр. Вы не можете ее удалить.');
	} else {
		unlink(HOME.'/album/photo/'.$photo['name'].'');
		mysql_query("DELETE FROM `album_photo` WHERE `id` = '$photo[id]'");
		mysql_query("OPTIMIZE TABLE `album_photo`");
		mysql_query("DELETE FROM `album_photo_plus` WHERE `photo` = '$photo[id]'");
		mysql_query("OPTIMIZE TABLE `album_photo_plus`");
		header("Location: index.php");
	}
}
echo '<div class="pole">
<center>';
$fi = pathinfo('photo/' .$photo['name']. '',PATHINFO_EXTENSION);
if($fi == 'jpg' or $fi == 'jpeg'){
	echo '<table width="100%"><tr>';
	echo '<td><img class="fotoFrame" src="photo/' . $photo['name'] . '" alt="' . output($photo['msg']) . '" width="120" /></td>';
	$pls = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]'"),0);
	if($pls > 0){
		echo '<td>';
		$a = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '5'"),0);
		if ($a) {
			echo '<img src="img/52.png" alt="*" /> (' . $a . ')<br />';
		}

		$b = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '4'"),0);
		if ($b) {
			echo '<b>+4</b> (' . $b . ')<br />';
		}

		$c = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '3'"),0);
		if ($c) {
			echo '<b>+3</b> (' . $c . ')<br />';
		}

		$d = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '2'"),0);
		if ($d) {
			echo '<b>+2</b> (' . $d . ')<br />';
		}
		$e = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '1'"),0);
		if ($e) {
			echo '<b>+1</b> (' . $e . ')<br />';
		}

		echo '</td>';
	}
	echo '</tr></table>';
} else {
	echo '<table width="100%"><tr>';
	echo '<td><img class="fotoFrame" src="photo/' . $photo['name'] . '" alt="' . output($photo['msg']) . '" width="120" /></td>';
	$pls = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]'"),0);
	if($pls > 0){
		echo '<td>';
		$a = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '5'"),0);
		if ($a) {
			echo '<img src="img/52.png" alt="" /> (' . $a . ')<br />';
		}
		$b = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `plus` = '4'"),0);
		if ($b) {
			echo '<b>+4</b> (' . $b . ')<br />';
		}
		$c = mysql_result(mysql_query("SELECT COUNT(id) FROM album_photo_plus
		WHERE photo = '$photo[id]' && plus = '3'"), 0);
		if ($c) {
			echo '<b>+3</b> (' . $c . ')<br />';
		}
		$d = mysql_result(mysql_query("SELECT COUNT(id) FROM album_photo_plus
		WHERE photo = '$photo[id]' && plus = '2'"), 0);
		if ($d) {
			echo '<b>+2</b> (' . $d . ')<br />';
		}
		$e = mysql_result(mysql_query("SELECT COUNT(id) FROM album_photo_plus
		WHERE photo = '$photo[id]' && plus = '1'"), 0);
		if ($e) {
			echo '<b>+1</b> (' . $e . ')<br />';
		} echo '</td>';
	}
	echo '</tr></table>';
}

echo '</center>
</div>';
if ($photo['down'] > 0) {
	$down = '(' . $photo['down'] . ')';
} else {
	$down = '';
}

$plus = mysql_query("SELECT * FROM album_photo_plus WHERE photo = '$photo[id]'");
if ($photo['msg'] != null) {
	echo '<div class="index">
Описание: ' . output($photo['msg']);
}
echo '</div>';

$qq = mysql_result(mysql_query("SELECT COUNT(id) FROM album_photo_plus WHERE photo = '$photo[id]' && user = '$user[id]'"),0);
if($qq < 0 || $photo['user'] != $user['id']){
	echo '<div class="index">';
	if(isset($_GET['plus'])){
		$pl = num($_GET['plus']);
		if($photo['user'] == $user['id']){
			message('Вы не можете ставить оценку для своего фото!');
		}
		$qq = mysql_result(mysql_query("SELECT COUNT(id) FROM `album_photo_plus` WHERE `photo` = '$photo[id]' && `user` = '$user[id]'"), 0);
		if($qq){
			err('Вы уже оценивали эту фотографию!');
		} else {
			if($pl == 5 && $user['money'] < 10){
				message('Услуга [Фото на +5] платная! Стоимость 10 монет!');
			} else {
				if($pl == 5){
					mysql_query("UPDATE `user` SET `money` = '$user[money]'-'10' WHERE `id` = '$user[id]'");
					message('За услугу [Фото на +5], было снято 10 монет');
				}
				mysql_query("INSERT INTO `album_photo_plus` SET `plus` = '$pl', `user` = '$user[id]', `photo` = '$photo[id]'");
			}
		}
	}

	for ($i = 1; $i <= 5; $i++){
		$lin = array(
		1 => '[<a href="?num='.$photo['id'].'&amp;plus=1">+1</a>]&harr;[',
		'<a href="?num='.$photo['id'].'&amp;plus=2">+2</a>]&harr;[',
		'<a href="?num='.$photo['id'].'&amp;plus=3">+3</a>]&harr;[',
		'<a href="?num='.$photo['id'].'&amp;plus=4">+4</a>]&harr;[',
		'<a href="?num='.$photo['id'].'&amp;plus=5"><img src="img/52.png" alt="*" /></a>]&nbsp;',
		);
		echo $lin[$i];
	}
	echo '</div>';
}

if($photo['user'] == $user['id'] && isset($_GET['avatar'])){
	mysql_query("UPDATE user SET avatar = '$photo[name]' WHERE id = '$user[id]'");
	message('Аватар успешно установлен!');
}
echo '<div class="menu">
<img src="img/share.png" alt="" /><a href="?down&amp;file='.$photo['name'].'&amp;num='.$photo['id'].'">Скачать: ('.sizef($photo['size']).')</a> '.$down.'<br />
&raquo; Загрузил: ';
user($photo['user']);
if($photo['user'] == $user['id']){
	if($user['avatar'] != $photo['name']){
		echo '<br />&raquo; <a href="?num='.$photo['id'].'&amp;avatar">Фото на аватар</a>';
		echo '<br />&raquo; <a href="?num='.$photo['id'].'&amp;dell_photo">Удалить фотографию</a>';
	}
}
echo '</div>';
include '../system/inc/footer.php';