<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[21]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."block";
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "unblock")
{
  $phpcolor->where="id='".$_GET['id']."'";
  $phpcolor->delete();
  Header("Location: jump.php?id=24&jump=block.php");
}
elseif(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$_POST['username']."'";
  if(!$phpcolor->exist(2) and !is_ip($_POST['username']))
    Header("Location: jump.php?id=1&jump=block.php?action=add");
  else
  {
    $blocktime=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
    if($_POST['hour']=="0")
      $removetime="0000-00-00 00:00:00";
    else
      $removetime=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+($_POST['hour']+$core_time)*60*60);
    $phpcolor->table=$core_mysql_prefix."block";
    $phpcolor->field="username, blocktime, removetime, operate";
    $phpcolor->where="'".$_POST['username']."','".$blocktime."','".$removetime."','".$_COOKIE['core_user_name']."'";
    $phpcolor->write();
    Header("Location: jump.php?id=24&jump=block.php");
  }
}
elseif(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("block_add.htm");
else
{
  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']*20).",20";
    $page=pages($count,20,$_GET['page'],'block','&username=',$_GET['username'],'0');
  }
  else
  {
    $phpcolor->where="1=1";
    $count = $phpcolor->exist(2);
    $phpcolor->where="1=1 limit ".($_GET['page']*20).",20";
    $page=pages($count,20,$_GET['page'],'block','','','0');
  }
  $block=$phpcolor->assignment();
  for($count=0;$count<count($block);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."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");
}
?>