<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：admin_single.php
 * 摘　　要：单页面
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS'))exit('access die');
if (!getAdminPri('8102'))exit(NO_AUTH_LOGIN);
$do = trim($_REQUEST['do']);
$tpl -> assign("do",$do);
if(is_post()){
		$data['body'] = filter_site_url_encode(trim($_POST['content']));
		if ($do == 'add' or $do == 'edit') {
			$is_add = $do=='add'?TRUE:FALSE;
			$msg = "操作成功！";
            $data['uptime'] = date("Y-m-d H:i:s");
			if ($do == 'edit') {
				$id = to_int($data['id']);
				unset($data['id']);
				if(empty($id))die($sp -> bgmsg('参数错误！',$_SERVER["HTTP_REFERER"]));
			}
			if(empty($data['title']))die($sp -> bgmsg('页面标题不能为空！',$_SERVER["HTTP_REFERER"]));
			if(empty($data['body']))die($sp -> bgmsg('页面内容不能为空！',$_SERVER["HTTP_REFERER"]));
			if ($do == 'add') {
				$db->insert($data, 'single_page');
			} else {
				if(!$is_add){
					$c = $db->fetch("SELECT * FROM ##__single_page WHERE `id` = '$id'",TRUE);
					if(empty($c))exit($sp->bgmsg('参数错误'));
					if(!empty($data['file_name'])){
						if($data['file_name']!=$c['file_name'] && file_exists(SYS_ROOT.$c['file_name'])){
							@unlink(SYS_ROOT.$c['file_name']);
						}
					}
				}
				$db->update($data, 'single_page', array('id'=>$id));
			}     
			$sp -> bgmsg($msg,'admincp.php?action=single&do=list');
		}
}
switch ($do) {
	case 'add':
		require_once SYS_ROOT.'pub/phpwms.kineditor.php';
		$fck = new editor();
		$fckstr = $fck->create();
		$tpl -> assign("body",$fckstr);
		$tpl -> assign("WMS_stitle",'{$WMS_stitle}');
		$tpl -> assign("WMS_skeywords",'{$WMS_skeywords}');
		$tpl -> assign("WMS_sdescription",'{$WMS_sdescription}');
		$tpl -> assign("WMS_sbody",'{$WMS_sbody}');
		$pn  = '添加单页面';
		break;
	case 'edit':
		require_once '../pub/phpwms.kineditor.php';
		$id = to_int($_GET['id']);
		if(empty($id))die($sp -> bgmsg('参数错误！',$_SERVER["HTTP_REFERER"]));
		$sql = 'SELECT * FROM ##__single_page WHERE id = '.$id;
		$re  = $db -> sql_query($sql);
		$farr = $db -> sql_fetchrowset($re);
		$tpl -> assign("farr",$farr);
		$fck = new editor();
		$fck->value = filter_site_url_decode($farr['0']['body']);
		$body = $fck->create();
		$tpl -> assign("body",$body);
		$tpl -> assign("WMS_stitle",'{$WMS_stitle}');
		$tpl -> assign("WMS_skeywords",'{$WMS_skeywords}');
		$tpl -> assign("WMS_sdescription",'{$WMS_sdescription}');
		$tpl -> assign("WMS_sbody",'{$WMS_sbody}');
		$db -> sql_freeresult($re);
		$db -> sql_close();
		$pn  = '编辑单页面';
		break;
	case 'delete':
		$id = to_int($_GET['id']);
		if(empty($id))$sp->bgmsg('无可用数据.');
		$c = $db->fetch("SELECT * FROM ##__single_page WHERE `id` = '$id' ",TRUE);
		if(empty($c))$sp->bgmsg('无可用数据.');
		@unlink(SYS_ROOT.$c['file_name']);
		$sql = 'DELETE FROM ##__single_page WHERE id = '.$id;
		$re  = $db -> query($sql);
		$sp->bgmsg('操作成功');
		break;
	default:		
		$pn  = '单页面列表';
		$sql = 'SELECT * FROM ##__single_page';
		$page = new ShowPage;
		$page->PageSize = 20;
		$page->Total = $db -> getCount($sql);
		$page->LinkAry = array();
		$showpage = $page->ShowLink();
		$farr = $db -> fetch($sql." limit  ".$page->OffSet());
		$tpl -> assign("farr",$farr);
		$tpl -> assign("show_page",$showpage);
}
$tpl -> assign("admin_nav",shownav($pn));
$sp  -> outPut('single_page.tpl',$pn);
?>