Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/install_new_modules.php

<?php
/**
 * Installation Script for New Modules
 * - Programs Module
 * - Ministries & Groups Module
 * - Ministry Executives Module
 */

require_once 'config/config.php';
checkLogin();

// Only superuser can run installation
if (!isSuperuser()) {
    die("Only superuser can run this installation script.");
}

$db = Database::getInstance()->getConnection();
$messages = [];
$errors = [];

// Execute SQL file
function executeSQLFile($db, $filePath) {
    $sql = file_get_contents($filePath);
    if ($sql === false) {
        return false;
    }
    
    try {
        // Split by semicolon but respect strings
        $statements = array_filter(array_map('trim', explode(';', $sql)));
        foreach ($statements as $statement) {
            if (!empty($statement)) {
                $db->exec($statement);
            }
        }
        return true;
    } catch (PDOException $e) {
        throw $e;
    }
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['install'])) {
    try {
        // Install Programs Module
        echo "<h3>Installing Programs Module...</h3>";
        flush();
        executeSQLFile($db, 'sql/programs_module.sql');
        $messages[] = "✓ Programs Module tables created successfully";
        
        // Install Ministries Module
        echo "<h3>Installing Ministries & Groups Module...</h3>";
        flush();
        executeSQLFile($db, 'sql/ministries_module.sql');
        $messages[] = "✓ Ministries & Groups Module tables created successfully";
        
        // Install Ministry Executives Module
        echo "<h3>Installing Ministry Executives Module...</h3>";
        flush();
        executeSQLFile($db, 'sql/ministry_executives.sql');
        $messages[] = "✓ Ministry Executives Module tables created successfully";
        
        // Register modules in module_management
        $modules = [
            ['Programs', 'Manage church programs and schedules', 'calendar-alt', 'modules/programs/index.php', 100, 'viewer'],
            ['Program Attendance', 'Track program attendance', 'clipboard-check', 'modules/programs/attendance.php', 101, 'viewer'],
            ['Ministries & Groups', 'Manage ministries, groups and interventions', 'hands-helping', 'modules/ministries/index.php', 110, 'viewer'],
            ['Ministry Executives', 'Manage ministry leadership positions', 'user-tie', 'modules/ministries/executives.php', 111, 'viewer']
        ];
        
        $stmt = $db->prepare("
            INSERT INTO module_management (module_name, module_description, module_icon, module_url, display_order, required_role, is_active)
            VALUES (:name, :desc, :icon, :url, :order, :role, 1)
            ON DUPLICATE KEY UPDATE 
                module_description = VALUES(module_description), 
                module_icon = VALUES(module_icon), 
                module_url = VALUES(module_url), 
                display_order = VALUES(display_order)
        ");
        
        foreach ($modules as $module) {
            $stmt->execute([
                'name' => $module[0],
                'desc' => $module[1],
                'icon' => $module[2],
                'url' => $module[3],
                'order' => $module[4],
                'role' => $module[5]
            ]);
        }
        $messages[] = "✓ Modules registered in module management";
        
        // Create module directories
        $dirs = [
            'modules/programs',
            'modules/ministries'
        ];
        
        foreach ($dirs as $dir) {
            if (!is_dir($dir)) {
                mkdir($dir, 0755, true);
                $messages[] = "✓ Created directory: $dir";
            }
        }
        
        $messages[] = "<strong>✓✓✓ All modules installed successfully!</strong>";
        
    } catch (Exception $e) {
        $errors[] = "Error during installation: " . $e->getMessage();
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Install New Modules - <?php echo APP_NAME; ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-gray-50">
    <div class="container mx-auto px-4 py-8 max-w-4xl">
        <div class="bg-white rounded-xl shadow-lg p-8">
            <h1 class="text-3xl font-bold text-gray-800 mb-6">
                <i class="fas fa-download mr-2 text-blue-500"></i>
                Install New Modules
            </h1>
            
            <?php if (!empty($messages)): ?>
                <div class="bg-green-50 border border-green-200 rounded-lg p-4 mb-6">
                    <h3 class="font-semibold text-green-800 mb-2">
                        <i class="fas fa-check-circle mr-2"></i>Installation Messages
                    </h3>
                    <ul class="space-y-1">
                        <?php foreach ($messages as $msg): ?>
                            <li class="text-green-700"><?php echo $msg; ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>
            
            <?php if (!empty($errors)): ?>
                <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
                    <h3 class="font-semibold text-red-800 mb-2">
                        <i class="fas fa-exclamation-circle mr-2"></i>Errors
                    </h3>
                    <ul class="space-y-1">
                        <?php foreach ($errors as $err): ?>
                            <li class="text-red-700"><?php echo $err; ?></li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>
            
            <div class="mb-8">
                <h2 class="text-xl font-semibold text-gray-800 mb-4">Modules to be Installed:</h2>
                <div class="space-y-4">
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h3 class="font-semibold text-blue-600 flex items-center">
                            <i class="fas fa-calendar-alt mr-2"></i>Programs Module
                        </h3>
                        <p class="text-gray-600 text-sm mt-2">Manage church programs with calendar view, recurring schedules, and attendance tracking</p>
                        <ul class="text-sm text-gray-500 mt-2 space-y-1">
                            <li>• Daily, weekly, monthly, and yearly programs</li>
                            <li>• Calendar view with schedule management</li>
                            <li>• Real-time attendance tracking</li>
                            <li>• Program instances for recurring events</li>
                        </ul>
                    </div>
                    
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h3 class="font-semibold text-green-600 flex items-center">
                            <i class="fas fa-hands-helping mr-2"></i>Ministries & Groups Module
                        </h3>
                        <p class="text-gray-600 text-sm mt-2">Organize ministries, groups, and interventions with categories</p>
                        <ul class="text-sm text-gray-500 mt-2 space-y-1">
                            <li>• Ministry categories and types</li>
                            <li>• Member assignments to ministries</li>
                            <li>• Position management</li>
                            <li>• Assembly-based organization</li>
                        </ul>
                    </div>
                    
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h3 class="font-semibold text-purple-600 flex items-center">
                            <i class="fas fa-user-tie mr-2"></i>Ministry Executives Module
                        </h3>
                        <p class="text-gray-600 text-sm mt-2">Track ministry leadership positions and executive history</p>
                        <ul class="text-sm text-gray-500 mt-2 space-y-1">
                            <li>• Executive position assignments</li>
                            <li>• Historical tracking of leadership changes</li>
                            <li>• Achievement and report management</li>
                            <li>• Term tracking and transitions</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <?php if (empty($messages)): ?>
                <form method="POST">
                    <div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-6">
                        <h4 class="font-semibold text-yellow-800 mb-2">
                            <i class="fas fa-exclamation-triangle mr-2"></i>Before Installing
                        </h4>
                        <ul class="text-sm text-yellow-700 space-y-1">
                            <li>• Make sure you have a database backup</li>
                            <li>• Ensure you're logged in as superuser</li>
                            <li>• This will create new database tables and register modules</li>
                        </ul>
                    </div>
                    
                    <button type="submit" name="install" 
                            class="w-full bg-blue-500 text-white px-6 py-3 rounded-lg hover:bg-blue-600 transition font-semibold">
                        <i class="fas fa-download mr-2"></i>Install All Modules
                    </button>
                </form>
            <?php else: ?>
                <div class="text-center space-x-4">
                    <a href="dashboard.php" class="inline-block bg-blue-500 text-white px-6 py-3 rounded-lg hover:bg-blue-600 transition">
                        <i class="fas fa-home mr-2"></i>Go to Dashboard
                    </a>
                    <a href="modules/programs/index.php" class="inline-block bg-green-500 text-white px-6 py-3 rounded-lg hover:bg-green-600 transition">
                        <i class="fas fa-calendar-alt mr-2"></i>View Programs
                    </a>
                </div>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists