#!/usr/bin/perl
# サーバーの環境に合わせて変更して下さい。
require './ore_config.cgi';				# ore_.pl의 패스
#-----------------------------------------------------------#
#  罪と罰++ 二律背反										#
#  관리자 기능												#
#  Copyright(C) 2001-2002 by Vivid Studio. BLANK BOARD		#
#  Vivid Studio.[ http://www17.big.or.jp/~obochan/vivid/ ]	#
#  BLANK BOARD [ http://pom.to/ ]							#
#-----------------------------------------------------------#
$ver	= 'v1.1';				# 버전 정보는 변경 불가
#--- [注意事項] --------------------------------------------#
# 1.このスクリプトは以下の利用規程に従って配布しています。	#
#   http://www24.big.or.jp/~obo/game/ore_/gild/				#
#-----------------------------------------------------------#
# 以下処理 基本的にこれ以下はいじらないように。

&get_time;	# 日時取得
&decode;	# フォームデコード
&axs_check;	# アクセスチェック
&usr_del		if($mode eq 'usr_del');			# キャラ削除
&usr_regist		if($mode eq 'usr_regist');		# キャラデータ変更
&usr_regist2	if($mode eq 'usr_regist2');		# キャラデータ変更2
&cdat_regist	if($mode eq 'cdat_regist');		# 国データ変更
&cdat_regist2	if($mode eq 'cdat_regist2');	# 国データ変更2
&rd_usrdata		if($mode eq 'rd_usrdata');		# $usrdata内ファイル全削除
&rd_backdata	if($mode eq 'rd_backdata');		# $backdata内ファイル全削除
&cdata_reset	if($mode eq 'cdata_reset');		# 国パラメータ初期化
&restore_all_usr if($mode eq 'restore_all_usr');# 全参加者ログ一括復旧(バックアップデータ差し替え)
&restore_person	if($mode eq 'restore_person');	# 個別全参加者ログ復旧(バックアップデータ差し替え)
&restore_cdat	if($mode eq 'restore_cdat');	# 国ログ復旧(バックアップデータ差し替え)
&usr_list;	# キャラリスト表示

exit;

#-------------------------------------------------------------------------------
# キャラリスト表示
sub usr_list{

	&admin_head;

if($comment){
	print <<"EOM";
<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap align="left">$comment</th>
</tr>
</table>
<br>
EOM
}
	print <<EOM;
<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="list_sort" value="$in{'list_sort'}">
<input type="hidden" name="list_view" value="$in{'list_view'}">
<input type="hidden" name="mode" value="usr_del">

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th nowrap colspan=4>정렬</th>
<th nowrap colspan=7>데이터 표시</th>
</tr>
<tr>
<td nowrap><input class="button1" type="button" style="width:20px" value="무" onClick="location.href='$ore_admin?administrator=$in{'administrator'}'"></td>
<td nowrap><input class="button1" type="button" value="레벨" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=4&list_view=$in{'list_view'}'"></td>
<td nowrap><input class="button1" type="button" value="IP 주소" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=15&list_view=$in{'list_view'}'"></td>
<td nowrap><input class="button1" type="button" value="최종 갱신" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=18&list_view=$in{'list_view'}'"></td>

<td nowrap><input class="button1" type="button" value="전체 표시" style="width:80px"onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=-1'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[0]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=-5'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[1]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=1'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[2]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=2'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[3]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=3'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[4]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=4'"></td>
<td nowrap><input class="button1" type="button" value="$cmp[5]" style="width:80px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=5'"></td>
</tr>
</table>
<br>
EOM

	if($in{'list_view'}){

		print <<EOM;
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th nowrap>삭제</th>
<th nowrap>로그인</th>
<th nowrap>편집</th>
<th nowrap>이름</th>
<th nowrap>ID</th>
<th nowrap>비밀번호</th>
<th nowrap>성별</th>
<th nowrap>레벨</th>
<th nowrap>소속</th>
<th nowrap>HP</th>
<th nowrap>MP</th>
<th nowrap>UA</th>
<th nowrap>UD</th>
<th nowrap>LR</th>
<th nowrap>AG</th>
<th nowrap>소지금</th>
<th nowrap>계급</th>
<th nowrap>행동</th>
<th nowrap>최종 로그인</th>
<th nowrap>IP 주소</th>
<th nowrap>호스트명</th>
<th nowrap>브라우저</th>
</tr>
EOM

	# 参加者データファイル一覧取得
	&usrdata_read;

	# 参加者データ一括読み込み
	foreach (0 .. $#usrfile) {
		open(IN,"$usrdata$usrfile[$_]") || &error("Can't open $usrfile[$_]");
		@line = <IN>;
		close(IN);
		push(@dat,$line[0]);
		push(@dat2,$line[1]);
	}

	local(@usr_data);

	foreach (0 .. $#dat){
		%DAT = '';
		my @prats = split(/,/,$dat[$_]);
		foreach (0 .. $#prats){
			my ($key,$v) = split(/;/,$prats[$_]);
			$DAT{$key} = $v;
		}

		my @y1 = split(/<>/,$dat2[$_]);

		$in{'list_view'}=0 if($in{'list_view'}==-5);

		if($in{'list_view'} eq $DAT{'camp'} || $in{'list_view'} eq -1){
			$id = $DAT{'id'};
			# ハッシュ読み込み
			&hash_data;

			push(@usr_data,"$nm<>$id<>$pw<>$sei<>$lv<>$camp<>$max_hp<>$max_mp<>$ua<>$ud<>$lr<>$gold<>$rank<>$sogo<>$y1[0]<>$y1[1]<>$y1[2]<>$y1[3]<>$la<>$ag<>$type<>");
		}
	}

	@usr_data = @{&csvsort('<>',$in{'list_sort'},@usr_data)};

	foreach(0 .. $#usr_data){
		my @y2 = split(/<>/,$usr_data[$_]);

		$y2_0 = (!$y2[13]) ? "$y2[0]" : "$y2[0] [$sogo_p[$y2[13]]]" ;
		$y2[14] ="" if($y2[14] =~ /date/);
		$y2[20] = "대기중" if(!$y2[20]);
		print <<"EOM";
<tr>
<td nowrap><input type="checkbox" name="usr_del"value="$y2[1]"></td>
<td nowrap><input class="button1" type="button" value="로그인" onClick="window.open('$script?id=$y2[1]&pw=$in{'administrator'}')"></td>
<td nowrap><input class="button1" type="button" value="편집" onClick="window.open('$ore_admin?id=$y2[1]&administrator=$in{'administrator'}&mode=usr_regist')"></td>
<td nowrap>$y2_0</td>
<td nowrap>$y2[1]</td>
<td nowrap>$y2[2]</td>
<td nowrap>$seibetu[$y2[3]]</td>
<td nowrap>$y2[4]</td>
<td nowrap>$cmp[$y2[5]]</td>
<td nowrap>$y2[6]</td>
<td nowrap>$y2[7]</td>
<td nowrap>$y2[8]</td>
<td nowrap>$y2[9]</td>
<td nowrap>$y2[10]</td>
<td nowrap>$y2[19]</td>
<td nowrap>$y2[11]</td>
<td nowrap>$cl[$y2[12]]</td>
<td nowrap>$y2[20]</td>
<td nowrap>$y2[14]</td>
<td nowrap>$y2[15]</td>
<td nowrap>$y2[16]</td>
<td nowrap>$y2[17]</td>
</tr>
EOM
		}
	}
	print <<"EOM";
</table>
<br><br>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th nowrap>캐릭터 삭제</th>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<th nowrap>국가 데이터 편집</th>

<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<th nowrap>국가 데이터 리셋</th>

<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<th nowrap colspan="2">Warning!! 디렉터리/데이터 전체 삭제</th>
</tr>
<tr>
<td nowrap align="center"><input class="button1" type="submit" value="캐릭터 삭제" style="width:80px"></td>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td nowrap align="center"><input class="button1" type="button" value="국가 데이터 편집" style="width:80px" onClick="window.open('$ore_admin?administrator=$in{'administrator'}&mode=cdat_regist')"></td>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td nowrap align="center"><input class="button1" type="button" value="국가 데이터 리셋" style="width:100px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=$in{'list_view'}&mode=cdata_reset'"></td>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td nowrap align="center"><input class="button1" type="button" value="캐릭터 데이터 일괄 삭제" style="width:120px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=$in{'list_view'}&mode=rd_usrdata'"></td>
<td nowrap align="center"><input class="button1" type="button" value="백업 일괄 삭제" style="width:120px" onClick="location.href='$ore_admin?administrator=$in{'administrator'}&list_sort=$in{'list_sort'}&list_view=$in{'list_view'}&mode=rd_backdata'"></td>
</tr>
</table>
</form>

<br>

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th nowrap colspan="5">캐릭터 로그 개별 복구</th>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<th nowrap colspan="3">전체 캐릭터 로그 복구</th>
<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<th nowrap colspan="3">국가 로그 복구</th>
</tr>
<tr>

<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="list_sort" value="$in{'list_sort'}">
<input type="hidden" name="list_view" value="$in{'list_view'}">
<input type="hidden" name="mode" value="restore_person">

<td nowrap>ID</td>
<td nowrap>
<select name="restore_usr" class="button1" type="button" style="width:110px">
EOM
	foreach(1 .. $#usrfile){
		print qq|<option value="$usrfile[$_]"|;
		print qq|>$usrfile[$_]\n|;
	}
	print <<"EOM";
</select>
</td>
<td nowrap>일시</td>
<td nowrap>
<select name="restore_date" class="button1" type="button" style="width:130px">
EOM
	foreach(0 .. $#week){

		if(-e "$backdata$week[$_]\.cgi"){
			my $bk_time = (stat("$backdata$week[$_]\.cgi"))[9];
			my($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($bk_time);
			$min = "0$min" if($min<10);
			$sec = "0$sec" if($sec<10);
			$month++;
			my $date_bk = "$month/$mday($week[$wday]) $hour:$min:$sec";
	
			print qq|<option value="$backdata$week[$_]\.cgi"|;
			print qq|>$date_bk\n|;
		}
	}
	print <<"EOM";
</select>
</td>
<td nowrap align="center"><input class="button1" type="submit" value="복 구" style="width:60px"></td>

</form>

<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>

<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="list_sort" value="$in{'list_sort'}">
<input type="hidden" name="list_view" value="$in{'list_view'}">
<input type="hidden" name="mode" value="restore_all_usr">

<td nowrap>일시</td>
<td nowrap>
<select name="restore_date" class="button1" type="button" style="width:130px">
EOM
	foreach(0 .. $#week){

		if(-e "$backdata$week[$_]\.cgi"){
			my $bk_time = (stat("$backdata$week[$_]\.cgi"))[9];
			my($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($bk_time);
			$min = "0$min" if($min<10);
			$sec = "0$sec" if($sec<10);
			$month++;
			my $date_bk = "$month/$mday($week[$wday]) $hour:$min:$sec";
	
			print qq|<option value="$backdata$week[$_]\.cgi"|;
			print qq|>$date_bk\n|;
		}
	}
	print <<"EOM";
</select>
</td>
<td nowrap align="center"><input class="button1" type="submit" value="복 구" style="width:60px"></td>

</form>

<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>

<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="list_sort" value="$in{'list_sort'}">
<input type="hidden" name="list_view" value="$in{'list_view'}">
<input type="hidden" name="mode" value="restore_cdat">

<td nowrap>일시</td>
<td nowrap>
<select name="restore_date" class="button1" type="button" style="width:110px">
EOM

	open (IN,"$histfile") || &error("Open error : $histfile");
	my @hist_dat = <IN>;
	close(IN)    or die "Can't close   : $!";

	foreach(0 .. $#hist_dat){
		my @y1 = split(/,/,$hist_dat[$_]);
		$y1[42]	=~ s/date;//g;
		print qq|<option value="$_">$y1[42]\n|;
	}
	print <<"EOM";
</select>
</td>
<td nowrap align="center"><input class="button1" type="submit" value="복 구" style="width:60px"></td>

</form>

</tr>
</table>
<br>

EOM
	&admin_end;
	exit;
}

# 個別参加者ログ復旧(バックアップデータ差し替え)
sub restore_person{

	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	# ファイルロック(rename式)
	$lock		= &lock if $lock_check;

	open(IN,"$in{'restore_date'}") || &error("Open Error : $in{'restore_date'}",1);
	my @tdat = <IN>;
	close(IN);

	$in{'restore_usr'} =~ s/\.cgi//g;

	foreach (0 .. $#tdat){

		%R = '';
		my @prats = split(/,/,$tdat[$_]);
		foreach $prats (@prats){
			my($y,$x) = split(/;/,$prats);
			$R{$y} = $x;

			if($in{'restore_usr'} eq $R{'id'}){
				open (OUT,">$usrdata$R{'id'}\.cgi") || &error("open error:$usrdata$R{'id'}\.cgi",1);
				print OUT $tdat[$_];
				close(OUT)		or die "Can't close   : $!";
			}
		}
	}

	&unlock($lock) if $lock_check;

	$comment ="$in{'restore_date'}로부터 $usrdata$in{'restore_usr'}\.cgi 복구 완료";

}

# 全参加者ログ一括復旧(バックアップデータ差し替え)
sub restore_all_usr{

	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	# ファイルロック(rename式)
	$lock		= &lock if $lock_check;

	open(IN,"$in{'restore_date'}") || &error("Open Error : $in{'restore_date'}",1);
	my @tdat = <IN>;
	close(IN);

	foreach (0 .. $#tdat){

		%R = '';
		my @prats = split(/,/,$tdat[$_]);
		foreach $prats (@prats){
			my($y,$x) = split(/;/,$prats);
			$R{$y} = $x;
		}

		open (OUT,">$usrdata$R{'id'}\.cgi") || &error("open error:$usrdata$R{'id'}\.cgi",1);
		print OUT $tdat[$_];
		close(OUT)		or die "Can't close   : $!";

	}

	&unlock($lock) if $lock_check;

	$comment ="$in{'restore_date'}에 포함된 전체 캐릭터 복구 완료";

}

# 国ログ復旧(バックアップデータ差し替え)
sub restore_cdat{

	# ファイルロック(rename式)
	$lock		= &lock if $lock_check;

	open (IN,"$histfile") || &error("Open error : $histfile");
	my @hist_dat = <IN>;
	close(IN)    or die "Can't close   : $!";

	foreach(0 .. $#hist_dat){
		my @y1 = split(/,/,$hist_dat[$_]);
		$y1[42]	=~ s/date;//g;
		print qq|<option value="$_">$y1[42]\n|;
	}

	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	open(IN,"$histfile") || &error("Open Error : $histfile",1);
	@hist_dat = <IN>;
	close(IN);

	open (OUT,">$cdatfile") || &error("open error:$cdatfile",1);
	print OUT $hist_dat[$_];
	close(OUT)		or die "Can't close   : $!";

	&unlock($lock) if $lock_check;

	$comment ="$cdatfile 복구 완료";

}

#-------------------------------------------------------------------------------
# 配列ソート処理
sub csvsort{
	local $key=shift;
	local $field=shift;
	local @in=@_;
	local @usr_data;
	@usr_data=map{$_->[0]}sort{$a->[1]<=>$b->[1]}map{[$_,(split /$key/) [$field]]}@in;
	return \@usr_data;
}

#-------------------------------------------------------------------------------
# 各種削除処理

# キャラ別削除
sub usr_del{
	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);
	foreach(0 .. $#USR_DEL){
		unlink("$usrdata$USR_DEL[$_]\.cgi") || &error("$usrdata$USR_DEL[$_]\.cgi 파일을 삭제할 수 없습니다.");
		$comment.="$usrdata$USR_DEL[$_]\.cgi 삭제 완료<br>";
	}
}
# $usrdata内ファイル全削除
sub rd_usrdata{
	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	&usrdata_read;
	my $flag=0;
	$comment ="$usrdata 에 포함된 모든 파일 삭제 완료<hr>";
	foreach(0 .. $#usrfile){
		unlink("$usrdata$usrfile[$_]");
		$comment .="[ $usrdata$usrfile[$_] ] ";
		$flag++;
		if($flag>=6){
			$comment .="<br>";
			$flag=0;
		}
	}
}
# $backdata内ファイル全削除
sub rd_backdata{
	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	$comment ="$backdata 에 포함된 모든 파일 삭제 완료<hr>";
	my $flag=0;
	foreach(0 .. $#week){
		unlink("$backdata$week[$_]\.cgi");
		$comment .="[ $backdata$week[$_]\.cgi ] ";
		$flag++;
		if($flag>=6){
			$comment .="<br>";
			$flag=0;
		}
	}
}

#-------------------------------------------------------------------------------
# 国データ初期化
sub cdata_reset{
	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	$lock		= &lock if $lock_check;

	&cdata_open;

	require './inc/ore_sub-main_reset.cgi';&reset_cdat;

	&cdat_write;

	&unlock($lock) if $lock_check;

	$comment = "국가 데이터를 초기화했습니다.<br>";
}

#-------------------------------------------------------------------------------
# キャラデータ変更

# 書き換え画面
sub usr_regist{

	&admin_head;
	&settei;

	# 参加者データ一括読み込み
	open(IN,"$usrdata$id\.cgi") || &error("Open Error : $usrdata$id\.cgi",1);
	@dat = <IN>;
	close(IN);

	%DAT = '';
	my @prats = split(/,/,$dat[0]);
	foreach (0 .. $#prats){
		my ($key,$v) = split(/;/,$prats[$_]);
		$DAT{$key} = $v;
	}

	# ハッシュ読み込み
	&hash_data;

	print <<"EOM";
<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="mode" value="usr_regist2">
<input type="hidden" name="id_old" value="$id">

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan=2 align="center">데이터 변경</th>
</tr>
<tr>
<td nowrap><input class="button1" type="submit" value="수정하기"></td>
<td nowrap><input class="button1" type="reset" value="되돌리기"></td>
</tr>
</table>

<br><br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>이름</th>
<th nowrap>ID</th>
<th nowrap>비밀번호</th>
<th nowrap>성별</th>
<th nowrap>레벨</th>
<th nowrap>소속</th>
</tr>
<tr>
<td nowrap><input type="text" name="nm" value="$nm" style="width:100px"></td>
<td nowrap><input type="text" name="id" value="$id" style="width:100px"></td>
<td nowrap><input type="text" name="pw" value="$pw" style="width:80px"></td>

<td nowrap>
<select name="sei">
EOM
	foreach(1 .. $#seibetu){
		print "<option value=$_";
		print " selected" if($sei==$_);
		print ">$_:$seibetu[$_]\n";
	}
	print <<"EOM";
</select>
</td>

<td nowrap><input type="text" name="lv" value="$lv" style="width:30px"></td>

<td nowrap>
<select name="camp">
EOM
	foreach(0 .. $#cmp){
		print "<option value=$_";
		print " selected" if($camp==$_);
		print ">$_:$cmp[$_]\n";
	}
	print <<"EOM";
</select>
</td>

</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>HP</th>
<th nowrap>MP</th>
<th nowrap>UA</th>
<th nowrap>UD</th>
<th nowrap>LR</th>
<th nowrap>AG</th>
<th nowrap>GOLD</th>
<th nowrap>계급</th>
<th nowrap>칭호</th>
<th nowrap>토벌 횟수</th>
</tr>
<tr>
</td>
<td nowrap><input type="text" name="max_hp" value="$max_hp" style="width:40px"></td>
<td nowrap><input type="text" name="max_mp" value="$max_mp" style="width:40px"></td>
<td nowrap><input type="text" name="ua" value="$ua" style="width:30px"></td>
<td nowrap><input type="text" name="ud" value="$ud" style="width:30px"></td>
<td nowrap><input type="text" name="lr" value="$lr" style="width:30px"></td>
<td nowrap><input type="text" name="ag" value="$ag" style="width:30px"></td>
<td nowrap><input type="text" name="gold" value="$gold" style="width:80px"></td>

<td nowrap>
<select name="rank">
EOM
	foreach(0 .. $#cl){
		print "<option value=$_";
		print " selected" if($rank==$_);
		print ">$_:$cl[$_]\n";
	}
	print <<"EOM";
</select>
</td>

<td nowrap>
<select name="sogo">
EOM
	foreach(0 .. $#sogo_p){
		print "<option value=$_";
		print " selected" if($sogo==$_);
		print ">$_:$sogo_p[$_]\n";
	}
	print <<"EOM";
</select>
</td>

<td nowrap><input type="text" name="we" value="$we" style="width:30px"></td>

</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan="2">무구</th>
<th nowrap colspan="2">방어구</th>
<th nowrap colspan="2">도구</th>
</tr>
<tr>

<td nowrap>
<select name="dg_a">
EOM
	foreach(0 .. $#dg_data){
		print "<option value=$_";
		print " selected" if($dg_a==$_);
		print ">$_:$dg_data[$_][1]\n";
	}
	print <<"EOM";
</select>
</td>
<td nowrap>남음 <input type="text" name="dg_cnt" value="$dg_cnt" style="width:30px"></td>

<td nowrap>
<select name="df_a">
EOM
	foreach(0 .. $#df_data){
		print "<option value=$_";
		print " selected" if($df_a==$_);
		print ">$_:$df_data[$_][1]\n";
	}
	print <<"EOM";
</select>
</td>
<td nowrap>남음 <input type="text" name="df_cnt" value="$df_cnt" style="width:30px"></td>

<td nowrap>
<select name="di_a">
EOM
	foreach(0 .. $#di_data){
		print "<option value=$_";
		print " selected" if($di_a==$_);
		print ">$_:$di_data[$_][1]\n";
	}
	print <<"EOM";
</select>
</td>
<td nowrap>남음 <input type="text" name="di_cnt" value="$di_cnt" style="width:30px"></td>

</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>행동 플래그 리셋</th>
<th nowrap>행동 세션</th>
<th nowrap>행동 판정</th>
<th nowrap>행동 판정</th>
<th nowrap>전투 판별</th>
<th nowrap>대전자</th>
<th nowrap>구속 시간</th>
<th nowrap>대상국</th>
</tr>
<tr>
</td>
<td nowrap>에러 발생 시 각 값 0 또는 삭제</td>
<td nowrap><input type="text" name="act_cnt" value="$act_cnt" style="width:30px"></td>
<td nowrap><input type="text" name="type" value="$type" style="width:60px"></td>
<td nowrap><input type="text" name="tm" value="$tm" style="width:30px"></td>
<td nowrap><input type="text" name="ck" value="$ck" style="width:30px"></td>
<td nowrap><input type="text" name="bt" value="$bt" style="width:30px"></td>
<td nowrap><input type="text" name="pr" value="$pr" style="width:50px"></td>
<td nowrap><input type="text" name="nation" value="$nation" style="width:30px"></td>
</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>정보 조회 시 표시되는 한마디(전각 40자까지)</th>
</tr>
<tr>
</td>
<td nowrap><input type="text" name="info_mes" value="$info_mes" style="width:400px"></td>
</tr>
</table>

</form>
EOM
&admin_end;
exit;
}

# 書き換え処理＆結果
sub usr_regist2{

	&admin_head;

	# ファイルロック(rename式)
	$lock		= &lock if $lock_check;

	# 参加者データ一括読み込み
	open(IN,"$usrdata$in{'id_old'}\.cgi") || &error("캐릭터 데이터를 열 수 없습니다[$in{'id_old'}]",1);
	@dat = <IN>;
	close(IN);

	%DAT = '';
	my @prats = split(/,/,$dat[0]);
	foreach (0 .. $#prats){
		my ($key,$v) = split(/;/,$prats[$_]);
		$DAT{$key} = $v;
	}

	# ハッシュ読み込み
	&hash_data;

	$dat[0] = "la;$la,nm;$in{'nm'},pw;$in{'pw'},id;$in{'id'},sei;$in{'sei'},type;$in{'type'},age_time;$age_time,act_cnt;$in{'act_cnt'},hp;$hp,max_hp;$in{'max_hp'},lv;$in{'lv'},mp;$mp,max_mp;$in{'max_mp'},rank;$in{'rank'},ua;$in{'ua'},ud;$in{'ud'},lr;$in{'lr'},ag;$in{'ag'},ck;$in{'ck'},tm;$in{'tm'},bt;$in{'bt'},bst;$in{'bst'},exe;$exe,rank_exe;$rank_exe,sol;$sol,sol_lv;$sol_lv,nation;$in{'nation'},we;$in{'we'},camp;$in{'camp'},pr;$in{'pr'},tnm;$tnm,tid;$tid,thp;$thp,tlr;$tlr,tsol;$tsol,tsg;$tsg,tsol_lv;$tsol_lv,b_n;$b_n,b_v;$b_v,thp_max;$thp_max,tlv;$tlv,tdg_a;$tdg_a,tdf_a;$tdf_a,tua;$tua,tud;$tud,tmp;$tmp,tcp;$tcp,gold;$in{'gold'},roku;$roku,dg_a;$in{'dg_a'},dg_cnt;$in{'dg_cnt'},df_a;$in{'df_a'},df_cnt;$in{'df_cnt'},di_a;$in{'di_a'},di_cnt;$in{'di_cnt'},sogo;$in{'sogo'},mes;$mes,info_mes;$in{'info_mes'},\n";

	open (OUT,">$usrdata$in{'id_old'}\.cgi") || &error("캐릭터 데이터를 열 수 없습니다[$in{'id_old'}]",1);
	print OUT @dat;
	close(OUT)		or die "Can't close   : $!";

	if($in{'id_old'} ne $in{'id'}){rename("$usrdata$in{'id_old'}\.cgi","$usrdata$in{'id'}\.cgi") || &error("파일명을 ID명으로 변경할 수 없습니다.",1);}

	# ファイルアンロック(rename式)
	&unlock($lock) if $lock_check;

	print <<"EOM";
<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan=2 align="center">다음과 같이 데이터를 변경했습니다.</th>
</tr>
</table>

<br><br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>이름</th>
<th nowrap>ID</th>
<th nowrap>비밀번호</th>
<th nowrap>성별</th>
<th nowrap>레벨</th>
<th nowrap>소속</th>
</tr>
<tr>
<td nowrap>$in{'nm'}</td>
<td nowrap>$in{'id'}</td>
<td nowrap>$in{'pw'}</td>
<td nowrap>$in{'sei'}</td>
<td nowrap>$in{'lv'}</td>
<td nowrap>$in{'camp'}</td>
</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>HP</th>
<th nowrap>MP</th>
<th nowrap>UA</th>
<th nowrap>UD</th>
<th nowrap>LR</th>
<th nowrap>AG</th>
<th nowrap>GOLD</th>
<th nowrap>계급</th>
<th nowrap>칭호</th>
<th nowrap>토벌 횟수</th>
</tr>
<tr>
<td nowrap>$in{'max_hp'}</td>
<td nowrap>$in{'max_mp'}</td>
<td nowrap>$in{'ua'}</td>
<td nowrap>$in{'ud'}</td>
<td nowrap>$in{'lr'}</td>
<td nowrap>$in{'ag'}</td>
<td nowrap>$in{'gold'}</td>
<td nowrap>$in{'rank'}</td>
<td nowrap>$in{'sogo'}</td>
<td nowrap>$in{'we'}</td>
</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan="2">무구</th>
<th nowrap colspan="2">방어구</th>
<th nowrap colspan="2">도구</th>
</tr>
<tr>
<td nowrap>$in{'dg_a'}</td>
<td nowrap>남음 $in{'dg_cnt'}</td>
<td nowrap>$in{'df_a'}</td>
<td nowrap>남음 $in{'df_cnt'}</td>
<td nowrap>$in{'di_a'}</td>
<td nowrap>남음 $in{'di_cnt'}</td>
</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>행동 세션</th>
<th nowrap>행동 판정</th>
<th nowrap>행동 판정</th>
<th nowrap>전투 판별</th>
<th nowrap>대전자</th>
<th nowrap>구속 시간</th>
<th nowrap>대상국</th>
</tr>
<tr>
<td nowrap>$in{'act_cnt'}</td>
<td nowrap>$in{'type'}</td>
<td nowrap>$in{'tm'}</td>
<td nowrap>$in{'ck'}</td>
<td nowrap>$in{'bt'}</td>
<td nowrap>$in{'pr'}</td>
<td nowrap>$in{'nation'}</td>
</tr>
</table>

<br>

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap>정보 조회 시 표시되는 한마디(전각 40자까지)</th>
</tr>
<tr>
</td>
<td nowrap>$info_mes</td>
</tr>
</table>

EOM
&admin_end;
exit;
}

#-------------------------------------------------------------------------------
# 国データ変更

# 書き換え画面
sub cdat_regist{

	&admin_head;
	&cdata_open;

	$set -= $time;

	print <<EOM;
<form method="$method" action="$ore_admin" name="ore_admin">
<input type="hidden" name="administrator" value="$in{'administrator'}">
<input type="hidden" name="mode" value="cdat_regist2">
<input type="hidden" name="id_old" value="$id">

<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan="2" align="center">데이터 변경</th>
<th nowrap rowspan="2" align="left" style="font-size:14px;line-height:18px">
・상태 >> 0:정상 1:망국<br>
・국가별 정원 >> 
EOM

($limit_mode) ? print "자동 산출" : print "수동 할당" ;

print <<EOM;
</th>
</tr>
<tr>
<td nowrap><input class="button1" type="submit" value="변경하기"></td>
<td nowrap><input class="button1" type="reset" value="되돌리기"></td>
</tr>
</table>

<br><br>

<table border="0" cellspacing="4" cellpadding="0" bgcolor="#444466" align="center">
<tr>
<td bgcolor="#000000" align="center" valign="top">

<table border=0 cellpadding=2 cellspacing=2 width=100% align=center>
<tr>
<td width="72">국가명</td>
EOM

	foreach(1 .. 5){
		print qq|<td align="center" width="92">$cmp[$_]</td>\n|;
	}
	print <<EOM;
</tr><tr><td>상태</td>
<td><input type="text" name="ce1" value="$ce1" style="width:60px"></td>
<td><input type="text" name="ce2" value="$ce2" style="width:60px"></td>
<td><input type="text" name="ce3" value="$ce3" style="width:60px"></td>
<td><input type="text" name="ce4" value="$ce4" style="width:60px"></td>
<td><input type="text" name="ce5" value="$ce5" style="width:60px"></td>
</tr>
<tr>
<td>총 국력</td>
<td><input type="text" name="cn1" value="$cn1" style="width:60px"></td>
<td><input type="text" name="cn2" value="$cn2" style="width:60px"></td>
<td><input type="text" name="cn3" value="$cn3" style="width:60px"></td>
<td><input type="text" name="cn4" value="$cn4" style="width:60px"></td>
<td><input type="text" name="cn5" value="$cn5" style="width:60px"></td>
</tr>
<tr>
<td>국가 예산</td>
<td><input type="text" name="cg1" value="$cg1" style="width:60px"></td>
<td><input type="text" name="cg2" value="$cg2" style="width:60px"></td>
<td><input type="text" name="cg3" value="$cg3" style="width:60px"></td>
<td><input type="text" name="cg4" value="$cg4" style="width:60px"></td>
<td><input type="text" name="cg5" value="$cg5" style="width:60px"></td>
</tr>
<tr>
<td>총 군량</td>
<td><input type="text" name="cf1" value="$cf1" style="width:60px"></td>
<td><input type="text" name="cf2" value="$cf2" style="width:60px"></td>
<td><input type="text" name="cf3" value="$cf3" style="width:60px"></td>
<td><input type="text" name="cf4" value="$cf4" style="width:60px"></td>
<td><input type="text" name="cf5" value="$cf5" style="width:60px"></td>
</tr>
<tr>
<td>총 병사 수</td>
<td><input type="text" name="cs1" value="$cs1" style="width:60px"></td>
<td><input type="text" name="cs2" value="$cs2" style="width:60px"></td>
<td><input type="text" name="cs3" value="$cs3" style="width:60px"></td>
<td><input type="text" name="cs4" value="$cs4" style="width:60px"></td>
<td><input type="text" name="cs5" value="$cs5" style="width:60px"></td>
</tr>
<tr>
<td bgcolor=#CCCCFF>소속 인원</td>
<td align=center>$c1/<input type="text" name="c1a" value="$c1a" style="width:30px"></td>
<td align=center>$c2/<input type="text" name="c2a" value="$c2a" style="width:30px"></td>
<td align=center>$c3/<input type="text" name="c3a" value="$c3a" style="width:30px"></td>
<td align=center>$c4/<input type="text" name="c4a" value="$c4a" style="width:30px"></td>
<td align=center>$c5/<input type="text" name="c5a" value="$c5a" style="width:30px"></td>
</tr>
</table>
통일 기한: 앞으로<input type="text" name="set" value="$set" style="width:60px">초
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
현재<input type="text" name="goal_no" value="$goal_no" style="width:20px">기
</td>
</tr>
</table>
</form>
EOM
	&admin_end;
	exit;
}

# 書き換え処理
sub cdat_regist2{

	&admin_head;

	# ファイルロック(rename式)
	$lock		= &lock if $lock_check;

	&cdata_open;

	$cn1=$in{'cn1'};# 国1の国力
	$cg1=$in{'cg1'};# 国1の財政
	$cf1=$in{'cf1'};# 国1の蓄米
	$cs1=$in{'cs1'};# 国1の予備兵
	$ce1=$in{'ce1'};# 国1の現状
	$c1a=$in{'c1a'};# 国1の定員数
	$cn2=$in{'cn2'};
	$cg2=$in{'cg2'};
	$cf2=$in{'cf2'};
	$cs2=$in{'cs2'};
	$ce2=$in{'ce2'};
	$c2a=$in{'c2a'};
	$cn3=$in{'cn3'};
	$cg3=$in{'cg3'};
	$cf3=$in{'cf3'};
	$cs3=$in{'cs3'};
	$ce3=$in{'ce3'};
	$c3a=$in{'c3a'};
	$cn4=$in{'cn4'};
	$cg4=$in{'cg4'};
	$cf4=$in{'cf4'};
	$cs4=$in{'cs4'};
	$ce4=$in{'ce4'};
	$c4a=$in{'c4a'};
	$cn5=$in{'cn5'};
	$cg5=$in{'cg5'};
	$cf5=$in{'cf5'};
	$cs5=$in{'cs5'};
	$ce5=$in{'ce5'};
	$c5a=$in{'c5a'};

	$goal_no=$in{'goal_no'};
	$set=$in{'set'}+$time;

	&cdat_write;

	# ファイルアンロック(rename式)
	&unlock($lock) if $lock_check;

	print <<EOM;
<table border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th nowrap colspan=2 align="center">다음과 같이 데이터를 변경했습니다.</th>
</tr>
</table>

<br><br>
<div align="center" style="font-size:14px;color:#222244">
・상태 >> 0:정상 1:망국<br>
・국가별 정원 >> 
EOM

($limit_mode) ? print "자동 산출" : print "수동 할당" ;

print <<EOM;
</div>
<br><br>

<table border="0" cellspacing="4" cellpadding="0" bgcolor="#444466" align="center">
<tr>
<td bgcolor="#000000" align="center" valign="top">

<table border=0 cellpadding=2 cellspacing=2 width=100% align=center>
<tr>
<td width="72">국가명</td>
EOM

	foreach(1 .. 5){
		print qq|<td align="center" width="92">$cmp[$_]</td>\n|;
	}
	print <<EOM;
</tr>
<tr>
<td>상태</td>
<td align=center>$in{'ce1'}</td>
<td align=center>$in{'ce2'}</td>
<td align=center>$in{'ce3'}</td>
<td align=center>$in{'ce4'}</td>
<td align=center>$in{'ce5'}</td>
</tr>
<tr>
<td>총 국력</td>
<td>$in{'cn1'}</td>
<td>$in{'cn2'}</td>
<td>$in{'cn3'}</td>
<td>$in{'cn4'}</td>
<td>$in{'cn5'}</td>
</tr>
<tr>
<td>국가 예산</td>
<td>$in{'cg1'}</td>
<td>$in{'cg2'}</td>
<td>$in{'cg3'}</td>
<td>$in{'cg4'}</td>
<td>$in{'cg5'}</td>
</tr>
<tr>
<td>총 군량</td>
<td>$in{'cf1'}</td>
<td>$in{'cf2'}</td>
<td>$in{'cf3'}</td>
<td>$in{'cf4'}</td>
<td>$in{'cf5'}</td>
</tr>
<tr>
<td>총 병사 수</td>
<td>$in{'cs1'}</td>
<td>$in{'cs2'}</td>
<td>$in{'cs3'}</td>
<td>$in{'cs4'}</td>
<td>$in{'cs5'}</td>
</tr>
<tr>
<td>소속 인원</td>
<td align=center>$c1/$in{'c1a'}</td>
<td align=center>$c2/$in{'c2a'}</td>
<td align=center>$c3/$in{'c3a'}</td>
<td align=center>$c4/$in{'c4a'}</td>
<td align=center>$c5/$in{'c5a'}</td>
</tr>
</table>

통일 기한: 앞으로 $in{'set'} 초
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
현재 $in{'goal_no'} 기

</td>
</tr>
</table>
</form>
EOM
	&admin_end;
	exit;
}

#-------------------------------------------------------------------------------
# テンプレート

# ヘッダー
sub admin_head{

	&error("비밀번호가 틀립니다!") if($in{'administrator'} ne $admin_pass);

	$in{'list_sort'} = 3 if(!$in{'list_sort'});

	&content_type;

	print <<"EOM";

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>$titleh</title>
<style type="text/css">
<!--
.button1{
	font-family: "ＭＳ Ｐゴシック", "Osaka"; font-size: 12px; font-weight: 400; color: #ddddee;
	border: 2px #aaaabb ridge; cursor: hand; background-color: #666699;
	width:50px;
}
body	{ font-size: 12px; color: #aaaab9; background-color: #ddddff; cursor: crosshair}
table	{ background-color: #666699;}
td		{ font-size: 14px; color: #222244; background-color: #eeeeff; cursor: crosshair}
th		{ font-size: 12px; color: #eeeeff; background-color: #222244; font-weight:400}

-->
</style>
</head>

<body bgcolor="#000000" text="#999999" link="#333399" vlink="#333399" alink="#333399">
EOM
}

# フッター
sub admin_end{
		print <<"EOM";
<br><br><br>
<table border="0" cellspacing="2" cellpadding="2" bgcolor="#9999CC" align="center">
<tr>
<td valign="middle" align="center" nowrap style="color:ddddee;font-size:14px;background-color:#333399">
죄와 벌++ 이율배반 관리자 기능 $ver 사용법
</td>
</tr>
<tr>
<td bgcolor="#DDDDEE" valign="middle" align="left" nowrap style="line-height:20px; font-size:12px">
>> 각 처리에 상세한 에러 처리는 되어 있지 않습니다. 데이터 수정 등은 신중히 진행해 주세요.<br>
>> 각 캐릭터의 <b>[로그인]</b> 버튼을 클릭하면 해당 캐릭터로 로그인할 수 있습니다.<br>
>> 각 캐릭터의 <b>[ 편집 ]</b> 버튼을 클릭하면 캐릭터 데이터 편집 화면으로 이동합니다.<br>
&nbsp;&nbsp;&nbsp;&nbsp;・캐릭터 데이터의 ID를 변경하면 캐릭터 데이터 파일명도 변경됩니다.<br>
>> 각 캐릭터의 왼쪽 끝 <b>[ 삭제 ]</b> 체크박스에 체크하고, 하단 메뉴의 <b>[캐릭터 삭제]</b> 버튼을 클릭하면 선택한 캐릭터가 삭제됩니다.<br>
>> 하단 메뉴의 <b>[국가 데이터 편집]</b> 버튼을 클릭하면 현재 국가 데이터를 편집할 수 있습니다.<br>
&nbsp;&nbsp;&nbsp;&nbsp;・정원 수 지정은 ore_config.cgi의 <b>[\$limit_mode]</b> 값이 우선 적용됩니다.<br>
>> 하단 메뉴의 <b>[국가 데이터 초기화]</b> 버튼을 클릭하면 현재 국가 데이터가 초기화됩니다.<br>
>> CGI 실행에 사용자 권한이 없는 서버에서 캐릭터 데이터 파일과 백업 파일이 삭제되지 않을 경우, 이 관리자 기능에서 삭제를 수행해 주세요.<br>
&nbsp;&nbsp;&nbsp;&nbsp;・하단 메뉴의 <b>[캐릭터 데이터 일괄 삭제]</b>를 클릭하면 모든 캐릭터 데이터를 일괄 삭제합니다.<br>
&nbsp;&nbsp;&nbsp;&nbsp;・하단 메뉴 of <b>[백업 일괄 삭제]</b>를 클릭하면 모든 백업 데이터를 일괄 삭제합니다.<br>
</td>
</tr>
<tr>
<td bgcolor="#DDDDEE" valign="middle" align="center" nowrap style="font-size:12px">
죄와 벌++ 이율배반 관리자 기능 $ver <a href="http://pom.to/" target="_blank">BLANK BOARD[인터넷 놀이터♪]</a> <a href="http://www17.big.or.jp/~obochan/vivid/" target="_blank">Vivid Studio.</a>
</td>
</tr>
</table>
</body>
</html>
EOM
}