Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/attendance/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/attendance/install.php

<?php
// Church Attendance Management System - Installation Script
// This script should be deleted after successful installation

// Check if system is already installed
if (file_exists('config/.installed')) {
    die('System is already installed. Delete config/.installed file to reinstall.');
}

$step = $_GET['step'] ?? 1;
$error = '';
$success = '';

// Handle installation steps
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($step == 2) {
        // Database configuration step
        $host = $_POST['host'] ?? 'localhost';
        $username = $_POST['username'] ?? 'root';
        $password = $_POST['password'] ?? '';
        $database = $_POST['database'] ?? 'church_attendance';
        
        try {
            // Test database connection
            $pdo = new PDO("mysql:host=$host", $username, $password);
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            
            // Create database if it doesn't exist
            $pdo->exec("CREATE DATABASE IF NOT EXISTS `$database`");
            $pdo->exec("USE `$database`");
            
            // Read and execute schema
            $schema = file_get_contents('database/schema.sql');
            $statements = explode(';', $schema);
            
            foreach ($statements as $statement) {
                $statement = trim($statement);
                if (!empty($statement)) {
                    $pdo->exec($statement);
                }
            }
            
            // Update database configuration
            $config_content = file_get_contents('config/database.php');
            $config_content = str_replace("'localhost'", "'$host'", $config_content);
            $config_content = str_replace("'church_attendance'", "'$database'", $config_content);
            $config_content = str_replace("'root'", "'$username'", $config_content);
            $config_content = str_replace("''", "'$password'", $config_content);
            
            file_put_contents('config/database.php', $config_content);
            
            $success = 'Database installed successfully!';
            $step = 3;
            
        } catch (Exception $e) {
            $error = 'Database error: ' . $e->getMessage();
        }
    } elseif ($step == 3) {
        // Final step - create installation marker
        if (!is_dir('config')) {
            mkdir('config', 0755, true);
        }
        file_put_contents('config/.installed', date('Y-m-d H:i:s'));
        $step = 4;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Church Attendance System - Installation</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#F59E0B',
                        accent: '#6B7280'
                    }
                }
            }
        }
    </script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #3B82F6 0%, #F59E0B 50%, #6B7280 100%);
        }
    </style>
</head>
<body class="min-h-screen gradient-bg flex items-center justify-center py-12 px-4">
    <div class="max-w-2xl w-full">
        <!-- Header -->
        <div class="text-center mb-8">
            <h1 class="text-4xl font-bold text-white mb-2">Church Attendance System</h1>
            <p class="text-white/80 text-lg">Installation Wizard</p>
        </div>

        <!-- Installation Card -->
        <div class="bg-white rounded-lg shadow-xl p-8">
            <!-- Progress Bar -->
            <div class="mb-8">
                <div class="flex items-center justify-between mb-2">
                    <span class="text-sm font-medium text-gray-700">Installation Progress</span>
                    <span class="text-sm font-medium text-gray-700"><?php echo min($step, 4); ?>/4</span>
                </div>
                <div class="w-full bg-gray-200 rounded-full h-2">
                    <div class="bg-primary h-2 rounded-full transition-all duration-300" 
                         style="width: <?php echo (min($step, 4) / 4) * 100; ?>%"></div>
                </div>
            </div>

            <?php if ($error): ?>
                <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6">
                    <div class="flex items-center">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <span><?php echo htmlspecialchars($error); ?></span>
                    </div>
                </div>
            <?php endif; ?>

            <?php if ($success): ?>
                <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-6">
                    <div class="flex items-center">
                        <i class="fas fa-check-circle mr-2"></i>
                        <span><?php echo htmlspecialchars($success); ?></span>
                    </div>
                </div>
            <?php endif; ?>

            <?php if ($step == 1): ?>
                <!-- Step 1: Welcome -->
                <div class="text-center">
                    <i class="fas fa-church text-6xl text-primary mb-6"></i>
                    <h2 class="text-2xl font-bold text-gray-900 mb-4">Welcome to the Installation</h2>
                    <p class="text-gray-600 mb-6">
                        This wizard will help you set up your Church Attendance Management System. 
                        Please ensure you have the following ready:
                    </p>
                    
                    <div class="text-left bg-gray-50 rounded-lg p-6 mb-6">
                        <h3 class="font-semibold text-gray-900 mb-4">Requirements:</h3>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                PHP 7.4 or higher
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                MySQL 5.7 or higher
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                Web server (Apache/Nginx)
                            </li>
                            <li class="flex items-center">
                                <i class="fas fa-check text-green-500 mr-2"></i>
                                Database credentials
                            </li>
                        </ul>
                    </div>
                    
                    <a href="?step=2" class="bg-primary text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition duration-300 inline-block">
                        <i class="fas fa-arrow-right mr-2"></i>
                        Start Installation
                    </a>
                </div>

            <?php elseif ($step == 2): ?>
                <!-- Step 2: Database Configuration -->
                <div>
                    <h2 class="text-2xl font-bold text-gray-900 mb-6">
                        <i class="fas fa-database mr-2 text-primary"></i>
                        Database Configuration
                    </h2>
                    
                    <form method="POST" class="space-y-6">
                        <div>
                            <label for="host" class="block text-sm font-medium text-gray-700 mb-2">
                                Database Host
                            </label>
                            <input type="text" id="host" name="host" value="localhost" required
                                   class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
                        </div>
                        
                        <div>
                            <label for="database" class="block text-sm font-medium text-gray-700 mb-2">
                                Database Name
                            </label>
                            <input type="text" id="database" name="database" value="church_attendance" required
                                   class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
                            <p class="text-sm text-gray-500 mt-1">Database will be created if it doesn't exist</p>
                        </div>
                        
                        <div>
                            <label for="username" class="block text-sm font-medium text-gray-700 mb-2">
                                Database Username
                            </label>
                            <input type="text" id="username" name="username" value="root" required
                                   class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
                        </div>
                        
                        <div>
                            <label for="password" class="block text-sm font-medium text-gray-700 mb-2">
                                Database Password
                            </label>
                            <input type="password" id="password" name="password"
                                   class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
                            <p class="text-sm text-gray-500 mt-1">Leave empty if no password is set</p>
                        </div>
                        
                        <div class="flex justify-between">
                            <a href="?step=1" class="px-4 py-2 text-gray-600 hover:text-gray-800">
                                <i class="fas fa-arrow-left mr-2"></i>
                                Back
                            </a>
                            <button type="submit" class="bg-primary text-white px-6 py-2 rounded-lg hover:bg-blue-700 transition duration-300">
                                <i class="fas fa-database mr-2"></i>
                                Install Database
                            </button>
                        </div>
                    </form>
                </div>

            <?php elseif ($step == 3): ?>
                <!-- Step 3: Admin Account -->
                <div class="text-center">
                    <i class="fas fa-user-shield text-6xl text-green-500 mb-6"></i>
                    <h2 class="text-2xl font-bold text-gray-900 mb-4">Database Installed Successfully!</h2>
                    
                    <div class="bg-blue-50 rounded-lg p-6 mb-6">
                        <h3 class="font-semibold text-gray-900 mb-4">Default Superuser Account:</h3>
                        <div class="text-left space-y-2">
                            <p><strong>Email:</strong> nabibo2@yahoo.co.uk</p>
                            <p><strong>Username:</strong> nabibo</p>
                            <p><strong>Password:</strong> password123</p>
                        </div>
                        <div class="mt-4 p-3 bg-yellow-100 rounded border-l-4 border-yellow-500">
                            <p class="text-sm text-yellow-800">
                                <i class="fas fa-exclamation-triangle mr-2"></i>
                                <strong>Important:</strong> Change the default password immediately after first login!
                            </p>
                        </div>
                    </div>
                    
                    <form method="POST">
                        <button type="submit" class="bg-primary text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition duration-300">
                            <i class="fas fa-check mr-2"></i>
                            Complete Installation
                        </button>
                    </form>
                </div>

            <?php elseif ($step == 4): ?>
                <!-- Step 4: Complete -->
                <div class="text-center">
                    <i class="fas fa-check-circle text-6xl text-green-500 mb-6"></i>
                    <h2 class="text-2xl font-bold text-gray-900 mb-4">Installation Complete!</h2>
                    <p class="text-gray-600 mb-6">
                        Your Church Attendance Management System has been successfully installed and configured.
                    </p>
                    
                    <div class="bg-gray-50 rounded-lg p-6 mb-6">
                        <h3 class="font-semibold text-gray-900 mb-4">Next Steps:</h3>
                        <ol class="text-left space-y-2 text-gray-700">
                            <li>1. Delete this installation file (install.php) for security</li>
                            <li>2. Login to the admin panel and change the default password</li>
                            <li>3. Configure your church locations and programs</li>
                            <li>4. Customize the site settings and theme</li>
                            <li>5. Test the attendance form functionality</li>
                        </ol>
                    </div>
                    
                    <div class="flex justify-center space-x-4">
                        <a href="index.php" class="bg-primary text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition duration-300">
                            <i class="fas fa-home mr-2"></i>
                            View Homepage
                        </a>
                        <a href="admin/login.php" class="bg-secondary text-white px-6 py-3 rounded-lg hover:bg-yellow-600 transition duration-300">
                            <i class="fas fa-sign-in-alt mr-2"></i>
                            Admin Login
                        </a>
                    </div>
                </div>
            <?php endif; ?>
        </div>

        <!-- Footer -->
        <div class="text-center mt-8 text-white/70">
            <p>&copy; 2024 Church Attendance Management System</p>
        </div>
    </div>
</body>
</html>

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