Sindbad~EG File Manager
<?php
require_once '../config/config.php';
// Check if user is logged in and has admin privileges
if (!isLoggedIn() || (!hasRole('admin') && !hasRole('superuser'))) {
redirect('login.php');
}
$db = new Database();
$conn = $db->getConnection();
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
// Check if officer_type column already exists
$check_query = "SHOW COLUMNS FROM attendance_records LIKE 'officer_type'";
$stmt = $conn->prepare($check_query);
$stmt->execute();
$column_exists = $stmt->rowCount() > 0;
if ($column_exists) {
$error_message = 'Officer type field already exists in the database.';
} else {
// Add officer_type column
$alter_query = "ALTER TABLE attendance_records
ADD COLUMN officer_type VARCHAR(50) NULL
AFTER assembly_id";
$conn->exec($alter_query);
// Add index for officer_type
$index_query = "ALTER TABLE attendance_records
ADD INDEX idx_officer_type (officer_type)";
$conn->exec($index_query);
$success_message = 'Officer type field has been successfully added to the database!';
// Log activity
logActivity($_SESSION['user_id'], 'database_migration', 'Added officer_type field to attendance_records table');
}
} catch (Exception $e) {
$error_message = 'Error adding officer type field: ' . $e->getMessage();
}
}
// Check current status
$column_exists = false;
try {
$check_query = "SHOW COLUMNS FROM attendance_records LIKE 'officer_type'";
$stmt = $conn->prepare($check_query);
$stmt->execute();
$column_exists = $stmt->rowCount() > 0;
} catch (Exception $e) {
// Error checking
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Officer Type Field - Admin Panel</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<div class="flex h-screen">
<!-- Sidebar -->
<?php include 'includes/sidebar.php'; ?>
<!-- Main Content -->
<div class="flex-1 flex flex-col overflow-hidden">
<!-- Header -->
<header class="bg-white shadow-sm border-b border-gray-200">
<div class="max-w-7xl mx-auto py-4 px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between">
<h1 class="text-2xl font-bold text-gray-900">
<i class="fas fa-database mr-2 text-blue-600"></i>Add Officer Type Field
</h1>
<a href="attendance.php" class="text-blue-600 hover:text-blue-800">
<i class="fas fa-arrow-right mr-1"></i>Go to Attendance
</a>
</div>
</div>
</header>
<!-- Main Content Area -->
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-100 p-6">
<div class="max-w-4xl mx-auto">
<!-- Success/Error Messages -->
<?php if ($success_message): ?>
<div class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg mb-6">
<i class="fas fa-check-circle mr-2"></i>
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg mb-6">
<i class="fas fa-exclamation-triangle mr-2"></i>
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<!-- Migration Status -->
<div class="bg-white rounded-lg shadow-lg p-6 mb-8">
<h2 class="text-xl font-semibold text-gray-900 mb-4">
<i class="fas fa-info-circle mr-2 text-blue-600"></i>Migration Status
</h2>
<div class="space-y-4">
<div class="flex items-center">
<?php if ($column_exists): ?>
<i class="fas fa-check-circle text-green-600 text-xl mr-3"></i>
<span class="text-green-700 font-medium">Officer type field exists in database</span>
<?php else: ?>
<i class="fas fa-times-circle text-red-600 text-xl mr-3"></i>
<span class="text-red-700 font-medium">Officer type field not found in database</span>
<?php endif; ?>
</div>
</div>
</div>
<?php if (!$column_exists): ?>
<!-- Migration Form -->
<div class="bg-white rounded-lg shadow-lg p-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">
<i class="fas fa-play-circle mr-2 text-green-600"></i>Add Officer Type Field
</h2>
<div class="mb-6">
<p class="text-gray-600 mb-4">
This will add the officer_type field to the attendance_records table to store officer type information.
</p>
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
<h3 class="font-semibold text-blue-900 mb-2">What will be added:</h3>
<ul class="text-blue-800 space-y-1">
<li><i class="fas fa-check mr-2"></i>officer_type VARCHAR(50) NULL column</li>
<li><i class="fas fa-check mr-2"></i>Database index for performance</li>
<li><i class="fas fa-check mr-2"></i>Support for officer types: Deacon, Deaconess, Elder, Pastor, Apostle, Prophet, Evangelist, Other</li>
</ul>
</div>
</div>
<form method="POST">
<button type="submit" class="bg-green-600 text-white py-3 px-6 rounded-lg hover:bg-green-700 transition duration-300 font-semibold">
<i class="fas fa-plus mr-2"></i>Add Officer Type Field
</button>
</form>
</div>
<?php else: ?>
<!-- Already Added -->
<div class="bg-white rounded-lg shadow-lg p-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">
<i class="fas fa-check-circle mr-2 text-green-600"></i>Field Already Added
</h2>
<p class="text-gray-600 mb-6">
The officer_type field has already been added to the database and is ready to use.
</p>
<div class="flex space-x-4">
<a href="attendance.php" class="bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700 transition duration-300">
<i class="fas fa-users mr-2"></i>View Attendance Records
</a>
<a href="../attendance/form.php?program=1" class="bg-green-600 text-white py-2 px-4 rounded-lg hover:bg-green-700 transition duration-300">
<i class="fas fa-edit mr-2"></i>Test Attendance Form
</a>
</div>
</div>
<?php endif; ?>
<!-- Officer Types Information -->
<div class="mt-8 bg-gray-50 border border-gray-200 rounded-lg p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-3">
<i class="fas fa-list mr-2"></i>Supported Officer Types
</h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-gray-700">
<div class="flex items-center">
<i class="fas fa-user text-blue-600 mr-2"></i>
<span>Deacon</span>
</div>
<div class="flex items-center">
<i class="fas fa-user text-pink-600 mr-2"></i>
<span>Deaconess</span>
</div>
<div class="flex items-center">
<i class="fas fa-user-tie text-purple-600 mr-2"></i>
<span>Elder</span>
</div>
<div class="flex items-center">
<i class="fas fa-cross text-green-600 mr-2"></i>
<span>Pastor</span>
</div>
<div class="flex items-center">
<i class="fas fa-crown text-yellow-600 mr-2"></i>
<span>Apostle</span>
</div>
<div class="flex items-center">
<i class="fas fa-eye text-indigo-600 mr-2"></i>
<span>Prophet</span>
</div>
<div class="flex items-center">
<i class="fas fa-bullhorn text-orange-600 mr-2"></i>
<span>Evangelist</span>
</div>
<div class="flex items-center">
<i class="fas fa-ellipsis-h text-gray-600 mr-2"></i>
<span>Other</span>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists