#!/usr/bin/perl
##!C:/Perl/bin/perl

# ライブラリ取込
require 'jcode.pl';

require 'config/_eform_ini.cgi';
require '_form_header.cgi';
require '_form_footer.cgi';
require '_contactform.cgi';
require 'validate.cgi';

&decode;

no warnings qw(once);

#入力項目
our ($a_shimei,$b_furigana,$g_yuubin,$c_tel,$d_email,$e_question,$f_doui);
#入力項目（エラー用）
our ($erra_shimei,$errb_furigana,$errg_yuubin,$errc_tel,$errd_email,$erre_question,$errf_doui);



  $stmode	=$in{'stmode'};

	if($stmode eq "check"){
		&contactform;
		&form_footer;
	}elsif($stmode eq "send"){
		&form_header;
		&mail_contactform;
	}else{
		print "Content-type: text/html\n\n";
		print <<"EOF";
<!doctype html>
<html lang="ja">
<head>
<meta chrset="shift-jis">
<title>お問い合せエラー｜株式会社シーコット</title>
</head>
<body>
<p>server error</p>
</body>
</html>
EOF
	}

#------------------------------------------------------
#  デコード処理  #
#------------------------------------------------------
sub decode {
	$post_flag=0;
	if ($ENV{'REQUEST_METHOD'} eq "POST") {
		$post_flag=1;
		if ($ENV{'CONTENT_LENGTH'} > 51200) {
			&error("The amount of the contribution is too large.");
		}
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	} else {
		$buffer = $ENV{'QUERY_STRING'};
	}
	@pairs = split(/&/, $buffer);

	foreach (@pairs) {
		($name,$value) = split(/=/);

		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

		# タグ処理
		$value =~ s/&/&amp;/g;
		$value =~ s/"/&quot;/g;
		$value =~ s/</&lt;/g;
		$value =~ s/>/&gt;/g;

		$in{$name} = $value;
	}
}

1;
