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

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

/*------------------------------------------------------ */
//-- 批量删除文章记录
/*------------------------------------------------------ */

if ($action == 'del')
{	
	if(!isset($_GET['log_id'])) $_GET['log_id']=false; 
	$_GET['log_id'] = $_GET['log_id'] + 0;
    if (isset($_POST['checkboxes']))
    {
        $count = 0;		
        foreach ($_POST['checkboxes'] AS $key => $id)
        {	 
           $condition = "log_id='".$id."' AND domain_id='$_SESSION[$un_domain_id]'";
           $oPub->delete($pre."account_log",$condition);
        }
		$tmpID = implode(",",$_POST['checkboxes']);
        $strMessage =  "批量删除成功!";
   }
   else if(isset($_GET['log_id']))
   {
        $id = $_GET['log_id'];
	   $condition = "log_id='".$id."' AND domain_id='$_SESSION[$un_domain_id]'";
	   $oPub->delete($pre."account_log",$condition); 
		$tmpID = $id; 
		$strMessage =  "删除成功!";
   }
   else
   {
      $strMessage =  "没有选择需要删除的信息!";
	  $tmpID = 0;
   }

   $db_table = $pre.'account_log';
   $change_desc = real_ip().' |  '.date("m月d日 h:i").' |  domain_id:'.$_SESSION[$un_domain_id];
   $change_desc .= ' | '.$_SESSION[$un_auser_name].' 日志删除:'.$tmpID;
   $Afields=array('user_id'=>$_SESSION[$un_auser_id] ,'type'=>'artiDel','change_desc'=>$change_desc,'states'=>1,'domain_id'=>$_SESSION[$un_domain_id]);
   $oPub->install($db_table,$Afields);
}

/* 查询条件 */
if(!isset($_REQUEST["acid"])) $_REQUEST["acid"]=false; 
if(!isset($filter['sort_by'])) $filter['sort_by']=false; 
$_REQUEST["acid"] = $_REQUEST["acid"] +0;
$db_table = $pre."account_log";
$where = "states=0 AND domain_id = '".$_SESSION[$un_domain_id]."'";

$sql = "SELECT COUNT(*) as count FROM ".$db_table." AS a WHERE 1 AND ". $where;
$row = $oPub->getRow($sql);
$filter['record_count'] = $row["count"];
unset($row);
$page = new ShowPage;
$page->PageSize = 20;
$page->Total = $filter['record_count'];
$pagenew = $page->PageNum();
$page->LinkAry = array('acid'=>$_REQUEST["acid"],'sort_by'=>$filter['sort_by']); 
$strOffSet = $page->OffSet();

$sql = "SELECT * FROM ".$db_table.
       " WHERE  $where ".
       " ORDER BY log_id DESC
         LIMIT ". $strOffSet;
$row = $oPub->select($sql);
$StrtypeAll = '';
$n = 0;
if($row)
foreach ($row AS $key=>$val)
{
	   $tmpstr = ($n % 2 == 0)?"even":"odd";
	   $n ++ ;
       $StrtypeAll .= '<TR class='.$tmpstr.'>';
	   $StrtypeAll .= '<TD align=left>';
	   $StrtypeAll .= '<input type="checkbox" name="checkboxes['.$val["log_id"].']" value="'.$val["log_id"].'" />';
	   $StrtypeAll .= '</TD>';

	   $db_table = $pre.'admin_user';
	   $sql = "SELECT user_name FROM ". $db_table ."  where user_id= ".$val["user_id"];
	   $rowuser_name = $oPub->getRow($sql);

	   $StrtypeAll .= '<TD align=left>'.$rowuser_name["user_name"].'</TD>';

       $StrtypeAll .= '<TD align=left>'.$val["type"].'</TD>';

	   $StrtypeAll .= '<TD align=left>'.$val["change_desc"].'</TD>';
       $StrtypeAll .= '<TD align=center>';
	   $StrtypeAll .= '<a href="'.$PHP_SELF.'?log_id='.$val["log_id"].'&action=del&page='.$pagenew.'"><IMG SRC="images/b_drop.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="删除"></a>';
       $StrtypeAll .= '</TD></TR>';    
} 
?>
<?php
include_once( "header.php");
if (!empty($strMessage)) echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>'; 
?>
	
<TABLE width="100%" border=0>
<form method="POST" action="<?php echo $PHP_SELF;?>" name="listForm" target="_self">
  <TR class=bg5>
    <TD width="5%" align=left>序号</TD>
    <TD width="10%" align=left>帐号</TD>
	<TD width="10%" align=left>类别</TD>
    <TD width="70%" align=left>内容</TD>
	<TD width="5%" align=center>操作</TD>
  </TR>

 <?php echo $StrtypeAll;?>

  <TR class=bg5>
    <TD  align=right colspan="5">
	<span style="float: left">
	全选删除:<input onclick=selectAll() type="checkbox" name="check_all"/>
	<INPUT TYPE="submit" name="submit" value="确认删除" style="background-color: #FF9900">
	<INPUT TYPE="reset" name="reset" value="恢复" style="background-color: #CCFF99"> 
	<INPUT TYPE="hidden" name="action" value="del"> 
    </span>
	<span style="float: right">
	<?php echo $showpage = $page->ShowLink();?>
	</span>
	</TD>
  </TR>
  </form>
 </table>
<script type="text/javascript" language="JavaScript">

function selectAll(){
	xx = listForm.check_all.checked
	for(var i=0;i<listForm.length;i++)
	{
		if(listForm.elements[i].type=="checkbox")
			listForm.elements[i].checked=xx;
	}
}

</script>

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