<?php
	/*
	*by Krite (http://upcoder.net)
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	$textl = 'Блоги | Файлы';
		require_once('../incfiles/head.php');
		$types = array(1 => 'Приложения WIN', 2 => 'Приложения Java', 3 => 'Приложения SIS', 4 => 'Текстовые файлы', 5 => 'Картинки', 6 => 'Архивы', 7 => 'Видео', 8 => 'MP3', 9 =>'Другое');
		$new = $realtime - 86400;// Сколько времени файлы считать новыми?
		if(!empty($id))
		{
			echo '<div class="phdr"><a href="./">Блоги</a> | '.$types[$id].'</div>';
			$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `" .$prefix . "blogs_files` WHERE `type`='" . $id . "';"), 0);
			if($count>0)
			{
				$res = mysql_query("SELECT * FROM `" . $prefix . "blogs_files` WHERE `type`='" . $id . "' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
				while ($row = mysql_fetch_assoc($res))
				{
					echo ($i % 2) ? '<div class="list1">':'<div class="list2">';
					echo '<a href="load.php?id='.$row['id'].'">'.$row['name'].'</a> ['.formatsize($row['size']).']';
					$req = mysql_fetch_assoc(mysql_query("SELECT * FROM `" . $prefix . "blogs` WHERE `id`='" . $row['post'] . "';"));
					echo '<div class="sub"><div class="func"><a href="?act=view&amp;id='.$req['id'].'">'.$req['name'].'</a><br />';
					echo 'Скачиваний: '.$row['count'];
					echo '</div></div></div>';
					++$i;
				}
				if ($count > $kmess)
				{
					echo '<p class="menu">' . pagenav('index.php?act=file&amp;id='.$id.'&amp;', $start, $count, $kmess) . '<br/>';
					echo '<form action="" method="POST">
					<input type="text" name="page" size="2"/> <input type="submit" value="Перейти"/></form></p>';
				}
			}
			else
			{
				echo '<div class="menu">Файлов нет</div>';
			}
			echo '<div class="menu"><a href="?act=file">Назад</a></div>';
		}
		elseif($do=='new')
		{
			echo '<div class="phdr"><a href="./">Блоги</a> | Новые файлы</div>';
			$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $prefix . "blogs_files` WHERE `time`>'".$new."';"), 0);
			if($count>0)
			{
				$res = mysql_query("SELECT * FROM `" . $prefix . "blogs_files` WHERE `time`>'".$new."' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
				while ($row = mysql_fetch_assoc($res))
				{
					echo ($i % 2) ? '<div class="list1">':'<div class="list2">';
					echo '<a href="load.php?id='.$row['id'].'">'.$row['name'].'</a> ['.formatsize($row['size']).']';
					$req = mysql_fetch_assoc(mysql_query("SELECT * FROM `" . $prefix . "blogs` WHERE `id`='" . $row['ref'] . "';"));
					echo '<div class="sub"><div class="func"><a href="?act=view&amp;id='.$req['id'].'">'.$req['name'].'</a><br />';
					echo 'Скачиваний: '.$row['count'];
					echo '</div></div></div>';
					++$i;
				}
				if ($count > $kmess)
				{
					echo '<p class="menu">' . pagenav('index.php?act=file&amp;do=new&amp;', $start, $count, $kmess) . '<br/>';
					echo '<form action="" method="POST">
					<input type="text" name="page" size="2"/> <input type="submit" value="Перейти"/></form></p>';
				}
			}
			else
			{
				echo '<div class="menu">Файлов нет</div>';
			}
			echo '<div class="menu"><a href="?act=file">Назад</a></div>';
		}
		elseif($do=='rate')
		{
			echo '<div class="phdr"><a href="./">Блоги</a> | Популярные файлы</div>';
			$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $prefix . "blogs_files` WHERE `count`>'0';"), 0);
			if($count>0)
			{
				$res = mysql_query("SELECT * FROM `" . $prefix . "blogs_files` WHERE `count`>'0' ORDER BY `count` DESC LIMIT " . $start . "," . $kmess);
				while ($row = mysql_fetch_assoc($res))
				{
					echo ($i % 2) ? '<div class="list1">':'<div class="list2">';
					echo '<a href="load.php?id='.$row['id'].'">'.$row['name'].'</a> ['.formatsize($row['size']).']';
					$req = mysql_fetch_assoc(mysql_query("SELECT * FROM `" . $prefix . "blogs` WHERE `id`='" . $row['ref'] . "';"));
					echo '<div class="sub"><div class="func"><a href="?act=view&amp;id='.$req['id'].'">'.$req['name'].'</a><br />';
					echo 'Скачиваний: '.$row['count'];
					echo '</div></div></div>';
					++$i;
				}
				if ($count > $kmess)
				{
					echo '<p class="menu">' . pagenav('index.php?act=file&amp;do=rate&amp;', $start, $count, $kmess) . '<br/>';
					echo '<form action="" method="POST">
					<input type="text" name="page" size="2"/> <input type="submit" value="Перейти"/></form></p>';
				}
			}
			else
			{
				echo '<div class="menu">Файлов нет</div>';
			}
			echo '<div class="menu"><a href="?act=file">Назад</a></div>';
		}
		else
		{
			echo '<div class="phdr"><a href="./">Блоги</a> | Файлы блогов</div>';
			$fnew = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $prefix . "blogs_files` WHERE `time`>'".$new."';"), 0);
			echo '<div class="menu"><a href="?act=file&amp;do=new">Новые файлы</a> ['.$fnew.']</div>';
			echo '<div class="menu"><a href="?act=file&amp;do=rate">Популярные файлы</a></div>';
			$i = 1;
			while ($i <= 9)
			{
				$cfile = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $prefix . "blogs_files` WHERE `type`='".$i."';"), 0);
				if($cfile>0)
				{
					echo ($i % 2) ? '<div class="list1">':'<div class="list2">';
					echo '<img src="img/'.$i.'.png" alt="&raquo;" /> <a href="?act=file&amp;id='.$i.'">'.$types[$i].'</a> ['.$cfile.']';
					echo '</div>';
				}
				++$i;
			}
			echo '<div class="bmenu"><a href="./">Назад</a></div>';
		}
?>