<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[21]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="block";
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "unblock")
{
  $phpcolor->where="id='".$_GET['id']."'";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=block.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  $phpcolor->table="user";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$_POST['bkusername']."'";
  if(!$phpcolor->exist(2) and !is_ip($_POST['bkusername']))
    jump("jump.php?id=1&jump=block.php?action=add");
  if($_POST['yuanyin']=="0")
  {
	$_POST['yuanyin']=$_POST['yuanyinb'];
	if($_POST['yuanyin']=="")
      jump("jump.php?id=2&jump=block.php?action=add");
  }
  $blocktime=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $removetime=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+($_POST['hour']+$core_time)*3600);
  $jssj=$removetime;
  if($_POST['hour']=="0")
  {
    $removetime="0000-00-00 00:00:00"; 
	$jssj="ÓÀ¾Ã·âËø";
  }
  $phpcolor->table="block";
  $phpcolor->field="username, blocktime, removetime, operate, yuanyin";
  $phpcolor->where="'".$_POST['bkusername']."','".$blocktime."','".$removetime."','".$_COOKIE['core_user_name']."', '".$_POST['yuanyin']."'";
  $phpcolor->write();
  if($email_mopen==1)
  {
	$email_fsyhc=str_replace("{jssj}",$jssj,$email_fsyhc);
    $email_fsyhc=str_replace("{fsfw}","È«Õ¾±»·âËø",$email_fsyhc);
	$email_fsyhc=str_replace("{fsyy}",$_POST['yuanyin'],$email_fsyhc);
	$phpcolor->message($email_fsyhc,$email_addresser,$_POST['bkusername'],$blocktime,2);
  }
  jump("jump.php?id=24&jump=block.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
{
  $tpl -> assign("un", $_GET['un']);
  $tpl -> display("block_add.htm");
}
else
{
  $blocktime = date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->table="block";
  $phpcolor->where="removetime < '".$blocktime."' and removetime!='0000-00-00 00:00:00'";
  $phpcolor->delete();
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['username']))
  {
    $phpcolor->where="username like '%".$_GET['username']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="username like '%".$_GET['username']."%' limit ".($_GET['page']*30).",30";
    $page=pages($count,30,$_GET['page'],'block','&username=',$_GET['username'],'0');
  }
  else
  {
    $phpcolor->where="1=1";
    $count = $phpcolor->exist(2);
    $phpcolor->where="1=1 limit ".($_GET['page']*30).",30";
    $page=pages($count,30,$_GET['page'],'block','','','0');
  }
  $block=$phpcolor->assignment();
  for($count=0;$count<count($block);$count++)
  {
    $phpcolor->table="bar";
    $phpcolor->field="barname";
    $phpcolor->where="id='".$block[$count]['barid']."'";
    $rs=$phpcolor->exist(1);
    $block[$count]['barname'] = $rs['barname'];
  }
  $tpl -> assign("block", $block);
  $tpl -> assign("page", $page);
  $tpl -> display("block.htm");
}
?>