<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[16]!=1)
  jump("jump.php?id=25&jump=main.php");
//执行删贴
if(isset($_GET['action']) and $_GET['action']=="del")
{
  //批量删除GET转POST
  if(isset($_GET['theme']))
  {
    $_POST['theme']=$_GET['theme'];
	$_POST['author']=$_GET['author'];
	$_POST['mubiao']=$_GET['mubiao'];
  }
  else
    $_GET['page']=0;
  //关键字不为空
  if($_POST['theme']!="" and $_POST['mubiao']=="1")
  {
    $where="theme like '%".$_POST['theme']."%' and state != 0";
    if($_POST['author']!="")
      $where=$where."and author='".$_POST['author']."'";
	$where=$where." limit 100";
  }
  elseif($_POST['theme']!="" and $_POST['mubiao']=="2")
  {
    $where="content like '%".$_POST['theme']."%' and state != 0";
    if($_POST['author']!="")
      $where=$where."and author='".$_POST['author']."'";
	$where=$where." limit 100";
  }
  //关键字为空
  elseif($_POST['author']!="")
    $where="author='".$_POST['author']."' and state != 0 limit 100";
  //不执行
  else
    jump("jump.php?id=24&jump=batch.php");
  //主题ID
  if($_POST['mubiao']=="1")
    $phpcolor->table="topic";
  elseif($_POST['mubiao']=="2")
    $phpcolor->table="repost";
  $phpcolor->field="id";
  $phpcolor->where=$where;
  $rs=$phpcolor->assignment();
  $phpcolor->field="state = 0";
  $phpcolor->upgrade();
  for($count=0;$count<count($rs);$count++)
  {
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $phpcolor->table="recover";
    $phpcolor->field="tid, operate, operatetime, ip, type";
    $phpcolor->where="'".$rs[$count]['id']."', '".$_COOKIE["core_user_name"]."','".$time."','".$_SERVER['REMOTE_ADDR']."' , '".$_POST['mubiao']."'";
    $phpcolor->write();
	if($_POST['mubiao']=="1")
	{
      $phpcolor->table="repost";
	  $phpcolor->field="state='4'";
	  $phpcolor->where="belong = '".$rs[$count]['id']."' and state!='0'";
      $phpcolor->upgrade();
	}
  }
  if(count($rs)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=batch.php?action=del=and=page=".($_GET['page']+1)."=and=theme=".$_POST['theme']."=and=mubiao=".$_POST['mubiao']."=and=author=".$_POST['author']);
  jump("jump.php?id=24&jump=batch.php");
}
elseif(isset($_GET['action']) and $_GET['action']=="bardel")
{
  //批量删除GET转POST
  if(isset($_GET['barname']))
  {
    $_POST['barname']=$_GET['barname'];
  }
  else
    $_GET['page']=0;
  //关键字不为空
  if($_POST['barname']=="")
    jump("jump.php?id=24&jump=batch.php");
  //找出吧ID
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname='".$_POST['barname']."'";
  $bar=$phpcolor->exist(1);
  //删除主题
  $phpcolor->table="topic";
  $phpcolor->field="id";
  $phpcolor->where="belong='".$bar['id']."' limit 100";
  $rs=$phpcolor->assignment();
  $phpcolor->field="state = 0";
  $phpcolor->upgrade();
  for($count=0;$count<count($rs);$count++)
  {
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $phpcolor->table="recover";
    $phpcolor->field="tid, operate, operatetime, ip, type";
    $phpcolor->where="'".$rs[$count]['id']."', '".$_COOKIE["core_user_name"]."','".$time."','".$_SERVER['REMOTE_ADDR']."' , '1'";
    $phpcolor->write();
  }
  if(count($rs)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=batch.php?action=bardel=and=page=".($_GET['page']+1)."=and=barname=".$_POST['barname']);
  jump("jump.php?id=24&jump=batch.php");
}
elseif(isset($_GET['action']) and $_GET['action']=="barmerge")
{
  //关键字不为空
  if($_POST['barname']=="" or $_POST['barnames']=="")
    jump("jump.php?id=24&jump=batch.php");
  //找出被合并吧ID
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname='".$_POST['barname']."'";
  $bar=$phpcolor->exist(1);
  //找出目标吧ID
  $phpcolor->where="barname='".$_POST['barnames']."'";
  $bars=$phpcolor->exist(1);
  //移动主题
  $phpcolor->table="topic";
  $phpcolor->field="belong='".$bars['id']."'";
  $phpcolor->where="belong='".$bar['id']."'";
  $phpcolor->upgrade();
  //删除贴吧
  $phpcolor->table="bar";
  $phpcolor->where="id = '".$bar['id']."'";
  $phpcolor->delete();
  $phpcolor->table="bar_user";
  $phpcolor->where="bid = '".$bar['id']."'";
  $phpcolor->delete();
  $phpcolor->table="barmaudit";
  $phpcolor->where="bid = '".$bar['id']."'";
  $phpcolor->delete();
  $phpcolor->table="bar_domain";
  $phpcolor->where="bid = '".$bar['id']."'";
  $phpcolor->delete();
  $phpcolor->table="bar_nav";
  $phpcolor->where="belong = '".$bar['id']."'";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=batch.php");
}
$tpl -> display("batch.htm");
?>