#!/usr/bin/perl
# Copyright Shigeru Uchida 2006/09/04
$|=1;
@argh=split(/\+/,$ENV{'QUERY_STRING'});
if($argh[0]=~/^spl:/){$areapl="+$argh[0]"}
require "whats_set$'.pl";
$EN_DOC=~s/(\\|\/)$//;
$host_url=~s/(\\|\/)$//;
$adbsw=$hikisu='';
$OPT{'test'}=0;
&hikisu;
if($cgi1!~/\// && $cgi2=~/(.+)\//){$cgi1="$1/$cgi1"}
if($areapl){$areapl=substr($areapl,1).'+'}
if($ENV{'HTTP_USER_AGENT'}=~/DoCoMo|J-PHONE|ASTEL|UP\.Browser|KDDI|PDXGW|L-mode/i || defined $FORM{'mb'}){$imode=$icode}
# フォーム内容を取得
if($ENV{'REQUEST_METHOD'} eq 'POST'){
	read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
	if($buffer){
		$buffer=~ tr/+/ /;
		@datas=split('&',$buffer);
		foreach $data (@datas) {
			$data=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
			($name,$value)=split('=',$data,2);
			if($name eq 'genre'){$whatsid=$value}
			elsif($name eq 'sort'){$SO_SW=$value}
			elsif(index($name,'sort_')>=0){$SO_SW.=$value}
			elsif($name eq 'base'){$OPT{'base'}=$value}
			elsif($name eq 'pfix'){$set_htmlout=$value;$mak_sw=1}
			else{
				if(defined $FORM{$name}){$FCNT{$name}++;$FORM{"$name$FCNT{$name}"}=$value}
				else{$FORM{$name}=$value}
			}
			if($name=~/^custom_no(\d+)$/ && $1>$max_s){$max_s=$1}
		}
		for($i=1;$i<=$max_s;$i++){
			if($FORM{"custom_no$i"} eq ''){next}
			if(!defined $FORM{"how$i"}){$FORM{"how$i"}='!ct!'}
			$ckey_h.=$FORM{"custom_no$i"}.$FORM{"how$i"}.$FORM{"value$i"}.(defined $FORM{"mvalue$i"} ? '/'.$FORM{"mvalue$i"}:'').(defined $FORM{"dvalue$i"} ? '/'.$FORM{"dvalue$i"}:'');
			if(defined $FCNT{"value$i"}){
				for($i1=1;$i1<$FCNT{"value$i"}+1;$i1++){
					$ckey_h.='!or!'.$FORM{"custom_no$i"}.$FORM{"how$i"}.$FORM{"value$i$i1"}.(defined $FORM{"mvalue$i$i1"} ? '/'.$FORM{"mvalue$i$i1"}:'').(defined $FORM{"dvalue$i$i1"} ? '/'.$FORM{"dvalue$i$i1"}:'');
				}
			}
			$i1=$i+1;
			if(defined $FORM{"custom_no$i1"}){$ckey_h.=$FORM{"plus$i1"} ? $FORM{"plus$i1"}:'!and!'}
		}
	}
}
if(defined $whatsplus){$whatsnew.=$whatsplus}
$host_url='';
if($host_url){$host_url="http://$host_url"}
if($ENV{'SCRIPT_NAME'}=~/$os_sepa(\~[^\/\\]+)$os_sepa/){$host_url.="/$1"}
$from_doc.="$whatsnew/";
$gpath="$host_url$from_doc";
if($OS){$os_sepa="\/";$os_sepax="/"}
else{
	$os_sepa="\\\\"; $os_sepax="\\";
	$dir_base=~s/\//$os_sepax/g;
}
#  このパスの下に各ジャンルのディレクトリが作成されます
$dpath=$ghdpath="$dir_base$whatsnew$os_sepax";
if(defined $FORM{'pass'}){
	@argh=split(/\+/,$FORM{'hikisu'});
	&hikisu;
	&passchk;
	$nopass=1;
}
$ENV{'TZ'}='JST-9';
@datex=localtime(time);
$datex[4]++;
if($datex[5]<200){$datex[5]=$datex[5]+1900}
$today=sprintf("%d/%02d/%02d",$datex[5],$datex[4],$datex[3]).sprintf("%02d:%02d",$datex[2],$datex[1]);
&FILE_SET;
if(defined $set_htmlout){&setfile_read}
if($k_htsw>0){$Xgpath='_img/';$xXgpath=$Xgpath}
elsif(defined $mak_sw){&outhtml_H0;$Xgpath=$chkhtml.'_img/';$xXgpath=$Xgpath}
if($whatsid){&dataread}
else{
	if($OPT{'base'} eq ''){&err('01 正しい引数を指定してください！')}
	$menu_sw=1;
}
$n= $imode ? '':"\n";
if($out_htmlsw){
	$k_htsw=2;$ckey_h="$h_id!eq!$out_htmlsw";
	&menu_job;
	$wmm_w=&hmake_end;
	if(($owner ne $whatsid) || ($h_mother && $h_mother ne '_$_')){
		undef %OTB;undef @recda;undef @recda1;$whatsid= $owner ne $whatsid ? $owner:$h_mother;$ocnt=0;
		&FILE_SET; &sw_reset; &dataread; &dataread1;
		&menu_job;
	}
	&err("$wmm_w<br>".&hmake_end);
}
if($recno eq ''){&menu_job}
else{&syousai_job}
exit;

sub hmake_end {
	return "<span $FONT>HTMLファイルを作成しました！（$whatsid）　[<a href=\"$host_url$chkhtml\">確認する</a>] $w1<br>$wmm</span>";
}

sub menu_job {
	$ixcnt=0;
	if(defined $S_pchk){
		if(($h_pass>0 && $h_pass<4) && $k_htsw==0 && !defined $nopass){&passin}
	}
	elsif($h_pass==2){&passin}
	&menu_gra(*mcust_buf);
	@mcust=split("\t",$mcust_buf);
	&sethiki;&dataread1;
	$whatsida=$whatsid;
	$mken=1;
	if($k_htsw>0){
		&outhtml_H0;
		$wmm='<table border=0><tr><td>';
		$wmmg='<hr><b>Moved</b><br>';
		if($k_delsw){$h_outhtml1=~s/.*$os_sepa//}
		if($k_htsw==4){$hikisu=~s/\+?hdel(\+?)/$1/;$hikisu=~s/\+?(htmldirs|hindex|htmldir|$COMOUT):[^\+]+//g}
		$chkhtml.=$k_index;
	}
	&menu_job_x;
	if($k_htsw>0 && defined $OPT{'max'} && $lastsw){
		while(@okrec>$start_mark){
			push(@index_d,$dw_out);
			$mken=1;
			$lsw++;
			$OPT{'start'}=$OPT{'max'}*$lsw+1;
			$start_mark=$start_mark+$OPT{'max'};
			$whatsid=$whatsida; undef $nwhatsid;
			&menu_job_x;
		}
	}
	&outhtml_H;
}

sub menu_job_x {
	$hfile=&baseread($h_html);
	if(defined $inp_menu && !$imode){
		if($hfile=~/$os_sepa/){$hfile=~s/(.*$os_sepa).*/$1_input_select_temp.html/}
		else{$hfile='_input_select_temp.html'}
	}
	$lastsw=$lcnt=0;
	$dw_out='';
	if($OPT{'test'}==1 && !$imode && $java_sw){
		$wunder='<input type=button value="編集画面に戻る" onclick="window.close()">';
	}
	foreach(@dataz){
		&pers_rep;
		if(index($_,'<!--')>=0){
			if($_=~/(.*)<!--(loop|Gmenu)[ :]?(\d*)[ :]?([^\?> #:]*)[ :]?(#)?([^> \?:]*)[ :]?(\?)?([^> \?]*)-->(.*)/){
				if(&loop_job){$lcnt++}
				next;
			}
			elsif($_=~/<!--([^> ]*) ?page ?(.*?)-->/){
				if(defined $OPT{'max'}){
					if(&page($`,$1,$2,$')){$dw_out.="$_$n"};
				}
				next;
			}
			elsif(index($_,'<!--continue')>=0){
				if(defined $OPT{'max'} && $lastsw){&continue}
			}
			elsif(@UPD=$_=~/(.*)<!--(upday)(%?)[ :]?(.*?)-->(.*)/){&rep_date}
			elsif($_=~s/<!--#(.*?)-->// && $1 ne $whatsid){next}
			elsif($_=~s/<!--menu_title-->//){$menu_title=$_;next}
			elsif($_=~s/<!--no_data-->//){$no_data=$_;next}
			else{
				if($_=~s/<!--title(\*?)-->/$fir_title/ && $1 && $fir_title eq ''){next}
				if($_=~/<!--comment\*?-->/){
					if(!defined $fir_comment && defined $no_data){$_=~s/<!--comment\*?-->/$no_data/}
					elsif($_=~s/<!--comment(\*?)-->/$fir_comment/ && $1 && $fir_comment eq ''){next}
				}				if($_=~s/<!--comment(\*?)-->/$fir_comment/ && $1 && $fir_comment eq ''){next}
			}
			&custom('m');
			&set_gra_kizi;
		}
		elsif($_=~/<meta/i){&meta_check}
		if($_ ne ''){$dw_out.="$_$n"}
	}
}

sub pers_rep {
	if($auto_sw){&link_html}
	$_=~s/%genre%/$whatsid/g;
	$_=~s/%replace%/$OPT{'rep'}/g;
	$_=~s/%owner%/$owner/g;
	$_=~s/%img_path%/$Xgpath/g;
	if(defined $wunder){
		if($_=~s/<!--test-->/$wunder/){$ntest_sw=1}
		if(!defined $ntest_sw){$_=~s/(<\/body)/<br><center>$wunder<\/center>$1/i}
#		$_=~s/(< *body.*>)/$1$wunder<br>/i;
	}
}

sub loop_job {
	if($lcnt>0){undef $ckey; undef $SO_SW; undef $FORM{'search'}; delete $OPT{'start'}}
	$qbef=$1;$loop=$3;$nwhatsid=$4;$qhon=$9;$ihiki=$ihiki1=$8;$qaf='';
	if($5 eq '#'){$ckey=$6}
	if($loop==0){$loop++}
	elsif($qhon=~/<!--endt(.*?)-->/){$qhon=$`;$qaf=$';$qhon1=$1}
	$w2=$_;
	if($ihiki1){&sethiki}
	if(!defined @newshead){&dataread1}
	if($nwhatsid ne ''){
		if($nwhatsid ne $whatsid || defined $ckey || defined $SO_SW || defined $FORM{'search'}){
			$whatsid=$nwhatsid;
			if(defined $ckey && $lcnt==0){}
			else{&sw_reset}
			&FILE_SET;
			&dataread;
			&menu_gra(*mcust_buf);
			@mcust=split("\t",$mcust_buf);
			if($ihiki1){&sethiki}
			&dataread1;
		}
		elsif($lcnt>0){
			if($ihiki1){&sethiki}
			&dataread2;
		}
	}
	elsif(defined $ckey || $menu_sw){&dataread2}
	if($menu_sw){
		$w2=~s/<!--(loop|Gmenu).*?-->//;
		$w2=~s/#cnt(0?)/$max/;
		if($1 eq '0' && $max==0){return 0}
		$w1="$cgi2\?id:$whatsid";
		if($ihiki1){$w1.="+$ihiki1"}
		if(defined $ckey){$w1.="+filter:$ckey_url"}
		$w2=~s/#cgi/$w1/;
		$w2=~s/#date/(substr($now_new,0,10))/e;
		$w2=~s/#time/(substr($now_new,11))/e;
		$dw_out.="$w2$n";
		return 1;
	}
	$loopz=$loop;
	if(!defined $start_mark){$start_mark=0}
	$cnt11=0;
	for($cnt1=$start_mark;$cnt1<@okrec;$cnt1++){
		if($cnt11++==0 && defined $menu_title){$dw_out.=$menu_title}
		($cnt,$edate)=$okrec[$cnt1]=~/(\d*),(.*)/;
		$a=$newshead[$cnt];
		&bunkai;
		&chk_owner;
		if(defined $OPT{'max'} && $OPT{'max'}<$cnt11){$lastsw=1;last}
		if($loopz==$loop){$dw_out.=$qbef}
		$wfn='';
		if($charset && !$engsw){&jcode::convert(\$title,$charset)}
		@D_D=&brdate($h_datem,$rdate);
		$_=$qhon;
		if(@UPD=$_=~/(.*)<!--(date)(%?)[ :]*(.*?)-->(.*)/){&rep_date}
		if(&daycheck){next}
		&rep_newmark;
		$errgra=defined $ERRGRA{$cnt1} ? &errgra($cnt1):'';
		if($inp_menu){
			$edate=~s/[\/ :]//g;
			if(defined $baseh_sw1 && $cgi!~/\\|\//){
				$cgi2=~/(.*\\|.*\/)/;
				$w2="$1$cgi";
			}
			else{$w2=$cgi}
			$wfn="$w2?$COM$inp_menu:$whatsid:$edate:$inp_id".($imode ? '+i':'');
			$target='';
			if($title=~s/< *a *href *\=[^>]+>/<a href=$wfn>/){$_=~s/<!--title%?-->/$errgra$title/g}
			$wfnx='##';
		}
		else{
			if($title=~/\< *a *href *\=/i){$_=~s/<!--title%?-->/$errgra$title/g}
			$target=$window;
		}
		if($url=~/$DV/){$url=$`}
		($url_1,$url_2,$url_target)=$url=~/^(https?:\/\/|\?)(\S*) ?(.*)/;
		$wh_link=$h_link;
		if(defined $nolink){$_=~s/<!--title%?-->/$errgra$title/g}
		elsif($wh_link<3){
			if($wh_link==0 || ($wh_link==2 && $comment eq '')){$_=~s/<!--title%?-->/$errgra$title/g}
			else{
				if($wfn eq ''){&setwfnx}
				if($k_htsw>0 || defined $mak_sw){&hdata_up('',$cnt)}
				$wfnx=~s/##/$wfn/g;
				$_=~s/<!--title%?-->/$errgra<a href=$wfnx>$title<\/a>/g;
				$_=~s/<!--link-->/$wfnx/;
			}
		}
		else{&linkh}
		if(index($_,'<!--comment')>=0){
			$comment=~s/<>//g;
			$_=~s/<!--comment%?-->/$comment/;
		}
		&custom('');
		$_=~s/<!--title!?-->/$title/g;
		if(--$loopz>0){$sw_n=1;$dw_out.=$_;next}
		$dw_out.="$_$qaf$n";
		$loopz=$loop;
		&set_gra_kizi;
		$sw_n=0;
	}
	if(!$cnt11){$dw_out.=$no_data}
	undef $menu_title; undef $no_data;
	if($sw_n==1){
		for($i=0;$i<$loopz;$i++){$dw_out.="$qhon1$n"}
		$dw_out.="$qaf$n";
	}
	return 1;
}

sub syousai_job {
	@mcust=split("\t",$mcust_buf);
	if($h_pass==1 && !defined $nopass){if(&getCookie==2){$nopass=1}}
	if(defined $ckey_h){$ckey=$ckey_h}
	&sethiki;&dataread1;
	for($cnt1s=0;$cnt1s<@okrec;$cnt1s++){
		($cnt,$edate)=$okrec[$cnt1s]=~/(\d*),(.*)/;
		$a=$newshead[$cnt];
		$wh_link=$h_link;
		&bunkai;
		if(!$adbsw){$hikaku=$edate}
		else{
			if($adbsw eq 'd' || $h_id eq ''){$hikaku=$edate}
			elsif($h_id eq '0'){$hikaku= $h_datem eq '*' ? substr($edate,0,23) : $rdate}
			else{$hikaku=$cust[$h_id-1]}
		}
		if($hikaku eq $recno){
			$hsfile=&baseread($h_htmls,'s');
			&chk_owner;
			&k_pass;
			if($imode){
				&syousai_i;
				if($h_log && !$OPT{'test'}){&log_out}
				&html_out;
			}
			if($url=~/$DV/){$url=$`}
			($url_1,$url_2,$url_target)=$url=~/^(https?:\/\/|\?|\d+)(\S*) ?(.*)/;
			if($wh_link<6){
				if($wh_link>2 && $url_2){&location($url_1,$url_2,$url_target)}
				if($title=~/\< *A *HREF *\=\"?(.+)\"? ?>?/i){print "Location: $1\n\n"}
				if($comment=~/^(https?:\/\/|\?|$os_sepa[\w~])([^ ]*) ?(.*)/){&location($1,$2,$3)}
				&syousai1(*comment);
				if(defined $gpdf){print "Location: $xXgpath$gpdf\n\n"}
				&syousai2;
				@D_D=&brdate($h_datem,$rdate);
				&syousai3($cnt,$edate);
				if($h_log && !$OPT{'test'}){&log_out}
				&html_out;
			}
		}
	}
	$dw_out="<html><head>$n<title></title></head><body bgcolor=#FFFFFF><br><center>$n指定したデータ（$recno）は見つかりませんでした！</center></body></html>$n";
	if(!$imode && $h_log && !$OPT{'test'}){&log_out}
	&html_out;
}

sub sethiki {
	if($ihiki ne ''){
		if($ihiki=~s/filter:([^\+:]*)\+?//){$ckey=$1}
		if($ihiki=~s/sort:([\dncBS]+)\+?//){$SO_SW=$1}
		if($ihiki=~s/new:([^\+:]*)\+?//){$OPT{'new'}=$1}
		if($ihiki=~s/max:([^\+:]*)\+?//){$OPT{'max'}=$1}
		if($ihiki){@argh=split(/\+/,$ihiki);&hikisu}
	}
	if(!defined $ckey && defined $ckey_h){$ckey=$ckey_h}
	if($ckey ne ''){
		$ckey_url=$ckey;
		if($ckey!~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg){$ckey_url=~s/(\W)/'%'.unpack('H2',$1)/eg}
	}
	if($FORM{'search'} ne ''){
		$ser_url=$FORM{'search'};
		if($FORM{'search'}!~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg){$ser_url=~s/(\W)/'%'.unpack("H2",$1)/eg}
	}
}

sub k_pass {
	if($h_pass>1 && $k_htsw==0){
		if($h_pass==2){if(&getCookie!=2){&passin}}
		elsif(index($nsw,'P')>=0){
			if($h_pass==4){if(!defined $nopass){&passin}}
			elsif($h_pass==3){if(&getCookie!=2){&passin}}
		}
	}
}

sub daycheck {
	if(defined $OPT{'day'}){
		if($limit){
			if(length($limit)==7){$limit.='/01'}
			elsif(length($limit)==4){$limit.='/01/01'}
			$dw1=substr($limit,0,10);
		}
		else{$dw1=substr($edate,0,10)}
		if($OPT{'day'} gt $dw1){return 1}
	}
	return 0;
}

sub rep_newmark {
	my $rnew;
	if(defined $OPT{'new'} && $h_new && $_=~/<!--new ?(\d*),?(\d*)-->/){
		if($limit){
			if(length($limit)==7){$limit.='/01'}
			elsif(length($limit)==4){$limit.='/01/01'}
			$dw1=substr($limit,0,10);
		}
		elsif($h_datem eq '*'){$dw1=$rdate}
		else{$dw1=substr($edate,0,10)}
		if($OPT{'new'} le $dw1){
			if($1){$rnew="<!--Custom$1-->"}
			elsif($h_newg=~/\.(gif|jpg|png|bmp)$/){$rnew=" <img src=$xXgpath$h_newg> "}
			else{$rnew= $h_newg eq '' ? '<font color=red><i><b>New!</font></b></i>':$h_newg}
		}
		else{$rnew= $2 ? "<!--Custom$2-->":''}
	}
	$_=~s/<!--new[^\-]*-->/$rnew/;
}

sub rep_date {
	my(@dated);
	if($UPD[1] eq 'upday'){@dated=&brdate('*',$mdate)}
	else{@dated=@D_D}
	if($dated[0] eq ''){$_=$UPD[0].($UPD[2] ? '<br>':'').$UPD[4];return}
	if($UPD[3]){
		$UPD[3]=~s/year/$dated[4]/;
		$UPD[3]=~s/wareki/$dated[1]/;
		$UPD[3]=~s/month_e/$dated[3]/;
		$UPD[3]=~s/month/$dated[5]/;
		$UPD[3]=~s/day/$dated[6]/;
		$UPD[3]=~s/hour/$dated[7]/;
		$UPD[3]=~s/minute/$dated[8]/;
	}
	else{$UPD[3]=$dated[0]}
	$_="$UPD[0]$UPD[3]$UPD[4]";
}

sub setwfnx {
	if(($gra)=$grap=~/\d+\/([^\/]+)\/.*\/title/i){
		if($gra!~/\.pdf$/i){$window=''}
		$wfn="$xXgpath$gra";
	}
	else{
		if($comment=~s/^(https?:\/\/|\?|$os_sepa[\w~])(\S*) ?(.*)//){
			if($1 eq '?'){
				$wfn="$cgi2?$areapl$2$hikisu".($imode ? '+i':'');
				&select_set;
			}
			else{$wfn="$1$2"}
			if($3 && $target eq ''){$target=$3}
		}
		else{
			if(($k_htsw==0 || $k_htsw==4) && !defined $mak_sw){
				$wfn="${cgi2}?${areapl}id:$whatsid+rec:".($edate).$hikisu.($imode ? '+i':'');
				&select_set;
			}
		}
	}
	&targetset;
}

sub select_set {
	if(defined $ckey){$wfn.="+filter:$ckey_url"}
	if($SO_SW){$wfn.="+sort:$SO_SW"}
	if($FORM{'search'}){$wfn.="+search:$ser_url"}
	if(index($wfn,'mid:')<0){
		if($whatsida eq ''){$whatsida=$whatsid}
		$wfn.= $mid ? "+mid:$mid":"+mid:$whatsida";
	}
	$wfn=~s/\+(\++)/\+/g;
}

sub dispcheck {
	if($adbsw ne 'x'){
		if($h_mother_sw && $owner ne $whatsid){return 1}
		if(defined $OPT{'start'} && $OPT{'start'}==$cnt+1 && !defined $lsw){$start_mark=$cnt}
		if(defined $ckey){
			my($qcnt,$acnt,$q0,$q2,$q3,$q4,$qe4,$wq);
			$_= $ckey ? "$ckey!and!":'';
			while($_=~s/(\d+)(=|!eq!|!ne!|!n?ct!|![GglL][te]!)(.*?)(!or!|!and!|\&|\|)//){
				$q2=$2;$q3=$3;$q4=$4;
				if($q3 eq ''){$qcnt++}
				else{
					if($1){
						$wq=$cust[$1-1];
						if(substr($h_custm[$1-1],0,1) eq 's'){$wq=~s/<>.*//}
					}
					else{$wq="$rdate $title $comment $idata $cus_buf"}
					if($q3=~/_(\d+)_/){
						$q3=$cust[$1-1];
						if(substr($h_custm[$1-1],0,1) eq 's'){$q3=~s/<>.*//}
					}
					if($q2 eq '=' || $q2 eq '!eq!'){if($wq eq $q3){$qcnt++}}
					elsif($q2 eq '!ne!'){if($wq ne $q3){$qcnt++}}
					elsif($q2 eq '!ct!'){if(index($wq,$q3)>=0){$qcnt++}}
					elsif($q2 eq '!nct!'){if(index($wq,$q3)<0){$qcnt++}}
					elsif($q2 eq '!gt!'){if($wq>$q3){$qcnt++}}
					elsif($q2 eq '!Gt!'){if($wq gt $q3){$qcnt++}}
					elsif($q2 eq '!ge!'){if($wq>=$q3){$qcnt++}}
					elsif($q2 eq '!Ge!'){if($wq ge $q3){$qcnt++}}
					elsif($q2 eq '!lt!'){if($wq<$q3){$qcnt++}}
					elsif($q2 eq '!Lt!'){if($wq lt $q3){$qcnt++}}
					elsif($q2 eq '!le!'){if($wq<=$q3){$qcnt++}}
					elsif($q2 eq '!Le!'){if($wq le $q3){$qcnt++}}
				}
				if($q4 eq '!and!' || $q4 eq '&'){
					if($acnt>0){
						$q0= $qe4 eq '!or!' || $qe4 eq '|' ? 0:1;
						if($qcnt<=$q0){return 1}
						$acnt=$qcnt=1;
					}
					else{
						$acnt++;
						if($qcnt==0){return 1}
						$qcnt=1;
					}
				}
				else{
					if($acnt>0){
						if($qcnt!=2){return 1}
						$acnt=$qcnt=1;
					}
					if($qcnt>1){$qcnt=1}
				}
				$qe4=$q4;
			}
#			if($_){return 1}
		}
	}
	if(defined $FORM{'search'}){
		$SEARCH="$rdate $title $comment $idata $cus_buf";
		if($orand){foreach(@SKEY){if(index($SEARCH,$_)<0){return 1}}}
		else{
			$sfind=0;
			foreach(@SKEY){if(index($SEARCH,$_)>=0){$sfind=1;last}}
			if($sfind==0){return 1}
		}
	}
	for($i=0;$i<length($_[0]);$i++){if(index($nsw,substr($_[0],$i,1))<0){$errgra.=substr($_[0],$i,1)}}
	if(defined $OPT{'date'} && $rdate!~/^$OPT{'date'}/){$errgra.='S'}
	if($limit && $limit gt substr($today,0,length($limit))){$errgra.='B'}
	if($limit1 && $limit1 lt substr($today,0,length($limit1)) && !defined $OPT{'nolimit'}){$errgra.='A'}
	if($OPT{'test'}==0 && $errgra && $adbsw ne 'x'){return 1}
	if($h_pass==3 && index($nsw,'P')>=0){
		if(!defined $nopass && &getCookie!=2){return 1}
	}
	return undef;
}

sub html_out {
	$dw_out.="<!--$ver-->";
	#print "Content-Type: text/html; charset=Shift_JIS\n";
	if($imode){
		if($I_hk){require $jcpath;&jcode'z2h_sjis(\$dw_out)}
		print 'Content-Length: ',length($dw_out),"\n";
	}
	print"\n$dw_out";
	exit;
}

sub hdata_up {
	if($wfn){push(@recda,"*,$whatsid,$wfn,")}
	else{
		if($h_id eq '0' && $rdate){
			if($h_datem eq '*'){$wfn.=substr($rdate,0,19);$wfn=~s/[\/ :]//g}
			else{$wfn.=$rdate}
		}
		elsif($h_id>0){
			if($cust[$h_id-1]){$wfn.=$cust[$h_id-1]}
			else{$wfn.=$edate;$wfn=~s/[\/ :]//g}
		}
		elsif($h_id eq '' || $wfn=~/[^\w\/\._\-$os_sepa]/){
			$wfn.= $h_datem eq '*' ? $rdate : $edate;
			$wfn=~s/[\/ :]//g;
		}
		if($_[0] ne ''){
			if(!defined $OTB{"$wfn$_[0]"}){
				$OTB{"$wfn$_[0]"}=++$ocnt;
				$wfn.='_'.$OTB{"$wfn$_[0]"}."$imode$khtml";
				push(@recda1,"$_[1],$whatsid,$wfn,$_[0]");
			}
			else{$wfn.='_'.$OTB{"$wfn$_[0]"}."$imode$khtml"}
		}
		else{
			$wfn.="$imode$khtml";
			push(@recda,"$_[1],$whatsid,$wfn,");
		}
		$wfn=(defined $baseh_sw ? $baseh_sw:'').(defined $mak_sw ? $chkhtml:'')."$k_hdirs$wfn";
	}
}

sub targetset {
	$wfnx='"##"';
	if($target ne ''){$wfnx.=($java_sw && $target!~s/^f=//i ? " target=$target onclick=\"JavaScript:window.open('##','$target'".($wwidth ? ",'$wwidth'":'').');return(false)"':" target=$target")}
}

sub outhtml_H0 {
	if($k_index=~s/(.*)(\\|\/)// && $k_hdir eq ''){$k_hdir=$1}
	if(substr($k_hdir,0,1) eq '/' || $k_hdir=~/^[a-zA-Z]:/){$odpath=$k_hdir;$hto=1}
	else{$odpath="${Xhpath}html$os_sepax$k_hdir"}
	$odpath=~s/$os_sepa$os_sepa+/$os_sepax/;
	$gmove_dir=$odpath.($odpath=~/$os_sepa$/ ? '':$os_sepax).'_img';
	$odpath.= $odpath=~/$os_sepa$/ ? '':$os_sepax;
	if($k_hdirs){
		my $wo1="$odpath$k_hdirs";
		$gmove_dirs=$wo1.($wo1=~/$os_sepa$/ ? '':$os_sepax).'_img';
		if($k_hdirs!~/$os_sepa$/){$k_hdirs.=$os_sepax}
		$hdirs1=$k_hdirs;
		$k_hdirs=~s/$os_sepa/\//g;
		$cntg=$k_hdirs;
		$idxback='';
		while($cntg=~s/\///){$idxback.='../'}
	}
	$cntg=0;
	$h_outhtml1="$odpath$k_index";
	$chkhtml=$odpath;
	if(!$OS){$chkhtml=~s/$os_sepa/\//g}
	if(defined $hto){$chkhtml=~s/$EN_DOC//}
	else{
		if($chkhtml=~/$from_doc(.*)/){$chkhtml="$from_doc$1"}
		elsif($chkhtml=~/$whatsnew\/(.*)/){$chkhtml="$from_doc$1"}
	}
}

sub outhtml_H {
	if($k_htsw>0){
		my($i,$i1);
		if($k_htsw==1 || $k_htsw==3 || $k_htsw==4){
			$wmmx='';
			$wmm.="<hr><b>Maked Menu ($odpath)</b><br>";
			if(!defined @index_d){push(@index_d,$dw_out)}
			my($mae,$ato)=$k_index=~/([^\.]+)(\.html?)$/i;
			for($i=0;$i<@index_d;$i++){
				$i1= $i ? "$mae$i$ato":"$mae$ato";
				&out_del_c($odpath);
				&open_file('OUT',">$odpath$i1",'01','HTML');
				print OUT $index_d[$i];
				close(OUT);
				$wmm.=($i % 2) ? " <font color=#1E9557>$i1</font>":" $i1";
			}
			$wmm.=$wmmx;
		}
		$wmmx='';
		if($k_htsw>1 && $k_htsw<4){
			&shtml;
			if(@recda1){@recda=@recda1;&shtml}
		}
		$w1='';
		if(!$imode && $h_imode==1){
			$w1="[<a href=\"${cgi2}?";
			foreach (@argh){$w1.=$_.'+'}
			$w1.="i\">携帯 メニューを作成</a>]";
		}
		$wmm.=$wmmx.($k_htsw==2 || $k_htsw==3 ? $wmmg:'')."</td></tr></table>$n";
		if(!$out_htmlsw){&err(&hmake_end)}
	}
	else{
		if($h_log && !$OPT{'test'}){&log_out('menu')}
		&html_out;
	}
}

sub del_allfile {
	my($wkdir,$wkaku,$iwk)=@_;
	opendir(DIR,$wkdir);
	$iwk= $iwk ? $icode : '';
	$wmmx.='<hr><b>Deleted</b><br>';
	my($cnt)=0;
	foreach(readdir(DIR)){
		if(substr($_,0,1) eq '.' || $_ eq $h_outhtml1){next}
		if($wkaku && $_!~/$iwk\.$wkaku?/){next}
		if(! -d "$wkdir$_"){
			$wmmx.= $cnt++%2 ? " <font color=#1E9557>$_</font>" : " $_";
			if(! unlink "$wkdir$_"){$wmmx.='(<font color=red>*</font>)'}
		}
	}
	close(DIR);
}

sub shtml {
	if(@recda){$whatsid=''}
	my $soutdir=$odpath.($odpath=~/$os_sepa$/ ? '':$os_sepax).$hdirs1;
	$soutdir=~s/$os_sepa$os_sepa+/$os_sepax/;
	$wmm.="<hr><b>Maked ($soutdir)</b><br>";
	my($cnth,$i1,$nwhatsid,$htmlf,$kbase);
	$recno=1;
	$rec=@recda;
	for($cnts=0;$cnts<$rec;$cnts++){
		($i1,$nwhatsid,$htmlf,$kbase)=split(",",$recda[$cnts]);
		if($i1 eq '*'){
			if($h_linkw ne '' && $htmlf=~/.*\//){$gra=$';&move_gra}
			next;
		}
		$ocnt=0;
		if($nwhatsid ne $whatsid){
			$whatsid=$nwhatsid;
			&FILE_SET; &sw_reset; &dataread; &dataread1;
		}
		$a=$newshead[$i1];
		&bunkai;
		if($imode){&syousai_i}
		else{
			$hsfile=&baseread(($kbase ? $kbase:$h_htmls),'s');
			&chk_owner;
			&syousai1(*comment);
			if(defined $gpdf){
				$dw_out="<html><head><title></title><meta http-equiv=\"refresh\" content=\"0;url=_img/$gpdf\"></head><body></body></html>$n";
				undef $gpdf;
			}
			else{
				&syousai2;
				@D_D=&brdate($h_datem,$rdate);
				&syousai3($i1,$edate);
			}
		}
		$wmm.= $cnth++%2 ? " <font color=#1E9557>$htmlf</font>" : " $htmlf";
		&out_del_c($soutdir);
		&open_file('SOUT',">$soutdir$htmlf",'02','HTML');
		print SOUT $dw_out;
		close(SOUT);
		undef @up;undef @down;undef @left;undef @right;
		undef @LRS;undef @DAT;undef $LR;undef $DATTOP;
		if($cnts>2000){&err("64 $cnts>2000".' 暴走しました!')}
	}
}

sub out_del_c {
	if(!defined $DELDH{$_[0]}){
		$DELDH{$_[0]}=1;
		if(! -d $_[0]){
			umask 0000;
			if(mkdir($_[0],oct($perms))==0){&err("02 HTML書き出しディレクトリ($_[0])が作成できません")}
		}
		elsif($k_delsw){&del_allfile($_[0],'html',$imode)}
	}
}

sub move_gra {
	my $w= $recno==1 && defined $gmove_dirs ? $gmove_dirs:$gmove_dir;
	if(open(FILE2,"$xXghdpath$gra")){
		if($owner ne '' && $owner ne $whatsid){$w.="$os_sepax$owner"}
		if(!defined $DELD{$w}){
			$DELD{$w}=1;
			if(not -d $w){
				umask 0000;
				if(mkdir($w,oct($perms))==0){&err("03 画像書き出しディレクトリ($w)が作成できません")}
			}
			elsif($k_delsw && $k_htsw==3){&del_allfile("$w$os_sepax",'',$imode)}
		}
		if(open(OUT1,">$w$os_sepax$gra")){
			binmode FILE2;
			binmode OUT1;
			while($w=<FILE2>){print OUT1 $w}
			close (OUT1);
		}
		close (FILE2);
	}
	else{$wmmg.='<font color=red>*</font>'}
	$wmmg.= $cntg++%2 ? "<font color=#1E9557>$gra</font> ":"$gra ";
}

sub syousai1 {
	local(*w_comment)=@_;
	foreach $g (@graphic=split($DV,$grap)){
		if(!$g || $g=~/^\d*,,/){next}
		($gxno,$gra,$width,$height,$where,$cw,$caps)= map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}(($g.',') =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
		if($k_htsw>0){&move_gra}
		if($where eq 'title'){$gpdf=$gra}
		elsif($where eq 'bg'){$bgimg=$gra}
		elsif($where eq 'news'){&d_news(1)}
		elsif($where eq 'up'){push(@up,$g)}
		elsif($where eq 'left'){
			push(@left,$g);
			if(!defined $LR){$LR=0}
		}
		elsif($where eq 'right'){
			push(@right,$g);
			if(!defined $LR){$LR=1}
		}
		else{push(@down,$g)}
	}
}

sub menu_gra {
	local(*w_comment)=@_;
	my($xxx,$wi,$wi1,$wi2);
	while($w_comment=~/<!(\d+):?([^ :>]*)>([^<]*)<!>/){
		$wi=$2 ? " target=$2":' target=_top';
		($dumm,$wi1)= map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}(((split($DV,$grap))[$1-1].',') =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
		$w_comment=~s/<!\d+:?[^ :>]*>([^<]*)<!>/<a href=$xXgpath$wi1$wi>$1<\/a>/;
		if($xxx++>99){last}
	}
	$xxx=0;
	while($w_comment=~/<\"?(!?)([^ :>]+\.[^\- :>]+):?([^ :>]*)\"?>/){
		if($1){
			$wi=$3 ? " target=$3":' target=_top';
			$w_comment=~s/<\"?!([^ :>]+\.?[^\- :>]*):?[^ :>]*\"?>([^<]*)<!>/<a href=$xXgpath$1$wi>$2<\/a>/;
		}
		else{
			$gra=$2;
			if($k_htsw>0){&move_gra}
			&d_news(0);
		}
		if($xxx++>99){last}
	}
}

sub d_news {
	if($_[0] && $w_comment=~/<\"?!($gxno|$gra):?([^ :>]*)\"?>([^\<]*)<!>/){
		my($wi);
		if($2){$wi=" target=$2"}
		$w_comment="$`<a href=$xXgpath$gra$wi>$3</a>$'";
		return;
	}
	if($caps || ($gra!~/\.(jpg|gif|png|bmp|swf)$/i)){&grbunkai('','',0)}
	elsif($gra=~/\.swf$/i){$widhit="<embed src=$xXgpath$gra type=application/x-shockwave-flash quality=best play=true></embed>"}
	else{$widhit="<img src=$xXgpath$gra>"}
	$gra=~s/\./\\./;
	if($w_comment=~s/<\"?($gxno|$gra)\"?>/$widhit/){}
	else{
		$widhit=~s/>$//;
		$w_comment=~s/< *img *src *= *\"?$gra\"?(.*)/$widhit$1/i;
	}
}

sub syousai2 {
	$comment=~s/<>//g;
	if($charset && !$engsw){&jcode::convert(\$comment,$charset)}
	$commentx=$comment;
	if((@db=split(/<\/bl><br>|<\/bl>/i,$comment))>1){
		$comment='';
		foreach (@db){
			if($_=~/(.*)<bl(\d+)>(.*)/i){
				$comment.=$1;
				$DAT[$2]=$3;
			}
			else{$comment.=$_}
		}
	}
	else{
		if(defined $LR){$LRS[$LR]=$comment}
		else{$DATTOP=$comment}
		$comment='';
	}
}

sub syousai3 {
	local($ano_cnt,$edate_w)=@_;
	$dw_out='';
	my $tag_sw;
	if($OPT{'test'}==1 && !$imode){
		$wunder=($java_sw ? "<input type=button value=\"編集画面に戻る\" onclick=\"window.close()\">":'').(defined $ERRGRA{$cnt1s} ? '　'.&errgra($cnt1s):'');
	}
	foreach(@dataz) {
		&pers_rep;
		if(($tag_sw=index($_,'<!--'))>=0){
			if($_=~/(.*)<!--(loop|Gmenu)[ :]?(\d*)[ :]?([^\?> #:]*)[ :]?(#)?([^> \?:]*)[ :]?(\?)?([^> \?]*)-->(.*)/){
				$ax=$a;$whatsidx=$whatsid;
				&loop_job;
				$whatsid=$whatsidx;
				$a=$ax;&bunkai;
				&chk_owner;
				next;
			}
			if($_=~s/<!--(end|END)[ :]?([^,>]*),?([^,>]*),?([^,>]*),?([^,>]*?)-->//){
				$endchr=$1;$u_prev=$2;$u_index=$3;$u_next=$4;
				&undermenu;
			}
			&rep_newmark;
			&custom('');
			&set_gra_kizi;
		}
		if($_=~/< *body/i && defined $bgimg){
			if($_=~s/(background=)\"?[^ >]*\"?([ >])/$1$xXgpath$bgimg$2/i){}
			else{$_=~s/(<[ ]*body)(.*)/$1 background=$xXgpath$bgimg$2/i}
		}
		elsif($tag_sw>=0){
			if($_=~s/<!--#(.*?)-->// && $1 ne $whatsid){next}
			elsif($_=~/<!--start-->/){
				my $w32=$';
				$dw_out.="$`<center>$n";
				if($comment){$dw_out.="<table border=0 cellspacing=5 cellpadding=5$font_size_st>$n<tr><td align=left>$comment</td></tr>$n</table>$n"}
				if(@up>0){&grtb(*up)}
				if($DATTOP){$dw_out.="<table border=0 cellspacing=5 cellpadding=5$font_size_st>$n<tr><td align=left>$DATTOP</td></tr>$n</table>$n"}
				if(@left+@right>0){&grlr}
				if(@down>0){&grtb(*down)}
				$dw_out.="</center>$n$w32$n";next;
			}
			elsif($_=~s/<!--menu_title-->//){$menu_title=$_;next}
			elsif($_=~s/<!--no_data-->//){$no_data=$_;next}
			if(@UPD=$_=~/(.*)<!--(upday|date)(%?)[ :]?(.*?)-->(.*)/){&rep_date}
#			if(&daycheck){next}
			if($_=~s/<!--title(\*?)-->/$title/ && $1 && $title eq ''){next}
			if($_=~s/<!--comment(\*?)-->/$commentx/ && $1 && $commentx eq ''){next}
		}
		elsif($_=~/<meta/i){&meta_check}
		if($_=~/%other[ :]?([^%,]*),?([^%,]*),?([^%]*)%/){
			if($k_htsw>0 || defined $mak_sw){
				$_="$`<a href=\x00".($3 ne '' ? " target=$3":'').">$2</a>$'";
				$wfn='';&hdata_up($1,$ano_cnt);
				$_=~s/\x00/$wfn/;
			}
			else{
				$_="$`<a href=${cgi2}?${areapl}id:$owner+sbase:$1+".($h_id>0 ? "call:$cust[$h_id-1]":"rec:$edate_w").$hikisu.($imode ? '+i':'').($3 ne '' ? " target=$3":'').">$2</a>$'";
			}
		}
		$dw_out.="$_$n";
	}
}

sub syousai_i {
	$dw_out='';
	foreach $g (@graphic=split($DV,$grap)){
		$i++;
		if(!$g || $g=~/^\//){next}
		elsif($g=~/\/up_i/){push(@up,$g)}
		elsif($g=~/\/down_i/){push(@down,$g)}
	}
	$comment=~s/<>//g;
	@D_D=&brdate($h_datem,$rdate);
	$hsfile=&baseread($h_htmls,'s');
	foreach (@dataz){
		&pers_rep;
		if($_=~/<!--/){
			if(@UPD=$_=~/(.*)<!--(date)(%?)[ :]?(.*?)-->(.*)/){&rep_date}
#			if(&daycheck){next}
			&rep_newmark;
			if($_=~s/<!--title(\*?)-->/$title/ && $1 && $title eq ''){next}
			elsif($_=~s/<!--start-->/$comment/){}
			elsif($_=~/<!--gra_top-->/){
				$w1='';
				foreach $g (@up){$w1.=&grbunkai('',' vspace=2',1)}
				$_=~s/<!--gra_top-->/$w1/;
			}
			elsif($_=~/<!--gra_bottom-->/){
				$w1='';
				foreach $g (@down){$w1.=&grbunkai('',' vspace=2',1)}
				$_=~s/<!--gra_bottom-->/$w1/;
			}
			elsif($_=~s/<!--end[ :]?([^,]*),?([^,]*),?([^,]*),?([^,]*?)-->//){
				$u_prev=$1;$u_index=$2;$u_next=$3;
				&undermenu_i;
			}
			elsif(@UPD=$_=~/(.*)<!--(upday)(%?)[ :]?(.*?)-->(.*)/){&rep_date}
			&custom('');
		}
		$dw_out.="$_$n";
	}
}

sub custom {
	$cs_kek='';
	while($_=~/<!--([^>]*?)[: ]?([Cc])ustom(\d+)(.*?)-->/){
		$cs_mae=$1;$cs_Cc=$2;$cs_d1=$3;$cs_csw=$4;$_=$cs_kurik=$';
		if(defined $ifsw){
			if($cs_d1 eq '0'){undef $ifsw}
			next;
		}
		$cs_kek.=$`;
		if($cs_Cc eq 'c'){
			$cs_w1=$_[0] eq 'm' ? $first_data[$cs_d1-1]:$cust[$cs_d1-1];
			$cs_w2=$h_custm[$cs_d1-1];
		}
		else{$cs_w1=$mcust[$cs_d1-1];$cs_w2=$h_mcustm[$cs_d1-1]}
		if($cs_mae ne ''){
			$cs_mae=~s/[: ]$//;
			if($cs_mae eq 'if' && $cs_csw=~/([=<>!]+)(.*)/){
				$chgc3=$1;
				($chgc4,$chgc5,$chgc6)=split(',',$2);
				$chgc=$cs_Cc eq 'C' ? $mcust[$cs_d1-1]:$cust[$cs_d1-1];
				if(substr($cs_w2,0,1) eq 's'){$chgc=~s/<>.*//}
				&chg_cust(*chgc4);
				if("$chgc5$chgc6" eq ''){
					if($chgc3 eq '=' && $chgc ne $chgc4){$ifsw=1}
					elsif($chgc3 eq '<>' && $chgc eq $chgc4){$ifsw=1}
					elsif($chgc3 eq '!' && index($chgc,$chgc4)>=0){$ifsw=1}
					elsif($chgc3 eq '!=' && index($chgc,$chgc4)<0){$ifsw=1}
					elsif($chgc3 eq '>' && $chgc <= $chgc4){$ifsw=1}
					elsif($chgc3 eq '<' && $chgc >= $chgc4){$ifsw=1}
					elsif($chgc3 eq '<=' && $chgc > $chgc4){$ifsw=1}
					elsif($chgc3 eq '>=' && $chgc < $chgc4){$ifsw=1}
				}
				else{
					&chg_cust(*chgc5);
					&chg_cust(*chgc6);
					if($chgc3 eq '='){$cs_kek.=$chgc eq $chgc4 ? $chgc5:$chgc6}
					elsif($chgc3 eq '<>'){$cs_kek.=$chgc ne $chgc4 ? $chgc5:$chgc6}
					elsif($chgc3 eq '!'){$cs_kek.=index($chgc,$chgc4)<0 ? $chgc5:$chgc6}
					elsif($chgc3 eq '!='){$cs_kek.=index($chgc,$chgc4)>=0 ? $chgc5:$chgc6}
					elsif($chgc3 eq '>'){$cs_kek.=$chgc > $chgc4 ? $chgc5:$chgc6}
					elsif($chgc3 eq '<'){$cs_kek.=$chgc < $chgc4 ? $chgc5:$chgc6}
					elsif($chgc3 eq '<='){$cs_kek.=$chgc <= $chgc4 ? $chgc5:$chgc6}
					elsif($chgc3 eq '>='){$cs_kek.=$chgc >= $chgc4 ? $chgc5:$chgc6}
				}
				next;
			}
		}
		if($h_cust2[$cs_d1-1] eq ''){next}
		if($cs_csw!~/[: ]?([Ddnusicg#*%\/\\\!]*)=?([\dxXT]*)[: ]?(.*)/){next}
		$cs_csw=$1;$bigp=$2;$cs_ato=$3;
		if($h_pass==1 && index($h_cus_p,"-$cs_d1-")>=0 && !defined $nopass){
			if(index($cs_csw,'*')>=0){$ifsw=1}
			next;
		}
		if($cs_csw=~/([dD])/){
			if(defined $DN){if($DN!=$bigp){next}}
			elsif($1 eq 'D'){next}
		}
		$cs_wx=substr($cs_w2,0,1);
		if($cs_w1 ne '' || $cs_wx eq 'o'){
			if($cs_wx eq '*'){
				($gra,$cs_wx,$cs_wy)=$cs_w2=~/(.)(\d*)[xX]?(\d*)/;
				($gra,$width,$height,$where)=split(',',$cs_w1);
				if(index($cs_csw,'*')>=0 && $gra eq ''){$cs_w1='';$ifsw=1}
				else{
					$cs_sm_sw=1;
					if(index($cs_csw,'i')>=0){
						if($gra=~/\./){$cs_sm_sw=0;$gra="$`_i.$'"}
					}
					if($k_htsw>0){&move_gra}
					if($gra=~/\.csv$|\.html?$|\.txt$/i){$cs_w1=&outcsv}
					else{
						if(index($cs_csw,'!')>=0){
							if($bigp=~/x/i){
								$cs_w1= $gra=~/\.swf$/i ? "<embed src=$xXgpath$gra type=application/x-shockwave-flash quality=best play=true></embed":"<img src=$xXgpath$gra";
								if($`){$cs_w1.=" width=$`"}
								if($'){$cs_w1.=" height=$`"}
								$cs_w1='>';
							}
							else{$cs_w1="$xXgpath$gra"}
						}
						else{
							if(index($cs_csw,'/')>=0 && $cs_kurik=~s/(.+?)<!--\/([^\-]*)-->//){$cs_w1="<a href=$xXgpath$gra".($2 ? " target=$2":'').">$1</a>"}
							else{
								$cs_w1= $gra=~/\.swf$/i ? "<embed src=$xXgpath$gra type=application/x-shockwave-flash quality=best play=true></embed" : "<img src=$xXgpath$gra";
								if($width && $cs_sm_sw){
									if($cs_wx && $width>$cs_wx){$cs_w1.=" width=$cs_wx"}
									elsif($cs_wy && $height>$cs_wy){$cs_w1.=" height=$cs_wy"}
									else{$cs_w1.=" height=$height width=$width"}
								}
								$cs_w1.=' border=0>';
								if($bigp){
									$cs_wx=$cs_Cc eq 'c' ? $cust[$bigp-1]:$mcust[$bigp-1];
									($gra,$width,$height,$where)=split(',',$cs_wx);
									$cs_w1="<a href=$xXgpath$gra target=newwin0>$cs_w1</a>";
								}
							}
						}
					}
				}
			}
			elsif($cs_wx eq 'd' && $cs_w1=~/([\d ]+)\/([\d ]+)\/?([\d ]*)/){
				if(substr($cs_w2,1,1) eq 'y'){$cs_w1=sprintf("%d年%d月%d日",$1,$2,$3)}
				elsif(substr($cs_w2,1,1) eq 'm'){$cs_w1=sprintf("%d年%d月",$1,$2)}
				else{$cs_w1=sprintf("%d月%d日",$1,$2)}
			}
			elsif($cs_wx eq 't' && $cs_w1=~/([\d ]+):([\d ]+)/){
				if($bigp eq '12T'){$cs_w1=$1>11 ? sprintf("午後%d時%d分",$1-12,$2):sprintf("午前%d時%d分",$1,$2)}
				else{$cs_w1=sprintf("%d時%d分",$1,$2)}
			}
			else{
				$cs_g1=($xXgpath=~/\/$whatsid\// ? "$`/img/":$xXgpath);
				if($cs_wx eq 's'){
					if($cs_w1=~s/<>(.*)// && $1 ne '' && index($cs_csw,'s')>=0){$cs_w1=$1}
					if($cs_w1=~/_(\/?)(jpg|bmp|gif)_/i){
						$cs_w1=($1 ? "<img src=$cs_g1":"<img src=$xXgpath")."$'.$2 border=0>";
					}
				}
				elsif($cs_wx eq 'c' && $cs_w1=~/_\/?(jpg|bmp|gif)_/i){
					$cs_w2='';
					foreach(split($sepa,$cs_w1)){
						if($_=~/^_(\/?)(jpg|bmp|gif)_/i){
							$cs_w2.=($1 ? "<img src=$cs_g1":"<img src=$xXgpath")."$'.$2 border=0>";
						}
						else{$cs_w2.=$_}
					}
					$cs_w1=$cs_w2;
				}
				elsif($cs_wx eq 'q' || $cs_wx eq 'o'){
					if($cs_w1 eq '' && $cs_wx eq 'q'){$cs_mae=$cs_ato=''}
					else{
						if($cs_wx eq 'o'){
							$i2=$cs_w1 eq '' || $cs_w1=~/[^\d]/ ? 10:$cs_w1;
							$cs_w1='';
							for($i=1;$i<$i2+1;$i++){$cs_w1.="$i,"}
						}
						$i="<select name=$h_cust3[$cs_d1-1]><option value=\"\">";
						foreach(split(',',$cs_w1)){
							$i2=$_=~s/^(\*)// ? ' selected':'';
							$i.="<option value=\"$_\"$i2>$_";
						}
						$cs_w1="$i</select>";
						if($cs_mae eq ''){$cs_mae=($h_cust2[$cs_d1-1]=~/\$/ ? $`:$h_cust2[$cs_d1-1]).'：'}
					}
				}
				else{
					if($cs_csw eq 'g'){
						@cs_w2=split($sepa,$cs_w1);
						$cs_w1='';
						foreach(@cs_w2){
							if($_=~s/^\///){$cs_g1=($xXgpath=~/\/$whatsid\// ? "$`/img/":$xXgpath)}
							else{$cs_g1=$xXgpath}
							$cs_w1.="<img src=$cs_g1$_ border=0>";
						}
					}
					else{
						while($cs_w1=~/<\"?([^<\/]*)\.(jpg|gif|swf|csv|png|bmp|html?|txt)\"?>/i){
							$cs_w1=$`;$cs_g2=$1; $cs_g3=$2; $cs_g4=$';
							if($cs_g3=~/csv|htm|txt/i){$cs_w1.=&outcsv.$cs_g4}
							elsif($cs_g3=~/swf/i){$cs_w1.="<embed src=$xXgpath$cs_g2.$cs_g3 type=application/x-shockwave-flash quality=best play=true></embed>$cs_g4"}
							else{$cs_w1.="<img src=$xXgpath$cs_g2.$cs_g3>$cs_g4"}
						}
						if($charset && !$engsw){&jcode::convert(\$cs_w1,$charset)}
					}
				}
			}
			if(index($cs_csw,"\\")>=0){$cs_w1=&commas($cs_w1)}
		}
		else{
			if(index($cs_csw,'*')>=0){$ifsw=1}
			elsif(index($cs_csw,'%')>=0){$cs_w1='<br>'}
			$cs_mae=$cs_ato='';
		}
		if($recno eq ''){
			if(index($cs_csw,'#')>=0){
				if($wfn eq ''){&setwfnx;$wfnx=~s/##/$wfn/g}
				$cs_w1="<a href=$wfnx>$cs_w1<\/a>";
			}
		}
		elsif(index($cs_csw,'n')>=0){
			($cs_wx,$cs_wy)=$cs_ato=~/([^,]*),?(.*)/;
			$cs_ato='';
			if($k_htsw>0 || defined $mak_sw){
				$wfn='';&hdata_up($cs_wx,$ano_cnt);
				$cs_w1="<a href=$wfn>$cs_w1</a>";
			}
			else{
				$cs_w1="<a href=${cgi2}?${areapl}id:$owner+sbase:$cs_wx+".($h_id>0 ? "call:$cust[$h_id-1]":"rec:$edate_w").$hikisu.($imode ? '+i':'').($cs_wy ne '' ? " target=$cs_wy":'').">$cs_w1</a>";
			}
		}
		if(index($cs_csw,'u')>=0){$cs_w1=~s/(\W)/'%'.unpack('H2', $1)/eg}
		$cs_kek.="$cs_mae$cs_w1$cs_ato";
		$_=$cs_kurik;
	}
	if(defined $ifsw){$_=$cs_kek;undef $ifsw}
	elsif($cs_kek){$_="$cs_kek$_"}
}

sub chg_cust {
	local(*chgcw)=@_;
	if($chgcw=~/(C|c)ustom(\d+)/){
		my $qqmae=$`;my $qqato=$';
		if($1 eq 'c'){$chgcw=$cust[$2-1];$cs_w2=substr($h_custm[$2],0,1)}
		else{$chgcw=$mcust[$2-1];$cs_w2=substr($h_mcustm[$2],0,1)}
		if($cs_w2 eq 's'){$chgcw=~s/<>.*//}
		$chgcw=$qqmae.$chgcw.$qqato;
	}
}

sub commas {
	if(my @cm=$_[0]=~/(\-?)(\d*)(\.?)(\d*)/){
		my $befo="$`$cm[0]";my $aft=$';
		1 while $cm[1]=~s/(.*\d)(\d\d\d)/$1,$2/;
		if(($cm[1]+$cm[3])){return "$befo$cm[1]$cm[2]$cm[3]$aft"}
	}
	return $_[0];
}

sub sw_reset {
	delete $OPT{'new'};delete $OPT{'day'};undef $font_size;undef $window;undef $wwidth;delete $OPT{'max'};
}

sub dataread {
	my($i1,$wd);
	&open_file('FILE',$file,'04','データ');
	$wd=<FILE>;
	if(substr($wd,0,1) ne '#'){&err("05 ($wd) データファイルのヘッダーがありません！")}
	chomp($wd);
	($h_dumm,$h_log,$h_dumm,$h_id,$h_date,$h_title,$h_kizi,$h_imode,$h_link,$h_code,$h_htmls,$h_line,$h_new,$h_html,$h_outhtml,$h_pass,$h_font,$h_mother,$h_newg,$h_newz,$h_cus_p,$h_mcno,$h_ldisp,$h_window,$h_winw,$h_dumm,$h_cno,$h_gno,$h_keisai,$h_sort,$h_efile,$h_colord,$h_direct,$h_base,@h_cust)=split("\t",$wd);
	($h_font,$h_fcolor)=split(',',$h_font);
	$font_size_st='';
	($h_line,$h_linep)=split('=',$h_line);
	if($h_link=~s/^(\d)(\d?) ?(.*)/$1/){$h_linkw=$2;$target=$3}
	if((!defined $OPT{'maxp'}) && $h_linep){$OPT{'maxp'}=$h_linep}
	if((!defined $OPT{'max'}) && $h_line){$OPT{'max'}=$h_line}
	if(defined $OPT{'new'}){$h_new=$OPT{'new'}}
	if($h_new){$OPT{'new'}=&newdate($h_new)}
	if(defined $OPT{'day'}){$h_newz=$OPT{'day'}}
	if($h_newz){$OPT{'day'}=&newdate($h_newz)}
	if(defined $font_size){$h_font=$font_size}
	$font_size_st=' style="font-size:'.($h_font ? $h_font:'13px').';color:'.($h_fcolor ? $h_fcolor:'#666666').'"';
	if(!defined $window){$window=$h_window}
	if((!defined $wwidth) && $h_winw){$wwidth=$h_winw}
	for($i1=0;$i1<$h_cno;$i1++){
		($h_custm[$i1],$h_cust2[$i1],$h_cust3[$i1])=split(',',$h_cust[$i1]);
		if(substr($h_custm[$i1],0,1) eq 'H'){$rec_ID=substr($h_custm[$i1],0,1)}
	}
	($h_datem)=split(',',$h_date,2);
	$wd=<FILE>;chomp($wd);
	($h_dumm,$h_dumm,$h_mlimit,@h_mcust)=split("\t",$wd);
	for($i1=0;$i1<$h_mcno;$i1++){($h_mcustm[$i1],$h_mcust[$i1])=split(',',$h_mcust[$i1])}
	$wd=<FILE>;chomp($wd);
	($h_dumy,$mdate,$h_dummy,$renban,$mlimit,$mlimit1,$mcust_buf)=split("\t",$wd,7);
	if($h_mlimit==0){
		if($mlimit && $mlimit gt substr($today,0,length($mlimit))){$mcust_buf=''}
		elsif($mlimit1 && $mlimit1 lt substr($today,0,length($mlimit1))){$mcust_buf=''}
	}
	if($h_mother && $h_mother ne '_$_'){
		close(FILE);
		$file=~s/$whatsid/$h_mother/;
		&open_file('FILE',$file,'06','データ');
		for($i1=1;$i1<4;$i1++){$wd=<FILE>}
		$h_mother_sw=1;
	}
	else{$h_mother_sw=0}
	($h_colord,$h_shonin1,$h_shonin2)=split(',',$h_colord);
	$h_SHO=($h_shonin1 ne '' ? '1':'').($h_shonin2 ne '' ? '2':'');
	$h_log=~s/=.*//;
}

sub bunkai {
	chomp($a);
	($rdate,$title,$grap,$url,$comment,$nsw,$edate,$idata,$owner,$limit,$limit1,$cus_buf)=split("\t",$a,12);
	if($imode && $idata=~/$DV/){
		if($` ne ''){$title=$`}
		if($' ne ''){$comment=$'}
	}
	&menu_gra(*comment);
	&menu_gra(*cus_buf);
	@cust=split("\t",$cus_buf);
	$edate=~s/[\/\: ]//g;
}

sub chk_owner {
	$xXgpath=$yXgpath; $xXghdpath=$Xghdpath;
	if($owner ne $whatsid){
		if($h_mother && $h_mother eq '_$_'){
			if($k_htsw==0){$xXgpath=~s/$whatsid/$owner/}
			else{$xXgpath=~s/(_img\/)/$1$owner\//}
		}
		$xXghdpath=~s/$whatsid/$owner/;
	}
}

sub grlr {
	$dw_out.="<table border=0 cellspacing=5 cellpadding=5 width=95%>$n<tr><td><table border=0 cellspacing=5 cellpadding=5$font_size_st><tr>";
	if(@left>0){$dw_out.='<td>'}
	foreach $g (@left){
		$dw_out.="<table border=0 cellspacing=5 cellpadding=5><tr>";
		($gxno)=$g=~/(\d*),/;
		$dw_out.='<td>'.&grbunkai('',' align=',1)."</td>$n";
		if(defined $DAT[$gxno]){$dw_out.="<td>$DAT[$gxno]</td>$n"}
		$dw_out.="</tr></table>$n";
	}
	if(@left>0){
		$dw_out.='</td>';
		if($LRS[0]){$dw_out.="<td>$LRS[0]</td>"}
	}
	if(@right>0){
		if($LRS[1]){$dw_out.="<td>$LRS[1]</td>"}
		$dw_out.='<td>';
	}
	foreach $g (@right){
		$dw_out.="<table border=0 cellspacing=5 cellpadding=5><tr>";
		($gxno)=$g=~/(\d*),/;
		if(defined $DAT[$gxno]){$dw_out.="<td>$DAT[$gxno]</td>$n"}
		$dw_out.='<td>'.&grbunkai('',' align=',1)."</td>$n</tr></table>$n";
	}
	if(@right>0){$dw_out.='</td>'}
	$dw_out.="</tr></table>$n</td></tr></table>$n";
}

sub grtb {
	local(*s)=@_;
	$dw_out.="<table border=0 cellspacing=5 cellpadding=5 width=95%>$n<tr>";
	my($w1)='<tr>';
	foreach $g (@s){
		$dw_out.='<td align=center nowrap>'.&grbunkai('','',1).'</td>';
		if($DAT[$gxno]){$w1.="<td>$DAT[$gxno]</td>"}
	}
	$dw_out.="</tr>$n".($w1 ne '<tr>' ? "$w1</tr>$n":'')."</table>$n";
}

sub grbunkai {
	$widhit="<table border=0$_[1]";
	if($_[2]){($gxno,$gra,$width,$height,$where,$cw,$caps)= map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}(($g.',') =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g)}
	if($_[1]){$widhit.="$where>$n"}
	else{$widhit.=">$n"}
	if($caps){
		if($cw=~/([^\/]*)\/([^\/]*)\/([^\/]*)/){
			$widhit.="<caption align=\"$1\" style=\"";
			if($2){$widhit.="font-size:$2;"}
			if($3){$widhit.='font-weight:'.($3*100)}
			$widhit.="\">$caps</caption>$n";
		}
		else{$widhit.="<caption>$caps</caption>$n"}
	}
	$widhit.='<tr><td>';
	if($gra=~/\.(csv|html?|txt)$/i){$widhit.=&outcsv}
	elsif($gra=~/\.(jpg|gif|png|bmp|swf)$/i){
		$widhit.= $1 eq 'swf' || $1 eq 'SWF' ? "<embed src=$xXgpath$gra type=application/x-shockwave-flash quality=best play=true></embed" : "<img src=$xXgpath$gra";
		if($width){$widhit.=" width=$width"}
		if($height){$widhit.=" height=$height"}
		$widhit.="$_[0]>";
	}
	$widhit.="</td></tr>$n</table>$n";
	return $widhit;
}

sub continue {
	if($k_htsw){
		$ixcnt++;
		($w1,$w2)=$k_index=~/([^$os_sepa]+)\.([^$os_sepa]+)$/;
		$_=~s/<!--continue[ :]?(.*)-->/<a href=\"$w1$ixcnt\.$w2\">$1<\/a>/;
	}
	else{
		my($wc)=$cnt+1;
		my($w1)=$hikisu;
		$w1=~s/start:\d+\+?//;
		$_=~s/<!--continue[ :]?(.*)-->/<a href=\"${cgi2}?${areapl}id:$whatsid+start:$wc$w1\">$1<\/a>/;
	}
}

sub page {
	my($pw1,$pmae,$pato,$pw2)=@_;
	my($outpa,$ds,$w1,$w2,$cntp,$pa_find,$af,$bf);
	my $wc=$pato=~s/color=([^ ]+) ?// ? $1:'red';
	$w1=$hikisu;
	$w1=~s/start:\d+\+?//;
	$ds=@okrec;
	$_="$pw1\x00$pw2";
	$_=~s/##1/$ds/;
	while($ds>0){
		$cntp++;
		if(!$pa_find && ($OPT{'start'}==0 || $mken==$OPT{'start'})){
			$outpa.=" <font color=$wc><b>$pmae$cntp</b></font>$pato";
			$_=~s/##2/$mken/;
			$mken+=$OPT{'max'};
			if(@okrec>=$mken){$wc=$mken-1}
			else{$wc=@okrec}
			$_=~s/##3/$wc/;
			$OPT{'start'}=$okrec[$cntp*$OPT{'max'}]+1;
			$pa_find=1;
		}
		else{
			if($k_htsw>0){
				$k_index=~/([^$os_sepa]+)\.([^$os_sepa]+)$/;
				$hw="<a href=\"$1".(($cntp-1) ? ($cntp-1):'').".$2\">";
				if($pa_find==1){$af=$hw;$pa_find=2}
				elsif($pa_find==0){$bf=$hw}
			}
			else{
				$hw="<a href=\"${cgi2}?${areapl}id:$whatsid+start:$mken$w1".($imode ? '+i':'').($ckey_h ? "+filter:$ckey_h":'').($SO_SW ? "+sort:$SO_SW":'').($FORM{'search'} ? "+search:$FORM{'search'}":'').'">';
				if($pa_find==1){$af=$hw;$pa_find=2}
				elsif($pa_find==0){$bf=$hw}
			}
			$outpa.=" $hw$pmae$cntp</a>$pato";
			if(defined $OPT{'maxp'} && $cntp>($OPT{'maxp'}-1)){$outpa.='....';last}
			$mken+=$OPT{'max'};
		}
		$ds=$ds-$OPT{'max'};
	}
	if($bf){$outpa=" $bf前$pmae</a> ".$outpa}
	if($af){$outpa.=" $af次$pmae</a> "}
	$_=~s/\x00/$outpa/;
	if($cntp==0){return 0}
	return 1;
}

sub outcsv {
	my($w2,@datab,$i,@w,$work,@dataa,$cntc,$thsw);
	if(open(CFILE,"$xXghdpath$gra")==0){return ''}
	while ($w2=<CFILE>) {$work.=$w2}
	close(CFILE);
	$work=~s/\r\n/\n/g;
	$work=~s/\r/\n/g;
	if($gra=~/\.csv$/i){
		@dataa=split("\n",$work);
		$work.='<center><table bgcolor=#000000 cellspacing=1 cellpadding=2 width=95%>';
		foreach $w2 (@dataa){
			if($w2 eq ''){next}
			if($cntc==0 && $w2=~s/^#//){@w=split(',',$w2);next}
			if($cntc++==0 && index($w2,',')<0){$work.="<caption><b>$w2</b></caption>$n"}
			elsif(!$thsw){
				@datab= map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}(($w2.',') =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
				$work.='<tr bgcolor=#FFFFFF>';
				for($i=0;$i<@datab;$i++){
					if($datab[$i] eq ''){$datab[$i]='<br>'}
					$work.="<th align=left width=$w[$i]>$datab[$i]</th>"
				}
				$work.="</tr>$n";
				$thsw=1;
			}
			else{
				@datab= map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}(($w2.',') =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
				$work.='<tr>';
				for($i=0;$i<@datab;$i++){
					if($datab[$i] eq ''){$datab[$i]='<br>'}
					$work.= $datab[$i]=~/^\d+[0-9.,]*\d$/ ? "<td align=right>$datab[$i]</td>" : "<td>$datab[$i]</td>";
				}
				$work.="</tr>$n";
			}
		}
		$work.="</table></center>$n";
	}
	else{
		if($gra=~/\.txt$/i){$work=~s/$n/<br>/g}
	}
	return $work;
}

sub under_cust {
	my $w1;
	while($_=~/(c|C)ustom(\d+)/){
		$w1=$1 eq 'c' ? $cust[$2-1]:$mcust[$2-1];
		if($w1 && $charset && !$engsw){&jcode::convert(\$w1,$charset)}
		$_="$`$w1$'";
	}
	if(!$endchr){$_=~s/>([^>]+)(\.gif|\.jpg)/><img src=$xXgpath$1$2 border=0>/g}
}

sub undermenu {
	my($ind,$udwk);
	$endchr=$endchr eq 'END' && $java_sw ? 1:0;
	if($k_htsw==0){
		$wfn=$hikisu;
		&select_set;
		$udwk="$cgi2?${areapl}id:$whatsid+rec:";
		if($cnt1s>0){
			($ind)=$okrec[$cnt1s-1]=~/\d*,(.*)/;
			if($endchr){$_=~s/<!--[^<>]*previous[^<>]*-->/<input type=button value=\"$u_prev\" onclick=\"location.href=\'$udwk$ind$wfn\'\">/}
			else{$_=~s/<!--([^<>]*)previous([^<>]*)-->/$1<a href=$udwk$ind$wfn>$u_prev<\/a>$2/}
		}
		if($cnt1s<(@okrec-1)){
			($ind)=$okrec[$cnt1s+1]=~/\d*,(.*)/;
			if($endchr){$_=~s/<!--[^<>]*next[^<>]*-->/<input type=button value=\"$u_next\" onclick=\"location.href=\'$udwk$ind$wfn\'\">/}
			else{$_=~s/<!--([^<>]*)next([^<>]*)-->/$1<a href=$udwk$ind$wfn>$u_next<\/a>$2/}
		}
		if($mid eq ''){$mid=$whatsid}
		$ind= $window && $java_sw && $window!~/^f=/ ? 'JavaScript:window.close()' : "$cgi2?${areapl}id:$mid$wfn";
		if($endchr){$_=~s/<!--[^<>]*index[^<>]*-->/<input type=button value=\"$u_index\" onclick=\"location.href=\'$ind\'\">/}
		else{$_=~s/<!--([^<>]*)index([^<>]*)-->/$1<a href=\"$ind\">$u_index<\/a>$2/}
	}
	else{
		if($cnts<(@recda-1)){
			($w1,$w3,$w2)=split(',',$recda[$cnts+1]);
			if($w3 eq $whatsid){
				if($endchr){$_=~s/<!--[^<>]*previous[^<>]*-->/<input type=button value=\"$u_prev\" onclick=\"location.href=\'$w2\'\">/}
				else{$_=~s/<!--([^<>]*)previous([^<>]*)-->/$1<a href=$w2>$u_prev<\/a>$2/}
			}
		}
		if($window && $java_sw && $window!~/^f=/){$ind='"JavaScript:window.close()"'}
		else{
			$chkhtml=~/.*\/(.*)/;
			$ind="$idxback$1";
		}
		if($endchr){$_=~s/<!--[^<>]*index[^<>]*-->/<input type=button value=\"$u_index\" onclick=\"location.href=\'$ind\'\">/}
		else{$_=~s/<!--([^<>]*)index([^<>]*)-->/$1<a href=$ind>$u_index<\/a>$2/}
		if($cnts>0){
			($w1,$w3,$w2)=split(',',$recda[$cnts-1]);
			if($w3 eq $whatsid){
				if($endchr){$_=~s/<!--[^<>]*next[^<>]*-->/<input type=button value=\"$u_next\" onclick=\"location.href=\'$w2\'\">/}
				else{$_=~s/<!--([^<>]*)next([^<>]*)-->/$1<a href=$w2>$u_next<\/a>$2/}
			}
		}
	}
	&under_cust;
}

sub undermenu_i {
	if($k_htsw==0){
		$wfn=$hikisu;
		&select_set;
		if($cnt1s>0){
			$ind=$okrec[$cnt1s-1]+1;
			$_=~s/<!--([^<>]*)previous([^<>]*)-->/$1<a href=$cgi2?${areapl}i+id:$whatsid+rec:$ind$wfn>$u_prev<\/a>$2/;
		}
		if($cnt1s<@okrec-1){
			$ind=$okrec[$cnt1s+1]+1;
			$_=~s/<!--([^<>]*)next([^<>]*)-->/$1<a href=$cgi2?${areapl}i+id:$whatsid+rec:$ind$wfn>$u_next<\/a>$2/;
		}
		$wfn=~s/\+mid:[^\+]+//;
		if($mid eq ''){$mid=$whatsid}
		$_=~s/<!--([^<>]*)index([^<>]*)-->/$1<a href=$cgi2?${areapl}i+id:$mid$wfn>$u_index<\/a>$2/;
	}
	else{
		if($cnts<(@recda-1)){
			($w1,$w3,$w2)=split(',',$recda[$cnts+1]);
			$_=~s/<!--(.*?)previous(.*?)-->/$1<a href=$w2>$u_prev<\/a>$2/;
		}
		($lin)=$chkhtml=~/.*$os_sepa(.*)/;
		$_=~s/<!--(.*?)index(.*?)-->/$1<a href=$lin>$u_index<\/a>$2/;
		if($cnts>0){
			($w1,$w3,$w2)=split(',',$recda[$cnts-1]);
			$_=~s/<!--(.*?)next(.*?)-->/$1<a href=$w2>$u_next<\/a>$2/;
		}
	}
	&under_cust;
}

sub newdate {
	my($w1)=@_;
	my($time)=time()-86400*$w1;	#60 * 60 * 24* $w1
	@datex=localtime($time);
	$datex[4]++;
	if($datex[5]<200){$datex[5]=$datex[5]+1900}
	return sprintf("%d/%02d/%02d",$datex[5],$datex[4],$datex[3]);
}

sub brdate {
	local($h_datem,$date_k)=@_;
	my(@d_d,$d_d2e);
	if(substr($h_datem,0,1) eq '*'){
		@d_d=$date_k=~/(\d+)\/(\d+)\/(\d+) (\d+):(\d+):\d+/;
		if($' eq '*'){return}
		$d_d2e=substr('JanFebMarAprMayJunJulAugSepOctNovDec',$d_d[1]*3-3,3);
		$d_d[1]=~s/^0/ /;
		$d_d[2]=~s/^0/ /;
		if($engsw==1){$date_k="$d_d[2] $d_d2e $d_d[0]"}
		else{$date_k=$d_d[0].'年'.$d_d[1].'月'.$d_d[2].'日'}
	}
	if($charset && !$engsw){&jcode::convert(\$date_k,$charset)}
	return ($date_k,'平成'.($d_d[0]-1988),'',$d_d2e,@d_d);
}

sub linkh {
	if($h_linkw ne '' && $cust[$h_linkw-1] ne ''){
		$cust[$h_linkw-1]=~/\,/;
		if($` ne ''){$wfn="$xXgpath$`"}
		&targetset;
	}
	elsif($url eq '' && $comment && $wh_link==4){&setwfnx;$url=1}
	else{
		if($url_1 eq '?'){
			if($wfn eq ''){$wfn="$cgi2?$areapl$url_2$hikisu+mid:$whatsida"}
			&select_set;
			$url=$wfn;
		}
		elsif($wfn eq ''){$wfn="$url_1$url_2"}
		if($url_target && $target eq ''){$target=$url_target}
		&targetset;
	}
	$wfnx=~s/##/$wfn/g;
	if($h_linkw ne '' && $cust[$h_linkw-1] ne ''){$_=~s/<!--title\*?-->/<a href=$wfnx>$title<\/a>/}
	elsif($wh_link==3){
		if($url){$_=~s/<!--url-->/<a href=$wfnx>$url<\/a>/;$_=~s/<!--link-->/$wfnx/}
		$_=~s/<!--title\*?-->/$ERRGRA{$cnt1}$title/;
	}
	elsif($wh_link==4){
		$_=~s/<!--url-->/$url/;
		if($ERRGRA{$cnt1} ne ''){$ERRGRA{$cnt1}="[$ERRGRA{$cnt1}] "}
		if($url){$_=~s/<!--title\*?-->/$ERRGRA{$cnt1}<a href=$wfnx>$title<\/a>/}
		else{$_=~s/<!--title\*?-->/$title/}
	}
	else{
		$_=~s/<!--url-->/$url/;
		$_=~s/<!--title\*?-->/$ERRGRA{$cnt1}$title/;
		if($url){$_=~s/<!--comment\*?-->/<a href=$wfnx>$comment<\/a>/}
		else{$_=~s/<!--comment\*?-->/$comment/}
	}
	if($url && $wfnx){$_=~s/<!--link-->/$wfnx/}
	if($k_htsw>0 || defined $mak_sw){&hdata_up('',$cnt)}
}

sub err {
	my($msg,$file)=@_;
	local($dw_out)="<html><head><title>Error!</title>$n</head><body bgcolor=#FFFFFF>$n";
	if(!$OS){$msg=~s/$os_sepa/\//g}
	$msg=~s/^(\d\d)/<font color=red>$1<\/font>/;
	$dw_out.="<span style=\"font-size:4px\"> <br></span><center><b>$msg";
	if($deb_sw && $file){
		if(!$OS){$file=~s/$os_sepa/\//g}
		$file=~s/>/&gt;/g;
		$dw_out.="<br>$file ($!)";
	}
	$dw_out.="</b><br><br>$n";
	if($backp){$dw_out.="[<a href=$backp>$endmsg</a>]"}
	$dw_out.="</center></body></html>$n";
	&html_out;
}

sub errgra {
	return "<font color=red>【</font><a href=\"$cgi1?${areapl}2ncaution\" target=newwin0>$ERRGRA{$_[0]}</a><font color=red>】</font>";
}

sub log_out {
	my($kb)=@_;
	$logfile= -e $logfile ? ">>$logfile" : ">$logfile";
	&open_file('LOG',$logfile,'07','ログ');
	if($kb eq 'menu'){$uniq=''}
	else{
		$kb=$h_log;
		if($h_log==1){$uniq=$rdate}
		elsif($h_log==2){$uniq=$title}
		else{$uniq=$cust[$h_log-3]}
	}
	print LOG substr($today,0,10),' ',substr($today,10,5),"\t$imode\t$kb\t$uniq",($owner ne '_$_' ? "\t$owner":''),"\n";
	close(LOG);
}

sub FILE_SET {
	$Xdpath="$dpath$whatsid$os_sepax";
	$Xghdpath=$Xhpath="$ghdpath$whatsid$os_sepax";
	$Xgpath="$gpath$whatsid/";
	if($OPT{'back'}){
		$file="${Xdpath}back_num$os_sepax$OPT{'back'}.$kaku";
		$Xghdpath.="back_num$os_sepax";
		$Xgpath.="back_num/";
		$logfile="${Xdpath}back_num$os_sepax${dfname}_LOG.$kaku";
	}
	else{
		$file=&spdir_chk("$Xdpath$dfname.$kaku");	#データファイルのファイル名
		$logfile="$Xdpath${dfname}_LOG.$kaku";	#ログファイルのファイル名
	}
	if($k_htsw>0){$Xgpath='_'}
	$Xghdpath.="img$os_sepax";
	$Xgpath.="img/";
	$xXghdpath=$Xghdpath;$xXgpath=$Xgpath;
}

sub dataread1 {
	$cnt=0;
	&dr_jun;
	undef @newshead;
	while($a=<FILE>){
		push(@newshead,$a);
		&sort_jun;
		$cnt++;
	}
	close(FILE);
	if(defined $SO_SW){&sort_key}
}

sub dr_jun {
	$max=$now_new=0;
	undef @okrec;undef @SKEY;
	%ERRGRA=%CNT=%XKEY=();
	if(defined $FORM{'search'}){$orand=&bara_key}
}

sub dataread2 {
	&dr_jun;
	for($cnt=0;$cnt<@newshead;$cnt++){
		$a=$newshead[$cnt];
		&sort_jun;
	}
	if(defined $SO_SW){&sort_key}
}

sub sort_jun {
	$errgra='';
	chomp($a);
	($rdate,$title,$grap,$url,$comment,$nsw,$edate,$idata,$owner,$limit,$limit1,$cus_buf)=split("\t",$a,12);
	@cust=split("\t",$cus_buf);
	my($w1,$w2);
	if($imode){if(&dispcheck("i$h_SHO")){return}}
	else{if(&dispcheck("w$h_SHO")){return}}
	$edate=~s/[\/\: ]//g;
	push(@okrec,"$cnt,$edate");
	if(!defined $fir_comment){
		@first_data=@cust;$fir_comment=$comment;$fir_title=$title;$fir_grap=$grap;
		if($imode && $idata=~/$DV/){$fir_title=$`;$fir_comment=$'}
		&menu_gra(*fir_comment);
	}
	if($h_datem eq '*'){if($now_new lt $rdate){$now_new=$rdate}}
	else{if($now_new lt $edate){$now_new=$edate}}
	$w2='';
	my $SO_SW1=$SO_SW;
	while($SO_SW1=~s/^(\d+)([nc]?)([BS]?):?//){
		$w1=$1 ? $cust[$1-1]:$rdate;
		$SO_dais=$3;
		if($2 eq 'n'){
			$w1=~s/[^\d\.]//g;
			$w1=sprintf("%0$sortbyte.10f",$w1);
		}
		else{$w1=$w1."\x00"x($sortbyte-length($w1))}
		$w2.=$w1;
	}
	if($w2){
		$w2.=sprintf("%04d",$cnt);
		$XKEY{$w2}="$cnt,$edate";
	}
	if($errgra){$ERRGRA{$max}=$errgra}
	$max++;
}

sub sort_key {
	@okrec=();
	if($SO_dais eq 'B'){foreach(reverse sort keys %XKEY){push(@okrec,$XKEY{$_})}}
	else{foreach(sort keys %XKEY){push(@okrec,$XKEY{$_})}}
}

sub location {
	if($_[0] eq '?'){print "Location: $cgi2?${areapl}$_[1]$hikisu\n\n"}
	else{print "Location: $_[0]$_[1]\n\n"}
#	if($w3){$wloc.=" target=$w3"}
}

sub baseread {
	my($para,$sfnm)=@_;
	my($bw1,$bw2,$bw3,$basefile);
	undef @dataz;
	if($ckey && $ckey=~/\=(.+)(\.html?)$/){	#loop タグの引数
		$bw1=$1,$bw2=$2;
		$para=~/^(\d?)/;
		if(!$1){$basefile="${Xdpath}_temp$os_sepax$bw1$imode$bw2"}
		elsif($1==1){$basefile="${dpath}_temp$os_sepax$bw1$imode$bw2"}
		else{$bw1=~s/\//${os_sepax}_temp$os_sepax/;$basefile="$dpath$bw1$imode$bw2"}
	}
	elsif(defined $OPT{"${sfnm}base"}){
		if($OPT{"${sfnm}base"}=~/^([a-zA-Z]:|\/)/){$para='3'}
		elsif($OPT{"${sfnm}base"}=~/^[^\/]+\/[^\/]+$/){$para='2'}
		elsif($OPT{"${sfnm}base"}=~s/^!//){$para='1'}
		else{$para='0'}
		$para.=$OPT{"${sfnm}base"};
	}
	elsif($sfnm eq 's' && $h_base==1 && $url=~/$DV(.+)(\.html?)$/){	#ページ毎に選択
		$basefile="$dpath$1$imode$2";
	}
	if(!$basefile){
		if($para=~/^(\d?)(.+)(\.html?$)/){
			if(!$1){
				$basefile="${Xdpath}_temp$os_sepax$2$imode$3";
#				if($owner ne '' && $owner ne $whatsid){$basefile=~s/$whatsid/$owner/}
			}	#ジャンル
			elsif($1==1){$basefile="${dpath}_temp$os_sepax$2$imode$3"}	#共用
			elsif($1==2){	#他ジャンル
				$bw1=$2;$bw2=$3;
				$bw1=~s/\//${os_sepax}_temp$os_sepax/;
				$basefile="$dpath$bw1$imode$bw2";
			}
			else{	#他ディレクトリ
				$basefile="$2$imode$3";
				if($basefile!~/$EN_DOC/){$basefile=$EN_DOC.$basefile}
				$htmlx=$basefile;
				$bw1=$EN_DOC; $bw2='##';
				if(!$OS){
					$basefile=~s/\//$os_sepax/g;
					$bw1=~s/$os_sepa/\//g;
					$htmlx=~s/$os_sepa/\//g;
				}
				$htmlx=~s/$bw1(.*)\/[^\/]+/$1/;
			}
		}
		else{
			if($sfnm eq ''){
				$basefile="${Xdpath}_temp${os_sepax}whatsnew$imode.html";
#				if($owner ne '' && $owner ne $whatsid){$basefile=~s/$whatsid/$owner/}
			}
			else{$basefile="${Xdpath}_temp${os_sepax}whatsindex$imode.html"}
		}
	}
	if($bw2 ne '##'){
		$htmlx=$basefile;
		if(!$OS){$htmlx=~s/$os_sepa/\//g}
		if($htmlx=~/$from_doc(.*)\/[^\/]+/){$htmlx="$from_doc$1"}
		elsif($htmlx=~/$whatsnew\/(.*)\/[^\/]+/){
		$htmlx="$from_doc$1";}
	}
	if($sfnm eq 's' && $basefile=~/<!--(c|C)ustom(\d+)-->/){
		$basefile=$`;$bw1=$';
		if($1 eq 'c'){$bw2=$h_custm[$1-1];$bw3=$cust[$1-1]}
		else{$bw2=$h_mcustm[$1-1];$bw3=$mcust[$1-1]}
		if(substr($bw2,0,1) eq 's' && $bw3=~/<>/){$basefile.="$`$bw1"}
		else{$basefile.="$bw3$bw1"}
	}
	$basefile=~s/%replace%/$OPT{'rep'}/;
	$basefile=~s/%owner%/$owner/;
	$basefile=~s/%recid%/$rec_ID/;
	&open_file('HFILE',$basefile,'08','BASE HTML ');
	undef $baseh_sw; undef $baseh_sw1; $yXgpath=$Xgpath;
	while(<HFILE>){
		chomp;
		if($_=~/< *base *href *= *"?([^"=]*)["\- ]/i){
			$auto_sw=0;
			$baseh_sw1=$1;
			if($k_htsw>0){
				$bw1="$host_url$chkhtml";
				if($bw1=~/$1(.*\/)/){$yXgpath=$1.'_img/'}
				elsif($bw1=~/(.*\/)/){$yXgpath=$1.$Xgpath}
				$baseh_sw=$1;
			}
		}
		push(@dataz,$_);
	}
	close(HFILE);
	return $basefile;
}

sub hikisu {
#	$backp='javascript:history.go(-1)';
	foreach(@argh){
		if($_=~/^id:(.*)/){$whatsid=$1}
		elsif($_=~/^rec([dc]?):(.+)$/){$recno=$2;$adbsw=$1}
		elsif($_=~/^filter:(.+)/){$ckey_h=$1}
		elsif($_=~/^call:(.+)/){$recno=$1;$adbsw='x'}
		elsif($_=~/^mid:(.+)/){$mid=$1}
		elsif($_ eq 'i'){$imode=$icode}
		elsif($_=~/^sort:(.+)/){$SO_SW=$1}
		elsif($_=~/^search:(.+)/){$FORM{'search'}=$1}
		elsif($_ eq 'pchk:'){$S_pchk=1}
		elsif($_=~/^([^:]+)(:?)(.*)/){
			if($1 eq $COMOUT){
				$set_htmlout=$3;
				if($set_htmlout=~s/^([^:]+)(:?)(.*)/$1/){$out_htmlsw=$3}
			}
			elsif($1 eq 'window'){$window= $3 ne '' ? $3:'newwin'}
			elsif($1 eq 'target'){$window="f=$3"}
			elsif($1 eq 'set' || $1 eq 'try'){
				if($3){$whatsplus=$3}
				$areapl="+$_";
			}
			elsif($1 eq 'nowindow'){$window=''}
			elsif($1 eq $COMJOB){
				if($3=~/(\d+):(.*)/){$inp_menu=$1;$inp_id=$2}
				next;
			}
			elsif($1 eq 'D'){$DN=$3}
			elsif($1 eq 'spl'){next}
			elsif($1 eq 'pfix'){$set_htmlout=$3;$mak_sw=1}
			elsif($_ eq 'nolink'){$nolink=1}
			else{$OPT{$1}= $3 ne '' ? $3:1}
			if($hikisu!~/$1$2/){$hikisu.="+$_"}
		}
	}
}

sub link_html {
	if(($dum,$valuex)=$_=~/ *(a|link).* +href *= *"?([^"> ]*)[ ?"]?.*>/i){
		if($valuex!~/^https?:\/\//i && $valuex!~/^mailto:/i && $valuex!~/javascript:/ && substr($valuex,0,1) ne '#'){
			if(&img_v){$_=~s/(href *= *"?)[^" ]*(["> ])/$1$valuex$2/i}
		}
	}
	elsif(($dum,$h_img,$valuex)=$_=~/ *(image|img|script|embed).* +(src) *= *"?([^" ]*)["> ]/i){&himg}
	elsif(($valuex)=$_=~/body.*background-image.*url *\("?([^()]*)"?\)/i){
		if($valuex!~/^https?:\/\//i){
			if(&img_v){$_=~s/(background-image.*url *\("?)[^()]*("?\))/$1$valuex$2/i}
		}
	}
	elsif(($dum,$h_img,$valuex)=$_=~/ *(body|table|td|th).*(background) *= *"?([^"]*)[">]/i){&himg}
	elsif(($dum,$h_img,$valuex)=$_=~/ *(param).* +(value) *= *"?([^"> ]*)[ ?"]?.*>/i){&himg}
	elsif($_=~/preloadimages/i){
		my $ww;
		while($_=~/\'([^\']+)\'/){
			$valuex=$1;$ww.="$`'";$_=$';
			if($valuex!~/^https?:\/\//i){&himg}
			$ww.="$valuex'";
		}
		$_="$ww$_";
	}
}

sub himg {
	if($valuex ne '' && $valuex!~/^https?:\/\//i && index($valuex,'<')<0){
		if(&img_v){$_=~s/($h_img *= *"?)[^" ]*(["> ])/$1$valuex$2/i}
	}
}

sub img_v {
	$htmlx1=$htmlx;
	if($valuex eq '' || $valuex=~s/^\.\//$htmlx\// || index($valuex,'<')>=0 || substr($valuex,0,1) eq '/'){return 0}
	while($valuex=~s/^\.\.\///){$htmlx1=~s/(.*)\/.*/$1/}
	$valuex="$host_url$htmlx1/".$valuex;
	return 1;
}

sub meta_check {
	my $chars;
	if(($chars)=$_=~/<meta.*charset *= *([^>]*)[\"> ]/i){
		if($chars=~/ISO.2002.JP/i){$charset='jis'}
		elsif($chars=~/EUC.JP/i){$charset='euc'}
		else{$charset=''}
		if($charset){require $jcpath}
	}
	elsif($_=~/<meta.*language.*content *=[\" ]*en/i){$engsw=1}
}

sub open_file {
	my($handle,$fname,$eno,$fmes)=@_;
	if(open($handle,$fname)){return}
	$handle="$eno $fmesファイルが開けません！$!";
	&err($handle,$fname);
}

sub passchk {
	my($id,$pass,$find_b,$wp);
	if($FORM{'pid'} eq '' || $FORM{'pass'} eq ''){&perror('ID、パスワードが入力されていません！')}
	&open_file('PASS',"$dpath$FORM{'genre'}$os_sepax$p_name",'09','パスワード');
	while(<PASS>){
		chomp($_);
		if($_ eq '!'){next}
		($id,$pass)=split(':',$_);
		if($id eq $FORM{'pid'}){
			if(!&pwd_match($FORM{'pass'},$pass)){&perror("10 パスワードが違います!")}
			$find_b=2;
			last;
		}
	}
	if($find_b!=2){&perror("11 正しいID、パスワードを指定してください！")}
	if($FORM{'rem_pass'}){$wp=1}
	else{$wp=0}
	print &setCookie("w_pchk_$FORM{'genre'}","$FORM{'genre'}:$find_b",$wp);
}

sub perror {
	$backp='javascript:history.go(-1)';
	$endmsg='ID、パスワード入力画面に戻る';
	&err($_[0]);
}

sub setCookie {
	my($val)=$_[1];
	$val=~s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
	$cook="$_[0]=$val; ";
	my $co="Set-Cookie: $cook";
#	$co.="path=./; \n";
	if($_[2]){$co.='expires='.&get_expire."\n"}
	return $co;
}

sub getCookie {
	my($wc);
	if(defined $cook){$wc=$cook}
	elsif($ENV{'HTTP_COOKIE'} ne ''){$wc=$ENV{'HTTP_COOKIE'}}
	else{return undef}
	$wc=~s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg;
	if($wc=~/w_pchk_$whatsid=(.*?):([^;]*)/){
		if($1){$COOKIE{'genre'}=$1};
		if($2){$COOKIE{'find'}=$2};
		return $2;
	}
	return undef;
}

sub passin {
	if(&getCookie!=2){
		$ENV{'QUERY_STRING'}=~s/\+?pchk://;
		my($hidden)="<input type=hidden name=genre value=$whatsid><input type=hidden name=hikisu value=$ENV{'QUERY_STRING'}>";
		$dw_out='';
		&open_file('LOGIN','_login.html','12','LOGIN');
		while(<LOGIN>){
			$_=~s/\n//;
			$_=~s/\r//;
			$_=~s/#title/$PASS_mes/;
			$_=~s/#cgi/$cgi2/;
			$_=~s/#hidden/$hidden/;
			$_=~s/#Cook_days/$Cook_days/;
			$dw_out.=$_;
		}
		close(LOGIN);
		&html_out;
	}
	else{$nopass=1}
}

#パスワード複元
sub pwd_match {
	my($crptkey)=0;
	if($_[1]=~/^\$1\$/){$crptkey=3}	# FreeBSDサーバ対応
	return crypt($_[0], substr($_[1],$crptkey,2)) eq $_[1];
}

sub get_expire{
	my(@exp)=gmtime(time + int($Cook_days*60*60*24));
	$exp[4]=substr("JanFebMarAprMayJunJulAugSepOctNovDec",$exp[4]*3,3);
	$exp[6]=substr("SunMonTueWedThuFriSat",$exp[6]*3,3);
	sprintf("$exp[6], %2.2d-$exp[4]-%4.4d %2.2d:%2.2d:%2.2d GMT",$exp[3],$exp[5]+1900,$exp[2],$exp[1],$exp[0]);
}

sub set_gra_kizi {
	while($_=~/<!--([^>]*)[: ]?kizi_g(\d+)[: ]?(\*?)[: ]?(.*?)-->/){
		$gmae=$`;$mae=$1;$d1=$2;$csw=$3;$ato=$4;$kurik=$';
		if(defined $fir_grap){@for_gra=split($DV,$fir_grap);undef $fir_grap}
		if($for_gra[$d1-1]=~/\d+,([^,]*,[^,]*,[^,]*)/ && substr($1,0,1) ne ','){
			$w1=$1;
			($gra,$width,$height)=split(',',$w1);
			if(index($csw,'*')>=0 && $gra eq ''){$_=$kek;$kek='';return}
			if($k_htsw>0){&move_gra}
			if($gra=~/\.csv$|\.html?$|\.txt$/i){$w1=&outcsv}
			elsif($gra=~/\.(swf|jpg|gif|png|bmp)$/i){
				$w1= $1 eq 'SWF' || $1 eq 'swf' ? "<embed src=$xXgpath$gra type=application/x-shockwave-flash quality=best play=true></embed":"<img src=$xXgpath$gra";
				if($ato=~s/(\d*)x(\d*)//i){$width=$1;$height=$2}
				if($width){$w1.=" width=$width"}
				if($height){$w1.=" height=$height"}
				$kek.="$gmae$mae$w1>$ato";
			}
		}
		elsif(index($csw,'*')>=0){$_=$kek;$kek='';return}
		$_=$kurik;
	}
	if($kek){$_="$kek$_";$kek=''}
}

sub spdir_chk {
	if(!$SP_dir){return $_[0]}
	if($SP_dir=~/$whatsid:([^,:]+)/){return $1}
	return $_[0];
}

sub bara_key {
	my $char = '(?:[\x00-\x7F\xA1-\xDF]|[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC])';
	my @datas=$FORM{'search'}=~/$char/go;
	my($qc,$qcs,$andi,$ori);
	foreach(@datas){
		if($_ eq '"'){
			if(defined $qc && $qc){push(@SKEY,$qc);undef $qc}
			else{$qc=''}
		}
		elsif(defined $qc){$qc.=$_}
		elsif($_ eq ' ' || $_ eq '　'){
			if(defined $qcs && $qcs){push(@SKEY,$qcs);undef $qcs;$andi++}
			else{$qcs=''}
		}
		elsif($_ eq '|' || $_ eq '｜'){
			if(defined $qcs && $qcs){push(@SKEY,$qcs);undef $qcs;$ori++}
			else{$qcs=''}
		}
		elsif(defined $qcs){$qcs.=$_}
		else{$qcs=$_}
	}
	if($qcs){push(@SKEY,$qcs)}
	if($andi && $ori){&err('and と or の組み合わせ条件は使えません')}
	if($ori){return 0}
	return 1;
}

sub setfile_read {
	&open_file('FILE',"${Xdpath}_temp$os_sepax$set_htmlout.dat",'58','HTML書出設定');
	$_=<FILE>;
	chomp($_);
	($k_imode,$k_htsw,$k_delsw,$k_shdir,$k_hdir,$k_index,$k_ejbase,$k_ejbase1,$k_sjbase,$k_sjbase1,$k_phik,$k_hdirs)=split("\t",$_);
	close(FILE);
	if(!$k_ejbase1){$k_ejbase1=$k_ejbase}
	if($k_ejbase1){$OPT{'base'}=$k_ejbase1}
	if(!$k_sjbase1){$k_sjbase1=$k_sjbase}
	if($k_sjbase1){$OPT{'sbase'}=$k_sjbase1}
	if(!$k_hdir){$k_hdir=$k_shdir}
	if($k_imode eq 'on'){$imode=$icode}
	if($k_phik){@argh=split(/\+/,$k_phik);&hikisu}
	$k_index=~s/(\.html?)$/$imode$1/;
	$khtml=$1;
	if(defined $mak_sw){$k_htsw=0}
}
