File size: 3.33Kb
<?php
include('inc/funct.php');
include('inc/funct_index.php');
include('inc/core.php');
if (empty($_GET['act'])) $act = 'index';
else $act = htmlspecialchars($_GET['act']);
if ($act=='index') {
if (empty($_GET['id'])) {
redirect(URL);
die();
} else {
$id = htmlspecialchars($_GET['id']);
}
$site = mysql_fetch_object(mysql_query('SELECT * FROM `sites` WHERE id='.$id.''));
if (empty($site)) {
$_SESSION['error'] = 'Запрашиваемого сайта не существует';
redirect(URL);
die();
}
$catname = mysql_fetch_array(mysql_query('SELECT * FROM `categories` WHERE id='.$site->category.''));
mysql_query('UPDATE `sites` SET hits=hits+1 WHERE id='.$site->id.'');
$pagetitle = $site->name;
include('inc/header.php');
echo '<div id="title_a">'.$pagetitle.'</div>';
echo '<div class="desc">
<b>Описание:</b> '.$site->description.'<br>
<b>Категория:</b> '.$catname[1].'<br>
<b>Просмотров:</b> '.$site->hits.'<br>
<b>Рейтинг:</b> '.round($site->reit,1).' (Проголосовало: '.$site->voted.')<br>';
if (empty($_SESSION['vote_'.$id])) {
echo '<b>Оцените сайт:</b> <form action="site.php?act=getvote" method="post">
<select name="vote">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="hidden" name="id" value="'.$site->id.'">
<input type="submit" value="Оценить" style="width: 20%; font-size : 7pt; ">
</form>';
} else {
echo '<b>Вы оценили сайт на '.$_SESSION['vote_'.$id].'</b>';
}
echo '</div><div id="menu"><ul>';
if ($site->reit <= minreit) echo '<li><a href="go.php?id='.$site->id.'"><b>Перейти на '.$site->name.'</b></a></li>';
else echo '<li><a href="'.$site->URL.'"><b>Перейти на '.$site->name.'</b></a></li>';
echo '</ul>';
echo '<div id="aut"><a href="view.php?cat='.$catname[0].'">Назад в категорию</a></div></div>';
}
if ($act=='getvote') {
if (empty($_POST['vote'])) {
redirect('site.php');
die();
}
if (empty($_POST['id'])) {
redirect('site.php');
die();
}
if (isset($_SESSION['vote_'.$id])) {
$_SESSION['error'] = 'Вы уже проголосовали за этот сайт';
redirect('site.php');
die();
}
$id = htmlspecialchars($_POST['id']);
$vote = htmlspecialchars($_POST['vote']);
$rating = mysql_fetch_row(mysql_query('SELECT `rating` FROM `sites` WHERE id='.$id.''));
$voted = mysql_fetch_row(mysql_query('SELECT `voted` FROM `sites` WHERE id='.$id.''));
$newrating = ($rating[0]+$vote)/($voted[0]+1);
if (mysql_query('UPDATE sites SET rating=rating+'.$vote.', voted=voted+1, reit='.$newrating.' WHERE id='.$id.'')) {
$_SESSION['info'] = 'Спасибо за оценку';
$_SESSION['vote_'.$id] = $vote;
redirect('site.php?id='.$id.'');
die();
} else {
$_SESSION['error'] = 'Ошибка при добавлении оценки';
redirect(URL);
die();
}
}
if ($act=='random') {
$counter = mysql_fetch_row(mysql_query('SELECT COUNT(*) FROM `sites`'));
for(;;) {
$num = rand(1,$counter[0]);
$site = mysql_query('SELECT * FROM `sites` WHERE id='.$num.'');
if (isset($site)) {
$site = mysql_fetch_object($site);
if ($site->status == 1) { redirect('site.php?id='.$num.''); die(); }
}
}
}
include('inc/footer.php');
?>