<?php

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

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

//是否提交
if($AdminLogin->IsPost(array('SMTPSERVER', 'SMTPSERVERPORT', 'SMTPUSERMAIL', 'SMTPUSER', 'SMTPPASS', 'USESSL', 'MAILTYPE', 'REPLY_EMAIL', 'CUSTOM_REPLY', 'CUSTOM_CONTENT', 'MailInputKey'), 'SaveSiteInfo')){
	//来路判断
	if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=mail') == true){
		//验证方法
		$AdminLogin->CheckPostFun = array(
				'SMTPSERVER' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckSmtpServer')),
				'SMTPSERVERPORT' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckSmtpPort')),
				'SMTPUSERMAIL' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckMail')),
				'SMTPUSER' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckMail')),
				'SMTPPASS' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags', 'trimall'), 'CheckOK'),
				'USESSL' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'MAILTYPE' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckMailtype')),
				'REPLY_EMAIL' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'CUSTOM_REPLY' => array(array('ToUtf8', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'strlen_only_one', 'only_z_or_o')),
				'CUSTOM_CONTENT' => array(array('ToUtf8', 'ContentHtmlToStr', 'addslashes_d'), 'CheckOK'),
				'MailInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckNull', 'CheckPostInputKey'))
		);
		//验证数据
		if($AdminLogin->CheckPostValue()){
			//过滤后的用户提交的数据
			$UserPostValue = $AdminLogin->Post;
			//判断InputKey
			if($AdminLogin->CheckValue($UserPostValue['MailInputKey'], $_SESSION['MailInputKey'])){
				//删除用户提交的InputKey
				unset($UserPostValue['MailInputKey']);
				//处理SSL选项
				if(in_array('1', $UserPostValue['USESSL'])){
					$UserPostValue['USESSL'] = '1';
				}
				else{
					$UserPostValue['USESSL'] = '0';
				}			
				//连接到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=mail', 1);
				}
				else{
					$AdminShowMessage = AdminShowMessage('更新失败！请检查原因！', WEB_URL.'/admin/index.php?location=mail', 0, '#F00');
				}
				//关闭数据库连接
				$DataBase->close_dblink();
			}
			else{
				$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=mail', 0, '#F00');	//InputKey不正确
			}
		}
		else{
			$AdminShowMessage = AdminShowMessage('您提交的数据不合法！', WEB_URL.'/admin/index.php?location=mail', 0, '#F00');	//验证不通过
		}
	}
	else{
		$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=mail', 0, '#F00');	//来路不正确
	}
	//销毁inputkey确保只能使用一次
	$_SESSION['MailInputKey'] = '';
}
else{
	$AdminShowMessage = AdminShowMessage('提交失败！', WEB_URL.'/admin/index.php?location=mail', 0, '#F00');	//表单未提交
}

?>