<?php 
////////////////////
///回复体系类 //////
////////////////////
class hf{
	var $wapid;        //网站id
	var $gro;          //所属id
	var $start;        //开始
	var $limit;     	//结束
	var $wapname;
	var $login;
   
   function __construct($wapid,$gro,$start,$limit,$login){

   $this->wapid =  $wapid;
	$this->gro   =  $gro;
	$this->start =  $start;
	$this->limit =  $limit;
	$this->login =  $login;
	$sql="SELECT id,name,nc,pass,sex,site_u,xid FROM user WHERE id='{$this->wapid}'";
            $logininfo=mysql_query($sql);
            if($logininfo && mysql_num_rows($logininfo)>0){
            list($id,$name,$nc,$pass,$sex,$site_u,$xid) = mysql_fetch_row($logininfo);
	        }
	$this->wapname = $name;
	    }
   
    function user($xid){
	    $sql="SELECT id,name,nc,pass,sex,site_u,xid FROM user WHERE id='{$xid}' AND site_u='{$this->wapname}'";
            $logininfo=mysql_query($sql);
            if($logininfo && mysql_num_rows($logininfo)>0){
            list($id,$name,$nc,$pass,$sex,$site_u,$xid) = mysql_fetch_row($logininfo);
	        }else{
			$nc='查无此人！';
			}
	    return $nc;
		}
	function pl($login){
	    if($login==1){
		    $z=' 
			<form  method="post" action="content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'&">
           <input type="text" name="htext" value="马上回复"
		   style="width:70%;float:left;"
		   />
           <input type="hidden" name="toid" value="'.$hid.'"/>
           <input type="hidden" name="id" value="'.$_GET['id'].'"/>
           <input type="hidden" name="action" value="post2"/>
           <input type="submit" value="评论" 
		        style="color:#222;background-color:#efefef;line-height:30px;width:29%;"/>
           </form>';
		    }else{
			$z='登录后发表评论!';
		    }
			return $z;
		}
	function huifunums(){
		$sql = "SELECT count(*) FROM bbscomm WHERE siteid='{$this->wapid}' AND gro='{$this->gro}'";   
	    $result = mysql_query($sql); 
	    list($nums) = mysql_fetch_row($result);
		return $nums;
		}
	function huifu_info($hid,$ser){
        $sql="SELECT hid,{$ser} FROM bbsComm WHERE hid='{$hid}'";  
        $result = mysql_query($sql);      
	    list($hid,$ser) = mysql_fetch_row($result);
		return $ser;
   }
    function huifulist(){
	if(PX == 1){
		$order = 'DESC';
	}else{
		$order = 'ASC';
	}
        $sql="SELECT hid,userid,htext,touserid,siteid,gro,time FROM bbscomm WHERE siteid='{$this->wapid}' AND gro='{$this->gro}' ORDER BY hid {$order} LIMIT {$this->start},{$this->limit}";  
        $result = mysql_query($sql);    
		$maxnum = mysql_num_rows($result);
	    if($result && $maxnum>0){
		$i=$this->start+1;
	    while(list($hid,$userid,$htext,$touserid,$siteid,$gro,$time) = mysql_fetch_row($result)){
	        $sql="SELECT id,name,nc,pass,sex,qianm,head,site_u,xid FROM user WHERE id='{$userid}'" ;
				$logininfo=mysql_query($sql);
				if($logininfo && mysql_num_rows($logininfo)>0){
				list($id,$name,$nc,$pass,$sex,$qm,$head,$site_u,$xid) = mysql_fetch_row($logininfo);
	        }else{
				$htext='<font color="red"><b>【注意】此内容作者已被删除，内容自动屏蔽！</b></font>';
				$nc='用户不存在';
			}
			if(PX == 1){
			$maxnums = mysql_num_rows(mysql_query("SELECT * FROM bbscomm WHERE siteid='{$this->wapid}' AND gro='{$this->gro}';"));
			$pxj = $maxnums + 1 - $i;
				if($pxj==1){
					$rlou = '沙发';
					}elseif($pxj == 2){
					$rlou = '椅子';
					}elseif($pxj == 3){
					$rlou = '板凳';
					}else{
					$rlou = $pxj.'楼';
				}
			}else{
			if($i==1){
			$rlou='沙发';
			}elseif($i == 2){
			$rlou='椅子';
			}elseif($i == 3){
			$rlou='板凳';
			}else{
			$rlou = $i.'楼';
				}
			}
			$zai = u_online($userid,$this->wapid);
				if($zai==1){
				$zai='[在线]';
				}else{
				$zai='[离线]';
	}
	if($touserid==NULL||$touserid=='NULL'){
		$bbs_content = viewStr($htext,9000,$_GET['id']) ;
		   }else{
		   $bbs_content = viewStr($htext,9000,$_GET['id']).'<br>[原文]<a href="http://'.$_SERVER["HTTP_HOST"].'/user/userinfo.php?toid='.user('xid','id',$this->huifu_info($touserid,'userid')).'">'.user('nc','id',$this->huifu_info($touserid,'userid')).'</a>:'.$this->huifu_info($touserid,'htext');
		   }
	$lz = NULL;
	if($userid == USERID){
		$lz = 'style="background:url(http://'.HTTP_HOST.'/style/louzhu.png) no-repeat 100% 0%;"';
	}	   			
	$html .= '<div class="bbs_line">';
	$html .= '<div class="piclz" '.$lz.' >';
	$html .= '<div class="bbs_louzhu">';
    $html .= '<div class="bbs_head"> <img src="'.user('head','id',$userid).'" style="width:35px;height:35px;"></div>';
	$html .= '<div class="bbs_info">';
	$html .= '<div class="bbs_nc">';
	$html .= '<a href="http://'.$_SERVER["HTTP_HOST"].'/user/userinfo.php?toid='.user('xid','id',$userid).'">'.user('nc','id',$userid).'('.user('xid','id',$userid).')</a></div>';
	$html .= '<div class="bbs_time">'.date('Y/m/d H:i:s',$time).'</div>';
	$html .= '</div></div>';
	$html .= '<div class="bbs_content">'.$bbs_content.' </div>';
	$html .= '<div class="bbs_bottom">[签名]'.user('qianm','id',$userid);
	$html .= '</div>';
	$html .= '<div class="bbs_end"><div class="louceng">'.$rlou.'</div><div class="bbs_qianm">'.date('Y/m/d H:i:s',$time).'</div>';
	$html .= '<div class="bbs_h"><a href="http://'.HTTP_HOST.'/bbs/huifuuser.php?cid='.$_GET['cid'].'&id='.$hid.'">回 复</a></div>';
	$html .= '</div>';
	$html .= '</div>';
	$html .= '</div>'; 
		   $i++;
		   
	}
				$huifunums = $this->huifunums();
	        }else{
	    $html = '<div class="bbs_line">
		         还没有人跟帖
		         </div>';
	        }
	return $html;
	    }
	
   }