<?php
//huifu_list.php

require "../headfun.php";

require "../include/page.inc.php";
//操作函数
    function view_info($wapid,$str){
         $sql="SELECT bbsid,{$str} FROM bbs WHERE bbsid='{$_GET['id']}' AND siteid={$wapid}";
         $view = mysql_query($sql);
          if($view && mysql_num_rows($view)>0){
          list($bbsid,$str) = mysql_fetch_row($view);
         }else{
         $str="抱歉 内容获取失败";
            }
			return $str;
    }
    function user($xid,$shibie,$str,$wapname){
	    $sql="SELECT site_u,{$shibie},{$str} FROM user WHERE {$shibie}='{$xid}' AND site_u='{$wapname}'";
            $result=mysql_query($sql);
            if($result && mysql_num_rows($result)>0){
            list($s1,$s2,$s3) = mysql_fetch_row($result);
	        }else{
			$nc='查无此人！';
			}
	    return $s3;
		}
	function huifunums($wapid,$gro){
		$sql = "SELECT count(*) FROM huifu WHERE siteid='{$wapid}' AND gro='{$gro}'";   
	    $result = mysql_query($sql); 
	    list($nums) = mysql_fetch_row($result);
		return $nums;
		}
	function huifu_info($hid,$ser){
        $sql="SELECT hid,{$ser} FROM huifu WHERE hid='{$hid}'";  
        $result = mysql_query($sql);      
	    list($hid,$ser) = mysql_fetch_row($result);
		return $ser;
   }
    function huifulist($wapid,$gro,$start,$limit,$sid_info){
        $sql="SELECT hid,userid,htext,touserid,siteid,gro FROM huifu WHERE siteid='{$wapid}' AND gro='{$gro}' ORDER BY hid DESC LIMIT {$start},{$limit}";  
        $result = mysql_query($sql);      
	    if($result && mysql_num_rows($result)>0){
		$i=0;
	    while(list($hid,$userid,$htext,$touserid,$siteid,$gro) = mysql_fetch_row($result)){
		     $sql="SELECT id,name FROM user WHERE id='{$wapid}'";
                 $result2=mysql_query($sql);
                 if($result && mysql_num_rows($result)>0){
                 list($wap2id,$wapname) = mysql_fetch_row($result2);
	                  $nc = user($userid,'xid','nc',$wapname);
			}
			if($touserid==NULL||$touserid=='NULL'){
		  $html.= '
		   <table class="huifu_line" border="0" cellpadding="0" cellspacing="0" >
		     <tr>
		      <td class="huifu_line_left" valign="top">
			  <img src="'.user($userid,'xid','head',$wapname).'">
			  </td>
			     <td class="huifu_line_right" valign="top">
				    <a href="http://'.$_SERVER["HTTP_HOST"].'/user/zone.php?toid='.$userid.'&">'.$nc.'</a>[<a href="#">+加好友</a>|<a href="#">顶部</a>]<br>
			          '.$htext.'
					  <br>[<a href="huifuuser.php?cid='.$_GET['cid'].'&id='.$hid.'&to='.$xid.'&sid='.$_GET['sid'].'">回复TA</a>]
	                </td>
				</tr>
		   </table>';
		   }else{
		   $html.= '
		   <table class="huifu_line" border="0" cellpadding="0" cellspacing="0" >
		     <tr>
		      <td class="huifu_line_left" valign="top">
			  <img src="'.user($userid,'xid','head',$wapname).'">
			  </td>
			     <td class="huifu_line_right" valign="top">
				    <a href="http://'.$_SERVER["HTTP_HOST"].'/user/zone.php?toid='.$userid.'&">'.$nc.'</a>回复<a href="http://'.$_SERVER["HTTP_HOST"].'/user/zone.php?toid='.huifu_info($touserid,'userid').'&">'.user(huifu_info($touserid,'userid')).'</a>[<a href="#">+加好友</a>|<a href="#">顶部</a>]<br>
			          '.$htext.'<br>[原文]'.huifu_info($touserid,'htext').'
					  <br>[<a href="huifuuser.php?cid='.$_GET['cid'].'&id='.$hid.'&to='.$xid.'&sid='.$_GET['sid'].'">回复TA</a>]
	                </td>
				</tr>
		   </table>';
		   }
		   $i++;
	            }
				mysql_free_result($result);
	        }else{
	    $html = '<div class="tip">
		         还没有人发表评论哦！赶快抢占沙发吧！
		         </div>';
	        }
	return $html;
	}
//获取当前页
function pagedq($type){
   $page=$_GET[$type];
    if($page<=0){
	  $page=1;
	  }
	  return $page;
   }
//开始的记录数
$start=(pagedq('p')-1)*12;
//输出
echo head_info($ver,'回复列表',$css,NULL);
echo '<body>';
echo UBB($wap_top,$wapid);
echo '<div class="nav_top"><a href="content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'&">返回</a></div>';
echo '<div class="subtitle">《<a href="content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'&">'.view_info($wapid,'title').'</a>》['.huifunums($wapid,$_GET['id']).'回]</div>';
echo huifulist($wapid,$_GET['id'],$start,12,$sid_info);
$url='huifu_list.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'&page='.$_GET['page'].'&';
$listnum = 10;
echo '<div class="mylink">'.page(huifunums($wapid,$_GET['id']),12,$url,'p','NO').'</div>';
echo UBB($wap_bottom,$wapid);
echo '</body></html>';
?>