<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[27]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="index";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->delete();
  jump("jump.php?id=24&jump=indexpost.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['yid']=="")
    jump("jump.php?id=2&jump=indexpost.php?action=add");
  $phpcolor->table="topic";
  $phpcolor->field="theme,belong";
  $phpcolor->where="id = '".$_POST['yid']."'";
  $rss=$phpcolor->exist(1);
  if($_POST['theme']=="")
    $_POST['theme']=$rss['theme'];
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id = '".$rss['belong']."'";
  if(!$rs=$phpcolor->exist(1))
    jump("jump.php?id=7&jump=indexpost.php?action=add");
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="type, yid, belong, theme, barname";
  $phpcolor->where="'1','".$_POST['yid']."','".$_POST['belong']."', '".$_POST['theme']."', '".$rs['barname']."'";
  $phpcolor->write();
  jump("jump.php?id=24&jump=indexpost.php");
}
if(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['yid']=="")
    jump("jump.php?id=2&jump=indexpost.php?action=edit=and=id=".$_GET['id']);
  $phpcolor->table="topic";
  $phpcolor->field="theme,belong";
  $phpcolor->where="id = '".$_POST['yid']."'";
  $rss=$phpcolor->exist(1);
  if($_POST['theme']=="")
    $_POST['theme']=$rss['theme'];
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id = '".$rss['belong']."'";
  if(!$rs=$phpcolor->exist(1))
	jump("jump.php?id=7&jump=indexpost.php?action=add");
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="type='1',yid='".$_POST['yid']."',belong='".$_POST['belong']."',theme='".$_POST['theme']."',barname='".$rs['barname']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=indexpost.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
{
  $phpcolor->table="class";
  $phpcolor->field="id,classname";
  $phpcolor->where="base = 0 and indexs = 1 order by belong";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> display("indexpost_add.htm");
}
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $indexpost=$phpcolor->exist(1);
  $phpcolor->table="class";
  $phpcolor->field="id,classname";
  $phpcolor->where="base = 0 and indexs = 1 order by belong";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> assign("indexpost", $indexpost);
  $tpl -> display("indexpost_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  if(isset($_GET['so']))
  {
    $phpcolor->field="*";
    $phpcolor->where="type=1 and theme like '%".$_GET['so']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=1 and theme like '%".$_GET['so']."%' order by id desc limit ".($_GET['page']*20).",20";
    $indexpost=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexpost','&so=',$_GET['so'],'0');
  }
  else
  {
    $phpcolor->field="*";
    $phpcolor->where="type=1";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=1 order by id desc limit ".($_GET['page']*20).",20";
    $indexpost=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexpost','','','0');
  }
  for($count=0;$count<count($indexpost);$count++)
  {
    $phpcolor->table="class";
    $phpcolor->field="classname";
    $phpcolor->where="id = '".$indexpost[$count]['belong']."'";
    $rs=$phpcolor->exist(1);
	$indexpost[$count]['belongn']=$rs['classname'];
  }
  $tpl -> assign("indexpost", $indexpost);
  $tpl -> assign("page", $page);
  $tpl -> display("indexpost.htm");
}
?>