<?php
/**
* FILE_NAME : single_cate.php
*
* @copyright Copyright (c) www.shuangyulin.com
* @author 双鱼林
* @package 单页分类管理
* @subpackage
* @version QQ:287307421 或 254540457
*/

define('IN_WEB', TRUE);

require_once( str_replace('\\', '/', dirname(__FILE__)). '/include/global.php');

/* act操作项的初始化 */
if (empty($_REQUEST['act'])) {
    $_REQUEST['act'] = 'show';
} else {
    $_REQUEST['act'] = trim($_REQUEST['act']);
}

/*------------------------------------------------------ */
//-- 显示分类
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'show')
{
	$cates = tree("singlecategories",0);
	
	$smarty->assign("cates",$cates);
	$smarty->assign("css_root",$css_root);
	 
	$smarty->display("single_cate.html");
}

/*------------------------------------------------------ */
//-- 删除分类
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove')
{
	$id = $_REQUEST['pid'];
	
	delcate("singlecategories",$id);
	
	if ($query) {
		showmsg("单页分类删除成功","single_cate.php?act=show");
	} else {
		showmsg("单页分类删除失败","single_cate.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 增加分类
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
	$id = $_REQUEST['pid'];
	
	$smarty->assign("pid",$id);
	$smarty->assign("css_root",$css_root);
	 
	$smarty->display("single_cate_add.html");
}

/*------------------------------------------------------ */
//-- 增加分类成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'addok')
{
	$cate = $_REQUEST['cate'];
	
	$sql = $query = '';
	$sql = "INSERT INTO {$dbprefix}singlecategories (catid,parentid,name,note,template,url,displayorder) VALUE ('','".$cate['pid']."','".$cate['name']."','".$cate['note']."','".$cate['template']."','".$cate['url']."','".$cate['displayorder']."')";
	$DB->query($sql);
	
	if ($query) {
		showmsg("单页分类添加成功","single_cate.php?act=show");
	} else {
		showmsg("单页分类添加失败","single_cate.php?act=add");
	}
}

/*------------------------------------------------------ */
//-- 编辑分类
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
	$catid = $_REQUEST['pid'];
	
	/*--  查询数据  --*/
	$sql = '';
	$sql = "SELECT * FROM {$dbprefix}singlecategories WHERE catid = $catid";
	$cate = $DB->fetch_one_array($sql);	
	
	$smarty->assign("css_root",$css_root);
	
	$smarty->assign("catid",$catid);
	$smarty->assign("cate_name",$cate['name']);
	$smarty->assign("cate_parentid",$cate['parentid']);
	$smarty->assign("cate_url",$cate['url']);
	$smarty->assign("cate_template",$cate['template']);
	$smarty->assign("cate_note",$cate['note']);
	$smarty->assign("cate_displayorder",$cate['displayorder']);
	 
	$smarty->display("single_cate_edit.html");
}

/*------------------------------------------------------ */
//-- 编辑分类成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'editok')
{
	$cate = $_REQUEST['cate'];
	
	$sql = '';
	$sql = "UPDATE {$dbprefix}singlecategories SET parentid = '".$cate['parentid']."', name = '".$cate['name']."',url = '".$cate['url']."', template = '".$cate['template']."', note = '".$cate['note']."', displayorder = '".$cate['displayorder']."' WHERE catid = ".$cate['catid'];
	$DB->query($sql);
	
	if ($query) {
		showmsg("单页分类修改成功","single_cate.php?act=show");
	} else {
		showmsg("单页分类修改失败","single_cate.php?act=show");
	}
}
?>