Exemple #1
0
 /**
  *  Show the overall statistics for this corporation.
  */
 function stats()
 {
     global $smarty;
     // The summary table is also used by the stats. Whichever is called
     // first generates the table.
     $this->page->setTitle('Corporation details - ' . $this->corp->getName() . " [" . $this->corp->getShortName() . "]");
     $smarty->registerObject('Corp', $this->corp);
     $smarty->assign('portrait_url', $this->corp->getPortraitURL(128));
     if ($this->alliance->getName() == "None") {
         $smarty->assign('alliance_url', false);
     } else {
         if ($this->alliance->getExternalID()) {
             $smarty->assign('alliance_url', edkURI::build(array('a', 'alliance_detail', true), array('all_ext_id', $this->alliance->getExternalID(), true)));
         } else {
             $smarty->assign('alliance_url', edkURI::build(array('a', 'alliance_detail', true), array('all_id', $this->alliance->getID(), true)));
         }
     }
     $smarty->assign('alliance_name', $this->alliance->getName());
     $smarty->assign('kill_count', $this->kill_summary->getTotalKills());
     $smarty->assign('loss_count', $this->kill_summary->getTotalLosses());
     $smarty->assign('damage_done', number_format($this->kill_summary->getTotalKillISK() / 1000000000, 2));
     $smarty->assign('damage_received', number_format($this->kill_summary->getTotalLossISK() / 1000000000, 2));
     if ($this->kill_summary->getTotalKillISK()) {
         $smarty->assign('efficiency', number_format(100 * $this->kill_summary->getTotalKillISK() / ($this->kill_summary->getTotalKillISK() + $this->kill_summary->getTotalLossISK()), 2));
     } else {
         $smarty->assign('efficiency', 0);
     }
     $smarty->assign('ceo_url', edkURI::build(array('a', 'pilot_detail', true), array('plt_ext_id', $this->corp->getCeoID(), true)));
     $pilot = new Pilot(0, $this->corp->getCeoID());
     $smarty->assign('ceo_name', $pilot->getName());
     return $smarty->fetch(get_tpl('corp_detail_stats'));
 }
Exemple #2
0
 function display()
 {
     global $smarty;
     $alls = $corps = $pilots = false;
     if (config::get('cfg_allianceid')) {
         $alls = array();
         foreach (config::get('cfg_allianceid') as $entity) {
             $alliance = new Alliance($entity);
             if ($alliance->getExternalID()) {
                 $url = edkURI::page('alliance_detail', $alliance->getExternalID(), 'all_ext_id');
             } else {
                 $url = edkURI::page('alliance_detail', $alliance->getID(), 'all_id');
             }
             $alls[] = array('id' => $alliance->getID(), 'extid' => $alliance->getExternalID(), 'name' => $alliance->getName(), 'portrait' => $alliance->getPortraitURL(128), 'url' => $url);
         }
     }
     if (config::get('cfg_corpid')) {
         $corps = array();
         foreach (config::get('cfg_corpid') as $entity) {
             $corp = new Corporation($entity);
             if ($corp->getExternalID()) {
                 $url = edkURI::page('corp_detail', $corp->getExternalID(), 'crp_ext_id');
             } else {
                 $url = edkURI::page('corp_detail', $corp->getID(), 'crp_id');
             }
             $corps[] = array('id' => $corp->getID(), 'extid' => $corp->getExternalID(), 'name' => $corp->getName(), 'portrait' => $corp->getPortraitURL(128), 'url' => $url);
         }
     }
     if (config::get('cfg_pilotid')) {
         $pilots = array();
         foreach (config::get('cfg_pilotid') as $entity) {
             $pilot = new Pilot($entity);
             if ($pilot->getExternalID()) {
                 $url = edkURI::page('pilot_detail', $pilot->getExternalID(), 'plt_ext_id');
             } else {
                 $url = edkURI::page('pilot_detail', $pilot->getID(), 'plt_id');
             }
             $pilots[] = array('id' => $pilot->getID(), 'extid' => $pilot->getExternalID(), 'name' => $pilot->getName(), 'portrait' => $pilot->getPortraitURL(128), 'url' => $url);
         }
     }
     $smarty->assignByRef('alliances', $alls);
     $smarty->assignByRef('corps', $corps);
     $smarty->assignByRef('pilots', $pilots);
     return $smarty->fetch(get_tpl('self'));
 }
 /**
  *  Show the overall statistics for this alliance.
  *
  * @global Smarty $smarty
  * @return string
  */
 function stats()
 {
     global $smarty;
     if ($this->alliance->isFaction()) {
         $this->page->setTitle(Language::get('page_faction_det') . ' - ' . $this->alliance->getName() . " [" . $this->alliance->getshortName() . "]");
     } else {
         $this->page->setTitle(Language::get('page_all_det') . ' - ' . $this->alliance->getName() . " [" . $this->alliance->getshortName() . "]");
     }
     $sql = "select crp_id from kb3_corps WHERE crp_all_id=" . $this->alliance->getID();
     $qry = DBFactory::getDBQuery();
     $qry->execute($sql);
     while ($row = $qry->getRow()) {
         $this->allianceCorps[] = Corporation::getByID((int) $row['crp_id']);
     }
     if (!isset($this->kill_summary)) {
         $this->kill_summary = new KillSummaryTable();
         $this->kill_summary->addInvolvedAlliance($this->alliance);
         $this->kill_summary->generate();
     }
     $execcrp = Corporation::lookupByExternalID($this->alliance->GetExecutorID());
     if ($execcrp !== false) {
         $smarty->assign('ExecutorName', $execcrp->getName());
     } else {
         $smarty->assign('ExecutorName', '');
     }
     $smarty->registerObject('Alliance', $this->alliance);
     $smarty->assign('memberCorpCount', count($this->allianceCorps));
     if ($this->kill_summary->getTotalKillISK()) {
         $efficiency = round($this->kill_summary->getTotalKillISK() / ($this->kill_summary->getTotalKillISK() + $this->kill_summary->getTotalLossISK()) * 100, 2);
     } else {
         $efficiency = 0;
     }
     // The summary table is also used by the stats. Whichever is called
     // first generates the table.
     $smarty->assign('all_img', $this->alliance->getPortraitURL(128));
     $smarty->assign('totalkills', $this->kill_summary->getTotalKills());
     $smarty->assign('totallosses', $this->kill_summary->getTotalLosses());
     $smarty->assign('totalkisk', round($this->kill_summary->getTotalKillISK() / 1000000000, 2));
     $smarty->assign('totallisk', round($this->kill_summary->getTotalLossISK() / 1000000000, 2));
     if ($this->kill_summary->getTotalKillISK()) {
         $smarty->assign('efficiency', round($this->kill_summary->getTotalKillISK() / ($this->kill_summary->getTotalKillISK() + $this->kill_summary->getTotalLossISK()) * 100, 2));
     } else {
         $smarty->assign('efficiency', '0');
     }
     return $smarty->fetch(get_tpl('alliance_detail_stats'));
 }
 /**
  * @return integer
  */
 function getAllianceID()
 {
     return $this->alliance_->getID();
 }
    /**
     * Add a new corporation to the database or update the details of an existing one.
     *
     * @param string $name The name of the new corporation.
     * @param Alliance $alliance The alliance this corporation belongs to.
     * @param string $timestamp The timestamp the corporation's details were updated.
     * @param integer $externalid The external CCP ID for the corporation.
     * @param boolean $loadExternals Whether to fetch unknown information from the API.
     * @return Corporation
     */
    static function add($name, $alliance, $timestamp, $externalid = 0, $loadExternals = true)
    {
        if (!$name) {
            trigger_error("Attempt to add a corporation with no name. Aborting.", E_USER_ERROR);
            // If things are going this wrong, it's safer to die and prevent more harm
            die;
        } else {
            if (!$alliance->getID()) {
                trigger_error("Attempt to add a corporation with no alliance. Aborting.", E_USER_ERROR);
                // If things are going this wrong, it's safer to die and prevent more harm
                die;
            }
        }
        $name = stripslashes($name);
        $externalid = (int) $externalid;
        $qry = DBFactory::getDBQuery(true);
        $qry->execute("select * from kb3_corps\n\t\t               where crp_name = '" . $qry->escape($name) . "'");
        // If the corp name is not present in the db add it.
        if (!$qry->recordCount()) {
            // If no external id is given then look it up.
            if (!$externalid && $loadExternals) {
                $myID = new API_NametoID();
                $myID->setNames($name);
                $myID->fetchXML();
                $myNames = $myID->getNameData();
                $externalid = (int) $myNames[0]['characterID'];
            }
            // If we have an external id then check it isn't already in use
            // If we find it then update the old corp with the new name and
            // return.
            if ($externalid) {
                $qry->execute("SELECT * FROM kb3_corps WHERE crp_external_id = " . $externalid);
                if ($qry->recordCount()) {
                    $row = $qry->getRow();
                    $qry->execute("UPDATE kb3_corps SET crp_name = '" . $qry->escape($name) . "' WHERE crp_external_id = " . $externalid);
                    $crp = Corporation::getByID((int) $row['crp_id']);
                    Cacheable::delCache($crp);
                    $crp->name = $name;
                    $crp->externalid = $row['crp_external_id'];
                    if (!is_null($row['crp_updated'])) {
                        $crp->updated = strtotime($row['crp_updated'] . " UTC");
                    } else {
                        $crp->updated = null;
                    }
                    // Now check if the alliance needs to be updated.
                    if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) {
                        $sql = 'update kb3_corps
									   set crp_all_id = ' . $alliance->getID() . ', ';
                        $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id;
                        $qry->execute($sql);
                        $crp->alliance = $alliance;
                    }
                    return $crp;
                }
            }
            // Neither corp name or external id was found so add this corp as new
            if ($externalid) {
                $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_external_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ", " . $externalid . ", date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))");
            } else {
                $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ",date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))");
            }
            $crp = Corporation::getByID((int) $qry->getInsertID());
            $crp->name = $name;
            $crp->externalid = (int) $externalid;
            $crp->alliance = $alliance->getID();
            $crp->updated = strtotime(preg_replace("/\\./", "-", $timestamp) . " UTC");
            return $crp;
        } else {
            $row = $qry->getRow();
            $crp = Corporation::getByID((int) $row['crp_id']);
            $crp->name = $row['crp_name'];
            $crp->externalid = (int) $row['crp_external_id'];
            $crp->alliance = $row['crp_all_id'];
            if (!is_null($row['crp_updated'])) {
                $crp->updated = strtotime($row['crp_updated'] . " UTC");
            } else {
                $crp->updated = null;
            }
            if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) {
                $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', ';
                $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id;
                $qry->execute($sql);
                $crp->alliance = $alliance;
            }
            if (!$crp->externalid && $externalid) {
                $crp->setExternalID((int) $externalid);
            }
            return $crp;
        }
        return false;
    }
Exemple #6
0
 /**
  * Return the raw killmail for this kill.
  *
  * @return string
  */
 function getRawMail()
 {
     if (!is_null($this->mail)) {
         return $this->mail;
     }
     if (config::get('km_cache_enabled') && file_exists(KB_PAGECACHEDIR . "/" . $this->getID() . ".txt")) {
         $this->mail = file_get_contents(KB_PAGECACHEDIR . "/" . $this->getID() . ".txt");
         return $this->mail;
     }
     if (!$this->timestamp) {
         $this->execQuery();
     }
     if (!$this->valid) {
         return "The specified kill ID is not valid.";
     }
     if ($this->isClassified()) {
         return 'Killmail not yet available, try again in ' . round($this->getClassifiedTime() / 3600, 2) . ' hrs.';
     }
     static $locations;
     if (!isset($locations)) {
         $qry = DBFactory::getDBQuery();
         $qry->execute("SELECT itl_flagID, itl_flagText FROM kb3_item_locations");
         while ($row = $qry->getRow()) {
             $locations[$row['itl_flagID']] = $row['itl_flagText'];
         }
     }
     $ship = $this->getVictimShip();
     $shipclass = $ship->getClass();
     if (!$this->getVictimCorpName()) {
         $corp = new Corporation($this->victimcorpid);
         $this->victimcorpname = $corp->getName();
     }
     if (!$this->getVictimAllianceName()) {
         $all = new Alliance($this->victimallianceid);
         $this->victimalliancename = $all->getName();
     }
     if (!$this->getVictimName()) {
         throw new KillException("Invalid mail, victim name blank");
     } else {
         if (!$this->getVictimCorpName()) {
             throw new KillException("Invalid mail, victim corporation blank");
         } else {
             if (!$this->getVictimAllianceName() && !$this->getVictimFactionName()) {
                 throw new KillException("Invalid mail, victim alliance blank");
             } else {
                 if (!$ship->getName()) {
                     throw new KillException("Invalid mail, ship blank");
                 } else {
                     if (!$this->getSystem()->getName()) {
                         throw new KillException("Invalid mail, system blank", ´);
                     }
                 }
             }
         }
     }
     $mail = substr(str_replace('-', '.', $this->getTimeStamp()), 0, 19) . "\r\n\r\n";
     // Starbase (so this is a POS mail)
     if (in_array($shipclass->getID(), array(35, 36, 37, 38))) {
         $mail .= "Corp: " . $this->getVictimCorpName() . "\r\n";
         if ($this->getIsVictimFaction()) {
             $mail .= "Alliance: None\r\n";
         } else {
             $mail .= "Alliance: " . $this->getVictimAllianceName() . "\r\n";
         }
         $mail .= "Faction: " . $this->getVictimFactionName() . "\r\n";
         //$ship = $this->getVictimShip();
         $mail .= "Destroyed: " . $ship->getName() . "\r\n";
         if ($this->getVictimName() == $this->getSystem()->getName()) {
             $mail .= "Moon: Unknown\r\n";
         } else {
             // is the victim's name a moon?
             $moonID = API_Helpers::getMoonID($this->getVictimName());
             if ($moonID) {
                 $mail .= "Moon: " . $this->getVictimName() . "\r\n";
             } else {
                 // try parsing the victim's name in case it's the format
                 // <corporationName> - <moonName>
                 $namePieces = explode(" - ", $this->getVictimName());
                 if (is_array($namePieces) && count($namePieces) > 2) {
                     // remove first part, which is the corp name
                     array_splice($namePieces, 0, 1);
                     $mail .= "Moon: " . implode(" - ", $namePieces) . "\r\n";
                 }
             }
         }
         $mail .= "System: " . $this->getSystem()->getName() . "\r\n";
         $mail .= "Security: " . $this->getSystem()->getSecurity(true) . "\r\n";
         $mail .= "Damage Taken: " . $this->dmgtaken . "\r\n\r\n";
         $mail .= "Involved parties:\r\n\r\n";
     } else {
         $mail .= "Victim: " . $this->getVictimName() . "\r\n";
         $mail .= "Corp: " . $this->getVictimCorpName() . "\r\n";
         if ($this->getIsVictimFaction()) {
             $mail .= "Alliance: None\r\n";
         } else {
             $mail .= "Alliance: " . $this->getVictimAllianceName() . "\r\n";
         }
         $mail .= "Faction: " . $this->getVictimFactionName() . "\r\n";
         //$ship = $this->getVictimShip();
         $mail .= "Destroyed: " . $ship->getName() . "\r\n";
         $system = $this->getSystem();
         $mail .= "System: " . $system->getName() . "\r\n";
         $mail .= "Security: " . $system->getSecurity(true) . "\r\n";
         $mail .= "Damage Taken: " . $this->dmgtaken . "\r\n\r\n";
         $mail .= "Involved parties:\r\n\r\n";
     }
     foreach ($this->involvedparties_ as $inv) {
         /* @var $inv InvolvedParty */
         $pilot = new Pilot($inv->getPilotID());
         $corp = new Corporation($inv->getCorpID());
         $alliance = new Alliance($inv->getAllianceID());
         $weapon = $inv->getWeapon();
         $ship = $inv->getShip();
         if ($ship->getID() != "9999") {
             // Split these into multiple ifs so the error tells us where the
             // problem was.
             if (!$pilot->getName()) {
                 throw new KillException("Invalid mail, invalid involved pilot (ID: " . $pilot->getID() . ")");
             } else {
                 if (!$corp->getName()) {
                     throw new KillException("Invalid mail, invalid involved corporation (ID: " . $corp->getID() . ")");
                 } else {
                     if (!$alliance->getName()) {
                         throw new KillException("Invalid mail, invalid involved alliance (ID: " . $alliance->getID() . ")");
                     } else {
                         if (!$weapon->getName()) {
                             throw new KillException("Invalid mail, invalid involved weapon (ID: " . $weapon->getID() . ")");
                         } else {
                             if (!$ship->getName()) {
                                 throw new KillException("Invalid mail, invalid involved ship (ID: " . $ship->getID() . ")");
                             }
                         }
                     }
                 }
             }
             if ($pilot->getName() == $weapon->getName()) {
                 $name = $pilot->getName() . " / " . $corp->getName();
             } else {
                 $name = $pilot->getName();
             }
             $mail .= "Name: " . $name;
             if ($pilot->getID() == $this->getFBPilotID()) {
                 $mail .= " (laid the final blow)";
             }
             $mail .= "\r\n";
             if ($pilot->getName() != $weapon->getName()) {
                 $mail .= "Security: " . $inv->getSecStatus() . "\r\n";
                 $mail .= "Corp: " . $corp->getName() . "\r\n";
                 if ($alliance->isFaction()) {
                     $mail .= "Alliance: None\r\n";
                     $mail .= "Faction: " . $alliance->getName() . "\r\n";
                 } else {
                     $mail .= "Alliance: " . $alliance->getName() . "\r\n";
                     $mail .= "Faction: None\r\n";
                 }
                 $mail .= "Ship: " . $ship->getName() . "\r\n";
                 $mail .= "Weapon: " . $weapon->getName() . "\r\n";
                 $mail .= "Damage Done: " . $inv->getDamageDone() . "\r\n";
             } else {
                 $mail .= "Damage Done: " . $inv->getDamageDone() . "\r\n";
             }
             $mail .= "\r\n";
         }
     }
     if (count($this->destroyeditems_) > 0) {
         $mail .= "\r\nDestroyed items:\r\n\r\n";
         foreach ($this->destroyeditems_ as $destroyed) {
             $item = $destroyed->getItem();
             $mail .= $item->getName();
             if ($destroyed->getQuantity() > 1) {
                 $mail .= ", Qty: " . $destroyed->getQuantity();
             }
             if ($destroyed->getSingleton() == InventoryFlag::$SINGLETON_COPY) {
                 $mail .= " (Copy)";
             }
             $flagID = InventoryFlag::collapse($destroyed->getLocationID());
             if ($destroyed->getLocationID() == InventoryFlag::$CARGO) {
                 $mail .= " (Cargo)";
             } else {
                 if ($destroyed->getLocationID() == InventoryFlag::$DRONE_BAY) {
                     $mail .= " (Drone Bay)";
                 } else {
                     if ($destroyed->getLocationID() == InventoryFlag::$IMPLANT) {
                         $mail .= " (Implant)";
                     } else {
                         if ($destroyed->getLocationID() == InventoryFlag::$OTHER) {
                             $mail .= " (Other)";
                         }
                     }
                 }
             }
             $mail .= "\r\n";
         }
     }
     if (count($this->droppeditems_) > 0) {
         $mail .= "\r\nDropped items:\r\n\r\n";
         foreach ($this->droppeditems_ as $dropped) {
             $item = $dropped->getItem();
             $mail .= $item->getName();
             if ($dropped->getQuantity() > 1) {
                 $mail .= ", Qty: " . $dropped->getQuantity();
             }
             if ($dropped->getSingleton() == InventoryFlag::$SINGLETON_COPY) {
                 $mail .= " (Copy)";
             }
             if ($dropped->getLocationID() == InventoryFlag::$CARGO) {
                 $mail .= " (Cargo)";
             } else {
                 if ($dropped->getLocationID() == InventoryFlag::$DRONE_BAY) {
                     $mail .= " (Drone Bay)";
                 } else {
                     if ($dropped->getLocationID() == InventoryFlag::$IMPLANT) {
                         $mail .= " (Implant)";
                     } else {
                         if ($dropped->getLocationID() == InventoryFlag::$OTHER) {
                             $mail .= " (Other)";
                         }
                     }
                 }
             }
             $mail .= "\r\n";
         }
     }
     if ($this->id && config::get('km_cache_enabled')) {
         file_put_contents(KB_MAILCACHEDIR . "/" . $this->getID() . ".txt", $mail);
     }
     $this->mail = $mail;
     return $mail;
 }