<?php
/**
* FILE_NAME : singlemanage.php
*
* @copyright Copyright (c) 2009 - 2010 www.dali.edu.cn
* @author DaLi University 2009 Graduation Design
* @package 单页面管理
* @subpackage
* @version Fri Oct 16 09:41:31 GMT 2009
*/

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')
{
	$sql = $query = $singlist = '';
	
	$sql = "SELECT s.id,s.catid,s.title,s.url,s.target,s.displayorder,c.catid,c.name FROM {$dbprefix}singlepage s LEFT JOIN {$dbprefix}singlecategories c ON s.catid = c.catid ORDER BY s.displayorder";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query)) {
		$row['target'] = $row['target'] ? "原窗口" : "新窗口";
		$row['url'] = $row['url'] ? "是" : "否";
		$singlist[] = $row;
	}
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("singlist", $singlist);
	
	$smarty->display("single.html");
}

/*------------------------------------------------------ */
//-- 增加单页
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
	$sql = $query = $singcatelist = '';
	
	/*--  查询分类信息  --*/
	$sql = "SELECT catid,name FROM {$dbprefix}singlecategories";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query)) {
		$singcatelist[] = $row;
	}
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("singcatelist",$singcatelist);
	$smarty->display("single_add.html");
}

/*------------------------------------------------------ */
//-- 增加单页成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'addok')
{
	$sing = $_REQUEST['sing'];
	$sql = $query = $singcatelist = '';
	
	/*--  插入信息  --*/
	$sql = "INSERT INTO {$dbprefix}singlepage (id,catid,title,template,url,target,content,displayorder) VALUE ('','".$sing['catid']."','".$sing['title']."','".$sing['template']."','".$sing['url']."','".$sing['target']."','".$sing['content']."','".$sing['displayorder']."')";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("单页添加成功","single.php?act=show");
	} else {
		showmsg("单页添加失败","single.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 编辑单页
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
	$id = $_REQUEST['id'];
	
	$sql = $query = $row = '';
	$singcatelist = $list = array();
	
	/*--  查询分类信息  --*/
	$sql = "SELECT catid,name FROM {$dbprefix}singlecategories";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query)) {
		$singcatelist[] = $row;
	}
	
	$sql = "SELECT * FROM {$dbprefix}singlepage WHERE id = $id";
	$query = $DB->query($sql);
	$list = $DB->fetch_array($query);
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("sing_id",$list['id']);
	$smarty->assign("sing_catid",$list['catid']);
	$smarty->assign("sing_title",$list['title']);
	$smarty->assign("sing_tpl",$list['template']);
	$smarty->assign("sing_url",$list['url']);
	$smarty->assign("sing_target",$list['target']);
	$smarty->assign("sing_cont",$list['content']);
	$smarty->assign("sing_disp",$list['displayorder']);
	
	$smarty->assign("singcatelist",$singcatelist);
	
	$smarty->display("single_edit.html");
}

/*------------------------------------------------------ */
//-- 编辑单页成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'editok')
{
	$sing = $_REQUEST['sing'];
	$sql = $query = $singcatelist = '';
	
	/*--  修改信息  --*/
	$sql = "UPDATE {$dbprefix}singlepage SET catid = '".$sing['catid']."',title = '".$sing['title']."',template = '".$sing['template']."',url = '".$sing['url']."',target = '".$sing['target']."',content = '".$sing['content']."',displayorder = '".$sing['displayorder']."' WHERE id = '".$sing['id']."'";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("单页修改成功","single.php?act=show");
	} else {
		showmsg("单页修改失败","single.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 删除单页
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove')
{
	$id = $_REQUEST['id'];
	$sql = $query = $singcatelist = '';
	
	/*--  删除信息  --*/
	$sql = "DELETE FROM {$dbprefix}singlepage WHERE id = $id";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("单页删除成功","single.php?act=show");
	} else {
		showmsg("单页删除失败","single.php?act=show");
	}
}
?>