<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[17]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
$time=strtotime($time)-259200;
$time=date("Y-m-d H:i:s", $time);
$phpcolor->table=$core_mysql_prefix."topic";
$phpcolor->where="id='".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "delt")
{
  if(isset($_GET['id']))
    $_POST['id'][0]=$_GET['id'];
  for($i=0;$i<count($_POST['id']);$i++)
  {
    $phpcolor->table=$core_mysql_prefix."topic";
    $phpcolor->field="vote";
    $phpcolor->where="id='".$_POST['id'][$i]."'";
    $post=$phpcolor->exist(1);
    $phpcolor->delete();
    $phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->where="belong='".$_POST['id'][$i]."'";
    $phpcolor->delete();
    if($post['vote']=="1")
    {
      $phpcolor->table=$core_mysql_prefix."vote";
      $phpcolor->where="tid='".$_POST['id'][$i]."'";
      $phpcolor->delete();
    }
    $phpcolor->table=$core_mysql_prefix."recover";
    $phpcolor->where="tid='".$_POST['id'][$i]."' and type='1'";
    $phpcolor->delete();
  }
  Header("Location: jump.php?id=24&jump=recover.php?type=topic");
}
elseif(isset($_GET['action']) and $_GET['action'] == "alldelt")
{
  $phpcolor->table=$core_mysql_prefix."recover";
  $phpcolor->field="*";
  $phpcolor->where="type='1' and operatetime<'".$time."'";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."topic";
	$phpcolor->field="vote";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $topic=$phpcolor->exist(1);
    $phpcolor->delete();
	$phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->where="belong='".$post[$count]['tid']."'";
    $phpcolor->delete();
	if($topic['vote']=="1")
    {
      $phpcolor->table=$core_mysql_prefix."vote";
      $phpcolor->where="tid='".$post[$count]['tid']."'";
      $phpcolor->delete();
    }
    $phpcolor->table=$core_mysql_prefix."recover";
    $phpcolor->where="tid='".$post[$count]['tid']."' and type='1'";
    $phpcolor->delete();
  }
  Header("Location: jump.php?id=24&jump=recover.php?type=topic");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "recovert")
{
  $phpcolor->field="state='1'";
  $phpcolor->upgrade();
  $phpcolor->table=$core_mysql_prefix."recover";
  $phpcolor->where="tid='".$_GET['id']."' and type='1'";
  $phpcolor->delete();
  Header("Location: jump.php?id=24&jump=recover.php?type=topic");
}
elseif(isset($_GET['action']) and $_GET['action'] == "delr")
{
  if(isset($_GET['id']))
    $_POST['id'][0]=$_GET['id'];
  for($i=0;$i<count($_POST['id']);$i++)
  {
    $phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->where="id='".$_POST['id'][$i]."'";
    $phpcolor->delete();
    $phpcolor->table=$core_mysql_prefix."recover";
    $phpcolor->where="tid='".$_POST['id'][$i]."' and type='2'";
    $phpcolor->delete();
  }
  Header("Location: jump.php?id=24&jump=recover.php?type=repost");
}
elseif(isset($_GET['action']) and $_GET['action'] == "alldelr")
{
  $phpcolor->table=$core_mysql_prefix."recover";
  $phpcolor->where="type='2' and operatetime<'".$time."'";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $phpcolor->delete();
  }
  Header("Location: jump.php?id=24&jump=recover.php?type=repost");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "recoverr")
{
  $phpcolor->table=$core_mysql_prefix."repost";
  $phpcolor->field="state='1'";
  $phpcolor->upgrade();
  $phpcolor->table=$core_mysql_prefix."recover";
  $phpcolor->where="tid='".$_GET['id']."' and type='2'";
  $phpcolor->delete();
  Header("Location: jump.php?id=24&jump=recover.php?type=repost");
}
elseif(isset($_GET['type']) and $_GET['type'] == "repost")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table=$core_mysql_prefix."repost";
  $phpcolor->field="*";
  $phpcolor->where="state='0'";
  $count = $phpcolor->exist(2);
  $phpcolor->field="id,content,author,belong,floor";
  $phpcolor->where="state='0' order by published desc limit ".($_GET['page']*20).",20";
  $page=pages($count,20,$_GET['page'],'recover','&type','repost','0');
  $post=$phpcolor->assignment();
  $phpcolor->table=$core_mysql_prefix."recover";
  $phpcolor->field="*";
  for($count=0;$count<count($post);$count++)
  {
	$phpcolor->where="tid='".$post[$count]['id']."' and type='2'";
    $rs = $phpcolor->exist(1);
    $post[$count]['operate'] = $rs['operate'];
    $post[$count]['operatetime'] = $rs['operatetime'];
    $post[$count]['ip'] = $rs['ip'];
    $post[$count]['authorip']=is_ip($post[$count]['author']);
	$post[$count]['content']=str_replace("<br />"," ",$post[$count]['content']);
	$post[$count]['content']=$phpcolor->mysubstr($post[$count]['content'],0,100); 
  }
  $tpl -> assign("post", $post);
  $tpl -> assign("page", $page);
  $tpl -> display("recover_repost.htm");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and ($_GET['action'] == "showt" or $_GET['action'] == "showr"))
{
  if($_GET['action'] == "showt")
  {
    $phpcolor->table=$core_mysql_prefix."topic";
	$phpcolor->field="id,theme,content,author,published";
  }
  else
  {
    $phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->field="id,content,author,published,belong";
  }
  $phpcolor->where="id = '".$_GET['id']."'";
  $post = $phpcolor->exist(1);
  if($_GET['action']=="showr")
  {
    $phpcolor->table=$core_mysql_prefix."topic";
	$phpcolor->field="theme";
	$phpcolor->where="id = '".$post['belong']."'";
    $rs = $phpcolor->exist(1);
	$post['theme']=$rs['theme'];
  }
  $tpl -> assign("action", $_GET['action']);
  $tpl -> assign("post", $post);
  $tpl -> display("recover_show.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['theme']) and isset($_GET['type']) and $_GET['type']=1)
  {
    $phpcolor->where="state='0' and theme like '%".$_GET['theme']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->field="id,theme,author,belong";
    $phpcolor->where="state='0' and theme like '%".$_GET['theme']."%' order by published desc limit ".($_GET['page']*20).",20";
  }
  elseif(isset($_GET['theme']) and isset($_GET['type']) and $_GET['type']=2)
  {
    $phpcolor->where="state='0' and author like '%".$_GET['theme']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->field="id,theme,author,belong";
    $phpcolor->where="state='0' and author like '%".$_GET['theme']."%' order by published desc limit ".($_GET['page']*20).",20";
  }
  else
  {
    $phpcolor->where="state='0'";
    $count = $phpcolor->exist(2);
    $phpcolor->field="id,theme,author,belong";
    $phpcolor->where="state='0' order by published desc limit ".($_GET['page']*20).",20";
  }
  $page=pages($count,20,$_GET['page'],'recover','&type','topic','0');
  $post=$phpcolor->assignment();
  for($count=0;$count<count($post);$count++)
  {
    $phpcolor->table=$core_mysql_prefix."recover";
    $phpcolor->field="*";
    $phpcolor->where="tid='".$post[$count]['id']."' and type='1'";
    $rs = $phpcolor->exist(1);
    $phpcolor->table=$core_mysql_prefix."bar";
    $phpcolor->field="barname";
    $phpcolor->where="id = '".$post[$count]['belong']."'";
    $rs1 = $phpcolor->exist(1);
    $post[$count]['belongbn'] = $rs1['barname'];
    $post[$count]['operate'] = $rs['operate'];
    $post[$count]['operatetime'] = $rs['operatetime'];
    $post[$count]['ip'] = $rs['ip'];
    $post[$count]['authorip']=is_ip($post[$count]['author']);
  }
  $tpl -> assign("post", $post);
  $tpl -> assign("page", $page);
  $tpl -> display("recover_topic.htm");
}
?>