function TrovaInvolvedParty($kill, &$killers)
{
    $qry = new DBQuery();
    /*        $qry->execute("SELECT kb3_pilots.plt_name as pilot, kb3_corps.crp_name as corp, kb3_pilots.plt_id as id, kb3_pilots.plt_externalid as xid 
            FROM kb3_inv_detail, kb3_pilots, kb3_corps
            WHERE (kb3_inv_detail.ind_plt_id = kb3_pilots.plt_id)and (kb3_inv_detail.ind_crp_id = kb3_corps.crp_id)and(kb3_inv_detail.ind_kll_id =" . $kill->getID() .")") 
            or die($qry->getErrorMsg()); 
    */
    $qry->execute("SELECT kb3_pilots.plt_name AS pilot, kb3_corps.crp_name AS corp, kb3_pilots.plt_id AS id, kb3_pilots.plt_externalid AS xid, kb3_ships.shp_class AS SClass\n        FROM kb3_inv_detail, kb3_pilots, kb3_corps, kb3_ships\n        WHERE (\n            kb3_inv_detail.ind_plt_id = kb3_pilots.plt_id\n            )\n        AND (\n            kb3_inv_detail.ind_crp_id = kb3_corps.crp_id\n            )\n        AND (\n            kb3_inv_detail.ind_shp_id = kb3_ships.shp_id\n            )\n        AND (\n            kb3_inv_detail.ind_kll_id = " . $kill->getID() . ")") or die($qry->getErrorMsg());
    $bs = 0;
    while ($row = $qry->getRow()) {
        $pilot = TestPilotName($row['pilot']);
        $killers[$pilot]['punti'] += $kill->getKillPoints();
        if ($pilot == TestPilotName($kill->getFBPilotName())) {
            $killers[$pilot]['punti'] += 1;
        }
        $killers[$pilot]['portrait'] = "?a=thumb&id=" . $row['xid'] . "&size=32";
        $killers[$pilot]['corp'] = $row['corp'];
        $killers[$pilot]['id'] = $row['id'];
        if ($row['SClass'] == 1) {
            //battleship
            $bs++;
        }
    }
    return $bs;
}
 /**
  * generate Balance of Power Table
  * @return String HTML for the Balance Of Power tab
  */
 public function balanceOfPower()
 {
     global $smarty;
     $this->sides = array();
     include $this->includeDir . "class.killlisttable.php";
     $BadShips = $BadAllies = $GoodShips = $GoodAllies = array();
     $numberOfFriendlyPilots = 0;
     $numberOfHostilePilots = 0;
     $pilotsCounted = array();
     $involvedOwners = array();
     $this->numberOfInvolvedOwners = 0;
     $ownerAlliances = config::get('cfg_allianceid');
     $ownerCorps = config::get('cfg_corpid');
     $ownerPilots = config::get('cfg_pilotid');
     foreach ($this->pilots as $side => $pilotA) {
         foreach ($pilotA as $pilotId => $kll) {
             foreach ($kll as $pilota) {
                 // determine numbers of involved Owners
                 if (in_array($pilota["aid"], $ownerAlliances)) {
                     $involvedOwners[$pilotId] = 1;
                 } elseif (in_array($pilota["cid"], $ownerCorps)) {
                     $involvedOwners[$pilotId] = 1;
                 } elseif (in_array($pilotId, $ownerPilots)) {
                     $involvedOwners[$pilotId] = 1;
                 }
                 $shippa = TestPilotName($pilota["ship"]);
                 if ($side == 'a') {
                     $GoodShips[$shippa]["shipClass"] = $pilota["shipClass"];
                     $GoodShips[$shippa]["sortWeight"] = getShipClassSortWeight($pilota["shipClassObject"]);
                     $GoodShips[$shippa]["times"] += 1;
                     $GoodShips[$shippa]["color"] = $pilota["color"];
                     if ($pilota["destroyed"] == 1) {
                         $GoodShips[$shippa]["destroyed"] += 1;
                     } else {
                         $GoodShips[$shippa]["destroyed"] += 0;
                     }
                     // check if we already got that pilot
                     if (in_array($pilota["name"], $pilotsCounted)) {
                         continue;
                     }
                     $pilotsCounted[] = $pilota["name"];
                     $numberOfFriendlyPilots++;
                     $GoodAllies[$pilota["alliance"]]["quantity"] += 1;
                     $GoodAllies[$pilota["alliance"]]["corps"][$pilota["corp"]] += 1;
                     // now set up sides for BR Setup tab
                     // entity type: alliance
                     if (strcasecmp($pilota["alliance"], "None") != 0) {
                         $allianceName = addslashes($pilota["alliance"]);
                         if (!isset($this->sides["a"][$pilota["alliance"]])) {
                             $this->sides["a"][$allianceName]["type"] = "alliance";
                             $this->sides["a"][$allianceName]["id"] = $pilota["aid"];
                             $this->sides["a"][$allianceName]["numberOfPilots"] = 1;
                             $this->sides["a"][$allianceName]["logoUrl"] = html_entity_decode(Alliance::getByID($pilota["aid"])->getPortraitURL(32));
                             $this->sides["a"][$allianceName]["infoUrl"] = html_entity_decode($pilota["alliance_url"]);
                         } else {
                             $this->sides["a"][$allianceName]["numberOfPilots"] += 1;
                         }
                     } else {
                         $corpName = addslashes($pilota["corp"]);
                         if (!isset($this->sides["a"][$pilota["corp"]])) {
                             $this->sides["a"][$corpName]["type"] = "corp";
                             $this->sides["a"][$corpName]["id"] = $pilota["cid"];
                             $this->sides["a"][$corpName]["numberOfPilots"] = 1;
                             $this->sides["a"][$corpName]["logoUrl"] = html_entity_decode(Corporation::getByID($pilota["cid"])->getPortraitURL(32));
                             $this->sides["a"][$corpName]["infoUrl"] = html_entity_decode($pilota["crp_url"]);
                         } else {
                             $this->sides["a"][$corpName]["numberOfPilots"] += 1;
                         }
                     }
                 } else {
                     $BadShips[$shippa]["shipClass"] = $pilota["shipClass"];
                     $BadShips[$shippa]["sortWeight"] = getShipClassSortWeight($pilota["shipClassObject"]);
                     $BadShips[$shippa]["times"] += 1;
                     $BadShips[$shippa]["color"] = $pilota["color"];
                     if ($pilota["destroyed"] == 1) {
                         $BadShips[$shippa]["destroyed"] += 1;
                     } else {
                         $BadShips[$shippa]["destroyed"] += 0;
                     }
                     // check if we already got that pilot
                     if (in_array($pilota["name"], $pilotsCounted)) {
                         continue;
                     }
                     $pilotsCounted[] = $pilota["name"];
                     $numberOfHostilePilots++;
                     // adjust numbers for the same pilots in different ships
                     if ($pilota[0]["times"] > 1) {
                         $numberOfHostilePilots -= $pilota[0]["times"] - 1;
                     }
                     $BadAllies[$pilota["alliance"]]["quantity"] += 1;
                     $BadAllies[$pilota["alliance"]]["corps"][$pilota["corp"]] += 1;
                     // now set up sides for BR Setup tab
                     // entity type: alliance
                     if (strcasecmp($pilota["alliance"], "None") != 0) {
                         $allianceName = addslashes($pilota["alliance"]);
                         if (!isset($this->sides["e"][$pilota["alliance"]])) {
                             $this->sides["e"][$allianceName]["type"] = "alliance";
                             $this->sides["e"][$allianceName]["id"] = $pilota["aid"];
                             $this->sides["e"][$allianceName]["numberOfPilots"] = 1;
                             $this->sides["e"][$allianceName]["logoUrl"] = html_entity_decode(Alliance::getByID($pilota["aid"])->getPortraitURL(32));
                             $this->sides["e"][$allianceName]["infoUrl"] = html_entity_decode($pilota["alliance_url"]);
                         } else {
                             $this->sides["e"][$allianceName]["numberOfPilots"] += 1;
                         }
                     } else {
                         $corpName = addslashes($pilota["corp"]);
                         if (!isset($this->sides["e"][$pilota["corp"]])) {
                             $this->sides["e"][$corpName]["type"] = "corp";
                             $this->sides["e"][$corpName]["id"] = $pilota["cid"];
                             $this->sides["e"][$corpName]["numberOfPilots"] = 1;
                             $this->sides["e"][$corpName]["logoUrl"] = html_entity_decode(Corporation::getByID($pilota["cid"])->getPortraitURL(32));
                             $this->sides["e"][$corpName]["infoUrl"] = html_entity_decode($pilota["crp_url"]);
                         } else {
                             $this->sides["e"][$corpName]["numberOfPilots"] += 1;
                         }
                     }
                 }
             }
         }
     }
     $this->numberOfInvolvedOwners = count($involvedOwners);
     foreach ($involvedOwners as $involvedOwnerId => $one) {
         $this->involvedOwners[] = $involvedOwnerId;
     }
     // calculate percentages
     foreach ($GoodAllies as $name => &$info) {
         $info["percentage"] = round($info["quantity"] / $numberOfFriendlyPilots * 100, 1);
         arsort($info["corps"]);
     }
     foreach ($BadAllies as $name => &$info) {
         $info["percentage"] = round($info["quantity"] / $numberOfHostilePilots * 100, 1);
         arsort($info["corps"]);
     }
     if (!is_null($GoodShips)) {
         uasort($GoodShips, array($this, 'sortShipClasses'));
     }
     if (!is_null($GoodAllies)) {
         arsort($GoodAllies);
     }
     $smarty->assignByRef('GAlliesCount', count($GoodAllies));
     $smarty->assignByRef('GoodAllies', $GoodAllies);
     $smarty->assignByRef('GoodShips', $GoodShips);
     if (!is_null($BadShips)) {
         uasort($BadShips, array($this, 'sortShipClasses'));
     }
     if (!is_null($BadAllies)) {
         arsort($BadAllies);
     }
     $smarty->assignByRef('BAlliesCount', count($BadAllies));
     $smarty->assignByRef('BadAllies', $BadAllies);
     $smarty->assignByRef('BadShips', $BadShips);
     $smarty->assign("numberOfFriendlyPilots", $numberOfFriendlyPilots);
     $smarty->assign("numberOfHostilePilots", $numberOfHostilePilots);
     return $smarty->fetch($this->templateDir . "battle_balance.tpl");
 }