<?php
include('inc/core.php');
error_reporting(0);
if (empty($_GET['act'])) $act = 'index';
else $act = htmlspecialchars($_GET['act']);
if ($act=='index') {
if (empty($_GET['id'])) { redirect(URL); die(); }
else $id = mysql_real_escape_string(trim(htmlspecialchars($_GET['id'])));
$post = mysql_fetch_object(mysql_query('SELECT * FROM `'.db_prefix.'posts` WHERE id='.$id.''));
if ($post->access==0 && empty($_SESSION['autorized'])) {
$_SESSION['info'] = 'Для просмотра этой записи вам необходимо войти на сайт';
redirect('auto.php');
die();
}
if (empty($post)) { redirect(URL); die(); }
$pagetitle = 'Просмотр записи "'.$post->title.'"';
$author = mysql_fetch_string('SELECT `nick` FROM `'.db_prefix.'users` WHERE id='.$post->author.'');
mysql_query('UPDATE `'.db_prefix.'posts` SET hits=hits+1 WHERE id='.$id.'') or die(mysql_error());
###############################################
$keywords = explode('||',$post->keywords);
$k_count = count($keywords);
$i = 0;
if ($k_count==1) $head_keywords = $keywords[0];
else {
while($i<$k_count) {
if ($i+1==$k_count) $head_keywords = $head_keywords.''.$keywords[$i];
else $head_keywords = $head_keywords.''.$keywords[$i].', ';
$i++;
}
}
$k_count = null;
$i = null;
$keywords = null;
########################## составили строку с ключевыми словами для шапки
include('design/'.$_SESSION['design'].'/header.php');
if (empty($_SESSION['lastvote'])) $_SESSION['lastvote'] = 0;
echo '<div id="title_a" align="center">Просмотр записи</div>
<div id="title_b">'.$post->title.'</div>
<div class="desc">'.check_post($post->text);
if ($_SESSION['id']==$post->author || $_SESSION['access']>=md_posts)
echo '<div class="order"><div align="right"><a href="viewpost.php?act=edit&id='.$post->id.'">Редактировать</a> <a href="viewpost.php?act=del&id='.$post->id.'">Удалить</a></div></div>';
echo '</div>
<div id="menu">
Добавил: <a href="usr/?id='.$post->author.'"><b>'.$author.'</b></a> ('.print_date($post->date).')<br>';
if ($post->sw_comm==1) {
echo '
Рейтинг: ';
if ($post->rating>=0) echo '<b><span style="color:green">'.$post->rating.'</span></b>';
else echo '<b><span style="color:red">'.$post->rating.'</span></b>';
#echo ''.$post->rating.'';
echo ' (<span style="color:green">+'.$post->plus.'</span>/<span style="color:red">-'.$post->minus.'</span>)<br>';
}
echo '
Просмотров: '.$post->hits.'<br>';
$cat = mysql_fetch_string('SELECT `title` FROM `'.db_prefix.'categories` WHERE id='.$post->category.'');
echo 'Категория: <b><a href="viewcat.php?id='.$post->category.'">'.$cat.'</a></b><br>';
echo 'Ключевые слова: ';
$keywords = explode('||',$post->keywords);
$k_count = count($keywords);
$i = 0;
if ($k_count==1) echo '<a href="search.php?act=search&q='.$keywords[0].'">'.$keywords[0].'</a>';
else {
while($i<$k_count) {
if ($i+1==$k_count) echo '<a href="search.php?act=search&q='.$keywords[$i].'">'.$keywords[$i].'</a>';
else echo '<a href="search.php?act=search&q='.$keywords[$i].'">'.$keywords[$i].'</a>, ';
$i++;
}
}
echo '<br>';
if (($_SESSION['lastvote']+voting)>time()) {
echo 'Вы уже проголосовали, подождите немного';
echo '<ul>';
if ($post->sw_comm==1) echo '<li><a href="comm.php?id='.$post->id.'">Комментарии ('.$post->comm_count.')</a></li>';
$res = mysql_query('SELECT * FROM `'.db_prefix.'post_comments` WHERE post='.$post->id.' ORDER BY `id` DESC LIMIT 0, '.view_last_comments);
while ($comm = mysql_fetch_object($res)) {
$author = mysql_fetch_string('SELECT `nick` FROM `'.db_prefix.'users` WHERE id='.$comm->author.'');
if (get_status($comm->author)=='Online') {
if (view_status==1) { ## если включен показ иконок х-статуса, то показываем его (если юзер онлайн)
$status_icon = mysql_fetch_string('SELECT `status_id` FROM `'.db_prefix.'users` WHERE id='.$comm->author.'');
if ($status_icon!=0) $img = '<img src="images/online.png"><img src="usr/statusicon/'.$status_icon.'.gif">';
else $img = '<img src="images/online.png">';
} else $img = '<img src="images/online.png">';
} else $img = $img = '<img src="images/offline.png">';
echo '<div class="wall_title"><a href="usr/index.php?id='.$comm->author.'">'.$img.'<b>'.$author.'</b></a>
<small>('.print_date($comm->time,$_SESSION['time_pref']).')</small></div>
<div class="desc">'.check_post($comm->text,0,1).'</div>';
}
echo '</div>';
} else {
if ($post->sw_comm==0) echo 'Автор запретил комментирование данной записи';
elseif($post->sw_comm==1 && $_SESSION['id']!=$post->author) {
if (empty($_SESSION['autorized']))
echo 'Для комментирования этой записи Вам необходимо зайти на сайт под своим ником или зарегистрироваться';
else {
echo 'Вам понравилась эта запись? <a href="viewpost.php?act=plus&id='.$id.'" style="color:green">Да</a> | <a href="viewpost.php?act=minus&id='.$id.'" style="color:red">Нет</a>';
}
}
# if (view_last_comments!=0 && $post->comm_count!=0) {
echo '<ul>';
if ($post->sw_comm==1) echo '<li><a href="comm.php?id='.$post->id.'"><img src="images/comment.png"> Комментарии ('.$post->comm_count.')</a></li>';
$res = mysql_query('SELECT * FROM `'.db_prefix.'post_comments` WHERE post='.$post->id.' ORDER BY `id` DESC LIMIT 0, '.view_last_comments);
while ($comm = mysql_fetch_object($res)) {
$author = mysql_fetch_string('SELECT `nick` FROM `'.db_prefix.'users` WHERE id='.$comm->author.'');
if (get_status($comm->author)=='Online') {
if (view_status==1) { ## если включен показ иконок х-статуса, то показываем его (если юзер онлайн)
$status_icon = mysql_fetch_string('SELECT `status_id` FROM `'.db_prefix.'users` WHERE id='.$comm->author.'');
if ($status_icon!=0) $img = '<img src="images/online.png"><img src="usr/statusicon/'.$status_icon.'.gif">';
else $img = '<img src="images/online.png">';
} else $img = '<img src="images/online.png">';
} else $img = $img = '<img src="images/offline.png">';
echo '<div class="wall_title"><a href="usr/index.php?id='.$comm->author.'">'.$img.'<b>'.$author.'</b></a>
<small>('.print_date($comm->time,$_SESSION['time_pref']).')</small></div>
<div class="desc">'.check_post($comm->text,0,1).'</div>';
}
echo '</ul></div>';
} echo '</div>';
}
if ($act=='plus' || $act=='minus') {
if (empty($_GET['id'])) { redirect(URL); die(); }
else $id = mysql_real_escape_string(trim(htmlspecialchars($_GET['id'])));
$post = mysql_fetch_object(mysql_query('SELECT * FROM `'.db_prefix.'posts` WHERE id='.$id.''));
if (empty($post)) { redirect('viewpost.php'); die(); }
if ($post->sw_comm==0) { redirect('viewpost.php?id='.$id); die(); }
if ($post->author==$_SESSION['id']) {
$_SESSION['error'] = 'Нельзя оценивать свою запись';
redirect('viewpost.php?id='.$id);
die();
}
if ($_SESSION['lastvote']+voting<time()) {
if ($act=='plus') {
$query = 'UPDATE `'.db_prefix.'posts` SET plus=plus+1, rating=rating+1 WHERE id='.$id.'';
} elseif ($act=='minus') {
$query = 'UPDATE `'.db_prefix.'posts` SET minus=minus+1, rating=rating-1 WHERE id='.$id.'';
}
mysql_query('UPDATE `'.db_prefix.'users` SET lastvote='.time().' WHERE id='.$_SESSION['id']);
$_SESSION['lastvote'] = time();
if (mysql_query($query)) {
mysql_query('INSERT INTO `'.db_prefix.'reply` (`from`,`usr`,`object`,`time`,`status`) VALUES ('.$_SESSION['id'].','.$post->author.',"post_reit||'.$post->id.'",'.time().',0)');
## оповещение автора о новой оценке
mysql_query('UPDATE `'.db_prefix.'users` SET lastvote='.time().' WHERE id='.$_SESSION['id'].'');
$_SESSION['info'] = 'Ваш голос учтен';
redirect('viewpost.php?id='.$id);
die();
} else {
$_SESSION['error'] = 'Неизвестная ошибка';
redirect('viewpost.php?id='.$id);
die();
}
} else {
$_SESSION['error'] = 'Вы пока не можете оценивать записи';
redirect('viewpost.php?id='.$id);
die();
}
}
if ($act=='edit') {
if (empty($_GET['id'])) { redirect(URL); die(); }
else $id = mysql_real_escape_string(trim(htmlspecialchars($_GET['id'])));
if (empty($_SESSION['autorized'])) {
$_SESSION['info'] = 'Необходима авторизация';
redirect('auto.php');
die();
}
$post = mysql_fetch_object(mysql_query('SELECT * FROM `'.db_prefix.'posts` WHERE id='.$id.''));
if ($post->author!=$_SESSION['id'] && $_SESSION['access']<md_posts) {
$_SESSION['info'] = 'Отказано в доступе';
redirect('auto.php');
die();
}
if (empty($post)) { redirect(URL); die(); }
$pagetitle = 'Редактировать запись';
$author = mysql_fetch_string('SELECT `nick` FROM `'.db_prefix.'users` WHERE id='.$post->author.'');
#mysql_query('UPDATE `'.db_prefix.'posts` SET hits=hits+1 WHERE id='.$id.'') or die(mysql_error());
include('design/'.$_SESSION['design'].'/header.php');
echo '<div id="title_a" align="center">'.$pagetitle.'</div>';
if (empty($_SESSION['post_title'])) $_SESSION['post_title'] = $post->title;
if (empty($_SESSION['post_text'])) $_SESSION['post_text'] = $post->text;
if (empty($_SESSION['post_keywords'])) {
$keywords = explode('||',$post->keywords);
$k_count = count($keywords);
$i = 0;
$_SESSION['post_keywords'] = '';
if ($k_count==1) $_SESSION['post_keywords'] = $keywords[0];
else {
while($i<$k_count) {
if ($i+1==$k_count) $_SESSION['post_keywords'] = $_SESSION['post_keywords'].''.$keywords[$i].'';
else $_SESSION['post_keywords'] = $_SESSION['post_keywords'].''.$keywords[$i].', ';
$i++;
}
}
}
if (empty($_SESSION['post_category'])) $_SESSION['post_category'] = $post->category;
echo '<div id="menu"><form action="viewpost.php?act=getedit" method="post">
<input type="hidden" name="id" value="'.$post->id.'">
Название записи:<br>
<input type="text" name="title" maxlength="64" value="'.$_SESSION['post_title'].'"><br>
Текст:<br>
<textarea name="text" rows="5" cols="25">'.$_SESSION['post_text'].'</textarea><br>
Ключевые слова:<br>
<input type="text" name="keywords" value="'.$_SESSION['post_keywords'].'"><br>
Категория:<br>';
echo ' <select name="category">';
$res = mysql_query('SELECT * FROM `'.db_prefix.'categories`');
while ($cat = mysql_fetch_object($res)) {
if ($_SESSION['post_category']==$cat->id) echo '<option selected value="'.$cat->id.'">'.$cat->title.'</option>';
else echo '<option value="'.$cat->id.'">'.$cat->title.'</option>';
}
echo '</select><br>';
if ($post->access==1) echo '<input type="checkbox" checked name="access" value="true">Разрешить гостям просматривать запись<br>';
else echo '<input type="checkbox" name="access" value="true">Разрешить гостям просматривать запись<br>';
if ($post->sw_comm==1) echo '<input type="checkbox" checked name="sw_comm" value="true">Разрешить оценивать и комментировать запись<br>';
else echo '<input type="checkbox" name="sw_comm" value="true">Разрешить оценивать и комментировать запись<br>';
echo '<div align="center">
<input type="submit" value="Изменить">
</div>';
echo '</div>';
$_SESSION['post_title'] = null;
$_SESSION['post_text'] = null;
$_SESSION['post_keywords'] = null;
$_SESSION['post_category'] = null;
}
if ($act=='del') {
if (empty($_GET['id'])) { redirect(URL); die(); }
else $id = mysql_real_escape_string(trim(htmlspecialchars($_GET['id'])));
if (empty($_SESSION['autorized'])) {
$_SESSION['info'] = 'Необходима авторизация';
redirect('auto.php');
die();
}
$post = mysql_fetch_object(mysql_query('SELECT * FROM `'.db_prefix.'posts` WHERE id='.$id.''));
if ($post->author!=$_SESSION['id'] && $_SESSION['access']<md_posts) {
$_SESSION['info'] = 'Отказано в доступе';
redirect('auto.php');
die();
}
if (mysql_query('DELETE FROM `'.db_prefix.'posts` WHERE id='.$id)) {
mysql_query('DELETE FROM `'.db_prefix.'reply` WHERE object="post_reit||'.$post->id.'"'); ## удаляем оповещения, относящиеся к этой записи
mysql_query('DELETE FROM `'.db_prefix.'reply` WHERE object="post_comm||'.$post->id.'"');
mysql_query('UPDATE `'.db_prefix.'categories` SET counter=counter-1 WHERE id='.$post->category);
$_SESSION['info'] = 'Запись удалена';
redirect('view.php');
die();
}
}
if ($act=='getedit') {
if (empty($_POST['id'])) { redirect(URL); die(); }
else {
$post = mysql_fetch_object(mysql_query('SELECT * FROM `'.db_prefix.'posts` WHERE id='.mysql_real_escape_string(htmlspecialchars($_POST['id'])).''));
if ($post->author!=$_SESSION['id'] && $_SESSION['access']<2) {
$_SESSION['error'] = 'Отказано в доступе';
redirect(URL);
die();
} else $id = mysql_real_escape_string(htmlspecialchars($_POST['id']));
}
if (empty($_POST['title'])) {
$_SESSION['error'] = 'Введите заголовок';
$_SESSION['post_text'] = htmlspecialchars($_POST['text']);
$_SESSION['post_keywords'] = htmlspecialchars($_POST['keywords']);
$_SESSION['post_category'] = htmlspecialchars($_POST['category']);
redirect('viewpost.php?act=edit&id='.$id);
die();
} else $title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
if (empty($_POST['text'])) {
$_SESSION['error'] = 'Введите текст';
$_SESSION['post_keywords'] = htmlspecialchars($_POST['keywords']);
$_SESSION['post_category'] = htmlspecialchars($_POST['category']);
$_SESSION['post_title'] = htmlspecialchars($_POST['title']);
redirect('viewpost.php?act=edit&id='.$id);
die();
} else $text = htmlspecialchars($_POST['text']);
if (empty($_POST['keywords'])) {
$_SESSION['error'] = 'Введите ключевые слова';
$_SESSION['post_category'] = htmlspecialchars($_POST['category']);
$_SESSION['post_title'] = htmlspecialchars($_POST['title']);
$_SESSION['post_text'] = htmlspecialchars($_POST['text']);
redirect('viewpost.php?act=edit&id='.$id);
die();
}
if (empty($_POST['category'])) {
$_SESSION['error'] = 'Выберите категорию';
$_SESSION['post_title'] = htmlspecialchars($_POST['title']);
$_SESSION['post_text'] = htmlspecialchars($_POST['text']);
$_SESSION['post_keywords'] = htmlspecialchars($_POST['keywords']);
redirect('viewpost.php?act=edit&id='.$id);
die();
} else $category = mysql_real_escape_string(htmlspecialchars($_POST['category']));
$keywords = explode(',',htmlspecialchars($_POST['keywords']));
if (is_array($keywords)) {
$k_count = count($keywords);
$i = 0;
while ($i<$k_count) {
$keywords[$i] = mysql_real_escape_string(trim($keywords[$i]));
if (!isset($string)) $string = $keywords[$i];
else $string = $string.'||'.$keywords[$i];
$i++;
}
} else $string = mysql_real_escape_string(trim($keywords));
#$string = mysql_real_escape_string($string);
#echo $string;
if ($_POST['access']=='true') $access = 1;
else $access = 0;
if ($_POST['sw_comm']=='true') $sw_comm = 1;
else $sw_comm = 0;
if (mysql_query('UPDATE `'.db_prefix.'posts` SET title="'.$title.'", text="'.$text.'", keywords="'.$string.'", category='.$category.', access='.$access.', sw_comm='.$sw_comm.' WHERE id='.$id.'')) {
$_SESSION['info'] = 'Запись изменена';
$_SESSION['post_title'] = null;
$_SESSION['post_text'] = null;
$_SESSION['post_keywords'] = null;
$_SESSION['post_category'] = null;
redirect('viewpost.php?id='.$id);
die();
} else {
$_SESSION['error'] = 'Ошибка при изменении записи';
redirect('viewpost.php?act=edit&id='.$id);
die();
}
}
include('design/'.$_SESSION['design'].'/footer.php');
?>