<?php
/**
* FILE_NAME : announcement.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')
{
	$sql = $query = $annolist = '';
	
	$sql = "SELECT * FROM {$dbprefix}announcements ORDER BY displayorder";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query)) {
		$row['postdate'] = formatdate($_CFG['format_type'],$row['postdate']);
		$row['message'] = cutstr($row['message'],50);
		$annolist[] = $row;
	}
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("annolist", $annolist);
	
	$smarty->display("announcement.html");
}

/*------------------------------------------------------ */
//-- 增加公告管理
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
	$sql = $query = '';
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->display("announcement_add.html");
}

/*------------------------------------------------------ */
//-- 增加公告管理成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'addok')
{
	$anno = $_REQUEST['anno'];
	$sql = $query = '';
	
	/*--  插入信息  --*/
	$sql = "INSERT INTO {$dbprefix}announcements (id,title,message,displayorder,postdate)
			VALUE ('','".$anno['title']."','".$anno['message']."','".$anno['displayorder']."','".$timestamp."')";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("公告添加成功","announcement.php?act=show");
	} else {
		showmsg("公告添加失败","announcement.php?act=add");
	}
}

/*------------------------------------------------------ */
//-- 编辑公告管理信息
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
	$id = $_REQUEST['id'];
	
	$sql = $query = $row = '';
	
	/*--  查询信息  --*/
	$sql = "SELECT * FROM {$dbprefix}announcements 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("annoid",$list['id']);
	$smarty->assign("annotitle",$list['title']);
	$smarty->assign("annoorder",$list['displayorder']);
	$smarty->assign("annomessage",$list['message']);
	
	$smarty->display("announcement_edit.html");
}

/*------------------------------------------------------ */
//-- 编辑公告管理成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'editok')
{
	$anno = $_REQUEST['anno'];
	$sql = $query = '';
	
	/*--  修改信息  --*/
	$sql = "UPDATE {$dbprefix}announcements SET title = '".$anno['title']."', displayorder = '".$anno['displayorder']."', message = '".$anno['message']."' WHERE id = '".$anno['id']."'";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("公告修改成功","announcement.php?act=show");
	} else {
		showmsg("公告修改失败","announcement.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 删除公告管理
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove')
{
	$id = $_REQUEST['id'];
	$sql = $query = '';
	
	/*--  删除信息  --*/
	$sql = "DELETE FROM {$dbprefix}announcements WHERE id = $id";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("公告删除成功","announcement.php?act=show");
	} else {
		showmsg("公告删除失败","announcement.php?act=show");
	}
}
?>