<?php

//禁止直接访问
!defined('IN_SYSTEM') && exit('Access Denied');

if(!isset($_POST['ANNOUNCEMENT'])){
	$_POST['ANNOUNCEMENT'] = '';
}

//是否提交
if($AdminLogin->IsPost(array('ANNOUNCEMENT', 'AnnouncementInputKey'), 'SaveSiteInfo')){
	//来路判断
	if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=announcement') == true){
		//验证方法
		$AdminLogin->CheckPostFun = array(
				'ANNOUNCEMENT' => array(array('ToUtf8', 'ContentHtmlToStr', 'addslashes_d'), 'CheckOK'),
				'AnnouncementInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckPostInputKey', 'CheckNull'))
		);
		//验证数据
		if($AdminLogin->CheckPostValue()){
			//过滤后的用户提交的数据
			$UserPostValue = $AdminLogin->Post;
			//判断InputKey
			if($AdminLogin->CheckValue($UserPostValue['AnnouncementInputKey'], $_SESSION['AnnouncementInputKey'])){
				//删除用户提交的InputKey
				unset($UserPostValue['AnnouncementInputKey']);
				//连接到MYSQL并打开系统数据库
				$DataBase->open_db();
				$return = true;
				//更新系统设置项
				foreach($UserPostValue as $k => $v){
					if($DataBase->up('setting', "`value` = '".$v."'", "WHERE `name` = '".$k."'") == false){
						$return = false;
					}
				}
				if($return == true){
					$AdminShowMessage = AdminShowMessage('系统公告更新成功！', WEB_URL.'/admin/index.php?location=announcement', 1);
				}
				else{
					$AdminShowMessage = AdminShowMessage('更新失败！请检查原因！', WEB_URL.'/admin/index.php?location=announcement', 0, '#F00');
				}
				//关闭数据库连接
				$DataBase->close_dblink();
			}
			else{
				$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=announcement', 0, '#F00');	//InputKey不正确
			}
		}
		else{
			$AdminShowMessage = AdminShowMessage('您提交的数据不合法！', WEB_URL.'/admin/index.php?location=announcement', 0, '#F00');	//验证不通过
		}
	}
	else{
		$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=announcement', 0, '#F00');	//来路不正确
	}
	//销毁inputkey确保只能使用一次
	$_SESSION['AnnouncementInputKey'] = '';
}
else{
	$AdminShowMessage = AdminShowMessage('提交失败！', WEB_URL.'/admin/index.php?location=announcement', 0, '#F00');	//表单未提交
}

?>