#!/usr/bin/perl -w use strict; $|=1; use EVEcommon; use POSIX qw(strftime); use Time::HiRes qw ( time ); my $begin = time; use CGI qw/ :standard /; my $debug = param("debug") || url_param("debug") || 0; my $interval = "1 DAY"; my $i = param("i"); if (defined $i && $i =~ /^(\d+)d$/) { $interval = "$1 DAY"; } unless ($ENV{REMOTE_ADDR} =~ /^(10|192)\./) { print header,start_html("yeah, right..."),"\n", h1("year, right..."),"\n", end_html; exit 0; } my $opt_d = 'eve'; my $opt_u = 'eve'; my ($opt_p, $opt_h,); use Getopt::Long qw(:config no_ignore_case bundling); GetOptions( 'd=s' => \$opt_d, # db name 'u=s' => \$opt_u, # db user 'p=s' => \$opt_p, # db pass 'h=s' => \$opt_h, # html output file ); use DBI; my $dbh = DBI->connect("DBI:mysql:database=$opt_d", $opt_u, $opt_p); die "cant connect to db: ".DBI->errstr unless $dbh; ######## check for requested changes use CGI qw/:standard *table /; print header,"\n", start_html("My Wallets"), "\n", h1("My Wallets"),"\n"; my %lists = (); my %names = (); my %balance = (); my $asth = $dbh->prepare(qq{ select an.itemName as ownerName, ac.accountID, ac.accountKey, ac.balance, ac.ownerType from account ac, apiNames an where ac.mine and ac.balance != 0 and ac.ownerID = an.itemID and ac.last > NOW() - INTERVAL 7 day }) or die $dbh->errstr; $asth->execute() or die $asth->errstr; while (my $row = $asth->fetchrow_hashref()) { my $name = sprintf "%s - %s %i - %s", $row->{ownerName}, $row->{ownerType}, $row->{accountKey}, &prettyisk($row->{balance}); $names{$row->{accountID}} = $name; $balance{$row->{accountID}} = $row->{balance}; $lists{$row->{accountID}} ||= []; } $asth->finish(); my $sth = $dbh->prepare(qq{ select tr.*, at.typeName, an.itemName as ownerName, ac.accountID, ac.accountKey, ac.balance, ac.ownerType, cn.itemName as clientName, sn.stationName, sn.stationID, sn.stationTypeID from transaction tr, dbo.invTypes at, account ac, apiNames an, apiNames cn, apiStations sn where tr.transactionDateTime > ( select max(transactionDateTime) from transaction ) - INTERVAL $interval and tr.typeID = at.typeID and tr.accountID = ac.accountID and ac.mine and ac.ownerID = an.itemID and tr.clientID = cn.itemID and tr.stationID = sn.stationID order by tr.transactionDateTime desc }) or die $dbh->errstr; # UTC_TIMESTAMP()- INTERVAL $interval $sth->execute() or die $sth->errstr; while (my $row = $sth->fetchrow_hashref()) { my $name = sprintf "%s - %s %i - %s", $row->{ownerName}, $row->{ownerType}, $row->{accountKey}, &prettyisk($row->{balance}); $names{$row->{accountID}} = $name; $balance{$row->{accountID}} = $row->{balance}; $lists{$row->{accountID}} ||= []; my $data = ""; $data .= td({align=>'right',},[ span({title=>$row->{id},},$row->{transactionDateTime},), $row->{transactionType}, ],); $data .= td({align=>'left',},[ a({href=>"showinfo:".$row->{typeID},}, $row->{typeName},),],); $data .= td({align=>'right', style=>'font-family:monospace; font-size:x-large',},[ $row->{quantity}, sprintf("%.2f",$row->{price}), sprintf("%.2f",($row->{quantity}*$row->{price})),],); my $sys = $row->{stationName}; $sys =~ s/\s+-.*//g; $data .= td({align=>'left',},[ a({href=>"showinfo:1//".$row->{clientID},},$row->{clientName},), a({href=>"showinfo:".$row->{stationTypeID}."//".$row->{stationID},title=>$row->{stationName},},$sys,), ],); push @{$lists{$row->{accountID}}}, $data."\n"; } $sth->finish(); my $balance = 0; for my $acc (sort keys %balance) { $balance += $balance{$acc}; } print hr,h2( sprintf("TOTAL: %s", &prettyisk($balance), ),),hr,"\n"; for my $acc (sort {$balance{$b} <=> $balance{$a}} keys %names) { print h3($names{$acc}),"\n"; if (@{$lists{$acc}}) { print start_table({border=>2,}),"\n"; print Tr(\@{$lists{$acc}}),"\n"; print end_table,"\n"; } } if ($debug) { print hr,"\n"; for (sort keys %ENV) { printf "%s: %s%s\n", $_, $ENV{$_}, br; } } my $runtime = time - $begin; print hr, "\n", strftime("Updated at %Y-%m-%d %H:%M:%S", gmtime),br, "\n", $runtime ? sprintf "Completed in %.3f sec.", $runtime : "",br,"\n", end_html,"\n"; exit 0; my $sth_name_by_typeid; sub name_by_typeid ($) { my ($tid,) = @_; my $sth = $sth_name_by_typeid ||= $dbh->prepare(qq{ select typeName from dbo.invTypes where typeID = ? }) or die $dbh->errstr; $sth->execute($tid) or die $sth->errstr; my $r = $sth->fetchrow_arrayref(); return "UNKNOWN:$tid" unless $r; return $r->[0]; } sub urlify ($){ my ($s,) = @_; $s =~ s/(\W)/sprintf("%%%02x", ord($1))/ige; return $s; }