<?php
session_start();
require_once 'database/db_config.php';
// Check if user has admin privileges
require_admin_privileges('login.php');
// Get user details
$user_id = $_SESSION['user_id'];
$user = [];
$stmt = $conn->prepare("SELECT id, username, email, first_name, last_name, role, profile_image, bio FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
} else {
$_SESSION['error_message'] = "User not found.";
header('Location: index.php');
exit();
}
// Include header
include 'includes/header.php';
?>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">
<div class="card shadow-sm mb-4">
<div class="card-body text-center">
<div class="mb-3">
<?php
$profile_image = '../assets/img/default-avatar.png';
if (!empty($user['profile_image'])) {
$profile_image = '../' . $user['profile_image'];
}
?>
<img src="<?php echo htmlspecialchars($profile_image); ?>" alt="Profile Image" class="img-fluid rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
</div>
<h3 class="mb-0"><?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?></h3>
<p class="text-muted mb-2"><?php echo get_role_display_name($user['role']); ?></p>
</div>
</div>
<div class="card shadow-sm">
<div class="card-header">
<h5 class="mb-0">Account Information</h5>
</div>
<div class="card-body">
<div class="mb-3">
<label class="text-muted">Username</label>
<p class="mb-0"><?php echo htmlspecialchars($user['username']); ?></p>
</div>
<div class="mb-3">
<label class="text-muted">Email</label>
<p class="mb-0"><?php echo htmlspecialchars($user['email']); ?></p>
</div>
<div>
<label class="text-muted">Role</label>
<p class="mb-0"><?php echo get_role_display_name($user['role']); ?></p>
</div>
</div>
</div>
</div>
<div class="col-lg-8">
<div class="card shadow-sm mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Profile Information</h5>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#editProfileModal">
<i class="fas fa-edit me-1"></i> Edit Profile
</button>
</div>
<div class="card-body">
<?php if (!empty($user['bio'])): ?>
<div class="mb-3">
<label class="text-muted">Bio</label>
<p><?php echo nl2br(htmlspecialchars($user['bio'])); ?></p>
</div>
<?php else: ?>
<div class="alert alert-info">
<i class="fas fa-info-circle me-2"></i> Your profile bio is empty. Click on "Edit Profile" to add information about yourself.
</div>
<?php endif; ?>
</div>
</div>
<div class="card shadow-sm">
<div class="card-header">
<h5 class="mb-0">Password & Security</h5>
</div>
<div class="card-body">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6 class="mb-1">Change Password</h6>
<p class="text-muted mb-0 small">It's a good idea to use a strong password that you don't use elsewhere</p>
</div>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#changePasswordModal">
<i class="fas fa-key me-1"></i> Update
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Edit Profile Modal -->
<div class="modal fade" id="editProfileModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Profile</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="update_profile.php" method="post" enctype="multipart/form-data">
<div class="modal-body">
<div class="mb-3">
<label for="first_name" class="form-label">First Name</label>
<input type="text" class="form-control" id="first_name" name="first_name" value="<?php echo htmlspecialchars($user['first_name']); ?>" required>
</div>
<div class="mb-3">
<label for="last_name" class="form-label">Last Name</label>
<input type="text" class="form-control" id="last_name" name="last_name" value="<?php echo htmlspecialchars($user['last_name']); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($user['email']); ?>" required>
</div>
<div class="mb-3">
<label for="bio" class="form-label">Bio</label>
<textarea class="form-control" id="bio" name="bio" rows="4"><?php echo htmlspecialchars($user['bio'] ?? ''); ?></textarea>
</div>
<div class="mb-3">
<label for="profile_image" class="form-label">Profile Image</label>
<input type="file" class="form-control" id="profile_image" name="profile_image">
<small class="form-text text-muted">Leave empty to keep current image</small>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- Change Password Modal -->
<div class="modal fade" id="changePasswordModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Change Password</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="update_password.php" method="post">
<div class="modal-body">
<div class="mb-3">
<label for="current_password" class="form-label">Current Password</label>
<input type="password" class="form-control" id="current_password" name="current_password" required>
</div>
<div class="mb-3">
<label for="new_password" class="form-label">New Password</label>
<input type="password" class="form-control" id="new_password" name="new_password" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm New Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Update Password</button>
</div>
</form>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>