The following files exists in this folder. Click to view.
admin.php68 lines UTF-8 Unix (LF) 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
<?php
require_once("check_login.php");
require_once("database_connection.php");
# shorthanded if som tar hand om meddelandet
$mess=isset($_GET['mess']) ? "<p class='text-error'>".$_GET['mess']."</p>" : "";
# Gör anropet till databasen
$sql = "SELECT * FROM user ORDER BY userId;";
$stm = $pdo->prepare($sql);
$stm->execute();
# fetchAll() eftersom vi kan få fleraposter
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
# $table lagrar hela tabellen som byggs upp
$table = "\n<table class='table table-striped table-hover'>";
$table .= "\n <thead>\n <tr>\n <th>userId</th>\n <th>username</th>
\n <th>password</th>\n <th>händelse</th>\n </tr>\n </thead>\n <tbody>";
# Loopa genom resultatet
foreach($res as $row){ # Bygger upp rad för rad
$table .= "\n <tr>";
$table .= "\n <td>".$row['userId']."</td>";
$table .= "\n <td>".$row['username']."</td>";
$table .= "\n <td>".$row['password']."</td>";
if($row['active'] == 1){
$active = "[<a href='change_active_user.php?userId=".$row['userId']."'
class='text-success'>aktiv</a>]";
} else {
$active = "[<a href='change_active_user.php?userId=".$row['userId']."'
class='text-error'>inaktiv</a>]";
}
$table .= "\n <td>[<a href='delete_user.php?userId=".$row['userId']."'>ta bort</a>]
[<a href='edit_user.php?userId=".$row['userId']."'>ändra</a>]
$active</td>";
$table .= "\n </tr>";
}
$table .= "\n </tbody>\n</table>";
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie-edge">
<title>Inloggnignsapplikation</title>
<link rel="stylesheet"
href ="https://unpkg.com/spectre.css/dist/spectre.min.css">
</head>
<body>
<div class="container">
<div class="columns">
<div class="column col-6">
<h1>Admin</h1>
<?php echo $mess; ?>
<p>Du är inloggad som <?php echo $_SESSION['username'];?></p>
<p><a href="logout.php">Logga ut</a></p>
<h2>Användare</h2>
<p><a href="add_user.php">Lägg till ny användare</a></p>
<?php echo $table; ?>
</div>
</div>
</div>
</body>
</html>