#!/usr/local/bin/perl
# perlまでのパス
#############################################################################
# NENPYO-CGI Ver.1.03 Beta
# Copyright 2000 HIDEKI OKUBO a---@netlaputa.ne.jp
# Created 06/11/2000 Last Modified 06/16/2000
# Scripts at: http://www.netlaputa.ne.jp/~a---/nenpyo/
#
# フリーCGIです。
# プログラムの改変等も自由です。ご自身の責任にもとづいてお使いください。
#
# 当プログラムのコードを販売することは、禁止させていただきます。
#
############################################
# 初期値設定
############################################
# データファイルを置くディレクトリまでのパス
$BaseDir = "/space/UserHome/home1/a---/HomePage/nenpyo/data";
# このCGIのURL
$CGIURL = "http://cgi.netlaputa.ne.jp/~a---/nenpyo/nenpyo.cgi";
# パスワード
$password = 'password';
# 拡張子(txt)を省いたファイル名、それに対応するファイル日本語名
@file_name=("chart_parm","Mark_parm","nenpyom","nenpyo2","alpha_name","vin17_10","search_engine");
@file_name_j=("チャートパラメータ","マーカーパラメータ","年代別モデル","年代別記事","モデル名称カナ","年コード","サーチエンジン連動");
#-------------------------------------------
# 初期表示時に抽出する値
#-------------------------------------------
@Form_checked = ("checked","checked","checked","checked","checked","checked","checked"); # 表示
$y_array = "19,0,3-20,0,0"; # 期間(自)-(至)
$Form_Years = "5";
#-------------------------------------------
@Years = (1,5,10,20,50,100);
@suji1 = (19,20);
@suji2 = (0,1,2,3,4,5,6,7,8,9);
#-------------------------------------------
@year_array = split(/-/, $y_array);
@y_array0 = split(/\,/, @year_array[0]);
@y_array1 = split(/\,/, @year_array[1]);
$Form_sYear = @y_array0[0] . @y_array0[1] . @y_array0[2];
$Form_eYear = @y_array1[0] . @y_array1[1] . @y_array1[2];
$Form_alphabets = "alphabets";
$Form_Count = 1; #
#-------------------------------------------
# HTML表示定義
#-------------------------------------------
$body = <<'EOT';
The chronological table of Harley-Davidson line-up
EOT
#--------------------------------------#あたま書き
$html_data = <<'EOT';
Harley-Davidson Model年表
The chronological table of Harley-Davidson line-up.
(年表CGI - FAQ)
EOT
#--------------------------------------#リンクなど
$html_foot = <<'EOT';
HOME | History of H-D | VIN17 of H-D | Alphabets
EOT
#-------------------------------------------
# バージョン情報
#-------------------------------------------
$version = <<'EOT';
(CGI Ver.1.03 Beta by HDK)
EOT
#############################################
# メイン処理
#############################################
&inForm; # フォーム入力
&HTML_Header; # ヘッダー
# 各アクションに対応した処理
if ($in{'action'} eq "") {&search;} # 初期表示検索
if ($in{'action'} eq "search") {&search;} # 検索 /(仮)更新後検索
if ($in{'action'} eq "up_index") {&up_index;} # 更新メニュー
if ($in{'action'} eq "alter") {&alter;} # (仮)更新用フォーム
if ($in{'action'} eq "up") {&up;} # (仮)更新 & 最終更新用フォーム
if ($in{'action'} eq "last_up") {&last_up;} # 最終更新
&HTML_Footer; # フッター
exit; # 終了
#############################################
# フォーム入力ルーチン
#############################################
sub inForm {
if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
else { $buffer = $ENV{'QUERY_STRING'}; }
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /; #
$value =~ s/ / /g; #
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #
if ($name ne "up") {$value =~ s/\n//g;} #
$value =~ s/\*//g; #
# コメント扱い
# $value =~ s///g; # SSIタグ禁止
# $value =~ s/</g; # HTMLタグ禁止
# $value =~ s/>/>/g;
# &jcode'h2z_sjis(*value); # 日本語変換用jcode.plが必要
# &jcode'convert(*value,'sjis'); # 日本語変換用jcode.plが必要
$in{$name} = $value;
}
}
############################################
# サーチメイン処理 (action="search" or "")
############################################
sub search {
# サーチキーセット処理(初期表示時は初期セット値)
if ($in{'action'} eq "search") {
$y_array1 = join(",", $in{'year00'},$in{'year01'},$in{'year02'});
$y_array2 = join(",", $in{'year10'},$in{'year11'},$in{'year12'});
$y_array = join("-", $y_array1,$y_array2);
$Form_sYear = $in{'year00'} . $in{'year01'} . $in{'year02'};
$Form_eYear = $in{'year10'} . $in{'year11'} . $in{'year12'};
$Form_alphabets = $in{'alphabets'};
$Form_Years = $in{'Years'};
$Form_Count = $in{'C_Count'};
for ($I = 0; $I <= $#Form_checked; $I++) {
@Form_chname[$I] = "ch".@file_name[$I];
@Form_checked[$I] = $in{$Form_chname[$I]};
}
}
if ($in{'alphabets'} eq "alphabets") {
$Form_Keywords = "";
}
else {
$Form_Keywords = $in{'alphabets'};
@Keywords = ();
foreach (split(/ /, $Form_Keywords)) {
s/([\\\|\(\)\[\{\^\$\*\+\?\.])/\\$1/g;
push(@Keywords, $_);
}
}
# 各ファイルオープン、クローズ
if ($in{'file_name'} ne "") { # (仮)更新後のテスト検索時
for ($I = 0; $I <= $#file_name; $I++) { # テスト検索用ファイル名設定
if ($in{'file_name'} eq @file_name[$I]) {
@file_name[$I] = @file_name[$I] . "_temp";
}
}
}
for ($I = 0; $I <= $#file_name; $I++) {
$X = "";
if ((@Form_checked[$I] eq "checked") || (@file_name[$I] eq "@file_name[2]")) { # 対象
open(IN, "$BaseDir/@file_name[$I].txt");
@IN = ;
close(IN);
# print "($I)@file_name[$I],";
foreach $LINE (@IN) {
$X = $X.$LINE;
}
}
@file[$I] = $X;
}
#-------------------------------------------
&P_Select;
#-------------------------------------------
# サーチ用フォーム書き出し
if ($in{'file_name'} eq "") {
print "";
}
#-------------------------------------------
# サーチ指定内容表示
#-------------------------------------------
sub search_Header {
$Msg_Keywords = $Form_Keywords;
if ($Form_Keywords eq "") {$Msg_Keywords = "指定なし";}
print <<"EOL";
*期間:$Form_sYear - $Form_eYear, アルファベット:$Msg_Keywords,
EOL
print " 表\示( ";
for ($I = 0; $I <= $#Form_checked; $I++) {
if (@Form_checked[$I] eq "checked") {
print "*@file_name_j[$I] ";
$wrflg = "1";
}
}
if ($wrflg ne "1") {print "指定なし";}
else {print "指定";}
print " )による検索結果です。
";
}
#-------------------------------------------
# チャートの説明 HTML書込み
#-------------------------------------------
sub HTML_chuChar {
print "
*チャート
\n";
# チャートパラメータに対応したチャートを描画
$xxB = 0;
foreach $cpline (@chart_parm) {
$xxB = $xxB + 1;
@cpline = split(/,【同系】,/, $cpline);
foreach $cpyouso (@cpline) {
print "\n";
@cpValue = split(/\,/, $cpyouso);
for ($xxA = 1; $xxA <= $#chart_parm + 1; $xxA++) {
if ($xxA == $xxB) {
$chart_color = "bgcolor = \"@cpValue[2]\"";
print "| | \n";
# last;
}
else {
$chart_color = "";
print " | \n";
}
}
print " : @cpValue[0] - @cpValue[1] @cpValue[3] | \n";
print "
\n";
}
}
}
#-------------------------------------------
# マーカーの説明 HTML書込み
#-------------------------------------------
sub HTML_chumark {
print "
*マーカー(";
$ii = 0;
foreach $MKline (@Mark_parm) {
$ii = $ii + 1;
@MKline = split(/\,/, $MKline);
@model_marker[$ii] = " style=\"color:black;background-color:@MKline[0]\"";
print " $ii:@MKline[1]";
}
print ")
\n";
}
#-------------------------------------------
# 年表HTMLプリントルーチン
#-------------------------------------------
sub HTML_Print1 {
if ($#P_FILE_C >= 0) {
print "
\n";
$wtbl_flg = "0";
$HLD_key = "DUMMY_MOJI";
for ($I = 0; $I <= $#P_FILE_C; $I++) {
@P_koumoku = split(/\,/,@P_FILE_C[$I]);
if (@P_koumoku[0] eq "") { @P_koumoku[0] = $HLD_key;}
if (@P_koumoku[0] ne $HLD_key) {
if ($wtbl_flg eq "1") {
print "\n\n\n";
}
&HTML_Chart;
print "\n";
&HTML_Year;
print "\n";
&HTML_event;
$wtbl_flg = "1";
}
$Work_Line = @P_koumoku[1];
&search_j; #キーワード検索
if (($MatFlg eq "1") && (@Form_checked[2] eq "checked")) {
&HTML_Model;
}
$HLD_key = @P_koumoku[0];
}
print " \n | \n\n";
}
}
#-------------------------------------------
# チャートHTML書込み
#-------------------------------------------
sub HTML_Chart {
print "\n";
foreach $cpline (@chart_parm) {
@cpline = split(/,【同系】,/, $cpline);
$chart_color = "";
foreach $cpyouso (@cpline) {
@cpValue = split(/\,/, $cpyouso);
if ((@P_koumoku[0] ge @cpValue[0]) && (@P_koumoku[0] le @cpValue[1])) { # 期間範囲内?
$chart_color = "bgcolor = \"@cpValue[2]\"" ;
last;
}
}
print "| | \n";
}
}
#-------------------------------------------
# 年の行 HTML書込み
#-------------------------------------------
sub HTML_Year {
$YEAR_Write = "";
@S_File = split(/\n/, @file[5]); # 年コード
foreach $S_Line(@S_File) {
@S_koumoku = split(/\,/, $S_Line);
if (@P_koumoku[0] eq @S_koumoku[0]) {
if (@S_koumoku[2] ne "") {
if (@S_koumoku[3] eq "") {
print " @P_koumoku[0]";
print "(@S_koumoku[1])\n";
}
else {
print " @P_koumoku[0]";
print "(@S_koumoku[1])\n";
print " @S_koumoku[3]... ";
}
}
else {
print " @P_koumoku[0]";
print "(@S_koumoku[1])\n";
}
$YEAR_Write = "1";
last;
}
}
if ($YEAR_Write ne "1"){ # 年の属性なし
print " @P_koumoku[0]";
}
# サーチエンジン連動
@S_File = split(/\n/, @file[6]);
foreach $S_Line(@S_File) {
@S_koumoku = split(/\,/, $S_Line);
if (@S_koumoku[0] ne "") {
$Search_url = @S_koumoku[0] . @P_koumoku[0];
print "@S_koumoku[1]...";
}
}
}
#-------------------------------------------
# 記事データ HTML書込み
#-------------------------------------------
sub HTML_event {
@S_File = split(/\n/, @file[3]); #年代別記事
$event_name = "";
foreach $S_Line(@S_File) {
@S_koumoku = split(/\,/, $S_Line);
if (@P_koumoku[0] eq @S_koumoku[0]) {
$event_name = @S_koumoku[1];
last;
}
}
if ($event_name ne "") {
print <<"EOL";
$event_name
EOL
}
}
#-------------------------------------------
# モデル HTML書込み
#-------------------------------------------
sub HTML_Model {
&model_marker;
if ((@P_koumoku[3] ne "") && (@P_koumoku[4] eq "")) {
print "@P_koumoku[1]...";
}
else{ print "@P_koumoku[1]...";}
if (@Form_checked[4] eq "checked") { # モデル名表示する?
&model_name;
if ($model_name ne "") {
print <<"EOL";
$model_name...
EOL
}
&model_Link;
print "
";
}
else {
&model_Link;
print "\n";
}
# モデル別リンク
sub model_Link {
if ((@P_koumoku[3] ne "") && (@P_koumoku[4] ne "")) {
print "@P_koumoku[4]...";
}
@S_File = split(/\n/, @file[6]); # サーチエンジン連動
$w_flg = "0";
foreach $S_Line(@S_File) {
@S_koumoku = split(/\,/, $S_Line);
if ((@S_koumoku[0] ne "") && (@P_koumoku[1] ne "他調査中")) {
if ($w_flg eq "0") {
print "";
$w_flg = "1";
}
$Search_url = @S_koumoku[0] . @P_koumoku[0] . "+" . @P_koumoku[1];
print " @S_koumoku[1]...";
}
}
if ($w_flg eq "1") {print "";}
}
#
}
#-------------------------------------------
# マーカータグ
#-------------------------------------------
sub model_marker {
$model_marker = "";
if (@P_koumoku[2] ne "") {
$model_marker = @model_marker[@P_koumoku[2]];
}
}
#-------------------------------------------
# 名称ルーチン
#-------------------------------------------
sub model_name {
@S_File = split(/\n/, @file[4]); #モデル名称カナ
$model_name = "";
foreach $S_Line(@S_File) {
@S_koumoku = split(/\,/, $S_Line);
if (@P_koumoku[1] eq @S_koumoku[0]) {
$model_name = @S_koumoku[1];
last;
}
}
}
#-------------------------------------------
# サーチ結果判定
#-------------------------------------------
sub search_j {
$MatFlg = "";
if ($Form_Keywords eq "") {
$MatFlg = "1";
}
else {
foreach $Keyword (@Keywords) {
if ($Work_Line =~ /$Keyword/i) {
$MatFlg = "1";
Last;
}
}
}
}
############################################
# 更新メニュー処理 (action="up_index")
############################################
sub up_index {
print <<"EOL";
*データを更新する
";
}
############################################
# (仮)更新用フォーム処理 (action="alter")
############################################
sub alter {
if ($in{'password'} eq $password) {
$file = $in{'file_name'};
open ($file, "$BaseDir/$file.txt");
@file = <$file>;
close($file);
print <<"EOL";
(仮)更新フォーム $in{'file_name'}_temp.txt
";
}
else {
print "*パスワードが一致しません。
\n";
}
print "BACK\n";
}
############################################
# (仮)更新処理 (action="up")
############################################
sub up {
if ($in{'password'} eq $password) {
$Form_textarea = $in{'tx1'};
$Form_textarea =~ s/\r\n/\r/g;
$Form_textarea =~ s/\r/\n/g;
&test_search;
&Form_HTML;
print "*(仮)更新明細 $in{'file_name'}_temp.txt
";
@Form_text = split(/\n/, $Form_textarea);
if ($in{'sort'} eq "") {@Form_sort = @Form_text;}
if (($in{'sort'} eq "sort") || ($in{'sort'} eq "reverse")) {
$HLD_key = "DUMMY_MOJI";
for ($I = 0; $I <= $#Form_text; $I++) {
if (substr($Form_text[$I], 0, 1) eq ",") {
$Form_text[$I] = $HLD_key.$Form_text[$I];
}
$HLD_key = substr($Form_text[$I], 0, index($Form_text[$I], ","));
}
}
if ($in{'sort'} eq "sort") {@Form_sort = sort @Form_text;}
if ($in{'sort'} eq "reverse") {@Form_sort = reverse @Form_text;}
open(OUT, "> $BaseDir/$in{'file_name'}_temp.txt");
foreach $Form_sort (@Form_sort) {
print(OUT "$Form_sort\n");
print "$Form_sort↓(LF)<\/font>
\n";
}
close(OUT);
}
else {
print "*パスワードが一致しません。
\n";
print "
BACK\n";
}
}
#-------------------------------------------
# テスト検索フォーム
#-------------------------------------------
sub test_search {
$backurl = $CGIURL ."?". "action=alter" . "&file_name=" . $in{'file_name'} . "&password=" . $in{'password'};
print <<"EOL";
*(仮)更新明細、テスト検索の確認後、問題なければ最終更新してください。
BACK