<?php 
/*
  C9社区 PHP无限级分类 类
*/
class classstr
{
  var $dbz;
  var $str="";
  //获取数据库表前缀
  function classstr($str){
    $this->dbz=$str;
	return $this->dbz;
  }
  var $trees = array();
  var $id = array();
  var $cid = array();
  var $names = array();
  
  var $lists = array();
  var $toplists = array();
  var $indexvs = array();
  var $orders = array();
  
  function classarr(){
    $sql=query("select * from ".$this->dbz."class order by orders asc");
    while($row=fetch($sql)){
	  array_push($this->trees,$row["trees"]);
	  array_push($this->id,$row["id"]);
	  array_push($this->cid,$row["cid"]);
	  array_push($this->names,$row["names"]);
	  
	  array_push($this->lists,$row["lists"]);
	  array_push($this->toplists,$row["toplists"]);
	  array_push($this->indexvs,$row["indexvs"]);
	  array_push($this->orders,$row["orders"]);
    }
  }
  
  //判断函数 0返回flase 其他返回trun
  function classbool($n_01,$url=""){
    if ($url==''){
      if ($n_01=='0'){
	    return 'false';
	  }
	  else{
	    return '<font color="#FF0000">true</font>';
	  }
	}
	else{
	  if ($n_01=='0'){
	    return "<a href=\"".$url."&num=1\">false</a>";
	  }
	  else{
	    return "<a href=\"".$url."&num=0\"><font color=\"#FF0000\">true</font></a>";
	  }
	}
  }
  
  //按照id查找names函数
  function classnames($id){
    $i=0;
	$names='';
	if ($id=='0'){
	  $names='顶级分类';
	}
	else{
	  while($i<count($this->id)){
	    if($this->id[$i]==$id){
	      $names=$this->names[$i];
	    }
	    $i=$i+1;
	  }
	}
	
	return $names;
  }
  
  
   //返回函数
  //$i_01:分类id,$n_01:分类等级,$m_01:输出类型0为添加输出,1分类列表
  function classadd($i_01=0,$n_01=1,$m_01=0){
    //获取分类标识
	$classz="";
	$n_02=1;
	while($n_02<$n_01){
	  $classz.="|-";
	  $n_02=$n_02+1;
	}
    $num=0;
	while($num<count($this->id)){
	  if ($this->cid[$num]==$i_01){
	    //取出一级
		if($m_01==0){
		  $this->str.="<option value=".$this->id[$num].",".$this->trees[$num].">".$classz.$this->names[$num]." </option>";
		}
		elseif($m_01==1){
		  $this->str.="<tr align=\"center\">
		    <td  height=\"25\" bgcolor=\"#FFFFFF\"><input type=\"checkbox\" name=\"checkbox".$this->id[$num]."\" id=\"checkbox".$this->id[$num]."\" value=\"".$this->id[$num]."\" />".$this->id[$num]."</td>
			<td bgcolor=\"#FFFFFF\" align=\"left\">".$classz."<a href=\"../class.php?id=".$this->id[$num]."\" target=\"_blank\">".$this->names[$num]."</a></td>
			<td bgcolor=\"#FFFFFF\" align=\"left\">".$this->classnames($this->cid[$num])."</td>
			<td bgcolor=\"#FFFFFF\" align=\"left\">".$this->classbool($this->lists[$num],"query.php?rel=lists&id=".$this->id[$num])."</td>
			<td bgcolor=\"#FFFFFF\" align=\"left\">".$this->classbool($this->toplists[$num],"query.php?rel=toplists&id=".$this->id[$num])."</td>
			<td bgcolor=\"#FFFFFF\" align=\"left\">".$this->classbool($this->indexvs[$num],"query.php?rel=indexvs&id=".$this->id[$num])."</td>
			<td bgcolor=\"#FFFFFF\" align=\"left\"><input type=\"text\" name=\"orders".$this->id[$num]."\" id=\"orders".$this->id[$num]."\" value=\"".$this->orders[$num]."\"  size=\"8\" /></td>
			<td bgcolor=\"#FFFFFF\" align=\"left\"><a href=\"html.php?rel=class_html&id=".$this->id[$num]."\">静态</a> <a href=\"class.php?rel=class_info&id=".$this->id[$num]."\">修改</a> <a href=\"query.php?rel=class_del&id=".$this->id[$num]."\">删除</a></td>
			
		    </tr>";
		}
		$this->classadd($this->id[$num],$n_01+1,$m_01);
	  }
	  $num=$num+1;
	}
	
	return $this->str;
  }
  //classlistbool分类是否为最后一级分类 ,返回值bool,为真时代表不为最后一级分类
  function classlistbool($id){
    $i=0;
	$n=false;
	while($i<count($this->id)){
	  if($id==$this->cid[$i]){
	    $n=true;
	  }
	  $i=$i+1;
	}
	return $n;
  }
  
  //查询单个id分类名称.
  function classidnames($id){
    $sql=query("select * from ".$this->dbz."class where id='$id'");
	if($sql){
	  if($row=fetch($sql)){
	    return $row["names"];
	  }
	  else{
	    return "分类不存在";
	  }
	}
	else{
	  return "查询失败";
	}
  }
  
  
  
}
?>