<?
function get_art_box($setting,&$block_val)	
{
	global $db_obj;
	$order_type		=	in_array($setting['order_type'],array('last_update'))?$setting['order_type']:'last_update';		
	$num				=	(int)$setting['num']?(int)$setting['num']:10;
	$name_length	=	(int)$setting['name_length']?(int)$setting['name_length']:50;
	$cat_id			=	(int)$setting['cat_id']?(int)$setting['cat_id']:($setting['cat_id']=='this_cat'?'this_cat':0);
	$order_sort		=	in_array($setting['order_sort'],array('DESC','ASC'))?$setting['order_sort']:'DESC';
	
	$sql				=	"SELECT title,last_update,article_id,cat_id FROM {$db_obj->db_pre}article WHERE 1=1";
	if($cat_id=='this_cat'){
		global $art_detail_res;
		$cat_id	=	(int)$art_detail_res['cat_id']?(int)$art_detail_res['cat_id']:0;
	}	
	if($cat_id){
		global $glo_category_obj;
		if((int)$setting['is_catname']){
			$cat_arr		=	$glo_category_obj->recursion_category('article',$cat_id,true);
			$cat_id_str	=	$cat_arr['cat_id_str'];
			$block_val['display_name']	=	$cat_arr['cat_name'];
		}else{
			$cat_id_str	=	$glo_category_obj->recursion_category('article',$cat_id,false);
		}
		$sql	.=	" AND cat_id in ($cat_id_str) ";
	}
	if($type			=	$setting['type']){
		$sql	.=	" AND ( 1!=1  ";		
		if(in_array('is_support',$type)){
				$sql.=" OR is_support=1";
		}	
		if(in_array('is_news',$type)){
				$sql.=" OR is_news=1";
		}
		if(in_array('is_article',$type)){
				$sql.=" OR is_article=1";
		}
		$sql	.=	" ) ";		
	}
	if($order_type&&$order_sort){
		$sql	.=	" ORDER BY $order_type $order_sort";	
	}	
	$sql		.=	" LIMIT $num";		
	$res	=		$db_obj->getRecords($sql);
	if($res){
		$res	=	format_art_list($res,$name_length);	
		return $res;
	}else{
		return false;
	}
}


function format_art_list($res,$name_length='')
{
	if(!$res){
		return false;
	}
	foreach($res as $key=>$val){
		$res[$key]	=	format_art($val,$name_length);
	}
	return $res;
}

function format_art($row,$name_length='')
{
	if($row['title']&&$row['article_id']){
		$row['article_url']		=		get_url('article.php?article_id='.$row['article_id'],$row['title']);
		if($name_length){
			$row['title']			=		sub_str($row['title'],$name_length);
		}	
		$row['title']				=	   htmlspecialchars($row['title'],ENT_QUOTES);	
		return $row;
	}else{
		return false;
	}
}
