<?php
//class TypeTree
//目录树(用于选择栏目)
//--------------------------------
require_once(dirname(__FILE__)."/config_base.php");
class TypeTreeMember
{
	var $dsql;
	var $artDir;
	var $baseDir;
	var $idCounter;
	var $idArrary;
	var $shortName;

	function __construct()
	{
		$this->idCounter = 0;
		$this->artDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
		$this->baseDir = $GLOBALS['cfg_basedir'];
		$this->shortName = $GLOBALS['art_shortname'];
		$this->idArrary = "";
		$this->dsql = 0;
	}

	function TypeTreeMember()
	{
		$this->__construct();
	}

	function Close()
	{
		if(is_object($this->dsql)){ $this->dsql->Close(); @$this->dsql=0; }
		$this->idArrary = "";
		$this->idCounter = 0;
	}

	//----读出所有分类,在类目管理页(list_type)中使用----------
	function ListAllType($nowdir=0,$issend=true,$opall=false,$channelid=0)
	{
		if($this->dsql==0){
			$this->dsql = new DedeSql();
		}

		if($issend) {
			$addct = " And issend=1 ";
		}else{
			$addct = '';
		}
		$this->dsql->SetQuery("Select ID,typedir,typename,ispart,channeltype From #@__arctype where reID=0 $addct order by sortrank");
		$this->dsql->Execute(0);
		$lastID = GetCookie('lastCidTree');
		while($row=$this->dsql->GetObject(0))
		{
			$typeDir = $row->typedir;
			$typeName = $row->typename;
			$ispart = $row->ispart;
			$ID = $row->ID;
			$dcid = $row->channeltype;
			if($ispart==2) continue;
			if($ispart==0 || ($ispart==1 && $opall))
			{//普通列表
				if($channelid==0 || $channelid==$dcid){
					$smenu = " <input type='checkbox' name='selid' id='selid$ID' class='np' onClick=\"ReSel($ID,'$typeName')\"> ";
				}else{
					$smenu = "[×]";
				}
			}else if($ispart==1)
			{//带封面的频道
				$smenu = "[封面]";
			}
			echo "<dl class='topcc'>\n";
			echo "<dd><img style='cursor:hand' onClick=\"LoadSuns('suns{$ID}',{$ID},{$channelid});\" src='img/tree_explode.gif' width='11' height='11'> $typeName{$smenu}</dd>\n";
			echo "</dl>\n";
			echo "<div id='suns".$ID."' class='sunct'>";
			if($lastID==$ID){
			$this->LogicListAllSunType($ID,"|-- ",$opall,$issend,$channelid);
			}
			echo "</div>\r\n";
		}
	}
	//获得子类目的递归调用
	function LogicListAllSunType($ID,$step,$opall,$issend,$channelid, $nums=0)
	{
		$fid = $ID;
		if($issend) $addct = " And issend=1 ";
		else $addct = '';
		if($nums){
			$step = '&nbsp;&nbsp;&nbsp;&nbsp;'.$step;
		}
		$nums = 1;
		$this->dsql->SetQuery("Select ID,reID,typedir,typename,ispart,channeltype From #@__arctype where reID='".$ID."' $addct order by sortrank");
		$this->dsql->Execute($fid);
		if($this->dsql->GetTotalRow($fid)>0)
		{
		  while($row=$this->dsql->GetObject($fid))
		  {
			  $typeDir = $row->typedir;
			  $typeName = $row->typename;
			  $reID = $row->reID;
			  $ID = $row->ID;
			  $ispart = $row->ispart;
			  $dcid = $row->channeltype;

			  if($ispart==2) continue;

			  //普通列表
			  if($ispart==0||($ispart==1 && $opall)){
			  	if($channelid==0 || $channelid==$dcid) $smenu = " <input type='checkbox' name='selid' id='selid$ID' class='np' onClick=\"ReSel($ID,'$typeName')\"> ";
			  	else $smenu = "[×]";
			  	$timg = " <img src='img/tree_list.gif'> ";
			  }
			  //带封面的频道
			  else if($ispart==1){
			  	$timg = " <img src='img/tree_part.gif'> ";
			  	$smenu = "[封面]";
			  }
			  echo '<dl class="topcc">'."\n";
			  echo '<dd>'.$step.$typeName."{$smenu}</dd>\n";
			  echo "</dl>\n";
			  $this->LogicListAllSunType($ID,$step,$opall,$issend,$channelid, $nums);
		  }
		}
	}
}
?>