1<?php
2
3if (!empty($_GET['warid'])) {
4 $warid = (int)$_GET['warid']; // Sanitizing GET.
5
6 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) $war = get_guild_war($warid);
7 else if (znote_server_adapter()->normalizedEngine() === 'TFS_03') $war = get_guild_war03($warid);
8 else die("Can't recognize TFS version. It has to be either TFS_02 or TFS_03. Correct this in config.php");
9
10 if ($war != false) {
11 // Kills data for this specific war entry
12 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) $kills = get_war_kills($warid);
13 else if (znote_server_adapter()->normalizedEngine() === 'TFS_03') $kills = get_war_kills03($warid);
14 ?>
15 <h1><?php echo $war['name1']; ?> - <?= t('guildwar.versus') ?> - <?php echo $war['name2']; ?></h1>
16
17 <?php
18 // Collecting <ul> data:
19 $guild1 = $war['guild1'];
20 $g1c = 0; // kill count
21
22 $guild2 = $war['guild2'];
23 $g2c = 0; // kill count
24
25 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) {
26 foreach (($kills ? $kills : array()) as $kill) {
27 if ($kill['killerguild'] == $guild1)
28 $g1c++;
29 else
30 $g2c++;
31 }
32
33 $green = false;
34 if ($g1c > $g2c) {
35 $leading = $war['name1'];
36 $green = true;
37 } else if ($g2c > $g1c) $leading = $war['name2'];
38 else $leading = t('guildwar.tie');
39 }
40 ?>
41 <ul class="war_list">
42 <li>
43 <?= t('guildwar.status', ['status' => $config['war_status'][$war['status']]]) ?>
44 </li>
45 <?php if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) { ?>
46 <li>
47 <?= t('guildwar.leading', ['guild' => $leading]) ?>
48 </li>
49 <li>
50 <?php
51 if ($green)
52 echo t('guildwar.score') .' <font color="green">'. $g1c .'</font>-<font color="red">'. $g2c .'</font>';
53 else if ($g1c == $g2c)
54 echo t('guildwar.score') .' <font color="orange">'. $g1c .'</font>-<font color="orange">'. $g2c .'</font>';
55 else
56 echo t('guildwar.score') .' <font color="red">'. $g1c .'</font>-<font color="green">'. $g2c .'</font>';
57 ?>
58 </li>
59 <?php } ?>
60 </ul>
61 <?php
62 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) {
63 ?>
64 <table id="guildwarTable" class="table table-striped table-hover">
65 <tr class="yellow">
66 <th><?= t('guildwar.killerguild') ?></th>
67 <th><?= t('guildwar.killer') ?></th>
68 <th><?= t('guildwar.victim') ?></th>
69 <th><?= t('guildwar.time') ?></th>
70 </tr>
71 <?php
72 foreach (($kills ? $kills : array()) as $kill) {
73 echo '<tr>';
74 //echo '<td>'. get_guild_name($kill['killerguild']) .'</td>';
75 echo '<td><a href="guilds.php?name='. get_guild_name($kill['killerguild']) .'">'. get_guild_name($kill['killerguild']) .'</a></td>';
76 echo '<td><a href="characterprofile.php?name='. $kill['killer'] .'">'. $kill['killer'] .'</a></td>';
77 echo '<td><a href="characterprofile.php?name='. $kill['target'] .'">'. $kill['target'] .'</a></td>';
78 echo '<td>'. getClock($kill['time'], true) .'</td>';
79 echo '</tr>';
80 }
81 ?>
82 </table>
83 <?php
84 }
85 if (znote_server_adapter()->normalizedEngine() === 'TFS_03') {
86 // BORROWED FROM GESIOR (and ported to work on Znote AAC).
87 $main_content = "";
88 $deaths = gesior_sql_death($warid);
89 if($deaths !== false)
90 {
91 //die(print_r($deaths));
92 foreach($deaths as $death)
93 {
94 $killers = gesior_sql_killer((int)$death['id']);
95 $count = count($killers); $i = 0;
96
97 $others = false;
98 $main_content .= date("j M Y, H:i", $death['date']) . " <span style=\"font-weight: bold; color: " . ($death['enemy'] == $war['guild_id'] ? "red" : "lime") . ";\">+</span>
99<a href=\"characterprofile.php?name=" . urlencode($death['name']) . "\"><b>".$death['name']."</b></a> ";
100 foreach($killers as $killer)
101 {
102 $i++;
103 if($killer['is_war'] != 0)
104 {
105 if($i == 1)
106 $main_content .= t('guildwar.killed_by', ['level' => $death['level']]) ." ";
107 else if($i == $count && $others == false)
108 $main_content .= " ". t('guildwar.and_by') ." ";
109 else
110 $main_content .= ", ";
111 if($killer['player_exists'] == 0)
112 $main_content .= "<a href=\"characterprofile.php?name=".urlencode($killer['player_name'])."\">";
113
114 $main_content .= $killer['player_name'];
115 if($killer['player_exists'] == 0)
116 $main_content .= "</a>";
117 }
118 else
119 $others = true;
120
121 if($i == $count)
122 {
123 if($others == true)
124 $main_content .= " ". t('guildwar.few_others');
125 $main_content .= ".<br />";
126 }
127 }
128 }
129 }
130 else
131 $main_content .= "<center>". t('guildwar.no_frags') ."</center>";
132 echo $main_content;
133 // END BORROWED FROM GESIOR
134 }
135 }
136
137} else {
138 // Display current wars.
139
140 // Fetch list of wars
141 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) $wardata = get_guild_wars();
142 else if (znote_server_adapter()->normalizedEngine() === 'TFS_03') $wardata = get_guild_wars03();
143 else die("Can't recognize TFS version. It has to be either TFS_02 or TFS_03. Correct this in config.php");
144 //echo $wardata[0]['name1'];
145 //die(var_dump($wardata));
146 if ($wardata != false) {
147 // kills data
148 $killsdata = array(); // killsdata[guildid] => array(warid) => array info about the selected war entry
149 foreach ($wardata as $wars) {
150 if (in_array(znote_server_adapter()->normalizedEngine(), array('TFS_02', 'OTHIRE', 'TFS_10'), true)) $killsdata[$wars['id']] = get_war_kills($wars['id']);
151 else if (znote_server_adapter()->normalizedEngine() === 'TFS_03') $killsdata[$wars['id']] = get_war_kills03($wars['id']);
152 }
153 ?>
154
155 <table id="guildwarViewTable" class="table table-striped table-hover">
156 <tr class="yellow">
157 <th><?= t('guildwar.attacking') ?></th>
158 <th><?= t('guildwar.deathcount') ?></th>
159 <th><?= t('guildwar.defending') ?></th>
160 </tr>
161 <?php
162 foreach ($wardata as $wars) {
163 $guild_1_kills = 0;
164 $guild_2_kills = 0;
165 foreach (($killsdata[$wars['id']] ? $killsdata[$wars['id']] : array()) as $kill) {
166
167 if ($isOtx && $kill['guild_id'] == $wars['guild1'] || !$isOtx && $kill['killerguild'] == $wars['guild1'])
168 $guild_1_kills++;
169 else
170 $guild_2_kills++;
171 }
172 $url = url("guildwar.php?warid=". $wars['id']);
173 $guildname1 = url("guilds.php?name=". $wars['name1']);
174 $guildname2 = url("guilds.php?name=". $wars['name2']);
175 echo '<tr>';
176 echo '<td><a href="' . $guildname1 . '">'. $wars['name1'] .'</a></td>';
177 echo '<td>'. $guild_1_kills .' - ' . $guild_2_kills . '</td>';
178 echo '<td><a href="' . $guildname2 . '">'. $wars['name2'] .'</a></td>';
179 echo '<td><a href="' . $url . '">'. t('common.view') .'</a></td>';
180 echo '</tr>';
181 }
182 ?>
183 </table>
184
185 <?php
186 } else {
187 echo t('guildwar.none');
188 }
189}
190// GET links sample:
191// guildwar.php?warid=1
192