<?php
	/*
	*by Krite (http://upcoder.net)
	*/
	define('_IN_JOHNCMS', 1);
	$headmod = 'blogs';
	require_once '../incfiles/core.php';
	if ($user_id && $user_ps)
	{
		$req = mysql_query("SELECT `name`, `text` FROM `" . $set['prefblog'] . "blogs` WHERE `id` = '" . $id . "' LIMIT 1;");
		if (mysql_num_rows($req) == 0)
		{
			$textl = 'Блоги';
			require_once('../incfiles/head.php');
			echo '<p class="rmenu">Статья не найдена</p>';
			require_once ("../incfiles/end.php");
			exit;
		}
		$res = mysql_fetch_array($req);
		$book_name = iconv('UTF-8', 'windows-1251', $res['name']);
		$book_text = iconv('UTF-8', 'windows-1251', $res['text']);
		
		$result = "\r\n" . $book_name . "\r\n\r\n----------\r\n\r\n" . $book_text . "\r\n\r\nDownloaded from $home";
		$num = "$realtime$id";
		
		header('Content-Encoding: none');
		header('Content-type: text/plain');
		header('Content-Disposition: attachment; filename="' . $num . '.txt"');
		header('Last-Modified: ' . date("D, d M Y H:i:s T"));
		header('Content-Length: '. strlen($result));
		echo $result;
		exit;
	}
	else
	{
		$textl = 'Блоги';
		require_once('../incfiles/head.php');
		echo '<p class="rmenu">Внимание!<br />
		Скачать статью в txt формате могут только зарегистрированные пользователи.</p>';
		echo '<p class="menu"><a href="index.php?act=view&amp;id=' . $id . '">К статье</a></p>';
	}
	require_once ('../incfiles/end.php');
?>