<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[8]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="class";
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['classname']=="")
    jump("jump.php?id=2&jump=class.php?action=add");
  else
  {
    if($_POST['queue']=="")
      $_POST['queue']="0";
	if($_POST['belong']!="0")
	  $_POST['base']="1";
	$_POST['introduction']=autolink($_POST['introduction']);
    $phpcolor->field="classname, belong, introduction, queue, base, indexs";
    $phpcolor->where="'".$_POST['classname']."', '".$_POST['belong']."', '".$_POST['introduction']."', '".$_POST['queue']."', '".$_POST['base']."', '".$_POST['indexs']."'";
    $phpcolor->write();
    jump("jump.php?id=24&jump=class.php");
  }
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "del")
{
  $phpcolor->field="*";
  $phpcolor->where="belong = '".$_GET['id']."'";
  if($phpcolor->exist(2))
    jump("jump.php?id=3&jump=class.php");
  $phpcolor->table="bar";
  $phpcolor->field="barclass='0'";
  $phpcolor->where="barclass = '".$_GET['id']."'";
  $phpcolor->upgrade();
  $phpcolor->table="class";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=class.php");
}
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "editdo")
{
  if($_POST['classname']=="")
    jump("jump.php?id=2&jump=class.php?action=edit=and=id=".$_GET['id']);
  $_POST['introduction']=autolink($_POST['introduction']);
  $phpcolor->field="classname='".$_POST['classname']."', belong='".$_POST['belong']."', introduction='".$_POST['introduction']."', queue='".$_POST['queue']."', base='".$_POST['base']."', indexs='".$_POST['indexs']."'";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=class.php");
}
if(!isset($_GET['page']))
  $_GET['page']=0;
$phpcolor->field="id,classname,belong,queue,base,indexs";
$phpcolor->where="belong = 0 order by queue";
$sort=$phpcolor->assignment();
for ($count=0;$count<count($sort);$count++)
{ 
  $phpcolor->where="belong = ".$sort[$count]['id']." order by queue";
  $ssort[$count]=$phpcolor->assignment();
}
$tpl -> assign("sort", $sort);
$tpl -> assign("ssort", $ssort);
if(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "edit")
{
  $phpcolor->field="*";
  $phpcolor->where="id = '".$_GET['id']."'";
  $tsort=$phpcolor->exist(1);
  $tpl -> assign("tsort", $tsort);
  $tpl -> display("class_edit.htm");
}
elseif(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("class_add.htm");
else
{
  $phpcolor->field="*";
  $phpcolor->where="1=1";
  $count=$phpcolor->exist(2);
  $tpl -> assign("count", $count);
  $tpl -> display("class.htm");
}
?>