){
s/!(\w+)!/$out{$1}/g;
print;
}
close FILE;
exit;
}
#---------------------------------------
# TOP表示
#---------------------------------------
sub top {
$num = 0;
$prv_id = '';
$idx = 0;
$sql = "select a.id,a.file_name,a.comment,a.pcid,b.name,a.upd_date from borrowed a,character b where a.no = 1 and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01
エラーが発生しました。");
foreach(@$ref) {
($id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$idx} = $id;
$hash_file_name{$idx} = $file_name;
$hash_comment{$idx} = $comment;
$hash_fpcid{$idx} = $fpcid;
$hash_nm{$idx} = $nm;
$hash_upd_date{$idx} = $upd_date;
$hash_game{$idx} = 'gx';
$idx++;
}
$dbh_jj = &connectDB('jj');
$sql = "select a.id,a.file_name,a.comment,a.pcid,b.name3 || '/' || b.name1,a.upd_date from borrowed a,character b where a.no = 2 and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh_jj->selectall_arrayref($sql) or &err("CODE:B-01
エラーが発生しました。");
foreach(@$ref) {
($id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$idx} = $id;
$hash_file_name{$idx} = $file_name;
$hash_comment{$idx} = $comment;
$hash_fpcid{$idx} = $fpcid;
$hash_nm{$idx} = $nm;
$hash_upd_date{$idx} = $upd_date;
$hash_game{$idx} = 'jj';
$idx++;
}
@keys = sort {
$hash_upd_date{$a} cmp $hash_upd_date{$b}
} keys %hash_upd_date;
# foreach $key ( keys %hash_upd_date ) {
foreach(@keys){
$key = $_;
$id = $hash_id{$key};
$file_name = $hash_file_name{$key};
$comment = $hash_comment{$key};
$fpcid = $hash_fpcid{$key};
$nm = $hash_nm{$key};
$upd_date = $hash_upd_date{$key};
$game = $hash_game{$key};
if ($i{$id} eq '' || $i{$id} eq 0){$out{$id} .= "";}
# if ($prv_id eq '' || $prv_id ne $id){
# if ($i{$prv_id} > 0){
# for($x=$i{$prv_id};$x<5;$x++){
# $out{$prv_id} .= "
| ";
# }
# $out{$prv_id} .= "
";
# }
# $num = 0;
# }
# $num++;
if ($number{$id} eq ''){$number{$id} = 1;}
else{$number{$id}++;}
$prv_id = $id;
# ($format,$width,$height) = &GetImageSize("/home/rexi-jp/public_html/jj/scenario/jw09/borrowed/$id/sum_$file_name");
if ($game eq 'jj'){
$img_sum = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/sum_$file_name";
$img_big = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/$file_name";
$myp_link = "mypage('http://rexi.jp/jj/mypage.cgi?pcid=$fpcid','mypage','scrollbars=yes,width=680,height=800')";
}
elsif ($game eq 'gx'){
$img_sum = "./borrowed/$id/sum_$file_name";
$img_big = "./borrowed/$id/$file_name";
$myp_link = "MypageOpen('$fpcid');";
}
$out{$id} .=<<"EOT";
$number{$id} |
|
$nm($fpcid) |
$comment |
|
EOT
$i{$id}++;
if ($i{$id} eq 5){
$i{$id} = 0;
$out{$id} .= "";
}
}
# if ($i{$id} > 0){
# for($x=$i{$id};$x<5;$x++){
# $out{$id} .= "
| ";
# }
# $out{$id} .= "";
# }
for($y=1;$y<=30;$y++){
if ($out{$y} eq ''){
$out{$y} =<<"EOT";
投稿データはありません。 |
EOT
}
else{
$e1 = int($number{$y} / 5);
$e2 = $number{$y} - ($e1 * 5);
if ($e2 > 0){
for($x=$e2;$x<5;$x++){
$out{$y} .= "
| ";
}
$out{$y} .= "";
}
}
}
$html_file = "xh05_borrowed_top.html";
if ($in{'page'} eq 2){$html_file = "xh05_borrowed_top02.html";}
elsif ($in{'page'} eq 3){$html_file = "xh05_borrowed_top03.html";}
elsif ($in{'page'} eq 4){$html_file = "xh05_borrowed_top04.html";}
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# FORM表示
#---------------------------------------
sub form {
$sql = "select file_name,comment from borrowed where no = 1 and id = $in{'id'} and pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($file_name,$comment)=@{$ref->[0]};
if ($file_name ne '' && $comment ne ''){
$out{'img'} =<<"EOT";
EOT
$out{'comment'} = $comment;
}
$html_file = "borrowed01.html";
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# 送信確認
#---------------------------------------
sub send_conf {
if ($in{'comment'} eq ''){&err("コメントが入力されていません。");}
$tmp = length($in{'comment'});
if ($tmp > 40){&err("コメントは全角20字までです。");}
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$yyyymmddJ = sprintf("%04d%02d%02d$hour$min$sec", $year + 1900, $mon +1, $mday);
if ($in{'photo'} eq ''){&err("ファイルが指定されていません。");}
my ($ex) = ($in{'photo'} =~ m|(\.[^./\\]+)$|);
$fname = $pcid . "_" . $yyyymmddJ . $ex;
$out{'fname'} = $fname;
$tmp_file = "/home/rexi-jp/public_html/gx/event/tmp/" . $fname;
# $rtn = &upload($tmp_file,$in{'photo'});
$rtn = &upload($tmp_file,$photo);
if ($rtn ne 0){&err($rtn);}
($format,$width,$height) = &GetImageSize($tmp_file);
$html_file = "borrowed02.html";
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# 送信
#---------------------------------------
sub sending {
if ($in{'fname'} eq ''){&err("ファイルが指定されていません。");}
$sql = "select reg_date from borrowed where no = 1 and id = $in{'id'} and pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。".$dbh->errstr);
($reg_date)=@{$ref->[0]};
if ($reg_date eq ''){
$sql = "insert into borrowed (no,id,pcid,file_name,comment) values (1,$in{'id'},'$pcid','$in{'fname'}','$in{'comment'}');";
}
else{
$sql = "update borrowed set file_name = '$in{'fname'}',comment = '$in{'comment'}',upd_date = now() where no = 1 and id = $in{'id'} and pcid = '$pcid';";
}
$dbh->do($sql) or &err("エラーが発生しました。
".$dbh->errstr);
$tmp_file = "/home/rexi-jp/public_html/gx/event/tmp/" . $in{'fname'};
$sum_file = $entry_dir . "sum_" . $in{'fname'};
#リサイズ
($format,$width,$height) = &GetImageSize($tmp_file);
if ($width > $height){
$rtn = &img_resize($tmp_file,$sum_file,140);
}
else{
$rtn = &img_resize($tmp_file,$sum_file,undef,140);
}
if ($rtn ne 0){&err("リサイズ処理にてエラーが発生しました。");}
#ファイル移動
$mv_file = $entry_dir . $in{'fname'};
move $tmp_file, $mv_file or die &err("ファイル処理にてエラーが発生しました。
$tmp_file, $mv_file");
print "Location: ./borrowed_end.html\n\n";
}
#---------------------------------------
# 画像アップロード
#---------------------------------------
sub upload {
#ファイル名確定(ここでは一時ファイル)
$outputfile = $_[0];
$chkfile = $_[1];
#サイズ等確認表示のため、一時読み込み
open(FILE, ">$outputfile") or die &err("ファイルアップロードでエラーが発生しました。");
flock(FILE, 2);#読み込み中ロック
if (defined $chkfile) { #NULLにならない限り繰り返し(と考えとこう)
while (<$chkfile>) {
print FILE $_; #受け取ったものを書込み
}
}
close FILE;
#サイズ取得
my @chksize = stat $outputfile;
$chksize=@chksize[7];
($format,$width,$height) = &GetImageSize($outputfile);
if(substr($format,0,4) ne 'JPEG' && substr($format,0,3) ne 'GIF' && substr($format,0,3) ne 'PNG'){
return "アップロード出来るファイル形式ではありません。$format"; #アップロード出来るファイル形式ではありません。
}
if($chksize <= 0){
$unlinkcount = unlink $outputfile;
&err("アップロード時にエラーが発生しました。");
}
return 0;
}
#---------------------------------------
# 投票
#---------------------------------------
sub post_form {
$out{'title'} = @odai[$in{'id'}];
$num = 0;
$tid = 1;
$sql = "select a.oid,a.id,a.file_name,a.comment,a.pcid,b.name,a.upd_date from borrowed a,character b where a.no = 1";
if ($in{'id'} ne 0){$sql .= " and a.id = $in{'id'}";}
$sql .= " and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01
エラーが発生しました。");
foreach(@$ref) {
($oid,$id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$idx} = $id;
$hash_file_name{$idx} = $file_name;
$hash_comment{$idx} = $comment;
$hash_fpcid{$idx} = $fpcid;
$hash_nm{$idx} = $nm;
$hash_upd_date{$idx} = $upd_date;
$hash_game{$idx} = 'gx';
$hash_oid{$idx} = 'gx' . $oid;
$idx++;
}
$dbh_jj = &connectDB('jj');
$sql = "select a.oid,a.id,a.file_name,a.comment,a.pcid,b.name3 || '/' || b.name1,a.upd_date from borrowed a,character b where a.no = 2";
if ($in{'id'} ne 0){$sql .= " and a.id = $in{'id'}";}
$sql .= " and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh_jj->selectall_arrayref($sql) or &err("CODE:B-01
エラーが発生しました。");
foreach(@$ref) {
($oid,$id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$idx} = $id;
$hash_file_name{$idx} = $file_name;
$hash_comment{$idx} = $comment;
$hash_fpcid{$idx} = $fpcid;
$hash_nm{$idx} = $nm;
$hash_upd_date{$idx} = $upd_date;
$hash_game{$idx} = 'jj';
$hash_oid{$idx} = 'jj' . $oid;
$idx++;
}
@keys = sort {
$hash_upd_date{$a} cmp $hash_upd_date{$b}
} keys %hash_upd_date;
# $sql = "select a.file_name,a.comment,a.pcid,b.name1,b.name3,b.attribute from borrowed a,character b where a.no = 1 and a.id = $in{'id'} and a.state = 0 and a.pcid = b.pcid order by a.id,a.upd_date;";
if ($in{'id'} eq 0){
$out{'title'} = '新春初笑賞';
$out{'cout'} = '
※「新春初笑賞」は必ず3つ選択してください。
';
# $sql = "select a.file_name,a.comment,a.pcid,b.name1,b.name3,b.attribute,a.id,a.oid from borrowed a,character b where a.no = 1 and a.state = 0 and a.pcid = b.pcid order by a.id,a.upd_date;";
}
# $ref = $dbh->selectall_arrayref($sql) or &err("CODE:PF-01
エラーが発生しました。");
# foreach(@$ref) {
# ($file_name,$comment,$fpcid,$nm1,$nm3,$atb,$id,$oid)=@{$_};
foreach(@keys){
$key = $_;
$id = $hash_id{$key};
$file_name = $hash_file_name{$key};
$comment = $hash_comment{$key};
$fpcid = $hash_fpcid{$key};
$nm = $hash_nm{$key};
$upd_date = $hash_upd_date{$key};
$game = $hash_game{$key};
$oid = $hash_oid{$key};
# ($format,$width,$height) = &GetImageSize("/home/rexi-jp/public_html/jj/scenario/jw09/borrowed/$id/sum_$file_name");
if ($game eq 'jj'){
$img_sum = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/sum_$file_name";
$img_big = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/$file_name";
$myp_link = "mypage('http://rexi.jp/jj/mypage.cgi?pcid=$fpcid','mypage','scrollbars=yes,width=680,height=800')";
}
elsif ($game eq 'gx'){
$img_sum = "./borrowed/$id/sum_$file_name";
$img_big = "./borrowed/$id/$file_name";
$myp_link = "MypageOpen('$fpcid');";
}
$atb = @atb_str[$atb];
if ($in{'id'} ne 0){$id_dir = $in{'id'};}
elsif ($in{'id'} eq 0){$id_dir = $id;}
if ($num eq 0){$out{'list'} .= "";}
$out{'list'} .=<<"EOT";
|
EOT
}
else{
$out{'list'} .=<<"EOT";
|
EOT
}
$num++;
$tid++;
if ($num eq 5){
$num = 0;
$out{'list'} .= "";
}
}
if ($num > 0){
for($x=$num;$x<5;$x++){
$out{'list'} .= "
| ";
}
$out{'list'} .= "";
}
$html_file = "borrowed_post01.html";
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# 投票確認
#---------------------------------------
sub post_conf {
$sql = "select a.id,a.file_name,a.comment,a.pcid,b.name,a.upd_date from borrowed a,character b where a.no = 1";
if ($in{'id'} ne 0){$sql .= " and a.id = $in{'id'}";}
$sql .= " and a.pcid = '$in{'post_pcid'}' and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01
エラーが発生しました。");
foreach(@$ref) {
($id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$fpcid} = $id;
$hash_file_name{$fpcid} = "./borrowed/$id/$file_name";
$hash_comment{$fpcid} = $comment;
$hash_fpcid{$fpcid} = $fpcid;
$hash_nm{$fpcid} = $nm;
$hash_upd_date{$fpcid} = $upd_date;
$hash_game{$fpcid} = 'gx';
$idx++;
}
$dbh_jj = &connectDB('jj');
$sql = "select a.id,a.file_name,a.comment,a.pcid,b.name3 || '/' || b.name1,a.upd_date from borrowed a,character b where a.no = 2";
if ($in{'id'} ne 0){$sql .= " and a.id = $in{'id'}";}
$sql .= " and a.pcid = '$in{'post_pcid'}' and a.pcid = b.pcid order by a.id,a.upd_date;";
$ref = $dbh_jj->selectall_arrayref($sql) or &err("CODE:B-01B
エラーが発生しました。");
foreach(@$ref) {
($id,$file_name,$comment,$fpcid,$nm,$upd_date)=@{$_};
$hash_id{$fpcid} = $id;
$hash_file_name{$fpcid} = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/$file_name";
$hash_comment{$fpcid} = $comment;
$hash_fpcid{$fpcid} = $fpcid;
$hash_nm{$fpcid} = $nm;
$hash_upd_date{$fpcid} = $upd_date;
$hash_game{$fpcid} = 'jj';
$idx++;
}
if ($in{'id'} ne 0){
$out{'title'} = @odai[$in{'id'}];
# $sql = "select a.file_name,a.comment,a.pcid,b.name1,b.name3,b.attribute from borrowed a,character b where a.no = 1 and a.id = $in{'id'} and a.state = 0 and a.pcid = '$in{'post_pcid'}' and a.pcid = b.pcid;";
# $ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
# ($out{'file_name'},$out{'comment'},$out{'fpcid'},$out{'nm1'},$out{'nm3'},$atb,$id,$oid)=@{$ref->[0]};
$out{'file_name'} = $hash_file_name{$in{'post_pcid'}};
$out{'comment'} = $hash_comment{$in{'post_pcid'}};
$out{'fpcid'} = $hash_fpcid{$in{'post_pcid'}};
$out{'nm'} = $hash_nm{$in{'post_pcid'}};
if ($out{'file_name'} eq ''){&err("不正な指定です。");}
$out{'atb'} = @atb_str[$atb];
}
else{
$out{'title'} = '新春初笑賞';
$k = 0;
$dbh_jj = &connectDB('jj');
foreach $key ( keys( %in ) ) {
if (substr($key,0,4) eq 'oid_' && $in{$key} ne '' && $in{$key} ne 0){
$k++;
$oid = $in{$key};
$game = substr($oid,0,2);
$oid = substr($oid,2);
if ($game eq 'jj'){
$sql = "select a.file_name,a.comment,a.pcid,b.name3 || '/' || b.name1,b.attribute,a.id from borrowed a,character b where a.no = 2 and a.oid = $oid and a.state = 0 and a.pcid = b.pcid;";
$ref = $dbh_jj->selectall_arrayref($sql) or &err("エラーが発生しました。");
($file_name,$comment,$fpcid,$nm,$atb,$id)=@{$ref->[0]};
$atb = @atb_str[$atb];
$img_sum = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/sum_$file_name";
$img_big = "http://rexi.jp/jj/scenario/gi/gi05/borrowed/$id/$file_name";
$myp_link = "mypage('http://rexi.jp/jj/mypage.cgi?pcid=$fpcid','mypage','scrollbars=yes,width=680,height=800')";
}
elsif ($game eq 'gx'){
$sql = "select a.file_name,a.comment,a.pcid,b.name,'―',a.id from borrowed a,character b where a.no = 1 and a.oid = $oid and a.state = 0 and a.pcid = b.pcid;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($file_name,$comment,$fpcid,$nm,$atb,$id)=@{$ref->[0]};
$img_sum = "./borrowed/$id/sum_$file_name";
$img_big = "./borrowed/$id/$file_name";
$myp_link = "MypageOpen('$fpcid');";
}
$out{'file_img'} .=<<"EOT";
$nm($fpcid)・$atb
EOT
}
}
if ($k > 3){&err("新春初笑賞は3つまでしか選べません。");}
elsif ($k < 3){&err("新春初笑賞は必ず3つ選んでください。");}
}
if ($in{'id'} ne 0){
$out{'id_dir'} = $in{'id'};
$html_file = "borrowed_post02.html";
}
elsif ($in{'id'} eq 0){
$out{'id_dir'} = $id;
$out{'fpcid'} = $oid;
$html_file = "borrowed_post02a.html";
}
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# 投票実行
#---------------------------------------
sub post_send {
if ($in{'id'} ne 0 && $in{'fpcid'} eq ''){&err("投票する画像が選択されていません。");}
if ($in{'id'} eq ''){&err("お題が選択されていません。");}
if ($in{'id'} ne 0){
$sql = "insert into borrowed_poll (no,id,uid,post_pcid,ip,host) values (1,$in{'id'},$uid,'$in{'fpcid'}','$ip','$host');";
}
elsif ($in{'id'} eq 0){
$sql = "insert into borrowed_poll (no,id,uid,ip,host,sinsyun1,sinsyun2,sinsyun3) values (1,$in{'id'},$uid,'$ip','$host',$in{'oid_1'},$in{'oid_2'},$in{'oid_3'});";
#&err($sql);
}
$dbh->do($sql) or &err("エラーが発生しました。");
print "Location: ./borrowed_post_end.html\n\n";
}