<?php

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

//是否提交
if($AdminLogin->IsPost(array('SITE_NAME', 'WEB_URL', 'AUTHORIZATION_CODE', 'SITE_TPL', 'SITE_LOGO', 'ADMIN_EMAIL', 'NEW_POST', 'MESSAGE_CHECK', 'ORDER', 'EDIT', 'SELECTEDIT', 'DELETEMODE', 'AVATAR_USABLE', 'ICP_ID', 'STAT_CODE', 'SiteinfoInputKey'), 'SaveSiteInfo')){
	//来路判断
	if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=siteinfo') == true){
		//验证方法
		$AdminLogin->CheckPostFun = array(
				'SITE_NAME' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), 'CheckOK'),
				'WEB_URL' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckURL')),
				'AUTHORIZATION_CODE' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckAuthorizationCode')),
				'SITE_TPL' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckSitetpl')),
				'SITE_LOGO' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckOK', 'CheckLogoUrl')),
				'ADMIN_EMAIL' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckOK', 'CheckMail')),
				'NEW_POST' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'MESSAGE_CHECK' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'only_z_or_o')),
				'ORDER' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckOrder')),
				'EDIT' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'SELECTEDIT' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckSelEdit')),
				'DELETEMODE' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'AVATAR_USABLE' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'ICP_ID' =>	array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckIcpId')),
				'STAT_CODE' => array(array('ToUtf8', 'addslashes_d'), array('CheckOK')),
				'SiteinfoInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckPostInputKey'))
		);
		//验证数据
		if($AdminLogin->CheckPostValue()){
			//过滤后的用户提交的数据
			$UserPostValue = $AdminLogin->Post;
			//判断InputKey
			if($AdminLogin->CheckValue($UserPostValue['SiteinfoInputKey'], $_SESSION['SiteinfoInputKey'])){
				//删除用户提交的InputKey
				unset($UserPostValue['InputKey']);		
				//连接到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=siteinfo', 1);
				}
				else{
					$AdminShowMessage = AdminShowMessage('更新失败！请检查原因！', WEB_URL.'/admin/index.php?location=siteinfo', 0, '#F00');
				}
				//关闭数据库连接
				$DataBase->close_dblink();								
			}
			else{
				$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=siteinfo', 0, '#F00');	//InputKey不正确
			}
		}
		else{
			$AdminShowMessage = AdminShowMessage('您提交的数据不合法！', WEB_URL.'/admin/index.php?location=siteinfo', 0, '#F00');	//验证不通过
		}
	}
	else{
		$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=siteinfo', 0, '#F00');	//来路不正确
	}
	//销毁inputkey确保只能使用一次
	$_SESSION['SiteinfoInputKey'] = '';
}
else{
	$AdminShowMessage = AdminShowMessage('提交失败！', WEB_URL.'/admin/index.php?location=siteinfo', 0, '#F00');	//表单未提交
}

?>