#!/usr/bin/perl
$lib_db_flg = 1;
require '/home/rexi-jp/public_html/gx/lib/lib.pl';
require '/home/rexi-jp/public_html/gx/lib/scenario.pl';
require '/home/rexi-jp/public_html/jj/lib/mobile.pl';
$mycgi = 'opening.cgi';
$mid = $uid;
$uid = '';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use File::Basename;
$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);
}
if ($in{'seq'} eq ''){&err("不正なパラメータ");}
$dbh = &connectDB($mainDB);
#PC情報取得
#$death_flg = &death_check($pcid,$dbh);
$death_flg = 0;
($out{'name1'},$pcclass,$pcsex,$pcbirth) = &get_pcdata_cookie;
if ($pcid ne '' && $out{'name1'} eq ''){
$sql = "select name,class,sex,birth,zensin,lumina from character where pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:C-01 エラーが発生しました。");
($out{'name1'},$pcclass,$pcsex,$pcbirth,$zensin,$lumina)=@{$ref->[0]};
}
$out{'pcid'} = $pcid;
$pcicon = &def_icon($pcclass);
#if ($zensin ne ''){
# $out{'zensin'} =<<"EOT";
#
#EOT
# chomp $out{'zensin'};
# $out{'pc_zen'} = $zensin;
## $out{'img_change'} = 'img_load();';
#}
$death_flg = 0;
#$sql = "select a.type,a.title,a.text,a.comment,op_illust,a.difficulty,a.reserve_close,a.playing_close,a.member_max,b.name,a.npc,a.option1,a.option2,a.option3,a.option4,a.option5,a.option6,a.main_id,a.open_date,a.club_seq,a.category,a.npc_zensin1,a.npc_zensin2,a.another,a.cmid,a.monster,a.show_img,a.option_pet,a.option_pet_kind from scenario a,master b where a.seq = $in{'seq'} and ((a.scenario_state <= 2 and a.type != 5) or (a.scenario_state > 0 and a.type = 5)) and a.open_date <= now()";
$sql = "select a.type,a.title,a.text,a.comment,op_illust,a.difficulty,a.reserve_close,a.playing_close,a.member_max,b.name,a.npc,a.option1,a.option2,a.option3,a.option4,a.option5,a.option6,a.option7,a.main_id,a.open_date,a.club_seq,a.category,a.npc_zensin1,a.npc_zensin2,a.another,a.cmid,a.monster,a.show_img,a.option_pet,a.option_pet_kind,substr(a.open_date,1,10) from scenario a,master b where a.seq = $in{'seq'} ";
$sql .= " and ((a.scenario_state <= 2 and a.type != 5) or (a.scenario_state > 0 and a.type = 5) or (a.scenario_state > 0 and a.type = 12))";
if ($uid ne 2){$sql .= " and a.msid != 'system'";}
$sql .= " and a.state = 0 and a.msid = b.id;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:C-02 エラーが発生しました。");
($type,$out{'title'},$out{'text'},$out{'comment'},$out{'op_illust'},$difficulty,$reserve_close,$playing_close,$out{'member_max'},$out{'ms_name'},$npc,$option1,$option2,$option3,$option4,$option5,$option6,$option7,$main_id,$open_date,$club_seq,$category,$npc_zensin1,$npc_zensin2,$another,$cmid,$monster,$show_img,$option_pet,$option_pet_kind,$open_date_new)=@{$ref->[0]};
$out{'scc'} = @sc_category_str2[$category];
if ($cmid ne ''){
$sql = "select name from master where id = '$cmid';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:C-02 エラーが発生しました。");
($cmname)=@{$ref->[0]};
$out{'ms_name'} .= '&' . $cmname;
}
if ($out{'title'} eq ''){&err("該当するシナリオが見つかりませんでした。");}
if ($another ne ''){
$d_err = 0;
$sql_d = "select name from master where id = '$another';";
$ref_d = $dbh->selectall_arrayref($sql_d) or $err_d=1;
($d_name)=@{$ref_d->[0]};
if ($d_err eq 0 && $d_name ne ''){$out{'ms_name'} = $out{'ms_name'} . "(代筆:$d_name)";}
}
#if ($uid eq 2){&err("$another");}
$out{'ms_name'} = &chr_rtn($out{'ms_name'});
##$sql = "select count(*) from character where pcid = '$pcid' and admission_date >= '2012-03-12 19:00:00' and now() < '2012-04-01 00:00:00';";
$sql = "select count(*) from character where pcid = '$pcid' and admission_date >= '2012-03-12 19:00:00';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:C-02 エラーが発生しました。");
($new_school)=@{$ref->[0]};
$open_date_new =~ s/\-//g;
#if ($uid eq 2){$open_date_new = "20110401";}
##&err("if ($new_school eq 1 && $open_date_new >= 20120401){$new_school = 0;}$sql");
if ($new_school eq 1 && $open_date_new >= 20120401){$new_school = 0;}
$out{'seq'} = $in{'seq'};
$pc_death_flg = &death_check($pcid,$dbh);
if ($pc_death_flg eq 1 && $in{'mode'} ne ''){
if (&death_check($pcid,$dbh) eq 1){&err("死亡している為、このコンテンツはご利用できません。");}
}
if ($in{'mode'} eq ''){
⊤
}
elsif ($in{'mode'} eq 'bbs_say'){
&bbs_say;
}
elsif ($in{'mode'} eq 'res_del'){
&res_del;
}
elsif ($in{'mode'} eq 'meeting'){
&meeting;
}
elsif ($in{'mode'} eq 'cure'){
&cure;
}
elsif ($in{'mode'} eq 'cure_conf'){
&cure_conf;
}
elsif ($in{'mode'} eq 'cure_exe'){
&cure_exe;
}
else{
&err("不正なパラメータ$in{'mode'}");
}
&disconDB($dbh);
exit;
#---------------------------------------
# TOP表示
#---------------------------------------
sub top {
&date_rtn;
#if ($uid eq 2 && $in{'seq'} eq 32){}
$out{'type'} = @sc_type_icon[$type];
$out{'type_str'} = @scenario_type[$type];
if ($type eq 4){$out{'beginer'} = '(ビギナー)';}
$out{'difficulty'} = @dif[$difficulty];
$tmp_start = &calDate(substr($playing_close,0,4),substr($playing_close,5,2),substr($playing_close,8,2),-1);
# $out{'start'} = substr($playing_close,2,8);
# $out{'start'} = substr($tmp_start,2,8) . ' 24:00';
$out{'start'} = substr($playing_close,2,14);
# $out{'start'} = substr($tmp_start,2,8) . ' 23:55';
$out{'start'} =~ s/\-/\//g;
$out{'cost'} = @cost[$type];
if ($option2 eq 1){$out{'cost'} = $out{'cost'} + 300;}
if ($option4 eq 1){$out{'cost'} = $out{'cost'} + 500;}
$out{'text'} =~ s/\n/ /g;
$out{'text'} =~ s/\<\/H2> /\<\/H2>/g;
$out{'text'} =~ s/\<\/H1> /\<\/H1>/g;
$out{'comment'} =~ s/\n/ /g;
$open_date = substr($open_date,0,10);
$open_date =~ s/\-//g;
$open_date =~ s/\://g;
$open_date =~ s/\ //g;
#おでっくす限定コミック
if ($type eq 6 || $type eq 13){
$dbh_pl = &connectDB($plDB);
$sql = "select count(*) from ticket_password where no = 3 and contents = 'STARS' and use_uid = $uid;";
$ref = $dbh_pl->selectall_arrayref($sql) or &err("CODE:C-01 エラーが発生しました。");
($ctmp)=@{$ref->[0]};
if ($ctmp eq ''){$ctmp = 0;}
&disconDB($dbh_pl);
}
#オプション
if ($option1 > 0 || $option2 eq 1){
$out{'opt'} .=<<"EOT";
■オプション
EOT
}
if ($option1 > 0){
$out{'opt'} .=<<"EOT";
@option1_list[$option1]
EOT
}
if ($option2 eq 1){
$out{'opt'} .=<<"EOT";
リアルタイム
EOT
}
if ($option3 eq 1){
$sql = "select name from club where seq = $club_seq;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-01A エラーが発生しました。");
($club_name)=@{$ref->[0]};
$out{'club'} =<<"EOT";
部活
$club_name
EOT
$sql = "select count(*) from club_member where pcid = '$pcid' and club_seq = $club_seq and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-01B エラーが発生しました。");
($club_member_flg)=@{$ref->[0]};
if ($club_member_flg eq ''){$club_member_flg = 0;}
}
#リアルタイム
if ($option2 eq 1){
$opt .= '';
}
#おまかせ
if ($option1 eq 1){
$opt .= '';
}
elsif ($option1 eq 2){
#お任せ&プレイング非公開
$opt .= '';
}
#EX
if ($option4 eq 1){
$opt .= '';
}
#遠方
if ($option6 > 0){
$opt .=<<"EOT";
EOT
}
#学年
if ($option5 > 0){
$opt .=<<"EOT";
EOT
}
#月道
if ($option7 eq 1){
$opt .= '';
}
if ($opt ne ''){
$out{'opt_list'} =<<"EOT";
オプション
$opt
EOT
}
# if ($type ne 3){
$option_pet_str = &option_pet_rtn($option_pet);
$option_pet_kind_str = option_pet_kind_rtn($option_pet_kind,$option_pet);
if ($option_pet_kind_str ne ''){$option_pet_kind_str = '(' . $option_pet_kind_str . ')';}
$out{'opt_pet'} =<<"EOT";
ペット
$option_pet_str$option_pet_kind_str
EOT
# }
if ($npc ne ''){
@ary_npc = split(/\,/,$npc);
$out{'npc'} .=<<"EOT";
■登場NPC
EOT
$n = 0;
foreach (@ary_npc){
$npcid = $_;
chomp $npcid;
$sql = "select pcid,name,sex,birth,class,lumina,zensin,race from character where pcid = '$npcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-01 エラーが発生しました。");
($n_pcid,$n_name1,$n_sex,$n_birth,$n_class,$n_lumina,$n_zensin,$n_race)=@{$ref->[0]};
if ($show_img eq ''){
if ($n eq 0 && $npc_zensin1 ne ''){$n_zensin = $npc_zensin1;}
elsif ($n eq 1 && $npc_zensin2 ne ''){$n_zensin = $npc_zensin2;}
# if ($n eq 0 && $n_zensin ne ''){
if ($n_zensin ne '' && ($#ary_npc < 2 || $out{'zensin'} eq '')){
$n_file = "/home/rexi-jp/public_html/" . substr($n_zensin,15);
($format,$width,$height) = &GetImageSize($n_file);
$out{'zensin'} =<<"EOT";
EOT
}
}
if ($n_birth ne ''){
if($n_race ne 6){
$n_age = &calcAge($n_birth);
}else{
$n_age = '';
}
}
if ($n_age eq ''){$n_age = '?';}
if ($n_sex eq 1){$n_sex = '♂';}
elsif ($n_sex eq 2){$n_sex = '♀';}
$npc_url =<<"EOT";
$n_name1($npcid)・$n_sex・$n_age歳・@class_str[$n_class]・@lumina_str[$n_lumina]・@race_str[$n_race]
EOT
$out{'npc'} .=<<"EOT";
$npc_url
EOT
$n++;
}
}
if ($npc_zensin1 eq '' && $npc_zensin2 eq '' && $show_img eq ''){$out{'zensin'} = '';}
if ($show_img ne ''){
$n_file = "/home/rexi-jp/public_html/" . substr($show_img,15);
($format,$width,$height) = &GetImageSize($n_file);
$out{'zensin'} =<<"EOT";
EOT
}
if ($in{'seq'} eq 390){
$out{'zensin'} =<<"EOT";
EOT
}
elsif ($in{'seq'} eq 1554){
$out{'zensin'} =<<"EOT";
EOT
}
# if ($out{'zensin'} eq ''){
# @m_ary = split(/\,/,$monster);
# $mon_id = @m_ary[0];
# if (int($mon_id) < 10){$mon_id = 'xm000' . $mon_id;}
# elsif (int($mon_id) < 100){$mon_id = 'xm00' . $mon_id;}
# elsif (int($mon_id) < 1000){$mon_id = 'xm0' . $mon_id;}
# else{$mon_id = 'xm' . $mon_id;}
# $sql2 = "select url from monster_image where mon_id = '$mon_id' order by reg_date desc limit 1;";
# $ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:C-02A エラーが発生しました。");
# ($mon_url)=@{$ref2->[0]};
# if ($mon_url ne ''){
# $out{'zensin'} =<<"EOT";
#
#EOT
# }
# }
$sql = "select count(*) from scenario_member where scenario_seq = $in{'seq'} and (entry_state = 1 and reserve != 1);";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-01A エラーが発生しました。");
($mcnt)=@{$ref->[0]};
if ($mcnt eq ''){$mcnt = 0;}
$out{'now_member_num'} = $mcnt;
$out{'sup_num'} = 0;
if ($type eq 5 || $type eq 3 || $type eq 12){
$out{'member_max'} = '―';
$out{'sup_num'} = '―';
}
#サポート参加可能チェック
$s_flg = 0;
$cnt = 0;
$sql = "select a.target_pcid,b.name,b.sex,b.birth,b.icon,b.class from bonds a,character b,scenario_member c where a.pcid = '$pcid' and a.point >= 11 and a.target_pcid = b.pcid and b.state = 0 and b.pcid = c.pcid and c.scenario_seq = $in{'seq'} and c.entry_state = 1 order by a.target_pcid;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($tmps)=@{$_};
$cnt++;
}
if ($cnt > 0){$s_flg = 1;}
if ($option7 eq 1){$s_flg = 0;}
#現在のサポート参加者数
if ($type ne 3){
$sql = "select count(*) from scenario_member where scenario_seq = $in{'seq'} and entry_state = 11 and pcid is not null and pcid != '' and pcid != ' ' and pcid != 'xp0085';";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'sup_num'})=@{$ref->[0]};
if ($out{'sup_num'} eq ''){$out{'sup_num'} = 0;}
}
$tmp_reserve = $reserve_close;
$tmp_reserve =~ s/\-//g;
$tmp_reserve =~ s/\://g;
$tmp_reserve =~ s/\ //g;
$tmp_playing_close = $playing_close;
$tmp_playing_close =~ s/\-//g;
$tmp_playing_close =~ s/\://g;
$tmp_playing_close =~ s/\ //g;
$tmp_reserve_one = substr($tmp_reserve,0,8) . "010500";
$sql = "select entry_state,reserve from scenario_member where scenario_seq = $in{'seq'} and pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-02 エラーが発生しました。");
($entry_state,$reserve)=@{$ref->[0]};
if ($type ne 5 && $type ne 3 && $type ne 7 && $type ne 12){
if ($entry_state eq 1 || $entry_state eq 11){
$out{'trade'}=<<"EOT";
EOT
}
}
#他シナリオ参加中チェック
# $sql = "select count(*) from scenario_member a,scenario b where a.pcid = '$pcid' and (a.entry_state = 1 or a.reserve = 1) and a.scenario_seq = b.seq and b.playing_close = '$playing_close' and b.state = 0 and b.type != 5 and b.type != 3;";
$sql = "select count(*) from scenario_member a,scenario b where a.pcid = '$pcid' and ((a.entry_state = 1 or a.reserve = 1) or a.entry_state = 11) and a.scenario_seq = b.seq and b.playing_close = '$playing_close' and b.state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-03 エラーが発生しました。");
($s_cnt1)=@{$ref->[0]};
if ($s_cnt1 eq ''){$s_cnt1 = 0;}
if ($type eq 5 || $type eq 12){
$s_cnt1 = 0;
}
#if ($uid eq 2){&err($s_cnt1);}
$sql = "select b.playing_close + '3 days',b.title,b.playing_close from scenario_member a,scenario b where a.pcid = '$pcid' and ((a.entry_state = 1 or a.reserve = 1) or a.entry_state = 11) and a.scenario_seq = b.seq and b.type != 5 and b.type != 3 and b.state = 0 order by b.playing_close desc limit 1;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-04 エラーが発生しました。");
($limit_date,$tmp_title,$tmp_pclosed)=@{$ref->[0]};
$limit_date =~ s/\-//g;
$limit_date =~ s/\://g;
$limit_date =~ s/\ //g;
$e_pclose = substr($playing_close,0,10);
#イベントシナリオ参加チェック
$sql = "select count(*) from scenario_member a,scenario b where a.pcid = '$pcid' and ((a.entry_state = 1 or a.reserve = 1) or a.entry_state = 11) and a.scenario_seq = b.seq and b.type = 3 and substr(b.playing_close,1,10) = '$e_pclose' and b.state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-05 エラーが発生しました。");
($e_cnt)=@{$ref->[0]};
if ($e_cnt eq ''){$e_cnt = 0;}
#イベントシナリオ時他シナリオ予約中チェック
$sql = "select count(*) from scenario_member a,scenario b where a.pcid = '$pcid' and ((a.entry_state = 1 or a.reserve = 1) or a.entry_state = 11) and a.scenario_seq = b.seq and b.type != 3 and substr(b.playing_close,1,10) = '$e_pclose' and b.state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-06 エラーが発生しました。");
($e2_cnt)=@{$ref->[0]};
if ($e2_cnt eq ''){$e2_cnt = 0;}
#月道参加チェック
#既に2日以内の月道シナリオに参加していた場合
$sql = "select playing_close from scenario_member a,scenario b where a.pcid = '$pcid' and a.entry_state in (1,11) and a.scenario_seq = b.seq and b.option7 = 1 and (b.scenario_reflection = 0 or b.scenario_reflection is null) and b.scenario_state != -1;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($g_playing_close)=@{$_};
$sql2 = "select to_timestamp('$playing_close','YYYY-MM-DD HH24:MI:SS') - to_timestamp('$g_playing_close','YYYY-MM-DD HH24:MI:SS');";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:O-06 エラーが発生しました。");
($g_cnt)=@{$ref2->[0]};
$g_cnt =~ s/\ days//g;
$gdbg .= "$sql2 $g_cnt ";
if ($g_cnt > 0 && $g_cnt <= 2){
$g_flg = 1;
last;
}
}
#以後2日以内の他シナリオに参加していた場合
if ($option7 eq 1){
$sql = "select count(*) from scenario_member a,scenario b where a.pcid = '$pcid' and a.entry_state in (1,11) and a.scenario_seq = b.seq and b.playing_close > to_timestamp('$playing_close','YYYY-MM-DD HH24:MI:SS') and b.playing_close <= to_timestamp('$playing_close','YYYY-MM-DD HH24:MI:SS') + '2 days';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:C-02 エラーが発生しました。");
($g_cnt)=@{$ref->[0]};
if ($g_cnt ne '' && $g_cnt > 0){$g_flg = 2;} ##後2日以内の他シナリオに参加で月道に参加できない
}
#if ($uid eq 2){&err("$g_flg $sql");}
#ボタン
if (($entry_state eq 1 || $entry_state eq 11) && "$g_year$g_mon$g_mday$g_hour$g_min$g_sec" < $tmp_playing_close && $pc_death_flg eq 0 && $type ne 7){
if ($type ne 7){
#キュアティブチェック
$sql = "select lv from magic where pcid = '$pcid' and id = 33;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-07 エラーが発生しました。");
($kyu_lv)=@{$ref->[0]};
if ($kyu_lv ne ''){
if ($kyu_lv <= 2){$kai_rank = 1;}
elsif ($kyu_lv <= 4){$kai_rank = 2;}
elsif ($kyu_lv <= 7){$kai_rank = 3;}
elsif ($kyu_lv >= 8){$kai_rank = 4;}
$sql = "select lv from magic where pcid = '$pcid' and id = 1;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:O-07 エラーが発生しました。");
($kouup_lv)=@{$ref->[0]};
if ($kyu_lv >= 3 || ($kyu_lv <= 2 && $kouup_lv ne '' && $kouup_lv > 0)){
if ($mid eq ''){
#ボタン
$out{'cure_btn'} =<<"EOT";
EOT
}
}
}
}
if ($mid eq ''){
$out{'btn'} .=<<"EOT";