Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 34.29 KB | None | 0 0
  1. <?php
  2.  
  3. class AlliCorpStats
  4. {
  5.    //! Create a box and set the title.
  6.    function AlliCorpStats()
  7.    {
  8.    }
  9.        
  10.    //! Generate the html from the template.
  11.    function generate()
  12.    {
  13.        global $smarty;
  14.                
  15.         #       //count also all those usless shitheads as active
  16.         #       $active_members_losses = true;
  17.                
  18.                 $datefilter = $this->getDateFilter();
  19.                
  20.                 $alliance = new Alliance(ALLIANCE_ID);
  21.                 $all_id = ALLIANCE_ID;
  22.                 $tempMyCorp = new Corporation();
  23.  
  24.                 $myAlliName = $alliance->getName();
  25.                 $myAlliAPI = new AllianceAPI();
  26.                 $myAlliAPI->fetchalliances();
  27.                 $myAlliAPI->UpdateAlliances();
  28.                 $myAlliance = $myAlliAPI->LocateAlliance( $myAlliName );
  29.                 $myCorpAPI = new API_CorporationSheet();
  30.                
  31.                 $allicorpstatspage_activity = config::get('allicorpstatspage_activity');
  32.                
  33.        
  34.                 $allicorpstatspage_activity_killsbymember = (int)config::get('allicorpstatspage_activity_kbm');
  35.                 $allicorpstatspage_activity_kills_min = (int)config::get('allicorpstatspage_activity_mkls');
  36.                 $allicorpstatspage_activity_members_minactprz = (int)config::get('allicorpstatspage_activity_mpzm');
  37.                 $active_members_losses = !config::get('allicorpstatspage_members_ack');
  38.                 $allicorpstatspage_activity_krr = config::get('allicorpstatspage_activity_krr');
  39.                
  40.                 $allicorpstatspage_activity_kpms = config::get('allicorpstatspage_activity_kpms');
  41.                
  42.                 if( !config::get('allicorpstatspage_members') ) {
  43.                     $allicorpstatspage_activity_killsbymember = $allicorpstatspage_activity_members_minactprz = 0;
  44.                 }              
  45.  
  46.                 if ($myAlliance)
  47.                 {
  48.            
  49.                     $str_no_n00bs = '';
  50.                     if( @$_GET['no_n00bs'] == 'true' ) {
  51.                         // Noobship, Shuttle, Capsule
  52.                         $str_no_n00bs = " AND st.shp_class NOT IN (3,11,2) ";
  53.                     }
  54.                
  55.                     $corps = array();
  56.                     foreach ( (array)$myAlliance['memberCorps'] as $tempcorp)
  57.                     {
  58.                         $myCorpAPI->setCorpID($tempcorp['corporationID']);
  59.                         $result .= $myCorpAPI->fetchXML();
  60.  
  61.                         // Check if corp is known to EDK DB, if not, add it.
  62.                         $tempMyCorp->Corporation();
  63.                         $tempMyCorp->lookup($myCorpAPI->getCorporationName());
  64.                         if ($tempMyCorp->getID() == 0)
  65.                         {
  66.                             $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($tempcorp['startDate'], 0, 16));
  67.                         }
  68.  
  69.                        
  70.                         // get a kill list, loss list and efficieny for each corp
  71.                         // lets bypass EDK here and do the query ourselves
  72.                         $qry = new DBQuery();
  73.                        
  74.                        
  75.                         $sql_OLD = "SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill
  76.                                                         FROM kb3_kills kll
  77.                                                         INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  78.                                                         WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
  79.                                                         AND inv.ind_all_id = {$all_id}
  80.                                                         AND {$datefilter}
  81.                                                     ";
  82.  
  83.                                 #print $datefilter.'<hr>';             
  84.                             // TODO: FIX-ME!  kll_isk_loss can't be calculated like this -- distinct may be a problem
  85.                         $sql = "SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill, count( DISTINCT ind_plt_id ) AS active_members
  86.                                                         FROM kb3_kills kll
  87.                                                         INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  88.                                                         INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  89.                                                         WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
  90.                                                         AND inv.ind_all_id = {$all_id}
  91.                                                         AND {$datefilter}
  92.                                                         {$str_no_n00bs}
  93.                                                         ";
  94.                                                        
  95.                     #       print $sql.'<br>';
  96.                                                        
  97.  
  98.                         $qry->execute($sql);                               
  99.                         $killData = $qry->getRow();
  100.                    
  101.         /*          if( true ) {  */
  102.                         $corps[$tempMyCorp->getID()] = $tempMyCorp->getID();
  103.         /*          } else {
  104.                    
  105.                         $sql = "SELECT sum(kll_isk_loss) as iskkill ".
  106.                             " FROM kb3_kills ".
  107.                             " WHERE kll_id IN ( ".
  108.                                         "SELECT distinct kll_id
  109.                                                 FROM kb3_kills kll
  110.                                                 INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  111.                                                 INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  112.                                                 WHERE inv.ind_crp_id = {$tempMyCorp->getID()}
  113.                                                 AND inv.ind_all_id = {$all_id}
  114.                                                 AND {$datefilter}
  115.                                                 {$str_no_n00bs} ".
  116.                             " ) ";
  117.                         $qry->execute($sql);   
  118.                         $killData2 = $qry->getRow();
  119.                         $killData['iskkill'] = $killData2['iskkill'];
  120.                    
  121.                 #       echo '<pre>'.print_r($killData,1).'</pre>';
  122.                
  123.                     }  
  124.             */     
  125.                        
  126.                         $qry = new DBQuery();
  127. /*
  128.                         $sql1 = "SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss
  129.                                                         FROM kb3_kills kll
  130.                                                         INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  131.                                                         INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  132.                                                         WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
  133.                                                         AND kll.kll_all_id = {$all_id}
  134.                                                         AND {$datefilter}
  135.                                                         {$str_no_n00bs}   ";
  136. */ 
  137.                                                    
  138.                         $sql_OLD = "SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss, st.shp_class
  139.                                                         FROM kb3_kills kll
  140.                                                         WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
  141.                                                         AND kll.kll_all_id = {$all_id}
  142.                                                         AND {$datefilter}
  143.                                                          ";
  144.                                                        
  145.                         $sql = "SELECT /*count(distinct kll_id)*/ kll_id, kll_isk_loss, st.shp_class
  146.                                                         FROM kb3_kills kll
  147.                                                         INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  148.                                                         INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  149.                                                         WHERE kll.kll_crp_id = {$tempMyCorp->getID()}
  150.                                                         AND kll.kll_all_id = {$all_id}
  151.                                                         AND {$datefilter}
  152.                                                         {$str_no_n00bs}
  153.                                                         GROUP BY kll_id
  154.                                                         ";
  155.                                                        
  156.                         $sql = "SELECT count(kll_id) as losses, sum(kll_isk_loss) as iskloss FROM ($sql) as st WHERE 1 {$str_no_n00bs} ";                      
  157.                                                
  158.                                     $qry->execute( $sql );
  159.            
  160.                         $lossData = $qry->getRow();
  161.                        
  162.                         // Build Data array
  163.                         $membercorp['corpName'] = $myCorpAPI->getCorporationName();
  164.                         $membercorp['corpID'] = $tempMyCorp->getID();
  165.                         $membercorp['corpKills'] = $killData['kills'];
  166.                         $membercorp['corpIskKill'] = $killData['iskkill']/1000;
  167.                         $membercorp['corpLosses'] = $lossData['losses'];
  168.                         $membercorp['corpIskLoss'] = $lossData['iskloss']/1000;
  169.                         $membercorp['active_members'] = $membercorp['active_members_real'] = (int)$killData['active_members'];
  170.  
  171.                         if (config::get('allicorpstatspage_eff') == 'killlosseff')
  172.                         {
  173.                             $membercorp['corpEfficiency'] = round($killData['kills'] / (($killData['kills'] + $lossData['losses']) == 0 ? 1 : ($killData['kills'] + $lossData['losses'])) * 100, 2);
  174.                         }
  175.                         else
  176.                         {   //die("test!");
  177.                             $membercorp['corpEfficiency'] = round($killData['iskkill'] / (($killData['iskkill'] + $lossData['iskloss']) == 0 ? 1 : ($killData['iskkill'] + $lossData['iskloss'])) * 100, 2);
  178.         #                   $membercorp['corpEfficiency'] = round( (@($killData['iskkill'] / ($killData['iskkill']+$lossData['iskloss'])) * 100) ,2 );
  179.         #                   print "<br>".((int)($killData['iskkill']/1000))." / (".((int)($killData['iskkill']/1000))."+".((int)($lossData['iskloss']/1000)).") *100 ";
  180.         #                   print " = ".((int)($killData['iskkill']/1000))." / (".(((int)($killData['iskkill']/1000))+((int)($lossData['iskloss']/1000))).") *100 ";
  181.         #                   print "  -- ".$membercorp['corpName'];
  182.                         }
  183.                         $bar = new BarGraph($membercorp['corpEfficiency'], 100, 75);
  184.                         $membercorp['corpBar'] = $bar->generate();
  185.                         if (config::get('allicorpstatspage_ticker')) $membercorp["ticker"] = $myCorpAPI->getTicker();
  186.                         if (config::get('allicorpstatspage_members') || $allicorpstatspage_activity_kpms) $membercorp["members"] = $myCorpAPI->getMemberCount();
  187.                         if (config::get('allicorpstatspage_ceo')) $membercorp['corpCeo'] = $myCorpAPI->getCeoName();
  188.                         if (config::get('allicorpstatspage_hq')) $membercorp['corpHQ'] = $myCorpAPI->getStationName();
  189.                        
  190.                         if ($allicorpstatspage_activity_kpms) {
  191.                             $membercorp['kills_by_member'] = $membercorp['corpKills']/$membercorp['members'];
  192.                             $membercorp['kills_by_member_bad'] = false;
  193.                         }
  194.                        
  195.                         $membercorp['kill_ratio'] = @($membercorp['corpKills']/$membercorp['corpLosses']);
  196.                        
  197.                         $membercorp['active_members_proz'] = $membercorp['active_members_proz_real'] = @($membercorp['active_members']/$membercorp['members'])*100;
  198.                        
  199.                         // add all the data together into another array
  200.                         $AllianceCorps[$tempMyCorp->getID()] = $membercorp;
  201.                        
  202.                         $membercorp = array();
  203.                         unset($membercorp);
  204.                     }
  205.                    
  206.                     ///*****************///
  207.  
  208.                     if(count($corps)) {
  209.    
  210.     ########################    ########################    ########################    ########################   
  211.                            
  212.                     $str_base = "SELECT inv.ind_crp_id, kll.kll_id, kll.kll_system_id, reg.reg_id ,reg.reg_name
  213.                         FROM kb3_kills kll
  214.                         INNER JOIN kb3_systems sys ON sys.sys_id = kll.kll_system_id
  215.                         INNER JOIN kb3_constellations cns ON sys.sys_con_id = cns.con_id
  216.                         INNER JOIN kb3_regions reg ON reg.reg_id = cns.con_reg_id
  217.                         INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  218.                         INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  219.                         WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." ) AND kll.kll_all_id <> '{$all_id}'
  220.                         AND  {$datefilter}
  221.                             $str_no_n00bs
  222.                         GROUP BY kll.kll_id "; //, inv.ind_crp_id ";
  223.                                
  224.                     $str = " SELECT ind_crp_id, COUNT(kll_id) AS kills ".
  225.                         " FROM ($str_base , inv.ind_crp_id) as xxx ".
  226.                         " GROUP BY ind_crp_id ";
  227.                     #print $str;   
  228.                            
  229.                     #   $qry = new DBQuery();
  230.                         if (!$qry->execute($str))
  231.                         {
  232.                             die("error - ".__FILE__.':'.__LINE__);
  233.                         }
  234.  
  235.                         while ($row = $qry->getRow())
  236.                         {
  237.                             if ( isset($AllianceCorps[$row['ind_crp_id']]) ) {
  238.                                 $AllianceCorps[$row['ind_crp_id']]['corpKills'] = $row['kills'];
  239.                                
  240.                                 $AllianceCorps[$row['ind_crp_id']]['kill_ratio'] = @($AllianceCorps[$row['ind_crp_id']]['corpKills']/$AllianceCorps[$row['ind_crp_id']]['corpLosses']);
  241.                        
  242.                                 if ($allicorpstatspage_activity_kpms) {
  243.                                     $AllianceCorps[$row['ind_crp_id']]['kills_by_member'] = $AllianceCorps[$row['ind_crp_id']]['corpKills']/$AllianceCorps[$row['ind_crp_id']]['members'];
  244.                                     $AllianceCorps[$row['ind_crp_id']]['kills_by_member_bad'] = false;
  245.                                 }  
  246.                             }
  247.  
  248.                            
  249.             #               if( isset($output_array[$row['ind_crp_id']]) ) {
  250.             #                   $output_array[$row['ind_crp_id']]['all_kills'] = $row['kills'];
  251.             #               }
  252.                         }
  253.                        
  254.                    
  255.     ########################    ########################    ########################    ########################
  256.                        
  257.                    
  258.                         $sql = "SELECT ind_crp_id, SUM(kll_isk_loss) AS iskkill
  259.                             FROM (
  260.                                 SELECT inv.ind_crp_id, kll_isk_loss, inv.ind_plt_id
  261.                                 FROM kb3_kills kll
  262.                                 INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  263.                                 INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  264.                                 WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." )
  265.                                 AND inv.ind_all_id ={$all_id}
  266.                                 AND {$datefilter}
  267.                                 {$str_no_n00bs}
  268.                                 GROUP BY kll.kll_id, inv.ind_crp_id
  269.                             ) AS TMP
  270.                             GROUP BY ind_crp_id";
  271.                         #   print $sql;
  272.                         if (!$qry->execute($sql))
  273.                         {
  274.                             continue;
  275.                         }
  276.  
  277.                         while ($row = $qry->getRow())
  278.                         {   $newisk = $row['iskkill']/1000;
  279.                             if ( isset($AllianceCorps[$row['ind_crp_id']]) ) {
  280.                                 $AllianceCorps[$row['ind_crp_id']]['corpIskKill'] = $newisk;
  281.                                 if (config::get('allicorpstatspage_eff') == 'killlosseff') {} else
  282.                                 {
  283.                                     $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);
  284.                                     $bar = new BarGraph($AllianceCorps[$row['ind_crp_id']]['corpEfficiency'], 100, 75);
  285.                                     $AllianceCorps[$row['ind_crp_id']]['corpBar'] = $bar->generate();
  286.                                 }
  287.                             }
  288.                         }
  289.                        
  290.             if ($active_members_losses)
  291.             {
  292.                         $sql = "SELECT COUNT(distinct charid) as active_members, corpid
  293.                             FROM (
  294.                                     SELECT kll.`kll_victim_id` as charid, kll.`kll_crp_id` AS corpid, 'losses' as `where`
  295.                                     FROM `kb3_kills` kll
  296.                                     WHERE kll.`kll_crp_id` IN ( ".join(',' , $corps )." ) AND kll.kll_all_id = '{$all_id}'
  297.                                     AND  {$datefilter}
  298.                                     GROUP BY kll.`kll_victim_id`, kll.`kll_crp_id`
  299.                                 UNION
  300.                                     SELECT inv.`ind_plt_id` as charid, inv.`ind_crp_id` AS corpid, 'kills' as `where`
  301.                                     FROM `kb3_inv_detail` inv
  302.                                     inner join `kb3_kills` kll ON kll.kll_id = inv.`ind_kll_id`  AND  {$datefilter}
  303.                                     WHERE inv.`ind_crp_id` IN ( ".join(',' , $corps )." ) AND inv.ind_all_id = '{$all_id}'
  304.                                     GROUP BY inv.`ind_plt_id`, inv.`ind_crp_id`
  305.                             ) AS TMP
  306.                             GROUP BY corpid
  307.                             ";
  308.                     #   print $sql;
  309.                         if (!$qry->execute($sql))
  310.                         {
  311.                             continue;
  312.                         }
  313.  
  314.                         while ($row = $qry->getRow())
  315.                         {  
  316.                             if ( isset($AllianceCorps[$row['corpid']]) ) {  #echo '<pre>'.print_r($AllianceCorps[$row['corpid']],1).'</pre>';  
  317.                             #   print_r( $row ); print $AllianceCorps[$row['ind_crp_id']]['active_members']." - ".$row['active_members']." <hr>";
  318.                                 $AllianceCorps[$row['corpid']]['active_members'] = $row['active_members'];
  319.                             #   var_dump( $row['active_members'] );
  320.                                 $AllianceCorps[$row['corpid']]['active_members_proz'] = @(($AllianceCorps[$row['corpid']]['active_members'])/($AllianceCorps[$row['corpid']]['members']))*100;
  321.                             #   print_r( $row ); print $AllianceCorps[$row['ind_crp_id']]['active_members']." - ".$row['active_members']." <hr>";
  322.                         #   echo '<pre>'.print_r($AllianceCorps[$row['corpid']],1).'</pre>';
  323.                             }
  324.                         }
  325.             }                      
  326.                     #   echo '<pre>'.print_r($AllianceCorps,1).'</pre>';   
  327.                            
  328.                     #   print $str;
  329.                        
  330.                     }
  331.                    
  332.                     ///*****************///
  333.                    
  334.                 }
  335.                 elseif ($myAlliName == 'Amarr Empire' || $myAlliName == 'Minmatar Republic' || $myAlliName == 'Caldari State' || $myAlliName == 'Gallente Federation')
  336.                 {              
  337.                         $qry = new DBQuery();
  338.                         $qry->execute(" SELECT crp_id, crp_name, crp_external_id
  339.                                                         FROM kb3_corps
  340.                                                         WHERE crp_all_id = {$all_id}
  341.                                                     ");
  342.                                                    
  343.                         $numRows = $qry->recordCount();
  344.                                                    
  345.                         for ($i = 0; $i < $numRows; ++$i)
  346.                         {
  347.                                 $corpData = $qry->getRow();
  348.                                 $membercorps[] = array( 'corpName' => $corpData['crp_name'],
  349.                                                                                 'corpID' => $corpData['crp_id'],
  350.                                                                                 'corpEVEID' => $corpData['crp_external_id']
  351.                                                                             );
  352.                         }
  353.                        
  354.                         foreach ($membercorps as $corp)
  355.                         {
  356.                                 $myCorpAPI->setCorpID($corp['corpEVEID']);
  357.                                 $result .= $myCorpAPI->fetchXML();
  358.  
  359.                                 // Check if corp is known to EDK DB, if not, add it.
  360.                                 $tempMyCorp->Corporation();
  361.                                 $tempMyCorp->lookup($myCorpAPI->getCorporationName());
  362.                                 if ($tempMyCorp->getID() == 0)
  363.                                 {
  364.                                     $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($corp['startDate'], 0, 16));
  365.                                 }
  366.                        
  367.                                 $crp_id = $corp['corpID'];
  368.                                 $qry = new DBQuery();
  369.                                 $qry->execute(" SELECT count(distinct kll_id) as kills, sum(kll_isk_loss) as iskkill
  370.                                                                 FROM kb3_kills kll
  371.                                                                 INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  372.                                                                 WHERE inv.ind_crp_id = {$corp['corpID']}
  373.                                                                 AND inv.ind_all_id = {$all_id}
  374.                                                                 AND {$datefilter}
  375.                                                             ");                                                        
  376.                                 $killData = $qry->getRow();
  377.                                
  378.                                 $qry = new DBQuery();
  379.                                 $qry->execute(" SELECT count(distinct kll_id) as losses, sum(kll_isk_loss) as iskloss
  380.                                                                 FROM kb3_kills kll
  381.                                                                 WHERE kll.kll_crp_id = {$corp['corpID']}
  382.                                                                 AND kll.kll_all_id = {$all_id}
  383.                                                                 AND {$datefilter}
  384.                                                             ");
  385.                                 $lossData = $qry->getRow();
  386.                                
  387.                                 // Build Data array
  388.                                 $membercorp['corpName'] = $corp['corpName'];
  389.                                 $membercorp['corpID'] = $corp['corpID'];
  390.                                 $membercorp['corpKills'] = $killData['kills'];
  391.                                 $membercorp['corpIskKill'] = $killData['iskkill']/1000;
  392.                                 $membercorp['corpLosses'] = $lossData['losses'];
  393.                                 $membercorp['corpIskLoss'] = $lossData['iskloss']/1000;
  394.                                 if (config::get('bm_allicorpstats_eff') == 'killlosseff')
  395.                                 {
  396.                                     $membercorp['corpEfficiency'] = round($killData['kills'] / (($killData['kills'] + $lossData['losses']) == 0 ? 1 : ($killData['kills'] + $lossData['losses'])) * 100, 2);
  397.                                 }
  398.                                 else
  399.                                 {   // damagedone / (damagedone + damagereceived ) * 100
  400.                                     $membercorp['corpEfficiency'] = round($killData['iskkill'] / (($killData['iskkill'] + $lossData['iskloss']) == 0 ? 1 : ($killData['iskkill'] + $lossData['iskloss'])) * 100, 2);
  401.                                 #   $membercorp['corpEfficiency'] = (( $killData['iskkill'] / ($killData['iskkill'] + $lossData['iskloss']) ) * 100 );
  402.                                 }
  403.                            
  404.                                                                    
  405.                                 $bar = new BarGraph($membercorp['corpEfficiency'], 100, 75);
  406.                                 $membercorp['corpBar'] = $bar->generate();
  407.                                 if (config::get('allicorpstatspage_ticker')) $membercorp["ticker"] = $myCorpAPI->getTicker();
  408.                                 if (config::get('allicorpstatspage_members')) $membercorp["members"] = $myCorpAPI->getMemberCount();
  409.                                 if (config::get('allicorpstatspage_ceo')) $membercorp['corpCeo'] = $myCorpAPI->getCeoName();
  410.                                 if (config::get('allicorpstatspage_hq')) $membercorp['corpHQ'] = $myCorpAPI->getStationName();
  411.                                
  412.                                 // add all the data together into another array
  413.                                 $AllianceCorps[] = $membercorp;
  414.                            
  415.                                 $membercorp = array();
  416.                                 unset($membercorp);
  417.                         }
  418.                 }
  419.                
  420.                 $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName');
  421.                
  422.                 // order by settings, pulled from allicorpstats_page settings.php
  423.                 // we have to order the array in php rather than order the SQL query. this is
  424.                 // because we dont pull names, ids or efficiency in our own query
  425.                 $_order = config::get('allicorpstatspage_order');
  426.                
  427.                    
  428.                 foreach( $AllianceCorps as &$_alycorp ) {
  429.             //      $killrq = (int)( (int)$_alycorp['members']>66 ? (int)$_alycorp['members']*3 : 200);
  430.                     $killrq = (int)@$_alycorp['members']*$allicorpstatspage_activity_killsbymember;
  431.                     if( $allicorpstatspage_activity_kills_min ) {
  432.                         $killrq = max( array($killrq,$allicorpstatspage_activity_kills_min) );
  433.                     }
  434.                    
  435.                     $_alycorp['killrq_base'] = $killrq;
  436.                     $_alycorp['killrq'] = $_alycorp['corpKills'] - $killrq;
  437.                     $_alycorp['killrq_nq'] = $_alycorp['killrq']<0;
  438.  
  439.                     $_alycorp['killrq_status_member_act'] = ($_alycorp['active_members_proz'] > ($allicorpstatspage_activity_members_minactprz-1) );
  440.                    
  441.                    
  442.                     if( !$_alycorp['killrq_status_member_act'] && $_alycorp['killrq_nq'] ) {
  443.                         $_alycorp['killrq_status'] = 'bad';
  444.                         $_alycorp['killrq_status_color'] = '#B11818';
  445.                     } elseif( !$_alycorp['killrq_status_member_act'] ) {
  446.                         $_alycorp['killrq_status'] = 'bad_act';
  447.                         $_alycorp['killrq_status_color'] = 'yellow';
  448.                     } elseif( $_alycorp['killrq_nq'] ) {
  449.                         $_alycorp['killrq_status'] = 'bad_killrq';
  450.                         $_alycorp['killrq_status_color'] = 'orange';
  451.                     } else {
  452.                         $_alycorp['killrq_status'] = 'ok';
  453.                         $_alycorp['killrq_status_color'] = '#6FAC60';
  454.                     }
  455.  
  456.                     if( !empty($this->weekno_) && (@$_GET['daterange']=='weekly') ) {
  457.                         $_alycorp['killrq_status'] = 'weekly';
  458.                         $_alycorp['killrq_status_color'] = '#E0E0E0';
  459.                     }
  460.                    
  461.                     $_alycorp['f_title'] = '';
  462.                     if( $_alycorp['killrq_nq'] ) {
  463.                         $_alycorp['f_title'] .= " ( ".( (int)(@($_alycorp['corpKills']/$_alycorp['killrq_base'])*100) ).'%';
  464.                        
  465.                         if( (int)$this->monthno_==(int)date('m') && (int)$this->yearno_==(int)date('Y') ) {
  466.                             $_alycorp['f_title'] .= " | ".( (int)(@(date('j')/date('t'))*100) ).'%';
  467.                         }
  468.                        
  469.                         $_alycorp['f_title'] .= " ) ";
  470.                     }
  471.                    
  472.                 }
  473.                
  474.                 if( isset($_GET['order']) && in_array( $_GET['order'],
  475.                         array('nameasc','tickerasc','ceodesc','membersdesc','memberactsdesc','memberactprozsdesc','nameasc','killsdesc','killiskdesc','killsbymemberasc','killsbymemberdesc','lossesdesc','lossiskdesc','effdesc','killrq','kill_ratio')
  476.                     ) ) {
  477.                     $_order = $_GET['order'];
  478.                 }
  479.                
  480.                 if ($_order == 'membersdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'members', arsort);
  481.                 if ($_order == 'memberactsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'active_members', arsort);
  482.                 if ($_order == 'memberactprozsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'active_members_proz', arsort);
  483.  
  484.                
  485.                 if ($_order == 'tickerasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'ticker' );
  486.                 if ($_order == 'ceodesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpCeo' );
  487.                
  488.                 if ($_order == 'nameasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName');
  489.                 if ($_order == 'namedesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpName', arsort);
  490.                 if ($_order == 'killsasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpKills');
  491.                 if ($_order == 'killsdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpKills', arsort);
  492.                 if ($_order == 'killiskasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskKill');
  493.                 if ($_order == 'killiskdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskKill', arsort);
  494.                 if ($_order == 'lossesasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpLosses');
  495.                 if ($_order == 'lossesdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpLosses', arsort);
  496.                 if ($_order == 'lossiskasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskLoss');
  497.                 if ($_order == 'lossiskdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpIskLoss', arsort);
  498.                 if ($_order == 'effasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpEfficiency');
  499.                 if ($_order == 'effdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'corpEfficiency', arsort);
  500.                 if ($_order == 'killrq') $AllianceCorps = $this->subvalSort($AllianceCorps, 'killrq');
  501.                
  502.                 if ($_order == 'killsbymemberasc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kills_by_member');
  503.                 if ($_order == 'killsbymemberdesc') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kills_by_member', arsort);
  504.            
  505.                 if ($_order == 'kill_ratio') $AllianceCorps = $this->subvalSort($AllianceCorps, 'kill_ratio', arsort);
  506.        
  507.                
  508.                
  509.                 $smarty->assign('order', $_order);
  510.                  
  511.             #   echo '<pre>'.print_r($AllianceCorps,1).'</pre>';
  512.                        
  513.                 if (config::get('allicorpstatspage_datefilter') == 'weekly')
  514.                 {
  515.                         $smarty->assign('datefilter', "Week {$this->weekno_}."." {$this->yearno_}");
  516.                 }
  517.                 elseif (config::get('allicorpstatspage_datefilter') == 'monthly')
  518.                 {
  519.                         $timestamp = mktime(0, 0, 0, $this->monthno_, 1, 2005);
  520.                         $smarty->assign('datefilter', date("F", $timestamp)." {$this->yearno_}");
  521.                 }
  522.                 elseif (config::get('allicorpstatspage_datefilter') == 'yearly')
  523.                 {
  524.                         $smarty->assign('datefilter', "{$this->yearno_}");
  525.                 }
  526.                 elseif (config::get('allicorpstatspage_datefilter') == 'alltime')
  527.                 {
  528.                         $smarty->assign('datefilter', "All-Time");
  529.                 }
  530.                
  531.                 if (isset($_GET['daterange']) && $_GET['daterange'] == 'weekly')
  532.                 {
  533.                         $smarty->assign('datefilter', "Week {$this->weekno_}."." {$this->yearno_}");
  534.                 }
  535.                 elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'monthly')
  536.                 {
  537.                         $timestamp = mktime(0, 0, 0, $this->monthno_, 1, 2005);
  538.                         $smarty->assign('datefilter', date("F", $timestamp)." {$this->yearno_}");
  539.                 }
  540.                 elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'yearly')
  541.                 {
  542.                         $smarty->assign('datefilter', "{$this->yearno_}");
  543.                 }
  544.                 elseif (isset($_GET['daterange']) && $_GET['daterange'] == 'alltime')
  545.                 {
  546.                         $smarty->assign('datefilter', "All-Time");
  547.                 }
  548.                
  549.                 if (config::get('allicorpstatspage_ticker')) $smarty->assign('showticker', 1);
  550.                 if (config::get('allicorpstatspage_members')) $smarty->assign('showmembers', 1);
  551.                 if (config::get('allicorpstatspage_ceo')) $smarty->assign('showceo', 1);
  552.                 if (config::get('allicorpstatspage_hq')) $smarty->assign('showhq', 1);
  553.                 $smarty->assign('membercorps', $AllianceCorps);
  554.                
  555.                 $ext_link = (!empty($_GET['w'])?'&w='.(int)$_GET['w']:'')
  556.                           . (!empty($_GET['m'])?'&m='.(int)$_GET['m']:'')
  557.                           . (!empty($_GET['y'])?'&y='.(int)$_GET['y']:'')
  558.                           . (@$_GET['no_n00bs']=='true' ? '&no_n00bs=true' : '' );
  559.                
  560.                 $smarty->assign( 'ext_link', $ext_link );
  561.                
  562.                 $smarty->assign( 'active_members_losses' , $active_members_losses );
  563.                
  564.                 $smarty->assign( 'allicorpstatspage_activity' , $allicorpstatspage_activity );
  565.                 $smarty->assign( 'show_kills_by_member', $allicorpstatspage_activity_kpms );
  566.                 $smarty->assign( 'show_kill_ratio' , $allicorpstatspage_activity_krr );
  567.                
  568.                
  569.                 return $smarty->fetch( dirname(__FILE__).'/allicorpstats.tpl');
  570.             //  return $smarty->fetch(getcwd() . '/mods/allicorpstats_page/allicorpstats.tpl');
  571.     }
  572.        
  573.  
  574.     function generate_by_region() {
  575.            
  576.  
  577.          global $smarty;
  578.            
  579.             $datefilter = $this->getDateFilter();
  580.            
  581.             $alliance = new Alliance(ALLIANCE_ID);
  582.             $all_id = ALLIANCE_ID;
  583.             $tempMyCorp = new Corporation();
  584.  
  585.             $myAlliName = $alliance->getName();
  586.             $myAlliAPI = new AllianceAPI();
  587.             $myAlliAPI->fetchalliances();
  588.             $myAlliAPI->UpdateAlliances();
  589.             $myAlliance = $myAlliAPI->LocateAlliance( $myAlliName );
  590.             $myCorpAPI = new API_CorporationSheet();
  591.            
  592.             $allicorpstatspage_kbr = config::get('allicorpstatspage_kbr');
  593.             if( is_null($allicorpstatspage_kbr) ) { $allicorpstatspage_kbr = true; }
  594.             $allicorpstatspage_kbr_src = config::get('allicorpstatspage_kbr_src');
  595.             if( $allicorpstatspage_kbr_src<3 || $allicorpstatspage_kbr_src>10 ) $allicorpstatspage_kbr_src = 6;
  596.  
  597.             if( !$allicorpstatspage_kbr ) {
  598.                 return '<b style="color:red;">corp stat by region not enabled!</b>';
  599.             }
  600.            
  601.             $show_max_regs = $allicorpstatspage_kbr_src;
  602.            
  603.             if ($myAlliance)
  604.             {
  605.        
  606.                 $str_no_n00bs = '';
  607.                 if( @$_GET['no_n00bs'] == 'true' ) {
  608.                     // Noobship, Shuttle, Capsule
  609.                     $str_no_n00bs = " AND st.shp_class NOT IN (3,11,2) ";
  610.                 }
  611.            
  612.                 $output_array = array( 'ally' => array('name' => $myAlliName, 'all_kills' => 0) );
  613.                 $output_array_names = array( 'ally' => $myAlliName );
  614.                 $output_array_regNames = array();
  615.                 $corps = array();
  616.                 foreach ( (array)$myAlliance['memberCorps'] as $tempcorp)
  617.                 {
  618.                
  619.                     $myCorpAPI->setCorpID($tempcorp['corporationID']);
  620.                     $result .= $myCorpAPI->fetchXML();
  621.  
  622.                     // Check if corp is known to EDK DB, if not, add it.
  623.                     $tempMyCorp->Corporation();
  624.                     $tempMyCorp->lookup($myCorpAPI->getCorporationName());
  625.                     if ($tempMyCorp->getID() == 0)
  626.                     {
  627.                         $tempMyCorp->add($myCorpAPI->getCorporationName(), $alliance , substr($tempcorp['startDate'], 0, 16));
  628.                     }
  629.                    
  630.                     $corps[$tempMyCorp->getID()] = $tempMyCorp->getID();
  631.                    
  632.             //      $output_array[$tempMyCorp->getID()] = array();
  633.             //      $output_array_names[$tempMyCorp->getID()] = $tempMyCorp->getName();
  634.                     $output_array_names_tmp[$tempMyCorp->getID()] = $tempMyCorp->getName();
  635.                     $output_array_names_tmp2[$tempMyCorp->getName()] = $tempMyCorp->getID();
  636.                 }
  637.                
  638.                 sort($output_array_names_tmp,SORT_STRING);
  639.             //  echo '<pre>'.print_r($output_array_names_tmp,1).'</pre>';
  640.                 foreach($output_array_names_tmp as $corpname) {
  641.                     $corpid = $output_array_names_tmp2[$corpname];
  642.                     $output_array[$corpid] = array( 'name' => $corpname, 'all_kills' => 0 );
  643.                     $output_array_names[$corpid] = $corpname;  
  644.                 }
  645.                
  646.     //          echo '<pre>'.print_r($corps,1).'</pre>';
  647.                
  648.                 $top10_regions = array();
  649.                 if( count($corps) ) {
  650.            
  651.                 $str_base = "SELECT inv.ind_crp_id, kll.kll_id, kll.kll_system_id, reg.reg_id ,reg.reg_name
  652.                     FROM kb3_kills kll
  653.                     INNER JOIN kb3_systems sys ON sys.sys_id = kll.kll_system_id
  654.                     INNER JOIN kb3_constellations cns ON sys.sys_con_id = cns.con_id
  655.                     INNER JOIN kb3_regions reg ON reg.reg_id = cns.con_reg_id
  656.                     INNER JOIN kb3_inv_detail inv ON inv.ind_kll_id = kll.kll_id
  657.                     INNER JOIN kb3_ships st ON st.shp_id = kll.kll_ship_id
  658.                     WHERE inv.ind_crp_id IN ( ".join(',' , $corps )." ) AND kll.kll_all_id <> '{$all_id}'
  659.                     AND  {$datefilter}
  660.                         $str_no_n00bs
  661.                     GROUP BY kll.kll_id "; //, inv.ind_crp_id ";
  662. #       print $str_base.'<hr>';        
  663.                 $str = " SELECT reg_id, reg_name, COUNT(kll_id) AS kills ".
  664.                     " FROM ($str_base) as xxx ".
  665.                     " GROUP BY reg_id ".
  666.                     " ORDER BY kills DESC LIMIT $show_max_regs ";
  667. #       print $str;
  668.  
  669.                 $qry = new DBQuery();
  670.                 if (!$qry->execute($str))
  671.                 {
  672.                     die("error - ".__FILE__.':'.__LINE__);
  673.                 }
  674.  
  675.                 while ($row = $qry->getRow())
  676.                 {
  677.                     $regKey = $row['reg_name'];
  678.                     $top10_regions[$row['reg_id']] = $row;
  679.                     $output_array_regNames[$row['reg_id']] = $row['reg_name'];
  680.                    
  681.                     $output_array['ally'][$regKey] = $row['kills'];
  682.                     foreach( $corps as $corpid ) {
  683.                         $output_array[$corpid][$regKey] = 0;
  684.                     }
  685.                    
  686.                 }
  687. // kills by corp               
  688.                 $str = " SELECT ind_crp_id, COUNT(kll_id) AS kills ".
  689.                     " FROM ($str_base , inv.ind_crp_id) as xxx ".
  690.                     " GROUP BY ind_crp_id ";
  691.                 #print $str;   
  692.                    
  693.                 $qry = new DBQuery();
  694.                 if (!$qry->execute($str))
  695.                 {
  696.                     die("error - ".__FILE__.':'.__LINE__);
  697.                 }
  698.  
  699.                 while ($row = $qry->getRow())
  700.                 {
  701.                     if( isset($output_array[$row['ind_crp_id']]) ) {
  702.                         $output_array[$row['ind_crp_id']]['all_kills'] = $row['kills'];
  703.                     }
  704.                 }
  705.                
  706. // get alliance killcount
  707.                 $str = " SELECT COUNT(kll_id) AS kills ".
  708.                     " FROM ($str_base) as xxx ".
  709.                     " ";
  710.                    
  711.                 $qry = new DBQuery();
  712.                 if (!$qry->execute($str))
  713.                 {
  714.                     die("error - ".__FILE__.':'.__LINE__);
  715.                 }
  716.  
  717.                 if ($row = $qry->getRow())
  718.                 {   #print_r($row);
  719.                     $output_array['ally']['all_kills'] = $row['kills'];
  720.                 }
  721.                
  722. // kills by region             
  723.                 $str = " SELECT reg_id, reg_name, ind_crp_id, COUNT(kll_id) AS kills ".
  724.                     " FROM ($str_base , inv.ind_crp_id) as xxx ".
  725.                     " GROUP BY reg_id, ind_crp_id ".
  726.                     " ";
  727.                
  728.                 if (!$qry->execute($str))
  729.                 {
  730.                     die("error - ".__FILE__.':'.__LINE__);
  731.                 }
  732.  
  733.                 while ($row = $qry->getRow())
  734.                 {  
  735.                     $regKey = $row['reg_name'];
  736.                    
  737.                     if( isset($output_array[$row['ind_crp_id']]) && isset($output_array[$row['ind_crp_id']][$regKey]) ) {
  738.                         $output_array[$row['ind_crp_id']][$regKey] = $row['kills'];
  739.                     }                  
  740.                 }
  741.                
  742.                 #echo '<pre>'.print_r($top10_regions,1).'</pre>';
  743.                
  744.     #           echo '<pre>'.print_r($output_array_names,1).'</pre>';
  745.     #           echo '<pre>'.print_r($output_array_regNames,1).'</pre>';
  746.     #           echo '<pre>'.print_r($output_array,1).'</pre>';
  747.                
  748.                 $order_set = false;
  749.                 if( in_array(@$_GET['order'],$output_array_regNames) ) {
  750.                     $output_array = $this->subvalSort($output_array, $_GET['order'], arsort);
  751.                     $order_set = true;
  752.                 }
  753.                 if (@$_GET['order'] == 'name' ) $order_set = true;
  754.                 if (@$_GET['order'] == 'all_kills' || !$order_set) $output_array = $this->subvalSort($output_array, 'all_kills', arsort);
  755.        
  756.                
  757.                 $ext_link = (!empty($_GET['w'])?'&w='.(int)$_GET['w']:'')
  758.                           . (!empty($_GET['m'])?'&m='.(int)$_GET['m']:'')
  759.                           . (!empty($_GET['y'])?'&y='.(int)$_GET['y']:'')
  760.                           . (@$_GET['no_n00bs']=='true' ? '&no_n00bs=true' : '' );
  761.                
  762.                 $smarty->assign( 'ext_link', $ext_link );
  763.                
  764.                 $smarty->assign( 'output_array_names' ,     $output_array_names );
  765.                 $smarty->assign( 'output_array_regNames' ,  $output_array_regNames );
  766.                 $smarty->assign( 'output_array' ,           $output_array );
  767.                
  768.                 $smarty->assign( 'output_all_id', $all_id );
  769.  
  770.                 return $smarty->fetch( dirname(__FILE__).'/allicorpstats_region.tpl' );            
  771.         //      return $smarty->fetch( getcwd() .'/mods/allicorpstats_page/allicorpstats.tpl');
  772.                
  773.                
  774.                 }
  775.                
  776.             }
  777.    
  778.    
  779.             return '';
  780.     }
  781.  
  782.         //! Filter results by week. Requires the year to also be set.
  783.     function setWeek($weekno)
  784.     {
  785.         $weekno=intval($weekno);
  786.         if($weekno <1)  $this->weekno_ = 1;
  787.         if($weekno >53) $this->weekno_ = 53;
  788.         else $this->weekno_ = $weekno;
  789.     }
  790.  
  791.     //! Filter results by year.
  792.     function setYear($yearno)
  793.     {
  794.         // 1970-2038 is the allowable range for the timestamp code used
  795.         // Needs to be revisited in the next 30 years
  796.         $yearno = intval($yearno);
  797.         if($yearno < 1970) $this->yearno_ = 1970;
  798.         if($yearno > 2038) $this->yearno_ = 2038;
  799.         else $this->yearno_ = $yearno;
  800.     }
  801.        
  802.         //! Filter results by month
  803.     function setMonth($monthno)
  804.     {
  805.         $monthno = intval($monthno);
  806.         if($monthno < 1) $this->monthno_ = 1;
  807.         if($monthno > 12) $this->monthno_ = 12;
  808.         else $this->monthno_ = $monthno;
  809.     }
  810.  
  811.     //! Filter results by starting week. Requires the year to also be set.
  812.     function setStartWeek($weekno)
  813.     {
  814.         $weekno=intval($weekno);
  815.         if($weekno <1)  $this->startweekno_ = 1;
  816.         if($weekno >53) $this->startweekno_ = 53;
  817.         else $this->startweekno_ = $weekno;
  818.     }
  819.  
  820.     //! Filter results by starting date/time.
  821.     function setStartDate($timestamp)
  822.     {
  823.         // Check timestamp is valid before adding
  824.         if(strtotime($timestamp)) $this->startDate_ = $timestamp;
  825.     }
  826.  
  827.     //! Filter results by ending date/time.
  828.     function setEndDate($timestamp)
  829.     {
  830.         // Check timestamp is valid before adding
  831.         if(strtotime($timestamp)) $this->endDate_ = $timestamp;
  832.     }
  833.  
  834.     //! \return string containing SQL date filter.
  835.     function getDateFilter()
  836.     {
  837.                 $qstartdate = makeStartDate($this->weekno_, $this->yearno_, $this->monthno_, $this->startweekno_, $this->startDate_);
  838.                 $qenddate = makeEndDate($this->weekno_, $this->yearno_, $this->monthno_, $this->endDate_);
  839.                 if($qstartdate) $sql .= " kll.kll_timestamp >= '".gmdate('Y-m-d H:i',$qstartdate)."' ";
  840.                 if($qstartdate && $qenddate) $sql .= " AND ";
  841.                 if($qenddate) $sql .= " kll.kll_timestamp <= '".gmdate('Y-m-d H:i',$qenddate)."' ";
  842.                 return $sql;
  843.    }
  844.        
  845.         function subvalSort($a, $subkey, $sort = asort)
  846.         {
  847.                 foreach($a as $k=>$v) {
  848.                     $b[$k] = strtolower($v[$subkey]);
  849.                 }
  850.                 $sort($b);
  851.                
  852.                 foreach($b as $key=>$val) {
  853.                     $c[] = $a[$key];
  854.                 }
  855.                 return $c;
  856.         }
  857. }
  858. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement