#!/usr/bin/perl
require 'cgi-lib0303.pl';
require 'jcode.pl';
require 'sub-lib.pl';
#use Pg;
$|=1;
#$bypasscgi='bypass.cgi';

#===========================================================#
#	hotcake02.pl	小分類表示(パッケージ版)
#	
#	2000/01/23	By T.Murakami 初版
#	2000/07/18	By T.Murakami HotcakeVer2(PostgreSQL)対応
#	
#===========================================================#

#===========================================================#
# メイン処理
#===========================================================#

	# メンテナンスフラグチェック
	&CheckMaintenanceFlg();
	
	# データベースへ接続
	&DBConnect();

	# 2003/02/24 Cookieオン／オフチェック
	&WriteCookie();

	# ブラウザから入力されたデータ取得
	&ReadData;

	# ジャンルＨＴＭＬ表示
	&DisplayHTML;

#===========================================================#
# メイン終了
#===========================================================#

# サブルーチン
#-----------------------------------------------------------
# ブラウザから入力されたデータを取得サブルーチン
#                                               
sub ReadData {

	# Getデータ読込み
#	@Recode = split( /&/,$ENV{'QUERY_STRING'} );	# & で分割
#	foreach $TMP1 ( @Recode ) {
#		# １レコードづつ処理を行う
#		( $Item, $Value ) = split( /=/,$TMP1 );		# = で項目を分割
#		$ReadData{$Item} = $Value;
#	}

	# GetDataの取得方法変更 2000/11/21
	( $Item, $Value ) = split( /=/,$ENV{'QUERY_STRING'} );		# = で項目を分割
	$Value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
	$ChoiceCategoryName = $Value;		# カテゴリコード
}


#-----------------------------------------------------------
# ジャンルＨＴＭＬ表示サブルーチン
#
sub OpenHtmlFile
{
	# カテゴリＨＴＭＬ存在確認
	if( -e $GenreHTML ){
		# ジャンルＨＴＭＬファイルオープン
	    open GenreHTML, "<$GenreHTML";
	}
	else{
		&CgiDie( "\$GenreHTML not found. ");
	}
}


#-----------------------------------------------------------
# ジャンルＨＴＭＬ表示サブルーチン
#
sub DisplayHTML {

	# HTMLファイルオープン
	&OpenHtmlFile();

	# MIMEヘッダー出力
	print &PrintHeader;

	# HTML出力
	while ( <GenreHTML> ) {
		&jcode::convert( *_, 'sjis' );

		# カテゴリ名表示
		if (/#CategoryName#/) {
			s/#CategoryName#/$ChoiceCategoryName/;
		}

		# ジャンル名表示
		if (/#Genre#/) {
			s/#Genre#//;
			&SetBunrui2();
		}
		print $_;
	}
	# ファイルクローズ
	close GenreCSV;
	close GenreHTML;
}


#-----------------------------------------------------------
# 分類２表示
#
sub SetBunrui2 {

	# SQL文発行
	&jcode::convert( *ChoiceCategoryName, 'euc' );
	$strSQL_Sel = "select * 
					from bunrui2_tbl
					 where bunrui1 = \'$ChoiceCategoryName\'
					 order by bunrui2";


	$sth = $conn->prepare("$strSQL_Sel");
	$sth->execute();

=pod
	$result = $conn->exec("$strSQL_Sel");
	$HitCnt = $result->ntuples;
=cut

	$i = 0;
	while ( @row = $sth->fetchrow_array ) {
#	for( $j=0; $j<$HitCnt; $j++ ){
		# 変数へセット
#		$CategoryCode = $result->getvalue($j,0);
		$CategoryCode = $row[0];

#		$GenreName = $result->getvalue($j,1);
		$GenreName = $row[1];

		&jcode::convert( *CategoryCode, 'sjis' );
		&jcode::convert( *GenreName, 'sjis' );
	
		# テーブルレコード開始
		if ( $i == 0 ) {
			print "<tr>\n";
		}
		
		# テーブル内項目設定(2項目)
		if ( $i < 2) {
			print "<td>\n";
#			print "<a href=\"$bypasscgi?hotcake03.pl?Category=" . &url_encode($CategoryCode) . "&Genre=" . &url_encode($GenreName) . "&ViewCnt=1\">";
			print "<a href=\"./hotcake03.pl?Category=" . &url_encode($CategoryCode) . "&Genre=" . &url_encode($GenreName) . "&ViewCnt=1\">";
			print "<img src=\"../hot_img1/b_arrow.gif\" hspace=5 border=0 align=\"middle\">";
			print "<font size=\"-1\">$GenreName</font></a>\n";
			print "</td>\n";
		}
		$i++;
		
		# テーブルレコード終了
		if ( $i == 2 ) {
			$i = 0;
			print "</tr>\n";
		}
	}
}


__END__


