#!/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; # &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 "
\n"; print "\n"; &Form_HTML; } else { # (仮)更新後のテスト検索時 &test_search; &Form_HTML; } # ファイルの内容を行単位に配列セット @chart_parm = split(/\n/, @file[0]); #チャートパラメータ @Mark_parm = split(/\n/, @file[1]); #マーカーパラメータ # 注 @file_nameの定義に従って、 # @file[2] :年代別モデル # @file[3] :年代別記事 # @file[4] :モデル名称カナ # @file[5] :年コード # @file[6] :サーチエンジン連動...と対応つけている。 # HTML出力処理 #&search_Header; &HTML_chumark; &HTML_chuChar; &HTML_Print1; &up_index; } #------------------------------------------- # 年代別モデル(プライマリ)抽出テーブル作成 #------------------------------------------- sub P_Select { @P_File = split(/\n/, @file[2]); #年代別モデル $count_Years = 0; $First_Set = ""; $J =0; $HLD_key = "DUMMY_MOJI"; for ($I = 0; $I <= $#P_File; $I++) { @P_koumoku = split(/\,/,@P_File[$I]); if (@P_koumoku[0] eq "") { @P_koumoku[0] = $HLD_key;} if (((@P_koumoku[0] ge $Form_sYear - 1) && (@P_koumoku[0] le $Form_eYear) && ($in{'submit1'} eq "Search")) || (($in{'submit1'} ne "Search") && ($I >= $Form_Count - 1))) { # 抽出期間/カウント? if (@P_koumoku[0] ne $HLD_key) { $count_Years = $count_Years + 1; $C_Count = $I + 1; } if ((($count_Years <= $Form_Years) && (@P_koumoku[0] ge $Form_sYear) && ($in{'submit1'} eq "Search")) || (($count_Years <= $Form_Years) && ($in{'submit1'} ne "Search"))) { @P_FILE_C[$J] = @P_File[$I]; $J = $J + 1; if ($count_Years == 1) {$RYear1 = @P_koumoku[0];} if ($First_Set ne "1") { $CNT1 = $I + 1; $First_Set = "1"; } $RYear2 = @P_koumoku[0]; } else{last;} } $HLD_key = @P_koumoku[0]; } $y_array1 = join(",", substr($RYear2, 0, 2),substr($RYear2, 2, 1),substr($RYear2, 3, 1)); $y_array2 = join(",", substr($RYear1, 0, 2),substr($RYear1, 2, 1),substr($RYear1, 3, 1)); $y_array = join("-", $y_array1,$y_array2); $Form_sYear = $RYear2; $Form_eYear = $RYear1; $CNT2 = $CNT1 + $#P_FILE_C; $CNT3 = $#P_File + 1; print "
results $CNT1 - $CNT2 about of $CNT3.
"; #print "SUBMIT : $in{'submit1'}
"; #print "$y_array --- $Form_sYear - $Form_eYear
"; #print "C_Count $C_Count count_Years $count_Years
"; #print "@P_FILE_C"; } #------------------------------------------- # 検索セレクトフォーム #------------------------------------------- sub Form_HTML { print "*期間指定、アルファベット指定(FL FX ...)、表\示項目指定
\n"; @nen_kanji = ("年−","年"); @year_array = split(/-/, $y_array); for ($I = 0; $I <= 1; $I++) { @y_array = split(/,/, @year_array[$I]); print ""; for ($J = 1; $J <= 2; $J++) { print ""; } print @nen_kanji[$I]; } print "\n"; print "\n "; print "
(表\示 "; for ($I = 0; $I <= $#Form_checked; $I++) { print "@file_name_j[$I]"; } print "\n"; print "\n)
"; print "\n
"; } #------------------------------------------- # サーチ指定内容表示 #------------------------------------------- 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 "\n"; print "
   : @cpValue[0] - @cpValue[1] @cpValue[3]
\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";
*データを更新する
EOL print ""; print "パスワード"; print ""; } ############################################ # (仮)更新用フォーム処理 (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
EOL print "\n"; print ""; print <<"EOL";
*ソ\ートを行う意味があるのは、プライマリデータに対してのみです。 ソ\ートの際、各行の先頭項目に省略がある場合には、直前の行の先頭項目を付加してソ\ートします。

EOL print "パスワード"; print ""; } 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
EOL } ############################################ # 最終更新(action="last_up") ############################################ sub last_up { if ($in{'password'} eq $password) { open (IN, "$BaseDir/$in{'file_name'}_temp.txt"); open(OUT, "> $BaseDir/$in{'file_name'}.txt"); while ( ) { print OUT; } close(OUT); close(IN); print "*最終更新完了!

\n"; } else { print "*パスワードが一致しません。

\n"; } print "BACK\n"; } ############################################ #   HTMLヘッダー書込み  ############################################ sub HTML_Header { print "Content-type: text/html\n\n"; print <<"EOL"; $body
$html_data EOL } ############################################ #   HTMLフッター書込み  ############################################ sub HTML_Footer { print <<"EOL";
$html_foot $version EOL }