#!/usr/local/bin/perl -w use strict; use lib './modules'; use CGI::Carp qw(fatalsToBrowser); #use CGI::Upload; use CGI; use DBI qw(:sql_types); use HTML::Template; use Fcntl ":flock"; use Jcode; require './common/lib.pl'; require './config.pl'; #require './procedure.pl'; #require '../common/Debug.pl'; #Debug::Dbg_Init(1); #Debug::Dbg_print("======== 処理開始 ========\n"); #======================== メイン処理開始 ======================== my( $dbh, $sth ); my(@aCookiList, $cCkName, $cCkValue); my( $cCookie ) = ""; my( $cgi ) =new CGI; #---- デフォルトは認証画面表示 if( !defined($cgi->param('MODE')) || $cgi->param('MODE') eq "" ) { $cgi->param( MODE=>"CLICK"); } if( !defined($cgi->param('UMODE')) ) { $cgi->param( UMODE=>"GUEST"); } if( !defined($cgi->param('CNTS')) ) { $cgi->param( CNTS=>"ACCESS"); } # # DB接続処理 # $dbh = DBI->connect("DBI:mysql:affyne:localhost", "affyne", "uheel+zn"); if( !$dbh ) { print $cgi->header( -type => "text/html", -charset => "EUC-JP" ); Disp_Error("DBに接続できません: ".$DBI::errstr); } # # 処理モード判別 # if( $cgi->param('MODE') eq "CLICK" ) { $cCookie = Disp_Click( $cgi, $dbh ); Disp_Jump( $cgi, $cCookie ); } else { Disp_Completed( $cgi, $dbh ); } #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ # # Contents 判別 # #{ # if( $cgi->param('CNTS') eq "SINSA" ) { # require "./c_sinsa.pl"; # } elsif( $cgi->param('CNTS') eq "KEISAI" ) { # require "./c_keisai.pl"; # } elsif( $cgi->param('CNTS') eq "KOUKOKU" ) { # require "./c_koukoku.pl"; # } elsif( $cgi->param('CNTS') eq "REPORT" ) { # require "./c_report.pl"; # } elsif( $cgi->param('CNTS') eq "MIBARAI" ) { # require "./c_mibarai.pl"; ## } elsif( $cgi->param('CNTS') eq "MISEIKYU" ) { ## require "./c_miseikyu.pl"; # } elsif( $cgi->param('CNTS') eq "ACCESS" ) { # require "./c_access.pl"; # } #} # # 処理モード判別 # #SwitchMode( $cgi, $dbh ); #+++++++++++++++++++++++++++++++++++++++++++++++++++++++ if( defined($sth) ) { $sth->finish; } $dbh->disconnect; exit; #========================================================================= #------------------------------------------------------------------- # Disp_Click クリック時のアクセスログ書き込み処理 # # 引数 \$cgi (I) パラメータ # $dbh (I) データベースハンドル # 戻値 なし #------------------------------------------------------------------- sub Disp_Click { my( $cgi, $dbh ) = @_; my( $cCookie ); my( @aCookiList, $cCkName, $cCkValue ); my( $cSql, $cID, $iCnt ); # # すでに同じ掲載者でクッキーが設定されている場合は、処理をしない # $cCookie = $cgi->cookie(Get_Configuration('CookieIDClick')); if( defined($cCookie) ) { @aCookiList = split(/\|\|\|/, $cCookie); foreach(@aCookiList) { ($cCkName, $cCkValue) = split(/=/); if( $cCkName eq "EID" ) { if( $cCkValue eq $cgi->param('EID') ) { return(""); } } } } # # クッキー設定 # $cID = Make_RandStr_Unique( $dbh, "ACCESSLOG_TBL", 8, "COMP" ); $cCookie = $cgi->cookie(-name=>Get_Configuration('CookieIDClick') ,-value=>"ID=".$cID."\|\|\|"."EID=".$cgi->param('EID')."\|\|\|"."OID=".$cgi->param('OID') ,-expires=>"+6h" ); # # アクセスログ書き込み # $cSql = "INSERT INTO ACCESSLOG_TBL"; $cSql .= " ( ID, CLICKDATE, KEISAIID, KOUKOKUID )"; $cSql .= " VALUES ( '".$cID."', NOW(), '".$cgi->param('EID')."', '".$cgi->param('OID')."')"; $iCnt = $dbh->do($cSql) || Disp_Error("SQL文が実行できませんでした:
\n[".$cSql."]
".$dbh->errstr); return($cCookie); } #------------------------------------------------------------------- # Disp_Jump 広告主サイト表示 # # 引数 $cgi (I) パラメータ # $cCookie (I) クッキー # 戻値 なし #------------------------------------------------------------------- sub Disp_Jump { my( $cgi, $cCookie ) = @_; my( $cTmplFileName ); my( $cKey ); my( $oTmpl ); #---------------------------- # テンプレート処理 #---------------------------- $cTmplFileName = Get_TmplFilePath( "R_JUMP" ); if( $cTmplFileName eq "" ) { Disp_Error("テンプレートファイル名が取得できませんでした"); } if( !-e "$cTmplFileName" ) { Disp_Error("テンプレートファイルが存在しません[$cTmplFileName]"); } $oTmpl = new HTML::Template( filename => $cTmplFileName ); if( $oTmpl->query( name =>'SITE') ) { $oTmpl->param( SITE => $cgi->param('SITE') ); } #---------------------------- # 画面表示 #---------------------------- if( $cCookie ne "" ) { print $cgi->header( -type => "text/html", -charset => "EUC-JP", -cookie => $cCookie ); } else { print $cgi->header( -type => "text/html", -charset => "EUC-JP" ); } print $oTmpl->output; } #------------------------------------------------------------------- # Disp_Completed オーダー完了ログ書き込み処理 # # 引数 \$cgi (I) パラメータ # $dbh (I) データベースハンドル # 戻値 なし #------------------------------------------------------------------- sub Disp_Completed { my( $cgi, $dbh ) = @_; my( $cCookie, @aCookiList, $cCkName, $cCkValue ); my( $cSql, $sth, $cID, $iCnt ); my( $cSuccess ); $cCookie = $cgi->cookie(Get_Configuration('CookieIDClick')); if( defined($cCookie) ) { @aCookiList = split(/\|\|\|/, $cCookie); foreach(@aCookiList) { ($cCkName, $cCkValue) = split(/=/); $cgi->param( $cCkName => $cCkValue ); } # # 成功判定種別 # $cSql = "SELECT SUCCESS FROM KOUKOKU_TBL WHERE ID='".$cgi->param('OID')."'"; $sth = $dbh->prepare($cSql); if (!$sth->execute) { Disp_Error("SQL文が実行できませんでした:
\n[".$cSql."]
".$dbh->errstr); } $sth->bind_columns(\($cSuccess)); $sth->fetch; # # アクセスログ書き込み # if( $cSuccess eq "1" ) { # 申込みベース $cSql = "UPDATE ACCESSLOG_TBL"; $cSql .= " SET SUCCESSDATE = NOW()"; $cSql .= " WHERE ID = '".$cgi->param('ID')."'"; } else { # 入金みベース $cSql = "UPDATE ACCESSLOG_TBL"; $cSql .= " SET ORDERDATE = NOW()"; $cSql .= " WHERE ID = '".$cgi->param('ID')."'"; } $iCnt = $dbh->do($cSql) || Disp_Error("SQL文が実行できませんでした:
\n[".$cSql."]
".$dbh->errstr); } my( $giffile, $size, $buf ); $giffile = "img/spacer.gif"; printf("Content-type: image/gif\n\n"); $size = -s $giffile; open(IN, $giffile); binmode(IN); binmode(STDOUT); read(IN, $buf, $size); print $buf; close(IN); } #========================================================================= ;#------------------------------------------------------------------- ;# Disp_Error エラー表示 ;# ;# 引数 @tMsg (I) エラーメッセージlist ;# (最後の値) (I) ナビゲーションボタン定義 ;# "BAK":「戻る」 << default ;# "CLS":「閉じる」 ;# ;# 戻値 なし ;#------------------------------------------------------------------- sub Disp_Error { my( @tMsg ) = @_; my( $cTmplFileName ); my( $oTmpl, @aTLoop ); #---------------------------- # テンプレート処理 #---------------------------- $cTmplFileName = Get_TmplFilePath( "LT_ERRORMSG" ); if( $cTmplFileName eq "" ) { die("Could not get TemplateFileName."); } $oTmpl = new HTML::Template( filename => $cTmplFileName ); #---- ベース部分 ---- my($SiteTitle) = Get_Configuration("SiteTitle"); my($Copyright) = Get_Configuration("Copyright"); my($CssPath) = Get_Configuration("CssPath"); my($JsPath) = Get_Configuration("JsPath"); if( $oTmpl->query( name =>'SiteTitle') ) { $oTmpl->param( SiteTitle => $SiteTitle ); } if( $oTmpl->query( name =>'Copyright') ) { $oTmpl->param( Copyright => $Copyright ); } if( $oTmpl->query( name =>'Script') ) { $oTmpl->param( Script => $cgi->script_name );} if( $oTmpl->query( name =>'CSSPath') ) { $oTmpl->param( CSSPath => $CssPath );} if( $oTmpl->query( name =>'JsPath') ) { $oTmpl->param( JsPath => $JsPath );} #---- リスト部分 ---- foreach (@tMsg) { my( %hLTmpl ) = ( ErrorMsg => $_ ); push( @aTLoop, \%hLTmpl ); } $oTmpl->param( ErrorMessageList => \@aTLoop ); #---------------------------- # 画面表示 #---------------------------- # print "Content-type: text/html; charset=EUC-JP\n\n"; if( $cCookie ne "" ) { print $cgi->header( -type => "text/html", -charset => "EUC-JP", -cookie => $cCookie ); } else { print $cgi->header( -type => "text/html", -charset => "EUC-JP" ); } print $oTmpl->output; if( defined($sth) ) { $sth->finish; } $dbh->disconnect; exit; } #=========================================================================