changeset 16:257e748cd08e

Merging -df
author Dominic Cleal <dominic@computerkb.co.uk>
date Sun, 25 Jan 2009 14:46:32 +0000
parents 50d8619bce32 (diff) ccd5e74fa58e (current diff)
children a79168f03fc4
files reproctool.cgi
diffstat 1 files changed, 69 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/reproctool.cgi	Sun Jan 25 14:40:37 2009 +0000
+++ b/reproctool.cgi	Sun Jan 25 14:46:32 2009 +0000
@@ -15,6 +15,16 @@
                    -pragma  => 'no-cache',
                    -expires => '-365d');
 
+sub user_error
+{
+    my $text = shift;
+    print<<END;
+<html><head><title>Error</title></head>
+<body><font color="#FF0000"><b>Error:</b></font> $text</body></html>
+END
+    exit;
+}
+
 # Generate the first page, where eve-central mineral prices are prefilled.
 # TODO: depending on the traffic, cache these eve-central prices.
 my $str_items;
@@ -68,18 +78,18 @@
 }
 
 # Inputs
+my $str_items = $cgi->param('items') or user_error('Items missing');
 my $cols = $cgi->param('cols') || 4;
 
-# Load mineral prices (names are generated above, but i feel
-# it's safe to assume they wont change that often).
-my $trit = $cgi->param('Tritanium') || die('No trit price');
-my $pyer = $cgi->param('Pyerite') || die('No pyer price');
-my $mexa = $cgi->param('Mexallon') || die('No mexa price');
-my $isog = $cgi->param('Isogen') || die('No isog price');
-my $nocx = $cgi->param('Nocxium') || die('No nocx price');
-my $zydr = $cgi->param('Zydrine') || die('No zydr price');
-my $mega = $cgi->param('Megacyte') || die('No mega price');
-my $morp = $cgi->param('Morphite') || die('No morp price');
+# Load mineral prices
+my $trit = $cgi->param('trit') || user_error('No tritanium price');
+my $pyer = $cgi->param('pyer') || user_error('No pyerite price');
+my $mexa = $cgi->param('mexa') || user_error('No mexallon price');
+my $isog = $cgi->param('isog') || user_error('No isogen price');
+my $nocx = $cgi->param('nocx') || user_error('No nocxium price');
+my $zydr = $cgi->param('zydr') || user_error('No zydrine price');
+my $mega = $cgi->param('mega') || user_error('No megacyte price');
+my $morp = $cgi->param('morp') || user_error('No morphite price');
 
 our @dbparams;
 require './dbparams.cgi';
@@ -93,11 +103,19 @@
 $str_items = $1 if ($str_items =~ /The container .+ contains the following items:(.+)/);
 $str_items = $1 if ($str_items =~ /(.+)Are you sure you want to continue?/);
 
+my @item_names = split(/\s*,\s*/, $str_items);
+
+# SQL fragment to match all items
+my $sql_typenames = '';
+$sql_typenames = 'types.typeName = ?' if ($#item_names >= 0);
+$sql_typenames .= " OR types.typeName = ?" foreach (1..$#item_names);
+
 # SQL lookup for reprocessing amounts
 my $sql_reprocess = <<END;
 SELECT
 	types.typeID,
 	types.typeName,
+	groups.groupName,
 	attrs.valueInt, -- metaLevel
 	types.basePrice,
 	graphics.icon,
@@ -110,41 +128,41 @@
 	SUM(CASE WHEN m1.requiredTypeID = 40 THEN m1.quantity ELSE 0 END), -- [Megacyte]
 	SUM(CASE WHEN m1.requiredTypeID = 11399 THEN m1.quantity ELSE 0 END) -- [Morphite]
 FROM invTypes types
-INNER JOIN dgmTypeAttributes attrs ON types.typeID = attrs.typeID AND attrs.attributeID = 633
+LEFT JOIN dgmTypeAttributes attrs ON types.typeID = attrs.typeID AND attrs.attributeID = 633
 INNER JOIN typeActivityMaterials m1 ON types.typeID = m1.typeID
+INNER JOIN invGroups groups ON types.groupID = groups.groupID
 INNER JOIN eveGraphics graphics ON types.graphicID = graphics.graphicID
-WHERE types.typeName = ?
-GROUP BY
-	types.typeID,
-	types.typeName,
-	attrs.valueInt,
-	types.basePrice
+WHERE $sql_typenames
+GROUP BY types.typeID
+ORDER BY groups.categoryID DESC, groupName ASC, typeName ASC
 END
 my $pre_reprocess = $db->prepare($sql_reprocess);
 
+# Execute, bring back one row per item
+my ($tid, $tname, $gname, $meta, $basePrice, $icon,
+    $ttrit, $tpyer, $tmexa, $tisog, $tnocx, $tzydr, $tmega, $tmorp);
+
+$pre_reprocess->execute(@item_names) or die("Can't lookup items: $DBI::errstr");
+$pre_reprocess->bind_columns(undef, \$tid, \$tname, \$gname, \$meta, \$basePrice,
+                             \$icon, \$ttrit, \$tpyer, \$tmexa, \$tisog,
+                             \$tnocx, \$tzydr, \$tmega, \$tmorp);
+
 my @output = ();
-for my $sitem (split(/\s*,\s*/, $str_items))
+while ($pre_reprocess->fetch())
 {
-    my ($tid, $tname, $meta, $basePrice, $icon,
-        $ttrit, $tpyer, $tmexa, $tisog, $tnocx, $tzydr, $tmega, $tmorp);
-    
-    $pre_reprocess->execute($sitem) or die("Can't lookup $sitem: $DBI::errstr");
-    $pre_reprocess->bind_columns(undef, \$tid, \$tname, \$meta, \$basePrice,
-                                 \$icon, \$ttrit, \$tpyer, \$tmexa, \$tisog,
-                                 \$tnocx, \$tzydr, \$tmega, \$tmorp);
-    
     my $item = {};
-    if ($pre_reprocess->fetch())
-    {
-        my $isk = ($trit * $ttrit) + ($pyer * $tpyer) + ($mexa * $tmexa) +
-                  ($isog * $tisog) + ($nocx * $tnocx) + ($zydr * $tzydr) +
-                  ($mega * $tmega) + ($morp * $tmorp);
-        
-        $meta = 0 unless defined $meta;
-        $item = { id => $tid, name => $tname, meta => $meta, icon => $icon,
-                  price => $basePrice, reprocess => $isk };
-    }
-    push @output, $item;
+    my $isk = ($trit * $ttrit) + ($pyer * $tpyer) + ($mexa * $tmexa) +
+                ($isog * $tisog) + ($nocx * $tnocx) + ($zydr * $tzydr) +
+                ($mega * $tmega) + ($morp * $tmorp);
+    
+    $meta = 0 unless defined $meta;
+    $item = { id => $tid, name => $tname, meta => $meta, icon => $icon,
+              price => $basePrice, reprocess => $isk };
+    
+    # If this item exists multiple times in the input, then they weren't stacked
+    # so output it multiple times
+    my @matching_in = grep({ $_ eq $tname } @item_names);
+    push @output, $item foreach (0..$#matching_in);
 }
 
 my $col = 0;
@@ -167,6 +185,8 @@
 <table>
 END
 
+my $igb = ($ENV{HTTP_USER_AGENT} =~ /EVE-minibrowser/i);
+
 for my $item (@output)
 {
     if ($col == $cols)
@@ -180,8 +200,16 @@
     if (defined $item->{id})
     {
         $style = "meta$item->{meta}";
-        $img = "typeicon:$item->{id}";
-        $link = "showinfo:$item->{id}";
+        if ($igb)
+        {
+            $img = "typeicon:$item->{id}";
+            $link = "showinfo:$item->{id}";
+        }
+        else
+        {
+            $img = "$img_http_path/icons/icons_items_png/64_64/icon$item->{icon}.png";
+        }
+        
         if ($item->{meta} == 4)
         {
             $text = $item->{name};
@@ -200,7 +228,8 @@
     
     print "<td width='64' class='item'>";
     print "<a href='$link'>" if defined $link;
-    print "<img src='$img' width='64' height='64' border='1' alt=\"$item->{name}\" />";
+    print "<img src='$img' width='64' height='64' border='1' ";
+    print   "title=\"$item->{name}\" alt=\"$item->{name}\" />";
     print "</a>" if defined $link;
     print "<br />";
     print "<font color='$colour'>" if defined $colour;