<?php
define('THIS_SCRIPT', 'lockip');
include_once 'global.php';
$lang = load_lang($lang,'lockip');
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'28,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $dv,$db,$lang,$action,$reaction;
	if($reaction=="addok"){
		add();
	}
	elseif($reaction=="editok"){
		edit();
	}
include printout('lockip');
}

function add(){
	global $dv,$db,$lang,$ip_address;
	$ip_address=str_replace(" ","",$ip_address);
	if($ip_address==""){
		show_msg($lang['sys.info'],$lang['ip.str1'],0,'','','lockip.php',$lang['comback']);
	exit;	
	}
	/*if( preg_match('/^\|[0-9]{1,3}\.[0-9]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}\|$/i','|'.$ip_address.'|') === false ){
		show_msg($lang['sys.info'],$lang['ip.str4'],0,'','','lockip.php',$lang['comback']);
	exit;
	}*///还要进行数据的比较/匹配;
	else{
		$result=$db->query("select forum_lockip from {$dv}setup");
		$arr=$db->fetch_array($result);
		//$ip_list=explode("|",$arr);
		$tmp=$arr['forum_lockip']."|".$ip_address;
		if($stmt=$db->query("update {$dv}setup set forum_lockip='".$tmp."'")){
			require_once INC_PATH.'BoardCache.class.php';
			$mycache =& new BoardCache($db);
			$mycache->createForumSetting();
			show_msg($lang['sys.info'],$lang['ip.str2'],1,'','','lockip.php',$lang['comback']);
		exit;
		}
		else{
		
			show_msg($lang['sys.info'],$lang['ip.str3'],0,'','','lockip.php',$lang['comback']);
		exit;
		}
	}
}
function edit(){
	global $dv,$db,$lang,$ip_mem;
	if($ip_mem==""){
		show_msg($lang['sys.info'],$lang['suc.info3'],0,'','','lockip.php',$lang['comback']);
	exit;
	}
	else{
		//$result=$db->query("select forum_lockip from {$dv}setup");
		$ip_mem=preg_replace('/\r\n|\n/i',"|",$ip_mem);
		if($result=$db->query("update {$dv}setup set forum_lockip='".$ip_mem."'")){
			require_once INC_PATH.'BoardCache.class.php';
			$mycache =& new BoardCache($db);
			$mycache->createForumSetting();
			show_msg($lang['sys.info'],$lang['ip.str5'],1,'','','lockip.php',$lang['comback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['ip.str3'],0,'','','lockip.php',$lang['comback']);
		exit;
		}
	}
}
?>