#!/usr/bin/perl
#use CGI::Carp qw(fatalsToBrowser);
#///////////////////////////////////////////////////////////////////////////////
#                          html_maker for PCtoMoble   VER2.00
#
#                      ----- 2008(C) WEB INVENTOR(Solve) -----
#                                 solve@wb-i.net
#                                 http://wb-i.net/
#
#///////////////////////////////////////////////////////////////////////////////
#================================ [注意事項] ===================================
# このスクリプトはシェアウエアです。このスクリプトを使用したいかなる損害に対して
# も作者は一切の責任を負いません。
#====================================使用法=====================================
# ショッピングカートと同じフォルダに入れて、次のようにして呼び出してください。
#	http://・・/html_maker.cgi
#
#===============================================================================
# ▼設定▼
#===============================================================================
#==HTML生成フォルダ==
$shop_html2 ="./";

#==============================================================================
# ▲設定終了▲
#==============================================================================

#======パスの設定====
#html_makerへのパス
$script_maker ="./html_maker.cgi";

#cgi-lib.plへのパス
require './cgi-lib.pl';

#===================

&ReadParse;

while (($key,$val) = each %in) {
	$in{$key} = $val;
}

# 設定ファイル====================================================================
require './set.pl';

#====================戻り先========================================================
$save_data="$script?&keyword=$in{'keyword'}&FF=$in{'FF'}&class=$in{'class'}";

#===============管理用入り口======================
if ( $in{'mode'} eq '') { &adm1; exit;}
if ( $in{'pass'} ne $adm_pass ) {  &adm1; exit; }
if ( $in{'mode'} eq 'make_ok' ) { &adm2; exit;}
if ( $in{'mode'} ne 'html_make' ) { &adm1; exit;}

#%%%%%%%%%%%ＴＯＰページのHTML生成
if($in{'html1'}){
	$url_home ="$class_htm_dir/home.htm";
	$h =$h_0;
	&top_make();

	$html_file_name ="$shop_html2".'home.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
#%%%%%%%%%%%ＴＯＰXページのHTML生成

if($in{'top1'} && $top1_name){
	$url_home ="$class_htm_dir/top1.htm";
	$topx_url =$top1_url;
	$topx_html =$top1_html;
	$h =$h_1;
	&topx_make();

	$html_file_name ="$shop_html2".'top1.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
if($in{'top2'} && $top2_name){
	$url_home ="$class_htm_dir/top2.htm";
	$topx_url =$top2_url;
	$topx_html =$top2_html;
	$h =$h_2;
	&topx_make();

	$html_file_name ="$shop_html2".'top2.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
if($in{'top3'} && $top3_name){
	$url_home ="$class_htm_dir/top3.htm";
	$topx_url =$top3_url;
	$topx_html =$top3_html;
	$h =$h_3;
	&topx_make();

	$html_file_name ="$shop_html2".'top3.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
if($in{'top4'} && $top4_name){
	$url_home ="$class_htm_dir/top4.htm";
	$topx_url =$top4_url;
	$topx_html =$top4_html;
	$h =$h_4;
	&topx_make();

	$html_file_name ="$shop_html2".'top4.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
if($in{'top5'} && $top5_name){
	$url_home ="$class_htm_dir/top5.htm";
	$topx_url =$top5_url;
	$topx_html =$top5_html;
	$h =$h_5;
	&topx_make();

	$html_file_name ="$shop_html2".'top5.html';
	&html_write();

	push (@result_url1,$html_file_name);
}
if($in{'top6'} && $top6_name){
	$url_home ="$class_htm_dir/top6.htm";
	$topx_url =$top6_url;
	$topx_html =$top6_html;
	$h= $h_6;
	&topx_make();

	$html_file_name ="$shop_html2".'top6.html';
	&html_write();

	push (@result_url1,$html_file_name);
	push (@result_name1,$top6_name);
}
if($in{'top7'} && $top7_name){
	$url_home ="$class_htm_dir/top7.htm";
	$topx_url =$top7_url;
	$topx_html =$top7_html;
	$h= $h_7;
	&topx_make();

	$html_file_name ="$shop_html2".'top7.html';
	&html_write();

	push (@result_url1,$html_file_name);
	push (@result_name1,$top7_name);
}
if($in{'top8'} && $top8_name){
	$url_home ="$class_htm_dir/top8.htm";
	$topx_url =$top8_url;
	$topx_html =$top8_html;
	$h= $h_8;
	&topx_make();

	$html_file_name ="$shop_html2".'top8.html';
	&html_write();

	push (@result_url1,$html_file_name);
	push (@result_name1,$top8_name);
}
if($in{'top9'} && $top9_name){
	$url_home ="$class_htm_dir/top9.htm";
	$topx_url =$top9_url;
	$topx_html =$top9_html;
	$h= $h_9;
	&topx_make();

	$html_file_name ="$shop_html2".'top9.html';
	&html_write();

	push (@result_url1,$html_file_name);
	push (@result_name1,$top9_name);
}
if($in{'top10'} && $top10_name){
	$url_home ="$class_htm_dir/top10.htm";
	$topx_url =$top10_url;
	$topx_html =$top10_html;
	$h= $h_10;
	&topx_make();

	$html_file_name ="$shop_html2".'top10.html';
	&html_write();

	push (@result_url1,$html_file_name);
	push (@result_name1,$top10_name);
}

&result();
exit;
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#========================HTMLの書き込み=================
sub html_write{

	open(OUT,"> $html_file_name") || &error("HTMLの書き込みに失敗しました","$html_file_name");
	print OUT "$html_data\n";
	close(OUT);

}
#===============ＴＯＰページの作成================
sub top_make{
$html_data ='';
if($xhtml_use){
	if($xhtml_use ne 2){$html_data = "<?xml version='1.0' encoding='Shift_JIS'?>\n";}
	$html_data .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n";
	$html_data .= "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='ja' lang='ja'>\n";
}else{
	$html_data .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
	$html_data .= "<html lang='ja'>\n";
}

	$html_data .= "<head>\n";
	$html_data .= "<meta content=\"text/html; charset=Shift_JIS\" http-equiv='Content-Type'$xslash>\n";
	$html_data .= "<title>$main_title</title>\n";
	$html_data .= "<meta name=\"keywords\" content=\"$shop_keywords\"$xslash>\n";
	$html_data .= "<meta name=\"description\" content=\"$shop_description\"$xslash>\n";
	$html_data .= "<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"$xslash>\n";
	$html_data .= "<meta content=\"text/css\" http-equiv='Content-Style-Type'$xslash>\n";
	$html_data .= "$style";
	$html_data .= "</head>$body$header\n";

if($inner_farme_yes){
$iframe_h =$h;
$url_home ="$class_htm_dir/home.htm";

$iframe_w =$t_width;

$html_data .=<<"EOF";
<center>
<table cellSpacing='0' cellPadding='0' border='0' width="$iframe_w">
<tr><td align="center" bgcolor="" height="$iframe_h">
<iframe src="$url_home" height="100%"  width="100%"  border="0" frameborder="0" marginheight="0" marginwidth="0" name="sign" scrolling="auto" allowtransparency='true'>
この部分は iframe 対応のブラウザで見てください。
</iframe>
</td></tr>
</table>
</center>
EOF
}

	$html_data .="$foot</body></html>" ;	

}
#===============ＴＯＰ１〜５のページの作成================
sub topx_make{
$url_goods_no ="$script?id";

$script_save ="$script?order=$order_encode&amp;class=$class_encode&amp;keyword=$keyword_encode&amp;FF=$in{'FF'}&amp;pic_only=$in{'pic_only'}";
$into_cart_url =$script_save."&amp;mode=look";
$url_class ="$script?superkey=1&amp;FF=0&amp;pic_only=$in{'pic_only'}&amp;class";
$url_keyword ="$script?FF=0&amp;pic_only=$in{'pic_only'}&amp;keyword";
$url_mode ="$script?t";
$url_mode =~ s/shop.cgi/index.cgi/g;

$kensaku_form = <<"EOF";
<form method='post' action="$script" style='margin: 0px;'>
<input type="text" size='20' name="keyword" value="$pas_word" class='kensaku'$xslash>
<input type="hidden" name="class" value="all"$xslash>
<input type='submit' value="商品検索" class='submit'$xslash>
<input type="hidden" name="FF" value='0'$xslash>
<input type="hidden" name="superkey" value="1"$xslash>
<input type="hidden" name="order" value="$in{'order'}"$xslash>
<input type="hidden" name="price_sort" value="$in{'price_sort'}"$xslash>
<input type="hidden" name="pic_only" value="$in{'pic_only'}"$xslash>
</form>
EOF

$into_cart_form = <<"EOF";
<form method="post" action="$script" style='margin: 0px;'>
<input type="hidden" name="order" value="$in{'order'}"$xslash>
<input type="hidden" name="class" value="$in{'class'}"$xslash>
<input type="hidden" name="keyword" value="$in{'keyword'}"$xslash>
<input type="hidden" name="superkey" value="$in{'superkey'}"$xslash>
<input type="hidden" name="price_sort" value="$in{'price_sort'}"$xslash>
<input type="hidden" name="pic_only" value="$in{'pic_only'}"$xslash>
<input type="hidden" name="mode" value="look"$xslash>
<input type='submit' value="レジへ進む" class='submit'$xslash>
</form>
EOF

$html_data ='';
if($xhtml_use){
	if($xhtml_use ne 2){$html_data = "<?xml version='1.0' encoding='Shift_JIS'?>\n";}
	$html_data .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n";
	$html_data .= "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='ja' lang='ja'>\n";
}else{
	$html_data .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
	$html_data .= "<html lang='ja'>\n";
}

	$html_data .= "<head>\n";
	$html_data .= "<meta content=\"text/html; charset=Shift_JIS\" http-equiv='Content-Type'$xslash>\n";
	$html_data .= "<title>$main_title</title>\n";
	$html_data .= "<meta name=\"keywords\" content=\"$shop_keywords\"$xslash>\n";
	$html_data .= "<meta name=\"description\" content=\"$shop_description\"$xslash>\n";
	$html_data .= "<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"$xslash>\n";
	$html_data .= "<meta content=\"text/css\" http-equiv='Content-Style-Type'$xslash>\n";
	$html_data .= "$style";
	$html_data .= "</head>$body$header\n";

if($topx_url eq 'auto'){

$log_in_id =$hello_id;

$topx_html =~ s/\$log_in_id/$log_in_id/g;
$topx_html =~ s/\$log_in_name/$hello_id/g;
$topx_html =~ s/\$log_in_mess/$log_in_mess/g;

$topx_html =~ s/\$url_goods_no/$url_goods_no/g;
$topx_html =~ s/\$url_class/$url_class/g;
$topx_html =~ s/\$url_keyword/$url_keyword/g;
$topx_html =~ s/\$kensaku_form/$kensaku_form/g;
$topx_html =~ s/\$into_cart_url/$into_cart_url/g;
$topx_html =~ s/\$into_cart_form/$into_cart_form/g;
$topx_html =~ s/\$url_top/$url_mode/g;
$topx_html =~ s/\$url_mode/$url_mode/g;

$topx_html =~ s/\$script/$script/g;
$topx_html =~ s/\$order_encode/$order_encode/g;
$topx_html =~ s/\$class_encode/$class_encode/g;
$topx_html =~ s/\$keyword_encode/$keyword_encode/g;
$topx_html =~ s/\$in{'pic_only'}/$in{'pic_only'}/g;
$topx_html =~ s/\$in{'FF'}/$in{'FF'}/g;
$topx_html =~ s/\$in{'price_sort'}/$in{'price_sort'}/g;
$topx_html =~ s/\$pic_only/$in{'pic_only'}/g;
$topx_html =~ s/\$page_no/$in{'FF'}/g;
$topx_html =~ s/\$price_sort/$in{'price_sort'}/g;

$html_data .=<<"EOF";
$topx_html
EOF
}elsif($inner_farme_yes){

$iframe_h =$h;
$url_home ="$class_htm_dir/home.htm";

$iframe_w =$t_width;

$html_data .=<<"EOF";
<center>
<table cellSpacing='0' cellPadding='0' border='0' width="$iframe_w">
<tr><td align="center" bgcolor="" height="$iframe_h">
<iframe src="$url_home" height="100%"  width="100%"  border="0" frameborder="0" marginheight="0" marginwidth="0" name="sign" scrolling="auto" allowtransparency="true">
この部分は iframe 対応のブラウザで見てください。
</iframe>
</td></tr>
</table>
</center>
EOF
}

	$html_data .="$foot</body></html>" ;	

}
#==============================================
sub adm1 {

if($adm_pass eq "1234"){
	$dis_closure = "<br>[パスワード = 1234]<br>";
}

&html_header();

print <<"EOF";
<table width=$o_width align=center cellpadding=0 border=0>
<tr><td>
<div align="right">HTML-MAKER VER2.00</div><hr width=$o_width noshade size=1>
<BR><BR></td></tr></table>
<table bgcolor=$color_adm_r width=400 align=center cellpadding=10 border=1 bordercolor=$color_adm_d>
<tr><td><center>
<form method='post' action="$script_maker">
<input type=hidden name=class value="all">
<input type=hidden name=FF value=0>
<input type=hidden name="keyword" value="">
<input type="hidden" name="superkey" value="1"><br>
◆HTMLを生成します◆<br><br>
生成フォルダ ： $shop_html2<br><br>
管理者用パスワードを入力してください。<br><br>
<input type=password name='pass'>
<input type=hidden name="mode" value="make_ok">
<input type=submit value='HTML生成'>$dis_closure<br>
</form></td></tr></table>
<br></center>
<hr width=$o_width noshade size=1>
$foot
</body></html>
EOF

}
# ====================================================
sub adm2 {

if($adm_pass eq "1234"){
	$dis_closure = "<br>[パスワード = 1234]<br>";
}

&html_header();

print <<"EOF";
<table width=$o_width align=center cellpadding=0 border=0>
<tr><td>
<div align="right">HTML-MAKER VER2.00</div><hr width=$o_width noshade size=1>
<BR><BR></td></tr></table>
<table bgcolor=$color_adm_r width=500 align=center cellpadding=10 border=1 bordercolor=$color_adm_d>
<tr><td><center>
<form method='post' action="$script_maker">
<input type=hidden name=class value="all">
<input type=hidden name=FF value=0>
<input type=hidden name="keyword" value="">
<input type="hidden" name="superkey" value="1"><br>
◆フォルダ $shop_html2 に HTMLを生成します◆<br><br>
<input type="checkbox" name="html1" value="on">home.htmlの生成\　\　 
<input type="checkbox" name="top1" value="on">top1.htmlの生成\　\　 
<input type="checkbox" name="top2" value="on">top2.htmlの生成\　\　 
<input type="checkbox" name="top3" value="on">top3.htmlの生成\　\　 
<input type="checkbox" name="top4" value="on">top4.htmlの生成\　\　 
<input type="checkbox" name="top5" value="on">top5.htmlの生成<br><br>

<input type=hidden name="pass" value="$adm_pass">
<input type=hidden name="mode" value="html_make">
<table>
  <tbody>
    <tr>
      <td height="73" width="370">
      システム設定【１】でタイトル、キーワード、アピールを記述してください。<br><br>
      <FONT color=#ff0000>※HTMLはshop.cgiと同じフォルダ内に生成されます。他のフォルダに移動するときはスタイルシートや画像フォルダのパスを書き換える必要があります。
      </FONT>
      </td>
    </tr>
  </tbody>
</table>

<input type=submit value=' ＯＫ '>
</form></td></tr></table>
<br></center>
<hr width=$o_width noshade size=1>
$foot
</body></html>
EOF

}

# ====================================================
sub result {

&html_header();

foreach(@result_url1){
	$result_link1 .="<LI><A href=\"$_\" target='_brank'><FONT class='link_color'>$_</FONT></A>";
}

print <<"EOF";
<center>
<table width=$o_width align=center cellpadding=0 border=0>
<tr><td>
<div align="right">HTML-MAKER VER2.00</div><hr width=$o_width noshade size=1>
<BR><BR></td></tr></table>
<table bgcolor=$color_adm_r width=500 align=center cellpadding=10 border=1 bordercolor=$color_adm_d>
<tr><td><center><BR>
<B>◆HTMLの生成結果◆</B><BR>
<BR>
<table cellPadding=10 width=400>
<TBODY>
<TR><td bgcolor="#cef0ff">■ＴＯＰページのHTML生成<BR>
      <UL>
$result_link1
      </UL></td></TR>
</TBODY>
</table></center><br>
</td></TR>
</TBODY>
</table>
<table width=$o_width align=center cellpadding=0 border=0>
<tr><td><br>
<div align="center"><A href="$script_maker?pass=$in{'pass'}&mode=make_ok"><FONT class='link_color'>▲戻る</FONT></A></div>
</td></tr></table>
</center><br>
<hr width=$o_width noshade size=1>
$foot
</body></html>
EOF

}

#======================================================================
# Cookieに値を書き込むためのSet-Cookie:ヘッダを生成する
#
sub setCookie{
}
sub setCookie_0{
}
#
# Cookieの値を読み出す
#
sub getCookie{
}

sub html_header{
	print "Content-type: text/html\n\n";
	print "<html><head><title>$main_title</title>\n";
	print "<META content=\"text/html; charset=Shift_JIS\" http-equiv=Content-Type>\n";
	print "<META content=text/css http-equiv=Content-Style-Type>\n";

	print "$style";
	
	print "</head>$body$header\n";

}

#===============================================================
sub error {
&html_header();

	print "<br><center>$_[0]</center>\n";
	print "<center>$_[1]</center>\n";

	print "<br><hr noshade size=1 width=$o_width>$foot</body></html>";
	exit;
}

