Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AlliCorpStats
- {
- //! Create a box and set the title.
- function AlliCorpStats()
- {
- }
- //! Generate the html from the template.
- function generate()
- {
- global $smarty;
- # //count also all those usless shitheads as active
- # $active_members_losses = true;
- $datefilter = $this->getDateFilter();
- $alliance = new Alliance(ALLIANCE_ID);
- $all_id = ALLIANCE_ID;
- $tempMyCorp = new Corporation();
- $myAlliName = $alliance->getName();
- $myAlliAPI = new AllianceAPI();
- $myAlliAPI->fetchalliances();
- $myAlliAPI->UpdateAlliances();
- $myAlliance = $myAlliAPI->LocateAlliance( $myAlliName );
- $myCorpAPI = new API_CorporationSheet();
- $allicorpstatspage_activity = config::get('allicorpstatspage_activity');
- $allicorpstatspage_activity_killsbymember = (int)config::get('allicorpstatspage_activity_kbm');
- $allicorpstatspage_activity_kills_min = (int)config::get('allicorpstatspage_activity_mkls');
- $allicorpstatspage_activity_members_minactprz = (int)config::get('allicorpstatspage_activity_mpzm');
- $active_members_losses = !config::get('allicorpstatspage_members_ack');
- $allicorpstatspage_activity_krr = config::get('allicorpstatspage_activity_krr');
- $allicorpstatspage_activity_kpms = config::get('allicorpstatspage_activity_kpms');
- if( !config::get('allicorpstatspage_members') ) {
- $allicorpstatspage_activity_killsbymember = $allicorpstatspage_activity_members_minactprz = 0;
- }
- if ($myAlliance)
- {
- $str_no_n00bs = '';
- if( @$_GET['no_n00bs'] == 'true' ) {
- // Noobship, Shuttle, Capsule
- $str_no_n00bs = " AND st.shp_class NOT IN (3,11,2) ";
- }
- $corps = array();
- foreach ( (array)$myAlliance['memberCorps'] as $tempcorp)
- {
- $myCorpAPI->setCorpID($tempcorp['corporationID']);
- $result .= $myCorpAPI->fetchXML();
- // Check if corp is known to EDK DB, if not, add it.
- $tempMyCorp->Corporation();
- $tempMyCorp->lookup($myCorpAPI->getCorporationName());
- if ($tempMyCorp->getID() == 0)
- {
- $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($tempcorp['startDate'], 0, 16));
- }
- // get a kill list, loss list and efficieny for each corp
- // lets bypass EDK here and do the query ourselves
- $qry = new DBQuery();
- $sql_OLD = "SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
- AND inv.ind_all_id = {$all_id}
- AND {$datefilter}
- ";
- #print $datefilter.'<hr>';
- // TODO: FIX-ME! kll_isk_loss can't be calculated like this -- distinct may be a problem
- $sql = "SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill, count( DISTINCT ind_plt_id ) AS active_members
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
- AND inv.ind_all_id = {$all_id}
- AND {$datefilter}
- {$str_no_n00bs}
- ";
- # print $sql.'<br>';
- $qry->execute($sql);
- $killData = $qry->getRow();
- /* if( true ) { */
- $corps[$tempMyCorp->getID()] = $tempMyCorp->getID();
- /* } else {
- $sql = "SELECT sum(kll_isk_loss) as iskkill ".
- " FROM kb3_kills ".
- " WHERE kll_id IN ( ".
- "SELECT distinct kll_id
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
- AND inv.ind_all_id = {$all_id}
- AND {$datefilter}
- {$str_no_n00bs} ".
- " ) ";
- $qry->execute($sql);
- $killData2 = $qry->getRow();
- $killData['iskkill'] = $killData2['iskkill'];
- # echo '<pre>'.print_r($killData,1).'</pre>';
- }
- */
- $qry = new DBQuery();
- /*
- $sql1 = "SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
- AND kll.kll_all_id = {$all_id}
- AND {$datefilter}
- {$str_no_n00bs} ";
- */
- $sql_OLD = "SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss, st.shp_class
- FROM kb3_kills kll
- WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
- AND kll.kll_all_id = {$all_id}
- AND {$datefilter}
- ";
- $sql = "SELECT /*count(distinct kll_id)*/ kll_id, kll_isk_loss, st.shp_class
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
- AND kll.kll_all_id = {$all_id}
- AND {$datefilter}
- {$str_no_n00bs}
- GROUP BY kll_id
- ";
- $sql = "SELECT count(kll_id) as losses, sum(kll_isk_loss) as iskloss FROM ($sql) as st WHERE 1 {$str_no_n00bs} ";
- $qry->execute( $sql );
- $lossData = $qry->getRow();
- // Build Data array
- $membercorp['corpName'] = $myCorpAPI->getCorporationName();
- $membercorp['corpID'] = $tempMyCorp->getID();
- $membercorp['corpKills'] = $killData['kills'];
- $membercorp['corpIskKill'] = $killData['iskkill']/1000;
- $membercorp['corpLosses'] = $lossData['losses'];
- $membercorp['corpIskLoss'] = $lossData['iskloss']/1000;
- $membercorp['active_members'] = $membercorp['active_members_real'] = (int)$killData['active_members'];
- if (config::get('allicorpstatspage_eff') == 'killlosseff')
- {
- $membercorp['corpEfficiency'] = round($killData['kills'] / (($killData['kills'] + $lossData['losses']) == 0 ? 1 : ($killData['kills'] + $lossData['losses'])) * 100, 2);
- }
- else
- { //die("test!");
- $membercorp['corpEfficiency'] = round($killData['iskkill'] / (($killData['iskkill'] + $lossData['iskloss']) == 0 ? 1 : ($killData['iskkill'] + $lossData['iskloss'])) * 100, 2);
- # $membercorp['corpEfficiency'] = round( (@($killData['iskkill'] / ($killData['iskkill']+$lossData['iskloss'])) * 100) ,2 );
- # print "<br>".((int)($killData['iskkill']/1000))." / (".((int)($killData['iskkill']/1000))."+".((int)($lossData['iskloss']/1000)).") *100 ";
- # print " = ".((int)($killData['iskkill']/1000))." / (".(((int)($killData['iskkill']/1000))+((int)($lossData['iskloss']/1000))).") *100 ";
- # print " -- ".$membercorp['corpName'];
- }
- $bar = new BarGraph($membercorp['corpEfficiency'], 100, 75);
- $membercorp['corpBar'] = $bar->generate();
- if (config::get('allicorpstatspage_ticker')) $membercorp["ticker"] = $myCorpAPI->getTicker();
- if (config::get('allicorpstatspage_members') || $allicorpstatspage_activity_kpms) $membercorp["members"] = $myCorpAPI->getMemberCount();
- if (config::get('allicorpstatspage_ceo')) $membercorp['corpCeo'] = $myCorpAPI->getCeoName();
- if (config::get('allicorpstatspage_hq')) $membercorp['corpHQ'] = $myCorpAPI->getStationName();
- if ($allicorpstatspage_activity_kpms) {
- $membercorp['kills_by_member'] = $membercorp['corpKills']/$membercorp['members'];
- $membercorp['kills_by_member_bad'] = false;
- }
- $membercorp['kill_ratio'] = @($membercorp['corpKills']/$membercorp['corpLosses']);
- $membercorp['active_members_proz'] = $membercorp['active_members_proz_real'] = @($membercorp['active_members']/$membercorp['members'])*100;
- // add all the data together into another array
- $AllianceCorps[$tempMyCorp->getID()] = $membercorp;
- $membercorp = array();
- unset($membercorp);
- }
- ///*****************///
- if(count($corps)) {
- ######################## ######################## ######################## ########################
- $str_base = "SELECT inv.ind_crp_id, kll.kll_id, kll.kll_system_id, reg.reg_id ,reg.reg_name
- FROM kb3_kills kll
- INNER JOIN kb3_systems sys ON sys.sys_id = kll.kll_system_id
- INNER JOIN kb3_constellations cns ON sys.sys_con_id = cns.con_id
- INNER JOIN kb3_regions reg ON reg.reg_id = cns.con_reg_id
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." ) AND kll.kll_all_id <> '{$all_id}'
- AND {$datefilter}
- $str_no_n00bs
- GROUP BY kll.kll_id "; //, inv.ind_crp_id ";
- $str = " SELECT ind_crp_id, COUNT(kll_id) AS kills ".
- " FROM ($str_base , inv.ind_crp_id) as xxx ".
- " GROUP BY ind_crp_id ";
- #print $str;
- # $qry = new DBQuery();
- if (!$qry->execute($str))
- {
- die("error - ".__FILE__.':'.__LINE__);
- }
- while ($row = $qry->getRow())
- {
- if ( isset($AllianceCorps[$row['ind_crp_id']]) ) {
- $AllianceCorps[$row['ind_crp_id']]['corpKills'] = $row['kills'];
- $AllianceCorps[$row['ind_crp_id']]['kill_ratio'] = @($AllianceCorps[$row['ind_crp_id']]['corpKills']/$AllianceCorps[$row['ind_crp_id']]['corpLosses']);
- if ($allicorpstatspage_activity_kpms) {
- $AllianceCorps[$row['ind_crp_id']]['kills_by_member'] = $AllianceCorps[$row['ind_crp_id']]['corpKills']/$AllianceCorps[$row['ind_crp_id']]['members'];
- $AllianceCorps[$row['ind_crp_id']]['kills_by_member_bad'] = false;
- }
- }
- # if( isset($output_array[$row['ind_crp_id']]) ) {
- # $output_array[$row['ind_crp_id']]['all_kills'] = $row['kills'];
- # }
- }
- ######################## ######################## ######################## ########################
- $sql = "SELECT ind_crp_id, SUM(kll_isk_loss) AS iskkill
- FROM (
- SELECT inv.ind_crp_id, kll_isk_loss, inv.ind_plt_id
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." )
- AND inv.ind_all_id ={$all_id}
- AND {$datefilter}
- {$str_no_n00bs}
- GROUP BY kll.kll_id, inv.ind_crp_id
- ) AS TMP
- GROUP BY ind_crp_id";
- # print $sql;
- if (!$qry->execute($sql))
- {
- continue;
- }
- while ($row = $qry->getRow())
- { $newisk = $row['iskkill']/1000;
- if ( isset($AllianceCorps[$row['ind_crp_id']]) ) {
- $AllianceCorps[$row['ind_crp_id']]['corpIskKill'] = $newisk;
- if (config::get('allicorpstatspage_eff') == 'killlosseff') {} else
- {
- $AllianceCorps[$row['ind_crp_id']]['corpEfficiency'] = round($AllianceCorps[$row['ind_crp_id']]['corpIskKill'] / (($AllianceCorps[$row['ind_crp_id']]['corpIskKill'] + $AllianceCorps[$row['ind_crp_id']]['corpIskLoss']) == 0 ? 1 : ($AllianceCorps[$row['ind_crp_id']]['corpIskKill'] + $AllianceCorps[$row['ind_crp_id']]['corpIskLoss'])) * 100, 2);
- $bar = new BarGraph($AllianceCorps[$row['ind_crp_id']]['corpEfficiency'], 100, 75);
- $AllianceCorps[$row['ind_crp_id']]['corpBar'] = $bar->generate();
- }
- }
- }
- if ($active_members_losses)
- {
- $sql = "SELECT COUNT(distinct charid) as active_members, corpid
- FROM (
- SELECT kll.`kll_victim_id` as charid, kll.`kll_crp_id` AS corpid, 'losses' as `where`
- FROM `kb3_kills` kll
- WHERE kll.`kll_crp_id` IN ( ".join(',' , $corps )." ) AND kll.kll_all_id = '{$all_id}'
- AND {$datefilter}
- GROUP BY kll.`kll_victim_id`, kll.`kll_crp_id`
- UNION
- SELECT inv.`ind_plt_id` as charid, inv.`ind_crp_id` AS corpid, 'kills' as `where`
- FROM `kb3_inv_detail` inv
- inner join `kb3_kills` kll ON kll.kll_id = inv.`ind_kll_id` AND {$datefilter}
- WHERE inv.`ind_crp_id` IN ( ".join(',' , $corps )." ) AND inv.ind_all_id = '{$all_id}'
- GROUP BY inv.`ind_plt_id`, inv.`ind_crp_id`
- ) AS TMP
- GROUP BY corpid
- ";
- # print $sql;
- if (!$qry->execute($sql))
- {
- continue;
- }
- while ($row = $qry->getRow())
- {
- if ( isset($AllianceCorps[$row['corpid']]) ) { #echo '<pre>'.print_r($AllianceCorps[$row['corpid']],1).'</pre>';
- # print_r( $row ); print $AllianceCorps[$row['ind_crp_id']]['active_members']." - ".$row['active_members']." <hr>";
- $AllianceCorps[$row['corpid']]['active_members'] = $row['active_members'];
- # var_dump( $row['active_members'] );
- $AllianceCorps[$row['corpid']]['active_members_proz'] = @(($AllianceCorps[$row['corpid']]['active_members'])/($AllianceCorps[$row['corpid']]['members']))*100;
- # print_r( $row ); print $AllianceCorps[$row['ind_crp_id']]['active_members']." - ".$row['active_members']." <hr>";
- # echo '<pre>'.print_r($AllianceCorps[$row['corpid']],1).'</pre>';
- }
- }
- }
- # echo '<pre>'.print_r($AllianceCorps,1).'</pre>';
- # print $str;
- }
- ///*****************///
- }
- elseif ($myAlliName == 'Amarr Empire' || $myAlliName == 'Minmatar Republic' || $myAlliName == 'Caldari State' || $myAlliName == 'Gallente Federation')
- {
- $qry = new DBQuery();
- $qry->execute(" SELECT crp_id, crp_name, crp_external_id
- FROM kb3_corps
- WHERE crp_all_id = {$all_id}
- ");
- $numRows = $qry->recordCount();
- for ($i = 0; $i < $numRows; ++$i)
- {
- $corpData = $qry->getRow();
- $membercorps[] = array( 'corpName' => $corpData['crp_name'],
- 'corpID' => $corpData['crp_id'],
- 'corpEVEID' => $corpData['crp_external_id']
- );
- }
- foreach ($membercorps as $corp)
- {
- $myCorpAPI->setCorpID($corp['corpEVEID']);
- $result .= $myCorpAPI->fetchXML();
- // Check if corp is known to EDK DB, if not, add it.
- $tempMyCorp->Corporation();
- $tempMyCorp->lookup($myCorpAPI->getCorporationName());
- if ($tempMyCorp->getID() == 0)
- {
- $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($corp['startDate'], 0, 16));
- }
- $crp_id = $corp['corpID'];
- $qry = new DBQuery();
- $qry->execute(" SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill
- FROM kb3_kills kll
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- WHERE inv.ind_crp_id = {$corp['corpID']}
- AND inv.ind_all_id = {$all_id}
- AND {$datefilter}
- ");
- $killData = $qry->getRow();
- $qry = new DBQuery();
- $qry->execute(" SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss
- FROM kb3_kills kll
- WHERE kll.kll_crp_id = {$corp['corpID']}
- AND kll.kll_all_id = {$all_id}
- AND {$datefilter}
- ");
- $lossData = $qry->getRow();
- // Build Data array
- $membercorp['corpName'] = $corp['corpName'];
- $membercorp['corpID'] = $corp['corpID'];
- $membercorp['corpKills'] = $killData['kills'];
- $membercorp['corpIskKill'] = $killData['iskkill']/1000;
- $membercorp['corpLosses'] = $lossData['losses'];
- $membercorp['corpIskLoss'] = $lossData['iskloss']/1000;
- if (config::get('bm_allicorpstats_eff') == 'killlosseff')
- {
- $membercorp['corpEfficiency'] = round($killData['kills'] / (($killData['kills'] + $lossData['losses']) == 0 ? 1 : ($killData['kills'] + $lossData['losses'])) * 100, 2);
- }
- else
- { // damagedone / (damagedone + damagereceived ) * 100
- $membercorp['corpEfficiency'] = round($killData['iskkill'] / (($killData['iskkill'] + $lossData['iskloss']) == 0 ? 1 : ($killData['iskkill'] + $lossData['iskloss'])) * 100, 2);
- # $membercorp['corpEfficiency'] = (( $killData['iskkill'] / ($killData['iskkill'] + $lossData['iskloss']) ) * 100 );
- }
- $bar = new BarGraph($membercorp['corpEfficiency'], 100, 75);
- $membercorp['corpBar'] = $bar->generate();
- if (config::get('allicorpstatspage_ticker')) $membercorp["ticker"] = $myCorpAPI->getTicker();
- if (config::get('allicorpstatspage_members')) $membercorp["members"] = $myCorpAPI->getMemberCount();
- if (config::get('allicorpstatspage_ceo')) $membercorp['corpCeo'] = $myCorpAPI->getCeoName();
- if (config::get('allicorpstatspage_hq')) $membercorp['corpHQ'] = $myCorpAPI->getStationName();
- // add all the data together into another array
- $AllianceCorps[] = $membercorp;
- $membercorp = array();
- unset($membercorp);
- }
- }
- $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName');
- // order by settings, pulled from allicorpstats_page settings.php
- // we have to order the array in php rather than order the SQL query. this is
- // because we dont pull names, ids or efficiency in our own query
- $_order = config::get('allicorpstatspage_order');
- foreach( $AllianceCorps as &$_alycorp ) {
- // $killrq = (int)( (int)$_alycorp['members']>66 ? (int)$_alycorp['members']*3 : 200);
- $killrq = (int)@$_alycorp['members']*$allicorpstatspage_activity_killsbymember;
- if( $allicorpstatspage_activity_kills_min ) {
- $killrq = max( array($killrq,$allicorpstatspage_activity_kills_min) );
- }
- $_alycorp['killrq_base'] = $killrq;
- $_alycorp['killrq'] = $_alycorp['corpKills'] - $killrq;
- $_alycorp['killrq_nq'] = $_alycorp['killrq']<0;
- $_alycorp['killrq_status_member_act'] = ($_alycorp['active_members_proz'] > ($allicorpstatspage_activity_members_minactprz-1) );
- if( !$_alycorp['killrq_status_member_act'] && $_alycorp['killrq_nq'] ) {
- $_alycorp['killrq_status'] = 'bad';
- $_alycorp['killrq_status_color'] = '#B11818';
- } elseif( !$_alycorp['killrq_status_member_act'] ) {
- $_alycorp['killrq_status'] = 'bad_act';
- $_alycorp['killrq_status_color'] = 'yellow';
- } elseif( $_alycorp['killrq_nq'] ) {
- $_alycorp['killrq_status'] = 'bad_killrq';
- $_alycorp['killrq_status_color'] = 'orange';
- } else {
- $_alycorp['killrq_status'] = 'ok';
- $_alycorp['killrq_status_color'] = '#6FAC60';
- }
- if( !empty($this->weekno_) && (@$_GET['daterange']=='weekly') ) {
- $_alycorp['killrq_status'] = 'weekly';
- $_alycorp['killrq_status_color'] = '#E0E0E0';
- }
- $_alycorp['f_title'] = '';
- if( $_alycorp['killrq_nq'] ) {
- $_alycorp['f_title'] .= " ( ".( (int)(@($_alycorp['corpKills']/$_alycorp['killrq_base'])*100) ).'%';
- if( (int)$this->monthno_==(int)date('m') && (int)$this->yearno_==(int)date('Y') ) {
- $_alycorp['f_title'] .= " | ".( (int)(@(date('j')/date('t'))*100) ).'%';
- }
- $_alycorp['f_title'] .= " ) ";
- }
- }
- if( isset($_GET['order']) && in_array( $_GET['order'],
- array('nameasc','tickerasc','ceodesc','membersdesc','memberactsdesc','memberactprozsdesc','nameasc','killsdesc','killiskdesc','killsbymemberasc','killsbymemberdesc','lossesdesc','lossiskdesc','effdesc','killrq','kill_ratio')
- ) ) {
- $_order = $_GET['order'];
- }
- if ($_order == 'membersdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'members', arsort);
- if ($_order == 'memberactsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'active_members', arsort);
- if ($_order == 'memberactprozsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'active_members_proz', arsort);
- if ($_order == 'tickerasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'ticker' );
- if ($_order == 'ceodesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpCeo' );
- if ($_order == 'nameasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName');
- if ($_order == 'namedesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName', arsort);
- if ($_order == 'killsasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpKills');
- if ($_order == 'killsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpKills', arsort);
- if ($_order == 'killiskasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskKill');
- if ($_order == 'killiskdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskKill', arsort);
- if ($_order == 'lossesasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpLosses');
- if ($_order == 'lossesdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpLosses', arsort);
- if ($_order == 'lossiskasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskLoss');
- if ($_order == 'lossiskdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskLoss', arsort);
- if ($_order == 'effasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpEfficiency');
- if ($_order == 'effdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpEfficiency', arsort);
- if ($_order == 'killrq') $AllianceCorps = $this->subvalSort($AllianceCorps, 'killrq');
- if ($_order == 'killsbymemberasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kills_by_member');
- if ($_order == 'killsbymemberdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kills_by_member', arsort);
- if ($_order == 'kill_ratio') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kill_ratio', arsort);
- $smarty->assign('order', $_order);
- # echo '<pre>'.print_r($AllianceCorps,1).'</pre>';
- if (config::get('allicorpstatspage_datefilter') == 'weekly')
- {
- $smarty->assign('datefilter', "Week {$this->weekno_}."." {$this->yearno_}");
- }
- elseif (config::get('allicorpstatspage_datefilter') == 'monthly')
- {
- $timestamp = mktime(0, 0, 0, $this->monthno_, 1, 2005);
- $smarty->assign('datefilter', date("F", $timestamp)." {$this->yearno_}");
- }
- elseif (config::get('allicorpstatspage_datefilter') == 'yearly')
- {
- $smarty->assign('datefilter', "{$this->yearno_}");
- }
- elseif (config::get('allicorpstatspage_datefilter') == 'alltime')
- {
- $smarty->assign('datefilter', "All-Time");
- }
- if (isset($_GET['daterange']) && $_GET['daterange'] == 'weekly')
- {
- $smarty->assign('datefilter', "Week {$this->weekno_}."." {$this->yearno_}");
- }
- elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'monthly')
- {
- $timestamp = mktime(0, 0, 0, $this->monthno_, 1, 2005);
- $smarty->assign('datefilter', date("F", $timestamp)." {$this->yearno_}");
- }
- elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'yearly')
- {
- $smarty->assign('datefilter', "{$this->yearno_}");
- }
- elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'alltime')
- {
- $smarty->assign('datefilter', "All-Time");
- }
- if (config::get('allicorpstatspage_ticker')) $smarty->assign('showticker', 1);
- if (config::get('allicorpstatspage_members')) $smarty->assign('showmembers', 1);
- if (config::get('allicorpstatspage_ceo')) $smarty->assign('showceo', 1);
- if (config::get('allicorpstatspage_hq')) $smarty->assign('showhq', 1);
- $smarty->assign('membercorps', $AllianceCorps);
- $ext_link = (!empty($_GET['w'])?'&w='.(int)$_GET['w']:'')
- . (!empty($_GET['m'])?'&m='.(int)$_GET['m']:'')
- . (!empty($_GET['y'])?'&y='.(int)$_GET['y']:'')
- . (@$_GET['no_n00bs']=='true' ? '&no_n00bs=true' : '' );
- $smarty->assign( 'ext_link', $ext_link );
- $smarty->assign( 'active_members_losses' , $active_members_losses );
- $smarty->assign( 'allicorpstatspage_activity' , $allicorpstatspage_activity );
- $smarty->assign( 'show_kills_by_member', $allicorpstatspage_activity_kpms );
- $smarty->assign( 'show_kill_ratio' , $allicorpstatspage_activity_krr );
- return $smarty->fetch( dirname(__FILE__).'/allicorpstats.tpl');
- // return $smarty->fetch(getcwd() . '/mods/allicorpstats_page/allicorpstats.tpl');
- }
- function generate_by_region() {
- global $smarty;
- $datefilter = $this->getDateFilter();
- $alliance = new Alliance(ALLIANCE_ID);
- $all_id = ALLIANCE_ID;
- $tempMyCorp = new Corporation();
- $myAlliName = $alliance->getName();
- $myAlliAPI = new AllianceAPI();
- $myAlliAPI->fetchalliances();
- $myAlliAPI->UpdateAlliances();
- $myAlliance = $myAlliAPI->LocateAlliance( $myAlliName );
- $myCorpAPI = new API_CorporationSheet();
- $allicorpstatspage_kbr = config::get('allicorpstatspage_kbr');
- if( is_null($allicorpstatspage_kbr) ) { $allicorpstatspage_kbr = true; }
- $allicorpstatspage_kbr_src = config::get('allicorpstatspage_kbr_src');
- if( $allicorpstatspage_kbr_src<3 || $allicorpstatspage_kbr_src>10 ) $allicorpstatspage_kbr_src = 6;
- if( !$allicorpstatspage_kbr ) {
- return '<b style="color:red;">corp stat by region not enabled!</b>';
- }
- $show_max_regs = $allicorpstatspage_kbr_src;
- if ($myAlliance)
- {
- $str_no_n00bs = '';
- if( @$_GET['no_n00bs'] == 'true' ) {
- // Noobship, Shuttle, Capsule
- $str_no_n00bs = " AND st.shp_class NOT IN (3,11,2) ";
- }
- $output_array = array( 'ally' => array('name' => $myAlliName, 'all_kills' => 0) );
- $output_array_names = array( 'ally' => $myAlliName );
- $output_array_regNames = array();
- $corps = array();
- foreach ( (array)$myAlliance['memberCorps'] as $tempcorp)
- {
- $myCorpAPI->setCorpID($tempcorp['corporationID']);
- $result .= $myCorpAPI->fetchXML();
- // Check if corp is known to EDK DB, if not, add it.
- $tempMyCorp->Corporation();
- $tempMyCorp->lookup($myCorpAPI->getCorporationName());
- if ($tempMyCorp->getID() == 0)
- {
- $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($tempcorp['startDate'], 0, 16));
- }
- $corps[$tempMyCorp->getID()] = $tempMyCorp->getID();
- // $output_array[$tempMyCorp->getID()] = array();
- // $output_array_names[$tempMyCorp->getID()] = $tempMyCorp->getName();
- $output_array_names_tmp[$tempMyCorp->getID()] = $tempMyCorp->getName();
- $output_array_names_tmp2[$tempMyCorp->getName()] = $tempMyCorp->getID();
- }
- sort($output_array_names_tmp,SORT_STRING);
- // echo '<pre>'.print_r($output_array_names_tmp,1).'</pre>';
- foreach($output_array_names_tmp as $corpname) {
- $corpid = $output_array_names_tmp2[$corpname];
- $output_array[$corpid] = array( 'name' => $corpname, 'all_kills' => 0 );
- $output_array_names[$corpid] = $corpname;
- }
- // echo '<pre>'.print_r($corps,1).'</pre>';
- $top10_regions = array();
- if( count($corps) ) {
- $str_base = "SELECT inv.ind_crp_id, kll.kll_id, kll.kll_system_id, reg.reg_id ,reg.reg_name
- FROM kb3_kills kll
- INNER JOIN kb3_systems sys ON sys.sys_id = kll.kll_system_id
- INNER JOIN kb3_constellations cns ON sys.sys_con_id = cns.con_id
- INNER JOIN kb3_regions reg ON reg.reg_id = cns.con_reg_id
- INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
- INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
- WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." ) AND kll.kll_all_id <> '{$all_id}'
- AND {$datefilter}
- $str_no_n00bs
- GROUP BY kll.kll_id "; //, inv.ind_crp_id ";
- # print $str_base.'<hr>';
- $str = " SELECT reg_id, reg_name, COUNT(kll_id) AS kills ".
- " FROM ($str_base) as xxx ".
- " GROUP BY reg_id ".
- " ORDER BY kills DESC LIMIT $show_max_regs ";
- # print $str;
- $qry = new DBQuery();
- if (!$qry->execute($str))
- {
- die("error - ".__FILE__.':'.__LINE__);
- }
- while ($row = $qry->getRow())
- {
- $regKey = $row['reg_name'];
- $top10_regions[$row['reg_id']] = $row;
- $output_array_regNames[$row['reg_id']] = $row['reg_name'];
- $output_array['ally'][$regKey] = $row['kills'];
- foreach( $corps as $corpid ) {
- $output_array[$corpid][$regKey] = 0;
- }
- }
- // kills by corp
- $str = " SELECT ind_crp_id, COUNT(kll_id) AS kills ".
- " FROM ($str_base , inv.ind_crp_id) as xxx ".
- " GROUP BY ind_crp_id ";
- #print $str;
- $qry = new DBQuery();
- if (!$qry->execute($str))
- {
- die("error - ".__FILE__.':'.__LINE__);
- }
- while ($row = $qry->getRow())
- {
- if( isset($output_array[$row['ind_crp_id']]) ) {
- $output_array[$row['ind_crp_id']]['all_kills'] = $row['kills'];
- }
- }
- // get alliance killcount
- $str = " SELECT COUNT(kll_id) AS kills ".
- " FROM ($str_base) as xxx ".
- " ";
- $qry = new DBQuery();
- if (!$qry->execute($str))
- {
- die("error - ".__FILE__.':'.__LINE__);
- }
- if ($row = $qry->getRow())
- { #print_r($row);
- $output_array['ally']['all_kills'] = $row['kills'];
- }
- // kills by region
- $str = " SELECT reg_id, reg_name, ind_crp_id, COUNT(kll_id) AS kills ".
- " FROM ($str_base , inv.ind_crp_id) as xxx ".
- " GROUP BY reg_id, ind_crp_id ".
- " ";
- if (!$qry->execute($str))
- {
- die("error - ".__FILE__.':'.__LINE__);
- }
- while ($row = $qry->getRow())
- {
- $regKey = $row['reg_name'];
- if( isset($output_array[$row['ind_crp_id']]) && isset($output_array[$row['ind_crp_id']][$regKey]) ) {
- $output_array[$row['ind_crp_id']][$regKey] = $row['kills'];
- }
- }
- #echo '<pre>'.print_r($top10_regions,1).'</pre>';
- # echo '<pre>'.print_r($output_array_names,1).'</pre>';
- # echo '<pre>'.print_r($output_array_regNames,1).'</pre>';
- # echo '<pre>'.print_r($output_array,1).'</pre>';
- $order_set = false;
- if( in_array(@$_GET['order'],$output_array_regNames) ) {
- $output_array = $this->subvalSort($output_array, $_GET['order'], arsort);
- $order_set = true;
- }
- if (@$_GET['order'] == 'name' ) $order_set = true;
- if (@$_GET['order'] == 'all_kills' || !$order_set) $output_array = $this->subvalSort($output_array, 'all_kills', arsort);
- $ext_link = (!empty($_GET['w'])?'&w='.(int)$_GET['w']:'')
- . (!empty($_GET['m'])?'&m='.(int)$_GET['m']:'')
- . (!empty($_GET['y'])?'&y='.(int)$_GET['y']:'')
- . (@$_GET['no_n00bs']=='true' ? '&no_n00bs=true' : '' );
- $smarty->assign( 'ext_link', $ext_link );
- $smarty->assign( 'output_array_names' , $output_array_names );
- $smarty->assign( 'output_array_regNames' , $output_array_regNames );
- $smarty->assign( 'output_array' , $output_array );
- $smarty->assign( 'output_all_id', $all_id );
- return $smarty->fetch( dirname(__FILE__).'/allicorpstats_region.tpl' );
- // return $smarty->fetch( getcwd() .'/mods/allicorpstats_page/allicorpstats.tpl');
- }
- }
- return '';
- }
- //! Filter results by week. Requires the year to also be set.
- function setWeek($weekno)
- {
- $weekno=intval($weekno);
- if($weekno <1) $this->weekno_ = 1;
- if($weekno >53) $this->weekno_ = 53;
- else $this->weekno_ = $weekno;
- }
- //! Filter results by year.
- function setYear($yearno)
- {
- // 1970-2038 is the allowable range for the timestamp code used
- // Needs to be revisited in the next 30 years
- $yearno = intval($yearno);
- if($yearno < 1970) $this->yearno_ = 1970;
- if($yearno > 2038) $this->yearno_ = 2038;
- else $this->yearno_ = $yearno;
- }
- //! Filter results by month
- function setMonth($monthno)
- {
- $monthno = intval($monthno);
- if($monthno < 1) $this->monthno_ = 1;
- if($monthno > 12) $this->monthno_ = 12;
- else $this->monthno_ = $monthno;
- }
- //! Filter results by starting week. Requires the year to also be set.
- function setStartWeek($weekno)
- {
- $weekno=intval($weekno);
- if($weekno <1) $this->startweekno_ = 1;
- if($weekno >53) $this->startweekno_ = 53;
- else $this->startweekno_ = $weekno;
- }
- //! Filter results by starting date/time.
- function setStartDate($timestamp)
- {
- // Check timestamp is valid before adding
- if(strtotime($timestamp)) $this->startDate_ = $timestamp;
- }
- //! Filter results by ending date/time.
- function setEndDate($timestamp)
- {
- // Check timestamp is valid before adding
- if(strtotime($timestamp)) $this->endDate_ = $timestamp;
- }
- //! \return string containing SQL date filter.
- function getDateFilter()
- {
- $qstartdate = makeStartDate($this->weekno_, $this->yearno_, $this->monthno_, $this->startweekno_, $this->startDate_);
- $qenddate = makeEndDate($this->weekno_, $this->yearno_, $this->monthno_, $this->endDate_);
- if($qstartdate) $sql .= " kll.kll_timestamp >= '".gmdate('Y-m-d H:i',$qstartdate)."' ";
- if($qstartdate && $qenddate) $sql .= " AND ";
- if($qenddate) $sql .= " kll.kll_timestamp <= '".gmdate('Y-m-d H:i',$qenddate)."' ";
- return $sql;
- }
- function subvalSort($a, $subkey, $sort = asort)
- {
- foreach($a as $k=>$v) {
- $b[$k] = strtolower($v[$subkey]);
- }
- $sort($b);
- foreach($b as $key=>$val) {
- $c[] = $a[$key];
- }
- return $c;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement