<? include $DOCUMENT_ROOT."/zzzfilelist.inc"; ?>
<? if (!$dont_inc_general) { include Inc("functions_general.inc.php"); } ?>
<? include Inc("functions_images.inc.php"); ?>
<? include Inc("metoo.inc.php"); ?>
<? include Inc("metoo_loc.inc.php"); ?>
<html>
<head><title>MeToo : Middle-Earth Tool for Overcoming Opposition</title></head>
<body>
<center>
<font size=+2><b>Middle-Earth Tool for Overcoming Opposition</b></font><br>
</center>
<hr><br>
<?
	if (!$goingtologin) { include Inc("testlogin.php");	}
	$game_checked=$game;
?>
<? $where="showinfo"; include Inc("checkgameaccess.inc.php"); ?>
<? include Inc("loaddata.inc.php"); ?>
<?
	switch ($asc) {
		case "asc" : $asc="desc"; break;
		case "desc" : $asc="asc"; break;
		default : $asc="asc"; break;
	}
	echo "<table align=center>";	
	switch ($show) {
		case "towns" :
			echo "<tr align=center><td><a href='showinfo.inc.php?game=$game&show=towns&sort=1&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+1][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=towns&sort=2&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+2][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=towns&sort=3&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+3][$lang]."</td>";
			echo "<td><font size=2>".$loc[$loctag[4]+15][$lang]."</td></tr>\n";
			for ($j=1; $j<=$nbtowns; $j++) {
				$comparealphamax="ÿ";
				$comparealphamin="000";
				$comparemax=999999;
				$comparemin=0;
				$k=0;
				for ($i=1; $i<=$nbtowns; $i++) {
					if (!$townsorted_used[$i]) {
						switch ($sort) {
							case "2" : 
								if ($asc=="asc") {
									if ($town[$i]->people<$comparealphamax) { $k=$i; $comparealphamax=$town[$i]->people; }
								} else {
									if ($town[$i]->people>$comparealphamin) { $k=$i; $comparealphamin=$town[$i]->people; }
								}
							break;
							case "3" : 
								if ($asc=="asc") {
									if ($town[$i]->def<$comparemax) { $k=$i; $comparemax=$town[$i]->def; }
								} else {
									if ($town[$i]->def>$comparemin) { $k=$i; $comparemin=$town[$i]->def; }
								}
							break;
							default :
								if ($asc=="asc") {
									if ($town[$i]->name<$comparealphamax) { $k=$i; $comparealphamax=$town[$i]->name; }
								} else {
									if ($town[$i]->name>$comparealphamin) { $k=$i; $comparealphamin=$town[$i]->name; }
								}
							break;
						}
					}
				}
				$townsorted_name[$j]=$town[$k]->name;
				$townsorted_hex[$j]=$town[$k]->hex;
				$townsorted_people[$j]=$town[$k]->people;
				$townsorted_def[$j]=$town[$k]->def;
				$townsorted_used[$k]=true;
			}
			for ($i=1; $i<=$nbtowns; $i++) {
				if (($townsorted_name[$i]!="") && ($townsorted_hex[$i]!=0) && (!is_numeric($townsorted_name[$i]))) {
					echo "<tr><td><b>".$townsorted_name[$i]."</td>";
					echo "<td><font size=1>(".$PeopleName[$townsorted_people[$i]].")</td>";
					echo "<td><font size=1><i>".$townsorted_def[$i]."</td>";
					echo "<td>".$townsorted_hex[$i]."</td></tr>\n";
				}
			}
		break;
		case "heroes" :
			echo "<tr align=center><td><a href='showinfo.inc.php?game=$game&show=heroes&sort=1&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+1][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=heroes&sort=2&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+2][$lang]."</td>";
			echo "<td><font size=2>".$loc[$loctag[4]+15][$lang]."</td></tr>\n";
			for ($j=1; $j<=$nbheroes; $j++) {
				$comparealphamax="ÿ";
				$comparealphamin="000";
				$comparemax=999999;
				$comparemin=0;
				$k=0;
				for ($i=1; $i<=$nbheroes; $i++) {
					if (!$herosorted_used[$i]) {
						switch ($sort) {
							case "2" : 
								if ($asc=="asc") {
									if ($hero[$i]->people<$comparealphamax) { $k=$i; $comparealphamax=$hero[$i]->people; }
								} else {
									if ($hero[$i]->people>$comparealphamin) { $k=$i; $comparealphamin=$hero[$i]->people; }
								}
							break;
							default :
								if ($asc=="asc") {
									if ($hero[$i]->name<$comparealphamax) { $k=$i; $comparealphamax=$hero[$i]->name; }
								} else {
									if ($hero[$i]->name>$comparealphamin) { $k=$i; $comparealphamin=$hero[$i]->name; }
								}
							break;
						}
					}
				}
				$herosorted_name[$j]=$hero[$k]->name;
				$herosorted_hex[$j]=$hero[$k]->hex;
				$herosorted_people[$j]=$hero[$k]->people;
				$herosorted_used[$k]=true;
			}
			for ($i=1; $i<=$nbheroes; $i++) {
				if (($herosorted_name[$i]!="") && ($herosorted_hex[$i]!=0)) {
					echo "<tr><td><b>".$herosorted_name[$i]."</td>";
					echo "<td><font size=1>(".$PeopleName[$herosorted_people[$i]].")</td>";
					echo "<td>".$herosorted_hex[$i]."</td></tr>\n";
				}
			}
		break;
		case "armies" :
			echo "<tr align=center><td><a href='showinfo.inc.php?game=$game&show=armies&sort=1&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+4][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=armies&sort=2&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+2][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=armies&sort=3&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+5][$lang]."</td>";
			echo "<td><a href='showinfo.inc.php?game=$game&show=armies&sort=4&asc=$asc' style='text-decoration:none;color:black;cursor:pointer'><font size=2>".$loc[$loctag[4]+22][$lang]."</td>";
			echo "<td><font size=2>".$loc[$loctag[4]+15][$lang]."</td></tr>\n";
			for ($i=1; $i<=$nbarmies; $i++) {
				CalculateArmyStr($i);
			}
			for ($j=1; $j<=$nbarmies; $j++) {
				$comparealphamax="ÿ";
				$comparealphamin="000";
				$comparemax=999999;
				$comparemin=0;
				$k=0;
				for ($i=1; $i<=$nbarmies; $i++) {
					if (!$armysorted_used[$i]) {
						switch ($sort) {
							case "2" : 
								if ($asc=="asc") {
									if ($army[$i]->people<$comparealphamax) { $k=$i; $comparealphamax=$army[$i]->people; }
								} else {
									if ($army[$i]->people>$comparealphamin) { $k=$i; $comparealphamin=$army[$i]->people; }
								}
							break;
							case "3" : 
								if ($asc=="asc") {
									if ($army[$i]->str_real<$comparemax) { $k=$i; $comparemax=$army[$i]->str_real; }
								} else {
									if ($army[$i]->str_real>$comparemin) { $k=$i; $comparemin=$army[$i]->str_real; }
								}
							break;
							case "4" : 
								if ($asc=="asc") {
									if ($army[$i]->con_final<$comparemax) { $k=$i; $comparemax=$army[$i]->con_final; }
								} else {
									if ($army[$i]->con_final>$comparemin) { $k=$i; $comparemin=$army[$i]->con_final; }
								}
							break;
							default :
								if ($asc=="asc") {
									if ($army[$i]->leadername<$comparealphamax) { $k=$i; $comparealphamax=$army[$i]->leadername; }
								} else {
									if ($army[$i]->leadername>$comparealphamin) { $k=$i; $comparealphamin=$army[$i]->leadername; }
								}
							break;
						}
					}
				}
				$armysorted_name[$j]=$army[$k]->leadername;
				$armysorted_hex[$j]=$army[$k]->hex;
				$armysorted_people[$j]=$army[$k]->people;
				$armysorted_str[$j]=(int)($army[$k]->str_real);
				$armysorted_con[$j]=(int)($army[$k]->con_final);
				$armysorted_used[$k]=true;
			}
			for ($i=1; $i<=$nbarmies; $i++) {
				if (($armysorted_name[$i]!="") && ($armysorted_hex[$i]!=0)) {
					echo "<tr><td><b>".$armysorted_name[$i]."</td>";
					echo "<td><font size=1>(".$PeopleName[$armysorted_people[$i]].")</td>";
					echo "<td><font size=1><i>".$armysorted_str[$i]."</td>";
					echo "<td><font size=1><i>".$armysorted_con[$i]."</td>";
					echo "<td>".$armysorted_hex[$i]."</td></tr>\n";
					echo "</td></tr>\n";
				}
			}
		break;
	}
	echo "</table>";	
?>