#!/usr/bin/perl require '/home/rexi-jp/public_html/jj/lib/lib.pl'; $mycgi = 'search.cgi'; use CGI; use CGI::Carp qw(fatalsToBrowser); $ip = $ENV{'REMOTE_ADDR'}; $host = gethostbyaddr(pack("C4", split(/\./, $ip)), 2); $host ||= $ENV{'REMOTE_HOST'}; $host ||= $ip; $referer=$ENV{'HTTP_REFERER'}; $script=$ENV{'SCRIPT_NAME'}; $id = $ENV{'REMOTE_USER'}; $query = CGI->new; my @params = $query->param();#全てのパラメータ名を取得 なのでこれを$inにしてしまえば$inで使用可能 foreach my $param (@params) { $in{$param} = $query->param($param); } $uid = &get_usr_cookie; $pcid = &get_pcid_cookie; if ($in{'mode'} eq ''){ &html_out("guide_kensaku.html"); exit; } $dbh = &connectDB($mainDB); if ($in{'mode'} eq 'search'){ &search; } else{ &search_err("不正なパラメータ"); } &disconDB($dbh); exit; #--------------------------------------- # エラー表示 #--------------------------------------- sub search_err { $out{'body'} = $_[0]; &out_enc; open FILE,"guide_err.html"; print $header; while(){ s/!(\w+)!/$out{$1}/g; print; } close FILE; exit; } #--------------------------------------- # HTML出力 #--------------------------------------- sub html_out { $file = $_[0]; open FILE,$file; print $header; while(){ s/!(\w+)!/$out{$1}/g; print; } close FILE; exit; } #--------------------------------------- # 検索結果表示 #--------------------------------------- sub search { &in_enc; foreach $key ( keys %in ) { if (substr($key,0,7) eq 'search_'){ $in{$key} =~ s/'//g; } } $sql = "select pcid,name1,name3,attribute,sex,birth,class,icon from character where state = 0 and substr(pcid,1,2) != 'jz' "; if ($in{'search_pcid'} ne ''){$sql .= "and pcid like '%$in{'search_pcid'}%' ";} if ($in{'search_name1'} ne ''){$sql .= "and name1 like '%$in{'search_name1'}%' ";} if ($in{'search_name2'} ne ''){$sql .= "and name3 like '%$in{'search_name2'}%' ";} #年齢 if ($in{'search_age1'} ne ''){ $s_age1 = &calBirth($in{'search_age1'}); $sql .= "and birth <= $s_age1 "; } if ($in{'search_age2'} ne ''){ $s_age2 = &calBirth($in{'search_age2'} + 1); $sql .= "and birth >= $s_age2 "; } if ($in{'search_sex_1'} ne '' && $in{'search_sex_2'} ne ''){ } else{ if ($in{'search_sex_1'} eq 1){$sql .= "and sex = 1 ";} elsif ($in{'search_sex_2'} eq 1){$sql .= "and sex = 2 ";} } # &err($sql); #出身 $s_hometown = ''; foreach $key ( keys %in ) { if (substr($key,0,16) eq 'search_hometown_'){ if ($in{$key} ne ''){ @a = (); @a = split(/\_/,$key); $s_hometown .= "'$in{$key}',"; } } } if ($s_hometown ne ''){ chop $s_hometown; $sql .= "and hometown in ($s_hometown) "; } #キャラクタークラス $s_class = ''; foreach $key ( keys %in ) { if (substr($key,0,13) eq 'search_class_'){ if ($in{$key} ne ''){ @a = (); @a = split(/\_/,$key); if (@a[2] eq 2){ $s_class .= "2,3,4,"; } elsif (@a[2] < 2){ $s_class .= "@a[2],"; } elsif (@a[2] > 2 && @a[2] <= 4){ $x = @a[2] + 2; $s_class .= "$x,"; } elsif (@a[2] eq 5){ $s_class .= "9,10,"; } } } } if ($s_class ne ''){ chop $s_class; $sql .= "and class in ($s_class) "; } #属性 if ($in{'search_atb_1'} ne '' && $in{'search_atb_2'} ne ''){ } else{ if ($in{'search_atb_1'} eq 1){$sql .= "and attribute = 1 ";} elsif ($in{'search_atb_2'} eq 1){$sql .= "and attribute = 2 ";} } # &err($sql); #立場 $s_position = ''; foreach $key ( keys %in ) { if (substr($key,0,16) eq 'search_position_'){ if ($in{$key} ne ''){ @a = (); @a = split(/\_/,$key); $s_position .= "@a[2],"; } } } if ($s_position ne ''){ chop $s_position; $sql .= "and position in ($s_position) "; } #アイコン有無 if ($in{'search_use_icon'} ne '' || $in{'search_use_icon'} eq 1){ # $sql .= "and (icon is not null or bustup1 is not null and bustup2 is not null) "; $sql .= "and icon is not null "; } $sql .= "order by pcid;"; $ref = $dbh->selectall_arrayref($sql) or &search_err("エラーが発生しました。"); if ($in{'search_icon'} eq 1 || $in{'search_use_icon'} eq 1){ $out{'body'} .=<<"EOT"; EOT } $cnt = 0; foreach(@$ref) { ($s_pcid,$s_name1,$s_name3,$s_attribute,$s_sex,$s_birth,$s_class,$s_icon)=@{$_}; $s_age = &calcAge($s_birth); if ($in{'search_icon'} ne 1 && $in{'search_use_icon'} eq ''){ $out{'body'} .=<<"EOT"; $s_pcid $s_name1($s_name3)・@atb_str[$s_attribute]・@sex_mark[$s_sex]・$s_age・@class_str2[$s_class] EOT } else{ if ($s_icon eq ''){$s_icon = &def_icon($s_class,$s_attribute,$s_sex);} $out{'body'} .=<<"EOT"; $s_pcid $s_name1($s_name3)・@atb_str[$s_attribute]・@sex_mark[$s_sex]・$s_age・@class_str2[$s_class] EOT } $cnt++; } if ($in{'search_icon'} eq 1 || $in{'search_use_icon'} eq 1){ $out{'body'} .=<<"EOT"; EOT } if ($cnt eq 0){&search_err("ごめんなさい! 該当する方はいらっしゃらないようです。もう一度、検索条件を修正してから試してみてくださいね。申し訳ありません。");} &out_enc; &html_out("guide_kekka.html"); }