<?php
if (!defined('BLOCK_FILE')) {
    Header("Location: ../index.php");
    exit;
}
/*
	© Shadow (Alfainfo)
	ICQ 9535600
	http://alfainfo.ru/
	http://alfafilms.ru/
*/
	global $prefix, $db, $admin, $admin_file, $homeurl;

function file_categories($cid)
{
 global $db,$prefix;
 $result=$db->sql_query("SELECT id FROM ".$prefix."_categories WHERE parentid=$cid AND modul='files'");
 while(list($cid)=$db->sql_fetchrow($result))
 {
  $return.="cid=".$cid.'|';
  $return.=file_categories($cid);
 }
 return $return;
}

$num_f_week = 7;	//кол-во дней для недели
$strip_block = 37;	//обрезать заголовок файла до указанного количества символов
$limit_block_link = 10; //кол-во строк в блоках
$num_cat_1 = 86;	
$num_cat_2 = 87;	
$num_cat_3 = 27;	
$num_cat_4 = 24;	
$num_cat_5 = 17;
$num_cat_6 = 88;
$num_cat_7 = 23;
$num_cat_8 = 89;


$content .= "<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">";

$blocks_num = 1;
while ($blocks_num <= 8) {

	if ($blocks_num == 1) {
		$start_cid = $num_cat_1;
		$bcat = $num_cat_1;
		$text_cat = "Новые программы - аудио";
	} elseif ($blocks_num == 2) {
		$start_cid = $num_cat_2;
		$bcat = $num_cat_2;
		$text_cat = "Новые программы - видео";
	} elseif ($blocks_num == 3) {
		$start_cid = $num_cat_3;
		$bcat = $num_cat_3;
		$text_cat = "Новые программы - графика";
	} elseif ($blocks_num == 4) {
		$start_cid = $num_cat_4;
		$bcat = $num_cat_4;
		$text_cat = "Новые программы -  диски";
	} elseif ($blocks_num == 5) {
		$start_cid = $num_cat_5;
		$bcat = $num_cat_5;
		$text_cat = "Новые программы - интернет";
	} elseif ($blocks_num == 6) {
		$start_cid = $num_cat_6;
		$bcat = $num_cat_6;
		$text_cat = "Новые программы - разное";
	} elseif ($blocks_num == 7) {
		$start_cid = $num_cat_7;
		$bcat = $num_cat_7;
		$text_cat = "Новые программы - текст";
	} else {
		$start_cid = $num_cat_8;
		$bcat = $num_cat_8;
		$text_cat = "Новые программы - утилиты";
	}

	$file_categories="cid=$start_cid|".file_categories($start_cid);
	$file_categories=substr($file_categories,0,strlen($file_categories)-1);
        $file_categories="(".str_replace('|',' OR ',$file_categories).")";
	list($sumfiles_subcat) = $db->sql_fetchrow($db->sql_query("SELECT count(*) FROM ".$prefix."_files WHERE status !='0' AND $file_categories"));

	if ($blocks_num == 1 or $blocks_num == 3 or $blocks_num == 5 or $blocks_num == 5 or $blocks_num == 7) {
		$content .= "<tr>";
		}
	$content .= "<td valign=\"top\"><img src=\"$homeurl/images/pix.gif\" width=\"250\" height=\"1\" border=\"0\" /><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"bgcolor4\">
	<tr><td><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
			<tr class=\"bgcolor1\"><td>
				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>
				<th width=\"50%\" valign=\"middle\" align=\"left\">&nbsp;<img src=\"$homeurl/images/misc/arrow.png\" width=\"10\" height=\"10\" border=\"0\" />&nbsp;<b><font class=\"option\">$text_cat</font></b>&nbsp;&nbsp;</th>
				</tr></table></td></tr>
			<tr class=\"bgcolor1\"><td>
				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	
	$result = $db->sql_query("SELECT lid, title, UNIX_TIMESTAMP(date) as formatted FROM ".$prefix."_files WHERE status !='0' AND ".$file_categories." ORDER BY UNIX_TIMESTAMP(date) DESC LIMIT ".$limit_block_link."");
	while(list($lid, $title, $f_date) = $db->sql_fetchrow($result)) {
	$linkstrip = cutstr($title, $strip_block);
	$content .= "<tr>
		<td width=\"10\" valign=\"middle\"><img src=\"$homeurl/images/misc/right.png\" width=\"10\" height=\"10\" align=\"middle\" /></td>";

	$content .= "<td><a href=\"$homeurl/index.php?name=files&amp;op=view&amp;id=$lid\" title=\"$title\"><div>&nbsp;$linkstrip&nbsp;</div></a></td>";
		
		if (is_admin($admin)) {
		$content .= "<td width=\"18\" align=\"center\"><a href=\"$homeurl/".$admin_file.".php?op=files_add&amp;id=$lid\"><img border=\"0\" src=\"$homeurl/images/edit.gif\" alt="._EDIT."></a></td>
		      <td width=\"18\" align=\"center\"><a href=\"$homeurl/".$admin_file.".php?op=file_delite&amp;id=$lid\"><img border=\"0\" src=\"$homeurl/images/delete.gif\" alt="._DELETE."></a></td>";
		}
	$content .= "</tr>";
	}

	$content .= "</table>			
			</td></tr>
			<tr><td>
				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
				<tr><td width=\"100%\" height=\"20\" align=\"left\" valign=\"middle\" class=\"bgcolor1\"><a href=\"$homeurl/index.php?name=files&amp;cat=$bcat\"><div>&nbsp;<b>Показать все&nbsp;$sumfiles_subcat</b>&nbsp;</div></a></td>
				</tr></table>
			</td></tr></table></td></tr></table></td>";

	if ($blocks_num == 2 or $blocks_num == 4 or $blocks_num == 6 or $blocks_num == 8) {
		$content .= "</tr>";
		}
	$blocks_num++;
	}
	$content .= "</table>";
?>