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

function file_categories($cid){
    global $db, $prefix, $cats;
    $subcats=array();
    if(is_array($cats)){
        $subcats=$cats[$cid];
        if(is_array($subcats)) foreach($subcats as $subcat){
            if(is_array($cats[$subcat])) $subcats=$subcats+$cats[$subcat];
        }
    }
    return $subcats;
}

$num_f_week = 7;	//кол-во дней для недели
$strip_block = 37;	//обрезать заголовок файла до указанного количества символов
$limit_block_link = 10; //кол-во строк в блоках
$num_cols=2;
$mod_name='Files';

$blocks_opt=array(
    array('start_cid'=>86, 'text_cat'=>'Новые программы - аудио'),
    array('start_cid'=>87, 'text_cat'=>'Новые программы - видео'),
    array('start_cid'=>27, 'text_cat'=>'Новые программы - графика'),
    array('start_cid'=>24, 'text_cat'=>'Новые программы - диски'),
    array('start_cid'=>17, 'text_cat'=>'Новые программы - интернет'),
    array('start_cid'=>88, 'text_cat'=>'Новые программы - разное'),
    array('start_cid'=>23, 'text_cat'=>'Новые программы - текст'),
    array('start_cid'=>89, 'text_cat'=>'Новые программы - утилиты')
);

$cats=array();
$result=$db->sql_fetchrowset($db->sql_query("SELECT id, parentid FROM ".$prefix."_categories WHERE modul='".$mod_name."'"));
if(is_array($result)) foreach($result as $item) $cats[$item['parentid']][]=$item['id'];
$content = '<table width="100%" border="0" cellspacing="5" cellpadding="0">';

$blocks_rows=array_chunk($blocks_opt, $num_cols);
foreach($blocks_rows as $row) {
    $content.='<tr>';
    foreach($row as $bl){
	    $where="WHERE status !='0' AND cid IN(".implode(',', file_categories($bl['start_cid'])).")";
        $result = $db->sql_query("SELECT SQL_CALC_FOUND_ROWS lid, title, UNIX_TIMESTAMP(date) as formatted FROM ".$prefix."_files ".$where." ORDER BY formatted DESC LIMIT ".$limit_block_link);
        list($sumfiles_subcat)=$db->sql_fetchrow($db->sql_query("SELECT FOUND_ROWS()"));

	    $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">'.$bl['text_cat'].'</font></b>&nbsp;&nbsp;</th>'.
				        '</tr></table></td></tr>'.
			            '<tr class="bgcolor1"><td>'.
				            '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
        
	    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='.$mod_name.'&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='.$mod_name.'&amp;cat='.$bl['start_cid'].'"><div>&nbsp;<b>Показать все&nbsp;'.$sumfiles_subcat.'</b>&nbsp;</div></a></td>
				    </tr></table>
			    </td></tr></table></td></tr></table></td>';
        }
		$content.='</tr>';
	}
	$content.='</table>';
?>