if ($debug == "1") {
    error_reporting(E_ALL);
}
// Quick login
if (!empty($_POST['steamid'])) {
    $_SESSION['steamlogin'] = $_POST['steamid'];
}
if (isset($_SESSION['steamlogin'])) {
    $steam_login_verify = $_SESSION['steamlogin'];
} else {
    $steam_login_verify = SteamSignIn::validate();
}
if (!empty($steam_login_verify)) {
    //echo "success + $steam_login_verify <br>";
    $_SESSION['steamlogin'] = $steam_login_verify;
    $_SESSION['steamname'] = steamid64convert($steam_login_verify);
    // Get Players Characters
    $con = mysql_connect($address, $user, $pass);
    if (!$con) {
        echo '<div class="alert alert-error">' . mysql_error() . '. Please tell the owner.</div>';
    }
    mysql_select_db($database, $con);
    $query = "SELECT DISTINCT _Name FROM characters WHERE _SteamID =  '" . $_SESSION["steamname"] . "' AND (_Faction = 'Metropolice Force' OR _Faction = 'Overwatch Transhuman Arm')";
    $rows = mysql_query($query);
    print "\n\n<form action='dash.php' method='post'>\n<div class='row'>\n  <div class='col-lg-3'>\n       <big>Login as:</big>\n       </div>\n       <div class='col-lg-8'>\n\n";
    //Get a row
    while ($row = MySQL_Fetch_array($rows)) {
        //get a feild
        for ($i = 0; $i < count($row); $i++) {
            //Grab an element in the array
            $array = next($row);
}
if (empty($_POST['faction']) && empty($_POST['name'])) {
    $result = mysql_query("SELECT * FROM  `characters` WHERE `_Schema` = '" . $gamemodecode . "' AND `_SteamID` LIKE  '" . $steamid . "'");
}
if (!empty($_POST['faction']) && !empty($_POST['name']) && empty($_POST['steamid'])) {
    $result = mysql_query("SELECT * FROM  `characters` WHERE `_Schema` = '" . $gamemodecode . "' AND `_SteamName` LIKE  '%" . $name . "%' AND `_Faction` LIKE  '%" . $faction . "%'");
}
if (mysql_error() == "") {
    echo '<div class="alert alert-success">Successfully Queried</div>';
} else {
    echo '<div class="alert alert-success"> ERROR' . mysql_error() . '</div>';
}
echo "\n<center>\n<table class='table table-striped'>\n<h1>All Characters</h1>\n<tr>\n<th>Name</th>\n<th>Faction</th>\n<th>Owner</th>\n<th>Last Played</th>";
if (!empty($steam_login_verify)) {
    $usersteamid = $steam_login_verify;
    $convertedsteamid = steamid64convert($usersteamid);
    if (issuperadmin($convertedsteamid) == "1") {
        echo '<th>Actions</th>';
    }
}
echo '
</tr>
</center>';
while ($row = @mysql_fetch_array($result)) {
    $lastplayed = $row['_LastPlayed'];
    $steam = $row['_SteamID'];
    $parsed = SteamID2CommunityID($steam);
    echo "<tr>";
    echo "<td>" . $row['_Name'] . "</td>";
    echo "<td>" . $row['_Faction'] . "</td>";
    echo "<td><a href='http://steamcommunity.com/profiles/{$parsed}'>" . $row['_SteamName'] . "</a></td>";
    //echo "success + $steam_login_verify <br>";
    $_SESSION['steamlogin'] = $steam_login_verify;
    $_SESSION['steamname'] = steamid64convert($steam_login_verify);
    // Lets get player information since we have the SteamID now.
    $xml = simplexml_load_file('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $apikey . '&steamids=' . $_SESSION['steamlogin'] . '&format=xml');
    // Set the session variable
    $steampersona = $xml->players->player->personaname;
    $hi = array('Hey', 'Hi', 'Howdy', 'Aloha', 'Bonjour', 'Shalom', 'What\'s up', 'Good day');
    echo '
<div class="btn-group">
                <button class="btn dropdown-toggle btn-info" data-toggle="dropdown"><b>' . $hi[array_rand($hi)] . ' ' . $steampersona . ' </b><span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><center>My Options</center></li>
                  <li><a href="mycharacters.php"><i class="icon-user"></i> My Characters</a></li>
                  <li><a href="myinfo.php"><i class="icon-info-sign"></i> My Information</a></li>';
    $convertedsteamid = steamid64convert($steam_login_verify);
    if (issuperadmin($convertedsteamid) == "1") {
        echo '
<li class="divider"></li>
<li><center>Admin Options</center></li>
<li><a href="players.php"><i class="icon-user"></i><b>Players</b></a></li>
';
    }
    echo '
                  <li class="divider"></li>
                  <li><a href="logout.php"><i class="icon-off"></i><b> Logout</b></a></li>
                </ul>
              </div>
  ';
} else {
    $steam_sign_in_url = SteamSignIn::genUrl();