#! /usr/local/bin/perl # # id=kensaku6.cgi (kensaku5にソート機能を追加したもの) # # update. 01.9.16 # 表形式表示(エクセル出力のデータを読む) # 改ページ機能付き # 区切り記号をタブにすれば簡単に読み、項目に分けることができます。 # ここでは、1行目に項目名が入っている形で処理しています。 # もし、データだけならば プログラムの中で項目名をSJISに変換させて # から使用すること # 1ページを10件とする $max=10; # ファイル名 $file = "/dialup/chichibu/cgi-bin/kensaku2.txt"; $reload = 'http://www0.kumagaya.or.jp/cgi-bin/users/chichibu/kensaku6.cgi'; # 文字コード変換用 require 'cgi-lib.pl'; require 'jcode.pl'; &ReadParse; # 共通処理として現在頁番号を受け取る $page=$in{'page'}; $a='あ,い,う,え,お,を,ア,イ,ウ,エ,オ,ヲ'; @t1=split(/,/,$a); $a='か,き,く,け,こ,が,ぎ,ぐ,げ,ご,カ,キ,ク,ケ,コ,ガ,ギ,グ,ゲ,ゴ'; @t2=split(/,/,$a); $a='さ,し,す,せ,そ,ざ,じ,ず,ぜ,ぞ,サ,シ,ス,セ,ソ,ザ,ジ,ズ,ゼ,ゾ'; @t3=split(/,/,$a); $a='た,ち,つ,て,と,ダ,ヂ,ヅ,デ,ド'; @t4=split(/,/,$a); $a='な,に,ぬ,ね,の,ナ,ニ,ヌ,ネ,ノ'; @t5=split(/,/,$a); $a='は,ひ,ふ,へ,ほ,ば,び,ぶ,べ,ぼ,ぱ,ぴ,ぷ,ぺ,ぽ,ハ,ヒ,フ,ヘ,ホ,バ,ビ,ブ,ベ,ボ,パ,ピ,プ,ペ,ポ'; @t6=split(/,/,$a); $a='ま,み,む,め,も,マ,ミ,ム,メ,モ'; @t7=split(/,/,$a); $a='や,ゆ,よ,ヤ,ユ,ヨ'; @t8=split(/,/,$a); $a='ら,り,る,れ,ろ,ラ,リ,ル,レ,ロ'; @t9=split(/,/,$a); $a='わ,ん,ワ,ン'; @t10=split(/,/,$a); #################################### # # # メインルーチン(処理の分岐) # # # #################################### # 全体の流れを決定する if ($in{'action'} eq 'kensaku') { ✓ } elsif ($in{'action'} eq 'first') { &first; } elsif ($in{'action'} eq 'next') { &next; } elsif ($in{'action'} eq 'back') { &back; } elsif ($in{'action'} eq 'last') { &last; } else { &entry; } # なくても良いが最終出口を示す exit; ############################################# # # # 検索条件入力画面を表示する    # # # ############################################# sub entry { # 表示出力処理 print "Content-type: text/html\n\n"; print ''; $a="住所録検索"; &jcode'convert(*a,'sjis'); print ''.$a.''; print ''."\n"; $a="住所録の検索"; &jcode'convert(*a,'sjis'); print '

'.$a.'

'."\n"; print '
' . "\n"; print '' . "\n"; $a="読みがなの選択"; &jcode'convert(*a,'sjis'); print "

$a\n"; print '

'; print '
'; $a="検索文字"; &jcode'convert(*a,'sjis'); print '

'.$a.'
'; print '

' . "\n"; $a="検索開始"; &jcode'convert(*a,'sjis'); print '

' . "\n"; $a="取消"; &jcode'convert(*a,'sjis'); print '

' . "\n"; print '
'; print ''."\n"; } # end of entry ############################################# # # # 検索条件チェックルーチン       # # # ############################################# sub check { # 入力データに関してチェックするならここに入れる # チェック通過 # 最初は1ページをセットする $page=1; &main; } ############################################# # # # チェックエラー表示画面ルーチン    # # # ############################################# sub error { # &error(xx); で呼び出されたルーチンは、()内の数字が $error に代入される。 $error = $_[0]; if ($error eq "0") { $a="検索データが入力されていません。"; &jcode'convert(*a,'sjis'); $error_msg = $a; } print "Content-type: text/html\n\n"; print '' . "\n"; print '' . "\n"; $a="検索条件の入力で下記のエラーが発生しました"; &jcode'convert(*a,'sjis'); print '

'.$a.'

' . "\n"; print '

'; print "$error_msg\n"; print '

'; # リロードでもどると入力データが消えてしまうので $a="ブラウザ画面の戻るをクリックする"; &jcode'convert(*a,'sjis'); print "$a\n"; print '' . "\n"; # サブルーチンからプログラムを抜けるので exit; } # end of error ############################################# # # # データを読む           # # # ############################################# sub read { open(DB,"$file"); flock(DB,2); $i=0; $j=0; # 配列の初期化 @data=(); while () { # 1行目から見出しをとりだし、その後配列から見出しをカットする $i++; # 名前、電話番号、FAX、住所、道順、ふりがな if ($i == 1) { ($m1,$m2,$m3,$m4,$m5,$m6) = split(/\t/,$_); # 1行目に項目名が入っているので別処理をする # SJISに合わせる $m0=""; &jcode'convert(*m0,'sjis'); &jcode'convert(*m1,'sjis'); &jcode'convert(*m2,'sjis'); &jcode'convert(*m3,'sjis'); &jcode'convert(*m4,'sjis'); &jcode'convert(*m5,'sjis'); } else { $bundt = $_; &bunkai; # 検索条件なしは全件表示 # ここでは1データに対して文字検索をしているが、名前やふりがなに対しての # 検索なら、$_を$dt1または$dt6に変える if ($sel eq "0" && length($keywd) == 0 ) { &tb_set } # ふりがな検索だけ if ($sel ne "0" && length($keywd) == 0 ) { &mojicheck; if ($flg == 1) { &tb_set } } # 文字検索だけ if ($sel eq "0" && length($keywd) > 0 ) { if ($_ =~ /$keywd/) { &tb_set} } # ふりがな検索と文字検索の両方 if ($sel ne "0" && length($keywd) > 0 ) { &mojicheck; if ($flg == 1 && $_ =~ /$keywd/) { &tb_set } } } # else } # end of while flock(DB,8); close(DB); # データ数 $cnt=@data; # 最終ページ数 $page_max = (($cnt-1) / $max) + 1; # 整数部をとりだす ($page_max,$dummy)=split(/\./,$page_max); # ふりがなを50音順でソートする @new = sort mojisort keys(%sort); # 50音順で並び替えたもの $i=0; @data=(); foreach(@new) { $data[$i]=$sort{$_}; $i++; } # foreach } # end of read # #  配列セット処理 # sub tb_set { # データを格納 $data[$j]=$_ ; # 名前を50音順に並び替えさせるための配列を作る $k="$dt6\0$j"; $sort{$k}=$_; $j++ } # 文字としてのソート(昇順) sub mojisort {$a cmp $b; } #################################################### # ふりがなの先頭文字が配列と一致するか調べる # #################################################### sub mojicheck { $b=$dt6; &jcode'convert(*b,'euc'); if ($sel eq "1") { @tb=@t1 } elsif ($sel eq "2") { @tb=@t2 } elsif ($sel eq "3") { @tb=@t3 } elsif ($sel eq "4") { @tb=@t4 } elsif ($sel eq "5") { @tb=@t5 } elsif ($sel eq "6") { @tb=@t6 } elsif ($sel eq "7") { @tb=@t7 } elsif ($sel eq "8") { @tb=@t8 } elsif ($sel eq "9") { @tb=@t9 } elsif ($sel eq "10") { @tb=@t10 } # あったら、1を返す $flg=0; foreach $a(@tb) { &jcode'convert(*a,'euc'); if ($b =~ /^$a/) { $flg=1; return } } # foreach } # mojicheck ################################# # hiddenパラメータ共通項目  # ################################# sub hidpara { print ''."\n"; print ''."\n"; print ''."\n"; } # end of hidpara ######################## #            # # 項目分解ルーチン   # #            # ######################## sub bunkai { # 名前、電話、FAX、住所、道順、ふりがな ($dt1,$dt2,$dt3,$dt4,$dt5,$dt6) = split(/\t/,$bundt); #&jcode'convert(*dt1,'sjis'); #&jcode'convert(*dt2,'sjis'); #&jcode'convert(*dt3,'sjis'); #&jcode'convert(*dt4,'sjis'); #&jcode'convert(*dt5,'sjis'); #&jcode'convert(*dt6,'sjis'); } # end of bunkai ############################################# # # # メイン処理         # # # ############################################# sub main { $sel=$in{'sel'}; $keywd=$in{'keywd'}; &read; # 表示出力処理 print "Content-type: text/html\n\n"; print < EOM # 該当データが0件の場合 if ($cnt == 0) { print '

'; $a="表示データはありません"; &jcode'convert(*a,'sjis'); print '
'.$a.'
'."\n"; return } # end of if # 該当データがあるとき print ''; print ''; $a1="登録件数"; &jcode'convert(*a1,'sjis'); $a2="表示頁"; &jcode'convert(*a2,'sjis'); $a3="最終頁"; &jcode'convert(*a3,'sjis'); # 見出し行 print "\n"; # 1ページしかないなら、なにもいらない if ($page_max > 1) { # 最初のページ if ($page > 2) { print "\n"; } # 前ページ if ($page > 1) { print "\n"; } # 次ページ if ($page < $page_max) { print "\n"; } # 最終ページ if ($page < $page_max) { print "\n"; } } # if print "\n"; print ''; print "\n"; print "\n"; # 1ページしかないなら、なにもいらない if ($page_max > 1) { # 最初のページ if ($page > 2) { print ''; } # end of if # 前ページ if ($page > 1) { print ''; } # end of if # 次ページ if ($page < $page_max) { print ''; } # 最終ページ if ($page < $page_max) { print ''; } } # if print '
'; print ''."\n"; $a="住所録"; &jcode'convert(*a,'sjis'); print "$a\n"; print '$a1$a2$a3
'; print '
' . "\n"; $a="最初に戻る"; &jcode'convert(*a,'sjis'); print '' . "\n"; print '
' . "\n"; print '
$cnt$page$page_max'; print '
' . "\n"; print '' . "\n"; &hidpara; $a="1ページ"; &jcode'convert(*a,'sjis'); print '' . "\n"; print '
'; print '
'; print '
' . "\n"; print '' . "\n"; &hidpara; $a="前頁"; &jcode'convert(*a,'sjis'); print '' . "\n"; print '
'; print '
'; print '
' . "\n"; print '' . "\n"; &hidpara; $a="次頁"; &jcode'convert(*a,'sjis'); print '' . "\n"; print '
'. "\n"; print '
'; print '
' . "\n"; print '' . "\n"; &hidpara; print ''."\n"; $a="最終頁"; &jcode'convert(*a,'sjis'); print '' . "\n"; print '
'. "\n"; print '
'."\n"; &display; } # end of main ########################## #            # #  詳細表示ルーチン  # #            # ########################## sub display { print "\n"; print "\n"; # 行数分だけ繰り返す for($i=1; $i<=$max; $i++) { # 1列目はページカウンタ*行数+$i $lno=$max * ($page - 1) + $i; $no=$lno-1; # 項目分解処理 $bundt=$data[$no]; &bunkai; print ''; print ''."\n"; # 名前 print ''."\n"; # 電話 print ''."\n"; # FAX print ''."\n"; # 住所 print ''."\n"; # 道順 print ''."\n"; print ''; # 最終データを表示したら抜ける if ($lno >= $cnt) { last } } # end of for print '
$m0$m1$m2$m3$m4$m5
'.$lno.''.$dt1.'
'.$dt6.''."\n"; print '
'.$dt2.''."\n"; print ''.$dt3.''."\n"; print ''.$dt4.''."\n"; print ''.$dt5.''."\n"; print '
'; print "\n"; } # end of display ########################################## # # # 1ページ表示処理         # # # ########################################## sub first { $page=1; &main; } # end of sub ########################################## # # # 前ページ表示処理         # # # ########################################## sub back { $page--; &main; } # end of sub ########################################## # # # 次ページ表示処理         # # # ########################################## sub next { $page++; &main; } # end of sub ########################################## # # # 最終ページ表示処理        # # # ########################################## sub last { $page=$in{'page_max'}; &main; } # end of sub ################## end of script ##################