View file pages/new.php

File size: 4.64Kb
<?
if (!defined('SECURED'))
{
	die("Unknown Error!");
}

$id=intval($_GET['id']);
$cid=intval($_REQUEST['cid']);
$today_midnight=mktime(0,0,0,date('m'),date('d'),date('Y'));
$yesterday_midnight=$today_midnight - (24*3600);
$for=$_GET['for'];

title('Новые файлы');
div('Новые файлы','b');
if(empty($id))
{
	echo'<img src="images/up.gif" alt="[UP]"/><a href="'.$_SERVER['PHP_SELF'].'?'.SID.'">На главную</a><br/>';
	echo $separator;
	if($for=='yesterday') 
	{
		$and_for="and uploaded>$yesterday_midnight and uploaded<$today_midnight";
		echo'<b>Новые файлы за вчера:</b><br/>';
	} else 
	{
		$for='today';
		$and_for="and uploaded>$today_midnight";
		echo'<b>Новые файлы за сегодня:</b><br/>';
	}
	$q=mysql_query("select * from categorys where parent='0' order by position;");
	while($category=mysql_fetch_array($q))
	{
		$files=mysql_result(mysql_query("select count(id) from files where refcat='".$category['id']."' $and_for;"),0);
		$text='<img src="images/dir.gif" alt="[DIR]"/> ';
		$text.='<b><a href="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for='.$for.'&amp;id='.$category['id'].'&amp;'.SID.'">'.$category['name'].'</a></b>('.$files.')<br/>';
		echo $text;
	}
}
else
{
	include'includes/func_pages.php';
	
	$where = (!empty($cid) ? "cat='$cid'" : "refcat='$id'");
	if($for=='yesterday') 
	{
		$where.=" and uploaded>$yesterday_midnight and uploaded<$today_midnight";
	} else 
	{
		$for='today';
		$where.=" and uploaded>$today_midnight";
	}
	
	$base_url=$_SERVER['PHP_SELF']."?mode=new&amp;for=$for&amp;id=$id&amp;cid=$cid";
	$num_items=mysql_result(mysql_query("select count(id) from files where $where;"),0);
	$pages = ceil($num_items/$config['files_on_page']);
	if(!empty($_REQUEST['page']))
	{
		$page = intval($_REQUEST['page']);
		if($page<=0) $page=1; 
		if($page>=$pages) $page=$pages; 
	} else
	{
		$page = 1;
	}
	$start = $page * $config['files_on_page'] - $config['files_on_page'];
	
	echo'<img src="images/up.gif" alt="[UP]"/><a href="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for='.$for.'&amp;'.SID.'">Вверх</a><br/>';
	echo $separator;
	$max=$start+$config['files_on_page'];
	if($max>$num_items) $max=$num_items;
	$total_files = $start + 1;
	if($num_items==0) $total_files=0;
	echo '<b>Файлы '.$total_files.'-'.$max.' из '.$num_items.'</b><br/>';
	echo $separator;
	echo'<b>Новые файлы за:</b><br/>';
	echo ($for=='yesterday' ? '<a href="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for=today&amp;id='.$id.'&amp;cid='.$cid.'&amp;'.SID.'"> сегодня</a> | <b>вчера</b><br/>' : '<b>сегодня</b> | <a href="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for=yesterday&amp;id='.$id.'&amp;cid='.$cid.'&amp;'.SID.'"> вчера</a><br/>');
	if($total_files==0) 
	{
		echo ($for=='yesterday' ? 'За вчера новых файлов не было<br/>' : 'За сегодня новых файлов еще не было<br/>');
	}
		
	$q=mysql_query("select * from files where $where order by uploaded desc limit $start,".$config['files_on_page'].";");
	while($file=mysql_fetch_array($q))
	{
		echo '&#8226; <a href="'.$_SERVER['PHP_SELF'].'?mode=file&amp;id='.$file['id'].'&amp;'.SID.'">'.basename($file['filename']).'</a> ('.$file['downloads'].' скачиваний)<br/>';
		echo '&#187; '.$file['desc'].'<br/>';
	}
	$page_links=pages($base_url, $pages, $page);
	if(!empty($page_links)) echo $separator.$page_links;
	echo $separator;
	echo'Категория:<br/>';
	if($ver=='html')
	{
		echo'<form action="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for='.$for.'&amp;id='.$id.'&amp;'.SID.'" method="post">
		<select name="cid">
		<option value="0">Все</option>';
		$q=mysql_query("select id,name from categorys where parent='".$id."' order by position;");
		while($subcategory=mysql_fetch_array($q))
		{
			echo'<option value="'.$subcategory['id'].'" '.($subcategory['id']==$cid ? 'selected="selected"' : '').'>'.$subcategory['name'].'</option>';
		}
		echo'</select><input type="submit" value="&#187;"/></form>';
	} else
	{
		echo'</small><select name="cid" value="'.$subcategory['id'].'">
		<option value="0">Все</option>';
		$q=mysql_query("select id,name from categorys where parent='".$id."' order by position;");
			while($subcategory=mysql_fetch_array($q))
			{
				echo'<option value="'.$subcategory['id'].'">'.$subcategory['name'].'</option>';
			}
		echo'</select>';
		echo'<small><anchor>&#187;<go href="'.$_SERVER['PHP_SELF'].'?mode=new&amp;for='.$for.'&amp;id='.$id.'&amp;'.SID.'" method="post">';
		echo'<postfield name="cid" value="$(cid)"/>';
		echo'</go></anchor><br/>';
	}
}
echo $separator;	
echo $goback;
?>