<?php

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

//GET中是否有id参数
if(isset($_GET['id'])){
	//过滤参数，待完善
	$EditId = addslashes($_GET['id']);
	//是否提交表单
	if($AdminLogin->IsPost(array('RadioGroup1', 'NickName', 'QQ', 'Phone', 'Mail', 'SecretOptions', 'MessageContentText', 'EditInputKey'), 'EditButton')){
		if($AdminLogin->CheckHttpReferer('{'.WEB_URL.'/index.php\?action=edit&id=[1-9]\d*}', 1) == true){
			//验证方法
			$AdminLogin->CheckPostFun = array(
					'RadioGroup1' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('check_zzs', 'strlen_only_one', 'CheckNull')),
					'NickName' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('strlen_nickname', 'CheckNull')),
					'QQ' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), 'check_qqnum'),
					'Phone' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), 'CheckPhone'),
					'Mail' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), 'CheckMail'),
					'SecretOptions' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckSecretOptions', 'CheckNull')),
					'MessageContentText' => array(array('ToUtf8', 'ContentHtmlToStr', 'addslashes_d'), 'CheckNull'),
					'EditInputKey' => array(array('ToUtf8', 'trimall', 'DeleteHtml', 'strip_tags'), array('CheckPostInputKey', 'CheckNull'))
			);
			//验证数据
			if($AdminLogin->CheckPostValue()){
				//过滤后的用户提交的数据
				$UserPostValue = $AdminLogin->Post;
				//判断InputKey
				if($AdminLogin->CheckValue($UserPostValue['EditInputKey'], $_SESSION['EditInputKey'])){
					//判断QQ号码是否必填
					if($UserPostValue['RadioGroup1'] == 7){
						if($UserPostValue['QQ'] == ''){
							ShowMessage("您填写的内容不符合要求！", 2, "", "", WEB_URL.'/index.php', 1);
							exit();
						}
					}
					//连接到MYSQL并打开系统数据库
					$DataBase->open_db();
					//更新留言
					if($DataBase->up('message', "`content` = '".$UserPostValue['MessageContentText']."', `avatar` = '".$UserPostValue['RadioGroup1']."', `nickname` = '".$UserPostValue['NickName']."', `qq` = '".$UserPostValue['QQ']."', `mobile` = '".$UserPostValue['Phone']."', `email` = '".$UserPostValue['Mail']."', `secret` = '".SecretOptions($UserPostValue['SecretOptions'], 'secret')."', `privacy` = '".SecretOptions($UserPostValue['SecretOptions'], 'privacy')."'", "WHERE `id` = '$EditId'")){
						ShowMessage("留言编辑成功！", 1, "", "", WEB_URL.'/index.php', 1);	//编辑成功
					}
					else{
						ShowMessage("更新失败！请检查原因！", 2, "", "", WEB_URL.'/index.php', 1);	//更新语句执行失败
					}
					//关闭数据库连接
					$DataBase->close_dblink();
				}
				else{
					ShowMessage("来路不正确！", 2, "", "", WEB_URL.'/index.php', 1); //InputKey验证不通过
				}
			}
			else{
				ShowMessage("提交的数据不合法！", 2, "", "", WEB_URL.'/index.php', 1);	//数据验证不通过
			}
		}
		else{
			ShowMessage("来路不正确！", 2, "", "", WEB_URL.'/index.php', 1);	//来路不正确
		}
		//销毁inputkey确保只能使用一次
		$_SESSION['EditInputKey'] = '';
	}
	else{
		ShowMessage("表单未提交！", 2, "", "", WEB_URL.'/index.php', 1);	//表单未提交
	}
}

?>