Sindbad~EG File Manager

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

<?php
/**
 * Installation Script
 * Church Membership System
 */

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

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

// Step 1: Database Configuration
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['test_connection'])) {
    $host = $_POST['db_host'];
    $user = $_POST['db_user'];
    $pass = $_POST['db_pass'];
    $name = $_POST['db_name'];
    
    try {
        $dsn = "mysql:host=$host;charset=utf8mb4";
        $pdo = new PDO($dsn, $user, $pass);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        // Create database
        $pdo->exec("CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
        $pdo->exec("USE `$name`");
        
        // Execute schema
        $schema = file_get_contents(__DIR__ . '/database/schema.sql');
        $pdo->exec($schema);
        
        // Insert superuser with properly hashed password
        $passwordHash = password_hash('password123', PASSWORD_BCRYPT);
        $pdo->exec("
            INSERT INTO users (username, email, password_hash, full_name, is_superuser, access_level, is_active) 
            VALUES ('nabibo', 'nabibo2@yahoo.co.uk', '$passwordHash', 'Super Administrator', 1, 'superuser', 1)
            ON DUPLICATE KEY UPDATE password_hash = '$passwordHash'
        ");
        
        // Create config file
        $configContent = "<?php\n";
        $configContent .= "define('DB_HOST', '$host');\n";
        $configContent .= "define('DB_USER', '$user');\n";
        $configContent .= "define('DB_PASS', '$pass');\n";
        $configContent .= "define('DB_NAME', '$name');\n";
        
        file_put_contents(__DIR__ . '/config/database.php', $configContent);
        
        // Create installed flag
        file_put_contents(__DIR__ . '/config/.installed', date('Y-m-d H:i:s'));
        
        $success = 'Installation completed successfully!';
        $step = 2;
        
    } catch (PDOException $e) {
        $error = 'Database error: ' . $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Installation - Church Membership System</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">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * { font-family: 'Inter', sans-serif; }
        .gradient-bg { background: linear-gradient(135deg, #3B82F6 0%, #60A5FA 50%, #FCD34D 100%); }
    </style>
</head>
<body class="bg-gray-50">
    <div class="gradient-bg py-6">
        <div class="container mx-auto px-4">
            <h1 class="text-3xl font-bold text-white text-center">
                <i class="fas fa-church mr-2"></i>Church Membership System Installation
            </h1>
        </div>
    </div>
    
    <div class="container mx-auto px-4 py-8">
        <div class="max-w-2xl mx-auto">
            <?php if ($step == 1): ?>
                <!-- Step 1: Database Configuration -->
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <h2 class="text-2xl font-bold text-gray-800 mb-6">
                        <i class="fas fa-database mr-2 text-blue-500"></i>Database Configuration
                    </h2>
                    
                    <?php if ($error): ?>
                        <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded-lg mb-6">
                            <i class="fas fa-exclamation-circle mr-2"></i><?php echo $error; ?>
                        </div>
                    <?php endif; ?>
                    
                    <form method="POST" class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Database Host</label>
                            <input type="text" name="db_host" value="localhost" required
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Database Name</label>
                            <input type="text" name="db_name" value="church_membership" required
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Database Username</label>
                            <input type="text" name="db_user" value="root" required
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Database Password</label>
                            <input type="password" name="db_pass"
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div class="pt-4">
                            <button type="submit" name="test_connection"
                                    class="w-full bg-gradient-to-r from-blue-500 to-blue-600 text-white px-6 py-3 rounded-lg hover:from-blue-600 hover:to-blue-700 transition">
                                <i class="fas fa-check mr-2"></i>Install System
                            </button>
                        </div>
                    </form>
                </div>
            
            <?php elseif ($step == 2): ?>
                <!-- Step 2: Installation Complete -->
                <div class="bg-white rounded-xl shadow-lg p-8 text-center">
                    <div class="inline-block p-6 bg-green-100 rounded-full mb-6">
                        <i class="fas fa-check-circle text-6xl text-green-600"></i>
                    </div>
                    
                    <h2 class="text-3xl font-bold text-gray-800 mb-4">Installation Complete!</h2>
                    <p class="text-gray-600 mb-6">Your Church Membership System has been successfully installed.</p>
                    
                    <div class="bg-blue-50 rounded-lg p-6 mb-6 text-left">
                        <h3 class="font-bold text-gray-800 mb-3">Default Superuser Credentials:</h3>
                        <div class="space-y-2 text-sm">
                            <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 border-yellow-300">
                            <i class="fas fa-exclamation-triangle text-yellow-600 mr-2"></i>
                            <span class="text-sm text-gray-700">Please change the default password after first login!</span>
                        </div>
                    </div>
                    
                    <a href="login.php" 
                       class="inline-block bg-gradient-to-r from-blue-500 to-blue-600 text-white px-8 py-3 rounded-lg hover:from-blue-600 hover:to-blue-700 transition">
                        <i class="fas fa-sign-in-alt mr-2"></i>Go to Login
                    </a>
                </div>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>

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