]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Include.pm
Remove a few warnings
[ndwebbie.git] / lib / NDWeb / Include.pm
index ff5a8825a20fc9f39ec0e62cea7ad0b6bdcfb389..b5acfbb43d8ca8f6e7d6eb58515b92f5e7f368b0 100644 (file)
@@ -26,13 +26,20 @@ use CGI qw/:standard/;
 
 our @ISA = qw/Exporter/;
 
-our @EXPORT = qw/parseMarkup min max
-       alliances intelquery html_escape/;
+our @EXPORT = qw/parseMarkup
+       intelquery html_escape
+       comma_value array_expand/;
 
 sub html_escape($) {
        return CGI::escapeHTML @_;
 }
 
+sub comma_value ($) {
+       my ($v) = @_;
+       $v =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
+       return $v;
+}
+
 sub parseMarkup ($) {
        my ($text) = @_;
 
@@ -53,31 +60,6 @@ sub parseMarkup ($) {
        return $text;
 }
 
-
-sub min {
-    my ($x,$y) = @_;
-    return ($x > $y ? $y : $x);
-}
-
-sub max {
-    my ($x,$y) = @_;
-    return ($x < $y ? $y : $x);
-}
-
-
-sub alliances {
-       my ($alliance) = @_;
-       my @alliances;
-       $alliance = -1 unless defined $alliance;
-       push @alliances,{Id => -1, Name => '', Selected => not $alliance};
-       my $query = $ND::DBH->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)});
-       $query->execute;        
-       while (my $ally = $query->fetchrow_hashref){
-               push @alliances,{Id => $ally->{id}, Name => $ally->{name}, Selected => $alliance == $ally->{id}};
-       }
-       return @alliances;
-}
-
 sub intelquery {
        my ($columns,$where) = @_;
        return qq{
@@ -86,10 +68,23 @@ FROM (fleets i NATURAL JOIN users u)
        JOIN current_planet_stats t ON i.target = t.id
        JOIN current_planet_stats o ON i.sender = o.id
 WHERE $where 
-GROUP BY i.tick,i.mission,t.x,t.y,t.z,o.x,o.y,o.z,i.amount,i.ingal,u.username,t.alliance,o.alliance,t.nick,o.nick
+GROUP BY i.tick,i.mission,t.x,t.y,t.z,o.x,o.y,o.z,i.amount,i.ingal,u.username,t.alliance,o.alliance,t.nick,o.nick,i.sender,i.target
 ORDER BY i.tick DESC, i.mission};
 }
 
+sub array_expand ($) {
+       my ($array) = @_;
+
+       my @arrays;
+       for my $string (@{$array}){
+               $string =~ s/^\((.*)\)$/$1/;
+               $string =~ s/"//g;
+               my @array = split /,/, $string;
+               push @arrays,\@array;
+       }
+       return \@arrays;
+}
+
 
 
 1;