#!/usr/bin/perl
$lib_db_flg = 1;
require '/home/rexi-jp/public_html/gx/lib/lib.pl';
$mycgi = 'stars_gallery.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;
$out{'pcid'} = $pcid;
$dbh = &connectDB($mainDB);
#$out{'rex'} = &get_rex($pcid);
if ($in{'mode'} eq ''){
&list;
}
elsif ($in{'mode'} eq 'detailed'){
&detailed;
}
elsif ($in{'mode'} eq 'creator_list'){
&creator_list;
}
elsif ($in{'mode'} eq 'product_list'){
&product_list;
}
else{
&mypage_err("不正なパラメータ");
}
&disconDB($dbh);
exit;
#---------------------------------------
# 一覧
#---------------------------------------
sub list {
if ($in{'page'} eq ''){$in{'page'} = 1;}
$sql = "select a.crid,a.pdname,a.crname,a.file_name,substr(a.reg_date,1,10),b.pcid,b.name,a.plural_pcid,a.url,a.comment from stars_data a,character b where a.state = 0 and a.pcid = b.pcid and a.crid not in('rexi','1101')";
##TEST $sql = "select a.crid,a.pdname,a.crname,a.file_name,substr(a.reg_date,1,10),b.pcid,b.name,a.plural_pcid,a.url,a.comment from stars_data a,character b where a.state = 0 and a.pcid = b.pcid ";
$sql2 = "select count(*) from stars_data a,character b where a.pcid = b.pcid and a.crid not in('rexi','1101')";
##TEST $sql2 = "select count(*) from stars_data a,character b where a.pcid = b.pcid ";
# $sql = "select a.crid,a.pdname,a.crname,a.file_name,substr(a.reg_date,1,10),b.pcid,b.name,a.plural_pcid,a.url from stars_data a,character b where a.pcid = b.pcid";
# $sql2 = "select count(*) from stars_data a,character b where a.pcid = b.pcid";
if ($in{'sort'} eq ''){
#最新順
$sql .= " order by a.reg_date desc";
$out{'title'} = "02_title_stars_saikin.gif";
$lump1 = "$mycgi?method=all";
$lump2 = "$mycgi";
}
elsif ($in{'sort'} eq 'creator'){
if ($in{'crid'} eq ''){&err("クリエーターが指定されていません。");}
$sql .= " and (a.crid = '$in{'crid'}' or a.crid2 = '$in{'crid'}') order by a.reg_date desc";
$out{'title'} = "02_title_stars_crebetu.gif";
$sql2 .= " and a.crid = '$in{'crid'}';";
$lump1 = "$mycgi?sort=creator&crid=$in{'crid'}&method=all";
$lump2 = "$mycgi?sort=creator&crid=$in{'crid'}";
}
elsif ($in{'sort'} eq 'pcid'){
if ($in{'pcid'} eq ''){&err("キャラクターが指定されていません。");}
$sql .= " and a.pcid = '$in{'pcid'}' order by a.reg_date desc";
$out{'title'} = "02_title_stars_crebetu.gif";
$sql2 .= " and a.pcid = '$in{'pcid'}';";
$lump1 = "$mycgi?sort=pcid&crid=$in{'pcid'}&method=all";
$lump2 = "$mycgi?sort=pcid&crid=$in{'pcid'}";
}
elsif ($in{'sort'} eq 'product'){
if ($in{'pdid'} eq ''){&err("商品が指定されていません。");}
$sql .= " and a.pdid = '$in{'pdid'}' order by a.reg_date desc";
$out{'title'} = "02_title_stars_sbetu.gif";
$sql2 .= " and a.pdid = '$in{'pdid'}';";
$lump1 = "$mycgi?sort=product&pdid=$in{'pdid'}&method=all";
$lump2 = "$mycgi?sort=product&pdid=$in{'pdid'}";
}
elsif ($in{'sort'} eq 'date'){
if ($in{'date'} eq ''){&err("日付が指定されていません。");}
$sql .= " and substr(a.reg_date,1,10) = '$in{'date'}' order by a.reg_date desc";
$out{'title'} = "02_title_stars_hiduke.gif";
$sql2 .= " and substr(a.reg_date,1,10) = '$in{'date'}';";
$lump1 = "$mycgi?sort=date&date=$in{'date'}&method=all";
$lump2 = "$mycgi?sort=date&date=$in{'date'}";
}
if ($in{'method'} eq 'all'){
$cloth_num = 10;
$out{'lump'} = "サムネイル表示 ";
}
else{
$cloth_num = 35;
$out{'lump'} = "一括表示 ";
}
#ページ数計算
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:S-01 エラーが発生しました。");
($cnt)=@{$ref2->[0]};
$page_cnt = int($cnt / $cloth_num);
$amari = $cnt - ($page_cnt * $cloth_num);
if ($amari > 0){$page_cnt++;}
$out{'page_str'} =<<"EOT";
<
EOT
$p_cnt = 0;
for ($i=1;$i<=$page_cnt;$i++){
if ($i ne $in{'page'}){
$i_str = &han_zen($i);
$out{'page_str'} .=<<"EOT";
$i /
EOT
$t_1 = $i / 30;
# if (int($t_1) eq $t_1){$out{'page_str'} .= "
";}
}
else{
$out{'page_str'} .=<<"EOT";
$i
/
EOT
}
chomp $out{'page_str'};
$p_cnt++;
# if ($p_cnt >= 20){
# $out{'page_str'} .= '
';
# $p_cnt = 0;
# }
}
$out{'page_str'} = substr($out{'page_str'},0,-51);
$out{'page_str'} .=<<"EOT";
>
EOT
$out{'page_str'} =<<"EOT";
EOT
$start = ($in{'page'} - 1) * $cloth_num;
if ($start eq ''){$start = 0;}
$sql .= " offset $start limit $cloth_num;";
$out{'list'} =<<"EOT";
EOT
$i = 1;
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:S-02 エラーが発生しました。");
foreach(@$ref) {
($crid,$pdname,$crname,$file_name,$reg_date,$gpcid,$pcname,$plural_pcid,$furl,$comment)=@{$_};
$len = length $crname;
if ($len > 15){
$crname = "$crname ";
}
$mem = '';
$mem2 = '';
$member = '';
if ($plural_pcid ne ''){
@mem_pcid = split(/\,/,$plural_pcid);
@mem_pcid = sort @mem_pcid;
foreach (@mem_pcid){
$mpcid = $_;
$sql = "select name from character where pcid = '$mpcid';";
$ref = $dbh->selectall_arrayref($sql) or &mypage_err("CODE:S-03 エラーが発生しました。");
($m_name)=@{$ref->[0]};
$mem .= ",$m_name($mpcid)";
$mem2 .=<<"EOT";
$m_name($mpcid )
EOT
}
if ($mem2 ne ''){$mem2 = substr($mem2,0,-2);}
}
$date2 = substr($reg_date,0,10);
if ($in{'method'} eq 'all'){
if ($mem ne ''){
$mem =~ s/\,/ /g;
$member =<<"EOT";
$mem2
EOT
}
$out{'a1'} = '';
$out{'a2'} = '';
$stars_file = "/home/rexi-jp/public_html/stars/data/gx/$file_name";
if (-e "/home/rexi-jp/public_html/stars/data/gx/$file_name"){
($format,$width,$height) = &GetImageSize("/home/rexi-jp/public_html/stars/data/gx/$file_name");
if ($width > 640){
$sfile = "/home/rexi-jp/public_html/gx/mypage/large_thum/$file_name";
if (!-e $sfile){
system "convert -resize 640 +profile iptc -quality 100% $stars_file $sfile";
}
$h = $height + 100;
$w = $width + 100;
$out{'a1'} = "";
$out{'a2'} = " ";
$out{'img'} = "./large_thum/$in{'file'}";
$gfile = "../mypage/large_thum/$file_name";
($format,$width,$height) = &GetImageSize($sfile);
$wh = " WIDTH=\"$width\" HEIGHT=\"$height\"";
}
else{
$wh = " WIDTH=\"$width\" HEIGHT=\"$height\"";
$gfile = "../../stars/data/gx/$file_name";
}
}
else{
$gfile = $furl;
$wh = '';
}
if ($crid ne '0131' && $crid ne '0482'){
$mark = " ";
}
else{
$mark = "";
}
$out{'list'} .=<<"EOT";
EOT
my ($ex) = ($gfile =~ m|(\.[^./\\]+)$|);
if(($ex eq '.MP3') or ($ex eq '.mp3') or ($ex eq '.Mp3')){
$comment_w = $comment;
$comment_w =~ s/\n/ /g;
$comment =~ s/\x0D\x0A/ /g;
$out{'list'} .=<<"EOT";
$comment_w
EOT
}else{
$out{'list'} .=<<"EOT";
$out{'a1'} $out{'a2'}
EOT
}
$out{'list'} .=<<"EOT";
$pcname($gpcid )
$member
$pdname
$crname $mark
$reg_date
EOT
}
else{
if ($i eq 1){
$out{'list'} .=<<"EOT";
EOT
}
if (-e "/home/rexi-jp/public_html/stars/data/gx/$file_name"){
($format,$width,$height) = &GetImageSize("/home/rexi-jp/public_html/stars/data/gx/$file_name");
$wh = '';
if ($width < 100 && $height < 100){$th_file = "http://rexi.jp/stars/data/gx/$file_name";}
else{
$th_file = "http://rexi.jp/stars/data/gx_thumbnail/$file_name";
($format,$twidth,$theight) = &GetImageSize("/home/rexi-jp/public_html/stars/data/gx_thumbnail/$file_name");
$wh = " WIDTH=\"$twidth\" HEIGHT=\"$theight\"";
}
}
else{
$th_file = $furl;
}
$title_name = $pcname;
if ($width > 100 && $height > 100){
# $ind = index ($ENV{'HTTP_USER_AGENT'},'MSIE 7.0');
$ind = index ($ENV{'HTTP_USER_AGENT'},'MSIE 6');
if ($ind > 0){
$link = "";
}
else{
# $link = " ";
$link = " ";
# if ($uid eq 2){$link = " ";}
}
}
else{
$link = "";
}
# }
$len = length $pcname;
if ($len > 12){
$pcname = "$pcname ";
}
$name =<<"EOT";
$pcname
EOT
# if ($uid eq 2){
if ($crid ne '0131' && $crid ne '0482'){
# $mark = " ";
$mark = "[STARS ]";
}
else{
$mark = "";
}
$out{'list'} .=<<"EOT";
EOT
my ($ex) = ($th_file =~ m|(\.[^./\\]+)$|);
if(($ex eq '.MP3') or ($ex eq '.mp3') or ($ex eq '.Mp3')){
$out{'list'} .=<<"EOT";
EOT
}else{
$out{'list'} .=<<"EOT";
$link
EOT
}
$out{'list'} .=<<"EOT";
$crname $mark
$reg_date
$gpcid
$name
EOT
# }
# else{
# $out{'list'} .=<<"EOT";
#
#
#
#EOT
# }
if ($i eq 5){
# if ($i eq 4){
$out{'list'} .=<<"EOT";
EOT
$i = 0;
}
$i++;
}
}
$out{'list'} .=<<"EOT";
EOT
&out_enc;
if ($in{'method'} eq 'all'){
$html_file = 'stars_gx_lump.html';
}
else{
$html_file = 'stars_gx.html';
}
# if ($uid eq 2){$html_file = 'stars_gx1.html';}
&html_out($html_file);
}
#---------------------------------------
# クリエーター一覧
#---------------------------------------
sub creator_list {
$dbh_stars = &connectDB('stars');
$out{'title'} = "02_title_stars_crebetu.gif";
$sql = "select crid,crname from stars_data where crid not in('rexi','1101') group by crid,crname order by max(reg_date) desc;";
##test $sql = "select crid,crname from stars_data group by crid,crname order by max(reg_date) desc;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($crid,$crname)=@{$_};
$sql2 = "select illust from sample where id = '$crid' and gid = -2 and state = 0;";
$ref2 = $dbh_stars->selectall_arrayref($sql2) or &err("エラーが発生しました。");
($icon)=@{$ref2->[0]};
if ($icon eq ''){$icon = "http://rexi.jp/images/stars/st_icon_sample.gif";}
else{$icon = "http://rexi.jp/stars/sample/$crid/$icon";}
$sql2 = "select count(*),substr(max(delivered_result_date),3,8) from reservation where crid = '$crid' and delivered_result = 3 and game = 'GX';";
$ref2 = $dbh_stars->selectall_arrayref($sql2) or &err("エラーが発生しました。");
($cnt,$last_de)=@{$ref2->[0]};
$last_de =~ s/\-/\//g;
$out{'list'} .=<<"EOT";
$crname
最新納品日:$last_de
納品数:$cnt
EOT
#$crname
}
&out_enc;
&html_out('stars_gx_crebetu.html');
&disconDB($dbh_stars);
}
#---------------------------------------
# 商品一覧
#---------------------------------------
sub product_list {
$dbh_stars = &connectDB('stars');
$sql = "select pdid,substr(max(reg_date),1,10),count(*) from stars_data where crid not in('rexi','system','1101') group by pdid order by pdid;";
###test $sql = "select pdid,substr(max(reg_date),1,10),count(*) from stars_data where crid != 'system' group by pdid order by pdid;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($pdid,$reg_date,$count)=@{$_};
$sql2 = "select pdname from goods where pdid = '$pdid';";
$ref2 = $dbh_stars->selectall_arrayref($sql2) or &err("エラーが発生しました。");
($pdname)=@{$ref2->[0]};
$reg_date =~ s/\-/\//g;
$out{'list'} .=<<"EOT";
$pdname $count $reg_date
EOT
}
&disconDB($dbh_stars);
&out_enc;
&html_out('stars_gx_pdbetu.html');
}
#---------------------------------------
# 詳細
#---------------------------------------
sub detailed {
$sql = "select a.pdname,a.crname,substr(a.reg_date,0,10),a.url,a.pcid,b.name,a.file_name from stars_data a,character b where a.file_name = '$in{'file'}' and a.pcid = b.pcid;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'pdname'},$out{'crname'},$out{'reg_date'},$furl,$spcid,$sname,$file_name)=@{$ref->[0]};
# $out{'img'} = "http://rexi.jp/stars/data/gx/$in{'file'}";
$out{'spcid'} = $spcid;
$out{'sname'} = $sname;
if (-e "/home/rexi-jp/public_html/stars/data/gx/$file_name"){
($format,$width,$height) = &GetImageSize("/home/rexi-jp/public_html/stars/data/gx/$file_name");
$out{'img'} = " ";
}
else{
$out{'img'} = " ";
}
&out_enc;
&html_out('stars_gx02.html');
}