<?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(){
        $sql="SELECT hid,userid,htext,touserid,siteid,gro,time FROM bbscomm WHERE siteid='{$this->wapid}' AND gro='{$this->gro}' ORDER BY hid ASC LIMIT {$this->start},{$this->limit}";  
        $result = mysql_query($sql);      
	    if($result && mysql_num_rows($result)>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($i==1){
			$rlou='<font color="red"><b>[沙发]</b></font>';
			}elseif($i==2){
			$rlou='<font color="green"><b>[椅子]</b></font>';
			}elseif($i==3){
			$rlou='<b>[板凳]</b>';
			}else{
			$rlou='['.$i.'楼]';
			}
			$zai=u_online($userid,$this->wapid);
				if($zai==1){
				$zai='[在线]';
				}else{
				$zai='[离线]';
				}
			if($touserid==NULL||$touserid=='NULL'){
		  $html.= '<div class="bbs">
<table class="bbs_line" border="0" cellpadding="0" cellspacing="0" >
    <tr>
        <td class="top" valign="top">
            <table width="100%">
                <tr>
                    <td width="50px">
                    <!--用户头像 开始-->
                    <img src="'.user('head','id',$userid).'">
                    <!--用户头像 结束-->
                    </td>
                    <td class="bbsuser"  valign="top">
                    <!--详细信息 开始-->
                        <div class="user">
					    <a href="http://'.$_SERVER["HTTP_HOST"].'/user/userinfo.php?toid='.user('xid','id',$userid).'">'.user('nc','id',$userid).'</a>[<a href="http://'.$_SERVER['HTTP_HOST'].'/user/myfriend.php?f='.user('xid','id',$userid).'&type=add">+加好友</a>]
					    </div>
                        <div class="time">'.$time.'</div>
                        <!--详细 结束-->
                        <!--楼层 开始-->
                    </td>
                    <td width="50px" class="lou" valign="top">
                        '.$rlou.'
                        <!--楼层 结束-->
                    </td>
                </tr>
            </table>
</td></tr><tr>
<td class="bottom" valign="top">
<div class="bbs_view">'.viewStr($htext,9000,$_GET['id']).'<br>[<a href="huifuuser.php?cid='.$_GET['cid'].'&id='.$hid.'&to='.$xid.'&sid='.$_GET['sid'].'">回复TA</a>]</div><div class="qianm">[签名]'.$qm.'</div>
</td>
</tr>
</table>
</div>';
		   }else{
		   $html .= '<div class="bbs">
<table class="bbs_line" border="0" cellpadding="0" cellspacing="0" >
    <tr>
        <td class="top" valign="top">
            <table width="100%">
                <tr>
                    <td width="50px">
                    <!--用户头像 开始-->
                    <img src="'.user('head','id',$userid).'">
                    <!--用户头像 结束-->
                    </td>
                    <td class="bbsuser"  valign="top">
                    <!--详细信息 开始-->
                        <div class="user">
					    <a href="http://'.$_SERVER["HTTP_HOST"].'/user/userinfo.php?toid='.user('xid','id',$userid).'&">'.user('nc','id',$userid).'</a>[<a href="http://'.$_SERVER['HTTP_HOST'].'/user/myfriend.php?f='.user('xid','id',$userid).'&type=add">+加好友</a>]
					    </div>
                        <div class="time">'.$time.'</div>
                        <!--详细 结束-->
                        <!--楼层 开始-->
                    </td>
                    <td width="50px" class="lou" valign="top">
                          '.$rlou.'
                        <!--楼层 结束-->
                    </td>
                </tr>
            </table>
</td></tr><tr>
<td class="bottom" valign="top">
<div class="bbs_view">'.viewStr($htext,9000,$_GET['id']).'<br>[原文]'.$this->huifu_info($touserid,'htext').'<br>[<a href="huifuuser.php?cid='.$_GET['cid'].'&id='.$hid.'&to='.$xid.'&sid='.$_GET['sid'].'">回复TA</a>]</div><div class="qianm">[签名]'.$qm.'</div>
</td>
</tr>
</table>
</div>';
		   }
		   $i++;
	            }
				$huifunums = $this->huifunums();
	        }else{
	    $html = '<div class="tip">
		         还没有人跟帖
		         </div>';
	        }
	return $html;
	    }
	
   }
?>