#
#マスターモード（削除機能とパスワード閲覧）
#
#0.713 (10/08/12)

sub master{
	
	print "master mode<BR>";
	
	if($language ne "English"){
		print "<HR><a href=$script?$salt>[登録システム入り口]</a><a href=$script?function=faq>[使い方]</a><a href='$homepage'>[ホームページへ戻る]</a><BR>";
		print "<a href='#config'>[各種設定]</a><a href='#sort'>[ソ\ート]</a><a href='#backup'>[バックアップ]</a><a href='#info'>[お知らせ変更]</a><BR>";
	}
	else {
		print "<HR><a href=$script?$salt>[ListPageTop]</a><a href=$script?function=faq>[Usage]</a><a href='$homepage'>[BacktoHome]</a><BR>";
		print "<a href='#config'>[Config]</a><a href='#sort'>[Sort]</a><a href='#backup'>[Backup]</a><a href='#info'>[Info change]</a><BR>";
	}
	
	if(($gpass ne $master_pass)){
		&error_message('illegal login','password is not correct.');
	}
	
	if ($mode eq "delete" && $anon eq "on"){
		if($language ne "English"){
			print "$name さんを削除します。データはすべて抹消されます。<BR>";
		} else {
			print "$name 's data will be delted.<BR>";
		}
		if(!open(IN,"$datafile")){
			&error_message('datafile error193','data file access failed.');
		}
		@all=<IN>;
		close IN;
		
		@out=();
		foreach $i (@all){
			($r_no,$r_name,$dummy)=split(/\t/,$i);
			if($name ne $r_name){
				push(@out,$i);
			}
		}
		if(!open(OUT,">$datafile")){
			&error_message('datafile error204','data file access failed.');
		}
		print OUT @out;
		close OUT;
		
		if($language ne "English"){
			print "$name さんのデータは削除されました。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		}
		else {
			print "$name 's data is deleted.<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back master mode'></form>";
		}
	}
	elsif ($mode eq "edit") {
		if(!open(IN,"$datafile")){
			&header; &error_message('datafile error214','data file access failed.');
		}
		@all=<IN>;
		close IN;
		
		$match="";
		foreach $i(@all){
			 ($r_no,$r_name,$r_pass,$r_dummy)=split(/\t/,$i);
			if($r_name eq $name){
					$match=$i;
			}
		}
		if($match eq ""){
			&header; &error_message('id/pass error','access failed.');
		}
		($no,$name,$pass,$anon,$race,$relm,$mainjob,$supportjob,$prof,$handle,$polhn,$mail,$home,$comment2,$point,$class,$time,$comment,$mrank,$etc[0],$etc[1],$etc[2],$prod[0],$prod[1],$prod[2],$prod[3],$prod[4],$prod[5],$prod[6],$prod[7],$prod[8],$prod[9],$prod[10],$prod[11],$prod[12],$prod[13],$prod[14],$prod[15],$lev[0],$lev[1],$lev[2],$lev[3],$lev[4],$lev[5],$lev[6],$lev[7],$lev[8],$lev[9],$lev[10],$lev[11],$lev[12],$lev[13],$lev[14],$lev[15],$lev[16],$lev[17],$lev[18],$lev[19])=split(/\t/,$match);
		@prod_r = split(/,/,$etc[1]);
		($syn,@synt) = split( /,/, $prod[9]);
		
		if($language ne "English"){
			print "'$name'($no) さんのデータを修正します。";
		} else {
			print "modifying $name'($no) 's data";
		}
		print "<BR><table><form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=name value=$name><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=hidden name=mode value=modify>";
		print "<TR><TD>$field[0]</TD><TD><input type=text name=class size=80 value='$class'></TD>";
		print "<input type=hidden name=name value=$name></TR>\n";
		print "<TR><TD>$field[1]</TD><TD><input type=text name=name2 value=$name></TD><TR><TD>$field[2]</TD><TD><input type=text name=pass value=$pass></TD></TR>\n";
		print "<TR><TD>no</TD><TD><input type=text name=no value=$no></TD></TR>";
		print "<TR><TD>$field[3]</TD><TD><select name=anon>";
		if($anon eq on){
			print "<option value=off>off</option><option value=on selected>on</option>";
		}
		else {
			print "<option value=off selected>off</option><option value=on>on</option>";
		}	
		print "</select></TD></TR>\n";
		
		print "<TR><TD>$field[4]</TD><TD><select name=race>";
		for($i=0;$i<$#racelist+1;$i++){
			if($i==$race){
				print "<option value=$i selected>$racelist[$i]</option>\n";
			}
			else {
				print "<option value=$i>$racelist[$i]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		print "<TR><TD>$field[5] (<a href=$icondir";
		print "samples.htm target='_blank'>$field[18]</a>)</TD><TD><select name=ftype>";
		for($i=0;$i<$#facetypename+1;$i++){
			if($i==$etc[0]){
				print "<option value=$i selected>$facetypename[$i]</option>\n";
			}
			else {
				print "<option value=$i>$facetypename[$i]</option>\n";
			}
		}
		print "</select></TD></tr>\n";
		
		print "<TR><TD>$field[6]</TD><TD><select name=relm>";
		for($i=0;$i<$#relmlist+1;$i++){
			if($i==$relm){
				print "<option value=$i selected>$relmlistl[$i]</option>\n";
			} else {
				print "<option value=$i>$relmlistl[$i]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		print "<TR><TD colspan=2><HR></TD></TR>\n";
		print "<TR><TD>$field[7]</TD><TD><select name=mainjob>";
		for($i=0;$i<$job_max;$i++){
			if($i==$mainjob){
				print "<option value=$i selected>$joblist[$i]</option>\n";
			} else {
				print "<option value=$i>$joblist[$i]</option>\n";
			}
		}
		print "</select></TD></TR>\n";

		print "<TR><TD>$field[8]</TD><TD><select name=supportjob>";
		print "<option value=99>none</option>\n";

		for($i=0;$i<$job_max;$i++){
			if($i==$supportjob){
				print "<option value=$i selected>$joblist[$i]</option>\n";
			} else {
				print "<option value=$i>$joblist[$i]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		for($i=0;$i<$job_max;$i++){
			print "<TR><TD>$joblist[$i]</TD><TD><input type=text size=2 name=lev$i value=$lev[$i]></TD></TR>\n";
		}
		print "<TR><TD colspan=2><HR></TD></TR>\n";

		for($i=0;$i<$prod_max-1;$i++){
			print "<TR><TD>$prodlist[$i]</TD><TD><input type=text size=2 name=prod$i value=$prod[$i]>\n";
			print "<select name=prod_r$i>";
			for($j=0;$j<$#ranklist+1;$j++){
				if($j==$prod_r[$i]){
					print "<option value=$j selected>$ranklist[$j]</option>\n";
				}
				else {
					print "<option value=$j>$ranklist[$j]</option>\n";
				}
			}
			print "</select></TD></TR>\n";
		}
		print "<TR><TD>$prodlist[9]</TD><TD><input type=text size=2 name=syn value=$syn>\n";
		for($i=0;$i<=$#synergytech;$i++){
			print "<TR><TD>$synergytech[$i]</td>";
			print "<td><input type=text size=2 name=synt$i value=$synt[$i]></td></tr>\n";
		}

####ミッション進行度フラグ
#pm,jm,sm,bm,wm,ds,db,dw,dj,df,dx

		@mission = split(/,/,$prod[15]);
		# 石の見る夢
		print "<TR><TD>$mlist[19]</TD>";
		print "<TD><select name=mission19>";
		for($j=0;$j<$#addcplist+1;$j++){
			if($j==$mission[19]){
				print "<option value=$j selected>$addcplist[$j]</option>\n";
			}
			else {
				print "<option value=$j>$addcplist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		# 戦慄！モグ祭りの夜
		print "<TR><TD>$mlist[20]</TD>";
		print "<TD><select name=mission20>";
		for($j=0;$j<$#addmklist+1;$j++){
			if($j==$mission[20]){
				print "<option value=$j selected>$addmklist[$j]</option>\n";
			}
			else {
				print "<option value=$j>$addmklist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		# シャントット帝国の陰謀
		print "<TR><TD>$mlist[21]</TD>";
		print "<TD><select name=mission21>";
		for($j=0;$j<$#addsslist+1;$j++){
			if($j==$mission[21]){
				print "<option value=$j selected>$addsslist[$j]</option>\n";
			}
			else {
				print "<option value=$j>$addsslist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		# アルタナミッション
		print "<TR><TD>$mlist[18]</TD>";
		print "<TD><select name=mission18>";
		for($j=0;$j<$#allist+1;$j++){
			if($j==$mission[18]){
				print "<option value=$j selected>$allist[$j]</option>\n";
			}
			else {
				print "<option value=$j>$allist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		# カンパニエ叙勲
		print "<TR><TD>$mlist[22]</TD>";
		print "<TD><select name=mission22>";
		for($j=0;$j<$#alrank+1;$j++){
			if($j==$mission[22]){
				print "<option value=$j selected>$alrank[$j]</option>\n";
			}
			else {
				print "<option value=$j>$alrank[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		print "<TR><TD>$mlist[15]</TD><TD>";
		print "<select name=mission15>";
		for($j=0;$j<$#amlist+1;$j++){
			if($j==$mission[15]){
				print "<option value=$j selected>$amlist[$j]</option>\n";
			} else {
				print "<option value=$j>$amlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		print "<TR><TD>$mlist[0]</TD><TD>";
		print "<select name=mission0>";
		for($j=0;$j<$#pmlist+1;$j++){
			if($j==$mission[0]){
				print "<option value=$j selected>$pmlist[$j]</option>\n";
			} else {
				print "<option value=$j>$pmlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		print "<TR><TD>$mlist[1]</TD><TD>";
		print "<select name=mission1>";
		for($j=0;$j<$#jmlist+1;$j++){
			if($j==$mission[1]){
				print "<option value=$j selected>$jmlist[$j]</option>\n";
			} else {
				print "<option value=$j>$jmlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		print "<TR><TD>$mlist[2]</TD><TD>";
		print "<select name=mission2>";
		for($j=0;$j<$#smlist+1;$j++){
			if($j==$mission[2]){
				print "<option value=$j selected>$smlist[$j]</option>\n";
			} else {
				print "<option value=$j>$smlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		print "<TR><TD>$mlist[3]</TD><TD>";
		print "<select name=mission3>";
		for($j=0;$j<$#bmlist+1;$j++){
			if($j==$mission[3]){
				print "<option value=$j selected>$bmlist[$j]</option>\n";
			} else {
				print "<option value=$j>$bmlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		print "<TR><TD>$mlist[4]</TD><TD>";
		print "<select name=mission4>";
		for($j=0;$j<$#wmlist+1;$j++){
			if($j==$mission[4]){
				print "<option value=$j selected>$wmlist[$j]</option>\n";
			} else {
				print "<option value=$j>$wmlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		for($k=5;$k<15;$k++){
			print "<TR><TD>$mlist[$k]</TD><TD>";
			print "<select name=mission$k>";
			for($j=0;$j<$#maru+1;$j++){
				if($j==$mission[$k]){
					print "<option value=$j selected>$maru[$j]</option>\n";
				} else {
					print "<option value=$j>$maru[$j]</option>\n";
				}
			}
			print "</select></TD></TR>\n";
		}

#assault
		@assault=split( //,$mission[16]);
		print "<TR><TD>$aslist[0]</TD><TD>";
		print "<select name=assault0>";
		for($j=0;$j<$#asrank+1;$j++){
			if($j==$assault[0]){
				print "<option value=$j selected>$asrank[$j]</option>\n";
			}
			else {
				print "<option value=$j>$asrank[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		print "<TR><TD>$mlist[17]</TD>";
		print "<TD><select name=mission17>";
		for($j=0;$j<$#nzlist+1;$j++){
			if($j==$mission[17]){
				print "<option value=$j selected>$nzlist[$j]</option>\n";
			}
			else {
				print "<option value=$j>$nzlist[$j]</option>\n";
			}
		}
		print "</select></TD></TR>\n";
		
		for($j=1;$j<$#aslist+1;$j++){
			print "<TR><TD>$aslist[$j]</TD><TD>";
			print "<select name=assault$j>";
			if($assault[$j]==1){
				print "<option value=1 selected>$maru[1]</option>\n";
				print "<option value=0>$maru[0]</option>\n";
			}
			else {
				print "<option value=1>$maru[1]</option>\n";
				print "<option value=0 selected>$maru[0]</option>\n";
			}
		}
		print "</select></TD></TR>\n";

####ミッション進行度ここまで

##############
#-- 以下スキル表示機能で追加した部分 
#    @skill = split(/,/,$etc[2]);
		($tempskill,$tempws)=split( /\//,$etc[2]);
		@skill = split( /\,/, $tempskill );
		@ws = split( //, $tempws );

		if ($skill_visible) {
			print "<tr><td colspan=2>-<br><table border=0><tr bgcolor=$indexcolor>";
			for($i=0;$i<15;$i++){
				print "<th width=6.66%>$skilllist[$i]</th>";
			}
			print "</tr><tr$bgn>";
			for($i=0;$i<15;$i++){
				print "<TD width=6.66% align=center><input type=text size=5 name=skill$i value=$skill[$i]></TD>\n";
			}
			print "</table></td></tr>";
			
			print "<tr><td colspan=2><table border=0><tr bgcolor=$indexcolor>";
			for($i=15;$i<$#skilllist+1;$i++){
				print "<th width=6.66%>$skilllist[$i]</th>";
			}
			print "</tr><tr>";
			for($i=15;$i<$#skilllist+1;$i++){
				print "<TD width=6.66% align=center><input type=text size=4 name=skill$i value=$skill[$i]></TD>\n";
			}
			print "</table></td></tr>";
		}
		for ($i=0;$i<=$#mwslist;$i++){
			( $wskill, $wname, $wtype, $wjob, $wcond ) = split( /,/, $mwslist[ $i ] );
			print "<TR><TD>$wname</TD>";
			if( $ws[ $i ] ){
				# 既に習得済みのものは、条件チェックせずに表示させる
				print "<TD><select name=ws$i><option value=0>-</option><option selected value=1>$maru[ 1 ]</option></select></TD></TR>\n";
			}
			else {
				print "<TD><select name=ws$i><option selected value=0>-</option><option value=1>$maru[ 1 ]</option></select></TD></TR>\n";
			}
		}
#-- スキル表示機能で追加した部分ここまで 
##############

		require("equip.pl");
		&def_equip_list();
		@elist = split(/\,/, $prod[10]);
		print "<tr><td colspan=2>-<br><table border=0>";
		# 武器リストのフォーム表示ループ
		for ( $e=0; $e<=3; $e++ ){
			# 武器リストを取得
			@templist = @{$equipdeflist[$e]};
			# 取得済みの武器リストを取得
			@equips = split( //, $elist[$e] );
			$itemnum = $#templist+1;
			print "<tr><th colspan=3 bgcolor=$indexcolor>$equiplist[$e]</th></tr>\n";
			print "<tr><td bgcolor=$indexcolor rowspan=$itemnum>$equiplist[$e]</td>";
			for( $i=0; $i<$itemnum; $i++ ){
				if( $i != 0 ){
					print "<tr>";
				}
				$fstr = $equiplistname[$e] . '_' . $i ;
				print "<td>$templist[$i]</td><td><select name=$fstr>";
				if( $equips[$i] ){
					print "<option value=0>$maru[0]</option><option selected value=1>$maru[1]</option></select>";
				}
				else{
					print "<option selected value=0>$maru[0]</option><option value=1>$maru[1]</option></select>";
				}
				print "</td></tr>\n";
			}
			print "<tr><td colspan=3>&nbsp;</td></tr>\n";
		}	
		
		# 防具リストのフォーム表示ループ
		
		for ( $e=4; $e<=10; $e++ ){
			@templist = @{$equipdeflist[$e]};
			@equipset = split( /\//, $elist[$e] );
			@setname = split( /\,/, $templist[0] );
			print "<tr><th colspan=3 bgcolor=$indexcolor>$equiplist[$e]</th></tr>\n";
			for( $i = 0; $i<$#templist; $i++ ){
				@equips = split( //, $equipset[$i] );
				@templist2 = split( /\,/, $templist[$i+1]);
				$itemnum = $#templist2+1;
				if( $e == 10 ){
					($jobnumber,$eqname) = split( /\//, $setname[$i] );
					print "<tr><td bgcolor=$indexcolor rowspan=$itemnum>$joblist[$jobnumber]/$eqname</td>";
				}
				else{
					print "<tr><td bgcolor=$indexcolor rowspan=$itemnum>$setname[$i]</td>";
				}
				for( $j=0; $j<=$#templist2;$j++){
					($eqslot, $eqname) = split( /\//, $templist2[$j] );
					$fstr = $equiplistname[$e] . '_' . $i . '_' . $j;
					if( $j != 0 ){
						print "<tr>";
					}
					print "<td>$eqname ($equipslot[$eqslot])</td><td><select name=$fstr>";
					if( $equips[$j] ){
						print "<option value=0>$maru[0]</option><option selected value=1>$maru[1]</option></select>";
					}
					else{
						print "<option selected value=0>$maru[0]</option><option value=1>$maru[1]</option></select>";
					}
					print "</td></tr>\n";
				}
			}
			print "<tr><td colspan=3>&nbsp;</td></tr>\n";
		}
		print "</table></td></tr>\n";
		
#めりぽはこのへんに。
		print "<input type=hidden name=prod12 value='$prod[12]'><input type=hidden name=prod13 value='$prod[13]'>";
		
#カスタムフィールド
		@custom=split(/,/,$prod[11]);

		print "<TR><TD>$custom_field[0]</TD></TR>";
		print "<TR><TD colspan=2><HR></TD></TR>";
		for ($i=1;$i<$#custom_field+1;$i++){
			print "<TR><TD>$custom_field[$i]</TD><TD><input type=text name=custom$i value='$custom[$i]'></TD></TR>";
		}
		print "<TR><TD colspan=2><HR></TD></TR>";
		
		print "<TR><TD>$field[9]</TD><TD><input type=text name=point size=80 value='$point'></TD></TR>\n";
		print "<TR><TD>$field[10]</TD><TD><input type=text name=mrank value='$mrank'></TD></TR>\n";
		print "<TR><TD>$field[11]</TD><TD><input type=text name=comment size=80 value='$comment'></TD></TR>\n";
		
		print "<TR><TD colspan=2><HR></TD></TR></TR>\n";
		print "<TR><TD>$field[12]</TD><TD><select name=prof>";
		if($prof eq off){
			print "<option value=off selected>off</option><option value=on>on</option>";
		}
		else {
			print "<option value=off>off</option><option value=on selected>on</option>";
		}	
		print "</select></TD></TR>\n";
		
		print "<TR><TD>$field[13]</TD><TD><input type=text name=handle value='$handle'></TD></TR>\n";
		print "<TR><TD>$field[14]</TD><TD><input type=text name=polhn value='$polhn'></TD></TR>\n";
		print "<TR><TD>$field[15]</TD><TD><input type=text name=mail value='$mail'></TD></TR>\n";
		
		print "<TR><TD>$field[16]</TD><TD><input type=text name=home size=80 value='$home'></TD></TR>\n";
		
		$comment2 =~ s/<BR>/\r/g;
		print "<TR><TD>$field[17]</TD><TD><textarea name=comment2 rows=5 cols=60>$comment2</textarea></TD></TR>\n";
		
		print "<TR><TD>Profile Photo Exists:[$prod[14]]</TD></TR>\n";
		print "<TR><TD>photo mode<select name=imgdel><option value=0>keep</option><option value=1>delete</option></select></TD></TR>\n";
		print "<input type=hidden name=profimage value='$prod[14]'>\n";
		
		print "<TR><TD><input type=submit value=modify></TD><TD></TD></TR>\n</form></table>";
		
	}
	elsif ($mode eq "modify") {
		
		&dirlock;
		if(!open(IN,"$datafile")){
			&header; &error_message('datafile error332','data file access failed.');
		}
		@all=<IN>;
		close IN;
		
		if($mainjob == $supportjob){
			&header; &error_message('main/job error','メインとサポートは同一のジョブにはできません');
		}
		if( !($pass =~ /^[A-Za-z0-9_]+$/) ){
			&error_message('そのパスワードは登録に利用できません。','パスワードは半角英数字で登録してください。');
		}
		if( !($name2 =~ /^[A-Za-z0-9_]+$/) ){
			&error_message('その名前は使えません。','名前は半角英数字で登録してください。');
		}
		
		$prod[11]=join(",", @custom);
		
		@out=();
		foreach $i(@all){
			($r_no,$r_name,$dummy1,$dummy2,$dummy3,$dummy4,$dummy5,$dummy6,$dummy7,$dummy8,$dummy9,$dummy10,$dummy11,$dummy12,$dummy13,$dummy14,$r_time)=split(/\t/,$i);
			if($r_name eq $name){
				push(@out,"$no\t$name2\t$pass\t$anon\t$race\t$relm\t$mainjob\t$supportjob\t$prof\t$handle\t$polhn\t$mail\t$home\t$comment2\t$point\t$class\t$r_time\t$comment\t$mrank\t$etc[0]\t$etc[1]\t$etc2skill/$etc2ws\t$prod[0]\t$prod[1]\t$prod[2]\t$prod[3]\t$prod[4]\t$prod[5]\t$prod[6]\t$prod[7]\t$prod[8]\t$prod[9]\t$prod[10]\t$prod[11]\t$prod[12]\t$prod[13]\t$prod[14]\t$prod[15]\t$lev[0]\t$lev[1]\t$lev[2]\t$lev[3]\t$lev[4]\t$lev[5]\t$lev[6]\t$lev[7]\t$lev[8]\t$lev[9]\t$lev[10]\t$lev[11]\t$lev[12]\t$lev[13]\t$lev[14]\t$lev[15]\t$lev[16]\t$lev[17]\t$lev[18]\t$lev[19]\t\n");
			}
			else {
				push(@out,$i);
			}
		}
		if(!open(OUT,">$datafile")){&header; &error_message('datafile error353','data file access failed.');}
		print OUT @out;
		close OUT;
		rmdir($lockdir);
		
		if($language ne "English"){
			print "<table width=100%><TR bgcolor=$indexcolor><TD>'$name'さんのデータを修正しました</TD></TR></table>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		}
		else {
			print "<table width=100%><TR bgcolor=$indexcolor><TD>modified '$name' 's data</TD></TR></table>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}

	}
	elsif($mode eq "backup"){
		if(!open(IN,"$datafile")){
			&error_message('datafile error364','data file access failed.');
		}
		@all=<IN>;
		close IN;
		
		if(!open(OUT,">$name")){
			&error_message('datafile error368','data file access failed.');
		}
		print OUT @all;
		close OUT;
		
		if($language ne "English"){
			print "バックアップファイル'$name'を作成しました。データ破損の場合はこのファイルを'$datafile'に上書きしてください。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "BackupFile:'$name'<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
	}
	elsif($mode eq "sort"){
		
		&dirlock;
		if(!open(IN,"$datafile")){&error_message('datafile error380','data file access failed.');}
		@all=<IN>;
		close IN;
		
		@all=sort(@all);
		
		@out=();
		$count=1;
		foreach $i (@all){
			@temp=split(/\t/,$i);
			
			$c=$count;
			if($c<10){$c="0$c";}
			if($c<100){$c="0$c";}
			$value="$c";
		
			for($j=1;$j<$#temp+1;$j++){
				$value="$value\t$temp[$j]";
			}
			
			push (@out,"$value");
		
			$count++;
		}
		
		if(!open(OUT,">$datafile")){
			&error_message('datafile error406','data file access failed.');
		}
		print OUT @out;
		close OUT;
		rmdir($lockdir);
		
		if($language ne "English"){
			print "Noを元にソ\ート、Noを振りなおしました。デフォルトでNo順で表\示されるようになります。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "Sort by No. New NO. set.<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
		
	}
	elsif($mode eq "sort2"){
		
		&dirlock;
		if(!open(IN,"$datafile")){
			&error_message('datafile error419','data file access failed.');
		}
		@all=<IN>;
		close IN;
		
		@all=sort(@all);
		
		if(!open(OUT,">$datafile")){
			&error_message('datafile error425','data file access failed.');
		}
		print OUT @all;
		close OUT;
		rmdir($lockdir);
		
		if($language ne "English"){
			print "Noを元にソ\ートしました。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "Sort by No.<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
		
	}
	elsif($mode eq "list"){
		
		&master_list;
		
	}
	elsif( $mode eq 'trilist' ){
		require("trigger.pl");
		&def_trigger_list();
		print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=hidden name=mode value=tridel>";
		print "<table border=0 width=70%><tr bgcolor=$indexcolor><th nowrap>No.</th><th nowrap>Type</th><th nowrap>Admin</th><th nowrap>Member</th><th nowrap>Delete</th></tr>\n";
		if( !open( IN, "$triggerfile" ) ){
			&error_message( 'datafie error/system', 'trigger file access failed');
		}
		my ( $t_no, $t_type, $t_adm, $t_ent, @t_tris, @t_adm_list, @t_ent_list, @trigger );
		foreach my $r ( <IN> ){
			if( $r =~ /^#/ ){
				next;
			}
			$tempr = $r;
			$tempr =~ s/\s//g;
			if( $tempr eq "" ){
				next;
			}
			($t_no, $t_type, $t_adm, $t_ent, @t_tris) = split( /\t/,$r );
			$t_adm =~ s/\,/\, /g;
			$t_ent =~ s/\,/\, /g;
			print "<tr bgcolor=$otherdata><td nowrap>$t_no</td><td nowrap>$triggerdefname[$t_type]</td><td>$t_adm</td><td>$t_ent</td>";
			print "<td><input type=checkbox name=del_$t_no value=1></td></tr>\n";
		}
		close IN;
		print "<tr><td colspan=5><input type=submit value=Delete checked groups></td></tr></table><br>\n";
	}
	elsif( $mode eq 'tridel' ){
		require("trigger.pl");
		&def_trigger_list();
		if( !open( IN, "$triggerfile" ) ){
			&error_message( 'datafie error/system', 'trigger file access failed');
		}
		my ( $tt_no, $tt_type, $tt_adm, $tt_ent, @tt_tris );
		@alltri = <IN>;
		close IN;
		
		&dirlock;
		
		foreach my $r ( @alltri ){
			my $tmpr = $r;
			$tmpr =~ s/\s//g;
			if( $tmpr eq "" ){
				next;
			}
			($tt_no, $tt_type, @others ) = split( /\t/, $r );
			$str = "del_" . $tt_no;
			if( $FORM{ $str } != 1 ){
				push( @newtri, $r );
			}
			else{
				$del_no .= "$tt_no,";
			}
		}
		if(!open(OUT,">$triggerfile")){
			&header; &error_message('datafile error1560','trigger file access failed.');
		}
		print OUT @newtri;
		close OUT;
		rmdir($lockdir);
		chop( $del_no );
		if($language ne "English"){
			print "トリガーグループ $del_no を削除しました。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "Trigger deleted $del_no<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
	}
	elsif($mode eq "message"){
		$body =~ s/&lt;/</g;
		$body =~ s/&gt;/>/g;
		$name =~ s/&lt;/</g;
		$name =~ s/&gt;/>/g;
		
		
		if(!open(OUT,">message.tbl")){
			&error_message('message datafile error437','data file access failed.');
		}
		print OUT "$name\n$body\n";
		close OUT;
		
		if($language ne "English"){
			print "お知らせを書き換えました。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "Information changed<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
	}
	elsif($mode eq "header"){
		
		$body =~ s/&lt;/</g;
		$body =~ s/&gt;/>/g;
		
		if(!open(OUT,">header.html")){
			&error_message('message datafile error460','data file access failed.');
		}
		print OUT "$body\n";
		close OUT;
		
		if($language ne "English"){
			print "ヘッダーを書き換えました。<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='マスターモードへ戻る'></form>";
		} else {
			print "Header changed<BR>";
			print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='back to master'></form>";
		}
		
	} else {
		
		#ここにリストがあったお
		print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=hidden name=mode value=list><input type=submit value='Listup Members'></form>";
		print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=hidden name=mode value=trilist><input type=submit value='Listup Trigger Group'></form>";
		
		if(!open(IN,"message.tbl")){
			$osirase="no";
		}
		else {
			$osirase=<IN>;
			$osirase =~ s/\n//g;
			$osirase =~ s/\r//g;
			$osirasebody=<IN>;
			close IN;
		}
		$osirasebody =~ s/<BR>/\n/g;
		
		if(!open(IN,"header.html")){
			$header="no";
		}
		else {
			$headerbody=<IN>;
			close IN;
		}
		$headerbody =~ s/<BR>/\n/g;
		
		if($language ne "English"){
			print <<"EOM";
<HR>
<a name='config'>
設定ファイルを書き換えます<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=login>
<input type=submit name=mode value='config'></form>
表\示項目のカスタマイズ<BR>
<form method=post action=$script2>
<input type=hidden name=function value="login2">
<input type=hidden name=pass value="$gpass">
<input type=submit value="設定画面へ">
</form>
<HR>
<B>カスタムフィールド項目の編集・一括入力</B><BR>
EOM
if($#custom_field != -1){
print "<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=custom><input type=hidden name=mode value='list'><input type=submit value='CustomField'></form>";
} else {
print "カスタムフィールド利用前に下のバージョンアップ処理をしてください。<BR>";
}
print <<"EOM";
<HR>
<B>バージョンアップ処理</B><BR>
<BR>
バージョンアップ時には下のボタンを押してください。<BR>

(0.63→0.717)<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=verup><input type=submit name=mode value='0717'></form>
<BR>

(アルタナ／アトルガン対応拡張自動処理/0.60a3からのデータコンバート含む(0.5X&0.6X→0.702))<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=verup><input type=submit name=mode value='060'></form>
<BR>

setup.cgiアルタナ／アトルガン対応拡張'強制'処理(0.5X→0.702)上ボタンでうまくいかない場合はこちらをお試しください。<BR>
バージョン0.5扱いにして強制的に修正を行います。<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=verup><input type=submit name=mode value='060a'></form>
<HR>
<B>メンテナンス</B><BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=maintenance><input type=hidden name=mode value='ahtjob'><input type=submit value='maintenance'></form>
名前のないメンバーデータが追加された場合や、バージョンアップを行った場合はこの処理を行ってください。
<HR>
<B>並べ替え</B><BR>
<a name='sort'>
No順にソ\ート、Noを振りなおして、その順で書き込みます。<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=submit name=mode value='sort'></form>
<HR>
No順にソ\ート、Noを振りなおしません。<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=submit name=mode value='sort2'></form>
<HR>
<a name='backup'>
データのバックアップ<BR>
ファイル名は'bk$year$mon$mday.cgi'になります。バックアップボタンを押してください。<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=hidden name=name value='bk$year$mon$mday.cgi'><input type=submit name=mode value='backup'></form>
<HR>
<a name='info'>
お知らせの表\示<BR>
お知らせの文章を入れてください。タグも使えますが、タグの閉じ方が悪いと表\示がおかしくなることがあります。<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
お知らせのタイトル（なしで表\示しません）<BR>
<input type=text name=name size=80 value='$osirase'><BR>
お知らせの文章<BR>
<textarea name=body rows=5 cols=60>$osirasebody</textarea><BR>
<input type=submit name=mode value='message'></form>
<a name='header'>
画面上部へ表\示したいhtmlを追加してください。<BR>
タグも使えますが、タグの閉じ方が悪いと表\示がおかしくなることがあります。<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
画面上部追加内容（BRタグが行末に自動追加されます)<BR>
<textarea name=body rows=5 cols=60>$headerbody</textarea><BR>
<input type=submit name=mode value='header'></form>
EOM
			print "<a href=$script?$salt>[登録システム入り口]</a><a href=$script?function=faq>[使い方]</a><a href='$homepage'>[ホームページへ戻る]</a><BR>";
		}
		else {
			print <<"EOM";
<HR>
<a name='config'>
Change Memberlist Configuration<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=login>
<input type=submit name=mode value='config'></form>
Customize<BR>
<form method=post action=$script2>
<input type=hidden name=function value="login2">
<input type=hidden name=pass value="$gpass">
<input type=submit value="Customize">
</form>
<HR>
<B>CustomField customize or input</B><BR>
EOM
			if($#custom_field != -1){
				print "<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=custom><input type=hidden name=mode value='list'><input type=submit value='CustomField'></form>";
			}
			else {
				print "Push version up button before using CustomField function.<BR>";
			}
			print <<"EOM";

Version UP0.5X&0.60X ->0.61<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=verup><input type=submit name=mode value='060'></form>
set version 0.5 mode (0.5X&0.60X -> 0.61)<BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=verup><input type=submit name=mode value='060a'></form>
<HR>
<B>Maintenance</B><BR>
<form method=post action=$script2><input type=hidden name=pass value='$gpass'><input type=hidden name=function value=maintenance><input type=hidden name=mode value='ahtjob'><input type=submit value='maintenance'></form>
Blank User deleting function, and modifying Aht urgan new job data.
<HR>
<a name='sort'>
Sort by No. and New No. set<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=submit name=mode value='sort'></form>
<HR>
Sort by No.<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=submit name=mode value='sort2'></form>
<HR>
<a name='backup'>
Backup list data<BR>
Filename : 'bk$year$mon$mday.cgi'<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
<input type=hidden name=name value='bk$year$mon$mday.cgi'><input type=submit name=mode value='backup'></form>
<HR>
<a name='info'>
Information<BR>
Input message(you can use HTML tag for this message)<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
Information title<BR>
<input type=text name=name size=80 value='$osirase'><BR>
Information message<BR>
<textarea name=body rows=5 cols=60>$osirasebody</textarea><BR>
<input type=submit name=mode value='message'></form>
<a name='header'>
header html( you can use HTML tag for header HTML)<BR>
<BR>
<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value='$gpass'><input type=hidden name=function value=master>
header html<BR>
<textarea name=body rows=5 cols=60>$headerbody</textarea><BR>
<input type=submit name=mode value='header'></form>
EOM

			print "<a href=$script?$salt>[List Top]</a><a href=$script?function=faq>[Usage]</a><a href='$homepage'>[back to home]</a><BR>";
		}
	}
}

sub master_list{

	if(!open(IN,"$datafile")){
		&error_message('datafile error446','data file access failed.');
	}
	@all=<IN>;
	close IN;
	
	if($sort ne ""){
		&sort_table;
	}
	print "<table border cellpading=0 cellspacing=0 width=100%><TR bgcolor=$indexcolor><TH width=5%>no</TH><TH width=10%><a href='$script?function=master&gpass=$gpass&sort=15'>class</a></TH><TH width=10%><a href='$script?function=master&gpass=$gpass&sort=1'>name</a></TH><TH>pass</TH>";
	print "<TH width=5%><a href='$script?function=master&gpass=$gpass&sort=16&mode=r'>time</a></TH><TH>edit</TH></TR>";
	$count=0;
	foreach $i(@all){
		($no,$name,$pass,$anon,$race,$relm,$mainjob,$supportjob,$prof,$handle,$polhn,$mail,$home,$comment2,$point,$class,$time,$comment,$mrank,$etc[0],$etc[1],$etc[2],$prod[0],$prod[1],$prod[2],$prod[3],$prod[4],$prod[5],$prod[6],$prod[7],$prod[8],$prod[9],$prod[10],$prod[11],$prod[12],$prod[13],$prod[14],$prod[15],$lev[0],$lev[1],$lev[2],$lev[3],$lev[4],$lev[5],$lev[6],$lev[7],$lev[8],$lev[9],$lev[10],$lev[11],$lev[12],$lev[13],$lev[14],$lev[15],$lev[16],$lev[17],$lev[18],$lev[19])=split(/\t/,$i);
		if($count==$c_max){
			print "</table><BR><table border cellpading=0 cellspacing=0 width=100%><TR bgcolor=$indexcolor><TH width=5%>no</TH><TH width=10%>class</TH><TH width=10%>name</TH><TH>pass</TH><TH>time</TH><TH>edit</TH></TR>";
			$count=0;
		}
		print "<TR><TD>$no</TD><TD>$class</TD><TD>$name</TD><TD>$pass</TD>";
		print "<form method=post enctype='multipart/form-data'  action=$script><TD>$time</TD><TD><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=hidden name=name value=$name>check<input type=checkbox name=anon value=on> <input type=submit name=mode value='delete'><input type=submit name=mode value='edit'></TD></form></TR>";
		$count++;
	}
	print "</table>";
	print "<form method=post enctype='multipart/form-data'  action=$script><input type=hidden name=gpass value=$gpass><input type=hidden name=function value=master><input type=submit value='Back to MasterTop'></form>";
}

1;
