1 | <?php |
---|
2 | require_once("common/includes/class.ship.php"); |
---|
3 | |
---|
4 | class KillSummaryTable |
---|
5 | { |
---|
6 | function KillSummaryTable($klist = null, $llist = null) |
---|
7 | { |
---|
8 | $this->klist_ = $klist; |
---|
9 | $this->llist_ = $llist; |
---|
10 | $this->verbose_ = false; |
---|
11 | $this->filter_ = true; |
---|
12 | $this->inv_crp_ = array(); |
---|
13 | $this->inv_all_ = array(); |
---|
14 | } |
---|
15 | |
---|
16 | function setBreak($break) |
---|
17 | { |
---|
18 | $this->break_ = $break; |
---|
19 | } |
---|
20 | |
---|
21 | function setVerbose($verbose) |
---|
22 | { |
---|
23 | $this->verbose_ = $verbose; |
---|
24 | } |
---|
25 | |
---|
26 | function setFilter($filter) |
---|
27 | { |
---|
28 | $this->filter_ = $filter; |
---|
29 | } |
---|
30 | |
---|
31 | function getTotalKills() |
---|
32 | { |
---|
33 | return $this->tkcount_; |
---|
34 | } |
---|
35 | |
---|
36 | function getTotalLosses() |
---|
37 | { |
---|
38 | return $this->tlcount_; |
---|
39 | } |
---|
40 | |
---|
41 | function getTotalKillPoints() |
---|
42 | { |
---|
43 | return $this->tkpoints_; |
---|
44 | } |
---|
45 | |
---|
46 | function getTotalLossPoints() |
---|
47 | { |
---|
48 | return $this->tlpoints_; |
---|
49 | } |
---|
50 | |
---|
51 | function getTotalKillISK() |
---|
52 | { |
---|
53 | return $this->tkisk_; |
---|
54 | } |
---|
55 | |
---|
56 | function getTotalLossISK() |
---|
57 | { |
---|
58 | return $this->tlisk_; |
---|
59 | } |
---|
60 | |
---|
61 | function setView($string) |
---|
62 | { |
---|
63 | $this->view_ = $string; |
---|
64 | } |
---|
65 | |
---|
66 | function addInvolvedCorp($corp) |
---|
67 | { |
---|
68 | $this->inv_crp_[] = $corp->getID(); |
---|
69 | if ($this->inv_plt_ || $this->inv_all_) |
---|
70 | { |
---|
71 | $this->mixedinvolved_ = true; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | function addInvolvedAlliance($alliance) |
---|
76 | { |
---|
77 | $this->inv_all_[] = $alliance->getID(); |
---|
78 | if ($this->inv_plt_ || $this->inv_crp_) |
---|
79 | { |
---|
80 | $this->mixedinvolved_ = true; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | // do it faster, baby! |
---|
85 | function getkills() |
---|
86 | { |
---|
87 | if ($this->mixedinvolved_) |
---|
88 | { |
---|
89 | echo 'mode not supported<br>'; |
---|
90 | exit; |
---|
91 | } |
---|
92 | |
---|
93 | $this->entry_ = array(); |
---|
94 | // as there is no way to do this elegant in sql |
---|
95 | // i'll keep it in php |
---|
96 | $sql = "select scl_id, scl_class from kb3_ship_classes |
---|
97 | where scl_class not in ('Drone','Unknown') order by scl_class"; |
---|
98 | |
---|
99 | $qry = new DBQuery(); |
---|
100 | $qry->execute($sql); |
---|
101 | while ($row = $qry->getRow()) |
---|
102 | { |
---|
103 | $this->entry_[$row['scl_class']] = array('id' => $row['scl_id'], |
---|
104 | 'kills' => 0, 'kills_isk' => 0, |
---|
105 | 'losses' => 0, 'losses_isk' => 0); |
---|
106 | } |
---|
107 | |
---|
108 | $sql = 'SELECT count(*) AS knb, scl_id, scl_class,'; |
---|
109 | if (config::get('ship_values')) |
---|
110 | { |
---|
111 | $sql .= ' sum(ifnull(ksv.shp_value,scl.scl_value)) AS kisk FROM kb3_kills kll |
---|
112 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
113 | left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | $sql .= ' sum(scl.scl_value) AS kisk FROM kb3_kills kll |
---|
118 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
119 | } |
---|
120 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
121 | |
---|
122 | if ($this->inv_crp_) |
---|
123 | { |
---|
124 | $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 ) '; |
---|
125 | } |
---|
126 | elseif ($this->inv_all_) |
---|
127 | { |
---|
128 | $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 ) '; |
---|
129 | } |
---|
130 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
131 | |
---|
132 | $qry = new DBQuery(); |
---|
133 | $qry->execute($sql); |
---|
134 | while ($row = $qry->getRow()) |
---|
135 | { |
---|
136 | $this->entry_[$row['scl_class']]['kills'] = $row['knb']; |
---|
137 | $this->entry_[$row['scl_class']]['kills_isk'] = $row['kisk']; |
---|
138 | $this->tkcount_ += $row['knb']; |
---|
139 | $this->tkisk_ += $row['kisk']; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | $sql = 'SELECT count(*) AS lnb, scl_id, scl_class,'; |
---|
144 | if (config::get('ship_values')) |
---|
145 | { |
---|
146 | $sql .= ' sum(ifnull(ksv.shp_value,scl.scl_value)) AS lisk FROM kb3_kills kll |
---|
147 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
148 | left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | $sql .= ' sum(scl.scl_value) AS lisk FROM kb3_kills kll |
---|
153 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
154 | } |
---|
155 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
156 | |
---|
157 | if ($this->inv_crp_) |
---|
158 | { |
---|
159 | $sql .= ' where kll.kll_crp_id in ( '.join(',', $this->inv_crp_).' ) '; |
---|
160 | } |
---|
161 | elseif ($this->inv_all_) |
---|
162 | { |
---|
163 | $sql .= ' where kll.kll_all_id in ( '.join(',', $this->inv_all_).' ) '; |
---|
164 | } |
---|
165 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
166 | |
---|
167 | $qry = new DBQuery(); |
---|
168 | $qry->execute($sql); |
---|
169 | while ($row = $qry->getRow()) |
---|
170 | { |
---|
171 | $this->entry_[$row['scl_class']]['losses'] = $row['lnb']; |
---|
172 | $this->entry_[$row['scl_class']]['losses_isk'] = $row['lisk']; |
---|
173 | |
---|
174 | $this->tlcount_ += $row['lnb']; |
---|
175 | $this->tlisk_ += $row['lisk']; |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | function generate() |
---|
180 | { |
---|
181 | if ($this->klist_) |
---|
182 | { |
---|
183 | $entry = array(); |
---|
184 | // build array |
---|
185 | $sql = "select scl_id, scl_class |
---|
186 | from kb3_ship_classes |
---|
187 | where scl_class not in ( 'Drone', 'Unknown' ) |
---|
188 | order by scl_class"; |
---|
189 | |
---|
190 | $qry = new DBQuery(); |
---|
191 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
192 | while ($row = $qry->getRow()) |
---|
193 | { |
---|
194 | if (!$row['scl_id']) |
---|
195 | continue; |
---|
196 | |
---|
197 | $shipclass = new ShipClass($row['scl_id']); |
---|
198 | $shipclass->setName($row['scl_class']); |
---|
199 | |
---|
200 | $entry[$shipclass->getName()]['id'] = $row['scl_id']; |
---|
201 | $entry[$shipclass->getName()]['kills'] = 0; |
---|
202 | $entry[$shipclass->getName()]['kills_isk'] = 0; |
---|
203 | $entry[$shipclass->getName()]['losses'] = 0; |
---|
204 | $entry[$shipclass->getName()]['losses_isk'] = 0; |
---|
205 | } |
---|
206 | // kills |
---|
207 | while ($kill = $this->klist_->getKill()) |
---|
208 | { |
---|
209 | $classname = $kill->getVictimShipClassName(); |
---|
210 | $entry[$classname]['kills']++; |
---|
211 | $entry[$classname]['kills_isk'] += $kill->getVictimShipValue(); |
---|
212 | $this->tkcount_++; |
---|
213 | $this->tkisk_ += $kill->getVictimShipValue(); |
---|
214 | } |
---|
215 | // losses |
---|
216 | while ($kill = $this->llist_->getKill()) |
---|
217 | { |
---|
218 | $classname = $kill->getVictimShipClassName(); |
---|
219 | $entry[$classname]['losses']++; |
---|
220 | $entry[$classname]['losses_isk'] += $kill->getVictimShipValue(); |
---|
221 | $this->tlcount_++; |
---|
222 | $this->tlisk_ += $kill->getVictimShipValue(); |
---|
223 | } |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | $this->getkills(); |
---|
228 | $entry = &$this->entry_; |
---|
229 | } |
---|
230 | |
---|
231 | $odd = false; |
---|
232 | $prevdate = ""; |
---|
233 | $width = round($this->break_/count($entry)*100); |
---|
234 | $width_abs = round($this->break_/count($entry)*600); |
---|
235 | |
---|
236 | $html .= "<table class=kb-subtable width=\"100%\" border=\"0\" cellspacing=0>"; |
---|
237 | if ($this->break_) |
---|
238 | $html .= "<tr><td valign=top width=\"$width%\"><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=\"$width_abs\">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=\"$width_abs\">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 | |
---|
250 | $html .= $header; |
---|
251 | |
---|
252 | foreach ($entry as $k => $v) |
---|
253 | { |
---|
254 | if (!$v['id'] || $v['id'] == 3) |
---|
255 | continue; |
---|
256 | if ($this->break_ && $counter > $this->break_) |
---|
257 | { |
---|
258 | $html .= "</table></td>"; |
---|
259 | $html .= "<td valign=top width=\"$width%\"><table class=kb-table cellspacing=\"1\">"; |
---|
260 | $html .= $header; |
---|
261 | $counter = 1; |
---|
262 | } |
---|
263 | |
---|
264 | if (!$odd) |
---|
265 | { |
---|
266 | $odd = true; |
---|
267 | $class = 'kb-table-row-odd'; |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | $odd = false; |
---|
272 | $class = 'kb-table-row-even'; |
---|
273 | } |
---|
274 | |
---|
275 | if ($_GET['scl_id'] != "" && $v['id'] == $_GET['scl_id']) |
---|
276 | $highlight = "-hl"; |
---|
277 | else |
---|
278 | $highlight = ""; |
---|
279 | |
---|
280 | if ($v['kills'] == 0) |
---|
281 | $kclass = "kl-kill-null"; |
---|
282 | else |
---|
283 | $kclass = "kl-kill"; |
---|
284 | |
---|
285 | if ($v['losses'] == 0) |
---|
286 | $lclass = "kl-loss-null"; |
---|
287 | else |
---|
288 | $lclass = "kl-loss"; |
---|
289 | |
---|
290 | $html .= "<tr class=".$class.">"; |
---|
291 | |
---|
292 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", $_SERVER['QUERY_STRING']); |
---|
293 | $qrystring = preg_replace("/&page=([0-9]?[0-9])/", "", $qrystring); |
---|
294 | if ($this->view_) |
---|
295 | { |
---|
296 | $qrystring .= '&view='.$this->view_; |
---|
297 | } |
---|
298 | $html .= "<td nowrap class=kb-table-cell><b>"; |
---|
299 | |
---|
300 | if ($this->filter_) $html .= "<a class=kb-shipclass".$highlight." href=\"?".$qrystring."&scl_id=".$v['id']."\">"; |
---|
301 | |
---|
302 | $html .= $k; |
---|
303 | |
---|
304 | if ($this->filter_) $html .= "</a>"; |
---|
305 | |
---|
306 | $html .= "</b></td>"; |
---|
307 | |
---|
308 | $html .= "<td class=".$kclass." align=center>".$v['kills']."</td>"; |
---|
309 | if ($this->verbose_) |
---|
310 | $html .= "<td class=".$kclass." align=center>".round($v['kills_isk']/1000000, 2)."</td>"; |
---|
311 | |
---|
312 | $html .= "<td class=".$lclass." align=center>".$v['losses']."</td>"; |
---|
313 | if ($this->verbose_) |
---|
314 | $html .= "<td class=".$lclass." align=center>".round($v['losses_isk']/1000000, 2)."</td>"; |
---|
315 | |
---|
316 | $html .= "</tr>"; |
---|
317 | |
---|
318 | $counter++; |
---|
319 | |
---|
320 | $this->tkcount_ += $kcount; |
---|
321 | $this->tkisk_ += $kisk; |
---|
322 | $this->tkpoints_ += $kpoints; |
---|
323 | $this->tlcount_ += $lcount; |
---|
324 | $this->tlisk_ += $lisk; |
---|
325 | $this->tlpoints_ += $lpoints; |
---|
326 | } |
---|
327 | if ($this->break_) |
---|
328 | $html .= "</table></td>"; |
---|
329 | |
---|
330 | $html .= "</tr></table>"; |
---|
331 | |
---|
332 | if (config::get('summarytable_summary')) |
---|
333 | { |
---|
334 | $html .= '<table width=100% border=0 cellspacing=2>' |
---|
335 | .'<tr align=center><td width=51%><span align=right class="killcount">' |
---|
336 | .$this->tkcount_.' Ships killed ('.round($this->tkisk_/1000000, 2).'M ISK)</span></td><td width=49%><span class="losscount">'.$this->tlcount_.' Ships lost ('.round($this->tlisk_/1000000, 2).'M ISK)</span></td></tr></table>'; |
---|
337 | } |
---|
338 | |
---|
339 | if ($_GET['scl_id'] != "") |
---|
340 | { |
---|
341 | $html .= "<table align=center><tr><td align=center valign=top class=weeknav>"; |
---|
342 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", $_SERVER['QUERY_STRING']); |
---|
343 | $html .= "[<a href=\"?".$qrystring."\">clear filter</a>]</td></tr></table>"; |
---|
344 | } |
---|
345 | |
---|
346 | return $html; |
---|
347 | } |
---|
348 | |
---|
349 | function forum() |
---|
350 | { |
---|
351 | |
---|
352 | if ($this->klist_) |
---|
353 | { |
---|
354 | $entry = array(); |
---|
355 | // build array |
---|
356 | $sql = "select scl_id, scl_class |
---|
357 | from kb3_ship_classes |
---|
358 | where scl_class not in ( 'Drone', 'Unknown' ) |
---|
359 | order by scl_class"; |
---|
360 | |
---|
361 | $qry = new DBQuery(); |
---|
362 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
363 | while ($row = $qry->getRow()) |
---|
364 | { |
---|
365 | if (!$row['scl_id']) |
---|
366 | continue; |
---|
367 | |
---|
368 | $shipclass = new ShipClass($row['scl_id']); |
---|
369 | $shipclass->setName($row['scl_class']); |
---|
370 | |
---|
371 | $entry[$shipclass->getName()]['id'] = $row['scl_id']; |
---|
372 | $entry[$shipclass->getName()]['kills'] = 0; |
---|
373 | $entry[$shipclass->getName()]['kills_isk'] = 0; |
---|
374 | $entry[$shipclass->getName()]['losses'] = 0; |
---|
375 | $entry[$shipclass->getName()]['losses_isk'] = 0; |
---|
376 | } |
---|
377 | // kills |
---|
378 | while ($kill = $this->klist_->getKill()) |
---|
379 | { |
---|
380 | $classname = $kill->getVictimShipClassName(); |
---|
381 | $entry[$classname]['kills']++; |
---|
382 | $entry[$classname]['kills_isk'] += $kill->getVictimShipValue(); |
---|
383 | $this->tkcount_++; |
---|
384 | $this->tkisk_ += $kill->getVictimShipValue(); |
---|
385 | } |
---|
386 | // losses |
---|
387 | while ($kill = $this->llist_->getKill()) |
---|
388 | { |
---|
389 | $classname = $kill->getVictimShipClassName(); |
---|
390 | $entry[$classname]['losses']++; |
---|
391 | $entry[$classname]['losses_isk'] += $kill->getVictimShipValue(); |
---|
392 | $this->tlcount_++; |
---|
393 | $this->tlisk_ += $kill->getVictimShipValue(); |
---|
394 | } |
---|
395 | } |
---|
396 | else |
---|
397 | { |
---|
398 | $this->getkills(); |
---|
399 | $entry = &$this->entry_; |
---|
400 | } |
---|
401 | |
---|
402 | // Build our Post |
---|
403 | $config = new config(KB_SITE); |
---|
404 | $set_colours = config::get('forum_post_colours'); //load colour settings |
---|
405 | if(!is_array($set_colours)) { $set_colours = array(); } // if the settings have been reset create an empty array so as not to brake the code later on |
---|
406 | $set_styles = config::get('forum_post_styles'); //load style settings |
---|
407 | if(!is_array($set_styles)) { $set_styles = array(); } // if the settings have been reset create an empty array so as not to brake the code later on |
---|
408 | $set_isk = config::get('forum_post_isk',$_POST['isk']); // load isk setting |
---|
409 | $forum_post_miss_empty_class = config::get(forum_post_miss_empty_class); |
---|
410 | //print_r($set_styles); |
---|
411 | foreach ($entry as $k => $v) |
---|
412 | { |
---|
413 | if($forum_post_miss_empty_class == 1 && $v['kills'] == 0 && $v['losses'] == 0) { |
---|
414 | |
---|
415 | } |
---|
416 | else { |
---|
417 | $class = $k.$kclass; |
---|
418 | $kills = $v['kills']; |
---|
419 | if($set_isk == "yes") |
---|
420 | { |
---|
421 | $kills_isk = "(".round($v['kills_isk']/1000000, 2)."M)"; |
---|
422 | $loss_isk = "(".round($v['losses_isk']/1000000, 2)."M)"; |
---|
423 | } |
---|
424 | $loss = $v['losses']; |
---|
425 | $close = "\r\n"; |
---|
426 | $spacer = " / "; |
---|
427 | if(array_key_exists(str_replace(" ","",$class),$set_colours)) |
---|
428 | { |
---|
429 | $colour_open = "[".$set_colours[str_replace(" ","",$class)]."]"; |
---|
430 | $colour_close = "[/".$set_colours[str_replace(" ","",$class)]."]"; |
---|
431 | } |
---|
432 | else |
---|
433 | { |
---|
434 | $colour_open = ""; |
---|
435 | $colour_close = ""; |
---|
436 | } |
---|
437 | if(array_key_exists(str_replace(" ","",$class),$set_styles)) |
---|
438 | { |
---|
439 | $style_open = "[".$set_styles[str_replace(" ","",$class)]."]"; |
---|
440 | $style_close = "[/".$set_styles[str_replace(" ","",$class)]."]"; |
---|
441 | } |
---|
442 | else |
---|
443 | { |
---|
444 | $style_open = ""; |
---|
445 | $style_close = ""; |
---|
446 | } |
---|
447 | $order = config::get('forum_post_order'); |
---|
448 | |
---|
449 | if($order == "first"){ |
---|
450 | $kills_list .= $colour_open . $style_open . $class . $spacer . $kills . $kills_isk . $spacer . $loss . $loss_isk . $style_close . $colour_close. $close; |
---|
451 | } |
---|
452 | else |
---|
453 | { |
---|
454 | $kills_list .= $colour_open . $style_open . $kills . $kills_isk . $spacer . $loss . $loss_isk . $spacer . $class . $style_close . $colour_close. $close; |
---|
455 | } |
---|
456 | $counter++; |
---|
457 | $this->tkcount_ += $kcount; |
---|
458 | $this->tlcount_ += $lcount; |
---|
459 | $this->tkisk_ += $kisk; |
---|
460 | $this->tlisk_ += $lisk; |
---|
461 | $this->tkpoints_ += $kpoints; |
---|
462 | $this->tlpoints_ += $lpoints; |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | if($order == "first") |
---|
467 | { |
---|
468 | $html .= "Class / "; |
---|
469 | } |
---|
470 | $html.= "Kills"; |
---|
471 | if($set_isk == "yes") |
---|
472 | { |
---|
473 | $html .= "(kills isk)"; |
---|
474 | } |
---|
475 | $html .=" / losses "; |
---|
476 | if($set_isk == "yes") |
---|
477 | { |
---|
478 | $html .= "(losses isk)"; |
---|
479 | } |
---|
480 | if($order != "first") |
---|
481 | { |
---|
482 | $html .= " / Class"; |
---|
483 | } |
---|
484 | $html .="\r\n"; |
---|
485 | $html .= $kills_list; |
---|
486 | $html .= "Total / ".$this->tkcount_; |
---|
487 | $html .= " (".round($this->tkisk_/1000000, 2)."M)"; |
---|
488 | $html .= " / ".$this->tlcount_; |
---|
489 | $html .= " (".round($this->tlisk_/1000000, 2)."M)"; |
---|
490 | return $html; |
---|
491 | } |
---|
492 | } |
---|
493 | ?> |
---|