<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[8]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."class";
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['classname']=="")
    Header("Location: 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']=html_replace(autolink($_POST['introduction']));
    $phpcolor->field="classname, belong, keyword, description, introduction, queue, base";
    $phpcolor->where="'".$_POST['classname']."', '".$_POST['belong']."', '".$_POST['keyword']."', '".$_POST['description']."', '".$_POST['introduction']."', '".$_POST['queue']."', '".$_POST['base']."'";
    $phpcolor->write();
    Header("Location: jump.php?id=24&jump=class.php");
  }
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "del")
{
  $phpcolor->field="*";
  $phpcolor->where="belong = '".$_GET['id']."'";
  if($phpcolor->exist(2))
    Header("Location: jump.php?id=3&jump=class.php");
  else
  {
    if($_POST['belong']!="0")
	  $_POST['base']="1";
    $phpcolor->table=$core_mysql_prefix."bar";
    $phpcolor->field="barclass='0'";
    $phpcolor->where="barclass = '".$_GET['id']."'";
    $phpcolor->upgrade();
    $phpcolor->table=$core_mysql_prefix."class";
    $phpcolor->where="id = '".$_GET['id']."'";
    $phpcolor->delete();
    Header("Location: jump.php?id=24&jump=class.php");
  }
}
elseif(isset($_GET['action']) and isset($_GET['id']) and $_GET['action'] == "editdo")
{
  if($_POST['classname']=="")
    Header("Location: jump.php?id=2&jump=class.php?action=edit=and=id=".$_GET['id']);
  else
  {
    $_POST['introduction']=html_replace(autolink($_POST['introduction']));
    $phpcolor->field="classname='".$_POST['classname']."', belong='".$_POST['belong']."', keyword='".$_POST['keyword']."', description='".$_POST['description']."', introduction='".$_POST['introduction']."', queue='".$_POST['queue']."', base='".$_POST['base']."'";
    $phpcolor->where="id = '".$_GET['id']."'";
    $phpcolor->upgrade();
    Header("Location: jump.php?id=24&jump=class.php");
  }
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="id,classname,belong,queue,base";
  $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
    $tpl -> display("class.htm");
}
?>