<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[17]!=1)
  jump("jump.php?id=25&jump=main.php");
$time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
$time=strtotime($time)-259200;
$time=date("Y-m-d H:i:s", $time);
$phpcolor->table="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="topic";
    $phpcolor->field="vote";
    $phpcolor->where="id='".$_POST['id'][$i]."'";
    $post=$phpcolor->exist(1);
    $phpcolor->delete();
    $phpcolor->table="repost";
    $phpcolor->where="belong='".$_POST['id'][$i]."'";
    $phpcolor->delete();
    if($post['vote']=="1")
    {
      $phpcolor->table="vote";
      $phpcolor->where="tid='".$_POST['id'][$i]."'";
      $phpcolor->delete();
    }
    $phpcolor->table="recover";
    $phpcolor->where="tid='".$_POST['id'][$i]."' and type='1'";
    $phpcolor->delete();
  }
  jump("jump.php?id=24&jump=recover.php?type=topic");
}
if(isset($_GET['action']) and $_GET['action'] == "alldelt")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="recover";
  $phpcolor->field="*";
  $phpcolor->where="type='1' and operatetime<'".$time."' limit 100";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table="topic";
	$phpcolor->field="vote";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $topic=$phpcolor->exist(1);
    $phpcolor->delete();
	$phpcolor->table="repost";
    $phpcolor->where="belong='".$post[$count]['tid']."'";
    $phpcolor->delete();
	if($topic['vote']=="1")
    {
      $phpcolor->table="vote";
      $phpcolor->where="tid='".$post[$count]['tid']."'";
      $phpcolor->delete();
    }
  }
  if(count($post)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=recover.php?action=alldelt=and=page=".($_GET['page']+1)."");
  jump("jump.php?id=24&jump=recover.php?type=topic");
}
if(isset($_GET['action']) and $_GET['action'] == "alldelts")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="recover";
  $phpcolor->field="*";
  $phpcolor->where="type='1' limit 100";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table="topic";
	$phpcolor->field="vote";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $topic=$phpcolor->exist(1);
    $phpcolor->delete();
	$phpcolor->table="repost";
    $phpcolor->where="belong='".$post[$count]['tid']."'";
    $phpcolor->delete();
	if($topic['vote']=="1")
    {
      $phpcolor->table="vote";
      $phpcolor->where="tid='".$post[$count]['tid']."'";
      $phpcolor->delete();
    }
  }
  if(count($post)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=recover.php?action=alldelts=and=page=".($_GET['page']+1)."");
  jump("jump.php?id=24&jump=recover.php?type=topic");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "recovert")
{
  $phpcolor->field="state='1'";
  $phpcolor->upgrade();
  $phpcolor->table="recover";
  $phpcolor->where="tid='".$_GET['id']."' and type='1'";
  $phpcolor->delete();
  $phpcolor->table="repost";
  $phpcolor->field="state='1'";
  $phpcolor->where="belong = '".$_GET['id']."' and state='4'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=recover.php?type=topic");
}
if(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="repost";
    $phpcolor->where="id='".$_POST['id'][$i]."'";
    $phpcolor->delete();
    $phpcolor->table="recover";
    $phpcolor->where="tid='".$_POST['id'][$i]."' and type='2'";
    $phpcolor->delete();
  }
  jump("jump.php?id=24&jump=recover.php?type=repost");
}
if(isset($_GET['action']) and $_GET['action'] == "alldelr")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="recover";
  $phpcolor->field="*";
  $phpcolor->where="type='2' and operatetime<'".$time."' limit 100";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table="repost";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $phpcolor->delete();
  }
  if(count($post)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=recover.php?action=alldelr=and=page=".($_GET['page']+1)."");
  jump("jump.php?id=24&jump=recover.php?type=repost");
}
if(isset($_GET['action']) and $_GET['action'] == "alldelrs")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="recover";
  $phpcolor->field="*";
  $phpcolor->where="type='2' limit 100";
  $post=$phpcolor->assignment();
  $phpcolor->delete();
  for ($count=0;$count<count($post);$count++)
  {
    $phpcolor->table="repost";
    $phpcolor->where="id='".$post[$count]['tid']."'";
    $phpcolor->delete();
  }
  if(count($post)!=0)
    jump("jump.php?page=".($_GET['page']+1)."&id=26&jump=recover.php?action=alldelrs=and=page=".($_GET['page']+1)."");
  jump("jump.php?id=24&jump=recover.php?type=repost");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "recoverr")
{
  $phpcolor->table="repost";
  $phpcolor->field="state='1'";
  $phpcolor->upgrade();
  $phpcolor->table="recover";
  $phpcolor->where="tid='".$_GET['id']."' and type='2'";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=recover.php?type=repost");
}
if(isset($_GET['type']) and $_GET['type'] == "repost")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="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']*30).",30";
  $page=pages($count,30,$_GET['page'],'recover','&type=','repost','0');
  $post=$phpcolor->assignment();
  $phpcolor->table="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="topic";
	$phpcolor->field="id,theme,content,author,published";
  }
  else
  {
    $phpcolor->table="repost";
    $phpcolor->field="id,content,author,published,belong";
  }
  $phpcolor->where="id = '".$_GET['id']."'";
  $post = $phpcolor->exist(1);
  if($_GET['action']=="showr")
  {
    $phpcolor->table="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']*30).",30";
  }
  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']*30).",30";
  }
  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']*30).",30";
  }
  $page=pages($count,30,$_GET['page'],'recover','&type=','topic','0');
  $post=$phpcolor->assignment();
  for($count=0;$count<count($post);$count++)
  {
    $phpcolor->table="recover";
    $phpcolor->field="*";
    $phpcolor->where="tid='".$post[$count]['id']."' and type='1'";
    $rs = $phpcolor->exist(1);
    $phpcolor->table="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");
}
?>