#!/usr/bin/perl
#*****************************************************************************************
#
#	■水戸証券CMS：アナリストメールページ
#
#	◇更新履歴
#		2006.03.17：新規作成
#
#	◇概要
#		アナリストメールページを表示します
#
#	◇注意事項
#		・Apache2 + mod_perl2(2.0.2) で動作します。
#		・startup.pl, Initialize.pm で共通モジュールをロードしています。
#		・HTMLタグのサニタイジングは HTML::Template を使用しているため、
#		　テンプレートファイル上で処理しています。ex) <tmpl_var name=hoge escape=html>
#
#	◇制作者
#		NEXIS Communications Corp.
#
#*****************************************************************************************





#*****************************************************************************************
#
#	■初期設定
#
#*****************************************************************************************

#=====================================================================
#	◇モジュール・ライブラリ
#=====================================================================
use strict;
use warnings FATAL => 'all', NONFATAL => 'uninitialized';
use Initialize;

#=====================================================================
#	◇変数定義
#=====================================================================
my $CGI            = '';
my $Template       = '';
my $DBH            = '';
my %SQL            = ();
my %Replace_String = ();
my @Analyst_Mail   = ();
my @Analyst_Mail_First = ();

#=====================================================================
#	◇初期化
#=====================================================================
$DBH = connect_db();
$CGI = new CGI;





#*****************************************************************************************
#
#	■情報取得・整理
#
#*****************************************************************************************
my( $sth, $rc, $info, $not_first ) = ();
$SQL{'select'} = <<EOS;
	SELECT
		*
	FROM
		analyst_mail
	ORDER BY
		date desc,
		create_time desc
EOS
$sth = $DBH->prepare( $SQL{'select'} );
$rc  = $sth->execute();
while( $info = $sth->fetchrow_hashref ) {
	$info->{'id'}   = $info->{'analyst_mail_id'};
	$info->{'date'} =~ s/\-/\//g;
	$info->{'date'} =~ s/\s.*$//g;
	$info->{'file_path'} = $Initialize::UPLOAD_DIR_PATH{'analyst_mail'}.'/'.$info->{'file'};
	if( $not_first ) {
		push( @Analyst_Mail, $info );
	} else {
		push( @Analyst_Mail_First, $info );
		$Replace_String{'analyst_mail_first'} = \@Analyst_Mail_First;
		$not_first = 1;
	}
}
$Replace_String{'analyst_mail'} = \@Analyst_Mail if( @Analyst_Mail );





#*****************************************************************************************
#
#	■画面表示
#
#*****************************************************************************************

#=====================================================================
#	◇テンプレート決定
#=====================================================================
$Template = get_template( $Initialize::DIR_DOCUMENT_ROOT.'/invest/weekly/cms_analyst_mail.html' );

#=====================================================================
#	◇テンプレート整形
#=====================================================================
for( keys %Replace_String ) {
	$Template->param( $_ => $Replace_String{$_} );
}

#=====================================================================
#	◇出力
#=====================================================================
$CGI->header(
	-pragma         => 'no-cache',
	-cache_control  => 'no-cache',
	-type           => 'text/html',
	-charset        => 'euc-jp',
	-content_length => length($Template->output),
);
print $Template->output;
$DBH->disconnect;
exit;
