<?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=indexbar.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['barname']=="")
    jump("jump.php?id=2&jump=indexbar.php?action=add");
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$_POST['barname']."'";
  if(!$rs=$phpcolor->exist(1))
	jump("jump.php?id=7&jump=indexbar.php?action=add");
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="type, yid, belong, theme, barname";
  $phpcolor->where="'2','".$rs['id']."','".$_POST['belong']."', '', '".$_POST['barname']."'";
  $phpcolor->write();
  jump("jump.php?id=24&jump=indexbar.php");
}
if(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['barname']=="")
    jump("jump.php?id=2&jump=indexbar.php?action=edit=and=id=".$_GET['id']);
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$_POST['barname']."'";
  if(!$rs=$phpcolor->exist(1))
	jump("jump.php?id=7&jump=indexbar.php?action=add");
  $phpcolor->table="index";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->field="type='2',yid='".$rs['id']."',belong='".$_POST['belong']."',theme='',barname='".$_POST['barname']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=indexbar.php");
}
if(isset($_GET['action']) and $_GET['action'] == "add")
{
  $phpcolor->table="class";
  $phpcolor->field="id,classname";
  $phpcolor->where="base = 1 and indexs = 1 order by belong";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> display("indexbar_add.htm");
}
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $indexbar=$phpcolor->exist(1);
  $phpcolor->table="class";
  $phpcolor->field="id,classname";
  $phpcolor->where="base = 1 and indexs = 1 order by belong";
  $sort=$phpcolor->assignment();
  $tpl -> assign("sort", $sort);
  $tpl -> assign("indexbar", $indexbar);
  $tpl -> display("indexbar_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  if(isset($_GET['so']))
  {
    $phpcolor->field="*";
    $phpcolor->where="type=2 and barname like '%".$_GET['so']."%'";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=2 and barname like '%".$_GET['so']."%' order by id desc limit ".($_GET['page']*20).",20";
    $indexbar=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexbar','&so=',$_GET['so'],'0');
  }
  else
  {
    $phpcolor->field="*";
    $phpcolor->where="type=2";
    $count = $phpcolor->exist(2);
    $phpcolor->where="type=2 order by id desc limit ".($_GET['page']*20).",20";
    $indexbar=$phpcolor->assignment();
	$page=pages($count,20,$_GET['page'],'indexbar','','','0');
  }
  for($count=0;$count<count($indexbar);$count++)
  {
    $phpcolor->table="class";
    $phpcolor->field="classname";
    $phpcolor->where="id = '".$indexbar[$count]['belong']."'";
    $rs=$phpcolor->exist(1);
	$indexbar[$count]['belongn']=$rs['classname'];
  }
  $tpl -> assign("indexbar", $indexbar);
  $tpl -> assign("page", $page);
  $tpl -> display("indexbar.htm");
}
?>