#!/usr/bin/perl
#↑Perlのパスをサーバに合わせて記述して下さい。


#=============================================================================#
#
# ThemeMail実行ファイル
# (C) Apps Page.
#
#=============================================================================#



# ↓コントローラ
#-----------------------------------------------------------------------------#
package AppsPage::Tmmail::Controller;


#use strict;
my $this = new();
$this->start;
$this->stop;


sub new {
	require( 'ini.cgi' );
	my $this = new AppsPage::Tmmail::;
	return bless $this;
}


# →処理開始
sub start {
	my $this = shift;
	$this->{'input'}  = {};
	$this->{'cookie'} = {};
	$this->{'config'} = {};
	$this->{'recs'}   = [];
	$this->{'fields'} = {};
	
	
	#ライブラリ
	require( $this->{'LIB_DIR'}.'modus/OO.cgi' );
	require( $this->{'LIB_DIR'}.'modus/DfBase.cgi' );
	require( $this->{'LIB_DIR'}.'modus/DfConfigR.cgi' );
	require( $this->{'LIB_DIR'}.'modus/CGIFuncs.cgi' );
	require( $this->{'LIB_DIR'}.'modus/Filelock.cgi' );
	require( $this->{'LIB_DIR'}.'modus/Btemplatej.cgi' );
	
	
	#ファイルロックオブジェクト
	$this->{'lock'} = new
	AppsPage::Tmmail::Filelock::(
		$this->{'LOCK_METHOD'},
		$this->{'LOCK_DIR'},
		'flock',
		$this->{'LOCK_EX'},
		$this->{'LOCK_SH'},
		$this->{'LOCK_UN'}
	);
	
	
	#データファイルオブジェクト
	$this->{'data'} = new AppsPage::Tmmail::Datafile::(
		$this->{'DATA_DIR'},
		$this->{'TMP_DIR'},
		'.cgi',
		$this->{'SU_MODE'}
	);
	
	
	#CGI関係機能のオブジェクト
	$this->{'funcs'} = new AppsPage::Tmmail::CGIFuncs::;
	$this->{'funcs'}->setHeader(
		'Content-Type: text/html;accept-charset=Shift_JIS'
	);
	
	
	########## 区切 ##########
	
	
	#入力値解析
	$this->{'req_method'} =
	$this->{'funcs'}->parseInput2($this->{'input'});
	
	
	########## 区切 ##########
	
	#ステップ１（入力フォーム）
	if(
		$this->{'input'}->{'mode'} eq 'step1' ||
		$this->{'input'}->{'mode'} eq ''
	) {
		require( $this->{'LIB_DIR'}.'mode/m_step1.cgi' );
		$this->doStep1Mode;
	}
	
	#ステップ２（内容確認）
	elsif( $this->{'input'}->{'mode'} eq 'step2' ) {
		require( $this->{'LIB_DIR'}.'modus/DfSessionS.cgi' );
		require( $this->{'LIB_DIR'}.'mode/inputcheck.cgi' );
		require( $this->{'LIB_DIR'}.'mode/m_step2.cgi' );
		$this->doStep2Mode;
	}
	
	#ステップ３（メール送信/送信後の画面）
	elsif( $this->{'input'}->{'mode'} eq 'step3' ) {
		require( $this->{'LIB_DIR'}.'modus/DfBaseUpd.cgi' );
		require( $this->{'LIB_DIR'}.'modus/DfSessionS.cgi' );
		require( $this->{'LIB_DIR'}.'modus/DfSessionSCh.cgi' );
		require( $this->{'LIB_DIR'}.'modus/jcode.pl' );
		require( $this->{'LIB_DIR'}.'modus/JisMailUtil.pl');
		require( $this->{'LIB_DIR'}.'mode/inputcheck.cgi' );
		require( $this->{'LIB_DIR'}.'mode/m_step3.cgi' );
		$this->doStep3Mode;
	}
	
	#その他
	elsif( $this->{'input'}->{'mode'} eq 'pgname' ) {
		require( $this->{'LIB_DIR'}.'mode/m_pgname.cgi' );
		$this->doInputMode;
	}
	else {
		$this->error('Q');
	}
}




#=============================================================================#
#
# 区切
#
#=============================================================================#




# →終了
sub stop {
	my $this = shift;
	$this->{'lock'}->unlock;
	if($ENV{'MOD_PERL'}) { Apache::exit(0); }
	exit(0);
}


# →エラー
sub error {
	my $this = shift;
	require($this->{'LIB_DIR'}.'modus/MyErrMsgs.cgi');
	_import AppsPage::Tmmail::MyErrMsgs::;
	$this->{'data'}->settle;
	$this->{'lock'}->unlock;
	$this->{'funcs'}->sendHeader;
	my(@err) = @_;
	$this->outErrMsgs(\@err);
	$this->stop;
}




0;
