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