<?php	
define('IN_OUN', true);
include_once( "includes/command.php");

if(!empty($Aconf['priveMessage'])) {
   echo showMessage($Aconf['priveMessage']);
   exit;
}

if ( $_SESSION[$un_aaction_list] != 'all' and empty($_SESSION[$un_aarticlecat_list])) {
   echo showMessage("文章分类权限没有指定，不能查阅文章列表，请与管理员联系");
   exit;  
}

//发帖统计
/* 查询条件 */

$where = "states=0 AND domain_id = '".$_SESSION[$un_domain_id]."'";  
if(!empty($_REQUEST['start_time'])) {
	$_REQUEST['start_time'] = $_REQUEST['start_time'];
	$_REQUEST['end_time'] = $_REQUEST['end_time'];
    $start_time = local_strtotime($_REQUEST['start_time']." 00:00:01");
    $end_time   = local_strtotime($_REQUEST['end_time']."  23:59:59");
	$where .= " AND dateadd >= '".$start_time."' AND dateadd <= '".$end_time."'";
} 
if(!empty($_REQUEST['end_time'])) {
	$end_time   = local_strtotime($_REQUEST['end_time']."  23:59:59");
}else{
	$end_time   = time();
}

$StrtypeAll ='';
$db_table = $pre."artitxt";
$sql = "SELECT user_id FROM ".$db_table." WHERE 1 AND ". $where." group by user_id";
$row_usr_id = $oPub->select($sql);
if($row_usr_id) {
   $n = 0 ;
   foreach ($row_usr_id AS $key=>$val) {
	     $user_id = $val["user_id"];
	     $where2 = ' AND user_id='.$val["user_id"];
		 $db_table = $pre."artitxt";
         $sql = "SELECT COUNT(*) as count,sum(hots) as sum_hots,sum(support) as sum_support,sum(against) as sum_against,sum(comms) as sum_comms FROM ".$db_table." WHERE ". $where.$where2;
		 
         $row = $oPub->getRow($sql);

         $Asum["sum_count"]   = $row["count"];
         $Asum["sum_hots"]    = $row["sum_hots"];
         $Asum["sum_support"] = $row["sum_support"];
         $Asum["sum_against"] = $row["sum_against"];
         $Asum["sum_sa"]      = $row["sum_support"] + $row["sum_against"];
         $Asum["sum_comms"]   = $row["sum_comms"];

         $sql = "SELECT b.my_name 
	       FROM ".$pre."admin_userbase  as b   
		   WHERE  b.user_id = '".$user_id."'";
         $user_name = $oPub->getOne($sql);
		 if(!empty($user_name)) {
             $sql = "SELECT b.user_name 
	           FROM ".$pre."admin_user   as b   
		       WHERE  b.user_id = '".$user_id."'";
             $user_name = $oPub->getOne($sql);
		 } 

	     $tmpstr = ($n % 2 == 0)?"even":"odd";
	     $n ++ ;
         $StrtypeAll .= '<TR class='.$tmpstr.'>';
		 $StrtypeAll .= '<TD align=left>';
	     $StrtypeAll .= $user_name;
		 $StrtypeAll .= '</TD>';
		 $StrtypeAll .= '<TD align=left>';
	     $StrtypeAll .= $Asum["sum_count"];
		 $StrtypeAll .= '</TD>';

	     $StrtypeAll .= '<TD align=left>';
         $StrtypeAll .=$Asum["sum_hots"] ;
	     $StrtypeAll .= '</TD>';
	     $tmp = $Asum["sum_support"] + $Asum["sum_against"];
	     $StrtypeAll .= '<TD align=left>';

         $StrtypeAll .=$Asum["sum_support"];
	     $StrtypeAll .= '+';

         $StrtypeAll .=$Asum["sum_against"];
	     $StrtypeAll .= '=';
	     $StrtypeAll .= $tmp;
	     $StrtypeAll .= '</TD>';
	     $StrtypeAll .= '<TD align=left>'. $Asum["sum_comms"].'</TD>'; 
   } 
} 
?>
<?php
   include_once( "header.php");
?>
<?php
if (!empty($strMessage)) echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>'; 
?>
<script src="js/calendar/calendar.js"  type="text/javascript" ></script>
<link href="js/calendar/calendar.css" rel="stylesheet" type="text/css">

<TABLE width="100%" border=0>

  <TR class=bg1>
    <TD align=left colspan="7">
	<FORM METHOD=POST ACTION="" style="margin: 0px">
        开始日期
		<input name="start_time" id="start_time" style="width:68px;" value="<?php echo !empty($start_time)?date("Y-m-d",$start_time):'';?>" readonly="readonly" type="text">
		<input name="selbtn1" id="selbtn1" onclick="return showCalendar('start_time', '%Y-%m-%d', false, false, 'selbtn1');" value="选择"  type="button" >

        结束日期<input name="end_time" id="end_time" style="width:68px" value="<?php echo !empty($end_time)?date("Y-m-d",$end_time):date("Y-m-d");?>" readonly="readonly" type="text">
		<input name="selbtn2" id="selbtn2" onclick="return showCalendar('end_time', '%Y-%m-%d', false, false, 'selbtn2');" value="选择" type="button" >
        <INPUT TYPE="submit" name="submit" value="确定查询">
		<INPUT TYPE="hidden" name="act" value="datesearch">
		<INPUT TYPE="hidden" name="action" value="">
       </span>
	   </FORM>
	</TD> 
  </TR>

  <TR class=bg5>
    <TD width="25%" align=left>姓名/账号</TD>
	<TD width="11%" align=left>总发帖量</TD>
	<TD width="11%" align=left> pv</TD>
	<TD width="10%" align=left>
    顶+踩=合计
	</TD>
	<TD width="4%" align=left>
    评论
    </TD>
  </TR>

 <?php echo $StrtypeAll;?>

 </table>
<SCRIPT src="../js/ajax.js" type="text/javascript"></SCRIPT>
<script type="text/javascript" language="JavaScript">

<?php
include_once( "footer.php");
?>