1 | <?php |
---|
2 | require_once("class.ship.php"); |
---|
3 | require_once("class.summary.php"); |
---|
4 | |
---|
5 | class KillSummaryTable |
---|
6 | { |
---|
7 | function KillSummaryTable($klist = null, $llist = null) |
---|
8 | { |
---|
9 | $this->klist_ = $klist; |
---|
10 | $this->llist_ = $llist; |
---|
11 | $this->verbose_ = false; |
---|
12 | $this->filter_ = true; |
---|
13 | $this->inv_plt_ = array(); |
---|
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 setWeek($weekno) |
---|
34 | { |
---|
35 | $weekno=intval($weekno); |
---|
36 | if($weekno <1) $this->weekno_ = 1; |
---|
37 | if($weekno >53) $this->weekno_ = 53; |
---|
38 | else $this->weekno_ = $weekno; |
---|
39 | } |
---|
40 | |
---|
41 | function setMonth($monthno) |
---|
42 | { |
---|
43 | $monthno = intval($monthno); |
---|
44 | if($monthno < 1) $this->monthno_ = 1; |
---|
45 | if($monthno > 12) $this->monthno_ = 12; |
---|
46 | else $this->monthno_ = $monthno; |
---|
47 | } |
---|
48 | |
---|
49 | function setYear($yearno) |
---|
50 | { |
---|
51 | // 1970-2038 is the allowable range for the timestamp code used |
---|
52 | // Needs to be revisited in the next 30 years |
---|
53 | $yearno = intval($yearno); |
---|
54 | if($yearno < 1970) $this->yearno_ = 1970; |
---|
55 | if($yearno > 2038) $this->yearno_ = 2038; |
---|
56 | else $this->yearno_ = $yearno; |
---|
57 | } |
---|
58 | |
---|
59 | function setStartWeek($weekno) |
---|
60 | { |
---|
61 | $weekno=intval($weekno); |
---|
62 | if($weekno <1) $this->startweekno_ = 1; |
---|
63 | if($weekno >53) $this->startweekno_ = 53; |
---|
64 | else $this->startweekno_ = $weekno; |
---|
65 | } |
---|
66 | |
---|
67 | function setStartDate($timestamp) |
---|
68 | { |
---|
69 | // Check timestamp is valid before adding |
---|
70 | if(strtotime($timestamp)) $this->startDate_ = $timestamp; |
---|
71 | } |
---|
72 | |
---|
73 | function setEndDate($timestamp) |
---|
74 | { |
---|
75 | // Check timestamp is valid before adding |
---|
76 | if(strtotime($timestamp)) $this->endDate_ = $timestamp; |
---|
77 | } |
---|
78 | |
---|
79 | // Return SQL for date filter using currently set date limits |
---|
80 | function setDateFilter() |
---|
81 | { |
---|
82 | $qstartdate = makeStartDate($this->weekno_, $this->yearno_, $this->monthno_, $this->startweekno_, $this->startDate_); |
---|
83 | $qenddate = makeEndDate($this->weekno_, $this->yearno_, $this->monthno_, $this->endDate_); |
---|
84 | if($qstartdate) $sql .= " kll.kll_timestamp >= '".gmdate('Y-m-d H:i',$qstartdate)."' "; |
---|
85 | if($qstartdate && $qenddate) $sql .= " AND "; |
---|
86 | if($qenddate) $sql .= " kll.kll_timestamp <= '".gmdate('Y-m-d H:i',$qenddate)."' "; |
---|
87 | return $sql; |
---|
88 | } |
---|
89 | |
---|
90 | function getTotalKills() |
---|
91 | { |
---|
92 | return $this->tkcount_; |
---|
93 | } |
---|
94 | |
---|
95 | function getTotalLosses() |
---|
96 | { |
---|
97 | return $this->tlcount_; |
---|
98 | } |
---|
99 | |
---|
100 | function getTotalKillPoints() |
---|
101 | { |
---|
102 | return $this->tkpoints_; |
---|
103 | } |
---|
104 | |
---|
105 | function getTotalLossPoints() |
---|
106 | { |
---|
107 | return $this->tlpoints_; |
---|
108 | } |
---|
109 | |
---|
110 | function getTotalKillISK() |
---|
111 | { |
---|
112 | return $this->tkisk_; |
---|
113 | } |
---|
114 | |
---|
115 | function getTotalLossISK() |
---|
116 | { |
---|
117 | return $this->tlisk_; |
---|
118 | } |
---|
119 | |
---|
120 | function setView($string) |
---|
121 | { |
---|
122 | $this->view_ = $string; |
---|
123 | } |
---|
124 | |
---|
125 | function addInvolvedPilot($pilot) |
---|
126 | { |
---|
127 | $this->inv_plt_[] = $pilot->getID(); |
---|
128 | if ($this->inv_crp_ || $this->inv_all_) |
---|
129 | { |
---|
130 | $this->mixedinvolved_ = true; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | function addInvolvedCorp($corp) |
---|
135 | { |
---|
136 | $this->inv_crp_[] = $corp->getID(); |
---|
137 | if ($this->inv_plt_ || $this->inv_all_) |
---|
138 | { |
---|
139 | $this->mixedinvolved_ = true; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | function addInvolvedAlliance($alliance) |
---|
144 | { |
---|
145 | $this->inv_all_[] = $alliance->getID(); |
---|
146 | if ($this->inv_plt_ || $this->inv_crp_) |
---|
147 | { |
---|
148 | $this->mixedinvolved_ = true; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | // do it faster, baby! |
---|
153 | function getkills() |
---|
154 | { |
---|
155 | if ($this->mixedinvolved_) |
---|
156 | { |
---|
157 | echo 'mode not supported<br>'; |
---|
158 | exit; |
---|
159 | } |
---|
160 | if( count($this->inv_all_) == 1 && !$this->inv_crp_ && !$this->inv_plt_ && $this->setDateFilter() == "") |
---|
161 | { |
---|
162 | $allsum = new allianceSummary($this->inv_all_[0]); |
---|
163 | $summary = $allsum->getSummary(); |
---|
164 | foreach($summary as $key => $row) |
---|
165 | { |
---|
166 | $this->entry_[$row['class_name']] = array('id' => $key, |
---|
167 | 'kills' => $row['killcount'], 'kills_isk' => $row['killisk'], |
---|
168 | 'losses' => $row['losscount'], 'losses_isk' => $row['lossisk']); |
---|
169 | |
---|
170 | $this->tkcount_ += $row['killcount']; |
---|
171 | $this->tkisk_ += $row['killisk']; |
---|
172 | $this->tlcount_ += $row['losscount']; |
---|
173 | $this->tlisk_ += $row['lossisk']; |
---|
174 | } |
---|
175 | return; |
---|
176 | } |
---|
177 | elseif( count($this->inv_crp_) == 1 && !$this->inv_all_ && !$this->inv_plt_ && $this->setDateFilter() == "") |
---|
178 | { |
---|
179 | $crpsum = new corpSummary($this->inv_crp_[0]); |
---|
180 | $summary = $crpsum->getSummary(); |
---|
181 | foreach($summary as $key => $row) |
---|
182 | { |
---|
183 | $this->entry_[$row['class_name']] = array('id' => $key, |
---|
184 | 'kills' => $row['killcount'], 'kills_isk' => $row['killisk'], |
---|
185 | 'losses' => $row['losscount'], 'losses_isk' => $row['lossisk']); |
---|
186 | |
---|
187 | $this->tkcount_ += $row['killcount']; |
---|
188 | $this->tkisk_ += $row['killisk']; |
---|
189 | $this->tlcount_ += $row['losscount']; |
---|
190 | $this->tlisk_ += $row['lossisk']; |
---|
191 | } |
---|
192 | return; |
---|
193 | } |
---|
194 | elseif( count($this->inv_plt_) == 1 && !$this->inv_all_ && !$this->inv_crp_ && $this->setDateFilter() == "") |
---|
195 | { |
---|
196 | $pltsum = new pilotSummary($this->inv_plt_[0]); |
---|
197 | $summary = $pltsum->getSummary(); |
---|
198 | foreach($summary as $key => $row) |
---|
199 | { |
---|
200 | $this->entry_[$row['class_name']] = array('id' => $key, |
---|
201 | 'kills' => $row['killcount'], 'kills_isk' => $row['killisk'], |
---|
202 | 'losses' => $row['losscount'], 'losses_isk' => $row['lossisk']); |
---|
203 | |
---|
204 | $this->tkcount_ += $row['killcount']; |
---|
205 | $this->tkisk_ += $row['killisk']; |
---|
206 | $this->tlcount_ += $row['losscount']; |
---|
207 | $this->tlisk_ += $row['lossisk']; |
---|
208 | } |
---|
209 | return; |
---|
210 | } |
---|
211 | |
---|
212 | $this->entry_ = array(); |
---|
213 | // as there is no way to do this elegantly in sql |
---|
214 | // i'll keep it in php |
---|
215 | $sql = "select scl_id, scl_class from kb3_ship_classes |
---|
216 | where scl_class not in ('Drone','Unknown') order by scl_class"; |
---|
217 | |
---|
218 | $qry = new DBQuery(); |
---|
219 | $qry->execute($sql); |
---|
220 | while ($row = $qry->getRow()) |
---|
221 | { |
---|
222 | $this->entry_[$row['scl_class']] = array('id' => $row['scl_id'], |
---|
223 | 'kills' => 0, 'kills_isk' => 0, |
---|
224 | 'losses' => 0, 'losses_isk' => 0); |
---|
225 | } |
---|
226 | |
---|
227 | $sql = 'SELECT count(distinct kll.kll_id) AS knb, scl_id, scl_class,'; |
---|
228 | $sql .= ' sum(kll_isk_loss) AS kisk FROM kb3_kills kll |
---|
229 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
230 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
231 | |
---|
232 | // Force MySQL to first filter by date if a date range is given. |
---|
233 | if($this->setDateFilter()) |
---|
234 | { |
---|
235 | $sql.= 'WHERE '.$this->setDateFilter(); |
---|
236 | if ($this->inv_plt_) |
---|
237 | { |
---|
238 | $sql .= ' AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind.ind_kll_id AND ind.ind_plt_id in ( '.implode(',', $this->inv_plt_).' ) LIMIT 1)'; |
---|
239 | } |
---|
240 | if ($this->inv_crp_) |
---|
241 | { |
---|
242 | $sql .= ' AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind.ind_kll_id AND ind.ind_crp_id in ( '.implode(',', $this->inv_crp_).' ) AND ind.ind_crp_id != kll.kll_crp_id LIMIT 1)'; |
---|
243 | } |
---|
244 | if ($this->inv_all_) |
---|
245 | { |
---|
246 | $sql .= ' AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind.ind_kll_id and ind.ind_all_id in ( '.implode(',', $this->inv_all_).' ) and ind.ind_all_id != kll.kll_all_id LIMIT 1) '; |
---|
247 | } |
---|
248 | } |
---|
249 | else |
---|
250 | { |
---|
251 | if ($this->inv_plt_) |
---|
252 | { |
---|
253 | $sql .= ' INNER JOIN (SELECT distinct a.ind_kll_id FROM kb3_inv_detail a WHERE a.ind_plt_id in ( '.implode(',', $this->inv_plt_).' ) ) ind ON (ind.ind_kll_id = kll.kll_id) '; |
---|
254 | } |
---|
255 | elseif ($this->inv_crp_) |
---|
256 | { |
---|
257 | $sql .= ' INNER JOIN (SELECT distinct b.ind_kll_id, b.ind_crp_id FROM kb3_inv_detail b WHERE b.ind_crp_id in ( '.implode(',', $this->inv_crp_).' ) ) ind ON (ind.ind_kll_id = kll.kll_id AND ind.ind_crp_id != kll.kll_crp_id) '; |
---|
258 | } |
---|
259 | elseif ($this->inv_all_) |
---|
260 | { |
---|
261 | $sql .= ' INNER JOIN (SELECT distinct c.ind_kll_id, c.ind_all_id FROM kb3_inv_detail c WHERE c.ind_all_id in ( '.implode(',', $this->inv_all_).' ) ) ind ON (ind.ind_kll_id = kll.kll_id AND ind.ind_all_id != kll.kll_all_id) '; |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
266 | |
---|
267 | $qry = new DBQuery(); |
---|
268 | $qry->execute($sql); |
---|
269 | while ($row = $qry->getRow()) |
---|
270 | { |
---|
271 | $this->entry_[$row['scl_class']]['kills'] = $row['knb']; |
---|
272 | $this->entry_[$row['scl_class']]['kills_isk'] = $row['kisk']; |
---|
273 | $this->tkcount_ += $row['knb']; |
---|
274 | $this->tkisk_ += $row['kisk']; |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | $sql = 'SELECT count(distinct kll_id) AS lnb, scl_id, scl_class,'; |
---|
279 | $sql .= ' sum(kll_isk_loss) AS lisk FROM kb3_kills kll |
---|
280 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id )'; |
---|
281 | $sql .= ' INNER JOIN kb3_ship_classes scl ON ( scl.scl_id = shp.shp_class )'; |
---|
282 | |
---|
283 | $sqlop = ' WHERE '; |
---|
284 | if($this->setDateFilter()) |
---|
285 | { |
---|
286 | $sql.= $sqlop.$this->setDateFilter(); |
---|
287 | $sqlop = " AND "; |
---|
288 | } |
---|
289 | |
---|
290 | if ($this->inv_plt_) |
---|
291 | { |
---|
292 | $sql .= $sqlop.' kll.kll_victim_id IN ( '.implode(',', $this->inv_plt_).' ) '; |
---|
293 | $sql .= ' AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind_kll_id AND ind.ind_plt_id NOT IN ( '.implode(',', $this->inv_plt_).' ) limit 0,1) '; |
---|
294 | } |
---|
295 | elseif ($this->inv_crp_) |
---|
296 | { |
---|
297 | $sql .= $sqlop.' kll.kll_crp_id IN ( '.implode(',', $this->inv_crp_).' ) '; |
---|
298 | $sql .= 'AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind_kll_id AND ind.ind_crp_id NOT IN ( '.implode(',', $this->inv_crp_).' ) limit 0,1) '; |
---|
299 | } |
---|
300 | elseif ($this->inv_all_) |
---|
301 | { |
---|
302 | $sql .= $sqlop.' kll.kll_all_id IN ( '.implode(',', $this->inv_all_).' ) '; |
---|
303 | $sql .= 'AND EXISTS (SELECT 1 FROM kb3_inv_detail ind WHERE kll.kll_id = ind_kll_id AND ind.ind_all_id NOT IN ( '.implode(',', $this->inv_all_).' ) limit 0,1) '; |
---|
304 | } |
---|
305 | $sql .= 'GROUP BY scl_class order by scl_class'; |
---|
306 | |
---|
307 | $qry = new DBQuery(); |
---|
308 | $qry->execute($sql); |
---|
309 | while ($row = $qry->getRow()) |
---|
310 | { |
---|
311 | $this->entry_[$row['scl_class']]['losses'] = $row['lnb']; |
---|
312 | $this->entry_[$row['scl_class']]['losses_isk'] = $row['lisk']; |
---|
313 | |
---|
314 | $this->tlcount_ += $row['lnb']; |
---|
315 | $this->tlisk_ += $row['lisk']; |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | function generate() |
---|
320 | { |
---|
321 | if ($this->klist_) |
---|
322 | { |
---|
323 | $entry = array(); |
---|
324 | // build array |
---|
325 | $sql = "select scl_id, scl_class |
---|
326 | from kb3_ship_classes |
---|
327 | where scl_class not in ( 'Drone', 'Unknown' ) |
---|
328 | order by scl_class"; |
---|
329 | |
---|
330 | $qry = new DBQuery(); |
---|
331 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
332 | while ($row = $qry->getRow()) |
---|
333 | { |
---|
334 | if (!$row['scl_id']) |
---|
335 | continue; |
---|
336 | |
---|
337 | $shipclass = new ShipClass($row['scl_id']); |
---|
338 | $shipclass->setName($row['scl_class']); |
---|
339 | |
---|
340 | $entry[$shipclass->getName()]['id'] = $row['scl_id']; |
---|
341 | $entry[$shipclass->getName()]['kills'] = 0; |
---|
342 | $entry[$shipclass->getName()]['kills_isk'] = 0; |
---|
343 | $entry[$shipclass->getName()]['losses'] = 0; |
---|
344 | $entry[$shipclass->getName()]['losses_isk'] = 0; |
---|
345 | } |
---|
346 | // kills |
---|
347 | while ($kill = $this->klist_->getKill()) |
---|
348 | { |
---|
349 | $classname = $kill->getVictimShipClassName(); |
---|
350 | $entry[$classname]['kills']++; |
---|
351 | $entry[$classname]['kills_isk'] += $kill->getISKLoss(); |
---|
352 | $this->tkcount_++; |
---|
353 | $this->tkisk_ += $kill->getISKLoss(); |
---|
354 | } |
---|
355 | // losses |
---|
356 | while ($kill = $this->llist_->getKill()) |
---|
357 | { |
---|
358 | $classname = $kill->getVictimShipClassName(); |
---|
359 | $entry[$classname]['losses']++; |
---|
360 | $entry[$classname]['losses_isk'] += $kill->getISKLoss(); |
---|
361 | $this->tlcount_++; |
---|
362 | $this->tlisk_ += $kill->getISKLoss(); |
---|
363 | } |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | $this->getkills(); |
---|
368 | $entry = &$this->entry_; |
---|
369 | } |
---|
370 | |
---|
371 | $odd = false; |
---|
372 | $prevdate = ""; |
---|
373 | // Don't count noobships. |
---|
374 | $num = count($entry) - 1; |
---|
375 | if($this->break_) $columns = ceil($num/$this->break_); |
---|
376 | else $columns = 2; |
---|
377 | if(!$columns) $columns = 1; |
---|
378 | $width_mod = 1/$columns; |
---|
379 | $width = round($width_mod*100); |
---|
380 | if($this->verbose_) $width_abs = round($width_mod*(760-240*$columns)); |
---|
381 | else $width_abs = round($width_mod*(760-60*$columns)); |
---|
382 | $summary = array(); |
---|
383 | $count = 0; |
---|
384 | foreach ($entry as $k => $v) |
---|
385 | { |
---|
386 | if($v['id'] == 3) continue; |
---|
387 | if($count && $this->break_ && $count%$this->break_ == 0) $v['break'] = 1; |
---|
388 | else $v['break'] = 0; |
---|
389 | if($_GET['scl_id'] && $_GET['scl_id'] == $v['id']) $v['hl'] = 1; |
---|
390 | else $v['hl'] = 0; |
---|
391 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", $_SERVER['QUERY_STRING']); |
---|
392 | $qrystring = preg_replace("/&page=([0-9]?[0-9])/", "", $qrystring); |
---|
393 | $qrystring = preg_replace("/&/", "&", $qrystring); |
---|
394 | if ($this->view_) |
---|
395 | { |
---|
396 | $qrystring .= '&view='.$this->view_; |
---|
397 | } |
---|
398 | $v['qry'] = $qrystring; |
---|
399 | $v['kisk'] = round($v['kills_isk']/1000000, 2); |
---|
400 | $v['lisk'] = round($v['losses_isk']/1000000, 2); |
---|
401 | $v['name'] = $k; |
---|
402 | |
---|
403 | $summary[] = $v; |
---|
404 | $count++; |
---|
405 | |
---|
406 | } |
---|
407 | global $smarty; |
---|
408 | $smarty->assign('summary', $summary); |
---|
409 | $smarty->assign('count', count($entry)); |
---|
410 | $smarty->assign('break', $this->break_); |
---|
411 | $smarty->assign('width', $width); |
---|
412 | $smarty->assign('width_abs', $width_abs); |
---|
413 | $smarty->assign('columns', $columns); |
---|
414 | $smarty->assign('verbose', $this->verbose_); |
---|
415 | $smarty->assign('filter', $this->filter_); |
---|
416 | $smarty->assign('losses', 1); |
---|
417 | |
---|
418 | if (config::get('summarytable_summary')) |
---|
419 | { |
---|
420 | $smarty->assign('summarysummary', 1); |
---|
421 | if (config::get('summarytable_efficiency')) |
---|
422 | $smarty->assign('efficiency', round($this->tkisk_ / (($this->tkisk_ + $this->tlisk_) == 0 ? 1 : ($this->tkisk_ + $this->tlisk_)) * 100, 2)); |
---|
423 | else $smarty->assign('efficiency', 0); |
---|
424 | $smarty->assign('kiskB', round($this->tkisk_/1000000000, 2)); |
---|
425 | $smarty->assign('liskB', round($this->tlisk_/1000000000, 2)); |
---|
426 | $smarty->assign('kiskM', round($this->tkisk_/1000000, 2)); |
---|
427 | $smarty->assign('liskM', round($this->tlisk_/1000000, 2)); |
---|
428 | $smarty->assign('kcount', $this->tkcount_); |
---|
429 | $smarty->assign('lcount', $this->tlcount_); |
---|
430 | } |
---|
431 | |
---|
432 | if ($_GET['scl_id'] != "") |
---|
433 | { |
---|
434 | $qrystring = preg_replace("/&scl_id=([0-9]?[0-9])/", "", '?'.$_SERVER['QUERY_STRING']); |
---|
435 | $qrystring = preg_replace("/&/", "&", $qrystring); |
---|
436 | $smarty->assign('clearfilter',$qrystring); |
---|
437 | } |
---|
438 | |
---|
439 | $html .= $smarty->fetch(get_tpl('summarytable')); |
---|
440 | |
---|
441 | return $html; |
---|
442 | } |
---|
443 | } |
---|
444 | ?> |
---|