Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add functionality for the admin page #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ styles.css – Main stylesheet for the website.
admin.css – Styles specific to the admin panel.

### Note
- This is super beautiful, Kudos!!!!!!
- Thank you sir
Admin Credencial
-admin123@gmail.com
-password123
34 changes: 34 additions & 0 deletions admin/admin_sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// Check if admin is logged in
if (!isset($_SESSION['admin'])) {
header("Location: ../index.php");
exit;
}
?>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="dashboard.php">Admin Panel</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="manage_users.php">Manage Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="manage_policies.php">Manage Policies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="manage_claims.php">Manage Claims</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
119 changes: 119 additions & 0 deletions admin/dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
session_start();
include '../config/config.php';

// Check if the user is logged in as an admin
if (!isset($_SESSION['admin_id'])) {
header("Location: login.php"); // Redirect to login if not logged in
exit();
}

// Fetching counts for dashboard
$users_count = $conn->query("SELECT COUNT(*) FROM users")->fetch_row()[0];
$policies_count = $conn->query("SELECT COUNT(*) FROM policies")->fetch_row()[0];
$claims_count = $conn->query("SELECT COUNT(*) FROM claims")->fetch_row()[0];
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
}
.sidebar {
background-color: #343a40;
color: white;
width: 220px;
height: 100vh;
position: fixed;
padding-top: 20px;
padding-left: 10px;
}
.sidebar a {
color: white;
text-decoration: none;
display: block;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
}
.sidebar a:hover {
background-color: #007bff;
}
.main-content {
margin-left: 240px;
padding: 20px;
}
.card {
display: inline-block;
width: 200px;
padding: 20px;
margin: 10px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
.card h3 {
margin: 0;
}
.card p {
color: #888;
}
.card:hover {
background-color: #f7f7f7;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 20px;
}
.header h1 {
margin: 0;
}
.header a {
color: #007bff;
text-decoration: none;
font-size: 16px;
}
</style>
</head>
<body>
<div class="sidebar">
<h2 style="color: white; text-align: center;">Admin Panel</h2>

<a href="manage_policies.php">Manage Policies</a>
<a href="manage_users.php">Manage Users</a>
<a href="manage_claims.php">Manage Claims</a>
<a href="logout.php">Logout</a>
</div>
<div class="main-content">
<div class="header">
<h1>Admin Dashboard</h1>
<a href="logout.php">Logout</a>
</div>
<div>
<div class="card">
<h3><?= $users_count ?></h3>
<p>Total Users</p>
</div>
<div class="card">
<h3><?= $policies_count ?></h3>
<p>Total Policies</p>
</div>
<div class="card">
<h3><?= $claims_count ?></h3>
<p>Total Claims</p>
</div>
</div>
</div>
</body>
</html>
111 changes: 111 additions & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
session_start();
include '../config/config.php';

$error = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = $_POST['email'];
$password = md5($_POST['password']); // Hash the password as stored in the database

$stmt = $conn->prepare("SELECT id, name, role FROM users WHERE email = ? AND password = ? AND role = 'admin'");
$stmt->bind_param("ss", $email, $password);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
$admin = $result->fetch_assoc();
$_SESSION['admin_id'] = $admin['id'];
$_SESSION['admin_name'] = $admin['name'];
$_SESSION['admin_role'] = $admin['role'];
header("Location: dashboard.php");
exit();
} else {
$error = "Invalid email, password, or you don't have admin access.";
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}
.login-container h1 {
text-align: center;
margin-bottom: 20px;
color: #333333;
}
.login-container label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555555;
}
.login-container input {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #cccccc;
border-radius: 4px;
font-size: 14px;
}
.login-container button {
width: 100%;
padding: 10px;
background-color:rgb(53, 58, 64);
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}
.login-container button:hover {
background-color:rgb(51, 56, 60);
}
.error-message {
color: red;
text-align: center;
font-size: 14px;
margin-top: -10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="login-container">
<h1>Admin Login</h1>
<form method="POST" action="">
<label for="email">Email:</label>
<input type="email" name="email" required>

<label for="password">Password:</label>
<input type="password" name="password" required>

<button type="submit">Login</button>
</form>
<?php if ($error): ?>
<p class="error-message"><?= $error ?></p>
<?php endif; ?>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions admin/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
exit();
?>
73 changes: 73 additions & 0 deletions admin/manage_claims.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
session_start();
require '../config/config.php';

// Approve claim
if (isset($_GET['approve'])) {
$claim_id = $_GET['approve'];
$sql = "UPDATE claims SET status = 'approved' WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $claim_id);
$stmt->execute();
}

// Reject claim
if (isset($_GET['reject'])) {
$claim_id = $_GET['reject'];
$sql = "UPDATE claims SET status = 'rejected' WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $claim_id);
$stmt->execute();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Claims</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
</head>
<body>

<div class="container py-5">
<h2>Manage Claims</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Claim ID</th>
<th>User</th>
<th>Policy</th>
<th>Description</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$result = $conn->query("SELECT claims.id, users.name AS user_name, policies.name AS policy_name, claims.description, claims.status
FROM claims
JOIN users ON claims.user_id = users.id
JOIN policies ON claims.policy_id = policies.id");

while ($claim = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>{$claim['id']}</td>";
echo "<td>{$claim['user_name']}</td>";
echo "<td>{$claim['policy_name']}</td>";
echo "<td>{$claim['description']}</td>";
echo "<td>{$claim['status']}</td>";
echo '<td>
<a href="manage_claims.php?approve=' . $claim['id'] . '" class="btn btn-success btn-sm">Approve</a>
<a href="manage_claims.php?reject=' . $claim['id'] . '" class="btn btn-danger btn-sm">Reject</a>
</td>';
echo "</tr>";
}
?>
</tbody>
</table>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Loading