<?php
//class TypeUnit
//这个类主要是封装频道管理时的一些复杂操作
//--------------------------------
require_once(dirname(__FILE__)."/config_base.php");
class TypeUnit
{
	var $dsql;
	var $artDir;
	var $baseDir;
	var $idCounter;
	var $idArrary;
	var $shortName;
	var $aChannels;
	var $isAdminAll;
	//-------------
	//php5构造函数
	//-------------
	function __construct($channel=""){
		$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;
		$this->aChannels = Array();
		$this->isAdminAll = false;
		if(preg_match("/>/",$channel)){
			$this->aChannels = explode('>',str_replace('<','',$channel));
		}else{
			$this->isAdminAll = true;
		}
  }
	function TypeUnit($channel=""){
		$this->__construct($channel);
	}
	//------------------
	//清理类
	//------------------
	function Close(){
		if($this->dsql){ $this->dsql->Close(); @$this->dsql=0; }
		$this->idArrary = "";
		$this->idCounter = 0;
	}
	//------------------------------
	function GetTotalArc($tid){
		if(!is_object($this->dsql)){ $this->dsql = new DedeSql(); }
		$maintable = $this->dsql->getone("select #@__arctype.ID,#@__channeltype.maintable from #@__arctype left join #@__channeltype on #@__channeltype.ID=#@__arctype.channeltype where #@__arctype.ID=$tid");
		$maintable = $maintable['maintable'];
		$row = $this->dsql->GetOne("Select count(ID) as dd From $maintable where typeid='$tid'");
		return $row['dd'];
	}
	//
	//----读出所有分类,在类目管理页(list_type)中使用----------
	//
	function ListAllType($channel=0,$nowdir=0)
	{

		if($this->dsql==0){ $this->dsql = new DedeSql(); }

		$this->dsql->SetQuery("Select ID,typedir,typename,ispart,sortrank,ishidden,channeltype From #@__arctype where reID=0 order by sortrank");
		$this->dsql->Execute('pn0');

		$lastID = GetCookie('lastCid');

		while($row=$this->dsql->GetObject('pn0'))
		{
			$typeDir = $row->typedir;
			$typeName = $row->typename;
			$ispart = $row->ispart;
			$ID = $row->ID;
			$rank = $row->sortrank;
			$channeltype = $row->channeltype;
			if($row->ishidden=='1') $nss = "<font color='red'>[隐]</font>";
			else  $nss = "";

			//有权限栏目
			if($this->isAdminAll===true || in_array($ID,$this->aChannels))
			{
			   //print_r($this->aChannels);
			   //互动栏目
			   if($channeltype<-1)
			   {
			   	 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' oncontextmenu=\"CommonMenuWd(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>\r\n";
				 echo "<td width='6%'>[ID:".$ID."]</td>\r\n";
				 echo "<td width='27%' align='left'>\r\n<img onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a><font color='red'>[互]</font> </td>\r\n";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>\r\n";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>\r\n";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>\r\n";
				 echo "|<a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a>\r\n";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a>\r\n";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a>\r\n";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a>\r\n";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a>\r\n";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td>\r\n</tr>\r\n";
			     echo "</table>\r\n <div id='suns".$ID."'>\r\n";

			   }
			   //普通列表
			   else if($ispart==0)
			   {
			   	 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' oncontextmenu=\"CommonMenu(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>\r\n";
				 echo "<td width='6%'>[ID:".$ID."]</td>\r\n";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>\r\n";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>\r\n";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>\r\n";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>\r\n";
				 echo "|<a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a>\r\n";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a>\r\n";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a>\r\n";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a>\r\n";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a>\r\n";
				 echo "</td>\r\n<td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td>\r\n</tr>\r\n";
			     echo "</table>\r\n <div id='suns".$ID."'>\r\n";

			   }
			   //带封面的频道
			   else if($ispart==1)
	       {
			   	 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' oncontextmenu=\"CommonMenuPart(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>\r\n";
				 echo "<td width='6%'>[ID:".$ID."]</td>\r\n";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>\r\n";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>\r\n";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>\r\n";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>\r\n";
				 echo "|<a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a>\r\n";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a>\r\n";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a>\r\n";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a>\r\n";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a>\r\n";
				 echo "</td>\r\n<td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td>\r\n</tr>\r\n";
			     echo "</table>\r\n <div id='suns".$ID."'>\r\n";
				 }
			  //独立页面
			  else if($ispart==2)
			  {
			   	 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' oncontextmenu=\"CommonMenuPart(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>\r\n";
				 echo "<td width='6%'>[ID:".$ID."]</td>\r\n";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>\r\n";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>\r\n";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>\r\n";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>\r\n";
				 echo "|<a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a>\r\n";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a>\r\n";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a>\r\n";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a>\r\n";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a>\r\n";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td>\r\n</tr>\r\n";
			     echo "</table>\r\n <div id='suns".$ID."'>\r\n";
				 }

			  if($lastID==$ID){
				   $this->LogicListAllSunType($ID,"　",false);
			  }
		  }
		  //没权限栏目
		  else{
		  	 $sonNeedShow = false;
		  	 $this->dsql->SetQuery("Select ID From #@__arctype where reID={$ID}");
		     $this->dsql->Execute('ss');
		     while($srow=$this->dsql->GetArray('ss')){
		        	if( in_array($srow['ID'],$this->aChannels) ){ $sonNeedShow = true;  break; }
		     }
		  	 //如果二级栏目中有的所属归类文档
		  	 if($sonNeedShow===true)
		  	 {
		  	    //互动栏目
			      if($channeltype<-1)
			      {
				 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center'>";
				 echo "<td width='7%'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
			     echo "</table>\r\n <div id='suns".$ID."'>";
			      }
				  //普通列表
				  else if($ispart==0)
			      {
				 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center'>";
				 echo "<td width='7%'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
			     echo "</table>\r\n <div id='suns".$ID."'>";
			      }
				  //带封面的频道
				  else if($ispart==1)
	          {
				 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center'>";
				 echo "<td width='7%'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
			     echo "</table>\r\n <div id='suns".$ID."'>";
			     }
				 //独立页面
				 else if($ispart==2)
				 {
				 echo "<table width='96%' border='0' cellpadding='1' cellspacing='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center'>";
				 echo "<td width='7%'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'><img style='cursor:hand' onClick=\"LoadSuns('suns".$ID."',$ID);\" src='images/class_sopen.gif' width='11' height='15' border='0' align='absmiddle' />  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
			     echo "</table>\r\n <div id='suns".$ID."'>";
			     }
			     $this->LogicListAllSunType($ID,"　",true);
			  }
		  }
			echo "</div>\r\n";
		}
	}
	//获得子类目的递归调用
	function LogicListAllSunType($ID,$step,$needcheck=true)
	{
		$fid = $ID;
		$this->dsql->SetQuery("Select ID,reID,typedir,typename,ispart,sortrank,ishidden,channeltype From #@__arctype where reID='".$ID."' order by sortrank");
		$this->dsql->Execute('s'.$fid);
		while($row=$this->dsql->GetObject('s'.$fid))
		{
			  $typeDir = $row->typedir;
			  $typeName = $row->typename;
			  $reID = $row->reID;
			  $ID = $row->ID;
			  $ispart = $row->ispart;
			  $channeltype = $row->channeltype;
			  if($step=="  ") $stepdd = 2;
			  else $stepdd = 3;
			  $rank = $row->sortrank;
			  if($row->ishidden=='1') $nss = "<font color='red'>[隐]</font>";
			  else  $nss = "";
			  //有权限栏目
			  if(in_array($ID,$this->aChannels) || $needcheck===false || $this->isAdminAll===true)
			  {
			  	 //互动栏目
			   if($channeltype<-1)
			    {
				 echo "<table width='96%' border='0' cellspacing='1' cellpadding='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' class='trlbg' oncontextmenu=\"CommonMenuWd(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'>$step   ├  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a><font color='red'>[互]</font> </td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>";
				 echo "| <a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a> ";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a> ";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a> ";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a> ";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a> ";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
				 echo "    </table>\r\n";
			    }
			    //普通列表
			    else if($ispart==0)
			    {
				 echo "<table width='96%' border='0' cellspacing='1' cellpadding='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' class='trlbg'  oncontextmenu=\"CommonMenu(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'>$step   ├  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a> </td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>";
				 echo "| <a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a> ";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a> ";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a> ";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a> ";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a> ";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
				 echo "    </table>\r\n";

			    }
			    //封面频道
			    else if($ispart==1)
			    {
				 echo "<table width='96%' border='0' cellspacing='1' cellpadding='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' class='trlbg' oncontextmenu=\"CommonMenuPart(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'>$step   ├  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a><font color='red'>[封面]</font></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>";
				 echo "| <a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a> ";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a> ";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a> ";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a> ";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a> ";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
				 echo "    </table>\r\n";
			    }
			    //独立页面
			    else if($ispart==2)
			    {
				 echo "<table width='96%' border='0' cellspacing='1' cellpadding='0' align='center' style='margin:0px auto' class='tblist2'>\r\n";
				 echo "<tr align='center' class='trlbg' oncontextmenu=\"SingleMenu(this,$ID,'".urlencode($typeName)."')\">\r\n";
				 echo "<td width='7%'><input class='np' type='checkbox' name='tids[]' value='{$ID}'></td>";
				 echo "<td width='6%'>[ID:".$ID."]</td>";
				 echo "<td width='27%' align='left'>$step   ├  <a href='catalog_do.php?cid=".$ID."&dopost=listArchives' style='font-size:14px; text-decoration:none;'>{$nss}".$typeName."</a><font color='red'>[封面]</font></td>";
				 echo "<td width='10%'>(文档：".$this->GetTotalArc($ID).")</td>";
				 echo "<td width='40%' align='right' style='letter-spacing:1px;'>";
				 echo "<a href='{$GLOBALS['cfg_plus_dir']}/list.php?tid={$ID}' target='_blank'>预览</a>";
				 echo "| <a href='catalog_do.php?cid={$ID}&dopost=listArchives'> 内容</a> ";
				 echo "| <a href='catalog_add.php?ID={$ID}'>添子类</a> ";
				 echo "| <a href='catalog_edit.php?ID={$ID}'>更改</a> ";
				 echo "| <a href='catalog_move.php?job=movelist&typeid={$ID}'>移动</a> ";
				 echo "| <a href='catalog_del.php?ID={$ID}&typeoldname=".urlencode($typeName)."'>删除</a> ";
				 echo "</td><td width='10%'><label>";
				 echo "<input name='sortrank{$ID}' type='text' id='textfield2' value='{$rank}' size='2' maxlength='4' style='text-align:center;' />";
				 echo "</label></td></tr>";
			     echo "    </table>\r\n";
				}
			  $this->LogicListAllSunType($ID,$step."　",false);
		  }//if 有权限
		}//End while
	}
	//------------------------------------------------------
	//-----返回与某个目相关的下级目录的类目ID列表(删除类目或文章时调用)
	//------------------------------------------------------
	function GetSunTypes($ID,$channel=0)
	{
		if($this->dsql==0) $this->dsql = new DedeSql(false);
		$this->idArray[$this->idCounter]=$ID;
		$this->idCounter++;
		$fid = $ID;
	  if($channel!=0) $csql = " And channeltype=$channel ";
	  else $csql = "";
		$this->dsql->SetQuery("Select ID From #@__arctype where reID=$ID $csql");
		$this->dsql->Execute("gs".$fid);
    //if($this->dsql->GetTotalRow("gs".$fid)!=0)
		//{
		while($row=$this->dsql->GetObject("gs".$fid)){
			$nid = $row->ID;
			$this->GetSunTypes($nid,$channel);
		}
		//}
		return $this->idArray;
	}
	//----------------------------------------------------------------------------
	//获得某ID的下级ID(包括本身)的SQL语句“($tb.typeid=id1 or $tb.typeid=id2...)”
	//----------------------------------------------------------------------------
	function GetSunID($ID,$tb="#@__archives",$channel=0)
	{
		$this->sunID = "";
		if($this->dsql==0) $this->dsql = new DedeSql(false);
		$this->idCounter = 0;
		$this->idArray = "";
		$this->GetSunTypes($ID,$channel);
		$this->dsql->Close();
		$this->dsql = 0;
		$rquery = "";
		for($i=0;$i<$this->idCounter;$i++)
		{
			if($i!=0) $rquery .= " Or ".$tb.".typeid='".$this->idArray[$i]."' ";
			else      $rquery .= "    ".$tb.".typeid='".$this->idArray[$i]."' ";
		}
		reset($this->idArray);
		$this->idCounter = 0;
		return " (".$rquery.") ";
	}
	//----------------------------------------
	//删除类目
	//----------------------------------------
	function DelType($ID,$isDelFile)
	{
		$this->idCounter = 0;
		$this->idArray = "";
		$this->GetSunTypes($ID);

		$query = "
		Select #@__arctype.*,#@__channeltype.typename as ctypename,
		#@__channeltype.addtable
		From #@__arctype left join #@__channeltype
		on #@__channeltype.ID=#@__arctype.channeltype
		where #@__arctype.ID='$ID'
		";
		$typeinfos = $this->dsql->GetOne($query);
		$topinfos = $this->dsql->GetOne("Select moresite,siterefer,sitepath,siteurl From #@__arctype where ID='".$typeinfos['topID']."'");

		if(!is_array($typeinfos)) return false;
		$indir = $typeinfos['typedir'];
		$addtable = $typeinfos['addtable'];
		$ispart = $typeinfos['ispart'];
		$defaultname = $typeinfos['defaultname'];

		//删除数据库里的相关记录
		foreach($this->idArray as $id){
			$myrow = $this->dsql->GetOne("Select * From #@__arctype where ID='$id'");
			if($myrow['topID']>0)
			{
				$mytoprow = $this->dsql->GetOne("Select moresite,siterefer,sitepath,siteurl From #@__arctype where ID='".$myrow['topID']."'");
				foreach($mytoprow as $k=>$v){
	  		   if(!ereg("[0-9]",$k)) $myrow[$k] = $v;
	  	  }
			}
			//删除目录和目录里的所有文件 ### 禁止了此功能
			//删除单独页面
		  if($myrow['ispart']==2 && $myrow['typedir']=="" && $myrow['channeltype']>-1){
			  if( is_file($this->baseDir."/".$myrow['defaultname']) )
			  { @unlink($this->baseDir."/".$myrow['defaultname']); }
		  }

		  if($myrow['channeltype']>-1){
			    //删除数据库信息
			    $this->dsql->ExecuteNoneQuery("Delete From #@__archives where typeid='$id'");
			    $this->dsql->ExecuteNoneQuery("update #@__archives set typeid2=0 where typeid2='$id'");
			    $this->dsql->ExecuteNoneQuery("Delete From #@__spec where typeid='$id'");
			    $this->dsql->ExecuteNoneQuery("Delete From #@__feedback where typeid='$id'");
		  }
		  $this->dsql->ExecuteNoneQuery("Delete From #@__arctype where ID='$id'");
		  if($addtable!=""){
			   $this->dsql->ExecuteNoneQuery("Delete From $addtable where typeid='$id'");
		  }

		}

		//删除目录和目录里的所有文件 ### 禁止了此功能

		//删除单独页面
		if($ispart==2 && $indir=="" && $myrow['channeltype']>-1){
			if( is_file($this->baseDir."/".$defaultname) ) @unlink($this->baseDir."/".$defaultname);
		}

		@reset($this->idArray);
		$this->idCounter = 0;

		return true;
	}
	//---------------------------
	//---- 删除指定目录的所有文件
	//---------------------------
	function RmDirFile($indir)
	{
   		if(!file_exists($indir)) return;
   		$dh = dir($indir);
   		while($file = $dh->read()) {
      	if($file == "." || $file == "..") continue;
      	else if(is_file("$indir/$file")) @unlink("$indir/$file");
     	 	else{
         		$this->RmDirFile("$indir/$file");
      	}
      	if(is_dir("$indir/$file")){
         	@rmdir("$indir/$file");
      	}
   		}
   		$dh->close();
   		return(1);
	}
}
?>