<?php

defined('_IN_JOHNCMS') or die('Error: restricted access');
if(empty($_SESSION['error']))
	$_SESSION['error'] = '';

if($id) {
	$query = mysql_query("SELECT `cms_news`.*, `cms_news_cat`.`name` as `catname`, `cms_news_cat`.`id` as `catid` FROM `cms_news` LEFT JOIN `cms_news_cat` ON `cms_news`.`refid`=`cms_news_cat`.`id` WHERE `cms_news`.`id`='$id'".($rights < 7 ? " AND `cms_news`.`time`<='" . time() . "'":"")." LIMIT 1;");
	if (mysql_num_rows($query)) {
// смотрено
$ncount = mysql_fetch_array(mysql_query("SELECT * FROM `cms_news` WHERE `id` ='$id'"));
if (!isset($_SESSION['cms_news']) || isset($_SESSION['cms_news'])&&$_SESSION['cms_news'] != $id) {
$_SESSION['cms_news'] = $id;
$newscount = intval($ncount['reads']) + 1;
mysql_query("UPDATE `cms_news` SET `reads` ='$newscount' WHERE `id` ='$id'");
}
//смотрено
$res1 = mysql_fetch_assoc($query);
//Выводим автора новости
		$us = mysql_query("SELECT `id`, `name` FROM `users` WHERE `id` = '{$res1['user_id']}'");
		if (mysql_num_rows($us)) {
			$rowuse = mysql_fetch_assoc($us);
			$name_use = $user_id ? '<a href="../users/profile.php?user=' . $rowuse['id'] . '">' . $rowuse['name'] . '</a>' : $rowuse['name'];
		} else {
			$name_use = $lng['guest'];
		}
		//
		//Показываем новость
		
		
		require_once('../incfiles/head.php');
		$textl = $lng['news'] . ' | ' . htmlentities($res1['name'], ENT_QUOTES, 'UTF-8');
		echo '<div class="phdr">' . htmlentities($res1['name'], ENT_QUOTES, 'UTF-8') . '</div>';
		echo'<div class="gmenu">
		' . functions::display_date($res1['time']) . ' / '.$lng_news['posted'] . ':' . $name_use . ' / 
		'.$lng_news['reads'] . ':'.$ncount['reads'].' 
		 
		
		'.($res1['time'] > time()?' | <div class="func">' . $lng_news['begin_show_through'] . ': ' . timer($res1['time'] - time()) . '</div>':'').'
		</div>';
		echo '<div class="menu">';
		if (!empty($res1['img'])) {
		echo'<img class="news_photo" src="'.$res1['img'].'" alt="FUTBOL.UZ"><br>
		     <a href="'.$res1['img'].'"><i class="fa fa-arrow-circle-down" aria-hidden="true"></i>'.$lng_news['download_img'].'</a><br><br>';	
								  }
		
		

		$text = functions::checkout($res1['text'], 1, 1);
		if ($set_user['smileys'])
			$text = functions::smileys($text);
		echo $text;
		echo '<div style="clear:both;"></div></div>';
		//Сообщение об оставленном голосе
		echo $_SESSION['error'];
		
		echo '</div>';
		echo '' . ($rights >= 7 ? '<div class="menu"><div class="func">
		<a href="../panel/index.php?act=news&amp;mod=newsedit&amp;id=' . $id . '">' . $lng['edit'] . '</a><br />
		<a href="../panel/index.php?act=news&amp;mod=delnews&amp;id=' . $id . '">' . $lng['delete'] . '</a><br />
		</div></div>':'').'';

include 'comments.php';

		echo'
		<div class="bmenu"><a href="index.php?id=' . $res1['catid'] . '">' . htmlentities($res1['catname'], ENT_QUOTES, 'UTF-8') . '</a></div>';
	} else {
		$textl = $lng['news'];
		require_once('../incfiles/head.php');
		echo functions::display_error($lng_news['news_does_not_exist']);
	}
} else {
	$textl = $lng['news'];
	require_once('../incfiles/head.php');
	echo functions::display_error($lng_news['news_is_not_chose']);
}
unset($_SESSION['error']);