<head>
  <title>Cheaterliste</title>
  <link href="style.css?v=1.0.1" rel="stylesheet" type="text/css">
  <script src="jquery-3.2.1.min.js"></script>
</head>

  <body>
    <div class="bild">
      <img src="schriftv2.png" class="cliff_logo">
    </div>
    <div class="key_login">
      <img src="lock.png" class="key" id="login_run">
    </div>


<?php
session_start();

$vac = "vac";
$host = "localhost";
$user = "vac";
$password = "hPUf8e4karnz61bS";

$conn = new mysqli($host,$user,$password,$vac);
if($conn->connect_error){
    die("Verbindung fehlgeschlagen: " . $conn->connect_error);
}
?>

<table  style="width:50%" class="center">
  <tr>
    <th style="padding: 0.5em 0.5em">Eintrag</th>
    <th style="padding: 0.4em">Avatar</th>
    <th class="profil">Steam-Profil</th>
    <th style="padding: 0.4em">Ersteller</th>
    <th style="padding: 0.4em" class="Zeit">Erstelldatum</th>
    <th style="padding: 0.4em">VAC-Ban</th>
  </tr>

<?php
$sql = "SELECT * FROM cheaterlist ORDER BY addtime DESC;";
$result = $conn->query($sql);
$number = 1;
$getplayersummarie ="http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E8D51260E5DF95AE8A6DA139D6C80288&steamids=";
$getplayerbans = "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=E8D51260E5DF95AE8A6DA139D6C80288&steamids=";
$avatarid = 0;
$fullids = "";
$counter = 0;
$counter2 = 0;

?>

<?php

while ($row = $result->fetch_assoc()) {
  if($row['deleted'])
    continue;

    $id = explode( "/", $row['url']);

    $fullids = $fullids . end($id) . ",";
$counter++;

}

mysqli_data_seek($result, 0);

$fullcallurl_summarie = $getplayersummarie . $fullids;
$fullcallurl_bans = $getplayerbans . $fullids;


$summarie = file_get_contents($fullcallurl_summarie);
$temp_summarie = json_decode($summarie, true);

$bans = file_get_contents($fullcallurl_bans);
$temp_bans = json_decode($bans, true);



/*ID PICTURE SORT by ALPHA*/
/*BAN Sorter*/

$pattern = explode( ",", $fullids);


while ($counter2 < $counter) {
$avaid = $temp_summarie["response"]["players"][$avatarid]["avatarmedium"];
$userid = $temp_summarie["response"]["players"][$avatarid]["steamid"];
$userid_bans = $temp_bans["players"][$avatarid]["SteamId"];

$visi = $temp_summarie["response"]["players"][$avatarid]["communityvisibilitystate"];
$personname = $temp_summarie["response"]["players"][$avatarid]["personaname"];


$sort["$userid"] = $avaid;
$sort_name["$userid"] = $personname;



if($visi > 1){

  $gameban_output = $temp_bans["players"][$avatarid]["NumberOfGameBans"];
  $vacban_output = $temp_bans["players"][$avatarid]["NumberOfVACBans"];
}
else{
  $gameban_output = 0;
  $vacban_output = 0;
}

$sort_bans["$userid_bans"]["gameban"] = $gameban_output;
$sort_bans["$userid_bans"]["vacban"] = $vacban_output;



$avatarid++;
$counter2++;
}

?>
<?php

while($row = $result->fetch_assoc()){
  if($row['deleted'])
    continue;

        $id = explode( "/", $row['url']);
        $ida = end($id);

        $avatarurl = $sort["$ida"];
        $person = $sort_name["$ida"];

        $gamebancheck = $sort_bans["$ida"]["gameban"];
        $vacbancheck = $sort_bans["$ida"]["vacban"];



    $output = "<tr>
            <td>".$number."</td>
            <td><a href=".$row['url']."><img src=$avatarurl></a></td>
            <td class='profil'><a target ='_blank'href='".$row['url']."'>".$person."</td>
            <td>".$row['author']."</td>
            <td>".$row['addtime']."</td>";
    if($gamebancheck || $vacbancheck > 0){
          $output .= "<td><img src='haken.png' height='20' width='20'</td>
          </tr>";
    }else{
      $output .= "<td></td>
      </tr>";
    }
    echo $output;
    $number++;

  }
?>
</table><br>


    <div id="login_modal" class="m_login">
        <div class="m_login_c">


          <span class="close">&times;</span>

          <script>
                var modal1 = document.getElementById("login_modal");
          var btn1 = document.getElementById("login_run");
          var span1 = document.getElementsByClassName("close")[0];
          btn1.onclick = function() {
              modal1.style.display = "block";
          }
          span1.onclick = function() {
              modal1.style.display = "none";
          }
          window.onclick = function(event) {
              if (event.target == modal1) {
                  modal1.style.display = "none";
              }
          }
          </script>




          <?php



          if (!isset ($_SESSION['id'])){
            echo    '<div class="loginform" id ="log">'.

            '<form action="/login.php" method="post">' .
              '<input type="text" placeholder="Username" name="user">' .
              '<input type="password" placeholder="Password" name="pw">' .
              '<input type="submit" value="Login" id="login_run">' .
            '</form>' .


                      '</div>';
                      if (isset ($_SESSION['status'])){
                        echo $_SESSION['status'];

                      }

                      return;
            }
              ?>
            }
 <?php
            echo    '<div class="loginform">' .
                      '<form action="/logout.php" method="post">' .
                          '<input type="submit" value="Logout">' .
                      '</form>' .
                      "<style> .key_login{ background: rgba(72, 121, 44, 0.7);
                        }
                        </style>".

                   '</div>';
 ?>

           </div>
         </div>

             <?php

            echo    '<div class="loginform_login">' .
                      '<form action="/insert.php" method="post">' .
                        '<input type="url" pattern="https?://.+" required placeholder="Link" name="url"><br>' .
                        '<input type="submit" value="Hinzufügen">' .
                      '</form>' .
            			 '</div>';


           ?>


</body>
