<?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_notice.php
 * 摘　　要：公告管理
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS'))exit('access die');
if (!getAdminPri('8108'))exit(NO_AUTH_LOGIN);
$do = trim($_REQUEST['do']);
$data = $_POST['data'];
$tpl->assign('do',$do);
switch($do){
	case "edit":
		$notice_id = abs(intval($_GET['noticeid']));
		$url = '?action=notice&page=' . $_GET['page'];
		if(empty($notice_id)){
			$sp->bgmsg('请您正确选择要编辑的公告',$url);
		}
		
		$sql = "SELECT * FROM ##__notice WHERE `id` = $notice_id order by id limit 0,1";
		$result = $db->fetch($sql, true);
		if(empty($result)){
			$sp->bgmsg('没有你要的数据，请您重新选择',$url);
		}
		$tpl->assign('result',$result);
		$pn = '编辑公告';
	case "add":
		$pn = empty($pn) ? '添加下载' : $pn;
		require_once '../pub/phpwms.kineditor.php';
		$fck = new editor();
		$fck->value = filter_site_url_decode($result['content']);
		$body = $fck->create();
		$tpl->assign('body', $body);
		$tpl->assign('curpage', $_GET['page']);
		break;
	case "oper":
		$notice_id = $_POST['noticeid'];
		$url = empty($notice_id) ? '?action=notice_add&do=add' : '?action=notice_add&do=edit&noticeid=' . $notice_id;
		$url = $url . '&page=' . $_GET['page'];
		if(empty($data['title'])){
			$sp->bgmsg('标题不能为空', $url);
		}
		$data['content'] = filter_site_url_encode($_POST['content']);
		if(empty($data['content'])){
			$sp->bgmsg('内容不能为空', $url);
		}
		if(empty($notice_id)){
			$data['post_time'] = date("Y-m-d H:i:s");
			/*添加*/
			$msg = $db->insert($data, 'notice') ? '添加成功' : '添加失败';
		}else{
			$msg = $db->update($data, 'notice', array('id'=>$notice_id)) ? '修改成功' : '修改失败';
		}
		php188StaticCache::getInstance()->remove('phpwms_notice');
		$sp->bgmsg($msg, '?action=notice&page=' . $_GET['page']);
		break;
	case 'del':
		$id = $_REQUEST['noticeid'];
		if(is_array($id)){
			$ids = array_filter($id);
			$id = '';
			foreach($ids as $v){
				$id .=  abs(intval($v)) . ',';
			}
			$id = substr($id, 0, strlen($id) - 1);
		}else{
			$id = abs(intval($id));
		}
		if(empty($id)){
			$sp->bgmsg('请选择正确的广告位', '?action=notice&page=' . $_GET['page']);
		}
		$sql = "DELETE FROM ##__notice WHERE `id` IN ($id)";
		$mes = $db->query($sql) ? '删除成功' : '删除失败';
		php188StaticCache::getInstance()->remove('phpwms_notice');
		$sp->bgmsg($mes, '?action=notice&page=' . $_GET['page']);
		break;
	default:
		$pn  = '公告管理';
		$tpl -> assign("admin_nav",shownav($pn));
		$channel_type = intval($_REQUEST['channel_type']);
		$channel_type?$condition='WHERE channel_type = '.$channel_type.' ':$condition='';
		$sql = "SELECT COUNT(*) AS count FROM ##__notice";
		$count = $db->fetch($sql, true);
		$count = $count['count'];
		$sql = "SELECT * FROM ##__notice ORDER BY post_time DESC";
		$result = page_for_db_extend($count, $sql,'?action=notice', 15);
		$tpl -> assign("data",$result['data']);
		$tpl -> assign("show_page",$result['page']);
		$tpl->assign('curpage', $result['curpage']);
		break;
}
$tpl -> assign("admin_nav",shownav($pn));
$tpl -> display('notice.tpl');

?>