<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[15]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."repost";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del")
{
  if(isset($_GET['id']))
    $_POST['id'][0]=$_GET['id'];
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  for($i=0;$i<count($_POST['id']);$i++)
  {
    $phpcolor->table=$core_mysql_prefix."repost";
    $phpcolor->field="state = 0";
    $phpcolor->where="id = '".$_POST['id'][$i]."'";
    $phpcolor->upgrade();
    $phpcolor->table=$core_mysql_prefix."recover";
    $phpcolor->field="tid, operate, operatetime, ip, type";
    $phpcolor->where="'".$_POST['id'][$i]."', '".$_COOKIE["core_user_name"]."','".$time."','".$_SERVER['REMOTE_ADDR']."' , '2'";
    $phpcolor->write();
  } 
  Header("Location: jump.php?id=24&jump=repost.php");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "edit")
{
  $phpcolor->field="id,content,author,belong,floor,ip";
  $post = $phpcolor->exist(1);
  $phpcolor->table=$core_mysql_prefix."topic";
  $phpcolor->field="theme";
  $phpcolor->where="id = '".$post['belong']."'";
  $topic = $phpcolor->exist(1);
  $post['content'] = str_replace("<br />","",$post['content']);
  $tpl -> assign("post", $post);
  $tpl -> assign("topic", $topic);
  $tpl -> display("repost_edit.htm");
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "editdo")
{
  if(strlen($_POST['content'])<$core_contentshort or strlen($_POST['content'])>$core_contentlong)
    Header("Location: jump.php?id=8&jump=repost.php?action=edit=and=id=".$_GET['id']);
  else
  {
    $_POST['content']=nl2br(html_replace(autolink($_POST['content'])));
    $phpcolor->field="content='".$_POST['content']."'";
    $phpcolor->upgrade();
    Header("Location: jump.php?id=24&jump=repost.php");
  }
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['search']) and isset($_GET['theme']))
  {
    if($_GET['search']==1)
    {
      $phpcolor->where="content like '%".$_GET['theme']."%' and state != '0'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="content like '%".$_GET['theme']."%' and state != '0' order by published desc limit ".($_GET['page']*20).",20";
    }
    else
    {
      $phpcolor->where="author like '%".$_GET['theme']."%' and state != '0'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="author like '%".$_GET['theme']."%' and state != '0' order by published desc limit ".($_GET['page']*20).",20";
    }
    $page=pages($count,20,$_GET['page'],'repost','&theme='.$_GET['theme'].'&search=',$_GET['search'],'0');
  }
  else
  {
    $phpcolor->where="state != '0'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="state != '0' order by published desc limit ".($_GET['page']*20).",20";
    $page=pages($count,20,$_GET['page'],'repost','','','0');
  }
  $post=$phpcolor->assignment();
  for($count=0;$count<count($post);$count++)
  {
    $post[$count]['content']=str_replace("<br />"," ",$post[$count]['content']);
    $post[$count]['content']=$phpcolor->mysubstr($post[$count]['content'],0,100); 
    $post[$count]['authorip']=is_ip($post[$count]['author']);
  }
  $tpl -> assign("post", $post);
  $tpl -> assign("page", $page);
  $tpl -> display("repost.htm");
}
?>