<?php
if(!defined('DEDEINC'))
{
	exit("Request Error!");
}
require_once(DEDEINC."/taglib/type.lib.php");
function lib_autochannel(&$ctag,&$refObj)
{
	global $dsql,$envs;

	$attlist="partsort|0,typeid=-1";
	FillAttsDefault($ctag->CAttribute->Items,$attlist);
	extract($ctag->CAttribute->Items, EXTR_SKIP);

	$innertext = trim($ctag->GetInnerText());
	$topid = $typeid;
	$sortid = $partsort;

	if($topid=='-1' || $topid=='') $topid = $envs['typeid'];
	if(empty($sortid)) $sortid = 1;
	$getstart = $sortid - 1;

	$row = $dsql->GetOne("Select id,typename From `#@__arctype` where reid='{$topid}' And ispart<2 And ishidden<>'1' order by sortrank asc limit $getstart,1");
	if(!is_array($row)) $typeid = 0;
	else $typeid = $row['id'];
	if($typeid==0) return '';
	include_once(DEDEINC.'/taglib/inc_type.php');
	if(trim($innertext)=='') $innertext = GetSysTemplets('part_autochannel.htm');
	return lib_type($typeid,$innertext);
}
?>