%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/rappan/www/cgi_hicnt200/
Upload File :
Create Path :
Current File : //home/rappan/www/cgi_hicnt200/hicnt.cgi

#!/usr/bin/perl
#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃HiCnt Ver 2.00                                                            ┃
#┃多機能アクセスカウンタスクリプト                                          ┃
#┃Copyright(C) 2003-2006 ミリオンシステム All Rights Reserved.              ┃
#┃   Web: http://www.e-hws.net/                                             ┃
#┃---[注意事項]-------------------------------------------------------------┃
#┃このスクリプトはフリーソフトです。このスクリプトを使用したいかなる損害に  ┃
#┃対して作者は一切の責任を負いません。                                      ┃
#┃--------------------------------------------------------------------------┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
# バージョン
$ver = "2.00";

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃<変更履歴>                                                                ┃
#┃ -Date-	-Ver-	-Comment-                                            ┃
#┃--------------------------------------------------------------------------┃
#┃2006.08.21	2.00	全面改良                                             ┃
#┃			メール通知機能追加                                   ┃
#┃			バックアップ機能追加                                 ┃
#┃2005.06.14	1.21	ブラウザ「Firefox」対応                              ┃
#┃2004.09.08	1.20	ファイルロック処理改善(hilib.pl)                     ┃
#┃2004.05.24	1.19	テキストカウンタが表示されない場合があるのを修正     ┃
#┃2004.04.26	1.18	不正なカウンタデータでも処理できるように修正         ┃
#┃			管理画面レイアウト変更                               ┃
#┃2004.04.07	1.17	ブラウザを閉じるまでカウントアップしない設定追加     ┃
#┃			テキスト表示機能追加                                 ┃
#┃2004.04.06	1.16	アクセス解析データを指定した日数経過するとクリアする ┃
#┃2004.04.05	1.15	アクセスユーザ画面でPID毎に表示できるようにした      ┃
#┃			アクセスユーザ情報ログ削除ボタンを追加               ┃
#┃2004.04.02	1.14	管理画面入室方法改良                                 ┃
#┃2004.03.26	1.13	FTPでカウンタデータファイルのみ削除した場合のバグ修正┃
#┃2003.11.04	1.12	データ編集すると2重フレームになってしまうのを修正    ┃
#┃2003.10.20	1.11	管理画面をフレーム化した                             ┃
#┃			アクセスログ/ユーザ/解析画面表示時にrefererをチェック┃
#┃2003.09.27	1.10	アクセスユーザログとアクセス解析のreferer値を統一    ┃
#┃			リンク元の表示を80文字以上は省略して表示する         ┃
#┃2003.09.25	1.09	リンク元除外URLを指定できるようにした                ┃
#┃			アクセス解析にてブラウザの種類の解析を追加           ┃
#┃			アクセス解析画面で各解析へのリンク追加               ┃
#┃			アクセスユーザログ取得行数を指定できるように修正     ┃
#┃			アクセスユーザ画面でリンク元にリンクを貼るように修正 ┃
#┃			リンク元が途中で切れる場合があるのを修正             ┃
#┃2003.09.17	1.08	アクセス解析のリンク元を正しく取得できるように修正   ┃
#┃2003.08.20	1.07	アクセスがない日のカウンタを0にするように修正        ┃
#┃2003.07.25	1.06	カウントアップ判定処理のバグ修正                     ┃
#┃2003.07.08	1.05	データ編集時のバグ修正                               ┃
#┃			管理画面のレイアウトを少し変更                       ┃
#┃2003.03.20	1.04	少しだけ性能改善                                     ┃
#┃			管理画面にてカウンタ値編集での不具合を修正           ┃
#┃2003.03.10	1.03	アクセス解析にてアクセス割合を表示させた             ┃
#┃2003.03.04	1.02	アクセス解析にてOS種別取得処理を改善                 ┃
#┃			アクセス解析のみの場合、ダミー画像を表示させる       ┃
#┃			カウントアップ種別=2のときの判定処理改良             ┃
#┃2003.02.26	1.01	アクセス解析データクリア処理追加                     ┃
#┃			アクセス解析PIDごとに表示できるように修正            ┃
#┃2003.02.17	1.00	ローカル公開                                         ┃
#┃2003.11.10	0.00	新規作成                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃<設置例>                                                                  ┃
#┃※カウンタを表示したい個所に貼り付けてください。                          ┃
#┃  hicnt.cgiへのパスは各自設置状況に応じて、正確に合わせてください。       ┃
#┠─────────────────────────────────────┨
#┃■総計カウンタを表示する(アクセス解析なし)                                ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=main&img=0&len=6" border="0"></a>           ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■総計カウンタを表示する(アクセス解析あり)                                ┃
#┃<script type="text/javascript">                                           ┃
#┃<!--                                                                      ┃
#┃document.write("<a href='http://www.e-hws.net/' target=_blank>");         ┃
#┃document.write("<img src='hicnt/hicnt.cgi?pid=main&img=0&len=6");         ┃
#┃document.write("&ref=" + document.referrer + "' border='0'></a>");        ┃
#┃// -->                                                                    ┃
#┃</script>                                                                 ┃
#┃<noscript>                                                                ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=main&img=0&len=6" border="0"></a>           ┃
#┃</noscript>                                                               ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■今日のカウンタを表示する                                                ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=main&img=0&len=3&typ=tday" border="0"></a>  ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■昨日のカウンタを表示する                                                ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=main&img=0&len=3&typ=yday" border="0"></a>  ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■リンクをクリックした回数をカウントする                                  ┃
#┃対象のリンクを下記のように指定してください。                              ┃
#┃<a href="hicnt/hicnt.cgi?pid=clk&img=0&len=3&url=http://aaa.com/xxx.jpg"> ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■リンクをクリックした回数を表示する                                      ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=click&img=0&len=3&typ=clk" border="0"></a>  ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■アクセス解析のみ行う場合                                                ┃
#┃カウントアップは行いますが、カウンタ表示はしません。                      ┃
#┃<script type="text/javascript">                                           ┃
#┃<!--                                                                      ┃
#┃document.write("<a href='http://www.e-hws.net/' target=_blank>");         ┃
#┃document.write("<img src='hicnt/hicnt.cgi?pid=main&typ=ana");             ┃
#┃document.write("&ref=" + document.referrer + "' border='0'></a>");        ┃
#┃// -->                                                                    ┃
#┃</script>                                                                 ┃
#┃<noscript>                                                                ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<img src="hicnt/hicnt.cgi?pid=main&typ=ana" border="0"></a>;              ┃
#┃</noscript>                                                               ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■カウンタをテキスト表示する                                              ┃
#┃SSIを使ってテキスト表示します。                                           ┃
#┃テキスト表示する場合はサーバ環境によってパラメータ指定はできない時がありま┃
#┃す。 その場合はconfig.cgiにてデフォルト値設定により指定してください。     ┃
#┃【※注意※】                                                              ┃
#┃テキスト表示の場合は「ブラウザを閉じるまでカウントしない」は機能しません。┃
#┃常にカウントさせるか、カウント無効時間指定でお願いします。                ┃
#┃                                                                          ┃
#┃<SSIでパラメータ指定できるサーバの場合>                                   ┃
#┃・総カウンタ表示                                                          ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<!--#exec cmd="./hicnt/hicnt.cgi pid=main img=txt len=6"--></a>           ┃
#┃・今日のカウンタ表示                                                      ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<!--#exec cmd="./hicnt/hicnt.cgi pid=main img=txt len=6 typ=tday"--></a>  ┃
#┃・昨日のカウンタ表示                                                      ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<!--#exec cmd="./hicnt/hicnt.cgi pid=main img=txt len=6 typ=yday"--></a>  ┃
#┃                                                                          ┃
#┃<SSIでパラメータ指定できないサーバの場合>                                 ┃
#┃config.cgiにてデフォルト値設定により指定してください。                    ┃
#┃ $pid_default = "main";                                                   ┃
#┃ $img_default = "txt";                                                    ┃
#┃ $len_default = "6";                                                      ┃
#┃この場合、パラメータ指定による複数PID設置はできず、今日昨日カウンタ表示も ┃
#┃できません。                                                              ┃
#┃<a href="http://www.e-hws.net/" target=_blank>                            ┃
#┃<!--#exec cmd="./hicnt/hicnt.cgi"--></a>                                  ┃
#┃                                                                          ┃
#┠─────────────────────────────────────┨
#┃■管理画面入室方法                                                        ┃
#┃http://www.xxx.com/hicnt/hicnt.cgi?mode=login                             ┃
#┃                                                                          ┃
#┃直接入室する方法は                                                        ┃
#┃http://www.xxx.com/hicnt/hicnt.cgi?mode=admin&pass=管理パスワード         ┃
#┃                                                                          ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
require "./jcode.pl" ;
require "./hilib.pl" ;
require "./hilib_mob.pl" ;
require "./gifcat.pl";
require "./config.cgi" ;
use File::Copy;
use CGI::Carp qw(fatalsToBrowser);

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃メイン分岐処理                                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
&decode;			# デコード処理
$mode    = $FORM{'mode'};	# 動作モード

#--- バックアップ -------------------------------------------------------------
if( $bkupflg ){
	# バックアップ実行
	&bkup;
}

#--- ログクリア ---------------------------------------------------------------
&clear_log;

#--- 分岐 ---------------------------------------------------------------------
if( $mode eq "login" ){		&login;		}	# ログイン画面
if( $mode eq "admin" ){		&admin;		}	# 管理画面トップ
if( $mode eq "adm_menu" ){	&adm_menu;	}	# 管理メニュー画面
if( $mode eq "adm_exe" ){	&adm_exe;	}	# 実行画面
if( $mode eq "adm_edit_pid" ){	&adm_edit_pid;	}	# PID編集画面
if( $mode eq "pid_write" ){	&pid_write;	}	# PIDデータ書き込み
if( $mode eq "mov_write" ){	&mov_write;	}	# PIDデータ移動書き込み
if( $mode eq "adm_edit_cnt" ){	&adm_edit_cnt;	}	# カウンタ編集画面
if( $mode eq "cnt_write" ){	&cnt_write;	}	# カウンタデータ書き込み
if( $mode eq "adm_log_cnt" ){	&adm_log_cnt;	}	# 日別アクセス数
if( $mode eq "adm_log_user" ){	&adm_log_user;	}	# アクセスユーザログ
if( $mode eq "adm_log_srch" ){	&adm_log_srch;	}	# アクセスユーザ検索
if( $mode eq "adm_ana_hour" ){	&adm_ana_hour;	}	# 時間別アクセス解析画面
if( $mode eq "adm_ana_day" ){	&adm_ana_day;	}	# 曜日別アクセス解析画面
if( $mode eq "adm_ana_host" ){	&adm_ana_host;	}	# ホスト別アクセス解析画面
if( $mode eq "adm_ana_ref" ){	&adm_ana_ref;	}	# リンク元別アクセス解析画面
if( $mode eq "adm_ana_os" ){	&adm_ana_os;	}	# OS別アクセス解析画面
if( $mode eq "adm_ana_brows" ){	&adm_ana_brows;	}	# ブラウザ別アクセス解析画面
if( $mode eq "adm_ana_clr" ){	&adm_ana_clr;	}	# データクリア画面
if( $mode eq "ver" ){					# バージョン表示
	&disp_html("HiCnt Ver $ver (C)<a href=\"http://www.e-hws.net/\" target=_blank>million system</a>");
}

# カウンタメイン処理
&main;
exit;

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃メイン分岐処理                                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub main{
#--- パラメータ設定 -----------------------------------------------------------
	$pid	= $FORM{'pid'};				# PID
	$img	= $FORM{'img'};				# カウンタ画像番号
	$len	= $FORM{'len'};				# カウンタ桁数
	$typ	= $FORM{'typ'};				# 表示タイプ
	$url	= $FORM{'url'};				# クリックカウンタ時のジャンプURL
	$ref	= $FORM{'ref'};				# リンク元
	# リンク元が設定されていない場合は環境変数から取得
	if( $ref eq "" ){
		$ref = $ENV{'HTTP_REFERER'};
	}
	$ref	= &url_decode($ref);			# URLデコード
	$ip	= $ENV{'REMOTE_ADDR'};			# IPアドレス

	# OS、ブラウザ取得
	$user_agent = $ENV{'HTTP_USER_AGENT'};
	if( $user_agent eq "" ){
		$os = "Unknown";
		$br = "Unknown";
	}else{
		($type,$os,$os_ver,$br,$br_ver) = &get_osinf( $user_agent );
		if( $os_ver ne "" ){
			$os = "$os $os_ver";
		}
		if( $br_ver ne "" ){
			$br = "$br $br_ver";
		}
	}

#--- デフォルト値設定 ---------------------------------------------------------
	if( $pid eq "" ){		$pid = $pid_default;}
	if( $img eq "" ){		$img = $img_default;}
	if( $len eq "" ){		$len = $len_default;}

	$now_ymd = &gettime(4);		# 時刻取得

	# ファイル名取得
	$imgpath    = "${imgdir}/img$img";			# カウンタ画像パス
	$totalf     = "${datdir}/${pid}_total_cnt.cgi";		# 総カウンタデータ
	$countf     = "${datdir}/${pid}_${now_ymd}_cnt.cgi";	# 日別カウンタデータ
	$acslog     = "${datdir}/${pid}_log.cgi";		# アクセス履歴ログ

	# 今日のカウント表示
	if( $typ eq "tday" ){
		&cnt_disp(&get_count($pid,$now_ymd));
		exit ;

	# 昨日のカウント表示
	}elsif( $typ eq "yday" ){
		&cnt_disp(&get_count($pid,&get_predate($now_ymd)));
		exit ;

	# クリックカウント表示
	}elsif( $typ eq "clk" ){
		&cnt_disp(&get_pid_count($pid));
		exit;
	}

	# 同時アクセス防止ロック
	&lock($countf);

	# PID存在チェック
	$flg = 0;
	open(PID, $pidfile);
	@piddat = <PID>;
	close(PID);
	foreach(@piddat){
		($wpid) = (split(/<>/, $_))[0];
		if( $pid eq $wpid ){
			$flg = 1;
			last;
		}
	}

	# 新規PIDならPIDデータを追加
	if( $flg == 0 ){
		&lock($pidfile);
		open(PID, ">> $pidfile");
		print PID "$pid<><><>\n";
		close(PID);
		&unlock($pidfile);
	}

	#--------------------------------------
	# カウンタ値取得
	#--------------------------------------
	# 総カウンタファイルデータ取得
	$totalcnt = &get_pid_count($pid);

	# 日別カウンタファイルデータ取得
	$cnt = &get_count($pid,$now_ymd);

	#--------------------------------------
	# メール送信
	#--------------------------------------
	if( $sendflg ){
		# メール送信実行
		&mail;
	}

	#--------------------------------------
	# アクセス解析
	#--------------------------------------
	foreach(@ana_id){
		if( $pid eq $_ ){
			&analyze($pid,$ref,$os,$br);
			last;
		}
	}

	# 常にカウント
	if( $cntup_type == 0 ){
		$cntup_flg = 1;

	# ブラウザを閉じるまでカウントしない
	}elsif( $cntup_type == 1 ){
		# テキスト表示の場合はカウントする
		if( $img ne "txt" ){
			($cntup_flg) = (split(/<>/, &get_cookie("hicntflg")))[0];
			if( $cntup_flg ne "0" ){
				$cntup_flg = 1;
			}
		}else{
			$cntup_flg = 1;
		}

	# 指定時間経過後カウント
	}else{
		$cntup_flg = &chk_cntup($pid,$ip);
	}

	# カウントアップ実行か?
	if( $cntup_flg ){
		# テキスト表示以外はカウントアップ済みフラグをセット
		if( $img ne "txt" ){
			&set_cookie("hicntflg",0,"0<>chdend");
		}

		# カウントアップ
		$totalcnt ++;
		$cnt ++;

		# 日別カウンタデータ更新
		open(OUT, "> $countf");
		print OUT "$cnt<><><>\n";
		close(OUT);

		# 総カウンタデータ更新
		open(OUT, "> $totalf");
		print OUT "$totalcnt<><><>\n";
		close(OUT);

		# ユーザ情報取得
		&get_usrinf($pid,$totalcnt,$now_ymd,$ref,$os,$br);
	}

	# ロックファイルを削除する
	&unlock($countf);

	#--------------------------------------
	# カウンタ表示
	#--------------------------------------
	if( $typ eq "ana" ){
		&ana_disp;
	}else{
		if( $url eq "" ){
			&cnt_disp($totalcnt) ;
		}else{
			&disp_page($url);
		}
	}

	exit;

}# main END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃管理画面ログイン画面表示処理                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub login{

	$html = <<_HTML_;
<html><head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<title>HiCnt管理画面ログイン</title>
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666">
<center>
<br>
<form action="$script" method="$method">
<input type="hidden" name="mode" value="admin">
<table border="0" bgcolor="#e6ffe6" width="300">
	<tr bgcolor="#ccffcc" align="center">
		<td nowrap>
			:::  HiCnt管理画面ログイン  :::
		</td>
	</tr>
	<tr>
		<td nowrap align="center" height="50">
			Password:<input type="password" name="pass"> <input type="submit" value="Login">
		</td>
	</tr>
</table>
</form>

<!-- 著作権表示は消さないで!! -->
<br>
<br>
<hr size="1" width="100%">
HiCnt Ver $ver (C)<a href="http://www.e-hws.net/" target=_blank>million system</a></font><br>
<!-- 著作権表示は消さないで!! -->

</center>
</BODY>
</html>
_HTML_

	&disp_html($html);

	exit;

}# login END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃管理画面処理                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub admin{

	$pass = $FORM{'pass'};

	# パスワードが設定されていない場合は入室画面を表示
	if( $pass eq "" ){
		($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];
		if( $pass eq "" ){
			&disp_page("$script?mode=login");
		}
	}else{
		&set_cookie("hicnt_pass",0,"$pass<>chdend");
		&disp_page("$script?mode=admin");
	}

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<STYLE type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</STYLE>
</head>
<title>HiCnt管理画面</title>
<frameset cols="135,*" border="0">
	<frame src="$script?mode=adm_menu" name="menu">
	<frame src="$script?mode=adm_log_cnt" name="exe">
</frameset>
<noframes>
<body>
<center>
<font color="red">フレーム対応のブラウザでご使用ください。</font>
</center>
</body>
</noframes>
</html>
_HTML_

	&disp_html($html);

	exit;

}# admin END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃管理メニュー画面処理                                    ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_menu{

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<center><font color="chocolate"><b>【HiCnt管理画面】</b></font></center>
<hr size="1">
<center>【− MENU −】</center>
<p>
▼アクセス状況<br>
 <font size="-1">・<a href="$script?mode=adm_log_cnt" target="exe">日別アクセス数</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_log_user" target="exe">アクセスユーザログ</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_log_srch" target="exe">アクセスユーザ検索</a></font><br>
</p>

<p>
▼アクセス解析<br>
 <font size="-1">・<a href="$script?mode=adm_ana_hour" target="exe">時間別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_day" target="exe">曜日別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_host" target="exe">ホスト別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_ref" target="exe">リンク元別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_os" target="exe">OS別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_brows" target="exe">ブラウザ別</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_ana_clr" target="exe">データクリア</a></font><br>
</p>

<p>
▼データ編集<br>
 <font size="-1">・<a href="$script?mode=adm_edit_pid" target="exe">PID編集</a></font><br>
 <font size="-1">・<a href="$script?mode=adm_edit_cnt" target="exe">カウンタ編集</a></font><br>
</p>

<br><br><br><br><br><br>
<hr size="1">
<center>
HiCnt Ver $ver<br>
(C)<a href="http://www.e-hws.net/" target=_blank>million system</a>
</center>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_menu END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃PID編集画面処理                                         ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_edit_pid{
	$act		= $FORM{'act'};			# 動作種別("edt","del","add","up","dw")

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	if( $act eq "edt" ){
		$msg = '<font color=red>*編集しました。</font>';
	}elsif( $act eq "del" ){
		$msg = '<font color=red>*削除しました。</font>';
	}elsif( $act eq "add" ){
		$msg = '<font color=red>*追加しました。</font>';
	}elsif( $act eq "up" ){
		$msg = '<font color=red>*上に移動しました。</font>';
	}elsif( $act eq "dw" ){
		$msg = '<font color=red>*下に移動しました。</font>';
	}

	# PIDファイル
	open(PID, $pidfile);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<font size="+1" color="chocolate"><b>■PIDファイルの編集</b></font><br>
PID名の編集、表\示順の変更、PIDの追加を行うことができます。<br>
PIDは変更できません。<br>
またPIDデータを削除してもカウンタデータやアクセス解析データは削除されません。<br>
(再度同じPIDを追加すれば復活します)<br><br>
$msg
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000">
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">PID</font></td>
	<td align="center"><font color="#ffffff">PID名</font></td>
	<td align="center"><font color="#ffffff">移動</font></td>
	<td align="center" colspan="2"><font color="#ffffff">実行</font></td>
</tr>
_HTML_

	# PID分ループ
	$no = 0;
	foreach(<PID>){
		($pid,$pidname) = (split(/<>/, $_))[0,1];
		$html .= <<_HTML_;
<tr bgcolor="#ffffff">
	<form action="$script" method="$method" target=_self>
	<input type="hidden" name="mode" value="pid_write">
	<input type="hidden" name="act" value="edt">
	<input type="hidden" name="no" value="$no">
	<input type="hidden" name="pid" value="$pid">
	<td>$pid</td>
	<td><input type="text" name="pidname" size="30" value="$pidname"></td>
	<td><a href="$script?mode=mov_write&no=$no&act=up">▲</a> <a href="$script?mode=mov_write&no=$no&act=dw">▼</a></td>
	<td>
		<input type="submit" value="編集">
	</td>
	</form>
	<form action="$script" method="$method" target=_self>
	<input type="hidden" name="mode" value="pid_write">
	<input type="hidden" name="act" value="del">
	<input type="hidden" name="pid" value="$pid">
	<input type="hidden" name="no" value="$no">
	<td>
		<input type="submit" value="削除" onclick="return window.confirm('PID:$pidを削除してよろしいですか?')">
	</td>
	</form>
</tr>
_HTML_
		$no ++;
	}
	close(PID);

	$html .= <<_HTML_;
<tr bgcolor="#ffffff">
	<form action="$script" method="$method" target=_self>
	<input type="hidden" name="mode" value="pid_write">
	<input type="hidden" name="act" value="add">
	<td><input type="text" name="pid" size="10"></td>
	<td><input type="text" name="pidname" size="30"></td>
	<td></td>
	<td colspan="2" align="center">
		<input type="submit" value="追加">
	</td>
	</form>
</tr>
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_edit_pid END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃PIDデータ書き込み処理                                   ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub pid_write{
	$act		= $FORM{'act'};			# 動作種別("edt","del","add")
	$no		= $FORM{'no'};			# データ番号
	$pid		= $FORM{'pid'};			# PID
	$pidname	= $FORM{'pidname'};		# PID名

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	if( $pid eq "" ){
		&errhtml("PIDを入力してください。");
	}
	if( $pid !~ /[a-zA-Z0-9_-]/ ){
		&errhtml("PIDは半角英数字で入力してください。");
	}

	&lock($pidfile);

	# PIDファイル
	open(PID, $pidfile);

	$cnt = 0;
	foreach(<PID>){
		($wpid,$wpidname) = (split(/<>/, $_))[0,1];

		if( $act eq "edt" ){
			if( $cnt == $no ){
				push(@pid_data, "$wpid<>$pidname<>\n");
			}else{
				push(@pid_data, $_);
			}

		}elsif( $act eq "del" ){
			if( $cnt == $no ){
			}else{
				push(@pid_data, $_);
			}
		}else{
			if( $pid eq $wpid ){
				&unlock($pidfile);
				&errhtml("同じPIDは追加できません。");
			}
			push(@pid_data, $_);
		}

		$cnt ++;
	}
	close(PID);

	if( $act eq "add" ){
		push(@pid_data, "$pid<>$pidname<>\n");
	}

	# データ書き込み
	open(OUT, "> $pidfile");
	print OUT @pid_data;
	close(OUT);

	&unlock($pidfile);

	&disp_page("$script?mode=adm_edit_pid&act=$act");

	exit;

}# pid_write END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃PIDデータ移動書き込み処理                               ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub mov_write{
	$no		= $FORM{'no'};			# データ番号
	$act		= $FORM{'act'};			# 動作種別("up","dw")

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	&lock($pidfile);

	# PIDファイル
	open(PID, $pidfile);
	@pid_data = <PID>;
	close(PID);

	$data_cnt = @pid_data;

	if( $act eq "up" && $no ne "0" ){
		$tmp = $pid_data[$no-1];
		$pid_data[$no-1] = $pid_data[$no];
		$pid_data[$no] = $tmp;
	}elsif( $act eq "dw" && $no != $data_cnt - 1 ){
		$tmp = $pid_data[$no+1];
		$pid_data[$no+1] = $pid_data[$no];
		$pid_data[$no] = $tmp;
	}else{
		undef($act);
	}

	# データ書き込み
	open(OUT, "> $pidfile");
	print OUT @pid_data;
	close(OUT);

	&unlock($pidfile);

	&disp_page("$script?mode=adm_edit_pid&act=$act");

	exit;

}# mov_write END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃カウンタ編集画面処理                                    ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_edit_cnt{
	$act		= $FORM{'act'};			# 動作種別("1")

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	if( $act ){
		$msg = '<font color=red>*編集しました。</font>';
	}

	# PIDファイル
	open(PID, $pidfile);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<font size="+1" color="chocolate"><b>■カウンタ値の編集</b></font><br>
指定のPIDに対して総カウンタ値の編集を行うことができます。<br>
<input type="button" value="最新の状態に更新" onclick="location='$script?mode=adm_edit_cnt'"><br><br>
$msg
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000">
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">PID</font></td>
	<td align="center"><font color="#ffffff">PID名</font></td>
	<td align="center"><font color="#ffffff">カウンタ値</font></td>
	<td align="center"><font color="#ffffff">編集</font></td>
</tr>
_HTML_

	# PID分ループ
	foreach(<PID>){
		($pid,$pidname) = (split(/<>/, $_))[0,1];

		# カウンタ値取得
		$count = &get_pid_count($pid);

		$html .= <<_HTML_;
<tr bgcolor="#ffffff">
	<form action="$script" method="$method" target=_self>
	<input type="hidden" name="mode" value="cnt_write">
	<input type="hidden" name="pid" value="$pid">
	<td nowrap>$pid</td>
	<td nowrap>$pidname</td>
	<td nowrap><input type="text" name="count" value="$count" size="10"></td>
	<td>
		<input type="submit" value="編集">
	</td>
	</form>
</tr>
_HTML_
	}
	close(PID);

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_edit_cnt END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃カウンタデータ書き込み処理                              ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub cnt_write{
	$pid		= $FORM{'pid'};			# PID
	$count		= $FORM{'count'};		# カウンタ値

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	$cntf = "$datdir/${pid}_total_cnt.cgi";

	&lock($cntf);

	# カウンタファイル
	open(CNT, "> $cntf");
	print CNT "$count<>\n";
	close(CNT);

	&unlock($cntf);

	&disp_page("$script?mode=adm_edit_cnt&act=1");

	exit;

}# cnt_write END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃時間別アクセス解析画面処理                              ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_hour{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_hour.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
	}
	seek(ANA, 0, 0);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■時間別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center" width="50"><font color="#ffffff">時間</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	for($i = 0; $i < 24; $i ++){
		$hourstr = sprintf("%02d", $i);
		$find = 0;
		foreach(<ANA>){
			($wid, $wcnt) = (split(/<>/, $_))[0,1];
			if( $wid eq $hourstr ){
				$find = 1;
				$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
				$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

				$html .= <<_HTML_;
					<tr bgcolor="#ffffff">
						<td nowrap align="center">$hourstr時</td>
						<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
					</tr>
_HTML_
			}
		}
		seek(ANA,0,0);
		if( $find == 0 ){
				$html .= <<_HTML_;
					<tr bgcolor="#ffffff">
						<td nowrap align="center">$hourstr時</td>
						<td nowrap><img src="$ana_barimg" border="0" width="0" height="10">\t0(0.0%)</td>
					</tr>
_HTML_
		}
	}
	close(ANA);

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_hour END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃曜日別アクセス解析画面処理                              ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_day{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_day.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
	}
	seek(ANA, 0, 0);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	# 曜日リスト
	@youbi = ('日曜日','月曜日','火曜日','水曜日','木曜日','金曜日','土曜日');

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■曜日別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center" width="50"><font color="#ffffff">曜日</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	for($i = 0; $i < 7; $i ++){
		$youbistr = $youbi[$i];
		$find = 0;
		foreach(<ANA>){
			($wid, $wcnt) = (split(/<>/, $_))[0,1];
			if( $wid eq $youbistr ){
				$find = 1;
				$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
				$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

				$html .= <<_HTML_;
					<tr bgcolor="#ffffff">
						<td nowrap align="center">$youbistr</td>
						<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
					</tr>
_HTML_
			}
		}
		seek(ANA,0,0);
		if( $find == 0 ){
				$html .= <<_HTML_;
					<tr bgcolor="#ffffff">
						<td nowrap align="center">$youbistr</td>
						<td nowrap><img src="$ana_barimg" border="0" width="0" height="10">\t0(0.0%)</td>
					</tr>
_HTML_
		}
	}
	close(ANA);

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_day END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃ホスト別アクセス解析画面処理                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_host{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_host.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
		push(@ana_data, $_);
	}
	close(ANA);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■ホスト別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">ホスト</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	# アクセス数でソート
	@ana_data = &ana_sort(@ana_data);

	foreach(@ana_data){
		($wid, $wcnt) = (split(/<>/, $_))[0,1];
		$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
		$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

		$html .= <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap>$wid</td>
				<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
			</tr>
_HTML_
	}

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_host END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃リンク元別アクセス解析画面処理                          ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_ref{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_ref.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
		push(@ana_data, $_);
	}
	close(ANA);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■リンク元別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">リンク元</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	# アクセス数でソート
	@ana_data = &ana_sort(@ana_data);

	foreach(@ana_data){
		($wid, $wcnt) = (split(/<>/, $_))[0,1];
		$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
		$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

		if( length($wid) > 80 ){
			$wid = &substr2($wid, 0, 80);
			$wid .= "...";
		}

		$html .= <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap><a href="$wid" target=_blank>$wid</a></td>
				<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
			</tr>
_HTML_
	}

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_ref END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃OS別アクセス解析画面処理                                ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_os{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_os.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
		push(@ana_data, $_);
	}
	close(ANA);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■OS別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">OS</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	# アクセス数でソート
	@ana_data = &ana_sort(@ana_data);

	foreach(@ana_data){
		($wid, $wcnt) = (split(/<>/, $_))[0,1];
		$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
		$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

		$html .= <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap>$wid</td>
				<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
			</tr>
_HTML_
	}

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_os END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃ブラウザ別アクセス解析画面処理                          ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_brows{
	$pid	= $FORM{'pid'};				# PID

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	($pid,@pid_list) = &make_pidlist($pid);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_brows.cgi";
	open(ANA, $anaf);
	$sum = 0;
	foreach(<ANA>){
		($cnt) = (split(/<>/, $_))[1];
		$sum += $cnt;
		push(@ana_data, $_);
	}
	close(ANA);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■ブラウザ別アクセス解析</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
対象PID選択:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td align="center"><font color="#ffffff">ブラウザ</font></td>
	<td align="center"><font color="#ffffff">アクセス数</font></td>
</tr>
_HTML_

	# アクセス数でソート
	@ana_data = &ana_sort(@ana_data);

	foreach(@ana_data){
		($wid, $wcnt) = (split(/<>/, $_))[0,1];
		$ratio = sprintf("%3.1f", $wcnt / $sum * 100);
		$bwidth = 5 * $ratio;	# 100%=500ピクセル幅

		$html .= <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap>$wid</td>
				<td nowrap><img src="$ana_barimg" border="0" width="$bwidth" height="10">\t$wcnt($ratio%)</td>
			</tr>
_HTML_
	}

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_ana_brows END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃データクリア画面処理                                    ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_ana_clr{
	$pid		= $FORM{'pid'};			# PID
	$exe_flg	= $FORM{'exe_flg'};		# 実行フラグ(1:実行)

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	if( !$exe_flg ){
		# (クリア実行前)

		# PIDリスト作成
		push(@pid_list, "<option value=>アクセス解析対象の全PID");
		foreach(@ana_id){
			push(@pid_list, "<option value=$_>$_");
		}

		$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_clr">
<input type="hidden" name="exe_flg" value="1">
<font size="+1" color="chocolate"><b>■アクセス解析データクリア</b></font><br>
アクセス解析データをクリアし、現時点から解析データを収集します。<br>
クリアしますか?<br><br>
クリアするPID:<select name="pid">@pid_list</select> <input type="submit" value="クリアする">
</form>
</body>
</html>
_HTML_
		&disp_html($html);

	}else{
		# (クリア実行)
		if( $pid eq "" ){
			foreach(@ana_id){
				&clr_analyze($_,1);
			}
		}else{
			&clr_analyze($pid,1);
		}

		# 実行後画面表示
		$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<font size="+1" color="chocolate"><b>■アクセス解析データクリア</b></font><br><br>
アクセス解析データをクリアしました。
</body>
</html>
_HTML_
		&disp_html($html);
	}

	exit;

}# adm_ana_clr END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃日別アクセス数画面処理                                  ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_log_cnt{
	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDファイル
	open(PID, $pidfile);

	# 対象期間取得
	$ymd      = &gettime(4);
	$now_date = &gettime(5);

	# 対象日付リスト作成
	push(@date_list, $ymd);
	undef($header);
	for($i = 0; $i < $maxlogcnt; $i ++){
		$ymd = &get_predate($ymd);
		push(@date_list, $ymd);
		$day = substr($ymd,6,2);
		$header .= "<td nowrap align=center width=20><font color=#ffffff>$day</font></td>";
	}
	if( $ymd =~ /(....)(..)(..)/ ){
		$ana_date = "$1/$2/$3";
	}

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■日別アクセス数</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td nowrap align="center"><font color="#ffffff">PID</font></td>
	<td nowrap align="center"><font color="#ffffff">PID名</font></td>
	<td nowrap align="center"><font color="#ffffff">総合計</font></td>
	<td nowrap align="center"><font color="#ffffff">対象計</font></td>
	<td nowrap align="center"><font color="#ffffff">一日平均</font></td>
	<td nowrap align="center"><font color="#ffffff">$now_date</font></td>
	$header
</tr>
_HTML_

	# PID分ループ
	foreach $fe_pid (<PID>){
		($pid,$pidname) = (split(/<>/, $fe_pid))[0,1];

		# 総カウント
		$totalcnt = &get_pid_count($pid);

		$html .= <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap>$pid</td>
				<td nowrap>$pidname</td>
				<td nowrap align=center>$totalcnt</td>
_HTML_

		$subcnt = 0;
		undef($day_html);
		foreach $fe_ymd (@date_list){
			$cnt = &get_count($pid,$fe_ymd);
			$day_html .= "<td nowrap align=center>$cnt</td>";
			$subcnt += $cnt;
		}

		# 一日平均
		$ave = sprintf("%3.1f", $subcnt / $maxlogcnt);

		$html .= <<_HTML_;
				<td nowrap align=center>$subcnt</td>
				<td nowrap align=center>$ave</td>
				$day_html
			</tr>
_HTML_
	}

	$html .= <<_HTML_;
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_log_cnt END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセスユーザログ画面処理                              ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_log_user{
	$pid	= $FORM{'pid'};				# PID
	$date	= $FORM{'date'};			# 対象日付

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	open(PID, $pidfile);
	foreach(<PID>){
		($wpid,$wpidname) = (split(/<>/, $_))[0,1];
		if( $pid eq "" ){
			$pid = $wpid;
		}
		if( $pid eq $wpid ){
			push(@pid_list, "<option value=$script?mode=$mode&pid=$wpid selected>[$wpid]$wpidname\n");
		}else{
			push(@pid_list, "<option value=$script?mode=$mode&pid=$wpid>[$wpid]$wpidname\n");
		}
	}

	# 対象日付リスト作成
	opendir( DIR, $datdir );
	@files = readdir DIR;
	closedir(DIR);
	@files = sort{ $b cmp $a } @files;
	foreach(@files){
		if( $_ =~ /${pid}_(....)(..)(..)_user\.cgi/ ){
			if( $date eq "" ){
				$date = "$1$2$3";
			}
			if( $date eq "$1$2$3" ){
				push(@date_list, "<option value=$script?mode=$mode&pid=$pid&date=$1$2$3 selected>$1/$2/$3\n");
			}else{
				push(@date_list, "<option value=$script?mode=$mode&pid=$pid&date=$1$2$3>$1/$2/$3\n");
			}
		}
	}

	if( @date_list == 0 ){
		push(@date_list, "<option value=\"\">データがありません\n");
	}

	# アクセスユーザログ
	if( $date eq "" ){
		$date = &gettime(4);
	}
	$logf = "${datdir}/${pid}_${date}_user.cgi";
	open(LOG, $logf);

	# 対象期間取得
	$ana_date = &get_ana_date($pid);
	$now_date = &gettime(5);

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<caption><div align="left">
<font size="+1" color="chocolate"><b>■アクセスユーザログ</b></font><br>
【対象期間:$ana_date 〜 $now_date】<br>
<table border="0">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_log_user">
<tr><td>対象PID選択</td>
<td>:<select name="pid" onchange="location.href=this.options[this.selectedIndex].value">
@pid_list
</select>
</tr>
</form>
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_log_user">
<input type="hidden" name="pid" value="$pid">
<tr><td>対象日付選択</td>
<td>:<select name="date" onchange="location.href=this.options[this.selectedIndex].value">
@date_list
</select></td>
</tr>
</table>
</div></caption>
</form>
<tr bgcolor="#9999ff">
	<td nowrap align="center"><font color="#ffffff">PID</font></td>
	<td nowrap align="center"><font color="#ffffff">カウンタ</font></td>
	<td nowrap align="center"><font color="#ffffff">アクセス日時</font></td>
	<td nowrap align="center"><font color="#ffffff">ユーザ情報</font></td>
	<td nowrap align="center"><font color="#ffffff">OS</font></td>
	<td nowrap align="center"><font color="#ffffff">ブラウザ</font></td>
	<td nowrap align="center"><font color="#ffffff">リンク元</font></td>
</tr>
_HTML_

	undef($log_html);
	foreach(<LOG>){
		($cnt,$pid,$acs_date,$ip1,$host1,$ip2,$host2,$agent,$ref,$os,$brows,$dmy) = split(/<>/, $_);

		# IP情報編集
		if( $ip1 eq "" ){
			$ip1 = "unknown";
		}
		if( $ip2 ne "" ){
			$ip1 .= "($ip2)";
		}
		$ip_info = "<a href=\"javascript:alert('$ip1')\"><img src=$ipimg border=0 alt=\"$ip1\"></a>";

		# ホスト情報編集
		if( $host1 eq "" ){
			$host1 = "unknown";
		}
		if( $host2 ne "" ){
			$host1 .= "($host2)";
		}
		$host_info = "<a href=\"javascript:alert('$host1')\"><img src=$hostimg border=0 alt=\"$host1\"></a>";

		# ユーザエージェント情報編集
		$agent_info = "<a href=\"javascript:alert('$agent')\"><img src=$agentimg border=0 alt=\"$agent\"></a>";

		# リンク元編集
		if( length($ref) > 80 ){
			$ref = substr($ref, 0, 80);
			$ref_disp .= "...";
		}else{
			$ref = $ref;
		}

		$tmp = <<_HTML_;
			<tr bgcolor="#ffffff">
				<td nowrap>$pid</td>
				<td nowrap align=center>$cnt</td>
				<td nowrap>$acs_date</td>
				<td nowrap align=center>$ip_info $host_info $agent_info</td>
				<td nowrap>$os</td>
				<td nowrap>$brows</td>
				<td nowrap><a href=$ref target=_blank>$ref</a></td>
			</tr>
_HTML_
		$log_html = $tmp . $log_html;
	}
	close(LOG);

	$html .= <<_HTML_;
$log_html
</table>
</body>
</html>
_HTML_

	&disp_html($html);

	exit;

}# adm_log_user END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセスユーザ検索画面処理                              ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub adm_log_srch{
	$srch_pid	= $FORM{'pid'};			# PID
	$search		= $FORM{'search'};		# 検索文字列

	# パスワード取得
	($pass) = (split(/<>/, &get_cookie("hicnt_pass")))[0];

	if( $pass ne $password ){
		&errhtml("管理パスワードが違います。");
	}

	# PIDリスト作成
	open(PID, $pidfile);
	push(@pid_list, "<option value=>全PID\n");
	foreach(<PID>){
		($wpid,$wpidname) = (split(/<>/, $_))[0,1];
		if( $srch_pid eq $wpid ){
			push(@pid_list, "<option value=$wpid selected>[$wpid]$wpidname\n");
		}else{
			push(@pid_list, "<option value=$wpid>[$wpid]$wpidname\n");
		}
	}
	close(PID);

	print "Content-type: text/html\n\n";
	print <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666" topmargin="3" leftmargin="3">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_ana_hour">
<font size="+1" color="chocolate"><b>■アクセスユーザ検索</b></font><br>
アクセスユーザログから任意の文字列を含むログを検索します。<br>
検索対象はIPアドレス・ホスト・ユーザエージェント・OS・ブラウザ・リンク元です。
<table border="0">
<form action="$script" method="$method" target=_self>
<input type="hidden" name="mode" value="adm_log_srch">
<input type="hidden" name="search" value="$search">
<tr><td>対象PID選択</td>
<td>:</td><td><select name="pid">
@pid_list
</select>
</tr>
<tr>
<td>検索文字列</td>
<td>:</td><td><input type="text" name="search" value="$search" size="50"><input type="submit" value="検索"></td>
</tr>
<tr>
<td></td><td></td><td>※半角スペースで区切ってOR検索できます。</td>
</tr>
</form>
</table>
_HTML_
	if( $search ne "" ){
		print <<_HTML_;
<hr size="1">
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#000000" width="700">
<caption>
<div align="left">
【検索結果】
</div>
</caption>
<tr bgcolor="#9999ff">
	<td nowrap align="center"><font color="#ffffff">PID</font></td>
	<td nowrap align="center"><font color="#ffffff">カウンタ</font></td>
	<td nowrap align="center"><font color="#ffffff">アクセス日時</font></td>
	<td nowrap align="center"><font color="#ffffff">ユーザ情報</font></td>
	<td nowrap align="center"><font color="#ffffff">OS</font></td>
	<td nowrap align="center"><font color="#ffffff">ブラウザ</font></td>
	<td nowrap align="center"><font color="#ffffff">リンク元</font></td>
</tr>
_HTML_

		# 検索文字列
		$search =~ s/ / /ig;
		@search_list = split(/ /, $search);

		# ログ検索
		opendir( DIR, $datdir );
		@files = readdir DIR;
		closedir(DIR);
		@files = sort{ $b cmp $a } @files;
		$search_cnt = 0;
		foreach $file (@files){
			if( $file =~ /${srch_pid}_(........)_user\.cgi/ ){
				open(LOG, "$datdir/$file");
				foreach $logs (<LOG>){
					($cnt,$pid,$acs_date,$ip1,$host1,$ip2,$host2,$agent,$ref,$os,$brows,$dmy) = split(/<>/, $logs);
					foreach $swd (@search_list){
						if( (index "$ip1$host1$ip2$host2$agent$ref$os$brows", $swd) != -1 ){

							# IP情報編集
							if( $ip1 eq "" ){
								$ip1 = "unknown";
							}
							if( $ip2 ne "" ){
								$ip1 .= "($ip2)";
							}
							$ip_info = "<a href=\"javascript:alert('$ip1')\"><img src=$ipimg border=0 alt=\"$ip1\"></a>";

							# ホスト情報編集
							if( $host1 eq "" ){
								$host1 = "unknown";
							}
							if( $host2 ne "" ){
								$host1 .= "($host2)";
							}
							$host_info = "<a href=\"javascript:alert('$host1')\"><img src=$hostimg border=0 alt=\"$host1\"></a>";

							# ユーザエージェント情報編集
							$agent_info = "<a href=\"javascript:alert('$agent')\"><img src=$agentimg border=0 alt=\"$agent\"></a>";

							# リンク元編集
							if( length($ref) > 80 ){
								$ref = substr($ref, 0, 80);
								$ref_disp .= "...";
							}else{
								$ref = $ref;
							}

							$tmp = <<_HTML_;
								<tr bgcolor="#ffffff">
									<td nowrap>$pid</td>
									<td nowrap align=center>$cnt</td>
									<td nowrap>$acs_date</td>
									<td nowrap align=center>$ip_info $host_info $agent_info</td>
									<td nowrap>$os</td>
									<td nowrap>$brows</td>
									<td nowrap><a href=$ref target=_blank>$ref</a></td>
								</tr>
_HTML_
							$log_html = $tmp . $log_html;
							$search_cnt ++;
							last;
						}
					}
				}
				close(LOG);
				print $log_html;
				undef($log_html);
			}
		}
		print <<_HTML_;
</table>
</body>
</html>
_HTML_
	}

	exit;

}# adm_log_srch END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃デコード処理                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub decode{
	local($name, $value, $buffer);
	my($server_os);

	# OS種別取得
	$server_os = &get_server_os;
	if( $server_os eq "win" ){
		binmode(STDIN);
	}

	if ($ENV{'REQUEST_METHOD'} eq "POST") {
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	}else{
		$buffer = $ENV{'QUERY_STRING'};
	}

	@pairs = split(/&/,$buffer);
	foreach $pair (@pairs) {
		($pair,$ref) = split(/ref=/, $pair);
		if( $ref ne "" ){
			$FORM{'ref'} = $ref;
		}
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#		&jcode'convert(*value,'sjis');
		$FORM{$name} = $value;
	}

	return;

}# decode END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃バックアップ実行処理                                                      ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub bkup{
	my ($ret,$now_date,$bkup_date,$dir);
	my (@file,@sort,@flist);

	# 前バックアップ実行日付取得
	open(BKUP, $bkf);
	($bkup_date) = (split(/<>/, join('',<BKUP>)))[0];
	close(BKUP);

	$ret = 0;
	$now_date = &gettime(4);

	if( $now_date ne $bkup_date ){

		# バックアップ実行
		if( &cpydir($datdir,"${bkupdir}/$now_date") ) {
			&dbglog("[bkup]ディレクトリコピーに失敗しました。($datdir -> $bkupdir/$now_date) [$!]");
			$ret = 1;
		}

		# 古いバックアップデータは削除
		if( $ret == 0 ){
			opendir( DIR, $bkupdir );
			@files = readdir DIR;
			closedir(DIR);
			@files = sort{ $a<=>$b } @files;
			if( @files > $bkdatmax + 2 ){
				$dir = "${bkupdir}/$files[2]";
				$ret = &deldir($dir);
				if( $ret ){
					&dbglog("[bkup]ディレクトリ削除に失敗しました。($dir)");
				}
			}

			if( $ret == 0 ){
				&lock($bkf);

				# バックアップ実行日付保存
				open(BKUP, "> $bkf");
				print BKUP "$now_date<>\n";
				close(BKUP);

				&unlock($bkf);
			}
		}
	}

	return;

}# bkup END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃日付指定カウンタ取得処理                                                  ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : カウンタ取得する日付(YYYYMMDD)                                   ┃
#┃Return : カウンタ値                                                       ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub get_count{

	my($pid,$cnt_date) = @_;
	my($cntf,$cnt);

	# カウンタデータファイル
	$cntf = "$datdir/${pid}_${cnt_date}_cnt.cgi";

	# ファイルが存在するか?
	if( -e $cntf ){
		open(CNT, $cntf);
		($cnt) = (split(/<>/, join('', <CNT>)))[0];
		close(CNT);
	}else{
		$cnt = 0;
	}

	return($cnt);

}# get_count END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃PID指定カウンタ取得処理                                                   ┃
#┃Param1 : PID                                                              ┃
#┃Return : カウンタ値                                                       ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub get_pid_count{

	my($pid) = @_;
	my($cntf,$cnt);

	# カウンタデータファイル
	$cntf = "$datdir/${pid}_total_cnt.cgi";

	# ファイルが存在するか?
	if( -e $cntf ){
		open(CNT, $cntf);
		($cnt) = (split(/<>/, join('', <CNT>)))[0];
		close(CNT);
	}else{
		$cnt = 0;
	}

	return($cnt);

}# get_pid_count END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃前日日付取得処理                                                          ┃
#┃Param1 : 日付(YYYYMMDD)                                                   ┃
#┃Return : 一日前の日付(YYYYMMDD)                                           ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub get_predate{
	my($date) = @_;
	my($yyyy,$mm,$dd,$flg,$predate);

	my @day = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) ;

	#エラーチェック
	if( $date =~ /^([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])/ ){

		if( $date =~ /(....)(..)(..)/ ){
			$yyyy = $1;
			$mm   = $2;
			$dd   = $3;
		}

		$dd -= 1 ;
		if( $dd == 0 or $dd eq "0" ){
			$flg = &chk_uruu($yyyy) ;
			$mm -= 1 ;
			if( $mm == 0 or $mm eq "0" ){
				$mm = 12 ;
				$yyyy -= 1 ;
			}
			$dd = @day[$mm-1] ;
			if( $flg == 1 and $mm == 2 ){
				$dd = 29 ;
			}
		}
		$predate = sprintf("%04d%02d%02d", $yyyy, $mm, $dd) ;
		return( $predate ) ;
	}
	
	return( "ERRORERROR" ) ;

}# get_predate END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃閏年判定処理                                                              ┃
#┃Param1 : 西暦(YYYY)                                                       ┃
#┃Return : 0=閏年でない、1=閏年である                                       ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub chk_uruu{
	my($yyyy) = @_;

	my($wk1,$wk2,$wk3,$flg);

	$wk1 = $yyyy % 4 ;			# 4で割り切れる?
	$wk2 = $yyyy % 100 ;			# 100で割り切れる?
	$wk3 = $yyyy % 400 ;			# 400で割り切れる?
	if( ($wk1 == 0) and ($wk2 != 0) ){      # 4で割り切れ400で割り切れる?
		$flg = 1 ;			# 閏年フラグON
	}elsif( $wk3 == 0 ){
		$flg = 1 ;			# 閏年フラグON
	}else{
		$flg = 0 ;			# 閏年フラグOFF
	}

	return($flg) ;

}# chk_uruu END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃カウントアップ判定処理                                                    ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : アクセスしているIPアドレス                                       ┃
#┃Return : 0=カウントアップ不可、1=カウントアップ実行                       ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub chk_cntup{
	my($pid,$ip) = @_;
	my($logf,$ret, @acsdata);
	my($acstime, $acsip);

	# アクセスログファイルオープン
	$logf = "$datdir/${pid}_log.cgi";
	&lock($logf);
	open(LOG, $logf);

	$times = time;

	$ret = 1;

	# $interval分経過しているIPデータは削除
	foreach(<LOG>){
		($acstime, $acsip) = (split(/<>/, $_))[0,1];
		# $interval分経過しているか?
		if( ($acstime + ($interval * 60)) < $times ){
			# 経過している
		}else{
			# 経過していない
			push(@acsdata, $_);
		}
	}
	close(LOG);

	# IPがマッチしているデータがあればカウント不可
	foreach(@acsdata){
		($acsip) = (split(/<>/, $_))[1];
		if( $ip eq $acsip ){
			# カウント不可
			$ret = 0;
			last;
		}else{
			# カウント実行
			$ret = 1;
		}
	}

	# カウント実行であればIP追加
	if( $ret == 1 ){
		$str = "$times<>$ip<>\n";
		push(@acsdata, $str);
	}

	# データ書き込み
	open(OUT, "> $logf");
	print OUT @acsdata;
	close(OUT);
	&unlock($logf);

	return($ret);

}# chk_cntup END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃カウンタ表示処理                                                          ┃
#┃Param1 : カウント値                                                       ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub cnt_disp{
	my($disp_cnt) = @_;
	my($cntstr,$i,$n,@files);

	# 桁数設定
	if( length($disp_cnt) > $len ){	$len = $len + 1;}

	# 表示フォーマット
	$cntstr = sprintf(sprintf("%%0%dld", $len), $disp_cnt);

	# カウンタ表示
	if( $img eq "txt" ){
		# (テキスト表示)
		if( $disp_type ){
			printf("Content-type: text/plain\n\n");
		}
		print "$cntstr";
	}else{
		# (画像表示)
		printf("Content-type: image/gif\n\n");
		for ($i = 0; $i < length($cntstr); $i++){
			$n = substr($cntstr, $i, 1);
			push(@files, "${imgpath}/$n.gif");
		}
		binmode(STDOUT);
		print &gifcat'gifcat(@files);
	}

	return;

}# cnt_disp END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセスユーザ情報出力処理                                                ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : カウント値                                                       ┃
#┃Param3 : 日付(YYYYMMDD)                                                   ┃
#┃Param4 : リンク元                                                         ┃
#┃Param5 : OS                                                               ┃
#┃Param6 : ブラウザ                                                         ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub get_usrinf{
	my($pid,$cnt,$ymd,$ref,$os,$br) = @_;
	my($date,$ip1,$ip2,$host1,$host2,$user_log,$logf);

	$logf = "$datdir/${pid}_${ymd}_user.cgi";
	&lock($logf);

	$date = &gettime(0);

	# IP、ホスト取得
	$ip1 = $ENV{'REMOTE_ADDR'};
	$ip2 = $ENV{'HTTP_X_FORWARDED_FOR'};
	$host1 = gethostbyaddr(pack('C4',split(/\./,$ip1)),2);
	if( $ip2 ne "" ){
		$host2 = gethostbyaddr(pack('C4',split(/\./,$ip2)),2);
	}

	$user_log = "$cnt<>$pid<>$date<>$ip1<>$host1<>$ip2<>$host2<>$ENV{'HTTP_USER_AGENT'}<>$ref<>$os<>$br<><><>\n";

	# データ書き込み
	open(LOG, ">> $logf");
	print LOG $user_log;
	close(LOG);

	&unlock($logf);

	return;

}# get_usrinf END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析画像表示処理                                                  ┃
#┃Param1 : なし                                                             ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_disp{
	printf("Content-type: image/gif\n\n");
	binmode(STDOUT);
	print &gifcat'gifcat($anaimg);

	return;

}# ana_disp END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析処理                                                          ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : リンク元                                                         ┃
#┃Param3 : OS                                                               ┃
#┃Param4 : ブラウザ                                                         ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub analyze{
	my($pid,$ref,$os,$br) = @_;
	my($anaf);

	# アクセス解析対象期間が過ぎていればクリアする
	&clr_analyze($pid);

	# 時間別アクセス解析
	&ana_hour($pid);

	# 曜日別アクセス解析
	&ana_day($pid);

	# ホスト別アクセス解析
	&ana_host($pid);

	# リンク元別アクセス解析
	&ana_ref($pid,$ref);

	# OS別アクセス解析
	&ana_os($pid,$os);

	# ブラウザ別アクセス解析
	&ana_brows($pid,$br);

	return;

}# analyze END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析クリア処理                                                    ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : 強制クリア実行フラグ(1=強制クリア)                               ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub clr_analyze{
	my($pid,$exe_clr) = @_;

	# アクセス解析開始情報
	my $anaf = "${datdir}/${pid}_ana_log.cgi";
	&lock($anaf);
	open(ANA, $anaf);
	my ($sta_times) = (split(/<>/, join('',<ANA>)))[0];
	close(ANA);

	my $now_times = time;
	my $now_date  = &gettime(5);

	if( $exe_clr || $sta_times + ($maxlogcnt * 24 * 60 * 60) < $now_times ){
		# アクセス解析開始情報更新
		open(ANA, "> $anaf");
		print ANA "$now_times<>$now_date<>\n";
		close(ANA);

		# アクセス解析データ削除
		unlink("${datdir}/${pid}_ana_hour.cgi");
		unlink("${datdir}/${pid}_ana_day.cgi");
		unlink("${datdir}/${pid}_ana_host.cgi");
		unlink("${datdir}/${pid}_ana_ref.cgi");
		unlink("${datdir}/${pid}_ana_os.cgi");
		unlink("${datdir}/${pid}_ana_brows.cgi");
	}

	&unlock($anaf);

	return;

}# clr_analyze END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(時間別)処理                                                ┃
#┃Param1 : PID                                                              ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_hour{
	my($pid) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);
	my($acs_hour);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_hour.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	# 時間取得
	$acs_hour = &gettime(6);
	$acs_hour = substr($acs_hour, 0, 2);

	$find = 0;
	foreach(<ANA>){
		($wid,$wcnt) = (split(/<>/, $_))[0,1];
		if( $wid eq $acs_hour ){
			$find = 1;
			$wcnt ++;
			push(@pool, "$wid<>$wcnt<>\n");
		}else{
			push(@pool, $_);
		}
	}
	close(ANA);

	# 既存データになければ新規追加する
	if( $find == 0 ){
		push(@pool, "$acs_hour<>1<>\n");
	}

	# データ書き込み
	open(OUT, "> $anaf");
	print OUT @pool;
	close(OUT);

	&unlock($anaf);

	return;

}# ana_hour END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(曜日別)処理                                                ┃
#┃Param1 : PID                                                              ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_day{
	my($pid) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_day.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	# 曜日取得
	my($times) = time;
	my($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($times);
	my($youbi) = ('日曜日','月曜日','火曜日','水曜日','木曜日','金曜日','土曜日') [$wday];

	$find = 0;
	foreach(<ANA>){
		($wid,$wcnt) = (split(/<>/, $_))[0,1];
		if( $wid eq $youbi ){
			$find = 1;
			$wcnt ++;
			push(@pool, "$wid<>$wcnt<>\n");
		}else{
			push(@pool, $_);
		}
	}
	close(ANA);

	# 既存データになければ新規追加する
	if( $find == 0 ){
		push(@pool, "$youbi<>1<>\n");
	}

	# データ書き込み
	open(OUT, "> $anaf");
	print OUT @pool;
	close(OUT);

	&unlock($anaf);

	return;

}# ana_day END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(ホスト別)処理                                              ┃
#┃Param1 : PID                                                              ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_host{
	my($pid) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_host.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	# ホスト取得
	my $acs_host = $ENV{'REMOTE_HOST'};
	if( $acs_host eq "" ){
		$acs_host = gethostbyaddr(pack('C4',split(/\./,$ENV{'REMOTE_ADDR'})),2);
	}
	if ($acs_host =~ /(.*)\.(\d+)$/) {
	}elsif ($acs_host =~ /(.*)\.(.*)\.(.*)\.(.*)$/) { $acs_host = "\*\.$2\.$3\.$4";
	}elsif ($acs_host =~ /(.*)\.(.*)\.(.*)$/) {       $acs_host = "\*\.$2\.$3";
	}
	if( $acs_host eq "" ){
		$acs_host = $ENV{'REMOTE_ADDR'};
	}

	$find = 0;
	foreach(<ANA>){
		($wid,$wcnt) = (split(/<>/, $_))[0,1];
		if( $wid eq $acs_host ){
			$find = 1;
			$wcnt ++;
			push(@pool, "$wid<>$wcnt<>\n");
		}else{
			push(@pool, $_);
		}
	}
	close(ANA);

	# 既存データになければ新規追加する
	if( $find == 0 ){
		push(@pool, "$acs_host<>1<>\n");
	}

	# データ書き込み
	open(OUT, "> $anaf");
	print OUT @pool;
	close(OUT);

	&unlock($anaf);

	return;

}# ana_host END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(リンク元別)処理                                            ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : リンク元                                                         ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_ref{
	my($pid,$ref) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_ref.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	# リンク元取得
	my $acs_referer;
	if( $ref eq "" ){
		$acs_referer = "none.";
	}else{
		$acs_referer = $ref;
	}

	# アクセス元除外URLチェック
	my $flg = 0;
	foreach(@out_url){
		if( index($acs_referer, $_) == 0 ){
			$flg = 1;
			last;
		}
	}

	# アクセス元除外であれば処理しない
	if( $flg == 0 ){
		$find = 0;
		foreach(<ANA>){
			($wid,$wcnt) = (split(/<>/, $_))[0,1];
			if( $wid eq $acs_referer ){
				$find = 1;
				$wcnt ++;
				push(@pool, "$wid<>$wcnt<>\n");
			}else{
				push(@pool, $_);
			}
		}
		close(ANA);

		# 既存データになければ新規追加する
		if( $find == 0 ){
			push(@pool, "$acs_referer<>1<>\n");
		}

		# データ書き込み
		open(OUT, "> $anaf");
		print OUT @pool;
		close(OUT);
	}

	&unlock($anaf);

	return;

}# ana_ref END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(OS別)処理                                                  ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : OS                                                               ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_os{
	my($pid,$acs_os) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_os.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	$find = 0;
	foreach(<ANA>){
		($wid,$wcnt) = (split(/<>/, $_))[0,1];
		if( $wid eq $acs_os ){
			$find = 1;
			$wcnt ++;
			push(@pool, "$wid<>$wcnt<>\n");
		}else{
			push(@pool, $_);
		}
	}
	close(ANA);

	# 既存データになければ新規追加する
	if( $find == 0 ){
		push(@pool, "$acs_os<>1<>\n");
	}

	# データ書き込み
	open(OUT, "> $anaf");
	print OUT @pool;
	close(OUT);

	&unlock($anaf);

	return;

}# ana_os END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析(ブラウザ別)処理                                            ┃
#┃Param1 : PID                                                              ┃
#┃Param2 : ブラウザ                                                         ┃
#┃Return : なし                                                             ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_brows{
	my($pid,$acs_br) = @_;
	my($anaf,$find,$wid,$wcnt,@pool);

	# アクセス解析データ
	$anaf = "${datdir}/${pid}_ana_brows.cgi";
	&lock($anaf);
	open(ANA, $anaf);

	$find = 0;
	foreach(<ANA>){
		($wid,$wcnt) = (split(/<>/, $_))[0,1];
		if( $wid eq $acs_br ){
			$find = 1;
			$wcnt ++;
			push(@pool, "$wid<>$wcnt<>\n");
		}else{
			push(@pool, $_);
		}
	}
	close(ANA);

	# 既存データになければ新規追加する
	if( $find == 0 ){
		push(@pool, "$acs_br<>1<>\n");
	}

	# データ書き込み
	open(OUT, "> $anaf");
	print OUT @pool;
	close(OUT);

	&unlock($anaf);

	return;

}# ana_brows END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃PIDリスト作成処理                                                         ┃
#┃Param1 : 初期選択するPID                                                  ┃
#┃Return : デフォルトPID,PIDリスト                                          ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub make_pidlist{
	my($pid) = @_;
	my($wpid,$pidname,@pid_list);

	foreach $wpid (@ana_id){
		if( $pid eq "" ){
			$pid = $wpid;
		}
		if( $pid eq $wpid ){
			push(@pid_list, "<option value=$script?mode=$mode&pid=$wpid selected>$wpid\n");
		}else{
			push(@pid_list, "<option value=$script?mode=$mode&pid=$wpid>$wpid\n");
		}
	}
	close(PID);

	return($pid,@pid_list);

}# make_pidlist END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析データソート処理                                              ┃
#┃Param1 : アクセス解析データ配列                                           ┃
#┃Return : ソート後アクセス解析データ配列                                   ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub ana_sort{
	my(@data) = @_;
	my($i,$j,$idi,$cti,$idj,$ctj,$tmp);

	# アクセス数でソート
	for( $i = 0; $i < @data -1; $i ++ ){
		for( $j = $i + 1; $j < @data; $j ++ ){
			($idi, $cti) = (split(/<>/, $data[$i]))[0,1];
			($idj, $ctj) = (split(/<>/, $data[$j]))[0,1];
			if( $cti < $ctj ){
				$tmp = $data[$i];
				$data[$i] = $data[$j];
				$data[$j] = $tmp;
			}
		}
	}

	return(@data);

}# ana_sort END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃アクセス解析開始日取得処理                                                ┃
#┃Param1 : PID                                                              ┃
#┃Return : アクセス解析開始日                                               ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub get_ana_date{
	my($pid) = @_;
	my($file,$ana_date);

	$file = "$datdir/${pid}_ana_log.cgi";

	if( -e $file ){
		open(DATE, $file);
		($ana_date) = (split(/<>/, join('',<DATE>)))[1];
		close(DATE);
	}else{
		$ana_date = &gettime(5);
	}

	return($ana_date);

}# get_ana_date END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃ログクリア処理                                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub clear_log{
	my ($now_date,$clr_date,$chk_date);

	# 前ログクリア実行日付取得
	open(CLR, $clrf);
	($clr_date) = (split(/<>/, join('',<CLR>)))[0];
	close(CLR);

	$now_date = &gettime(4);

	if( $now_date ne $clr_date ){

		&lock($clrf);

		# クリア対象の日付を求める
		my $clr_times = time - ($maxlogcnt * 24 * 60 * 60);
		my($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime($clr_times);
		$year = $year + 1900;
		$month++;
		$chk_date = sprintf("%04d%02d%02d", $year, $month, $mday);

		# ログ取得対象日数より過去のデータを削除する
		opendir( DIR, $datdir );
		foreach(readdir DIR){
			if( $_ =~ /_(....)(..)(..)_/ ){
				if( $chk_date > "$1$2$3" ){
					unlink("$datdir/$_");
				}
			}
		}
		closedir(DIR);

		# データ書き込み
		open(CLR, "> $clrf");
		print CLR "$now_date<>\n";
		close(CLR);

		&unlock($clrf);
	}

	return;

}# clear_log END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃メール送信処理                                                            ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub mail{
	my ($now_date,$mail_date,$pre_date,$pre_date2,$count,$total_count,$pid,$pidname,$log);
	local($message);

	&lock($mailf);

	# 前メール送信実行日付取得
	open(ML, $mailf);
	($mail_date) = (split(/<>/, join('',<ML>)))[0];
	close(ML);

	$now_date = &gettime(4);

	if( $now_date ne $mail_date ){

		# 前日の日付取得
		$pre_date = &get_predate($now_date);
		if( $pre_date =~ /(....)(..)(..)/ ){
			$pre_date2 = "${1}年${2}月${3}日";
		}

		# 全PID分ループ
		open(PID, $pidfile);
		foreach(<PID>){
			($pid,$pidname) = (split(/<>/, $_))[0,1];
			# 日付指定アクセス数
			$count = &get_count($pid,$pre_date);

			# 総アクセス数
			$total_count = &get_pid_count($pid);

			$log .= "[$pid]$pidname -> ${count}/${total_count} アクセス\n";
		}
		close(PID);

		if( $log eq "" ){
			$log = "PIDデータがありません\n";
		}

		$message = <<_MSG_;
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  HiCnt アクセス状況報告メール

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
▼アクセス状況($pre_date2分/総アクセス数)
$log
▼管理画面
$script_url$script?mode=login

───────────────────────────────────
 このメールは
          多機能\アクセスカウンタスクリプト HiCnt Ver $ver
            (C)million system(http://www.e-hws.net/)
                                            を利用して送信しています。
───────────────────────────────────
_MSG_

		# 文字コード変換
		&jcode'convert(*mail_subject,'jis');
		&jcode'convert(*message,'jis');

		# メール送信
		$err = 0;
		open (MAIL,"| $sendpath -t -f $masmail") or $err = 1;
		if( $err == 0 ){
			print MAIL "To: $masmail\n";
			print MAIL "From: $masmail\n";
			print MAIL "Subject: $mail_subject\n";
			print MAIL "MIME-Version: 1.0\n";
			print MAIL "Content-Transfer-Encoding: 7bit\n";
			print MAIL "Content-Type: text/plain\; charset=\"ISO-2022-JP\"\n\n";
			print MAIL "$message\n\n";
			close (MAIL);

			# データ書き込み
			open(ML, "> $mailf");
			print ML "$now_date<>\n";
			close(ML);

		}else{
			close (MAIL);
			&dbglog("メール送信エラー[$sendpath][FROM:$masmail][TO:$masmail]", __FILE__, __LINE__);
		}
	}

	&unlock($mailf);

	return;

}# mail END

#┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#┃エラー画面表示処理                                      ┃
#┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sub errhtml{
	($errmsg)	= @_;		# エラーメッセージ

	$html = <<_HTML_;
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<style type="text/css">
<!--
body,tr,td,table{
	font-family : "MS UI Gothic";
}
-->
	</style>
</head>
<body text="#666666" link="#666666" alink="#666666" vlink="#666666">
<font color="red">エラー</font>
<hr size="1">
$errmsg
<br><br>
<input type="button" value="戻る" onclick='history.back()'>
</body>
</html>
_HTML_
	&disp_html($html);

	exit;

}# errhtml END

Zerion Mini Shell 1.0