comparison reproctool.cgi @ 0:9c46727ce7ab

Initial version
author Dominic Cleal <dominic@computerkb.co.uk>
date Sat, 24 Jan 2009 16:23:08 +0000
parents
children c39512d94605
comparison
equal deleted inserted replaced
-1:000000000000 0:9c46727ce7ab
1 #!/usr/bin/perl -T
2
3 use warnings;
4 use strict;
5
6 use CGI;
7 use DBI;
8
9 # Settings
10 my $db_path = 'qr100-sqlite3-v1.db';
11 my $img_http_path = '/itemimgs';
12
13 my $cgi = new CGI;
14 print $cgi->header(-type => 'text/html',
15 -pragma => 'no-cache',
16 -expires => '-365d');
17
18 # Inputs
19 my $str_items = $cgi->param('items') or die('Items missing');
20 my $cols = $cgi->param('cols') || 4;
21
22 # Load mineral prices
23 my $trit = $cgi->param('trit') || die('No trit price');
24 my $pyer = $cgi->param('pyer') || die('No pyer price');
25 my $mexa = $cgi->param('mexa') || die('No mexa price');
26 my $isog = $cgi->param('isog') || die('No isog price');
27 my $nocx = $cgi->param('nocx') || die('No nocx price');
28 my $zydr = $cgi->param('zydr') || die('No zydr price');
29 my $mega = $cgi->param('mega') || die('No mega price');
30 my $morp = $cgi->param('morp') || die('No morp price');
31
32 my $db = DBI->connect("DBI:SQLite:$db_path")
33 or die("Database connection failure: $DBI::errstr");
34
35 # Strip out line endings
36 $str_items =~ s/[\n\r]+//g;
37
38 # If the items string contains the contract info too, strip it out
39 $str_items = $1 if ($str_items =~ /The container .+ contains the following items:(.+)/);
40 $str_items = $1 if ($str_items =~ /(.+)Are you sure you want to continue?/);
41
42 # SQL lookup for reprocessing amounts
43 my $sql_reprocess = <<END;
44 SELECT
45 types.typeID,
46 types.typeName,
47 attrs.valueInt [metaLevel],
48 types.basePrice,
49 graphics.icon,
50 SUM(CASE WHEN m1.requiredTypeID = 34 THEN m1.quantity ELSE 0 END) [Tritanium],
51 SUM(CASE WHEN m1.requiredTypeID = 35 THEN m1.quantity ELSE 0 END) [Pyerite],
52 SUM(CASE WHEN m1.requiredTypeID = 36 THEN m1.quantity ELSE 0 END) [Mexallon],
53 SUM(CASE WHEN m1.requiredTypeID = 37 THEN m1.quantity ELSE 0 END) [Isogen],
54 SUM(CASE WHEN m1.requiredTypeID = 38 THEN m1.quantity ELSE 0 END) [Nocxium],
55 SUM(CASE WHEN m1.requiredTypeID = 39 THEN m1.quantity ELSE 0 END) [Zydrine],
56 SUM(CASE WHEN m1.requiredTypeID = 40 THEN m1.quantity ELSE 0 END) [Megacyte],
57 SUM(CASE WHEN m1.requiredTypeID = 11399 THEN m1.quantity ELSE 0 END) [Morphite]
58 FROM invTypes types
59 INNER JOIN dgmTypeAttributes attrs ON types.typeID = attrs.typeID AND attrs.attributeID = 633
60 INNER JOIN typeActivityMaterials m1 ON types.typeID = m1.typeID
61 INNER JOIN eveGraphics graphics ON types.graphicID = graphics.graphicID
62 WHERE types.typeName = ?
63 GROUP BY
64 types.typeID,
65 types.typeName,
66 attrs.valueInt,
67 types.basePrice
68 END
69 my $pre_reprocess = $db->prepare($sql_reprocess);
70
71 my @output = ();
72 for my $sitem (split(/\s*,\s*/, $str_items))
73 {
74 my ($tid, $tname, $meta, $basePrice, $icon,
75 $ttrit, $tpyer, $tmexa, $tisog, $tnocx, $tzydr, $tmega);
76
77 $pre_reprocess->execute($sitem) or die("Can't lookup $sitem: $DBI::errstr");
78 $pre_reprocess->bind_columns(undef, \$tid, \$tname, \$meta, \$basePrice,
79 \$icon, \$ttrit, \$tpyer, \$tmexa, \$tisog, \$tnocx, \$tzydr, \$tmega);
80
81 my $item = {};
82 if ($pre_reprocess->fetch())
83 {
84 my $isk = ($trit * $ttrit) + ($pyer * $tpyer) + ($mexa * $tmexa) +
85 ($isog * $tisog) + ($nocx * $tnocx) + ($zydr * $tzydr) +
86 ($mega * $tmega);
87
88 $item = { id => $tid, name => $tname, meta => $meta, icon => $icon,
89 price => $basePrice, reprocess => $isk };
90 }
91 push @output, $item;
92 }
93
94 my $col = 0;
95 print<<END;
96 <html>
97 <head>
98 <style type="text/css">
99 .meta4, .meta5, .meta6, .meta7, .meta8, .meta9
100 {
101 border: 2px #FF0000 solid;
102 }
103 </style>
104 </head>
105 <body>
106 <table>
107 END
108
109 for my $item (@output)
110 {
111 if ($col == $cols)
112 {
113 print "</tr><tr>\n";
114 $col = 0;
115 }
116
117 my ($style, $img, $text);
118
119 if (defined $item->{id})
120 {
121 $style = "meta$item->{meta}";
122 $img = "icons/icons_items_png/64_64/icon$item->{icon}.png";
123 if ($item->{meta} == 4)
124 {
125 $text = $item->{name};
126 }
127 else
128 {
129 $text = $item->{reprocess};
130 }
131 }
132 else
133 {
134 $text = 'Unknown item';
135 $img = "icons/icons_items_png/64_64/icon07_15.png";
136 }
137
138 print "<td class='item $style'>";
139 print "<img src='$img_http_path/$img' width='64' height='64' alt='$item->{name}' /><br />$text";
140 print "</td>\n";
141
142 $col++;
143 }
144
145 print<<END;
146 </tr>
147 </table>
148 </body>
149 </html>
150 END
151