<?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=indexhead.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['yid']=="")
    jump("jump.php?id=2&jump=indexhead.php?action=add");
  $phpcolor->table="topic";
  $phpcolor->field="theme";
  $phpcolor->where="id = '".$_POST['yid']."'";
  $rss=$phpcolor->exist(1);
  if($_POST['theme']=="")
    $_POST['theme']=$rss['theme'];
  $phpcolor->table="index";
  $phpcolor->field="type, yid, belong, theme, barname";
  $phpcolor->where="'4','".$_POST['yid']."','".$_POST['belong']."', '".$_POST['theme']."', ''";
  $phpcolor->write();
  jump("jump.php?id=24&jump=indexhead.php");
}
if(isset($_GET['action']) and $_GET['action'] == "xiaxian" and isset($_GET['id']))
{
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="barname='1'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=indexhead.php");
}
if(isset($_GET['action']) and $_GET['action'] == "shangxian" and isset($_GET['id']))
{
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="barname=''";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=indexhead.php");
}
if(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['yid']=="")
    jump("jump.php?id=2&jump=indexhead.php?action=edit=and=id=".$_GET['id']);
  $phpcolor->table="topic";
  $phpcolor->field="theme";
  $phpcolor->where="id = '".$_POST['yid']."'";
  $rss=$phpcolor->exist(1);
  if($_POST['theme']=="")
    $_POST['theme']=$rss['theme'];
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="type='4',yid='".$_POST['yid']."',belong='".$_POST['belong']."',theme='".$_POST['theme']."',barname=''";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=indexhead.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
{
  $phpcolor->table="index";
  $phpcolor->field="id,yid,theme";
  $phpcolor->where="type = 4 and belong = 0 and barname='' order by id desc";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> display("indexhead_add.htm");
}
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $indexhead=$phpcolor->exist(1);
  $phpcolor->table="index";
  $phpcolor->field="id,yid,theme";
  $phpcolor->where="type = 4 and belong = 0 and barname='' order by id desc";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> assign("indexhead", $indexhead);
  $tpl -> display("indexhead_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  if(isset($_GET['so']))
  {
    $phpcolor->field="*";
    $phpcolor->where="type=4 and theme like '%".$_GET['so']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=4 and theme like '%".$_GET['so']."%' order by id desc limit ".($_GET['page']*20).",20";
    $indexhead=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexhead','&so=',$_GET['so'],'0');
  }
  else
  {
    $phpcolor->field="*";
    $phpcolor->where="type=4";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=4 order by id desc limit ".($_GET['page']*20).",20";
    $indexhead=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexhead','','','0');
  }
  for($count=0;$count<count($indexhead);$count++)
  {
    $phpcolor->table="topic";
    $phpcolor->field="theme";
    $phpcolor->where="id = '".$indexhead[$count]['belong']."'";
    if($rs=$phpcolor->exist(1))
	  $indexhead[$count]['belongt']=$rs['theme'];
	else
	  $indexhead[$count]['belongt']="¶¥¼¶Í·Ìõ";
  }
  $tpl -> assign("indexhead", $indexhead);
  $tpl -> assign("page", $page);
  $tpl -> display("indexhead.htm");
}
?>