#!/usr/bin/perl
$lib_db_flg = 1;
require '/home/rexi-jp/public_html/gx/lib/scenario.pl';
require '/home/rexi-jp/public_html/gx/lib/lib.pl';
$mycgi = 'master_list.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'};
$uid = &get_usr_cookie;
$pcid = &get_pcid_cookie;
$query = CGI->new;
my @params = $query->param();#全てのパラメータ名を取得 なのでこれを$inにしてしまえば$inで使用可能
foreach my $param (@params) {
$in{$param} = $query->param($param);
}
$dbh = &connectDB($mainDB);
#$dbh_pl = &connectDB($plDB);
if ($in{'mode'} eq ''){
&list;
}
elsif ($in{'mode'} eq 'dt'){
&dt;
}
else{
&err("不正なパラメータ");
}
&disconDB($dbh);
#&disconDB($dbh_pl);
exit;
#---------------------------------------
# マスター一覧
#---------------------------------------
sub list {
# $sql = "select id,name,profile,last_update,icon from master where profile is not null and id not in ('sae','sd','system') order by last_update desc;";
$sql = "select id,name,profile,last_update,icon from master where profile is not null ";
# if ($uid ne 2){$sql .= "and id not in ('system') ";}
$sql .= "and state = 0 order by last_update desc;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:M-01
エラーが発生しました。");
foreach(@$ref) {
($msid,$msname,$profile,$last_update,$icon)=@{$_};
$sql2 = "select user_mail from masterdat where msid = '$msid' and state = 0;";
($user_mail) = &rtn_db_data('select_line',$sql2,'user');
# $ref2 = $dbh_pl->selectall_arrayref($sql2) or &err("CODE:M-02
エラーが発生しました。");
# ($user_mail)=@{$ref2->[0]};
if ($icon eq ''){$icon = "../images/npc/icon_master_def.gif";}
if (($user_mail ne '' || $msid eq 'sd' || $msid eq 'sae') && $profile ne '' && $msid ne ''){
$last_update = substr($last_update,2,8);
$last_update =~ s/\-/\//g;
if ($last_update eq ''){$last_update = "--/--/--";}
$profile = &del_tag($profile);
$profile = &newline_remove($profile);
$len1 = length ($profile);
if ($len1 > 200){
$profile = substr($profile,0,198);
if ($profile =~ /\x8F$/ or $profile =~ tr/\x8E\xA1-\xFE// % 2) {
$profile = substr($profile,0,-1);
}
$profile .= "…"
}
# $sql2 = "select count(*) from scenario where msid = '$msid' and replay is not null and type != 5;";
$sql2 = "select count(*) from scenario where ((msid = '$msid' and another is null) or another = '$msid') and apply_state = 5 and type != 5 and state = 0;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:M-03
エラーが発生しました。");
($cnt)=@{$ref2->[0]};
if ($cnt eq 0){$cnt_str = '
';}
else{$cnt_str = "リプレイ本数:$cnt本";}
# $out{'icon'} = &get_icon($msid);
$tmp .= $msid .'
';
#表示
$out{'list'} .=<<"EOT";
|
$msname |
|
$cnt_str |
最終更新日:$last_update |
$profile
| |
EOT
}
}
# &err($tmp);
&out_enc;
&html_out("ms_list01.html");
}
#---------------------------------------
# 詳細
#---------------------------------------
sub dt {
# if ($in{'id'} eq '' || $in{'id'} eq 'sae' || $in{'id'} eq 'sd' || $in{'id'} eq 'system'){&err("マスターが指定されていません。");}
if ($in{'id'} eq ''){&err("マスターが指定されていません。");}
# $sql = "select name,profile,last_update,plan,update_profile,update_plan,icon from master where id = '$in{'id'}' and id not in ('sae','system','sd');";
$sql = "select name,profile,last_update,plan,update_profile,update_plan,icon from master where id = '$in{'id'}'";
# if ($uid ne 2){$sql .= " and id not in ('system')";}
$sql .= ";";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:MD-01
エラーが発生しました。");
($out{'msname'},$out{'profile'},$out{'last_update'},$out{'plan'},$out{'update_profile'},$out{'update_plan'},$out{'icon'})=@{$ref->[0]};
if ($out{'msname'} eq ''){&err("指定されたマスターは存在しません。");}
$out{'msname'} .= " ";
# $out{'icon'} = &get_icon($in{'id'});
if ($out{'icon'} eq ''){$out{'icon'} = "../images/npc/icon_master_def.gif";}
$out{'profile'} = &newline_change($out{'profile'});
$out{'plan'} = &newline_change($out{'plan'});
$out{'last_update'} = substr($out{'last_update'},2,8);
$out{'last_update'} =~ s/\-/\//g;
if ($out{'last_update'} eq ''){$out{'last_update'} = "--/--/--";}
$out{'update_profile'} = substr($out{'update_profile'},2,8);
$out{'update_profile'} =~ s/\-/\//g;
if ($out{'update_profile'} eq ''){$out{'update_profile'} = "--/--/--";}
$out{'update_plan'} = substr($out{'update_plan'},2,8);
$out{'update_plan'} =~ s/\-/\//g;
if ($out{'update_plan'} eq ''){$out{'update_plan'} = "--/--/--";}
$sql = "select max(replay_open_date) from scenario where (msid = '$in{'id'}' or another = '$in{'id'}' or (cmid is not null and cmid = '$in{'id'}')) and replay_open_date is not null and type != 5;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:MD-02
エラーが発生しました。");
($out{'replay_open_date'})=@{$ref->[0]};
$out{'replay_open_date'} = substr($out{'replay_open_date'},2,8);
$out{'replay_open_date'} =~ s/\-/\//g;
if ($out{'replay_open_date'} eq ''){$out{'replay_open_date'} = "--/--/--";}
if ($out{'plan'} ne ''){
$out{'plan'} =<<"EOT";
雑記 ($out{'update_plan'}更新) |
|
EOT
}
#公開中シナリオ数
$sql = "select count(*) from scenario where msid = '$in{'id'}' and open_date <= now() and playing_close >= now() and type != 5 and msid != 'system' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:MD-03
エラーが発生しました。");
($out{'open_scenario_num'})=@{$ref->[0]};
#執筆中シナリオ数
$sql = "select count(*) from scenario where msid = '$in{'id'}' and playing_close <= now() and scenario_state = 2 and type != 5 and msid != 'system' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:MD-04
エラーが発生しました。");
($out{'writing_scenario_num'})=@{$ref->[0]};
#公開済みリプレイ数
$sql = "select count(*) from scenario where ((msid = '$in{'id'}' and another is null) or another = '$in{'id'}' or (cmid is not null and cmid = '$in{'id'}')) and apply_state = 5 and type != 5 and msid != 'system' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:MD-05
エラーが発生しました。");
($out{'replay_num'})=@{$ref->[0]};
#NPC
$sql = "select b.seq from masterdat a,userdat b where a.msid = '$in{'id'}' and a.user_mail = b.mail;";
($ms_seq) = &rtn_db_data('select_line',$sql,'user');
# $ref = $dbh_pl->selectall_arrayref($sql) or &err("CODE:MD-06
エラーが発生しました。");
# ($ms_seq)=@{$ref->[0]};
if ($ms_seq ne ''){
$sql = "select pcid,name,sex,class,icon,npc_info from character where substr(pcid,1,2) = 'xz' and uid = $ms_seq order by pcid;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:M-07
エラーが発生しました。");
foreach(@$ref) {
($pcid,$name1,$sex,$class,$icon,$npc_info)=@{$_};
$npc_info = &del_tag($npc_info);
$npc_info = &newline_remove($npc_info);
$len1 = length ($npc_info);
if ($len1 > 160){
$npc_info = substr($npc_info,0,178);
if ($npc_info =~ /\x8F$/ or $npc_info =~ tr/\x8E\xA1-\xFE// % 2) {
$npc_info = substr($npc_info,0,-1);
}
$npc_info .= "…"
}
if ($icon eq ''){$icon = &def_icon($class);}
$out{'npc'} .=<<"EOT";
|
|
|
$pcid $name1 @sex_mark[$sex]・@class_str[$class] |
|
|
|
|
EOT
}
}
if ($out{'npc'} ne ''){
$out{'npc'} =<<"EOT";
EOT
}
$rcnt = 0;
$sql = "select seq,title,playing_close,type,option1,option2,option3,club_seq from scenario where ((msid = '$in{'id'}' and another is null) or (another = '$in{'id'}') or (cmid is not null and cmid = '$in{'id'}')) and state = 0 and scenario_state = 2 and type != 5 and msid != 'system' order by playing_close;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:M-08
エラーが発生しました。");
foreach(@$ref) {
($seq,$title,$playing_close,$type,$option1,$option2,$option3,$club_seq)=@{$_};
if ($rcnt eq 0){$border = '';}
else{
$border=<<"EOT";
|
EOT
}
$opt = '';
$opt3 = '';
#おまかせ
if ($option1 eq 1){
$opt = '';
}
elsif ($option1 eq 2){
#お任せ&プレイング非公開
$opt = '';
}
#リアルタイム
if ($option2 eq 1){
$opt .= '';
}
if ($option3 eq 1){
$sql2 = "select name from club where seq = $club_seq;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:MD-05
エラーが発生しました。");
($club_name)=@{$ref2->[0]};
$opt3 = '('. $club_name . ')';
}
$playing_close = substr($playing_close,0,10);
$playing_close =~ s/\-/\//g;
$out{'writing_list'} .=<<"EOT";
$border
$title$opt3$dai | $playing_close | $pin$opt | @scenario_type[$type] |
EOT
$rcnt++;
}
if ($out{'writing_list'} ne ''){
$out{'writing_list'} =<<"EOT";
EOT
}
$rcnt = 0;
$sql = "select seq,title,playing_close,type,option1,option2,option3,club_seq,replay_open_date,playing_close + '-1 days' from scenario where ((msid = '$in{'id'}' and another is null) or (another = '$in{'id'}') or (cmid is not null and cmid = '$in{'id'}')) and state = 0 and scenario_state = 3 and type != 5 and msid != 'system' order by replay_open_date desc;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:M-09
エラーが発生しました。");
foreach(@$ref) {
($seq,$title,$playing_close,$type,$option1,$option2,$option3,$club_seq,$replay_open_date,$playing_close2)=@{$_};
if ($rcnt eq 0){$border = '';}
else{
$border=<<"EOT";
|
EOT
}
$opt = '';
$opt3 = '';
#おまかせ
if ($option1 eq 1){
$opt = '';
}
elsif ($option1 eq 2){
#お任せ&プレイング非公開
$opt = '';
}
#リアルタイム
if ($option2 eq 1){
$opt .= '';
}
if ($option3 eq 1){
$sql2 = "select name from club where seq = $club_seq;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:MD-05
エラーが発生しました。");
($club_name)=@{$ref2->[0]};
$opt3 = '('. $club_name . ')';
}
$sql2 = "select count(*) from scenario_pinup where scenario_seq = $seq;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:04
エラーが発生しました。");
($pcnt)=@{$ref2->[0]};
if ($pcnt > 0){$pin = '';}
else{$pin = '';}
# $replay_open_date = substr($replay_open_date,0,10);
$replay_open_date = substr($playing_close2,0,10);
$replay_open_date =~ s/\-/\//g;
$out{'replay_list'} .=<<"EOT";
$border
$title$opt3$dai | $replay_open_date | $pin$opt | @scenario_type[$type] |
EOT
$rcnt++;
}
if ($out{'replay_list'} ne ''){
$out{'replay_list'} =<<"EOT";
EOT
}
&out_enc;
&html_out("ms_list02.html");
}
#---------------------------------------
# アイコンデータ取得
#---------------------------------------
sub get_icon {
my $msid = $_[0];
if ($msid eq ''){return;}
$sql2 = "select user_mail from masterdat where msid = '$msid';";
($user_mail) = &rtn_db_data('select_line',$sql2,'user');
# $ref2 = $dbh_pl->selectall_arrayref($sql2) or &err("CODE:M-02
エラーが発生しました。");
# ($user_mail)=@{$ref2->[0]};
$sql2 = "select seq from userdat where mail = '$user_mail';";
($user_mail) = &rtn_db_data('select_line',$sql2,'user');
# $ref2 = $dbh_pl->selectall_arrayref($sql2) or &err("CODE:M-04
エラーが発生しました。");
# ($museq)=@{$ref2->[0]};
if ($museq ne ''){
$npc_ls = '';
$sql2 = "select pcid from character where usr_seq = $museq and substr(pcid,1,2) = 'jz';";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:M-05
エラーが発生しました。");
foreach(@$ref2) {
($npcid)=@{$_};
$npc_ls .= "pcid = '" . $npcid . "' or ";
}
# &err($npc_ls);
if ($npc_ls ne ''){
$npc_ls = "and (" . substr($npc_ls,0,-4) . ")";
$sql2 = "select url from stars_data where pdid = 'C02' $npc_ls order by reg_date desc limit 1;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:M-06
エラーが発生しました。");
($icon)=@{$ref2->[0]};
}
}
if ($icon eq ''){$icon = "../images/spacer.gif";}
return $icon;
}