Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/reports/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/reports/setup.php

<?php
// Database Setup Script for COP Madina Area Reports System
error_reporting(E_ALL);
ini_set('display_errors', 1);

$setup_complete = false;
$error_message = '';
$success_message = '';

if ($_POST && isset($_POST['setup_database'])) {
    try {
        // Database connection parameters
        $host = 'localhost';
        $username = 'root';
        $password = $_POST['db_password'] ?? '';
        
        // Connect to MySQL server (without database)
        $pdo = new PDO("mysql:host=$host", $username, $password);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        // Create database
        $pdo->exec("CREATE DATABASE IF NOT EXISTS copmadinaarea_copreports");
        $pdo->exec("USE copmadinaarea_copreports");
        
        // Read and execute schema
        $schema = file_get_contents('database/schema.sql');
        
        // Split the schema into individual statements
        $statements = array_filter(array_map('trim', explode(';', $schema)));
        
        foreach ($statements as $statement) {
            if (!empty($statement)) {
                $pdo->exec($statement);
            }
        }
        
        // Update the default password hash for the superuser
        $password_hash = password_hash('password123', PASSWORD_DEFAULT);
        $pdo->exec("UPDATE users SET password_hash = '$password_hash' WHERE username = 'nabibo'");
        
        $setup_complete = true;
        $success_message = 'Database setup completed successfully!';
        
    } catch (Exception $e) {
        $error_message = 'Setup failed: ' . $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Setup - COP Madina Area Reports</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        'cop-blue': '#1e40af',
                        'cop-light-blue': '#3b82f6',
                    }
                }
            }
        }
    </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, #667eea 0%, #764ba2 100%);
        }
    </style>
</head>
<body class="gradient-bg min-h-screen flex items-center justify-center p-4">
    <div class="w-full max-w-md">
        <div class="text-center mb-8">
            <div class="mx-auto w-20 h-20 bg-white rounded-full flex items-center justify-center mb-4 shadow-lg">
                <i class="fas fa-church text-3xl text-cop-blue"></i>
            </div>
            <h1 class="text-3xl font-bold text-white mb-2">COP Madina Area Reports</h1>
            <p class="text-blue-100">Database Setup</p>
        </div>

        <div class="bg-white rounded-2xl p-8 shadow-2xl">
            <?php if ($setup_complete): ?>
            <div class="text-center">
                <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-check text-2xl text-green-600"></i>
                </div>
                <h2 class="text-2xl font-semibold text-gray-800 mb-4">Setup Complete!</h2>
                <p class="text-gray-600 mb-6"><?php echo htmlspecialchars($success_message); ?></p>
                
                <div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6">
                    <h3 class="font-medium text-blue-800 mb-2">Superuser Login Credentials:</h3>
                    <div class="text-sm text-blue-700">
                        <p><strong>Email:</strong> nabibo2@yahoo.co.uk</p>
                        <p><strong>Username:</strong> nabibo</p>
                        <p><strong>Password:</strong> password123</p>
                    </div>
                </div>
                
                <a href="login.php" class="w-full bg-cop-blue text-white py-3 px-4 rounded-lg font-medium hover:bg-cop-light-blue transition duration-200 inline-block text-center">
                    <i class="fas fa-sign-in-alt mr-2"></i>Go to Login
                </a>
            </div>
            <?php else: ?>
            <div class="text-center mb-6">
                <h2 class="text-2xl font-semibold text-gray-800">Database Setup</h2>
                <p class="text-gray-600 mt-2">Initialize the database for your application</p>
            </div>

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

            <form method="POST" action="">
                <div class="mb-6">
                    <label for="db_password" class="block text-sm font-medium text-gray-700 mb-2">
                        <i class="fas fa-key mr-2"></i>MySQL Root Password
                    </label>
                    <input type="password" 
                           id="db_password" 
                           name="db_password"
                           class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-cop-blue focus:border-transparent"
                           placeholder="Enter MySQL root password (leave blank if none)">
                    <p class="text-xs text-gray-500 mt-1">Default XAMPP installation usually has no password</p>
                </div>

                <button type="submit" 
                        name="setup_database"
                        class="w-full bg-cop-blue text-white py-3 px-4 rounded-lg font-medium hover:bg-cop-light-blue transition duration-200">
                    <i class="fas fa-database mr-2"></i>Setup Database
                </button>
            </form>

            <div class="mt-6 p-4 bg-gray-50 rounded-lg">
                <h3 class="font-medium text-gray-800 mb-2">What this will do:</h3>
                <ul class="text-sm text-gray-600 space-y-1">
                    <li>• Create the 'copmadinaarea_copreports' database</li>
                    <li>• Set up all required tables and relationships</li>
                    <li>• Insert sample data and default settings</li>
                    <li>• Create the superuser account</li>
                </ul>
            </div>
            <?php endif; ?>
        </div>

        <div class="text-center mt-8 text-white/80">
            <p class="text-sm">© 2024 The Church of Pentecost - Madina Area</p>
        </div>
    </div>
</body>
</html>

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