Advertisement
Guest User

guildwar.php

a guest
Dec 11th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.30 KB | None | 0 0
  1. <?php require_once 'engine/init.php';
  2. if ($config['require_login']['guildwars']) protect_page();
  3. if ($config['log_ip']) znote_visitor_insert_detailed_data(3);
  4. if ($config['guildwar_enabled'] === false) {
  5.     header('Location: guilds.php');
  6.     exit();
  7. }
  8. include 'layout/overall/header.php';
  9.  
  10. if (!empty($_GET['warid'])) {
  11.     $warid = (int)$_GET['warid']; // Sanitizing GET.
  12.    
  13.     if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') $war = get_guild_war($warid);
  14.     else if ($config['TFSVersion'] == 'TFS_03') $war = get_guild_war03($warid);
  15.     else die("Can't recognize TFS version. It has to be either TFS_02 or TFS_03. Correct this in config.php");
  16.    
  17.     if ($war != false) {
  18.         // Kills data for this specific war entry
  19.         if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') $kills = get_war_kills($warid);
  20.         else if ($config['TFSVersion'] == 'TFS_03') $kills = get_war_kills03($warid);
  21.         // XDXD
  22.        
  23.         ?>
  24.         <h1><?php echo $war['name1']; ?> - VERSUS - <?php echo $war['name2']; ?></h1>
  25.        
  26.         <?php
  27.         // Collecting <ul> data:
  28.         $guild1 = $war['guild1'];
  29.         $g1c = 0; // kill count
  30.        
  31.         $guild2 = $war['guild2'];
  32.         $g2c = 0; // kill count
  33.        
  34.         if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') {
  35.             foreach ($kills as $kill) {
  36.                 if ($kill[killerguild] == $guild1) ++$g1c;
  37.                 if ($kill[killerguild] == $guild2) ++$g2c;
  38.             }
  39.            
  40.             $green = false;
  41.             if ($g1c > $g2c) {
  42.                 $leading = $war['name1'];
  43.                 $green = true;
  44.             } else if ($g2c > $g1c) $leading = $war['name2'];
  45.             else $leading = "Tie";
  46.         }
  47.         ?>
  48.         <ul class="war_list">
  49.             <li>
  50.                 War status: <?php echo $config['war_status'][$war['status']]; ?>.
  51.             </li>
  52.             <?php if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') { ?>
  53.             <li>
  54.                 Leading guild: <?php echo $leading; ?>.
  55.             </li>
  56.             <li>
  57.                 <?php
  58.                 if ($green) echo 'Score: <font color="green">'. $g1c .'</font>-<font color="red">'. $g2c .'</font>';
  59.                 else if ($g1c = $g2c) echo 'Score: <font color="orange">'. $g1c .'</font>-<font color="orange">'. $g2c .'</font>';
  60.                 else echo 'Score: <font color="red">'. $g1c .'</font>-<font color="green">'. $g2c .'</font>';
  61.                 ?>
  62.             </li>
  63.             <?php } ?>
  64.         </ul>
  65.         <?php
  66.         if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') {
  67.         ?>
  68.             <table id="guildwarTable" class="table table-striped table-hover">
  69.                 <tr class="yellow">
  70.                     <th>Killer's guild:</th>
  71.                     <th>Killer:</th>
  72.                     <th>Victim:</th>
  73.                     <th>Time:</th>
  74.                 </tr>
  75.                     <?php
  76.                     foreach ($kills as $kill) {
  77.                         echo '<tr>';
  78.                         //echo '<td>'. get_guild_name($kill['killerguild']) .'</td>';
  79.                         echo '<td><a href="guilds.php?name='. get_guild_name($kill['killerguild']) .'">'. get_guild_name($kill['killerguild']) .'</a></td>';
  80.                         echo '<td><a href="characterprofile.php?name='. $kill['killer'] .'">'. $kill['killer'] .'</a></td>';
  81.                         echo '<td><a href="characterprofile.php?name='. $kill['target'] .'">'. $kill['target'] .'</a></td>';
  82.                         echo '<td>'. getClock($kill['time'], true) .'</td>';
  83.                         echo '</tr>';
  84.                     }
  85.                     ?>
  86.             </table>
  87.         <?php
  88.         }
  89.         if ($config['TFSVersion'] == 'TFS_03') {
  90.             // BORROWED FROM GESIOR (and ported to work on Znote AAC).
  91.             $main_content = "";
  92.             $deaths = gesior_sql_death($warid);
  93.             if($deaths !== false)
  94.             {
  95.                 //die(print_r($deaths));
  96.                 foreach($deaths as $death)
  97.                 {
  98.                     $killers = gesior_sql_killer((int)$death['id']);
  99.                     $count = count($killers); $i = 0;
  100.  
  101.                     $others = false;
  102.                     $main_content .= date("j M Y, H:i", $death['date']) . " <span style=\"font-weight: bold; color: " . ($death['enemy'] == $war['guild_id'] ? "red" : "lime") . ";\">+</span>
  103. <a href=\"characterprofile.php?name=" . urlencode($death['name']) . "\"><b>".$death['name']."</b></a> ";
  104.                     foreach($killers as $killer)
  105.                     {
  106.                         $i++;
  107.                         if($killer['is_war'] != 0)
  108.                         {
  109.                             if($i == 1)
  110.                                 $main_content .= "killed at level <b>".$death['level']."</b> by ";
  111.                             else if($i == $count && $others == false)
  112.                                 $main_content .= " and by ";
  113.                             else
  114.                                 $main_content .= ", ";
  115.                             if($killer['player_exists'] == 0)
  116.                                 $main_content .= "<a href=\"characterprofile.php?name=".urlencode($killer['player_name'])."\">";
  117.  
  118.                             $main_content .= $killer['player_name'];
  119.                             if($killer['player_exists'] == 0)
  120.                                 $main_content .= "</a>";
  121.                         }
  122.                         else
  123.                             $others = true;
  124.  
  125.                         if($i == $count)
  126.                         {
  127.                             if($others == true)
  128.                                     $main_content .= " and few others";
  129.                             $main_content .= ".<br />";
  130.                         }
  131.                     }
  132.                 }
  133.             }
  134.             else
  135.                 $main_content .= "<center>There were no frags on this war so far.</center>";
  136.             echo $main_content;
  137.             // END BORROWED FROM GESIOR
  138.         }
  139.     }
  140.    
  141. } else {
  142.     // Display current wars.
  143.    
  144.     // Fetch list of wars
  145.     if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') $wardata = get_guild_wars();
  146.     else if ($config['TFSVersion'] == 'TFS_03') $wardata = get_guild_wars03();
  147.     else die("Can't recognize TFS version. It has to be either TFS_02 or TFS_03. Correct this in config.php");
  148.     //echo $wardata[0]['name1'];
  149.     //die(var_dump($wardata));
  150.     if ($wardata != false) {
  151.    
  152.     // kills data
  153.     $killsdata = array(); // killsdata[guildid] => array(warid) => array info about the selected war entry
  154.     foreach ($wardata as $wars) {
  155.         if ($config['TFSVersion'] == 'TFS_02' || $config['TFSVersion'] == 'TFS_10') $killsdata[$wars['id']] = get_war_kills($wars['id']);
  156.         else if ($config['TFSVersion'] == 'TFS_03') $killsdata[$wars['id']] = get_war_kills03($wars['id']);
  157.     }
  158.         ?>
  159.        
  160.         <table id="guildwarViewTable" class="table table-striped table-hover">
  161.             <tr class="yellow">
  162.                 <th>Attacking Guild:</th>
  163.                 <th>Death Count:</th>
  164.                 <th>Defending Guild:</th>
  165.             </tr>
  166.                 <?php
  167.                 foreach ($wardata as $wars) {
  168.                     $url = url("guildwar.php?warid=". $wars['id']);
  169.                     echo '<tr class="special" onclick="javascript:window.location.href=\'' . $url . '\'">';
  170.                     echo '<td>'. $wars['name1'] .'</td>';
  171.                     echo '<td>'. count($killsdata[$wars['id']]) .'</td>';
  172.                     echo '<td>'. $wars['name2'] .'</td>';
  173.                     echo '</tr>';
  174.                 }
  175.                 ?>
  176.         </table>
  177.  
  178.         <?php
  179.     } else {
  180.         echo 'There have not been any pending wars on this server.';
  181.     }
  182. }
  183. // GET links sample:
  184. // guildwar.php?warid=1
  185. include 'layout/overall/footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement