1 | <?php |
---|
2 | require_once("db.php"); |
---|
3 | require_once("class.page.php"); |
---|
4 | require_once("class.ship.php"); |
---|
5 | |
---|
6 | class KillSummaryTable |
---|
7 | { |
---|
8 | function KillSummaryTable($klist = null, $llist = null) |
---|
9 | { |
---|
10 | $this->klist_ = $klist; |
---|
11 | $this->llist_ = $llist; |
---|
12 | |
---|
13 | $this->verbose_ = false; |
---|
14 | $this->filter_ = true; |
---|
15 | $this->inv_crp_ = array(); |
---|
16 | $this->inv_all_ = array(); |
---|
17 | } |
---|
18 | |
---|
19 | function setBreak($break) |
---|
20 | { |
---|
21 | $this->break_ = $break; |
---|
22 | } |
---|
23 | |
---|
24 | function setVerbose($verbose) |
---|
25 | { |
---|
26 | $this->verbose_ = $verbose; |
---|
27 | } |
---|
28 | |
---|
29 | function setFilter($filter) |
---|
30 | { |
---|
31 | $this->filter_ = $filter; |
---|
32 | } |
---|
33 | |
---|
34 | function getTotalKills() |
---|
35 | { |
---|
36 | return $this->tkcount_; |
---|
37 | } |
---|
38 | |
---|
39 | function getTotalLosses() |
---|
40 | { |
---|
41 | return $this->tlcount_; |
---|
42 | } |
---|
43 | |
---|
44 | function getTotalKillPoints() |
---|
45 | { |
---|
46 | return $this->tkpoints_; |
---|
47 | } |
---|
48 | |
---|
49 | function getTotalLossPoints() |
---|
50 | { |
---|
51 | return $this->tlpoints_; |
---|
52 | } |
---|
53 | |
---|
54 | function getTotalKillISK() |
---|
55 | { |
---|
56 | return $this->tkisk_; |
---|
57 | } |
---|
58 | |
---|
59 | function getTotalLossISK() |
---|
60 | { |
---|
61 | return $this->tlisk_; |
---|
62 | } |
---|
63 | |
---|
64 | function setView($string) |
---|
65 | { |
---|
66 | $this->view_ = $string; |
---|
67 | } |
---|
68 | |
---|
69 | function addInvolvedCorp($corp) |
---|
70 | { |
---|
71 | $this->inv_crp_[] = $corp->getID(); |
---|
72 | if ($this->inv_plt_ || $this->inv_all_) |
---|
73 | { |
---|
74 | $this->mixedinvolved_ = true; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | function addInvolvedAlliance($alliance) |
---|
79 | { |
---|
80 | $this->inv_all_[] = $alliance->getID(); |
---|
81 | if ($this->inv_plt_ || $this->inv_crp_) |
---|
82 | { |
---|
83 | $this->mixedinvolved_ = true; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | // do it faster, baby! |
---|
88 | function getkills() |
---|
89 | { |
---|
90 | global $config; |
---|
91 | if ($this->mixedinvolved_) |
---|
92 | { |
---|
93 | echo 'mode not supported<br>'; |
---|
94 | exit; |
---|
95 | } |
---|
96 | |
---|
97 | $this->entry_ = array(); |
---|
98 | // as there is no way to do this elegant in sql |
---|
99 | // i'll keep it in php |
---|
100 | $sql = "select scl_id, scl_class from kb3_ship_classes |
---|
101 | where scl_class not in ('Drone','Unknown') order by scl_class"; |
---|
102 | |
---|
103 | $qry = new DBQuery(); |
---|
104 | $qry->execute($sql); |
---|
105 | while ($row = $qry->getRow()) |
---|
106 | { |
---|
107 | $this->entry_[$row['scl_class']] = array('id' => $row['scl_id'], |
---|
108 | 'kills' => 0, 'kills_isk' => 0, |
---|
109 | 'losses' => 0, 'losses_isk' => 0); |
---|
110 | } |
---|
111 | |
---|
112 | $sql = 'SELECT count(*) AS knb, scl_id, scl_class,'; |
---|
113 | if ($config->getConfig('ship_values')) |
---|
114 | { |
---|
115 | $sql .= ' sum(ifnull(ksv.shp_value,scl.scl_value)) AS kisk FROM kb3_kills kll |
---|
116 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
117 | left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | $sql .= ' sum(scl.scl_value) AS kisk FROM kb3_kills kll |
---|
122 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
123 | } |
---|
124 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
125 | |
---|
126 | if ($this->inv_crp_) |
---|
127 | { |
---|
128 | $sql .= ' inner join kb3_inv_crp inc on ( inc.inc_crp_id in ( '.join(',', $this->inv_crp_).' ) and kll.kll_id = inc.inc_kll_id ) '; |
---|
129 | } |
---|
130 | elseif ($this->inv_all_) |
---|
131 | { |
---|
132 | $sql .= ' inner join kb3_inv_all ina on ( ina.ina_all_id in ( '.join(',', $this->inv_all_).' ) and kll.kll_id = ina.ina_kll_id ) '; |
---|
133 | } |
---|
134 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
135 | |
---|
136 | $qry = new DBQuery(); |
---|
137 | $qry->execute($sql); |
---|
138 | while ($row = $qry->getRow()) |
---|
139 | { |
---|
140 | $this->entry_[$row['scl_class']]['kills'] = $row['knb']; |
---|
141 | $this->entry_[$row['scl_class']]['kills_isk'] = $row['kisk']; |
---|
142 | $this->tkcount_ += $row['knb']; |
---|
143 | $this->tkisk_ += $row['kisk']; |
---|
144 | } |
---|
145 | |
---|
146 | $sql = 'SELECT count(*) AS lnb, scl_id, scl_class,'; |
---|
147 | if ($config->getConfig('ship_values')) |
---|
148 | { |
---|
149 | $sql .= ' sum(ifnull(ksv.shp_value,scl.scl_value)) AS lisk FROM kb3_kills kll |
---|
150 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
151 | left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $sql .= ' sum(scl.scl_value) AS lisk FROM kb3_kills kll |
---|
156 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
157 | } |
---|
158 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
159 | |
---|
160 | if ($this->inv_crp_) |
---|
161 | { |
---|
162 | $sql .= ' where kll.kll_crp_id in ( '.join(',', $this->inv_crp_).' ) '; |
---|
163 | } |
---|
164 | elseif ($this->inv_all_) |
---|
165 | { |
---|
166 | $sql .= ' where kll.kll_all_id in ( '.join(',', $this->inv_all_).' ) '; |
---|
167 | } |
---|
168 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
169 | |
---|
170 | $qry = new DBQuery(); |
---|
171 | $qry->execute($sql); |
---|
172 | while ($row = $qry->getRow()) |
---|
173 | { |
---|
174 | $this->entry_[$row['scl_class']]['losses'] = $row['lnb']; |
---|
175 | $this->entry_[$row['scl_class']]['losses_isk'] = $row['lisk']; |
---|
176 | |
---|
177 | $this->tlcount_ += $row['lnb']; |
---|
178 | $this->tlisk_ += $row['lisk']; |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | function generate() |
---|
183 | { |
---|
184 | if ($this->klist_) |
---|
185 | { |
---|
186 | $entry = array(); |
---|
187 | // build array |
---|
188 | $sql = "select scl_id, scl_class |
---|
189 | from kb3_ship_classes |
---|
190 | where scl_class not in ( 'Drone', 'Unknown' ) |
---|
191 | order by scl_class"; |
---|
192 | |
---|
193 | $qry = new DBQuery(); |
---|
194 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
195 | while ($row = $qry->getRow()) |
---|
196 | { |
---|
197 | if (!$row['scl_id']) |
---|
198 | continue; |
---|
199 | |
---|
200 | $shipclass = new ShipClass($row['scl_id']); |
---|
201 | $shipclass->setName($row['scl_class']); |
---|
202 | |
---|
203 | $entry[$shipclass->getName()]['id'] = $row['scl_id']; |
---|
204 | $entry[$shipclass->getName()]['kills'] = 0; |
---|
205 | $entry[$shipclass->getName()]['kills_isk'] = 0; |
---|
206 | $entry[$shipclass->getName()]['losses'] = 0; |
---|
207 | $entry[$shipclass->getName()]['losses_isk'] = 0; |
---|
208 | } |
---|
209 | // kills |
---|
210 | while ($kill = $this->klist_->getKill()) |
---|
211 | { |
---|
212 | $classname = $kill->getVictimShipClassName(); |
---|
213 | $entry[$classname]['kills']++; |
---|
214 | $entry[$classname]['kills_isk'] += $kill->getVictimShipValue(); |
---|
215 | $this->tkcount_++; |
---|
216 | $this->tkisk_ += $kill->getVictimShipValue(); |
---|
217 | } |
---|
218 | // losses |
---|
219 | while ($kill = $this->llist_->getKill()) |
---|
220 | { |
---|
221 | $classname = $kill->getVictimShipClassName(); |
---|
222 | $entry[$classname]['losses']++; |
---|
223 | $entry[$classname]['losses_isk'] += $kill->getVictimShipValue(); |
---|
224 | $this->tlcount_++; |
---|
225 | $this->tlisk_ += $kill->getVictimShipValue(); |
---|
226 | } |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | $this->getkills(); |
---|
231 | $entry = &$this->entry_; |
---|
232 | } |
---|
233 | |
---|
234 | $odd = false; |
---|
235 | $prevdate = ""; |
---|
236 | $html .= "<table class=kb-subtable width=\"100%\" border=\"0\" cellspacing=0>"; |
---|
237 | if ($this->break_) |
---|
238 | $html .= "<tr><td valign=top><table class=kb-table cellspacing=\"1\" width=\"100%\">"; |
---|
239 | $counter = 1; |
---|
240 | |
---|
241 | if ($this->verbose_) |
---|
242 | { |
---|
243 | $header = "<tr class=kb-table-header><td class=kb-table-cell width=110>Ship class</td><td class=kb-table-cell width=60 align=center>Kills</td><td class=kb-table-cell width=60 align=center>ISK (M)</td><td class=kb-table-cell width=60 align=center>Losses</td><td class=kb-table-cell width=60 align=center>ISK (M)</td></tr>"; |
---|
244 | } |
---|
245 | else |
---|
246 | { |
---|
247 | $header = "<tr class=kb-table-header><td class=kb-table-cell width=110>Ship class</td><td class=kb-table-cell width=30 align=center>K</td><td class=kb-table-cell width=30 align=center>L</td></tr>"; |
---|
248 | } |
---|
249 | $html .= $header; |
---|
250 | |
---|
251 | foreach ($entry as $k => $v) |
---|
252 | { |
---|
253 | if (!$v['id'] || $v['id'] == 3) |
---|
254 | continue; |
---|
255 | if ($this->break_ && $counter > $this->break_) |
---|
256 | { |
---|
257 | $html .= "</table></td>"; |
---|
258 | $html .= "<td valign=top><table class=kb-table cellspacing=\"1\">"; |
---|
259 | $html .= $header; |
---|
260 | $counter = 1; |
---|
261 | } |
---|
262 | |
---|
263 | if (!$odd) |
---|
264 | { |
---|
265 | $odd = true; |
---|
266 | $class = 'kb-table-row-odd'; |
---|
267 | } |
---|
268 | else |
---|
269 | { |
---|
270 | $odd = false; |
---|
271 | $class = 'kb-table-row-even'; |
---|
272 | } |
---|
273 | |
---|
274 | if ($_GET['scl_id'] != "" && $v['id'] == $_GET['scl_id']) |
---|
275 | $highlight = "-hl"; |
---|
276 | else |
---|
277 | $highlight = ""; |
---|
278 | |
---|
279 | if ($v['kills'] == 0) |
---|
280 | $kclass = "kl-kill-null"; |
---|
281 | else |
---|
282 | $kclass = "kl-kill"; |
---|
283 | |
---|
284 | if ($v['losses'] == 0) |
---|
285 | $lclass = "kl-loss-null"; |
---|
286 | else |
---|
287 | $lclass = "kl-loss"; |
---|
288 | |
---|
289 | if ($this->verbose_) |
---|
290 | { |
---|
291 | $kclass .= "-bg"; |
---|
292 | $lclass .= "-bg"; |
---|
293 | } |
---|
294 | |
---|
295 | $html .= "<tr class=".$class.">"; |
---|
296 | |
---|
297 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", $_SERVER['QUERY_STRING']); |
---|
298 | $qrystring = preg_replace("/&page=([0-9]?[0-9])/", "", $qrystring); |
---|
299 | if ($this->view_) |
---|
300 | { |
---|
301 | $qrystring .= '&view='.$this->view_; |
---|
302 | } |
---|
303 | $html .= "<td class=kb-table-cell><b>"; |
---|
304 | |
---|
305 | if ($this->filter_) $html .= "<a class=kb-shipclass".$highlight." href=\"?".$qrystring."&scl_id=".$v['id']."\">"; |
---|
306 | |
---|
307 | $html .= $k; |
---|
308 | |
---|
309 | if ($this->filter_) $html .= "</a>"; |
---|
310 | |
---|
311 | $html .= "</b></td>"; |
---|
312 | |
---|
313 | $html .= "<td class=".$kclass." align=center>".$v['kills']."</td>"; |
---|
314 | if ($this->verbose_) |
---|
315 | $html .= "<td class=".$kclass." align=center>".round($v['kills_isk']/1000000, 2)."</td>"; |
---|
316 | $html .= "<td class=".$lclass." align=center>".$v['losses']."</td>"; |
---|
317 | if ($this->verbose_) |
---|
318 | $html .= "<td class=".$lclass." align=center>".round($v['losses_isk']/1000000, 2)."</td>"; |
---|
319 | |
---|
320 | $html .= "</tr>"; |
---|
321 | |
---|
322 | $counter++; |
---|
323 | $this->tkcount_ += $kcount; |
---|
324 | $this->tlcount_ += $lcount; |
---|
325 | $this->tkisk_ += $kisk; |
---|
326 | $this->tlisk_ += $lisk; |
---|
327 | $this->tkpoints_ += $kpoints; |
---|
328 | $this->tlpoints_ += $lpoints; |
---|
329 | } |
---|
330 | if ($this->break_) |
---|
331 | $html .= "</table></td>"; |
---|
332 | |
---|
333 | $html .= "</tr></table>"; |
---|
334 | |
---|
335 | if ($_GET['scl_id'] != "") |
---|
336 | { |
---|
337 | $html .= "<table align=center><tr><td align=center valign=top class=weeknav>"; |
---|
338 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", $_SERVER['QUERY_STRING']); |
---|
339 | $html .= "[<a href=\"?".$qrystring."\">clear filter</a>]</td></tr></table>"; |
---|
340 | } |
---|
341 | |
---|
342 | return $html; |
---|
343 | } |
---|
344 | } |
---|
345 | ?> |
---|