<?php
  include('global.php');
  ShowHeader();

  echo('<h3>Online hráči:</h3><div align="center">');
  $Database->select_db($Config['Mangos']['DatabaseCharacters']);

	$order_by = (isset($_GET['order_by'])) ? $Database->real_escape_string($_GET['order_by']) : "name";

	$dir = (isset($_GET['dir'])) ? $Database->real_escape_string($_GET['dir']) : 1;
	$order_dir = ($dir) ? "ASC" : "DESC";
	$dir = ($dir) ? 0 : 1;
	
	$result = $Database->query("SELECT count(*) FROM `characters` WHERE `online`= 1");
	$Row = $result->fetch_array();
	$total_online = $Row[0];

	$order_side = "";  
	
	require_once("minimanager/scripts/defines.php");
	$result = $Database->query("SELECT guid, name, race, class, zone, map, CAST( SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', ".(CHAR_DATA_OFFSET_HONOR_POINTS+1)."), ' ', -1) AS UNSIGNED) AS highest_rank, CAST( SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', ".(CHAR_DATA_OFFSET_LEVEL+1)."), ' ', -1) AS UNSIGNED) AS level,account FROM `characters` WHERE `online`= 1 $order_side ORDER BY $order_by $order_dir");

	require_once("minimanager/lang/english.php");
  $lang_index = array(
	// ----- INDEX.PHP -----
	'realm' => 'Realm',
	'online' => 'Online',
	'offline_or_let_height' => 'Offline or Latency too Height',
	'delete' => 'Delete',
	'tot_users_online' => 'Celkem hráčů online',
	'name' => 'Jméno',
	'race' => 'Rasa',
	'class' => 'Třída',
	'level' => 'Úroveň',
	'map' => 'Mapa',
	'zone' => 'Zóna',
	'honor_kills' => 'Body cti',
  );
	
	$output = "<font class=\"bold\">{$lang_index['tot_users_online']}: $total_online</font><br />
	<table class=\"TableGuilda\" border=\"1\" cellspacing=\"0\">
	<tr> 
	<th width=\"26%\"><a href=\"?order_by=name&amp;dir=$dir\">".($order_by=='name' ? "<img src=\"images/online_player/arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['name']}</a></th>
	<th width=\"7%\"><a href=\"?order_by=race&amp;dir=$dir\">".($order_by=='race' ? "<img src=\"images/online_player/arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['race']}</a></th>
	<th width=\"7%\"><a href=\"?order_by=class&amp;dir=$dir\">".($order_by=='class' ? "<img src=\"images/online_player/arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['class']}</a></th>
	<th width=\"7%\"><a href=\"?order_by=level&amp;dir=$dir\">".($order_by=='level' ? "<img src=\"images/online_player/arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['level']}</a></th>
	<th width=\"20%\"><a href=\"?order_by=map&amp;dir=$dir\">".($order_by=='map' ? "<img src=\"images/online_player/arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['map']}</a></th>
	<th width=\"25%\">{$lang_index['zone']}</th>
    <th width=\"10%\"><a href=\"?order_by=highest_rank&amp;dir=$dir\">".($order_by=='highest_rank' ? "<img src=\"images/online_player//arr_".($dir ? "up" : "dw").".gif\" /> " : "")."{$lang_index['honor_kills']}</a></th>
	</tr>";

	require_once("minimanager/scripts/id_tab.php");

	while($char = $result->fetch_row())
  {
    $zone = get_zone_name($char[4]);
    if($zone == ' ') $zone = '&nbsp;';
    $race = get_player_race($char[2]);
    if(($char[2] == 1) or ($char[2] == 3) or ($char[2] == 4) or ($char[2] == 7) or ($char[2] == 11)) $color = '#9090ff'; 
    else $color = '#FF5050';
$output .= "<tr>
 <td style=\"color: ".$color.";\">$char[1]</td>
         <td><img src='images/online_player/{$char[2]}-0.gif' onmousemove='toolTip(\"".$race."\",\"item_tooltip\")' onmouseout='toolTip()' /></td>
	<td><img src='images/online_player/{$char[3]}.gif' onmousemove='toolTip(\"".get_player_class($char[3])."\",\"item_tooltip\")' onmouseout='toolTip()' /></td>
	<td>$char[7]</td>
	<td>".get_map_name($char[5])."</td>
	<td>".$zone."</td>
	<td>$char[6]</td>
        </tr>";
}
   $output .= "</table></div>";
  echo($output);

  ShowFooter();
?>
