<?
function maketotree($treemb) {
global $tablepre;
$tree="<table width=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"text\">\n";
$tree=$tree."<tr align=\"left\" valign=\"middle\">\n";
$tree=$tree."<td width=\"40\">\n";
$tree=$tree."<table width=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"text\">\n";
$tree=$tree."<tr align=\"left\" valign=\"middle\">\n";
$tree=$tree."<td width=\"15\"><a href=\"#\" onClick=\"expandIt('KB#bbs_id#'); return false\" style=\"cursor: default;\"><img id=\"dir#bbs_id#\" name=\"dir#bbs_id#\" src=\"images/#openclose#\" width=\"18\" height=\"18\" border=0></a></td>\n";
$tree=$tree."<td width=\"15\"><a href=\"#\" onClick=\"expandIt('KB#bbs_id#'); return false\" style=\"cursor: default;\"><img id=\"fold#bbs_id#\" name=\"fold#bbs_id#\" src=\"images/#openclosex#\" width=\"18\" height=\"15\" border=0></a></td>\n";
$tree=$tree."<td>\n";
$tree=$tree."<div id=\"KB#bbs_id#Parent\" class=\"parent\"> &nbsp;<a class=head3 href=\"#\" onClick=\"parent.frames('main').location.href='main.php?layer_1=#BBSCateID#&qs=#BBSCateQs#';expandIt('KB#bbs_id#'); return false\">#BBSCateName#</a> </div>\n";
$tree=$tree."</td>\n";
$tree=$tree."</tr>\n";
$tree=$tree."</table>\n";
$tree=$tree."</td>\n";
$tree=$tree."</tr>\n";			
$tree=$tree."<tr align=\"left\" valign=\"middle\">\n";
$tree=$tree."<td>\n";
$tree=$tree."<div id=\"KB#bbs_id#Child\" #classchild#>\n";
$tree=$tree."<table width=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"text\">\n";				
$tree=$tree."#888888#";			 						
$tree=$tree."</table>\n";
$tree=$tree."</div>\n";	
$tree=$tree."</td>\n";
$tree=$tree."</tr>\n";
$tree=$tree."</table>\n";

$ftbbsub="<tr align=\"left\" valign=\"middle\">\n";
$ftbbsub=$ftbbsub."<td width=\"15\" class=\" \"><img src=\"images/treeline.gif\" width=\"18\" height=\"18\"></td>\n";      
$ftbbsub=$ftbbsub."<td width=\"15\" align=\"center\" valign=\"top\">#line#</td>\n";
$ftbbsub=$ftbbsub."<td>\n";
$ftbbsub=$ftbbsub."<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"text\">\n";
$ftbbsub=$ftbbsub."<tr>\n";     
$ftbbsub=$ftbbsub."<td width=\"10\"><img src=\"images/doc.gif\" width=\"16\" height=\"18\"></td>\n";
$ftbbsub=$ftbbsub."<td> <a class=head3 href=\"main.php?layer_1=#BBS_Cate_PID#&layer_2=#BBS_Cate_ID#&qs=#BBS_Cate_Qs#\" target=\"main\"> #BBS_Cate_Name#</a></td>\n";
$ftbbsub=$ftbbsub."</tr>\n";
$ftbbsub=$ftbbsub."</table>\n";
$ftbbsub=$ftbbsub."</td>\n";
$ftbbsub=$ftbbsub."</tr>\n";

$sql="select BBS_ID,BBS_Cate_Name,BBS_Cate_ID,BBS_Cate_PID,BBS_Cate_Qs,treesign from {$tablepre}bbs_cate where BBS_Cate_PID='0' and deleted=0 order by totop asc";
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
$dotree="";
do { 
   $sql15="select BBS_Cate_Name,BBS_Cate_ID,BBS_Cate_PID,BBS_Cate_Qs from {$tablepre}bbs_cate where BBS_Cate_PID='".$myrow["BBS_Cate_ID"]."' and deleted=0 order by totop asc";
   $rm=mysql_query($sql15);
   $myrow15 = mysql_fetch_array($rm);
   $numrows = mysql_num_rows($rm);
   $treembhtm="";
   $treenl="";
   if ($numrows!=0){
      $treesign=$myrow["treesign"]; 
      if ($treesign==1){
      $openclose="opentm.gif";
      $openclosex="openx.gif";
	  $k="";
	  }
      else{
      $openclose="closetm.gif";
      $openclosex="close.gif";
	  $k="class=\"child\"";
      }
	  /*
      if ($treesign==0){
      $k="class=\"child\"";
	  }
      else{
      $k=""; 
      }
	  */
      $dotree=$tree;
	  $dotree=str_replace("#openclose#",$openclose,$dotree);
	  $dotree=str_replace("#openclosex#",$openclosex,$dotree);
	  
	  $dotree=str_replace("#bbs_id#",$myrow["BBS_ID"],$dotree);
	  $dotree=str_replace("#BBSCateName#",$myrow["BBS_Cate_Name"],$dotree);
	  $dotree=str_replace("#BBSCateID#",$myrow["BBS_Cate_ID"],$dotree);
	  $dotree=str_replace("#BBSCatePID#",$myrow["BBS_Cate_PID"],$dotree);
	  $dotree=str_replace("#BBSCateQs#",$myrow["BBS_Cate_Qs"],$dotree);
	  $dotree=str_replace("#classchild#",$k,$dotree); 
      $i=0;
      do {
      if ($i==$numrows-1){
		$line="<img src=\"images/nodeend.gif\" width=\"16\" height=\"18\">";
		}
	  else{
	    $line="<img src=\"images/node.gif\" width=\"16\" height=\"18\">";
	  }
	  $treembhtm=$treembhtm.$ftbbsub;
	  $treembhtm=str_replace("#line#",$line,$treembhtm);
	  $treembhtm=str_replace("#BBS_Cate_Name#",$myrow15["BBS_Cate_Name"],$treembhtm);
	  $treembhtm=str_replace("#BBS_Cate_ID#",$myrow15["BBS_Cate_ID"],$treembhtm);
	  $treembhtm=str_replace("#BBS_Cate_PID#",$myrow15["BBS_Cate_PID"],$treembhtm);
	  $treembhtm=str_replace("#BBS_Cate_Qs#",$myrow15["BBS_Cate_Qs"],$treembhtm);
	  $treenl=str_replace("#888888#",$treembhtm,$dotree);
	  $i++;
	  }
      while ($myrow15 = mysql_fetch_array($rm));
  }
    $mbnl=$mbnl.$treenl;
}
while ($myrow = mysql_fetch_array($rs));
$nl=str_replace("#ftbbstree#",$mbnl,$treemb);

$file="../ftbbstree.htm";
if ($treemb!="" ||!empty($treemb)){
$fp = fopen($file,"w"); 
fputs($fp, $nl); 
fclose($fp);
}
 
}
?>