<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[15]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="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*3600);
  for($i=0;$i<count($_POST['id']);$i++)
  {
    $phpcolor->table="repost";
    $phpcolor->field="state = 0";
    $phpcolor->where="id = '".$_POST['id'][$i]."'";
    $phpcolor->upgrade();
    $phpcolor->table="recover";
    $phpcolor->field="tid, operate, operatetime, ip, type";
    $phpcolor->where="'".$_POST['id'][$i]."', '".$_COOKIE["core_user_name"]."','".$time."','".$_SERVER['REMOTE_ADDR']."' , '2'";
    $phpcolor->write();
  } 
  jump("jump.php?id=24&jump=repost.php");
}
if(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="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)
    jump("jump.php?id=8&jump=repost.php?action=edit=and=id=".$_GET['id']);
  $_POST['content']=nl2br(autolink($_POST['content']));
  $phpcolor->field="content='".$_POST['content']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=repost.php");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  if(isset($_GET['so']) and isset($_GET['theme']))
  {
    if($_GET['so']==1)
    {
      $phpcolor->where="content like '%".$_GET['theme']."%' and state = '1'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="content like '%".$_GET['theme']."%' and state = '1' order by published desc limit ".($_GET['page']*20).",20";
    }
    else
    {
      $phpcolor->where="author like '%".$_GET['theme']."%' and state = '1'";
      $count = $phpcolor->exist(2);
      $phpcolor->where="author like '%".$_GET['theme']."%' and state = '1' order by published desc limit ".($_GET['page']*20).",20";
    }
    $page=pages($count,20,$_GET['page'],'repost','&theme='.$_GET['theme'].'&so=',$_GET['so'],'0');
  }
  else
  {
    $phpcolor->where="state = '1'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="state = '1' 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']);
	$phpcolor->table="topic";
    $phpcolor->field="theme";
    $phpcolor->where="id = '".$post[$count]['belong']."'";
    $topic = $phpcolor->exist(1);
	$post[$count]['topic']=$topic['theme'];
  }
  $tpl -> assign("post", $post);
  $tpl -> assign("page", $page);
  $tpl -> display("repost.htm");
}
?>