#!/usr/bin/perl
$|=1;

use DBI;
use Time::Local;
use Image::Magick;
#use CGI::Carp qw(fatalsToBrowser);

require '/home/yymail/public_html/lib/aelib.pl';
require '/home/storenavi/public_html/master/index.pl';
require '/home/snich/public_html/lib/analog_system.pl';
require '/home/snich/public_html/lib/jcode.pl';
require '/home/snich/public_html/lib/cgi-lib.pl';
$sendmail = '/usr/sbin/sendmail';
$domain = "http://www.storenavi.com";
$domains = "https://www.storenavi.com";
$cgifile = "index.a";
$snich = 'jin@clockstep.com';
$bannertemp = '/home/storenavi/public_html/store/banner';#登録時のバナーイメージの格納フォルダ
$bannerplace = '../store/banner';#表示寺のバナーイメージの格納フォルダ

&ReadParse(*in);
$mode = $in{'mode'};
$type = $in{'type'};
$returnadd = $in{'returnadd'};
$cmode = $in{'cmode'};
$uid = $in{'uid'};
$cid = $in{'cid'};
$gid = $in{'gid'};
$mobid = $in{'mobid'};
$cname = $in{'cname'};
$gscategory = $in{'gscategory'};
$newgoods = $in{'newgoods'};
$cgegs = $in{'cgegs'};
$cgemath = $in{'cgemath'};
$cgeexplus = $in{'cgeexplus'};
$ersgs = $in{'ersgs'};
$ersexplus = $in{'ersexplus'};
$newgoodsmath = $in{'newgoodsmath'};
$newexplus = $in{'newexplus'};
$schepl = $in{'schepl'};
$okgsmath = $in{'okgsmath'};
$watch = $in{'watch'};

$regname = $in{'regname'};
$freename = $in{'freename'};
$sex = $in{'sex'};
$birtha = $in{'birtha'};
$birthb = $in{'birthb'};
$birthc = $in{'birthc'};
$email = $in{'email'};
$zip1 = $in{'zip1'};
$zip2 = $in{'zip2'};
$ken = $in{'ken'};
$add1 = $in{'add1'};
$add2 = $in{'add2'};
$add3 = $in{'add3'};
$tel = $in{'tel'};
$fax = $in{'fax'};
$howto = $in{'howto'};
$password = $in{'password'};
$pass = $in{'pass'};
$areacode = $in{'areacode'};
$sendmon = $in{'sendmon'};
$sendday = $in{'sendday'};
$sendtime = $in{'sendtime'};
$msg = $in{'msg'};
$contacttitle = $in{'contacttitle'};
$contactmsg = $in{'contactmsg'};
$contactname = $in{'contactname'};
$contactemail = $in{'contactemail'};
unless($watch){$watch=time;}

$afy = $in{'afy'};

$time = time;

$imgplace = 'store/gsimgs';#表示時の商品イメージの格納フォルダ

$ngs = "$uid";

#もしモバイルからのアクセスなら
&furiwake;
if ($furiwake eq "mobile" && $pc ne "yes") {
	print "Location: http://www.storenavi.com/mobile.a?uid=$uid\n\n";
}


unless($uid){
	#トップページに飛ばす

	if($afy){
		print "Set-Cookie: afy=$afy;";
	}

	print "content-type: text/html\n\n";

#クッキー
#	$afytag = <<"EOF";
#	<meta http-equiv="Set-Cookie" content="afy=$afy;">
#EOF

	open(HTML,"/home/storenavi/public_html/index.html");
	while(<HTML>){push(@disphtml,$_);}
	close(HTML);

	foreach $gogodisphtml(@disphtml){
		#$_ =~ s/Shift_JIS/euc-jp/g;

		if($afy && $gogodisphtml =~ /<!--here-->/){
			print $afytag;
		}else{
			#jcode::convert(*_,'euc');
			print $gogodisphtml;
		}
	}

	#print "Location: http://www.storenavi.com/index.html\n\n";
	exit(0);
}


#クッキーの読み込み--------------------------------------------------------------------------
$cookie=$ENV{'HTTP_COOKIE'};
@part=split(';',$cookie);
foreach $w (@part){
	if ($w =~ /storedata/){
		($cname,$storedata)=split('=',$w); #変数にユーザー名を代入
		$storedata =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg; #デコード
	}
}
#クッキーの読み込み--------------------------------------------------------------------------

#データベース---------------------------------------------------------
	$ds = 'dbi:Pg:dbname=store';
	$user = 'pgsql';
	$dbpass = '';
	$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");
		
	unless($mobid){
		#モバイル用IDの読み込み--------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select newid from mobids");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$mobid = @$ref[0];}
		$sth = $dbh->prepare("update mobids set newid = newid +1");
		$sth->execute;
		#モバイル用IDの読み込み--------------------------------------------------------------------------------------
	}

	#店舗情報の読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from users where uid = '$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$loginok = join(':-snichcode-:',@$ref);
	}
	($uid,$masterpass,$time,$regname1,$regname2,$freename1,$freename2,$masteremail,$shopname,$compname,$shopadd,$mastertel,$masterfax,$masterhoetopay,$needfee,$ersday,$arrive,$return,$coimg,$homepage,$masterzip1,$masterzip2,$masterplan,$okgsmath,$afyname) = split(":-snichcode-:",$loginok);
	unless($loginok){ &exitError('エラー：店舗が存在しません。'); }
	#店舗情報の読み込み--------------------------------------------------------------------------------------

		#プライバシーポリシーの読み込み
		$sth = $dbh->prepare("select * from privacy where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$prdata = join(':-snichcode-:',@$ref);}
		($ruid,$description,$prvtext) = split(":-snichcode-:",$prdata);
		
	#店舗状態の読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select disp from openshop where uid = '$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){$openshop = @$ref[0];}
	unless($watch eq "mastercheck"){
		if($openshop eq "close"){ &closeShop; }
	}
	#店舗状態の読み込み--------------------------------------------------------------------------------------

	#テンプレートの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select usetemp from openshop where uid = '$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){$usetemp = @$ref[0];}
	#テンプレートの読み込み--------------------------------------------------------------------------------------

	#店舗デザインの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from design where uid = '$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$design = join(':-snichcode-:',@$ref);
	}
	($uid,$bgcolor,$titleimg,$titlebgcolor,$titlesize,$titlecolor,$titlestyle,$fontcolor,$linkcolor,$displimit,$bgcolorin,$newslimit,$toptext,$topimg,$usecal,$buymath,$menutitlecolor,$menubackcolor,$menulinecolor,$menutitletextcolor,$bodylr,$bodylinecolor,$calcolor,$globebackcolor) = split(":-snichcode-:",$design);
	if(-e $topimg){$topimgdisp="<img src=../store/topimgs/$uid.jpg>";}

	#店舗デザインの読み込み--------------------------------------------------------------------------------------

	#メニューの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from category where uid = '$uid' order by cnum");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$categorypart = join(':-snichcode-:',@$ref);
		push(@category,$categorypart);
	}
	#メニューの読み込み--------------------------------------------------------------------------------------

	#バナーの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from bunner where uid = '$uid' order by bid");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$bannerpart = join(':-snichcode-:',@$ref);
		push(@banner,$bannerpart);
	}
	#バナーの読み込み--------------------------------------------------------------------------------------
	
	#メニューデザインの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from menu where uid = '$uid' order by mnum");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$menupart = join(':-snichcode-:',@$ref);
		push(@menu,$menupart);
	}
	#メニューデザインの読み込み--------------------------------------------------------------------------------------

	#各ページテキストの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from textbox where uid = '$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){$textbox = join(':-snichcode-:',@$ref);}
	($uid,$disptxttoptext,$disptxtcart,$disptxtintext,$disptxtchecktxt,$disptxtprofile,$disptxtcontact,$disptxtcthanks,$disptxtthanks,$dispfooter) = split(":-snichcode-:",$textbox);

	$disptxttoptext =~ s/\n/<br>/g;
	$disptxtcart =~ s/\n/<br>/g;
	$disptxtintext =~ s/\n/<br>/g;
	$disptxtchecktxt =~ s/\n/<br>/g;
	$disptxtprofile =~ s/\n/<br>/g;
	$disptxtcontact =~ s/\n/<br>/g;
	$disptxtcthanks =~ s/\n/<br>/g;
	$disptxtthanks =~ s/\n/<br>/g;

	#各ページテキストの読み込み--------------------------------------------------------------------------------------

	if($mode eq ""){
		#トップページの時---------------------------------------------------------------------------------------------------

		#オススメ情報を入力すること
		$sth = $dbh->prepare("select * from news where uid='$uid' order by timelocal DESC limit $newslimit");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$ncodata = join(':-snichcode-:',@$ref);
			push(@news, $ncodata);
		}

		$sth = $dbh->prepare("select * from goodslist where uid='$uid' and gsdisp='1' and gscategory != '' order by time DESC limit 5");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$goodspart = join(':-snichcode-:',@$ref);
			push(@goods,$goodspart);
		}

	}elsif($mode eq "categorydisp"){

		#EZテンプレート（カテゴリ用）の呼び出し
		#require '/home/storenavi/public_html/master/tmp_category.pl';

		#カテゴリ用ページの時---------------------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select * from goodslist where uid = '$uid' and gscategory = '$gscategory'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$goodspart = join(':-snichcode-:',@$ref);
			push(@goods,$goodspart);
		}
		##メニュー名読み込み
		$sth = $dbh->prepare("select * from category where uid = '$uid' and cid='$gscategory' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$linecategorypart = join(':-snichcode-:',@$ref);}
		($uid,$cid,$cname,$cnum,$ctitle,$ctext,$ctitlecolor,$cgimg) = split(":-snichcode-:",$linecategorypart);

		$cnamedisp = $cname;
		#$cnamedisp =~ s/<br>//g;
		
		$gmenu = "＞　<a href=$cgifile?uid=$uid&mode=categorydisp&gscategory=$gscategory&watch=$watch&mobid=$mobid>$cnamedisp</a>";


	}elsif($mode eq "dispone"){
		#単品用ページの時---------------------------------------------------------------------------------------------------
		
		$sth = $dbh->prepare("select * from goodslist where uid='$uid' and gid='$gid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$goodspart = join(':-snichcode-:',@$ref);
		}
		($uid,$gid,$time,$gsname,$gscategory,$gsprice,$gsunit,$gstax,$explus,$extext,$gnum,$gsallmath,$gsdisp,$gsimg,$extext02,$costprice,$release) = split(":-snichcode-:",$goodspart);

		##メニュー名読み込み
		$sth = $dbh->prepare("select cname from category where uid = '$uid' and cid = '$gscategory'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$cname = @$ref[0];}

		$gmenu = "＞　<a href=$cgifile?uid=$uid&mode=categorydisp&gscategory=$gscategory&watch=$watch&mobid=$mobid>$cname</a>　＞　 $gsname";


	}elsif($mode eq "profile"){
		#会社紹介ページの時---------------------------------------------------------------------------------------------------

		#会社情報の読み込み
		$sth = $dbh->prepare("select * from users where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$codata = join(':-snichcode-:',@$ref);}

		#振込方法の読み込み
		$sth = $dbh->prepare("select * from howtopay where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$howtopaydt = join(':-snichcode-:',@$ref);}

		#送料の読み込み
		$sth = $dbh->prepare("select * from sendfee where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$sendfeedt = join(':-snichcode-:',@$ref);}

		#例外地域の読み込み
		$sth = $dbh->prepare("select * from kenfee where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$kenfeedt = join(':-snichcode-:',@$ref);}
		
		#県コードの読み込み
		$sth = $dbh->prepare("select * from kencodes");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){push(@kencode, join(':-snichcode-:',@$ref));}

		foreach (@kencode) {
			($kencode, $kenname) = split(':-snichcode-:', $_);
			$ken{"$kencode"} = $kenname;
		}

		@kenfee = split(":-snichcode-:",$kenfeedt);
		($uid,$pass,$time,$regname1,$regname2,$freename1,$freename2,$email,$shopname,$compname,$shopadd,$tel,$fax,$hoetopay,$needfee,$ersday,$arrive,$return,$coimg,$homepage,$zip1,$zip2,$plan,$okgsmath,$afyname) = split(":-snichcode-:",$codata);
		($uid,$bank,$banktext,$daibiki,$daibikitext,$yubin,$yubintext,$credit,$credittext) = split(":-snichcode-:",$howtopaydt);
		($uid,$area01,$area02,$area03,$area04,$area05,$area06,$area07,$area08,$area09,$area10,$area11,$area12,$area13,$area14,$daibikifee,$nofee) = split(":-snichcode-:",$sendfeedt);

		$gmenu = "＞　案内";

	}elsif($mode eq "privacy"){
		#プライバシーポリシーの時---------------------------------------------------------------------------------------------------

		#会社情報の読み込み
		$sth = $dbh->prepare("select * from users where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$codata = join(':-snichcode-:',@$ref);}
		
		($uid,$pass,$time,$regname1,$regname2,$freename1,$freename2,$email,$shopname,$compname,$shopadd,$tel,$fax,$hoetopay,$needfee,$ersday,$arrive,$return,$coimg,$homepage,$zip1,$zip2,$plan,$okgsmath,$afyname) = split(":-snichcode-:",$codata);

		$gmenu = "＞　プライバシーポリシー";

	}elsif($mode eq "contact"){
		#お問い合わせページの時---------------------------------------------------------------------------------------------------
		#お問い合せ項目の読み込み
		$sth = $dbh->prepare("select * from contact where uid = '$uid' order by ctnum");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$cttdata = join(':-snichcode-:',@$ref);
			push(@contact, $cttdata);
		}
		
		$gmenu = "＞　お問い合わせ";
	}elsif($mode eq "cthanks"){
		#お問い合わせ完了ページの時---------------------------------------------------------------------------------------------------

		$gmenu = "＞　<a href=$cgifile?uid=$uid&mode=contact&watch=$watch&mobid=$mobid>お問い合わせ</a>　＞　送信完了";

	}elsif($mode eq "cart"){
		#カート処理ページの時---------------------------------------------------------------------------------------------------

		$gmenu = "＞　カートを見る";

	}elsif($mode eq "check"){
		#個人情報入力ページの時---------------------------------------------------------------------------------------------------

		$sth = $dbh->prepare("select * from howtopay where uid = '$uid' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$howtopaydt = join(':-snichcode-:',@$ref);
		}
		($uid,$bank,$banktext,$daibiki,$daibikitext,$yubin,$yubintext,$credit,$credittext) = split(":-snichcode-:",$howtopaydt);

		$gmenu = "＞　<a href=$cgifile?uid=$uid&mode=cart&watch=$watch&mobid=$mobid>カートを見る</a>　＞　配送先入力";


	}elsif($mode eq "buy"){
		#情報確定ページの時---------------------------------------------------------------------------------------------------

		$gmenu = "＞　<a href=$cgifile?uid=$uid&mode=cart&watch=$watch&mobid=$mobid>カートを見る</a>　＞　<a href=history.go(-1)>配送先入力</a>　＞　入力情報確認";


	}elsif($mode eq "thanks"){
		#お礼ページの時---------------------------------------------------------------------------------------------------

		$gmenu = "＞　カートを見る　＞　配送先入力　＞　入力情報確認　＞　ご購入完了";
	}

	$sth->finish;
	$dbh->disconnect;

	#店舗表示設定-------------------------------------------------------------------------------------
	if($cnamedisp){$dgsname="／$cnamedisp"}
	if($gsname){$dgsname = "／$cname／$gsname"}
	
	$title = "<title>$shopname$dgsname</title>";
	if(-e $titleimg){$shopnamedisp="<img src=store/titleimgs/$uid.jpg>";}else{$shopnamedisp="　 <$titlestyle>$shopname</$titlestyle>";}
	$titleheight = "60" if($titleimg || $titlebgcolor);
	#店舗表示設定-------------------------------------------------------------------------------------
#データベース---------------------------------------------------------


#ショッピングトップページ----------------------------------------------------------------------------------------------------------------------
unless($mode){

	if($topimgdisp){
	$topimgdata=<<"EOF";
	<table border="0" width="545" cellpadding = "0" cellspacing="0">
	<tr><td>$topimgdisp</td></tr>
	<tr><td><img src="images/spacer.gif" height="5" width="10"></td></tr>


	</table>
EOF
	}

	$play.=<<"EOF";
	<table border="0" width="545" cellpadding = "0" cellspacing="0">
EOF
	if($disptxttoptext){
	$disptxttoptext = &loadPS("$disptxttoptext");
	$play.=<<"EOF";
	<tr><td><font size="2">$disptxttoptext</font></td></tr>
	<tr><td><img src="images/spacer.gif" height="5" width="10"></td></tr>
EOF
	}

	$play.=<<"EOF";
		</table>
EOF
if(@goods){
	$play.=<<"EOF";
		<hr size="1" noshade>
		<table border="0" width="100%" cellpadding = "3" cellspacing="0">
		<tr>
EOF
	foreach(@goods){$gsexists++;}
	$gsexistspct = int(100/$gsexists);

	foreach(@goods){
		($uid,$gid,$time,$gsname,$gscategory,$gsprice,$gsunit,$gstax,$explus,$explain,$gnum,$gsallmath,$gsdisp,$gsimg,$extext02,$costprice,$release) = split(":-snichcode-:",$_);
		unless($gsdisp){next;}
		$imgnamedisp = "$imgplace/$gsimg"."_k.jpg";
		if(-e $imgnamedisp){$imgdisp="<img src=$imgnamedisp border=0>";}
		else{$imgdisp="<img src=images/noimage.gif border=0>";}


		$play.=<<"EOF";
			<td align="center" valign="top" width="$gsexistspct%">
			<font size="2"><a href="$cgifile?uid=$uid&mode=dispone&gid=$gid&gscategory=$gscategory&watch=$watch&mobid=$mobid">
			$imgdisp<br>$gsname</a></font>
			</td>
EOF
	}
	
	$play.=<<"EOF";
		</tr>
		</table>
EOF
}
	$play.=<<"EOF";
		<hr size="1" noshade>
		
		<table border="0" width="100%" cellpadding = "0" cellspacing="0">
		<tr>
		<td valign="top">

			<table border="0" width="100%" cellpadding = "1" cellspacing="1">
EOF

			foreach (@news){
			($uid,$newsnum,$year,$mon,$day,$msg,$msgtitle) = split(":-snichcode-:",$_);
			$msg =~ s/\n/<br>/g;

			$play .=<<"EOF";
			<tr>
			<td><font size="2">$year/$mon/$day　$msgtitle</font></td></tr>
			<tr>
			<td><font size="2">$msg</font></td>
			</tr>
			<tr>
			<td><hr size=1 color="#cccccc"></td>
			</tr>
EOF
			}
		$play.=<<"EOF";
		</table>

		</td>
EOF
if($usecal){

	$play.=<<"EOF";
		<td width="15" valign="top">
		<img src="images/spacer.gif" width="15" height="15">
		</td>
		<td width="137" valign="top">
EOF

	&calendar;

		$play.=<<"EOF";
EOF
}
		$play.=<<"EOF";
		</td>
		</tr>
		</table>
		<br>
EOF
&designdisp;
}
#カテゴリ内商品表示----------------------------------------------------------------------------------------------------------------------
if($mode eq "categorydisp"){

	$ctext = &loadPS("$ctext");

		if($cgimg){
			$checkimg_c="/home/storenavi/public_html/store/category/$cgimg.jpg";
			if(-e $checkimg_c){$cgimgdisp ="<img src=store/category/$cgimg.jpg><br>";}else{$cgimgdisp ="";}
		}

		unless($cgimg){ $cgunline="<hr size=1 color=#dddddd noshade>";}

		if($ctitle && $ctext ){
			$gscategorydisp = <<"EOF";
			$cgimgdisp
			<font size="2" color="$ctitlecolor"><b>$ctitle</b></font><br>
			$cgunline
			<font size="2">$ctext</font>
			<hr size=1 color="#dddddd" noshade>
EOF
		}elsif($ctitle && $ctext eq ""){
			$gscategorydisp = <<"EOF";
			$cgimgdisp
			<font size="2" color="$ctitlecolor"><b>$ctitle</b><br>
			<hr size=1 color="#dddddd" noshade>
EOF
		}elsif($ctitle eq "" && $ctext){
			$gscategorydisp = <<"EOF";
			$cgimgdisp
			<font size="2">$ctext</font>
			<hr size=1 color="#dddddd" noshade>
EOF
		}else{
			$gscategorydisp = <<"EOF";
			$cgimgdisp
EOF
		}

	$play.=<<"EOF";
		$gscategorydisp
		<table border="0" width="100%" cellpadding = "0" cellspacing="0"><tr>
EOF

	$tableflug=0;

	foreach(@goods){
		$tableflug++;
		($uid,$gid,$time,$gsname,$gscategory,$gsprice,$gsunit,$gstax,$explus,$extext,$gnum,$gsallmath,$gsdisp,$gsimg,$extext02,$costprice,$release) = split(":-snichcode-:",$_);
		if($gstax){$dispgstax="（税抜）";}else{$dispgstax="（税込）";}
		$imgnamedisp = "$imgplace/$gsimg"."_k.jpg";
		if(-e $imgnamedisp){$imgdisp="<img src=$imgnamedisp border=0 width=90>";}
		else{$imgdisp="<img src=images/noimage.gif border=0 width=90 height=90>";}


		$play.=<<"EOF";
		<td width="265">

		<table border="0" width="265" cellpadding = "0" cellspacing="0">
		<tr>
			<td>
				<table border="0" width="265" cellpadding = "0" cellspacing="0">
				<tr>
				<td width="90" valign="top"><a href="$cgifile?uid=$uid&mode=dispone&gid=$gid&gscategory=$gscategory&watch=$watch&mobid=$mobid" border="0">$imgdisp</a></td>
				<td width="5"><img src="images/spacer.gif" width="5"></td>
				<td width="170">
					<table border="0" width="100%" cellpadding = "1" cellspacing="2">
					<tr><td><font size="2"><a href="$cgifile?uid=$uid&mode=dispone&gid=$gid&gscategory=$gscategory&watch=$watch&mobid=$mobid"><b>$gsname</b></a></font></td></tr>
					<tr><td><font size="2">価格:$gsprice円$dispgstax</font></td></tr>
					<tr>

EOF

		if($buymath>0 && $gsallmath>0){
			$play.=<<"EOF";

				<form action="$cgifile" method="post">
				<td align="left">
				<select name="newgoodsmath">
EOF
			for($yu=1;$yu<=$gsallmath; $yu++){
				$play.="<option value=$yu>　$yu$gsunit　</option>";
				if($yu==$buymath){ last; }
			}
			if ($explus) {
				$play.=<<"EOF";
					</select><br>
					<select name="newexplus">
EOF
				foreach $explusdisp (split /\r\n|\r|\n/, $explus){
					$play.="<option value=\"$explusdisp\">　$explusdisp　</option>";
				}
			}
			$play.=<<"EOF";
				</select>
				<input type="submit" name="submit" value="購入する">
				<input type="hidden" name="mode" value="cart">
				<input type="hidden" name="uid" value="$uid">
				<input type="hidden" name="cmode" value="buy">
				<input type="hidden" name="gid" value="$gid">
				<input type="hidden" name="gscategory" value="$gscategory">
				<input type="hidden" name="watch" value="$watch">
				<input type="hidden" name="mobid" value="$mobid">
				</td>
				</form>
EOF
		}else{
			$play.=<<"EOF";
				<td>
				<font size=2>商品在庫：</font><font size=2 color=red><b>売り切れ</b></font>
				</td>
EOF
		}

	$play.=<<"EOF";
				</tr>
				</table>
			</td>
			</tr>
			</table>

			</td>
		</tr>
		<tr>
			<td><img src="images/spacer.gif" height="5"></td>
		</tr>
		<tr>
			<td><font size="2">$extext</font></td>
		</tr>
		</table>

		</td>
EOF

		if($tableflug==2){
			$play.="</tr><tr><td colspan=3><hr size=1 noshade></td></tr><tr>";
			$tableflug=0;
		}else{
			$play.="<td><img src=images/spacer.gif width=15></td>";
		}

	}#end_foreach

	if($tableflug==1){
	$play.="<td></td>";
	}
	
	$play.=<<"EOF";
	</tr>
	</table>
EOF
&designdisp;
}

#商品の単品表示---------------------------------------------------------------------------
if($mode eq "dispone"){

	$imgnamedisp = "$imgplace/$gsimg.jpg";
	if(-e $imgnamedisp){$imgdisp="<img src=$imgnamedisp>";}
	else{$imgdisp="<img src=images/noimage200.gif>";}

	if($gstax){$dispgstax="（税抜）";}else{$dispgstax="（税込）";}

	$extext =~ s/\n/<br>/g;

	$play.=<<"EOF";
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td valign="top" width="200">$imgdisp</td>
		<td valign="top" width="15"><img src="images/spacer.gif" width="15" height="15"></td>
		<td valign="top">
			<table width="100%" border="0" cellspacing="0" cellpadding="3">
			<tr><td bgcolor="#f1f1f1"><font size="2">商品名</font></td><td bgcolor="#f1f1f1"><font size="2">$gsname</font></td></tr>
			<tr><td bgcolor="#f1f1f1"><font size="2">価格</font></td><td bgcolor="#f1f1f1"><font size="2" color="red">$gsprice</font><font size="2">円$dispgstax</font></td></tr>
			<tr>
EOF

		if($buymath > 0 && $gsallmath > 0){
			$play.=<<"EOF";
				<form action="$cgifile" method="post">
				<td colspan="2" bgcolor="#f1f1f1" align="right">
				<select name="newgoodsmath">
EOF
			for($yu=1;$yu<=$gsallmath; $yu++){
				$play.="<option value=$yu>　$yu$gsunit　</option>";
				if($yu==$buymath){ last; }
			}
			if ($explus) {
				$play.=<<"EOF";
					</select><br>
					<select name="newexplus">
EOF
				foreach $explusdisp (split /\r\n|\r|\n/, $explus){
					$play.="<option value=\"$explusdisp\">　$explusdisp　</option>";
				}
			}
			$play.=<<"EOF";
				</select>
				<input type="hidden" name="mode" value="cart">
				<input type="hidden" name="uid" value="$uid">
				<input type="hidden" name="cmode" value="buy">
				<input type="hidden" name="gid" value="$gid">
				<input type="hidden" name="gscategory" value="$gscategory">
				<input type="hidden" name="watch" value="$watch">
				<input type="hidden" name="mobid" value="$mobid">
				　　<input type="submit" name="submit" value="購入する">
				</td>
				</form>
EOF
		}else{
			$play.=<<"EOF";
				<td bgcolor="#f1f1f1">
				<font size=2>在庫</font>
				</td>
				<td bgcolor="#f1f1f1">
				<font size=2 color=red><b>売り切れ</b></font>
				</td>
EOF
		}

	$play.=<<"EOF";
			</tr>
			<tr><td colspan="2"><font size="2">$extext</font></td></tr>
			</table>
		</td>
	</tr>
	</table>
EOF

	if($extext02){
		$extext02 =~ s/\n/<br>/g;
		$completeplay=&loadPS("$extext02");
	$play .=<<"EOF";
	<hr size=1 noshade>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr><td><font size="2">$completeplay</font></td></tr>
	</table>
EOF
	}

&designdisp;
}
#会社紹介--------------------------------------------------------------------------------------------------------------
if($mode eq "profile"){

	$imgnamedisp = "store/coimgs/$uid.jpg";
	$coimgdisp ="<img src=$imgnamedisp>";
	$disptxtprofile = &loadPS("$disptxtprofile");

	$play .=<<"EOF";
	<table border="0" width="100%" cellspacing="1" cellpadding="3">
	<tr><td><font size="2">$disptxtprofile</font></td></tr>
	</table>

	<hr size="1" noshade>

	<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
	<td colspan="2">
EOF

	if(-e $imgnamedisp){
		$play .=<<"EOF";
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td valign="middle" width="120"><font size="2">販売業者名</font></td>
			<td valign="middle" width="225"><font size="2">$compname</font></td>
			<td rowspan="7" width="200">$coimgdisp</td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">運営統括責任者</font></td>
			<td valign="top"><font size="2">$regname1$regname2</font></td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">所在地</font></td>
			<td valign="top"><font size="2">$shopadd</font></td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">連絡先</font></td>
			<td valign="top">
				<font size="2">
				TEL：$tel<br>
				FAX：$fax<br>
				Email：$masteremail<br>
				<a href="$homepage" target="_top">ホームページ</a>
				</font>
			</td>
		</tr>
		</table>
EOF
	}else{
		$play .=<<"EOF";
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td valign="middle" width="120"><font size="2">販売業者名</font></td>
			<td valign="middle" width="425"><font size="2">$compname</font></td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">運営統括責任者</font></td>
			<td valign="top"><font size="2">$regname1$regname2</font></td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">所在地</font></td>
			<td valign="top"><font size="2">$shopadd</font></td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120"><font size="2">連絡先</font></td>
			<td valign="top">
				<font size="2">
				TEL：$tel<br>
				FAX：$fax<br>
				Email：$masteremail<br>
				<a href="$homepage" target="_top">ホームページ</a>
				</font>
			</td>
		</tr>
		</table>
EOF
	}

	$play .=<<"EOF";
	</td>
	</tr>
	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
		<td valign="top" width="120"><font size="2">お支払い方法</font></td>
		<td valign="top" bgcolor="white"><font size="2">$hoetopay<hr size="1" noshade>
EOF

			if($bank && $banktext){ $bankword="（$banktext）"; }
			if($bank){$play.="銀行振込$bankword<br>";}

			if($daibiki && $daibikitext){ $daibikiword="（$daibikitext）"; }
			if($daibiki){$play.="代金引換$daibikiword<br>";}

			if($yubin && $yubintext){ $yubinword="（$yubintext）"; }
			if($yubin){$play.="郵便振替$yubinword";}

			if($credit && $credittext){ $creditword="（$credittext）"; }
			if($credit){$play.="クレジットカード$creditword";}

$play.=<<"EOF";
		</font>
		</td>
	</tr>
	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
		<td valign="top" width="120"><font size="2">商品代金以外<br>の必要料金</font></td>
		<td valign="top" bgcolor="white">
		<font size="2">$needfee</font>
		<hr size="1" noshade>
		<font size="2"><b>送料一覧</b></font>
		<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#999999">
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">北海道</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">北海道</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area01円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">北東北</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">青森/岩手/秋田/</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area02円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">南東北</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">宮城/山形/福島</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area03円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">関東</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">群馬/栃木/山梨/茨城/千葉/埼玉/東京/神奈川</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area04円</font></td>
		</tr>
		<tr>

		<td valign="top" width="50" bgcolor="white"><font size="2">信越</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">新潟/長野</font></td>
		<td valign="top" bgcolor="white"><font size="2" bgcolor="white">$area05円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">北陸</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">富山/石川/福井</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area06円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">中部</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">静岡/愛知/三重/岐阜</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area07円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">近畿</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">大阪/京都/奈良/滋賀/兵庫/和歌山</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area08円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">中国</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">島根/鳥取/山口/広島/岡山</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area09円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">四国</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">愛媛/香川/高知/徳島</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area10円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">九州</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">福岡/佐賀/長崎/熊本/大分/宮崎/鹿児島</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area11円</font></td>
		</tr>
		<tr>
		<td valign="top" width="50" bgcolor="white"><font size="2">沖縄</font></td>
		<td valign="top" width="300" bgcolor="white"><font size="2">沖縄</font></td>
		<td valign="top" bgcolor="white"><font size="2">$area12円</font></td>
		</tr>
		</table>
		<br>
EOF
		if(@kenfee){
			$play.=<<"EOF";
			<font size="2"><b>例外地域</b><br>以下の都道府県は上記の送料と異なります。</b></font>
			<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#999999">
EOF
			for ($i=1;$i<=47;$i++) {
				if ($kenfee[$i] eq '') {next;}
				$kencode = sprintf("%02d", $i);
				$kenname = $ken{"$kencode"};
			$play.=<<"EOF";
				<tr>
				<td valign="top" width="50" bgcolor="white"><font size="2"> </font></td>
				<td valign="top" width="300" bgcolor="white"><font size="2">$kenname</font></td>
				<td valign="top" bgcolor="white"><font size="2">$kenfee[$i]円</font></td>
				</tr>
EOF
			}
			
			$play.=<<"EOF";
			</table>
			<br>
EOF
		}

		if($daibiki){
			$play.=<<"EOF";
			<font size="2"><b>代引き手数料</b></font>
			<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#999999">
			<tr><td valign="top" bgcolor="white"><font size="2">$daibikifee円を送料に加算。</font></td></tr>
			</table>
			<br>
EOF
		}
		if($nofee > 0){
			$play.=<<"EOF";
			<font size="2"><b>送料無料設定</b></font>
			<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="#999999">
			<tr><td valign="top" bgcolor="white"><font size="2">$nofee円以上で無料。</font></td></tr>
			</table>
EOF
		}

$play.=<<"EOF";
		</td>

	</tr>
	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
	<td valign="top" width="120"><font size="2">お申込みの有効期限</font></td>
	<td valign="top"><font size="2">$ersday</font></td>
	</tr>
	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
	<td valign="top" width="120"><font size="2">商品の引渡し時期</font></td>
	<td valign="top"><font size="2">$arrive</font></td>
	</tr>

	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
	<td valign="top" width="120"><font size="2">返品について</font></td>
	<td valign="top"><font size="2">$return</font></td>
	</tr>
	<tr><td colspan="2"><hr size="1" noshade></td></tr>
	<tr>
	<td valign="top" width="120" colspan="2"><font size="2"><a href="index.a?uid=$uid&mode=privacy&watch=$watch">＞＞プライバシーポリシー</a></font></td>
	</tr>
	</table>
EOF



&designdisp;
}
#プライバシーポリシー--------------------------------------------------------------------------------------------------------------
if($mode eq "privacy"){


	$play .=<<"EOF";
	<table border="0" width="100%" cellspacing="1" cellpadding="3">
	<tr><td><font size="2"><b>プライバシーポリシー</b></font></td></tr>
	<tr><td><font size="2">お客様の個人情報について</font></td></tr>
	</table>

	<hr size="1" noshade>

	<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<tr>
	<td colspan="2">
EOF
	$description =~ s/\r\n|\r|\n/<br>/g;
		$play .=<<"EOF";
		<table border="0" cellpadding="3" cellspacing="0" width="100%">
		<tr>
			<td valign="top" width="120" bgcolor="$globebackcolor" rowspan="2"><font size="2"><br>　概要</font></td>
			<td valign="middle" width="425"><font size="2">$description</font></td>
		</tr>
		<tr>
			<td valign="middle" width="425">
				<table border="0" cellpadding="3" cellspacing="1" width="100%" bgcolor="$globebackcolor">
					<tr>
						<td valign="middle" width="80" bgcolor="#ffffff"><font size="2">メール</font></td>
						<td valign="middle" width="342"  bgcolor="#ffffff"><font size="2"><a href="mailto:$masteremail">$masteremail</a></font></td>
					</tr>
					<tr>
						<td valign="middle" width="80" bgcolor="#ffffff"><font size="2">お電話</font></td>
						<td valign="middle" width="342" bgcolor="#ffffff"><font size="2">$tel</font></td>
					</tr>
					<tr>
						<td valign="top" width="80" bgcolor="#ffffff"><font size="2">所在地</font></td>
						<td valign="top" width="342" bgcolor="#ffffff"><font size="2">〒$masterzip1-$masterzip2<br>
						$shopadd</font></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td colspan="2"><hr size="1" noshade></td></tr>
		<tr>
			<td valign="top" width="120" bgcolor="$globebackcolor"><font size="2"><br>　全文</font></td>
			<td valign="top"><font size="2"><textarea rows="12" cols="40"
			style="width:100%;height:200">$prvtext</textarea></font></td>
		</tr>
		</table>
EOF

&designdisp;
}
#お問い合わせ--------------------------------------------------------------------------------------------------------------
if($mode eq "contact"){

	$disptxtcontact = &loadPS("$disptxtcontact");
	$play .=<<"EOF";
	<table border="0" width="100%" cellspacing="0" cellpadding="3">
	<tr><td><font size="2">$disptxtcontact</font></td></tr>
	</table>

	<hr size="1" noshade>

	<table border="0" cellpadding="5" cellspacing="1" width="100%">
	<form method="post" action="$cgifile">
	<tr>
		<td valign="middle" width="120" bgcolor="#e5e5e5"><font size=2>ジャンル</font></td>
		<td bgcolor="#eeeeee">
			<select name="contacttitle">
EOF
	foreach (@contact) {
		($uid,$ctname,$ctnum) = split(':-snichcode-:', $_);
		$play .= "<option value=\"$ctname\">$ctname</option>";
	}

$play .=<<"EOF";
			</select>
		</td>
	</tr>
	<tr>
		<td valign="middle" width="120" bgcolor="#e5e5e5"><font size="2">ご意見・ご質問</font></td>
		<td valign="middle" bgcolor="#eeeeee"><font size="2"><textarea cols="40" rows="10" name="contactmsg"></textarea></font></td>
	</tr>
	<tr>
		<td valign="middle" width="120" bgcolor="#e5e5e5"><font size="2">お名前</font></td>
		<td valign="middle" bgcolor="#eeeeee"><font size="2"><input type="text" name="contactname" size="36"></font></td>
	</tr>
	<tr>
		<td valign="middle" width="120" bgcolor="#e5e5e5"><font size="2">メールアドレス</font></td>
		<td valign="middle" bgcolor="#eeeeee"><font size="2"><input type="text" name="contactemail" size="36"></font></td>
	</tr>
	<tr>
		<td valign="middle" colspan="2" align="center"><input type="submit" name="" value="上記を確認して送信する"></td>
	</tr>
	<input type="hidden" name="uid" value="$uid">
	<input type="hidden" name="mode" value="cthanks">
	<input type="hidden" name="watch" value="$watch">
	</form>
	</table>
EOF



&designdisp;
}
#お問い合わせ送信完了--------------------------------------------------------------------------------------------------------------
if($mode eq "cthanks"){

	unless($contactmsg){ &exitError("お問い合わせ内容を入力してください"); }
	unless($contactmsg){ &exitError("お名前を入力してください"); }
	unless($contactemail){ &exitError("メールアドレスを入力してください"); }

	$subject = "[StoreNavi：お問い合わせ]$shopname";
	jcode::convert(*subject,'sjis');
	$EncodeSubject = &EncodeSubject("$subject");
	$subject = <<"SBJ";
$EncodeSubject
SBJ

$mailhead = <<"EOM";
Return-Path: <$masteremail>
Reply-To: $contactemail
Content-type: Text/Plain; charset=iso-2022-jp
Content-transfer-Encoding: 7bit
From: $contactemail
To: $masteremail
Subject: $subject

EOM

$mailbody = <<"EOF";
$shopnameにお問い合わせがきました。
------------------------------------------------------------
■お問い合わせ
------------------------------------------------------------
ジャンル $contacttitle
お名前　 $contactname
メール　 $contactemail
------------------------------------------------------------
■送信内容
------------------------------------------------------------
$contactmsg
------------------------------------------------------------
■アクセス情報
Remote host: $ENV{'REMOTE_HOST'}
User Agent : $ENV{'HTTP_USER_AGENT'}
HTTP_REFERER: $ENV{'HTTP_REFERER'}
REMOTE_ADDR : $ENV{'REMOTE_ADDR'}
------------------------------------------------------------
EOF

	jcode::convert(*mailhead, 'jis');
	jcode::convert(*mailbody, 'jis');
	open(MAIL, "| $sendmail $masteremail");
	print MAIL $mailhead;
	print MAIL $mailbody;
	close(MAIL);

	$play .=<<"EOF";
		<div align="center">
		<table border="0" cellpadding="5" cellspacing="1" bgcolor="#545454" width="300">
			<tr>
				<td align="center" bgcolor="white"><img src="store/tmpimgs/cthanks01.gif" width="333" height="21" border="0"></td>
			</tr>
			<tr>
				<td bgcolor="#e6e6e6" align="left"><font size="2">$disptxtcthanks</font>
				</td>
			</tr>
		</table>
		</div>
EOF



&designdisp;
}
#カートの処理--------------------------------------------------------------------------------------------------------------
if($mode eq "cart"){

	$ds = 'dbi:Pg:dbname=store';
	$user = 'pgsql';
	$dbpass = '';
	$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");

		
	if($cmode eq "buy"){
		#被っていないかチェック
		$sth = $dbh->prepare("select * from mobcart where mobid = '$mobid' and cgid = '$gid' and explus='$newexplus'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$buyalready = @$ref[0];}

		if($buyalready){
			$msg = "<font size=2 color=red>すでに同じ商品を購入されています。追加でご購入される場合は、下記のリストの追加したい項目の数を選択し、必ず「変更」ボタンを押して下さい。</font><br>";
		}else{
			$sth = $dbh->prepare("insert into mobcart values('$mobid','$uid','$gid','$newgoodsmath','$time','$newexplus')");
			$sth->execute;
		}

	}elsif($cmode eq "cge"){
	
		$sth = $dbh->prepare("update mobcart set cgsmath='$cgemath' where mobid = '$mobid' and cgid = '$cgegs' and explus='$newexplus'");
		$sth->execute;
		$msg = "<font color=red>商品数の変更を一件行いました。</font><br>";

	}elsif($cmode eq "ers"){
		if ($ersexplus) {
			$sth = $dbh->prepare("delete from mobcart where mobid='$mobid' and cgid='$ersgs' and explus='$ersexplus'");
		} else {
			$sth = $dbh->prepare("delete from mobcart where mobid='$mobid' and cgid='$ersgs'");
		}
		$sth->execute;
		$msg = "<font color=red>商品を一件削除しました。</font><br>";

	}
	
		$sth = $dbh->prepare("select cuid,cgid,cgsmath,explus from mobcart where mobid = '$mobid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$buyerdata = join(':-snichcode-:',@$ref);
		push(@lines,$buyerdata);
	}

	$sth->finish;
	$dbh->disconnect;

	if(@lines){$dispcart = "yes";}
	
	$disptxtcart = &loadPS("$disptxtcart");
	if($dispcart eq "yes"){
		$play.=<<"EOF";
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr><td><img src="../images/spacer.gif" width="10" height="10" border="0"></td></tr>
		<tr><td>$msg<font size="2">$disptxtcart</font></td></tr>
		<tr><td><img src="../images/spacer.gif" width="10" height="10" border="0"></td></tr>
		</table>
		<table border="0" width="100%" cellspacing="1" cellpadding="5">
		<tr>
		<!--<td bgcolor="#cccccc" align="center">商品番号</td>-->
		<td bgcolor="#cccccc" align="center"><font size="2"><b>商品名</b></font></td>
		<td bgcolor="#cccccc" align="center"><font size="2"><b>単価</b></font></td>
		<td bgcolor="#cccccc" align="center"><font size="2"><b>種別／個数</b></font></td>
		<td bgcolor="#cccccc" align="center"><font size="2"><b>小計</b></font></td>
		<td bgcolor="#cccccc" align="center"><font size="2"><b>削除</b></font></td>
		</tr>
EOF
		$allmath = 0;
		#データベース---------------------------------------------------------
		$ds = 'dbi:Pg:dbname=store';
		$user = 'pgsql';
		$dbpass = '';
		$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");

		foreach (@lines){
			($c_uid,$c_gid,$c_gsmath,$c_explus) = split(':-snichcode-:',$_);
			$sth = $dbh->prepare("select gsname,gsprice,gstax,gsallmath,gsunit,explus from goodslist where uid='$uid' and gid='$c_gid'");
			$sth->execute;
			$num = $sth->{'NUM_OF_FIELDS'};
			while($ref = $sth->fetchrow_arrayref){$gsdata = join(':-snichcode-:',@$ref);}
			unless($gsdata){next;}
			($gsname,$gsprice,$gstax,$gsallmath,$gsunit,$explus) = split(":-snichcode-:",$gsdata);
			
			$pfee = $c_gsmath * $gsprice;
			$total = $total + $pfee;
			if($gstax){$tax = $tax + int($c_gsmath * $gsprice * 0.05);}else{ $tax=$tax+0; }
			if($c_explus) {
				$gsname .= "($c_explus)";
			}

			$play.=<<"EOF";
			<tr>
			<!--<td bgcolor="#dddddd" align="center"><font size="2">$gid</font></td>-->
			<td bgcolor="#dddddd" align="left"><font size="2">$gsname</font></td>
			<td bgcolor="#dddddd" align="center"><font size="2">$gsprice円</font></td>
			<form method="post" action="$cgifile">
			<td bgcolor="#dddddd" align="center">
			<input type="hidden" name="uid" value="$uid">
			<input type="hidden" name="mode" value="cart">
			<input type="hidden" name="cmode" value="cge">
			<input type="hidden" name="cgegs" value="$c_gid">
			<input type="hidden" name="mobid" value="$mobid">
			<input type="hidden" name="type" value="$type">
			<input type="hidden" name="newexplus" value="$c_explus">
			<input type="hidden" name="watch" value="$watch">
			<select name=\"cgemath\">
EOF
			if($buymath > $gsallmath){$maxmath=$gsallmath;}
			elsif($buymath < $gsallmath){$maxmath=$buymath;}
			else{$maxmath=$buymath;}
			
			for($i=1; $i <= $maxmath; $i++){
				if($i == $c_gsmath){$play.="<option value=$i selected>$i$gsunit</option>";}
				else{$play.="<option value=$i>$i$gsunit</option>";}
			}
			
			$play.=<<"EOF";
			</select><input type="submit" value="変更">
			</td>
			</form>
			<td bgcolor="#dddddd" align="right"><font size="2">$pfee円</font></td>
			<form method="post" action="$cgifile">
			<td bgcolor="#dddddd" align="center">
				<input type="hidden" name="uid" value="$uid">
				<input type="hidden" name="mode" value="cart">
				<input type="hidden" name="cmode" value="ers">
				<input type="hidden" name="ersgs" value="$c_gid">
				<input type="hidden" name="mobid" value="$mobid">
				<input type="hidden" name="ersexplus" value="$c_explus">
				<input type="hidden" name="type" value="$type">
				<input type="hidden" name="watch" value="$watch">
				<input type="submit" value="取消">
			</td>
			</form>
			</tr>
EOF
		}#end_foreach

		$sth->finish;
		$dbh->disconnect;
		$total_all = $total + $tax;

		$play.=<<"EOF";
		<tr>
			<td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">商品計</font></td>

			<td align="right" bgcolor="#ffcccc"><font size="2">$total円</font></td><td></td>
		</tr>
		<tr>
			<td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">送料</font></td>
			<td align="right" bgcolor="#ffcccc"><font size="2">住所・送付方法<br>決定後算出</font></td><td></td>
		</tr>
		<tr>
			<td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">消費税(課税対象のみ)</font></td>
			<td align="right" bgcolor="#ffcccc"><font size="2">$tax円</font></td><td></td>
		</tr>
		<tr>
			<td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">お支払い合計<br>（送料は住所入力後）</font></td>
			<td align="right" bgcolor="#ffcccc"><font size="2" color="#990000">$total_all円＋送料</font></td><td></td>
		</tr>
		</table>
		<hr size="1" color="#555555">
		<table border="0" cellpadding="5" cellspacing="0" width="100%" bgcolor="#aaaaaa">
		<form action="$domains/$cgifile" method="post">
		<tr>
		<td colspan="2" bgcolor="#eeeeee"><font size="2">会員登録をされているの場合は、下記にご登録のメールアドレスとパスワードをご記入頂きますと、情報入力の手間が省け、よりスムーズにご購入が可能です。初めての方は、何も入力せずに購入画面へお進み下さい。</font></td>
		</tr>
		<tr>
		<td bgcolor="#eeeeee">
			<table border=0>
			<tr><td><b><font size="1">メールアドレス：</font></b></td><td><input type="text" name="email" size="30"></td></tr>
			<tr><td><b><font size="1">パスワード：</font></b></td><td><input type="password" name="password" size="8" maxlength="8"></td></tr>
			</table>
		</td>
		<td align="right" width="120" bgcolor="#eeeeee">
			<input type="submit" name="" value="購入画面へ">
			<input type="hidden" name="uid" value="$uid">
			<input type="hidden" name="mode" value="check">
			<input type="hidden" name="type" value="$type">
			<input type="hidden" name="mobid" value="$mobid">
			<input type="hidden" name="watch" value="$watch">
		</td>
		</tr>
		</form>
		</table><br><br>
EOF
	}else{
		$play.=<<"EOF";
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr><td><hr size=1 noshade></td></tr>
		<tr><td><font size="2" color="red">現在、まだ何も購入されていません。</font><br><font size="2">$disptxtcart</font></td></tr>
		<tr><td><hr size=1 noshade></td></tr>
		</table>
		<br><br>
EOF
	}

#	$cookietag = <<"EOF";
#	<meta http-equiv="Set-Cookie" content="storedata=$newstoredata;">
#EOF

$gogocookie="set";

&designdisp;
}
#チェックモード---------------------------------------------------------------------------------------------------------------------
if($mode eq "check"){
	#メールｔが記入されていたらデータベース読み込み-------------------------------------------------------------------------------------------------
	if($email && $password){
	
		#もし、全店共通でユーザー情報を使用する場合、下記検索からuidを削除すればよい

		$ds = 'dbi:Pg:dbname=store';
		$user = 'pgsql';
		$dbpass = '';
		$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");
		$sth = $dbh->prepare("select * from buyerdata where uid = '$uid' and email = '$email' and pass = '$password' order by buytime DESC limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$buyerdata = join(':-snichcode-:',@$ref);
		}
		$sth->finish;
		$dbh->disconnect;

		unless($buyerdata){ exitError("パスワードが違います。誤入力の場合は、前の画面に戻り正しい情報をご入力するか入力文字を削除して下さい。");}
		if($buyerdata){($uid,$bid,$buytime,$pass,$regname,$freename,$email,$sex,$zip1,$zip2,$ken,$add1,$add2,$add3,$tel,$fax,$birtha,$birthb,$birthc,$end)=split(':-snichcode-:',$buyerdata);}
	}
	#-------------------------------------------------------------------------------------------------

	$script=<<EOF;
		<SCRIPT Language="JavaScript">
		<!--
		function formCheck(){
		if (document.apform.freename.value == ""){alert("氏名（ふりがな）を記入して下さい");return false;}
		if (document.apform.regname.value == ""){alert("氏名（漢字）を記入して下さい");return false;}
		if (document.apform.email.value == ""){alert("メールアドレスを記入して下さい");return false;}
		if (document.apform.zip1.value == ""){alert("郵便番号を記入して下さい");return false;}
		if (document.apform.zip2.value == ""){alert("郵便番号を記入して下さい");return false;}
		if (document.apform.ken.value == "必ず選択して下さい"){alert("都道府県を選択して下さい");return false;}
		if (document.apform.add1.value == ""){alert("住所を記入して下さい");return false;}
		if (document.apform.tel.value == ""){alert("電話番号を正確に記入して下さい");return false;}
		return true;
		}
		// --></SCRIPT>
EOF


##############


	$disptxtintext = &loadPS("$disptxtintext");

$play.= <<EOF;
	<table border="0" width="100%" cellspacing="0" cellpadding="3">
	<tr><td><font size="2">$disptxtintext</font></td></tr>
	</table>

	<hr size="1" noshade>

	<table border="0" width="100%" cellspacing="1" cellpadding="5">
		<tr>
			<!--<td bgcolor="#cccccc" align="center"><font size="2">商品番号</font></td>-->
			<td bgcolor="#cccccc" align="center"><font size="2">商品名</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">単価</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">個数</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">小計</font></td>
		</tr>
EOF

		$allmath = 0;
		#データベース---------------------------------------------------------
		$ds = 'dbi:Pg:dbname=store';
		$user = 'pgsql';
		$dbpass = '';
		$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");
		
		#カートの中身---------------------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select cuid,cgid,cgsmath,explus from mobcart where cuid='$uid' and mobid = '$mobid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$buyerdata = join(':-snichcode-:',@$ref);
			push(@lines,$buyerdata);
		}
		#カートの中身---------------------------------------------------------------------------------------------------

		foreach (@lines){
			($c_uid,$c_gid,$c_gsmath,$c_explus) = split(':-snichcode-:',$_);
			$sth = $dbh->prepare("select gsname,gsprice,gstax,gsallmath,gsunit from goodslist where uid='$uid' and gid='$c_gid'");
			$sth->execute;
			$num = $sth->{'NUM_OF_FIELDS'};
			while($ref = $sth->fetchrow_arrayref){
				$gsdata = join(':-snichcode-:',@$ref);
			}
			unless($gsdata){next;}
			($gsname,$gsprice,$gstax,$gsallmath,$gsunit) = split(":-snichcode-:",$gsdata);
			
			$pfee = $c_gsmath * $gsprice;
			$total = $total + $pfee;
			if($gstax){$tax = $tax + int($c_gsmath * $gsprice * 0.05);}else{ $tax=$tax+0; }
			if($c_explus) {
				$gsname .= "($c_explus)";
			}

			$play.=<<"EOF";
			<tr>
			<!--<td bgcolor="#dddddd" align="center"><font size="2">$gid</font></td>-->
			<td bgcolor="#dddddd" align="left"><font size="2">$gsname</font></td>
			<td bgcolor="#dddddd" align="center"><font size="2">$gsprice円</font></td>
			<td bgcolor="#dddddd" align="center"><font size="2">$c_gsmath$gsunit</font></td>
			<td bgcolor="#dddddd" align="right"><font size="2">$pfee円</font></td>
			</tr>
EOF
		}#end_foreach

		$sth->finish;
		$dbh->disconnect;
		$total_all = $total + $tax;

	$play.= <<"EOF";
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">商品計</font></td><td align="right" bgcolor="#ffcccc"><font size="2">$total円</font></td></tr>
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">送料/手数料</font></td><td align="right" bgcolor="#ffcccc"><font size="2">住所・送付方法<br>決定後算出</font></td></tr>
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">消費税</font></td><td align="right" bgcolor="#ffcccc"><font size="2">$tax円</font></td></tr>

	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">お支払い合計<br>（送料抜き）</font></td><td align="right" bgcolor="#ffcccc"><font size="2" color="#990000">$total_all円＋送料</font></td></tr>
	</table>
EOF
$play.= <<EOF;
<form name="apform" action="$cgifile" method="post">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr><td><hr size=1 noshade></td></tr>
		<tr><td><font size="2">お客様の情報をお間違えの無いようにご入力下さい。</font></td></tr>
		<tr><td><hr size=1 noshade></td></tr>
	</table>
	<table border="0" cellpadding="2" cellspacing="1" width="100%">
		<tr>
			<td width="100" bgcolor="#cccccc" rowspan="2"><font size="2">お名前</font></td>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">漢字</font></td>
			<td bgcolor="#eeeeee"><input type="text" name="regname" size="24" value="$regname"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">ふりがな</font></td>
			<td bgcolor="#eeeeee"><input type="text" name="freename" size="24" value="$freename"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">メールアドレス</font></td>
			<td width="100" colspan="2" bgcolor="#eeeeee"><input type="text" name="email" size="30" value="$email"></td>
		</tr>
		<tr>
			<td width="100" rowspan="5" bgcolor="#cccccc"><font size="2">ご住所</font></td>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">郵便番号</font></td>
			<td bgcolor="#eeeeee"><font size="2"><input type="text" name="zip1" size="5" maxlength="3" value="$zip1">-<input type="text" name="zip2" size="6" maxlength="4" value="$zip2">(半角数字でご記入下さい)</font></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">都道府県</font></td>
			<td bgcolor="#eeeeee">
EOF

unless($ken){
$play.= <<"EOF";
	<SELECT NAME="ken">
	<OPTION value="" selected>必ず選択して下さい</option>
	<OPTION VALUE="area01:北海道">北海道</option>
	<OPTION VALUE="area02:青森県">青森県</option>
	<OPTION VALUE="area02:岩手県">岩手県</option>
	<OPTION VALUE="area03:宮城県">宮城県</option>
	<OPTION VALUE="area02:秋田県">秋田県</option>
	<OPTION VALUE="area03:山形県">山形県</option>
	<OPTION VALUE="area03:福島県">福島県</option>
	<OPTION VALUE="area04:茨城県">茨城県</option>
	<OPTION VALUE="area04:栃木県">栃木県</option>
	<OPTION VALUE="area04:群馬県">群馬県</option>
	<OPTION VALUE="area04:埼玉県">埼玉県</option>
	<OPTION VALUE="area04:千葉県">千葉県</option>
	<OPTION VALUE="area04:東京都">東京都</option>
	<OPTION VALUE="area04:神奈川県">神奈川県</option>
	<OPTION VALUE="area05:新潟県">新潟県</option>
	<OPTION VALUE="area06:富山県">富山県</option>
	<OPTION VALUE="area06:石川県">石川県</option>
	<OPTION VALUE="area06:福井県">福井県</option>
	<OPTION VALUE="area04:山梨県">山梨県</option>
	<OPTION VALUE="area05:長野県">長野県</option>
	<OPTION VALUE="area07:岐阜県">岐阜県</option>
	<OPTION VALUE="area07:静岡県">静岡県</option>
	<OPTION VALUE="area07:愛知県">愛知県</option>
	<OPTION VALUE="area07:三重県">三重県</option>
	<OPTION VALUE="area08:滋賀県">滋賀県</option>
	<OPTION VALUE="area08:京都府">京都府</option>
	<OPTION VALUE="area08:大阪府">大阪府</option>
	<OPTION VALUE="area08:兵庫県">兵庫県</option>
	<OPTION VALUE="area08:奈良県">奈良県</option>
	<OPTION VALUE="area08:和歌山県">和歌山県</option>
	<OPTION VALUE="area09:鳥取県">鳥取県</option>
	<OPTION VALUE="area09:島根県">島根県</option>
	<OPTION VALUE="area09:岡山県">岡山県</option>
	<OPTION VALUE="area09:広島県">広島県</option>
	<OPTION VALUE="area09:山口県">山口県</option>
	<OPTION VALUE="area10:徳島県">徳島県</option>
	<OPTION VALUE="area10:香川県">香川県</option>
	<OPTION VALUE="area10:愛媛県">愛媛県</option>
	<OPTION VALUE="area10:高知県">高知県</option>
	<OPTION VALUE="area11:福岡県">福岡県</option>
	<OPTION VALUE="area11:佐賀県">佐賀県</option>
	<OPTION VALUE="area11:長崎県">長崎県</option>
	<OPTION VALUE="area11:熊本県">熊本県</option>
	<OPTION VALUE="area11:大分県">大分県</option>
	<OPTION VALUE="area11:宮崎県">宮崎県</option>
	<OPTION VALUE="area11:鹿児島県">鹿児島県</option>
	<OPTION VALUE="area12:沖縄県">沖縄県</option>
	</SELECT>
EOF
}else{
	$play.="<SELECT NAME=ken>";
	$play.="<OPTION value= >必ず選択して下さい</option>";

	if($ken eq "北海道"){$play.="<OPTION VALUE=area01:北海道 selected>北海道</option>";}
	else{$play.="<OPTION VALUE=area01:北海道>北海道</option>";}

	if($ken eq "青森県"){$play.="<OPTION VALUE=area02:青森県 selected>青森県</option>";}
	else{$play.="<OPTION VALUE=area02:青森県>青森県</option>";}

	if($ken eq "岩手県"){$play.="<OPTION VALUE=area02:岩手県 selected>岩手県</option>";}
	else{$play.="<OPTION VALUE=area02:岩手県>岩手県</option>";}

	if($ken eq "宮城県"){$play.="<OPTION VALUE=area03:宮城県 selected>宮城県</option>";}
	else{$play.="<OPTION VALUE=area03:宮城県>宮城県</option>";}

	if($ken eq "秋田県"){$play.="<OPTION VALUE=area02:秋田県 selected>秋田県</option>";}
	else{$play.="<OPTION VALUE=area02:秋田県>秋田県</option>";}

	if($ken eq "山形県"){$play.="<OPTION VALUE=area03:山形県 selected>山形県</option>";}
	else{$play.="<OPTION VALUE=area03:山形県>山形県</option>";}

	if($ken eq "福島県"){$play.="<OPTION VALUE=area03:福島県 selected>福島県</option>";}
	else{$play.="<OPTION VALUE=area03:福島県>福島県</option>";}

	if($ken eq "茨城県"){$play.="<OPTION VALUE=area04:茨城県 selected>茨城県</option>";}
	else{$play.="<OPTION VALUE=area04:茨城県>茨城県</option>";}

	if($ken eq "栃木県"){$play.="<OPTION VALUE=area04:栃木県 selected>栃木県</option>";}
	else{$play.="<OPTION VALUE=area04:栃木県>栃木県</option>";}

	if($ken eq "群馬県"){$play.="<OPTION VALUE=area04:群馬県 selected>群馬県</option>";}
	else{$play.="<OPTION VALUE=area04:群馬県>群馬県</option>";}

	if($ken eq "埼玉県"){$play.="<OPTION VALUE=area04:埼玉県 selected>埼玉県</option>";}
	else{$play.="<OPTION VALUE=area04:埼玉県>埼玉県</option>";}

	if($ken eq "千葉県"){$play.="<OPTION VALUE=area04:千葉県 selected>千葉県</option>";}
	else{$play.="<OPTION VALUE=area04:千葉県>千葉県</option>";}

	if($ken eq "東京都"){$play.="<OPTION VALUE=area04:東京都 selected>東京都</option>";}
	else{$play.="<OPTION VALUE=area04:東京都>東京都</option>";}

	if($ken eq "神奈川県"){$play.="<OPTION VALUE=area04:神奈川県 selected>神奈川県</option>";}
	else{$play.="<OPTION VALUE=area04:神奈川県>神奈川県</option>";}

	if($ken eq "新潟県"){$play.="<OPTION VALUE=area05:新潟県 selected>新潟県</option>";}
	else{$play.="<OPTION VALUE=area05:新潟県>新潟県</option>";}

	if($ken eq "富山県"){$play.="<OPTION VALUE=area06:富山県 selected>富山県</option>";}
	else{$play.="<OPTION VALUE=area06:富山県>富山県</option>";}

	if($ken eq "石川県"){$play.="<OPTION VALUE=area06:石川県 selected>石川県</option>";}
	else{$play.="<OPTION VALUE=area06:石川県>石川県</option>";}

	if($ken eq "福井県"){$play.="<OPTION VALUE=area06:福井県 selected>福井県</option>";}
	else{$play.="<OPTION VALUE=area06:福井県>福井県</option>";}

	if($ken eq "山梨県"){$play.="<OPTION VALUE=area04:山梨県 selected>山梨県</option>";}
	else{$play.="<OPTION VALUE=area04:山梨県>山梨県</option>";}

	if($ken eq "長野県"){$play.="<OPTION VALUE=area05:長野県 selected>長野県</option>";}
	else{$play.="<OPTION VALUE=area05:長野県>長野県</option>";}

	if($ken eq "岐阜県"){$play.="<OPTION VALUE=area07:岐阜県 selected>岐阜県</option>";}
	else{$play.="<OPTION VALUE=area07:岐阜県>岐阜県</option>";}

	if($ken eq "静岡県"){$play.="<OPTION VALUE=area07:静岡県 selected>静岡県</option>";}
	else{$play.="<OPTION VALUE=area07:静岡県>静岡県</option>";}

	if($ken eq "愛知県"){$play.="<OPTION VALUE=area07:愛知県 selected>愛知県</option>";}
	else{$play.="<OPTION VALUE=area07:愛知県>愛知県</option>";}

	if($ken eq "三重県"){$play.="<OPTION VALUE=area07:三重県 selected>三重県</option>";}
	else{$play.="<OPTION VALUE=area07:三重県>三重県</option>";}

	if($ken eq "滋賀県"){$play.="<OPTION VALUE=area08:滋賀県 selected>滋賀県</option>";}
	else{$play.="<OPTION VALUE=area08:滋賀県>滋賀県</option>";}

	if($ken eq "京都府"){$play.="<OPTION VALUE=area08:京都府 selected>京都府</option>";}
	else{$play.="<OPTION VALUE=area08:京都府>京都府</option>";}

	if($ken eq "大阪府"){$play.="<OPTION VALUE=area08:大阪府 selected>大阪府</option>";}
	else{$play.="<OPTION VALUE=area08:大阪府>大阪府</option>";}

	if($ken eq "兵庫県"){$play.="<OPTION VALUE=area08:兵庫県 selected>兵庫県</option>";}
	else{$play.="<OPTION VALUE=area08:兵庫県>兵庫県</option>";}

	if($ken eq "奈良県"){$play.="<OPTION VALUE=area08:奈良県 selected>奈良県</option>";}
	else{$play.="<OPTION VALUE=area08:奈良県>奈良県</option>";}

	if($ken eq "和歌山県"){$play.="<OPTION VALUE=area08:和歌山県 selected>和歌山県</option>";}
	else{$play.="<OPTION VALUE=area08:和歌山県>和歌山県</option>";}

	if($ken eq "鳥取県"){$play.="<OPTION VALUE=area09:鳥取県 selected>鳥取県</option>";}
	else{$play.="<OPTION VALUE=area09:鳥取県>鳥取県</option>";}

	if($ken eq "島根県"){$play.="<OPTION VALUE=area09:島根県 selected>島根県</option>";}
	else{$play.="<OPTION VALUE=area09:島根県>島根県</option>";}

	if($ken eq "岡山県"){$play.="<OPTION VALUE=area09:岡山県 selected>岡山県</option>";}
	else{$play.="<OPTION VALUE=area09:岡山県>岡山県</option>";}

	if($ken eq "広島県"){$play.="<OPTION VALUE=area09:広島県 selected>広島県</option>";}
	else{$play.="<OPTION VALUE=area09:広島県>広島県</option>";}

	if($ken eq "山口県"){$play.="<OPTION VALUE=area09:山口県 selected>山口県</option>";}
	else{$play.="<OPTION VALUE=area09:山口県>山口県</option>";}

	if($ken eq "徳島県"){$play.="<OPTION VALUE=area10:徳島県 selected>徳島県</option>";}
	else{$play.="<OPTION VALUE=area10:徳島県>徳島県</option>";}

	if($ken eq "香川県"){$play.="<OPTION VALUE=area10:香川県 selected>香川県</option>";}
	else{$play.="<OPTION VALUE=area10:香川県>香川県</option>";}

	if($ken eq "愛媛県"){$play.="<OPTION VALUE=area10:愛媛県 selected>愛媛県</option>";}
	else{$play.="<OPTION VALUE=area10:愛媛県>愛媛県</option>";}

	if($ken eq "高知県"){$play.="<OPTION VALUE=area10:高知県 selected>高知県</option>";}
	else{$play.="<OPTION VALUE=area10:高知県>高知県</option>";}

	if($ken eq "福岡県"){$play.="<OPTION VALUE=area11:福岡県 selected>福岡県</option>";}
	else{$play.="<OPTION VALUE=area11:福岡県>福岡県</option>";}

	if($ken eq "佐賀県"){$play.="<OPTION VALUE=area11:佐賀県 selected>佐賀県</option>";}
	else{$play.="<OPTION VALUE=area11:佐賀県>佐賀県</option>";}

	if($ken eq "長崎県"){$play.="<OPTION VALUE=area11:長崎県 selected>長崎県</option>";}
	else{$play.="<OPTION VALUE=area11:長崎県>長崎県</option>";}

	if($ken eq "熊本県"){$play.="<OPTION VALUE=area11:熊本県 selected>熊本県</option>";}
	else{$play.="<OPTION VALUE=area11:熊本県>熊本県</option>";}

	if($ken eq "大分県"){$play.="<OPTION VALUE=area11:大分県 selected>大分県</option>";}
	else{$play.="<OPTION VALUE=area11:大分県>大分県</option>";}

	if($ken eq "宮崎県"){$play.="<OPTION VALUE=area11:宮崎県 selected>宮崎県</option>";}
	else{$play.="<OPTION VALUE=area11:宮崎県>宮崎県</option>";}

	if($ken eq "鹿児島県"){$play.="<OPTION VALUE=area11:鹿児島県 selected>鹿児島県</option>";}
	else{$play.="<OPTION VALUE=area11:鹿児島県>鹿児島県</option>";}

	if($ken eq "沖縄県"){$play.="<OPTION VALUE=area12:沖縄県 selected>沖縄県</option>";}
	else{$play.="<OPTION VALUE=area12:沖縄県>沖縄県</option>";}


	$play.="</SELECT>";
}

		$play.= <<"EOF";
			</td>
		</tr>
		<tr>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">市区郡</font></td>
			<td bgcolor="#eeeeee"><input type="text" name="add1" size="50" value="$add1"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">町村番地</font></td>
			<td bgcolor="#eeeeee"><input type="text" name="add2" size="50" value="$add2"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#dddddd" align="center"><font size="2">ビル名など</font></td>
			<td bgcolor="#eeeeee"><input type="text" name="add3" size="50" value="$add3"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">電話番号</font></td>
			<td width="100" colspan="2" bgcolor="#eeeeee"><input type="text" name="tel" size="24" value="$tel"></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">お支払い方法</font></td>
			<td colspan="2" bgcolor="#eeeeee"><font size="2">
			<select name="howto">
EOF

			if($bank && $banktext){ $bankword="（$banktext）"; }
			if($bank){$play.="<option value=銀行振込>銀行振込$bankword</option>";}

			if($daibiki && $daibikitext){ $daibikiword="（$daibikitext）"; }
			if($daibiki){$play.="<option value=代金引換>代金引換$daibikiword</option>";}

			if($yubin && $yubintext){ $yubinword="（$yubintext）"; }
			if($yubin){$play.="<option value=郵便振替>郵便振替$yubinword</option>";}

			if($credit && $credittext){ $creditword="（$credittext）"; }
			if($credit){$play.="<option value=クレジットカード>クレジットカード$creditword</option>";}

$play.=<<"EOF";
			</select>
			</font></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">ご希望配送日</font></td>
			<td width="100" colspan="2" bgcolor="#eeeeee"><font size="2"><input type="text" name="sendmon" size="4" value="$sendmon" maxlength="2">月<input type="text" name="sendday" size="4" value="$sendday" maxlength="2">日</font></td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">ご希望配送時間</font></td>
			<td colspan="2" bgcolor="#eeeeee">
				<select name="sendtime">
				<option value="希望なし">希望なし</option>
				<option value="午前中">午前中</option>
				<option value="12時〜14時">12時〜14時</option>
				<option value="14時〜16時">14時〜16時</option>
				<option value="16時〜18時">16時〜18時</option>
				<option value="18時〜20時">18時〜20時</option>
				<option value="20時〜21時">20時〜21時</option>
				</select>
				<font size="2"></font>
			</td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">その他メッセージ</font></td>
			<td colspan="2" bgcolor="#eeeeee">
				<textarea cols="40" rows="4" name="msg"></textarea>
				<font size="2"></font>
			</td>
		</tr>
		<tr>
			<td width="100" bgcolor="#cccccc"><font size="2">パスワード</font></td>
			<td colspan="2" bgcolor="#eeeeee">
				<font size="2"><input type="text" name="pass" size="10" maxlength="8" value="$pass"><br>
				任意入力ですが、パスワードを登録しておくと次回購入時、メールアドレスとパスワードだけでお買い物ができます。</font>
			</td>
		</tr>
	</table>
	<br>

	<input type="submit" value="＞＞確認画面へ" onClick="return formCheck()">
	<input type="hidden" name="uid" value="$uid">
	<input type="hidden" name="type" value="$type">
	<input type="hidden" name="mode" value="buy">
	<input type="hidden" name="mobid" value="$mobid">
	<input type="hidden" name="watch" value="$watch">
	</form>
<br>
EOF
&designdisp;
}
#購入確定------------------------------------------------------------------------------------------------------------------------------------------------

if($mode eq "buy"){
	unless($regname){ &exitError("氏名（漢字）を入力してください"); }
	unless($freename){ &exitError("氏名（ふりがな）を入力してください"); }
	unless($email){ &exitError("メールアドレスを入力してください"); }
	unless($ken){ &exitError("都道府県を入力してください"); }
	unless($add1){ &exitError("住所を入力してください"); }
	unless($tel){ &exitError("電話番号を入力してください"); }
	unless($zip1 =~ /[0-9]/){ &exitError("郵便番号は半角数字を使用してください"); }
	unless($zip2 =~ /[0-9]/){ &exitError("郵便番号は半角数字を使用してください"); }
	if($pass){$passdisp="登録する";}else{$passdisp="登録しない";}

	if($sendmon eq "" && $sendday){ &exitError("配送日を指定する場合は、「月」「日」の両方をご指定下さい。"); }
	if($sendday eq "" && $sendmon){ &exitError("配送日を指定する場合は、「月」「日」の両方をご指定下さい。"); }

	if($sendmon && $sendday){$sendworks="$sendmon月$sendday日";}elsif($sendmon eq "" && $sendday eq ""){$sendmonandday="希望日なし";}

	#入力した都道府県から地域を読み込む
	($areacode,$ken) = split(':',$ken);


	$disptxtchecktxt = &loadPS("$disptxtchecktxt");

$play.= <<EOF;
	<table border="0" width="100%" cellspacing="0" cellpadding="3">
	<tr><td><font size="2">$disptxtchecktxt</font></td></tr>
	</table>
	<hr size="1" noshade>
	<table border="0" width="100%" cellspacing="1" cellpadding="5">
		<tr>
			<!--<td bgcolor="#cccccc" align="center"><font size="2">商品番号</font></td>-->
			<td bgcolor="#cccccc" align="center"><font size="2">商品名</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">単価</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">個数</font></td>
			<td bgcolor="#cccccc" align="center"><font size="2">小計</font></td>
		</tr>
EOF


		$allmath = 0;
		#データベース---------------------------------------------------------
		$ds = 'dbi:Pg:dbname=store';
		$user = 'pgsql';
		$dbpass = '';
		$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");

		#カートの中身---------------------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select cuid,cgid,cgsmath,explus from mobcart where cuid='$uid' and mobid = '$mobid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$buyerdata = join(':-snichcode-:',@$ref);
			push(@lines,$buyerdata);
		}
		#カートの中身---------------------------------------------------------------------------------------------------
	
		#例外地域に含まれていないか確認---------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select kencode from kencodes where kenname='$ken'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$kencode = $ref->[0];
		}
		$kencode = sprintf("k%02d", $kencode);
		$sth = $dbh->prepare("select $kencode from kenfee where uid='$uid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$kenfee = $ref->[0];
		}

		#地域ごとの送料呼び出し---------------------------------------------------------------------------------------
		$sth = $dbh->prepare("select $areacode,daibiki,nofee from sendfee where uid='$uid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){
			$areafeedt = join(':-snichcode-:',@$ref);
		}
		($areafee,$daibiki,$nofee) = split(':-snichcode-:',$areafeedt);

		if ($kenfee ne '') {
			$areafee = $kenfee;
		}

		foreach (@lines){
			($c_uid,$c_gid,$c_gsmath,$c_explus) = split(':-snichcode-:',$_);
			$sth = $dbh->prepare("select gsname,gsprice,gstax,gsunit from goodslist where uid='$uid' and gid='$c_gid'");
			$sth->execute;
			$num = $sth->{'NUM_OF_FIELDS'};
			while($ref = $sth->fetchrow_arrayref){
				$gsdata = join(':-snichcode-:',@$ref);
			}
			unless($gsdata){next;}
			($gsname,$gsprice,$gstax,$gsunit) = split(":-snichcode-:",$gsdata);
			
			$pfee = $c_gsmath * $gsprice;
			$total = $total + $pfee;
			if($gstax){$tax = $tax + int($c_gsmath * $gsprice * 0.05);}else{ $tax=$tax+0; }
			if($c_explus) {
				$gsname .= "($c_explus)";
			}

				$play.= <<EOF;
				<tr>
				<!--<td bgcolor="#dddddd" align="center"><font size="2">$gid</font></td>-->
				<td bgcolor="#dddddd" align="left"><font size="2">$gsname</font></td>
				<td bgcolor="#dddddd" align="center"><font size="2">$gsprice円</font></td>
				<td bgcolor="#dddddd" align="center"><font size="2">$c_gsmath$gsunit</font></td>
				<td bgcolor="#dddddd" align="right"><font size="2">$pfee円</font></td>
				</tr>
EOF
		}#end_foreach
		$sth->finish;
		$dbh->disconnect;
		
		if($howto eq "代金引換"){ $sendfee = $areafee + $daibiki; }else{ $sendfee = $areafee; }
		#お買いあげ●●円以上で送料無料！の設定をする場合
		if($nofee > 0){
			if($total >= $nofee){$sendfee=0;}
		}

		$total_all = $total + $tax + $sendfee;

	$play.= <<"EOF";
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">商品計</font></td><td align="right" bgcolor="#ffcccc"><font size="2">$total円</font></td></tr>
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">送料/手数料</font></td><td align="right" bgcolor="#ffcccc"><font size="2">$sendfee円</font></td></tr>
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">消費税</font></td><td align="right" bgcolor="#ffcccc"><font size="2">$tax円</font></td></tr>
	<tr><td colspan="2"></td><td align="right" bgcolor="#ffcc99"><font size="2">お支払い合計</font></td><td align="right" bgcolor="#ffcccc"><font size="2" color="#990000">$total_all円</font></td></tr>
	</table>
EOF
	$play.= <<EOF;
		<form name="apform" action="$cgifile" method="post">
	<table border="0" cellpadding="2" cellspacing="1" width="100%">
		<tr>
			<td width="100" height="24" bgcolor="#cccccc" rowspan="2"><font size="2">お名前</font></td>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">漢字</font></td>
			<td  height="24" bgcolor="#eeeeee"><font size="2">$regname<input type="hidden" name="regname" value="$regname"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">ふりがな</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$freename<input type="hidden" name="freename" value="$freename"></font></td>
		</tr>

		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">メールアドレス</font></td>
			<td width="100" height="24" colspan="2" bgcolor="#eeeeee"><font size="2">$email<input type="hidden" name="email" value="$email"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" rowspan="5" bgcolor="#cccccc"><font size="2">ご住所</font></td>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">郵便番号</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$zip1-$zip2<input type="hidden" name="zip1" value="$zip1"><input type="hidden" name="zip2" value="$zip2"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">都道府県</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$ken<input type="hidden" name="ken" value="$ken"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">市区郡</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$add1<input type="hidden" name="add1" value="$add1"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">町村番地</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$add2<input type="hidden" name="add2" value="$add2"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#dddddd" align="center"><font size="2">ビル名など</font></td>
			<td  height="24"bgcolor="#eeeeee"><font size="2">$add3<input type="hidden" name="add3" value="$add3"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">電話番号</font></td>
			<td width="100" height="24" colspan="2" bgcolor="#eeeeee"><font size="2">$tel<input type="hidden" name="tel" value="$tel"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">お支払い方法</font></td>
			<td  height="24"colspan="2" bgcolor="#eeeeee"><font size="2">$howto<input type="hidden" name="howto" value="$howto"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">ご希望配送日</font></td>
			<td  height="24"colspan="2" bgcolor="#eeeeee"><font size="2">$sendworks<input type="hidden" name="sendmon" value="$sendmon"><input type="hidden" name="sendday" value="$sendday"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">ご希望配送時間</font></td>
			<td  height="24"colspan="2" bgcolor="#eeeeee"><font size="2">$sendtime<input type="hidden" name="sendtime" value="$sendtime"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">その他メッセージ</font></td>
			<td  height="24"colspan="2" bgcolor="#eeeeee"><font size="2">$msg<input type="hidden" name="msg" value="$msg"></font></td>
		</tr>
		<tr>
			<td width="100" height="24" bgcolor="#cccccc"><font size="2">パスワード</font></td>
			<td  height="24"colspan="2" bgcolor="#eeeeee"><font size="2">$passdisp<input type="hidden" name="pass" value="$pass"></font></td>
		</tr>
	</table>
	<hr size=1 noshade>
	<table border="0" cellpadding="2" cellspacing="1" width="100%">
		<tr>
			<td width="50%" align="center">
			<input type="submit" value="＞＞購入する">
			<input type="hidden" name="uid" value="$uid">
			<input type="hidden" name="mode" value="thanks">
			<input type="hidden" name="areacode" value="$areacode">
			<input type="hidden" name="password" value="$password">
			<input type="hidden" name="type" value="$type">
			<input type="hidden" name="mobid" value="$mobid">
			<input type="hidden" name="watch" value="$watch">
			</td>
			</form>
			<td width="50%" align="center">
			<input type="button" value="＜＜前の画面へ" onClick="history.go(-1)">
			</td>
		</tr>
	</table>
<br>
EOF
&designdisp;
}
#お礼画面------------------------------------------------------------------------------------------------------------------------------------------------
if($mode eq "thanks"){

	if($sendmon && $sendday){$sendworks="$sendmon月$sendday日";}elsif($sendmon eq "" && $sendday eq ""){$sendmonandday="希望日なし";}

	$ds = 'dbi:Pg:dbname=store';
	$user = 'pgsql';
	$dbpass = '';
	$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");

	#カートの中身---------------------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select cuid,cgid,cgsmath,explus from mobcart where cuid='$uid' and mobid = '$mobid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$buyerdata = join(':-snichcode-:',@$ref);
		push(@lines,$buyerdata);
	}
	#カートの中身---------------------------------------------------------------------------------------------------

	#BIDの読み込み--------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select newid from ids");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){$bid = @$ref[0];}
	$sth = $dbh->prepare("update ids set newid = newid +1");
	$sth->execute;
	
	$buytime=time;

	#例外地域に含まれていないか確認---------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select kencode from kencodes where kenname='$ken'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$kencode = $ref->[0];
	}
	$kencode = sprintf("k%02d", $kencode);
	$sth = $dbh->prepare("select $kencode from kenfee where uid='$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$kenfee = $ref->[0];
	}

	#地域ごとの送料呼び出し---------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select $areacode,daibiki,nofee from sendfee where uid='$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$areafeedt = join(':-snichcode-:',@$ref);
	}
	($areafee,$daibiki,$nofee) = split(':-snichcode-:',$areafeedt);

	if ($kenfee ne '') {
		$areafee = $kenfee;
	}

	foreach (@lines){
		($c_uid,$c_gid,$c_gsmath,$c_explus) = split(':-snichcode-:',$_);
		$sth = $dbh->prepare("select gsname,gsprice,gstax,gsunit from goodslist where uid='$uid' and gid='$c_gid'");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$gsdata = join(':-snichcode-:',@$ref);}
		($gsname,$gsprice,$gstax,$gsunit) = split(":-snichcode-:",$gsdata);

		$pfee = $c_gsmath * $gsprice;
		$total = $total + $pfee;
		if($gstax){$tax = $tax + int($c_gsmath * $gsprice * 0.05);}else{ $tax=$tax+0; }
		if($c_explus) {
			$gsname .= "($c_explus)";
		}

		$mailbuydata2 .="$gsname： $gsprice× $c_gsmath$gsunit＝ $pfee円\n";

		$writedata.="$gsname:-snichcode-:$gsprice:-snichcode-:$gstax:-snichcode-:$c_gsmath\n";
		push(@gslist, [$gsname,$gsprice,$gstax,$c_gsmath]);#配列リファレンスを配列に追加

		#在庫への反映-------------------------------------------------------------------------------------
		$sth = $dbh->prepare("update goodslist set gsallmath=gsallmath-$c_gsmath where uid='$uid' and gid='$c_gid'");
		$sth->execute;

	}#end_foreach

	#送料・手数料の計算-------------------------------------------------------------------------------------
	if($howto eq "代金引換"){ $sendfee = $areafee + $daibiki; }else{ $sendfee = $areafee; }
	if($nofee > 0){
		if($total >= $nofee){$sendfee=0;}

	}
	$total_all = $total + $tax + $sendfee;

	#購入者情報の書き出し-------------------------------------------------------------------------------------
	if($c_uid){
		#BID/時間と同期して購入商品データの書き出し-------------------------------------------------------------------------------------
		$sth = $dbh->prepare("insert into buyergoods values('$uid','$bid','$buytime','$writedata','$sendfee','$howto','$paymoney','$sendgoods','$sendmon','$sendday','$sendtime','$msg')");
		$sth->execute;

		#BID/時間と同期して購入商品データを個別に書き出し(buyergoods2)-------------------------------------------------------------------------------------
		($s,$m,$h,$d,$m,$y) = (localtime($buytime))[0..5];
		$m++;$y+=1900;
		$buydate = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $y,$m,$d,$h,$m,$s);
		foreach $gsdata (@gslist) {
			($mygsname, $mygsprice, $mygstax, $mygsmath) = @$gsdata;
			$sth = $dbh->prepare("insert into buyergsdata values('$uid','$bid','$buydate','$mygsname','$mygsprice','$mygstax','$mygsmath')");
			$sth->execute;
		}

		#顧客個人情報の書き出し
		$sth = $dbh->prepare("insert into buyerdata values('$uid','$bid','$buytime','$pass','$regname','$freename','$email','$sex','$zip1','$zip2','$ken','$add1','$add2','$add3','$tel','$fax','$birtha','$birthb','$birthc')");
		$sth->execute;

	}
	#メール情報の呼び出し-------------------------------------------------------------------------------------
	$sth = $dbh->prepare("select * from mailset where uid='$uid'");
	$sth->execute;
	$num = $sth->{'NUM_OF_FIELDS'};
	while($ref = $sth->fetchrow_arrayref){
		$maildata = join(':-snichcode-:',@$ref);
	}

	#カートの削除
	$sth = $dbh->prepare("delete from mobcart where cuid='$uid' and mobid='$mobid'");
	$sth->execute;

	$sth->finish;
	$dbh->disconnect;



	#メール配信-------------------------------------------------------------------------------------
	#メール設定呼び出し→分解
	if($c_uid){
		($uid,$mailtomaster,$mailtobuyer,$mailtitle,$mailtop,$mailunder,$footer) = split(":-snichcode-:",$maildata);
	}

	#顧客情報の記入
	$mailbuydata1 .=<<"EOF";

お名前　　　　 $regname
ふりがな　　　 $freename
お届け先住所　 $zip1-$zip2
　　　　　　　 $ken
　　　　　　　 $add1
　　　　　　　 $add2
　　　　　　　 $add3
電話番号　　　 $tel

EOF

	$mailbuydata2 .="　　　　　　　　　小計　　　　 $total円\n";
	$mailbuydata2 .="　　　　　　　　　消費税　　　 $tax円\n";
	$mailbuydata2 .="　　　　　　　　　送料/手数料　 $sendfee円\n";
	$mailbuydata2 .="　　　　　　　　　総合計　　　 $total_all円\n";
	$mailbuydata2 .="　　　　　　　　　支払い方法　 $howto\n";
	$mailbuydata2 .="\n";
	$mailbuydata2 .="ご希望配送日：$sendworks\n";
	$mailbuydata2 .="ご希望配送時間：$sendtime\n";


	$subject = "[StoreNavi：購入者]$shopname";
	$subject2 = "$mailtitle";
	$subject3 = "$mailtitle 1/2";
	$subject4 = "$mailtitle 2/2";

	jcode::convert(*subject,'sjis');
	jcode::convert(*subject2,'sjis');
	jcode::convert(*subject3,'sjis');
	jcode::convert(*subject4,'sjis');

	#001-----管理者に配信
	$EncodeSubject = &EncodeSubject("$subject");
	$subject = <<"SBJ";
$EncodeSubject
SBJ

	#002-----購入者へ配信
	$EncodeSubject = &EncodeSubject("$subject2");
	$subject2 = <<"SBJ";
$EncodeSubject

SBJ

	#003-----携帯用1
	$EncodeSubject = &EncodeSubject("$subject3");
	$subject3 = <<"SBJ";
$EncodeSubject
SBJ

	#004-----携帯用2
	$EncodeSubject = &EncodeSubject("$subject4");
	$subject4 = <<"SBJ";
$EncodeSubject
SBJ

	#管理者にメール配信をするかどうか
	if($mailtomaster){
	
$mailhead = <<"EOM";
Return-Path: <$masteremail>
Reply-To: $email
Content-type: Text/Plain; charset=iso-2022-jp
Content-transfer-Encoding: 7bit
From: $email
To: $masteremail
Subject: $subject

EOM

$mailbody = <<"EOF";
$shopnameの商品が購入されました。
このメールは自動で配信されています。
------------------------------------------------------------
購入者情報
------------------------------------------------------------
$mailbuydata1
$mailbuydata2


現在の詳しい状況は下記の管理者専用ページにアクセスし確認してください。
■管理者専用ログインページ
http://www.storenavi.com/$uid/index.a
------------------------------------------------------------
■アクセス情報
Remote host: $ENV{'REMOTE_HOST'}
User Agent : $ENV{'HTTP_USER_AGENT'}
HTTP_REFERER: $ENV{'HTTP_REFERER'}
REMOTE_ADDR : $ENV{'REMOTE_ADDR'}
------------------------------------------------------------
EOF
	jcode::convert(*mailhead, 'jis');
	jcode::convert(*mailbody, 'jis');
	open(MAIL, "| $sendmail $masteremail");
	print MAIL $mailhead;
	print MAIL $mailbody;
	close(MAIL);

	jcode::convert(*mailhead, 'jis');
	jcode::convert(*mailbody, 'jis');
	open(MAIL, "| $sendmail $snich");
	print MAIL $mailhead;
	print MAIL $mailbody;
	close(MAIL);
}

if($mailtobuyer){
	if($email =~ /ezweb.ne.jp/ || $email =~ /docomo.ne.jp/ || $email =~ /jp-[a-z].ne.jp/ || $email =~ /analogengine.jp/ || $email =~ /vodafone.ne.jp/){
	$mailhead3 = <<"EOM";
Return-Path: <$masteremail>
Reply-To: $masteremail
Content-type: Text/Plain; charset=iso-2022-jp
Content-transfer-Encoding: 7bit
From: $masteremail
To: $email
Subject: $subject3

EOM
	$mailhead4 = <<"EOM";
Return-Path: <$masteremail>
Reply-To: $masteremail
Content-type: Text/Plain; charset=iso-2022-jp
Content-transfer-Encoding: 7bit
From: $masteremail
To: $email
Subject: $subject4

EOM

$mailbody3 = <<"EOF";
$regname様
$mailtop

$mailbuydata1
EOF

$mailbody4 = <<"EOF";
$mailbuydata2
$mailunder

$footer

EOF

	jcode::convert(*mailhead3, 'jis');
	jcode::convert(*mailbody3, 'jis');
	open(MAILL, "| $sendmail $email");
	print MAILL $mailhead3;
	print MAILL $mailbody3;
	close(MAILL);

	jcode::convert(*mailhead4, 'jis');
	jcode::convert(*mailbody4, 'jis');
	open(MAILL, "| $sendmail $email");
	print MAILL $mailhead4;
	print MAILL $mailbody4;
	close(MAILL);

	}else{

$mailhead2=<<"EOF";
Return-Path: <$masteremail>
Reply-To: $masteremail
Content-type: Text/Plain; charset=iso-2022-jp
Content-transfer-Encoding: 7bit
From: $masteremail
To: $email
Subject: $subject2

EOF

$mailbody2 = <<"EOF";
$regname様
$mailtop

$mailbuydata1
$mailbuydata2

$mailunder

$footer

EOF

	jcode::convert(*mailhead2, 'jis');
	jcode::convert(*mailbody2, 'jis');
	open(MAILL, "| $sendmail $email");
	print MAILL $mailhead2;
	print MAILL $mailbody2;
	close(MAILL);
	}
}

	#クッキーの削除
#	$cookietag = <<"EOF";
#	<meta http-equiv="Set-Cookie" content="storedata=;">
#EOF
	$gogocookie = "ers";

	#サンクス画面の生成
	$play.=<<"EOF";
		<div align="center">
		<table border="0" cellpadding="5" cellspacing="1" bgcolor="#545454" width="300">
			<tr>
				<td align="center" bgcolor="white"><img src="store/tmpimgs/thanks01.gif" width="227" height="21" border="0"></td>
			</tr>
			<tr>
				<td bgcolor="#e6e6e6" align="left"><font size="2">$disptxtthanks</font>
				</td>
			</tr>
		</table>
		</div>
EOF
&designdisp;
}


#デザイン出力------------------------------------------------------------------------------------------------------------------------------------------------------
sub menudisp {

	foreach $gomenupart(@menu){
		($uid,$mid,$mname,$mnum,$mtitlecolor,$mbgcolor,$mimg,$mtitlebgcolor,$mlinecolor,$mlineimg) = split(":-snichcode-:",$gomenupart);


		if($mimg){
			$menutitlein=<<"EOF";
				<img src="store/menu/$mimg.jpg">
EOF
			$mtitlebgcolor="";
		}else{
			$menutitlein=<<"EOF";
				<table width="100%" border="0" cellpadding="3" cellspacing="0">
				<tr><td><font size="2" color="$mtitlecolor">$mname</font></td></tr>
				</table>
EOF
		}

		if($mlineimg){
			$menuline=<<"EOF";
			<img src="store/menu/$mimg-line.jpg">
EOF
		}else{

			$menuline=<<"EOF";
			<hr size="1" color="$mlinecolor" noshade>
EOF
		}

		$menudisp.= <<"EOF";
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr><td bgcolor="$mtitlebgcolor">$menutitlein</td></tr>
		<tr><td bgcolor="$mbgcolor"><img src="images/spacer.gif" width="100%" height="5"></td></tr>
EOF

		foreach $categopart(@category){
			($uid,$cid,$cname,$cnum,$ctitle,$ctext,$ctitlecolor,$cgimg,$rmid) = split(":-snichcode-:",$categopart);
			if($mid == $rmid){
				if($cid==1){
					$menudisp.= <<"EOF";
					<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$cgifile?uid=$uid&mode=cart&watch=$watch&mobid=$mobid">$cname</a></font></td></tr>
					<tr><td bgcolor="$mbgcolor">$menuline</td></tr>
EOF
				}elsif($cid==2){
					$menudisp.= <<"EOF";
					<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$cgifile?uid=$uid&mode=profile&watch=$watch&mobid=$mobid">$cname</a></font></td></tr>
					<tr><td bgcolor="$mbgcolor">$menuline</td></tr>
EOF
				}elsif($cid==3){
					$menudisp.= <<"EOF";
					<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$cgifile?uid=$uid&mode=contact&watch=$watch&mobid=$mobid">$cname</a></font></td></tr>
					<tr><td bgcolor="$mbgcolor">$menuline</td></tr>
EOF
				}elsif($cid==4){
					$menudisp.= <<"EOF";
					<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$cgifile?uid=$uid&watch=$watch&mobid=$mobid">$cname</a></font></td></tr>
					<tr><td bgcolor="$mbgcolor">$menuline</td></tr>
EOF
				}else{
					$menudisp.= <<"EOF";
					<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$cgifile?uid=$uid&mode=categorydisp&gscategory=$cid&watch=$watch&mobid=$mobid">$cname</a></font></td></tr>
					<tr><td bgcolor="$mbgcolor">$menuline</td></tr>
EOF
				}
			}
		}
		$menudisp.= <<"EOF";
		</table><br>
EOF
	}
#=cmt
	if ($description || $prtext) {
	$menudisp.= <<"EOF";
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr><td bgcolor="$mbgcolor"><font size="2"><a href="index.a?uid=$uid&mode=privacy&watch=$watch&mobid=$mobid">プライバシーポリシー</a></font></td></tr>
	</table><br>
EOF
	}
	if (@banner) {
		$menudisp.= <<"EOF";
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr><td bgcolor="$mbgcolor"><img src="images/spacer.gif" width="100%" height="5"></td></tr>
EOF

		foreach $bannerpart (@banner) {
			($uid,$time,$bid,$bname,$bimg,$linktext,$golink,$target) = split(/:-snichcode-:/,$bannerpart);
			if (-e "$bannertemp/$bimg.jpg") {
				$bimgdisp = <<"EOF";
				<img src="$bannerplace/$bimg.jpg"><br>
EOF
			} else {
				$bimgdisp="";
			}
			$menudisp .= <<"EOF";
			<tr><td bgcolor="$mbgcolor"><font size="2"><a href="$golink" target="$target">$bimgdisp$linktext</a></font></td></tr>
EOF
		}

		$menudisp.= <<"EOF";
		</table><br>
EOF
	}
#=cut
}



#デザイン出力------------------------------------------------------------------------------------------------------------------------------------------------------
sub designdisp {
	local($callsize) = @_;
	unless($callsize || $type){&menudisp;}

	unless($titleheight){$titleheight=90;}
	if($bodylr eq "left" || $bodylr eq "right"){ $contentswidth="751"; }else{ $contentswidth="752"; }

	$bodytag=<<"EOF";
	<body bgcolor="$bgcolor" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" text="$fontcolor" link="$linkcolor" vlink="$linkcolor" alink="$linkcolor">
EOF


#menudisp→メニュー
#play→コンテンツ
	

	#cookieクッキー
	if($gogocookie eq "set"){
		print "Set-Cookie: storedata=$newstoredata;";
	}if($gogocookie eq "ers"){
		print "Set-Cookie: storedata=;";
	}

	print "content-type: text/html\n\n";

	
	unless($usetemp eq ""){
		open(TMP,"<temp/$usetemp.txt");
		while(<TMP>){ push(@hptemp,$_)};
		close(TMP);
		

		foreach $hptemp(@hptemp){
			if($hptemp =~ /<##MENU##>/){ $hptemp =~ s/<##MENU##>/$menudisp/g; }
			if($hptemp =~ /<##PLAY##>/){ $hptemp =~ s/<##PLAY##>/$play/g; }
			if($hptemp =~ /<##TOPIMG##>/){ $hptemp =~ s/<##TOPIMG##>/$topimgdata/g; }
			if($hptemp =~ /<##head##>/){ $hptemp =~ s/<##head##>/$headimg/g; }
			if($hptemp =~ /<##GLINK##>/){ $hptemp =~ s/<##GLINK##>/$gmenu/g; }
			if($hptemp =~ /<##COOKIE##>/){ $hptemp =~ s/<##COOKIE##>/$cookietag/g; }
			if($hptemp =~ /<##SCRIPT##>/){ $hptemp =~ s/<##SCRIPT##>/$script/g; }
			if($hptemp =~ /<##TITLE##>/){ $hptemp =~ s/<##TITLE##>/$title/g; }
			if($hptemp =~ /<##BODY##>/){ $hptemp =~ s/<##BODY##>/$bodytag/g; }
			if($hptemp =~ /<##FOOT##>/){ $hptemp =~ s/<##FOOT##>/$dispfooter/g; }

			#変数
			if($hptemp =~ /\$bodylr/){ $hptemp =~ s/\$bodylr/$bodylr/g; }
			if($hptemp =~ /\$contentswidth/){ $hptemp =~ s/\$contentswidth/$contentswidth/g; }
			if($hptemp =~ /\$bgcolorin/){ $hptemp =~ s/\$bgcolorin/$bgcolorin/g; }
			if($hptemp =~ /\$bgcolor/){ $hptemp =~ s/\$bgcolor/$bgcolor/g; }
			if($hptemp =~ /\$bodylinecolor/){ $hptemp =~ s/\$bodylinecolor/$bodylinecolor/g; }
			if($hptemp =~ /\$titlebgcolor/){ $hptemp =~ s/\$titlebgcolor/$titlebgcolor/g; }
			if($hptemp =~ /\$titleimg/){ $hptemp =~ s/\$titleimg/$titleimg/g; }
			if($hptemp =~ /\$titleheight/){ $hptemp =~ s/\$titleheight/$titleheight/g; }
			if($hptemp =~ /\$titlesize/){ $hptemp =~ s/\$titlesize/$titlesize/g; }
			if($hptemp =~ /\$titlecolor/){ $hptemp =~ s/\$titlecolor/$titlecolor/g; }
			if($hptemp =~ /\$shopnamedisp/){ $hptemp =~ s/\$shopnamedisp/$shopnamedisp/g; }
			if($hptemp =~ /\$cgifile/){ $hptemp =~ s/\$cgifile/$cgifile/g; }
			if($hptemp =~ /\$uid/){ $hptemp =~ s/\$uid/$uid/g; }
			if($hptemp =~ /\$watch/){ $hptemp =~ s/\$watch/$watch/g; }
			if($hptemp =~ /\$globebackcolor/){ $hptemp =~ s/\$globebackcolor/$globebackcolor/g; }

			$hptemp =~ s/<!--#.*?-->//g;

			print $hptemp;
		}

	}else{
		print<<"EOF";
		<html>
		<head>
		<title>$title$dgsname</title>
		<meta http-equiv="content-type" content="text/html;charset=euc-jp">
		$cookietag
		$script
		</head>
		<body bgcolor="$bgcolor" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" text="$fontcolor" link="$linkcolor" vlink="$linkcolor" alink="$linkcolor">
		<div align="$bodylr">
		<table border="0" width="$contentswidth" height="100%" bgcolor="$bgcolor" border="0" cellpadding="0" cellspacing="0">
		<tr>
EOF

		unless($bodylr eq "left"){
			print<<"EOF";
			<td width="1" bgcolor="$bodylinecolor" valign="top"><img src="images/spacer.gif" width="1" height="1"></td>
EOF
		}

		print<<"EOF";
		<td width="750" valign="top" bgcolor="$bgcolorin">

			<table border="0" width="750" border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td valign="center" bgcolor="$titlebgcolor" background="$titleimg" height="$titleheight"><font size="$titlesize" color="$titlecolor">$shopnamedisp</font></td>
				</tr>
				<tr>
					<td valign="top">
EOF

	unless($type){
		print<<"EOF";
			<table border="0" width="750" border="0" cellpadding="0" cellspacing="0">
			<tr>
			<td valign="top" width="10" rowspan="4"><img src="images/spacer.gif" width="10" height="10"></td>
			<td valign="top" colspan="3"><img src="images/spacer.gif" width="10" height="10"></td>
			<td valign="top" width="10" rowspan="4"><img src="images/spacer.gif" width="10" height="10"></td>
			</tr>
			<tr>
			<td valign="top" width="170">$menudisp</td>
			<td valign="top" width="15"><img src="images/spacer.gif" width="15" height="15"></td>
			<td valign="top" width="545">
				<table border="0" width="100%" border="0" cellpadding="3" cellspacing="0">
				<tr><td bgcolor="$globebackcolor"><font size="2">$homepagedisp<a href="$cgifile?uid=$uid&watch=$watch&mobid=$mobid">トップページ</a>　$gmenu</font></td></tr>
				<tr><td><img src="images/spacer.gif" width="1" height="1"></td>
				</tr>
				</table>
EOF
	}else{
		print<<"EOF";
			<table border="0" width="750" border="0" cellpadding="0" cellspacing="0">
			<tr>
			<td valign="top" width="10" rowspan="4"><img src="images/spacer.gif" width="10" height="10"></td>
			<td valign="top"><img src="images/spacer.gif" width="10" height="10"></td>
			<td valign="top" width="10" rowspan="4"><img src="images/spacer.gif" width="10" height="10"></td>
			</tr>
			<tr>
			<td valign="top" width="730">
EOF
	}

	print<<"EOF";
		$play
		</td>
		</tr>
		</table>

		</td></tr>
		<tr>
			<td valign="top" align="center">
			<hr size="1" color="#$menucolor_orange[0]" noshade>
			<font size="2">
			<a href="$cgifile?uid=$uid&mode=profile&watch=$watch&mobid=$mobid">通信販売法による法規表示</a>　
			<a href="$cgifile?uid=$uid&mode=contact&watch=$watch&mobid=$mobid">お問い合わせ</a>　
			<a href="http://www.storenavi.com" target="_blank">通販開業支援ストアナビ</a>
			<br>
			<br>
			<br>
			</font>
			</td>
		</tr>
		</table>
	
		</td>
EOF

		unless($bodylr eq "right"){
			print<<"EOF";
			<td width="1" bgcolor="$bodylinecolor" valign="top"><img src="images/spacer.gif" width="1" height="1"></td>
EOF
		}

		print<<"EOF";
		</tr>
		</table>
		</div>
		</body>
		</html>
EOF
	}#無いとき〜

}
#デザイン出力------------------------------------------------------------------------------------------------------------------------------------------------------

#閉店時出力------------------------------------------------------------------------------------------------------------------------------------------------------
sub closeShop {
	print "content-type: text/html\n\n";
	print<<"EOF";
	
	<html>
	<head>
	<title>$shopname</title>
	<meta http-equiv="content-type" content="text/html;charset=euc-jp">
	</head>
	<body bgcolor="#ffffff" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
	<div align="center">
	<br>
	<br>
	<table border="1" width="400" border="1" cellpadding="10" cellspacing="0">
	<tr><td align="center" bgcolor="#ff9900"><b>準備中です</b></td></tr>
	<tr><td align="left" bgcolor="#ffffff"><font size="2">
	この店舗は、現在準備中です。ご迷惑をおかけいたしますが、今しばらくお待ち下さい。またのご訪問、お待ちしております。<br>
	<br>
	<b>$shopname</b><br>
	ご連絡お問い合わせは<a href="mailto:$masteremail">こちら</a>まで
	</font></td></tr>
	</table>
	</div>
	</body>
	</html>
EOF
exit(0);
}
#閉店時出力------------------------------------------------------------------------------------------------------------------------------------------------------



#------------------------------------------------------------------
#　サブルーチン集
#------------------------------------------------------------------
sub comma {
	$len=length($_[0])-3;
	for($i=$len;$i>0;$i=$i-3){
	$tmp=substr($_[0],0,$i);
	substr($_[0],0,$i)="$tmp,";
	}
}

sub exitError {
	my($msg) = @_;
	$msg =~ s/\n/<br>/g;

$play.=<<"EOF";
<hr size="1" noshade>
<font size="2"><b>エラーが発生しました</b></font>
<hr size="1" noshade>
<font color="#FF0000" size="2">$msg</font>
<hr size="1" noshade>
<INPUT TYPE="BUTTON" value="戻る" onClick="history.go(-1)">
<hr size="1" noshade>

EOF

&designdisp;
}

sub exitErrorMS {
	my($msg) = @_;
	$msg =~ s/\n/<BR>\n/g;
$play.=<<"EOF";
<font color="#FF0000">$msg</font><BR>
<font color="#0000FF">$!</font>
<INPUT TYPE="BUTTON" value="戻る" onClick="history.go(-1)">

EOF

&designdisp;
}


sub calendar {
@week = ('日','月','火','水','木','金','土');

	$callenddisp = "　　<a href=$cgifile?uid=$uid&schepl=1&watch=$watch&mobid=$mobid>来月</a>";
	$callenddispp = "<a href=$cgifile?uid=$uid&watch=$watch&mobid=$mobid>先月</a>　　";
	if($schepl){$callenddisp = "";}
	else{$callenddispp = "";}

	($rs1,$rs1,$rs1,$rs1,$mon01,$year01,$wday01,$yday,$isdst) = localtime(time );
	$mon01 = $mon01 + 1 + $schepl;
	$year01 = $year01 + 1900;
	if ($mon01 > 12) { $mon01 -= 12; $year++; } 
	$calltimelocal = timelocal(0,0,0,1,$mon01-1,$year01-1900);
	
	$play .=<<"EOF";
	<table border="0" cellpadding="3" cellspacing="1" bgcolor="$calcolor">
	<tr>
		<td colspan="7" align="center">
		<font size="1">$callenddispp$year01年$mon01月$callenddisp</font></center>
		</td>
	</tr>
	<tr>
		<td align="center" width="15" bgcolor="#ffeeee"><font size="1" color="$hclr">$week[0]</font></td>
		<td align="center" width="15" bgcolor="$bgcolorin"><font size="1" color="$dclr">$week[1]</font></td>
		<td align="center" width="15" bgcolor="$bgcolorin"><font size="1" color="$dclr">$week[2]</font></td>
		<td align="center" width="15" bgcolor="$bgcolorin"><font size="1" color="$dclr">$week[3]</font></td>
		<td align="center" width="15" bgcolor="$bgcolorin"><font size="1" color="$dclr">$week[4]</font></td>
		<td align="center" width="15" bgcolor="$bgcolorin"><font size="1" color="$dclr">$week[5]</font></td>

		<td align="center" width="15" bgcolor="#eeeeff"><font size="1" color="$eclr">$week[6]</font></td>
		</tr>
	<tr>
EOF

	$ds = 'dbi:Pg:dbname=store';
	$user = 'pgsql';
	$dbpass = '';
	$dbh = DBI->connect($ds,$user)or exitError("Cannot connect.");

#月の末日----------
$lastday01 = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$mon01 - 1]
 + ($mon01 == 2 and $year01 % 4 == 0 and
($year01 % 400 == 0 or $year01 % 100 != 0));
#月の末日----------

	for($i=1; $i<=$lastday01;$i++){
		$calltimelocal02 = timelocal(0,0,0,$i,$mon01-1,$year01-1900);
		($rs1,$rs1,$rs1,$mday02,$mon02,$year02,$wday02,$yday,$isdst) = localtime($calltimelocal02);
		$mon02 = $mon02 + 1;
		$year02 = $year02 + 1900;

		$mmmon = sprintf("%02d",$mon02);
		$mmday = sprintf("%02d",$mday02);
		$cktimelocal=$year02.$mmmon.$mmday;

		$existrest ="";
		$sth = $dbh->prepare("select * from calendar where uid = '$uid' and timelocal='$cktimelocal' limit 1");
		$sth->execute;
		$num = $sth->{'NUM_OF_FIELDS'};
		while($ref = $sth->fetchrow_arrayref){$existrest = @$ref[0];}

		if($mon01 ne $mon02){

			$callreturn = 7-$wday02;
			foreach(1..$callreturn){$play.="<td bgcolor=$bgcolorin align=center><font size=1 color=$bgcolorin>-</font></td>";}
		last;
		}
		if($callflag eq "" && $wday02 != 0){
			foreach(1..$wday02){$play.="<td bgcolor=$bgcolorin align=center><font size=1 color=$bgcolorin>-</font></td>";}
		}
		$callflag++;
		if($existrest){
			$play.="<td bgcolor=$bgcolorin align=center><font size=1 color=red>$mday02</font></td>";
		}else{
			$play.="<td bgcolor=$bgcolorin align=center><font size=1>$mday02</font></td>";
		}

		if($wday02 == 6){$play.="</tr><tr>";}
	}

	$sth->finish;
	$dbh->disconnect;

	$play .=<<"EOF";
	</tr></table>
	<font size=2>※赤字は休業日です。</font>
EOF
}

exit(0);