1 | <?php |
---|
2 | require_once('common/includes/class.item.php'); |
---|
3 | require_once('common/includes/class.corp.php'); |
---|
4 | require_once('common/includes/class.alliance.php'); |
---|
5 | require_once('common/includes/class.ship.php'); |
---|
6 | require_once('common/includes/class.system.php'); |
---|
7 | require_once('common/includes/class.pilot.php'); |
---|
8 | //require_once('common/includes/class.killlist.php'); |
---|
9 | require_once('common/includes/class.itemlist.php'); |
---|
10 | require_once('common/includes/class.cache.php'); |
---|
11 | require_once('common/includes/class.summary.php'); |
---|
12 | |
---|
13 | class Kill |
---|
14 | { |
---|
15 | function Kill($id = 0, $external = false) |
---|
16 | { |
---|
17 | if($id && $external) |
---|
18 | { |
---|
19 | $qry = new DBQuery(); |
---|
20 | $qry->execute("SELECT kll_id FROM kb3_kills WHERE kll_external_id = ".$id); |
---|
21 | if($qry->recordCount()) |
---|
22 | { |
---|
23 | $result = $qry->getRow(); |
---|
24 | $this->id_ = $result['kll_id']; |
---|
25 | $this->externalid_ = $id; |
---|
26 | } |
---|
27 | else |
---|
28 | { |
---|
29 | $this->id_ = 0; |
---|
30 | $this->external_id = 0; |
---|
31 | } |
---|
32 | } |
---|
33 | else |
---|
34 | { |
---|
35 | $this->id_ = $id; |
---|
36 | $this->externalid_ = 0; |
---|
37 | } |
---|
38 | $this->involvedparties_ = array(); |
---|
39 | $this->destroyeditems_ = array(); |
---|
40 | $this->droppeditems_ = array(); |
---|
41 | $this->fullinvolved_ = false; |
---|
42 | } |
---|
43 | |
---|
44 | function set($var, $value) |
---|
45 | { |
---|
46 | $this->$var = $value; |
---|
47 | } |
---|
48 | |
---|
49 | function getID() |
---|
50 | { |
---|
51 | return $this->id_; |
---|
52 | } |
---|
53 | |
---|
54 | function getExternalID() |
---|
55 | { |
---|
56 | if($this->externalid_) return $this->externalid_; |
---|
57 | $this->execQuery(); |
---|
58 | return $this->externalid_; |
---|
59 | } |
---|
60 | |
---|
61 | function getTimeStamp() |
---|
62 | { |
---|
63 | $this->execQuery(); |
---|
64 | return $this->timestamp_; |
---|
65 | } |
---|
66 | |
---|
67 | function getVictimName() |
---|
68 | { |
---|
69 | $this->execQuery(); |
---|
70 | return $this->victimname_; |
---|
71 | } |
---|
72 | |
---|
73 | function getVictimID() |
---|
74 | { |
---|
75 | $this->execQuery(); |
---|
76 | return $this->victimid_; |
---|
77 | } |
---|
78 | |
---|
79 | function getVictimPortrait($size = 32) |
---|
80 | { |
---|
81 | $this->execQuery(); |
---|
82 | $plt = new Pilot($this->victimid_); |
---|
83 | return $plt->getPortraitURL($size); |
---|
84 | } |
---|
85 | |
---|
86 | function getVictimCorpID() |
---|
87 | { |
---|
88 | $this->execQuery(); |
---|
89 | return $this->victimcorpid_; |
---|
90 | } |
---|
91 | |
---|
92 | function getVictimCorpName() |
---|
93 | { |
---|
94 | $this->execQuery(); |
---|
95 | return $this->victimcorpname_; |
---|
96 | } |
---|
97 | |
---|
98 | function getVictimAllianceName() |
---|
99 | { |
---|
100 | $this->execQuery(); |
---|
101 | return $this->victimalliancename_; |
---|
102 | } |
---|
103 | |
---|
104 | function getVictimAllianceID() |
---|
105 | { |
---|
106 | $this->execQuery(); |
---|
107 | return $this->victimallianceid_; |
---|
108 | } |
---|
109 | |
---|
110 | function getVictimShip() |
---|
111 | { |
---|
112 | $this->execQuery(); |
---|
113 | return $this->victimship_; |
---|
114 | } |
---|
115 | |
---|
116 | function getSystem() |
---|
117 | { |
---|
118 | $this->execQuery(); |
---|
119 | return $this->solarsystem_; |
---|
120 | } |
---|
121 | |
---|
122 | function getFBPilotID() |
---|
123 | { |
---|
124 | $this->execQuery(); |
---|
125 | if (!$this->fbpilotid_) return "null"; |
---|
126 | else return $this->fbpilotid_; |
---|
127 | } |
---|
128 | |
---|
129 | function getFBPilotName() |
---|
130 | { |
---|
131 | $this->execQuery(); |
---|
132 | return $this->fbpilotname_; |
---|
133 | } |
---|
134 | |
---|
135 | function getFBCorpID() |
---|
136 | { |
---|
137 | $this->execQuery(); |
---|
138 | if (!$this->fbcorpid_) return "null"; |
---|
139 | else return $this->fbcorpid_; |
---|
140 | } |
---|
141 | |
---|
142 | function getFBCorpName() |
---|
143 | { |
---|
144 | $this->execQuery(); |
---|
145 | return $this->fbcorpname_; |
---|
146 | } |
---|
147 | |
---|
148 | function getFBAllianceID() |
---|
149 | { |
---|
150 | $this->execQuery(); |
---|
151 | if (!$this->fballianceid_) return "null"; |
---|
152 | else return $this->fballianceid_; |
---|
153 | } |
---|
154 | |
---|
155 | function getFBAllianceName() |
---|
156 | { |
---|
157 | $this->execQuery(); |
---|
158 | return $this->fballiancename_; |
---|
159 | } |
---|
160 | |
---|
161 | function getISKLoss() |
---|
162 | { |
---|
163 | $this->execQuery(); |
---|
164 | return $this->iskloss_; |
---|
165 | } |
---|
166 | function getKillPoints() |
---|
167 | { |
---|
168 | $this->execQuery(); |
---|
169 | return $this->killpoints_; |
---|
170 | } |
---|
171 | |
---|
172 | function getSolarSystemName() |
---|
173 | { |
---|
174 | return $this->solarsystemname_; |
---|
175 | } |
---|
176 | |
---|
177 | function getSolarSystemSecurity() |
---|
178 | { |
---|
179 | return $this->solarsystemsecurity_; |
---|
180 | } |
---|
181 | |
---|
182 | function getVictimShipName() |
---|
183 | { |
---|
184 | return $this->victimshipname_; |
---|
185 | } |
---|
186 | |
---|
187 | function getVictimShipExternalID() |
---|
188 | { |
---|
189 | return $this->victimshipexternalid_; |
---|
190 | } |
---|
191 | |
---|
192 | function getVictimShipClassName() |
---|
193 | { |
---|
194 | return $this->victimshipclassname_; |
---|
195 | } |
---|
196 | |
---|
197 | function getVictimShipValue() |
---|
198 | { |
---|
199 | return $this->victimshipvalue_; |
---|
200 | } |
---|
201 | |
---|
202 | function getVictimShipImage($size) |
---|
203 | { |
---|
204 | return IMG_URL."/ships/".$size."_".$size."/".$this->victimshipexternalid_.".png"; |
---|
205 | } |
---|
206 | |
---|
207 | function getVictimShipValueIndicator() |
---|
208 | { |
---|
209 | // value is now raw |
---|
210 | $value = $this->getVictimShipValue()/1000000; |
---|
211 | |
---|
212 | if ($value >= 0 && $value <= 1) |
---|
213 | $color = 'gray'; |
---|
214 | elseif ($value > 1 && $value <= 15) |
---|
215 | $color = 'blue'; |
---|
216 | elseif ($value > 15 && $value <= 25) |
---|
217 | $color = 'green'; |
---|
218 | elseif ($value > 25 && $value <= 40) |
---|
219 | $color = 'yellow'; |
---|
220 | elseif ($value > 40 && $value <= 80) |
---|
221 | $color = 'red'; |
---|
222 | elseif ($value > 80 && $value <= 250) |
---|
223 | $color = 'orange'; |
---|
224 | elseif ($value > 250) |
---|
225 | $color = 'purple'; |
---|
226 | |
---|
227 | return IMG_URL.'/ships/ship-'.$color.'.gif'; |
---|
228 | } |
---|
229 | |
---|
230 | function getRawMail() |
---|
231 | { |
---|
232 | if (config::get('km_cache_enabled') && file_exists(config::get('km_cache_dir')."/".$this->getID().".txt")) |
---|
233 | { |
---|
234 | return file_get_contents(config::get('km_cache_dir')."/".$this->getID().".txt"); |
---|
235 | } |
---|
236 | |
---|
237 | $this->execQuery(); |
---|
238 | if ($this->isClassified()) |
---|
239 | { |
---|
240 | return 'Killmail not yet available, try again in '.round($this->getClassifiedTime()/3600, 2).' hrs.'; |
---|
241 | } |
---|
242 | |
---|
243 | $ship = $this->getVictimShip(); |
---|
244 | $shipclass = $ship->getClass(); |
---|
245 | |
---|
246 | $mail .= substr(str_replace('-', '.' , $this->getTimeStamp()), 0, 16)."\r\n\r\n"; |
---|
247 | if ( $shipclass->getID() == 35 ) // Starbase (so this is a POS mail) |
---|
248 | { |
---|
249 | $mail .= "Corp: ".$this->getVictimCorpName()."\r\n"; |
---|
250 | $mail .= "Alliance: ".$this->getVictimAllianceName()."\r\n"; |
---|
251 | $mail .= "Faction: NONE\r\n"; |
---|
252 | //$ship = $this->getVictimShip(); |
---|
253 | $mail .= "Destroyed: ".$ship->getName()."\r\n"; |
---|
254 | $mail .= "Moon: ".$this->getVictimName()."\r\n"; |
---|
255 | $system = $this->getSystem(); |
---|
256 | $mail .= "System: ".$system->getName()."\r\n"; |
---|
257 | $mail .= "Security: ".$system->getSecurity(true)."\r\n"; |
---|
258 | $mail .= "Damage Taken: ".$this->VictimDamageTaken."\r\n\r\n"; |
---|
259 | $mail .= "Involved parties:\r\n\r\n"; |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | $mail .= "Victim: ".$this->getVictimName()."\r\n"; |
---|
264 | $mail .= "Corp: ".$this->getVictimCorpName()."\r\n"; |
---|
265 | $mail .= "Alliance: ".$this->getVictimAllianceName()."\r\n"; |
---|
266 | $mail .= "Faction: NONE\r\n"; |
---|
267 | //$ship = $this->getVictimShip(); |
---|
268 | $mail .= "Destroyed: ".$ship->getName()."\r\n"; |
---|
269 | $system = $this->getSystem(); |
---|
270 | $mail .= "System: ".$system->getName()."\r\n"; |
---|
271 | $mail .= "Security: ".$system->getSecurity(true)."\r\n"; |
---|
272 | $mail .= "Damage Taken: ".$this->VictimDamageTaken."\r\n\r\n"; |
---|
273 | $mail .= "Involved parties:\r\n\r\n"; |
---|
274 | } |
---|
275 | |
---|
276 | foreach ($this->involvedparties_ as $inv) |
---|
277 | { |
---|
278 | $pilot = new Pilot($inv->getPilotID()); |
---|
279 | $corp = new Corporation($inv->getCorpID()); |
---|
280 | $alliance = new Alliance($inv->getAllianceID()); |
---|
281 | |
---|
282 | $weapon = $inv->getWeapon(); |
---|
283 | $ship = $inv->getShip(); |
---|
284 | if ($pilot->getName() == $weapon->getName()) |
---|
285 | { |
---|
286 | $name = $pilot->getName()." / ".$corp->getName(); |
---|
287 | } |
---|
288 | else |
---|
289 | { |
---|
290 | $name = $pilot->getName(); |
---|
291 | } |
---|
292 | |
---|
293 | $mail .= "Name: ".$name; |
---|
294 | if ($pilot->getID() == $this->getFBPilotID()) |
---|
295 | { |
---|
296 | $mail .= " (laid the final blow)"; |
---|
297 | } |
---|
298 | $mail .= "\r\n"; |
---|
299 | |
---|
300 | if ($pilot->getName() != $weapon->getName()) |
---|
301 | { |
---|
302 | $mail .= "Security: ".$inv->getSecStatus()."\r\n"; |
---|
303 | $mail .= "Corp: ".$corp->getName()."\r\n"; |
---|
304 | $mail .= "Alliance: ".$alliance->getName()."\r\n"; |
---|
305 | $mail .= "Faction: NONE\r\n"; |
---|
306 | $mail .= "Ship: ".$ship->getName()."\r\n"; |
---|
307 | $mail .= "Weapon: ".$weapon->getName()."\r\n"; |
---|
308 | $mail .= "Damage Done: ".$inv->dmgdone_."\r\n"; |
---|
309 | } |
---|
310 | else |
---|
311 | { |
---|
312 | $mail .= "Damage Done: ".$inv->dmgdone_."\r\n"; |
---|
313 | } |
---|
314 | $mail .= "\r\n"; |
---|
315 | } |
---|
316 | |
---|
317 | if (count($this->destroyeditems_) > 0) |
---|
318 | { |
---|
319 | $mail .= "\r\nDestroyed items:\r\n\r\n"; |
---|
320 | |
---|
321 | foreach($this->destroyeditems_ as $destroyed) |
---|
322 | { |
---|
323 | $item = $destroyed->getItem(); |
---|
324 | $mail .= $item->getName(); |
---|
325 | if ($destroyed->getQuantity() > 1) |
---|
326 | { |
---|
327 | // if the option is enabled and the item is fitted then split it up |
---|
328 | // this is aworkaround for the lazy parser of griefwatch |
---|
329 | if (config::get('kill_splitfit') && $destroyed->getQuantity() < 9 && ($destroyed->getLocationID() == 1 |
---|
330 | || $destroyed->getLocationID() == 2 || $destroyed->getLocationID() == 3)) |
---|
331 | { |
---|
332 | for ($i = $destroyed->getQuantity(); $i > 1; $i--) |
---|
333 | { |
---|
334 | $mail .= "\r\n".$item->getName(); |
---|
335 | } |
---|
336 | |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | $mail .= ", Qty: ".$destroyed->getQuantity(); |
---|
341 | } |
---|
342 | } |
---|
343 | if ($destroyed->getLocationID() == 4) // cargo |
---|
344 | $mail .= " (Cargo)"; |
---|
345 | if ($destroyed->getLocationID() == 6) // drone |
---|
346 | $mail .= " (Drone Bay)"; |
---|
347 | $mail .= "\r\n"; |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | if (count($this->droppeditems_) > 0) |
---|
352 | { |
---|
353 | $mail .= "\r\nDropped items:\r\n\r\n"; |
---|
354 | |
---|
355 | foreach($this->droppeditems_ as $dropped) |
---|
356 | { |
---|
357 | $item = $dropped->getItem(); |
---|
358 | $mail .= $item->getName(); |
---|
359 | if ($dropped->getQuantity() > 1) |
---|
360 | { |
---|
361 | // if the option is enabled and the item is fitted then split it up |
---|
362 | // this is aworkaround for the lazy parser of griefwatch |
---|
363 | if (config::get('kill_splitfit') && $dropped->getQuantity() < 9 && ($dropped->getLocationID() == 1 |
---|
364 | || $dropped->getLocationID() == 2 || $dropped->getLocationID() == 3)) |
---|
365 | { |
---|
366 | for ($i = $dropped->getQuantity(); $i > 1; $i--) |
---|
367 | { |
---|
368 | $mail .= "\r\n".$item->getName(); |
---|
369 | } |
---|
370 | |
---|
371 | } |
---|
372 | else |
---|
373 | { |
---|
374 | $mail .= ", Qty: ".$dropped->getQuantity(); |
---|
375 | } |
---|
376 | } |
---|
377 | if ($dropped->getLocationID() == 4) // cargo |
---|
378 | $mail .= " (Cargo)"; |
---|
379 | if ($dropped->getLocationID() == 6) // drone |
---|
380 | $mail .= " (Drone Bay)"; |
---|
381 | $mail .= "\r\n"; |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | if (config::get('km_cache_enabled')) file_put_contents(config::get('km_cache_dir')."/".$this->getID().".txt", $mail); |
---|
386 | |
---|
387 | return $mail; |
---|
388 | } |
---|
389 | |
---|
390 | function getDupe($checkonly = false) |
---|
391 | { |
---|
392 | if (!$checkonly) |
---|
393 | { |
---|
394 | $this->execQuery(); |
---|
395 | } |
---|
396 | $dupe = 0; |
---|
397 | $qry = new DBQuery(true); |
---|
398 | if (!$this->getFBPilotID() || !$this->victimid_) |
---|
399 | return 0; |
---|
400 | $qry->execute("select kll_id |
---|
401 | from kb3_kills |
---|
402 | where kll_timestamp ='".$this->timestamp_."' |
---|
403 | and kll_victim_id = ".$this->victimid_." |
---|
404 | and kll_ship_id = ".$this->victimship_->getID()." |
---|
405 | and kll_system_id = ".$this->solarsystem_->getID()." |
---|
406 | and kll_fb_plt_id = ".$this->getFBPilotID()." |
---|
407 | and kll_id != ".$this->id_); |
---|
408 | |
---|
409 | $row = $qry->getRow(); |
---|
410 | if ($row) |
---|
411 | return $row['kll_id']; |
---|
412 | else |
---|
413 | return 0; |
---|
414 | } |
---|
415 | |
---|
416 | function execQuery() |
---|
417 | { |
---|
418 | if (!$this->timestamp_) |
---|
419 | { |
---|
420 | $qry = new DBQuery(); |
---|
421 | |
---|
422 | $this->qry_ = new DBQuery(); |
---|
423 | $this->sql_ = "select kll.kll_id, kll.kll_timestamp, plt.plt_name, |
---|
424 | crp.crp_name, ali.all_name, ali.all_id, kll.kll_ship_id, |
---|
425 | kll.kll_system_id, kll.kll_ship_id, kll.kll_external_id, |
---|
426 | kll.kll_victim_id, plt.plt_externalid, kll.kll_isk_loss, |
---|
427 | kll.kll_crp_id, kll.kll_points, kll.kll_isk_loss, |
---|
428 | fbplt.plt_id as fbplt_id, |
---|
429 | fbplt.plt_externalid as fbplt_externalid, |
---|
430 | fbcrp.crp_id as fbcrp_id, |
---|
431 | fbali.all_id as fbali_id, |
---|
432 | fbplt.plt_name as fbplt_name, |
---|
433 | fbcrp.crp_name as fbcrp_name, |
---|
434 | fbali.all_name as fbali_name, |
---|
435 | kll_dmgtaken |
---|
436 | from kb3_kills kll, kb3_pilots plt, kb3_corps crp, |
---|
437 | kb3_alliances ali, kb3_alliances fbali, kb3_corps fbcrp, |
---|
438 | kb3_pilots fbplt, kb3_inv_detail fb |
---|
439 | where kll.kll_id = '".$this->id_."' |
---|
440 | and plt.plt_id = kll.kll_victim_id |
---|
441 | and crp.crp_id = kll.kll_crp_id |
---|
442 | and ali.all_id = kll.kll_all_id |
---|
443 | and fb.ind_kll_id = kll.kll_id |
---|
444 | and fb.ind_plt_id = kll.kll_fb_plt_id |
---|
445 | and fbali.all_id = fb.ind_all_id |
---|
446 | and fbcrp.crp_id = fb.ind_crp_id |
---|
447 | and fbplt.plt_id = kll.kll_fb_plt_id"; |
---|
448 | |
---|
449 | $this->qry_->execute($this->sql_); |
---|
450 | $row = $this->qry_->getRow(); |
---|
451 | if (!$row) |
---|
452 | { |
---|
453 | $this->valid_ = false; |
---|
454 | return false; |
---|
455 | } |
---|
456 | else |
---|
457 | { |
---|
458 | $this->valid_ = true; |
---|
459 | } |
---|
460 | |
---|
461 | $this->setTimeStamp($row['kll_timestamp']); |
---|
462 | $this->setSolarSystem(new SolarSystem($row['kll_system_id'])); |
---|
463 | $this->setVictimID($row['kll_victim_id']); |
---|
464 | $this->setVictimName($row['plt_name']); |
---|
465 | $this->setVictimCorpID($row['kll_crp_id']); |
---|
466 | $this->setVictimCorpName($row['crp_name']); |
---|
467 | $this->setVictimAllianceID($row['all_id']); |
---|
468 | $this->setVictimAllianceName($row['all_name']); |
---|
469 | $this->setVictimShip(new Ship($row['kll_ship_id'])); |
---|
470 | $this->setFBPilotID($row['fbplt_id']); |
---|
471 | $this->setFBPilotName($row['fbplt_name']); |
---|
472 | $this->setFBCorpID($row['fbcrp_id']); |
---|
473 | $this->setFBCorpName($row['fbcrp_name']); |
---|
474 | $this->setFBAllianceID($row['fbali_id']); |
---|
475 | $this->setFBAllianceName($row['fbali_name']); |
---|
476 | $this->setKillPoints($row['kll_points']); |
---|
477 | $this->setExternalID($row['kll_external_id']); |
---|
478 | $this->setISKLoss($row['kll_isk_loss']); |
---|
479 | $this->plt_ext_ = $row['plt_externalid']; |
---|
480 | $this->fbplt_ext_ = $row['fbplt_externalid']; |
---|
481 | $this->VictimDamageTaken = $row['kll_dmgtaken']; |
---|
482 | |
---|
483 | // involved |
---|
484 | if($this->fullinvolved_) |
---|
485 | { |
---|
486 | $sql = "select ind_plt_id, ind_crp_id, ind_all_id, ind_sec_status, |
---|
487 | ind_shp_id, ind_wep_id, typeName, ind_dmgdone, |
---|
488 | shp_id, shp_name, shp_externalid, shp_class, scl_class, |
---|
489 | plt_name, plt_externalid, crp_name, all_name |
---|
490 | from kb3_inv_detail |
---|
491 | join kb3_pilots on ind_plt_id = plt_id |
---|
492 | join kb3_corps on ind_crp_id = crp_id |
---|
493 | join kb3_alliances on ind_all_id = all_id |
---|
494 | join kb3_ships on ind_shp_id = shp_id |
---|
495 | join kb3_ship_classes on shp_class = scl_id |
---|
496 | join kb3_invtypes on ind_wep_id = typeID |
---|
497 | where ind_kll_id = ".$this->getID()." |
---|
498 | order by ind_order"; |
---|
499 | |
---|
500 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
501 | while ($row = $qry->getRow()) |
---|
502 | { |
---|
503 | $pilot = new Pilot($row['ind_plt_id']); |
---|
504 | $pilot->externalid_ = $row['plt_externalid']; |
---|
505 | $pilot->name_ = $row['plt_name']; |
---|
506 | $pilot->corp_ = $row['ind_crp_id']; |
---|
507 | |
---|
508 | $corp = new Corporation($row['ind_crp_id']); |
---|
509 | $corp->name_ = $row['crp_name']; |
---|
510 | $corp->alliance_ = $row['ind_all_id']; |
---|
511 | |
---|
512 | $alliance = new Alliance($row['ind_all_id']); |
---|
513 | $alliance->name_ = $row['all_name']; |
---|
514 | |
---|
515 | $ship = new Ship($row['shp_id']); |
---|
516 | $ship->externalid_ = $row['shp_externalid']; |
---|
517 | $ship->shipname_ = $row['shp_name']; |
---|
518 | |
---|
519 | $ship->shipclass_ = new ShipClass($row['shp_class']); |
---|
520 | $ship->shipclass_->name_ = $row['scl_class']; |
---|
521 | |
---|
522 | $weapon = new Item($row['ind_wep_id']); |
---|
523 | $weapon->row_['typeName'] = $row['typeName']; |
---|
524 | $weapon->row_['typeID'] = $row['ind_wep_id']; |
---|
525 | $weapon->row_['itm_externalid'] = $row['ind_wep_id']; |
---|
526 | |
---|
527 | $involved = new DetailedInv($pilot, |
---|
528 | $row['ind_sec_status'], |
---|
529 | $corp, |
---|
530 | $alliance, |
---|
531 | $ship, |
---|
532 | $weapon); |
---|
533 | $involved->dmgdone_ = $row['ind_dmgdone']; |
---|
534 | array_push($this->involvedparties_, $involved); |
---|
535 | } |
---|
536 | } |
---|
537 | else |
---|
538 | { |
---|
539 | $sql = "select ind_plt_id, ind_crp_id, ind_all_id, ind_sec_status, |
---|
540 | ind_shp_id, ind_wep_id, ind_dmgdone |
---|
541 | from kb3_inv_detail |
---|
542 | where ind_kll_id = ".$this->getID()." |
---|
543 | order by ind_order"; |
---|
544 | |
---|
545 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
546 | while ($row = $qry->getRow()) |
---|
547 | { |
---|
548 | $involved = new InvolvedParty($row['ind_plt_id'], |
---|
549 | $row['ind_crp_id'], |
---|
550 | $row['ind_all_id'], |
---|
551 | $row['ind_sec_status'], |
---|
552 | new Ship($row['ind_shp_id']), |
---|
553 | new Item($row['ind_wep_id'])); |
---|
554 | $involved->dmgdone_ = $row['ind_dmgdone']; |
---|
555 | array_push($this->involvedparties_, $involved); |
---|
556 | } |
---|
557 | } |
---|
558 | $destroyedlist = new ItemList(null, true); |
---|
559 | $destroyedlist->addKillDestroyed($this->id_); |
---|
560 | while($item = $destroyedlist->getItem()) |
---|
561 | { |
---|
562 | $destroyed = new DestroyedItem($item, |
---|
563 | $item->row_['itd_quantity'], |
---|
564 | $item->row_['itl_location'], |
---|
565 | $item->row_['itd_itl_id']); |
---|
566 | array_push($this->destroyeditems_, $destroyed); |
---|
567 | } |
---|
568 | $droppedlist = new ItemList(null, true); |
---|
569 | $droppedlist->addKillDropped($this->id_); |
---|
570 | while($item = $droppedlist->getItem()) |
---|
571 | { |
---|
572 | $dropped = new DroppedItem($item, |
---|
573 | $item->row_['itd_quantity'], |
---|
574 | $item->row_['itl_location'], |
---|
575 | $item->row_['itd_itl_id']); |
---|
576 | array_push($this->droppeditems_, $dropped); |
---|
577 | } |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | function isClassified() |
---|
582 | { |
---|
583 | if (config::get('kill_classified')) |
---|
584 | { |
---|
585 | if (user::role('classified_see')) |
---|
586 | { |
---|
587 | return false; |
---|
588 | } |
---|
589 | |
---|
590 | $offset = config::get('kill_classified')*3600; |
---|
591 | if (config::get('date_gmtime')) |
---|
592 | { |
---|
593 | $time = time()-date('Z'); |
---|
594 | } |
---|
595 | else |
---|
596 | { |
---|
597 | $time = time(); |
---|
598 | } |
---|
599 | if (strtotime($this->timestamp_) > $time-$offset) |
---|
600 | { |
---|
601 | return true; |
---|
602 | } |
---|
603 | } |
---|
604 | return false; |
---|
605 | } |
---|
606 | |
---|
607 | function getClassifiedTime() |
---|
608 | { |
---|
609 | if (config::get('kill_classified')) |
---|
610 | { |
---|
611 | $offset = config::get('kill_classified')*3600; |
---|
612 | if (config::get('date_gmtime')) |
---|
613 | { |
---|
614 | $time = time()-date('Z'); |
---|
615 | } |
---|
616 | else |
---|
617 | { |
---|
618 | $time = time(); |
---|
619 | } |
---|
620 | if (strtotime($this->timestamp_) > $time-$offset) |
---|
621 | { |
---|
622 | return ($offset-$time+strtotime($this->timestamp_)); |
---|
623 | } |
---|
624 | } |
---|
625 | return 0; |
---|
626 | } |
---|
627 | |
---|
628 | function getInvolvedPartyCount() |
---|
629 | { |
---|
630 | if(isset($this->involvedcount_)) return $this->involvedcount_; |
---|
631 | $qry = new DBQuery(); |
---|
632 | $qry->execute("select max(ind_order)+1 inv from kb3_inv_detail where ind_kll_id = ". $this->id_); |
---|
633 | $result = $qry->getRow(); |
---|
634 | $this->involvedcount_ = $result['inv']; |
---|
635 | return $result['inv']; |
---|
636 | } |
---|
637 | |
---|
638 | // Set the number of involved parties - used by killlist |
---|
639 | function setInvolvedPartyCount($invcount = 0) |
---|
640 | { |
---|
641 | $this->involvedcount_ = $invcount; |
---|
642 | } |
---|
643 | |
---|
644 | function setDetailedInvolved() |
---|
645 | { |
---|
646 | $this->fullinvolved_ = true; |
---|
647 | } |
---|
648 | function exists() |
---|
649 | { |
---|
650 | $this->execQuery(); |
---|
651 | return $this->valid_; |
---|
652 | } |
---|
653 | |
---|
654 | //Count all kills by board owner related to this kill |
---|
655 | function relatedKillCount() |
---|
656 | { |
---|
657 | if($this->relatedkillcount_) return $this->relatedkillcount_; |
---|
658 | $sql="SELECT COUNT(kll.kll_id) AS kills FROM kb3_kills kll WHERE "; |
---|
659 | $sql.="kll.kll_timestamp <= '".(date('Y-m-d H:i:s',strtotime($this->timestamp_) + 60 * 60))."' |
---|
660 | AND kll.kll_timestamp >= |
---|
661 | '".(date('Y-m-d H:i:s',strtotime($this->timestamp_) - 60 * 60))."' |
---|
662 | AND kll.kll_system_id = ".$this->solarsystem_->getID(); |
---|
663 | if(ALLIANCE_ID <>0) |
---|
664 | { |
---|
665 | $sql .=" AND EXISTS (SELECT 1 FROM kb3_inv_detail ind". |
---|
666 | " WHERE ( ind.ind_all_id = ".ALLIANCE_ID." AND kll.kll_id = ind.ind_kll_id". |
---|
667 | " AND ind.ind_all_id != kll.kll_all_id ) LIMIT 1)"; |
---|
668 | } |
---|
669 | else if(CORP_ID <>0) |
---|
670 | { |
---|
671 | $sql .=" AND EXISTS (SELECT 1 FROM kb3_inv_detail". |
---|
672 | " WHERE ( ind_crp_id = ".CORP_ID." AND kll.kll_id = ind_kll_id". |
---|
673 | " AND ind_crp_id != kll.kll_crp_id ) LIMIT 1) "; |
---|
674 | } |
---|
675 | else if(PILOT_ID <>0) |
---|
676 | { |
---|
677 | $sql .=" AND EXISTS (SELECT 1 FROM kb3_inv_detail". |
---|
678 | " WHERE ( ind_plt_id = ".PILOT_ID." AND kll.kll_id = ind_kll_id". |
---|
679 | " AND ind_plt_id != kll.kll_victim_id ) LIMIT 1) "; |
---|
680 | } |
---|
681 | $sql .= "-- related kill count"; |
---|
682 | $qry = new DBQuery(); |
---|
683 | if(!$qry->execute($sql)) return 0; |
---|
684 | $res=$qry->getRow(); |
---|
685 | $this->relatedkillcount_ = $res['kills']; |
---|
686 | return $this->relatedkillcount_; |
---|
687 | } |
---|
688 | |
---|
689 | //Count all losses by board owner related to this kill |
---|
690 | function relatedLossCount() |
---|
691 | { |
---|
692 | if($this->relatedlosscount_) return $this->relatedlosscount_; |
---|
693 | $sql="SELECT count(kll.kll_id) as losses FROM kb3_kills kll "; |
---|
694 | $sql.="WHERE kll.kll_system_id = ".$this->solarsystem_->getID(). |
---|
695 | " AND kll.kll_timestamp <= '". |
---|
696 | (date('Y-m-d H:i:s',strtotime($this->timestamp_) + 60 * 60)). |
---|
697 | "' AND kll.kll_timestamp >= '". |
---|
698 | (date('Y-m-d H:i:s',strtotime($this->timestamp_) - 60 * 60))."'"; |
---|
699 | if(ALLIANCE_ID <>0) |
---|
700 | { |
---|
701 | $sql .="AND kll.kll_all_id = ".ALLIANCE_ID. |
---|
702 | " AND EXISTS (SELECT 1 FROM kb3_inv_detail ind". |
---|
703 | " WHERE ( kll.kll_id = ind.ind_kll_id". |
---|
704 | " AND ind.ind_all_id != ".ALLIANCE_ID." ) ) "; |
---|
705 | } |
---|
706 | else if(CORP_ID <>0) |
---|
707 | { |
---|
708 | $sql .="AND kll_crp_id = ".CORP_ID." AND". |
---|
709 | " EXISTS (SELECT 1 FROM kb3_inv_detail". |
---|
710 | " WHERE ( kll.kll_id = ind_kll_id". |
---|
711 | " AND ind_crp_id != ".CORP_ID." ) ) "; |
---|
712 | } |
---|
713 | else if(PILOT_ID <>0) |
---|
714 | { |
---|
715 | $sql .="AND kll_victim_id = ".PILOT_ID." AND". |
---|
716 | " EXISTS (SELECT 1 FROM kb3_inv_detail". |
---|
717 | " WHERE ( kll.kll_id = ind_kll_id". |
---|
718 | " AND ind_plt_id != ".PILOT_ID." ) ) "; |
---|
719 | } |
---|
720 | $sql .= "-- related loss count"; |
---|
721 | $qry = new DBQuery(); |
---|
722 | if(!$qry->execute($sql)) return 0; |
---|
723 | $res=$qry->getRow(); |
---|
724 | $this->relatedlosscount_ = $res['losses']; |
---|
725 | return $this->relatedlosscount_; |
---|
726 | } |
---|
727 | |
---|
728 | function countComment($kll_id) |
---|
729 | { |
---|
730 | if(isset($this->commentcount_)) return $this->commentcount_; |
---|
731 | $qry = new DBQuery(); |
---|
732 | $sql = "SELECT count(id) as comments FROM kb3_comments WHERE kll_id = '$kll_id'"; |
---|
733 | // return 0 if query fails. May be incorrect but is harmless here |
---|
734 | if(!$qry->execute($sql)) return 0; |
---|
735 | $result = $qry->getRow(); |
---|
736 | $this->commentcount_ = $result['comments']; |
---|
737 | return $result['comments']; |
---|
738 | } |
---|
739 | |
---|
740 | // Set the number of comments - used by killlist |
---|
741 | function setCommentCount($comcount = 0) |
---|
742 | { |
---|
743 | $this->commentcount_ = $comcount; |
---|
744 | } |
---|
745 | |
---|
746 | function setID($id) |
---|
747 | { |
---|
748 | $this->id_ = $id; |
---|
749 | } |
---|
750 | |
---|
751 | function setTimeStamp($timestamp) |
---|
752 | { |
---|
753 | $this->timestamp_ = $timestamp; |
---|
754 | } |
---|
755 | |
---|
756 | function setSolarSystem($solarsystem) |
---|
757 | { |
---|
758 | $this->solarsystem_ = $solarsystem; |
---|
759 | } |
---|
760 | |
---|
761 | function setSolarSystemName($solarsystemname) |
---|
762 | { |
---|
763 | $this->solarsystemname_ = $solarsystemname; |
---|
764 | } |
---|
765 | |
---|
766 | function setSolarSystemSecurity($solarsystemsecurity) |
---|
767 | { |
---|
768 | $this->solarsystemsecurity_ = $solarsystemsecurity; |
---|
769 | } |
---|
770 | |
---|
771 | function setExternalID($externalid) |
---|
772 | { |
---|
773 | if($externalid) $this->externalid_ = $externalid; |
---|
774 | else $this->externalid_ = 0; |
---|
775 | } |
---|
776 | |
---|
777 | function setVictim($victim) |
---|
778 | { |
---|
779 | $this->victim_ = $victim; |
---|
780 | } |
---|
781 | |
---|
782 | function setVictimID($victimid) |
---|
783 | { |
---|
784 | $this->victimid_ = $victimid; |
---|
785 | } |
---|
786 | |
---|
787 | function setVictimName($victimname) |
---|
788 | { |
---|
789 | $this->victimname_ = $victimname; |
---|
790 | } |
---|
791 | |
---|
792 | function setVictimCorpID($victimcorpid) |
---|
793 | { |
---|
794 | $this->victimcorpid_ = $victimcorpid; |
---|
795 | } |
---|
796 | |
---|
797 | function setVictimCorpName($victimcorpname) |
---|
798 | { |
---|
799 | $this->victimcorpname_ = $victimcorpname; |
---|
800 | } |
---|
801 | |
---|
802 | function setVictimAllianceID($victimallianceid) |
---|
803 | { |
---|
804 | $this->victimallianceid_ = $victimallianceid; |
---|
805 | } |
---|
806 | |
---|
807 | function setVictimAllianceName($victimalliancename) |
---|
808 | { |
---|
809 | $this->victimalliancename_ = $victimalliancename; |
---|
810 | } |
---|
811 | |
---|
812 | function setVictimShip($victimship) |
---|
813 | { |
---|
814 | $this->victimship_ = $victimship; |
---|
815 | } |
---|
816 | |
---|
817 | function setVictimShipName($victimshipname) |
---|
818 | { |
---|
819 | $this->victimshipname_ = $victimshipname; |
---|
820 | } |
---|
821 | |
---|
822 | function setVictimShipExternalID($victimshipexternalid) |
---|
823 | { |
---|
824 | $this->victimshipexternalid_ = $victimshipexternalid; |
---|
825 | } |
---|
826 | |
---|
827 | function setVictimShipClassName($victimshipclassname) |
---|
828 | { |
---|
829 | $this->victimshipclassname_ = $victimshipclassname; |
---|
830 | } |
---|
831 | |
---|
832 | function setVictimShipValue($victimshipvalue) |
---|
833 | { |
---|
834 | $this->victimshipvalue_ = $victimshipvalue; |
---|
835 | } |
---|
836 | |
---|
837 | function setFBPilotID($fbpilotid) |
---|
838 | { |
---|
839 | $this->fbpilotid_ = $fbpilotid; |
---|
840 | } |
---|
841 | |
---|
842 | function setFBPilotName($fbpilotname) |
---|
843 | { |
---|
844 | $npc = strpos($fbpilotname, "#"); |
---|
845 | if ($npc === false) |
---|
846 | { |
---|
847 | $this->fbpilotname_ = $fbpilotname; |
---|
848 | } |
---|
849 | else |
---|
850 | { |
---|
851 | $name = explode("#", $fbpilotname); |
---|
852 | $plt = new Item($name[2]); |
---|
853 | $this->fbpilotname_ = $plt->getName(); |
---|
854 | } |
---|
855 | } |
---|
856 | |
---|
857 | function setFBCorpID($fbcorpid) |
---|
858 | { |
---|
859 | $this->fbcorpid_ = $fbcorpid; |
---|
860 | } |
---|
861 | |
---|
862 | function setFBCorpName($fbcorpname) |
---|
863 | { |
---|
864 | $this->fbcorpname_ = $fbcorpname; |
---|
865 | } |
---|
866 | |
---|
867 | function setFBAllianceID($fballianceid) |
---|
868 | { |
---|
869 | $this->fballianceid_ = $fballianceid; |
---|
870 | } |
---|
871 | |
---|
872 | function setFBAllianceName($fballiancename) |
---|
873 | { |
---|
874 | $this->fballiancename_ = $fballiancename; |
---|
875 | } |
---|
876 | function setKillPoints($killpoints) |
---|
877 | { |
---|
878 | $this->killpoints_ = $killpoints; |
---|
879 | } |
---|
880 | |
---|
881 | function setISKLoss($isk) |
---|
882 | { |
---|
883 | $this->iskloss_ = $isk; |
---|
884 | } |
---|
885 | |
---|
886 | function calculateISKLoss() |
---|
887 | { |
---|
888 | $value = 0; |
---|
889 | foreach($this->destroyeditems_ as $itd) |
---|
890 | { |
---|
891 | $value += $itd->getValue() * $itd->getQuantity(); |
---|
892 | } |
---|
893 | if(config::get('kd_droptototal')) |
---|
894 | { |
---|
895 | foreach($this->droppeditems_ as $itd) |
---|
896 | { |
---|
897 | $value += $itd->getValue() * $itd->getQuantity(); |
---|
898 | } |
---|
899 | } |
---|
900 | $value += $this->getVictimShip()->getPrice(); |
---|
901 | $this->iskloss_ = $value; |
---|
902 | return $value; |
---|
903 | } |
---|
904 | |
---|
905 | function calculateKillPoints() |
---|
906 | { |
---|
907 | $ship = $this->getVictimShip(); |
---|
908 | $shipclass = $ship->getClass(); |
---|
909 | $vicpoints = $shipclass->getPoints(); |
---|
910 | $maxpoints = round($vicpoints * 1.2); |
---|
911 | |
---|
912 | foreach ($this->involvedparties_ as $inv) |
---|
913 | { |
---|
914 | $shipinv = $inv->getShip(); |
---|
915 | $shipclassinv = $shipinv->getClass(); |
---|
916 | $invpoints += $shipclassinv->getPoints(); |
---|
917 | } |
---|
918 | |
---|
919 | $gankfactor = $vicpoints / ($vicpoints + $invpoints); |
---|
920 | $points = ceil($vicpoints * ($gankfactor / 0.75)); |
---|
921 | |
---|
922 | if ($points > $maxpoints) $points = $maxpoints; |
---|
923 | |
---|
924 | $points = round($points, 0); |
---|
925 | return $points; |
---|
926 | } |
---|
927 | |
---|
928 | function add($id = null) |
---|
929 | { |
---|
930 | if (!$this->solarsystem_->getID()) |
---|
931 | { |
---|
932 | echo 'INTERNAL ERROR; SOLARSYSTEM NOT FOUND; PLEASE CONTACT A DEV WITH THIS MESSAGE<br/>'; |
---|
933 | var_dump($this->solarsystem_); |
---|
934 | var_dump($this->solarsystemname_); |
---|
935 | return 0; |
---|
936 | } |
---|
937 | |
---|
938 | $dupe = $this->getDupe(true); |
---|
939 | if ($dupe == 0) |
---|
940 | { |
---|
941 | $this->realadd(); |
---|
942 | } |
---|
943 | elseif (config::get('readd_dupes')) |
---|
944 | { |
---|
945 | $this->dupeid_ = $dupe; |
---|
946 | $this->id_ = $dupe; |
---|
947 | $this->remove(false); |
---|
948 | $this->realadd($dupe); |
---|
949 | $this->id_ = -1; |
---|
950 | } |
---|
951 | else |
---|
952 | { |
---|
953 | $this->dupeid_ = $dupe; |
---|
954 | $this->id_ = -1; |
---|
955 | } |
---|
956 | return $this->id_; |
---|
957 | } |
---|
958 | |
---|
959 | function realadd($id = null) |
---|
960 | { |
---|
961 | if ( $this->timestamp_ == "" || !$this->victimid_ || !$this->victimship_->getID() || !$this->solarsystem_->getID() || |
---|
962 | !$this->victimallianceid_ || !$this->victimcorpid_ || !$this->getFBAllianceID() || !$this->getFBCorpID() || |
---|
963 | !$this->getFBPilotID() ) return 0; |
---|
964 | if ($id == null) |
---|
965 | { |
---|
966 | $qid = 'null'; |
---|
967 | } |
---|
968 | else |
---|
969 | { |
---|
970 | $qid = $id; |
---|
971 | } |
---|
972 | if (!$this->dmgtaken) |
---|
973 | { |
---|
974 | $this->dmgtaken = 0; |
---|
975 | } |
---|
976 | |
---|
977 | $qry = new DBQuery(); |
---|
978 | $sql = "INSERT INTO kb3_kills |
---|
979 | (kll_id , kll_timestamp , kll_victim_id , kll_all_id , kll_crp_id , kll_ship_id , kll_system_id , kll_fb_plt_id , kll_points , kll_dmgtaken, kll_external_id, kll_isk_loss) |
---|
980 | VALUES (".$qid.", |
---|
981 | date_format('".$this->timestamp_."', '%Y.%m.%d %H:%i:%s'), |
---|
982 | ".$this->victimid_.", |
---|
983 | ".$this->victimallianceid_.", |
---|
984 | ".$this->victimcorpid_.", |
---|
985 | ".$this->victimship_->getID().", |
---|
986 | ".$this->solarsystem_->getID().", |
---|
987 | ".$this->getFBPilotID().", |
---|
988 | ".$this->calculateKillPoints().", |
---|
989 | ".$this->dmgtaken.", "; |
---|
990 | if($this->externalid_) $sql .= $this->externalid_.", "; |
---|
991 | else $sql .= "NULL, "; |
---|
992 | $sql .= $this->calculateISKLoss()." )"; |
---|
993 | $qry->autocommit(false); |
---|
994 | if(!$qry->execute($sql)) |
---|
995 | { |
---|
996 | $qry->rollback(); |
---|
997 | $qry->autocommit(true); |
---|
998 | //If the query is causing errors here there's no point going on |
---|
999 | return false; |
---|
1000 | } |
---|
1001 | |
---|
1002 | if ($id) |
---|
1003 | { |
---|
1004 | $this->id_ = $id; |
---|
1005 | } |
---|
1006 | else |
---|
1007 | { |
---|
1008 | $this->id_ = $qry->getInsertID(); |
---|
1009 | } |
---|
1010 | if(!$this->id_) |
---|
1011 | { |
---|
1012 | $qry->rollback(); |
---|
1013 | $qry->autocommit(true); |
---|
1014 | return false; |
---|
1015 | } |
---|
1016 | // involved |
---|
1017 | $order = 0; |
---|
1018 | $invall = array(); |
---|
1019 | $invcrp = array(); |
---|
1020 | $invplt = array(); |
---|
1021 | $involveddsql = 'insert into kb3_inv_detail |
---|
1022 | (ind_kll_id, ind_plt_id, ind_sec_status, ind_all_id, ind_crp_id, ind_shp_id, ind_wep_id, ind_order, ind_dmgdone ) |
---|
1023 | values '; |
---|
1024 | $notfirstd = false; |
---|
1025 | foreach ($this->involvedparties_ as $inv) |
---|
1026 | { |
---|
1027 | $ship = $inv->getShip(); |
---|
1028 | $weapon = $inv->getWeapon(); |
---|
1029 | if (!$inv->getPilotID() || $inv->getSecStatus() == "" || !$inv->getAllianceID() || !$inv->getCorpID() || !$ship->getID() || !$weapon->getID()) |
---|
1030 | { |
---|
1031 | $this->remove(); |
---|
1032 | return 0; |
---|
1033 | } |
---|
1034 | |
---|
1035 | if (!$inv->dmgdone_) |
---|
1036 | { |
---|
1037 | $inv->dmgdone_ = 0; |
---|
1038 | } |
---|
1039 | if($notfirstd) $involveddsql .= ", "; |
---|
1040 | $involveddsql .= "( ".$this->getID().", ".$inv->getPilotID().", '".$inv->getSecStatus()."', " |
---|
1041 | .$inv->getAllianceID().", ".$inv->getCorpID().", ".$ship->getID().", " |
---|
1042 | .$weapon->getID().", ".$order++.", ".$inv->dmgdone_.")"; |
---|
1043 | $notfirstd = true; |
---|
1044 | |
---|
1045 | } |
---|
1046 | if($notfirstd && !$qry->execute($involveddsql)) |
---|
1047 | { |
---|
1048 | $qry->rollback(); |
---|
1049 | $qry->autocommit(true); |
---|
1050 | return false; |
---|
1051 | } |
---|
1052 | |
---|
1053 | // destroyed |
---|
1054 | $notfirstitd=false; |
---|
1055 | $itdsql = "insert into kb3_items_destroyed (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values "; |
---|
1056 | foreach ($this->destroyeditems_ as $dest) |
---|
1057 | { |
---|
1058 | $item = $dest->getItem(); |
---|
1059 | $loc_id = $dest->getLocationID(); |
---|
1060 | if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) |
---|
1061 | { |
---|
1062 | trigger_error('error with destroyed item.', E_USER_WARNING); |
---|
1063 | var_dump($dest);exit; |
---|
1064 | continue; |
---|
1065 | } |
---|
1066 | |
---|
1067 | if($notfirstitd) $itdsql .= ", "; |
---|
1068 | $itdsql .= "( ".$this->getID().", ".$item->getID().", ".$dest->getQuantity().", ".$loc_id." )"; |
---|
1069 | $notfirstitd = true; |
---|
1070 | } |
---|
1071 | if($notfirstitd &&!$qry->execute($itdsql)) |
---|
1072 | { |
---|
1073 | $qry->rollback(); |
---|
1074 | $qry->autocommit(true); |
---|
1075 | return false; |
---|
1076 | } |
---|
1077 | |
---|
1078 | // dropped |
---|
1079 | $notfirstitd=false; |
---|
1080 | $itdsql = "insert into kb3_items_dropped (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values "; |
---|
1081 | foreach ($this->droppeditems_ as $dest) |
---|
1082 | { |
---|
1083 | $item = $dest->getItem(); |
---|
1084 | $loc_id = $dest->getLocationID(); |
---|
1085 | if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) |
---|
1086 | { |
---|
1087 | trigger_error('error with dropped item.', E_USER_WARNING); |
---|
1088 | var_dump($dest);exit; |
---|
1089 | continue; |
---|
1090 | } |
---|
1091 | |
---|
1092 | if($notfirstitd) $itdsql .= ", "; |
---|
1093 | $itdsql .= "( ".$this->getID().", ".$item->getID().", ".$dest->getQuantity().", ".$loc_id." )"; |
---|
1094 | $notfirstitd = true; |
---|
1095 | } |
---|
1096 | if($notfirstitd &&!$qry->execute($itdsql)) |
---|
1097 | { |
---|
1098 | $qry->rollback(); |
---|
1099 | $qry->autocommit(true); |
---|
1100 | return false; |
---|
1101 | } |
---|
1102 | //Update cache tables. |
---|
1103 | allianceSummary::addKill($this); |
---|
1104 | corpSummary::addKill($this); |
---|
1105 | pilotSummary::addKill($this); |
---|
1106 | $qry->autocommit(true); |
---|
1107 | // call the event that we added this mail |
---|
1108 | event::call('killmail_added', $this); |
---|
1109 | cache::notifyKillAdded(); |
---|
1110 | return $this->id_; |
---|
1111 | } |
---|
1112 | |
---|
1113 | function remove($delcomments = true) |
---|
1114 | { |
---|
1115 | if (!$this->id_) |
---|
1116 | return; |
---|
1117 | |
---|
1118 | event::call('killmail_delete', $this); |
---|
1119 | |
---|
1120 | $qry = new DBQuery(); |
---|
1121 | $qry->execute("delete from kb3_kills where kll_id = ".$this->id_); |
---|
1122 | $qry->execute("delete from kb3_inv_detail where ind_kll_id = ".$this->id_); |
---|
1123 | // $qry->execute("delete from kb3_inv_all where ina_kll_id = ".$this->id_); |
---|
1124 | // $qry->execute("delete from kb3_inv_crp where inc_kll_id = ".$this->id_); |
---|
1125 | // $qry->execute("delete from kb3_inv_plt where inp_kll_id = ".$this->id_); |
---|
1126 | $qry->execute("delete from kb3_items_destroyed where itd_kll_id = ".$this->id_); |
---|
1127 | $qry->execute("delete from kb3_items_dropped where itd_kll_id = ".$this->id_); |
---|
1128 | // Don't remove comments when readding a kill |
---|
1129 | if ($delcomments) |
---|
1130 | { |
---|
1131 | $qry->execute("delete from kb3_comments where kll_id = ".$this->id_); |
---|
1132 | } |
---|
1133 | } |
---|
1134 | |
---|
1135 | function addInvolvedParty($involved) |
---|
1136 | { |
---|
1137 | array_push($this->involvedparties_, $involved); |
---|
1138 | } |
---|
1139 | |
---|
1140 | function addDestroyedItem($destroyed) |
---|
1141 | { |
---|
1142 | array_push($this->destroyeditems_, $destroyed); |
---|
1143 | /* |
---|
1144 | // Ensure each item type is added once. |
---|
1145 | echo "x".($destroyed->getLocationID()).($destroyed->getItem()->getID())."x "; |
---|
1146 | if($this->destroyeditems_[$destroyed->getLocationID().$destroyed->getItem()->getID()]) |
---|
1147 | $this->destroyeditems_[$destroyed->getLocationID().$destroyed->getItem()->getID()]->quantity_ .= $destroyed->getQuantity(); |
---|
1148 | else |
---|
1149 | $this->destroyeditems_[$destroyed->getLocationID().$destroyed->getItem()->getID()] = $destroyed; |
---|
1150 | */ |
---|
1151 | } |
---|
1152 | |
---|
1153 | function addDroppedItem($dropped) |
---|
1154 | { |
---|
1155 | array_push($this->droppeditems_, $dropped); |
---|
1156 | } |
---|
1157 | } |
---|
1158 | |
---|
1159 | class InvolvedParty |
---|
1160 | { |
---|
1161 | function InvolvedParty($pilotid, $corpid, $allianceid, $secstatus, $ship, $weapon) |
---|
1162 | { |
---|
1163 | $this->pilotid_ = $pilotid; |
---|
1164 | $this->corpid_ = $corpid; |
---|
1165 | $this->allianceid_ = $allianceid; |
---|
1166 | $this->secstatus_ = $secstatus; |
---|
1167 | $this->ship_ = $ship; |
---|
1168 | $this->weapon_ = $weapon; |
---|
1169 | } |
---|
1170 | |
---|
1171 | function getPilotID() |
---|
1172 | { |
---|
1173 | return $this->pilotid_; |
---|
1174 | } |
---|
1175 | |
---|
1176 | function getCorpID() |
---|
1177 | { |
---|
1178 | return $this->corpid_; |
---|
1179 | } |
---|
1180 | |
---|
1181 | function getAllianceID() |
---|
1182 | { |
---|
1183 | return $this->allianceid_; |
---|
1184 | } |
---|
1185 | |
---|
1186 | function getSecStatus() |
---|
1187 | { |
---|
1188 | return $this->secstatus_; |
---|
1189 | } |
---|
1190 | |
---|
1191 | function getShip() |
---|
1192 | { |
---|
1193 | return $this->ship_; |
---|
1194 | } |
---|
1195 | |
---|
1196 | function getWeapon() |
---|
1197 | { |
---|
1198 | return $this->weapon_; |
---|
1199 | } |
---|
1200 | } |
---|
1201 | |
---|
1202 | class DestroyedItem |
---|
1203 | { |
---|
1204 | function DestroyedItem($item, $quantity, $location, $locationID = null) |
---|
1205 | { |
---|
1206 | $this->item_ = $item; |
---|
1207 | $this->quantity_ = $quantity; |
---|
1208 | $this->location_ = $location; |
---|
1209 | $this->locationID_ = $locationID; |
---|
1210 | } |
---|
1211 | |
---|
1212 | function getItem() |
---|
1213 | { |
---|
1214 | return $this->item_; |
---|
1215 | } |
---|
1216 | |
---|
1217 | function getQuantity() |
---|
1218 | { |
---|
1219 | if ($this->quantity_ == "") $this->quantity = 1; |
---|
1220 | return $this->quantity_; |
---|
1221 | } |
---|
1222 | //! Deprecated function to support old mods. |
---|
1223 | function getFormatttedValue() |
---|
1224 | { |
---|
1225 | return $this->getFormattedValue(); |
---|
1226 | } |
---|
1227 | //! Return value formatted into millions or thousands. |
---|
1228 | function getFormattedValue() |
---|
1229 | { |
---|
1230 | if (!isset($this->value)) |
---|
1231 | { |
---|
1232 | $this->getValue(); |
---|
1233 | } |
---|
1234 | if ($this->value > 0) |
---|
1235 | { |
---|
1236 | $value = $this->value * $this->getQuantity(); |
---|
1237 | // Value Manipulation for prettyness. |
---|
1238 | if (strlen($value) > 6) // Is this value in the millions? |
---|
1239 | { |
---|
1240 | $formatted = round($value / 1000000, 2); |
---|
1241 | $formatted = number_format($formatted, 2); |
---|
1242 | $formatted = $formatted." M"; |
---|
1243 | } |
---|
1244 | elseif (strlen($value) > 3) // 1000's ? |
---|
1245 | { |
---|
1246 | $formatted = round($value / 1000, 2); |
---|
1247 | |
---|
1248 | $formatted = number_format($formatted, 2); |
---|
1249 | $formatted = $formatted." K"; |
---|
1250 | } |
---|
1251 | else |
---|
1252 | { |
---|
1253 | $formatted = number_format($value, 2); |
---|
1254 | $formatted = $formatted." isk"; |
---|
1255 | } |
---|
1256 | } |
---|
1257 | else |
---|
1258 | { |
---|
1259 | $formatted = "0 isk"; |
---|
1260 | } |
---|
1261 | return $formatted; |
---|
1262 | } |
---|
1263 | |
---|
1264 | function getValue() |
---|
1265 | { |
---|
1266 | if ($this->value) |
---|
1267 | { |
---|
1268 | return $this->value; |
---|
1269 | } |
---|
1270 | if ($this->item_->row_['itm_value']) |
---|
1271 | { |
---|
1272 | $this->value = $this->item_->row_['itm_value']; |
---|
1273 | return $this->item_->row_['itm_value']; |
---|
1274 | } |
---|
1275 | elseif ($this->item_->row_['baseprice']) |
---|
1276 | { |
---|
1277 | $this->value = $this->item_->row_['baseprice']; |
---|
1278 | return $this->item_->row_['baseprice']; |
---|
1279 | } |
---|
1280 | $this->value = 0; |
---|
1281 | $qry = new DBQuery(); |
---|
1282 | $qry->execute("select basePrice, price |
---|
1283 | from kb3_invtypes |
---|
1284 | left join kb3_item_price on kb3_invtypes.typeID=kb3_item_price.typeID |
---|
1285 | where kb3_invtypes.typeID='".$this->item_->getID()."'"); |
---|
1286 | if ($row = $qry->getRow()) |
---|
1287 | { |
---|
1288 | if ($row['price']) |
---|
1289 | { |
---|
1290 | $this->value = $row['price']; |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | $this->value = $row['basePrice']; |
---|
1295 | } |
---|
1296 | } |
---|
1297 | return $this->value; |
---|
1298 | |
---|
1299 | //returns the value of an item |
---|
1300 | $value = 0; // Set 0 value incase nothing comes back |
---|
1301 | $id = $this->item_->getID(); // get Item ID |
---|
1302 | $qry = new DBQuery(); |
---|
1303 | $qry->execute("select itm_value from kb3_items where itm_id= '".$id."'"); |
---|
1304 | $row = $qry->getRow(); |
---|
1305 | $value = $row['itm_value']; |
---|
1306 | if ($value == '') |
---|
1307 | { |
---|
1308 | $value = 0; |
---|
1309 | } |
---|
1310 | return $value; |
---|
1311 | } |
---|
1312 | |
---|
1313 | function getLocationID() |
---|
1314 | { |
---|
1315 | if(!is_null($this->locationID_)) return $this->locationID_; |
---|
1316 | $id = false; |
---|
1317 | if (strlen($this->location_) < 2) |
---|
1318 | { |
---|
1319 | $id = $this->item_->getSlot(); |
---|
1320 | } |
---|
1321 | else |
---|
1322 | { |
---|
1323 | $qry = new DBQuery(); |
---|
1324 | $qry->execute("select itl_id from kb3_item_locations where itl_location = '".$this->location_."'"); |
---|
1325 | $row = $qry->getRow(); |
---|
1326 | $id = $row['itl_id']; |
---|
1327 | } |
---|
1328 | return $id; |
---|
1329 | } |
---|
1330 | } |
---|
1331 | |
---|
1332 | class DroppedItem extends DestroyedItem |
---|
1333 | { |
---|
1334 | function DroppedItem($item, $quantity, $location, $locationID = null) |
---|
1335 | { |
---|
1336 | $this->item_ = $item; |
---|
1337 | $this->quantity_ = $quantity; |
---|
1338 | $this->location_ = $location; |
---|
1339 | $this->locationID_ = $locationID; |
---|
1340 | } |
---|
1341 | } |
---|
1342 | |
---|
1343 | class DetailedInv extends InvolvedParty |
---|
1344 | { |
---|
1345 | function DetailedInv($pilot, $secstatus, $corp, $alliance, $ship, $weapon) |
---|
1346 | { |
---|
1347 | $this->pilot_ = $pilot; |
---|
1348 | $this->secstatus_ = $secstatus; |
---|
1349 | $this->corp_ = $corp; |
---|
1350 | $this->alliance_ = $alliance; |
---|
1351 | $this->ship_ = $ship; |
---|
1352 | $this->weapon_ = $weapon; |
---|
1353 | } |
---|
1354 | |
---|
1355 | function getPilot() |
---|
1356 | { |
---|
1357 | return $this->pilot_; |
---|
1358 | } |
---|
1359 | |
---|
1360 | function getPilotID() |
---|
1361 | { |
---|
1362 | return $this->pilot_->getID(); |
---|
1363 | } |
---|
1364 | |
---|
1365 | function getCorp() |
---|
1366 | { |
---|
1367 | return $this->corp_; |
---|
1368 | } |
---|
1369 | |
---|
1370 | function getCorpID() |
---|
1371 | { |
---|
1372 | return $this->corp_->getID(); |
---|
1373 | } |
---|
1374 | |
---|
1375 | function getAlliance() |
---|
1376 | { |
---|
1377 | return $this->alliance_; |
---|
1378 | } |
---|
1379 | |
---|
1380 | function getAllianceID() |
---|
1381 | { |
---|
1382 | return $this->alliance_->getID(); |
---|
1383 | } |
---|
1384 | |
---|
1385 | } |
---|
1386 | ?> |
---|