Sindbad~EG File Manager

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

<?php
/**
 * COP News Portal - Database Setup Script
 * Run this file once to set up the database
 */

// Database configuration
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'cop_news_portal';

try {
    // Connect to MySQL server (without selecting database)
    $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`");
    echo "✅ Database '$database' created successfully.<br>";
    
    // Connect to the specific database
    $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Read and execute the schema file
    $schema = file_get_contents(__DIR__ . '/database/schema.sql');
    
    // Remove comments and clean up the SQL
    $lines = explode("\n", $schema);
    $cleanedLines = [];
    
    foreach ($lines as $line) {
        $line = trim($line);
        // Skip empty lines and comment lines
        if (!empty($line) && !preg_match('/^--/', $line)) {
            $cleanedLines[] = $line;
        }
    }
    
    $cleanedSchema = implode("\n", $cleanedLines);
    
    // Split into statements and execute one by one
    $statements = explode(';', $cleanedSchema);
    
    foreach ($statements as $statement) {
        $statement = trim($statement);
        if (!empty($statement)) {
            try {
                $pdo->exec($statement);
            } catch (PDOException $e) {
                // Skip errors for statements that might already exist
                if (strpos($e->getMessage(), 'already exists') === false) {
                    echo "Warning: " . $e->getMessage() . "<br>";
                }
            }
        }
    }
    
    echo "✅ Database schema imported successfully.<br>";
    echo "✅ Default categories created.<br>";
    echo "✅ System settings configured.<br>";
    
    // Hash the superuser password properly
    $hashedPassword = password_hash('Swanzy10@', PASSWORD_DEFAULT);
    
    // Update the superuser password with proper hash
    $stmt = $pdo->prepare("UPDATE users SET password = ? WHERE email = 'nabibo2@yahoo.co.uk'");
    $stmt->execute([$hashedPassword]);
    
    echo "✅ Superuser account configured.<br>";
    echo "<br><strong>Setup Complete!</strong><br>";
    echo "<br><div style='background: #e3f2fd; padding: 15px; border-radius: 8px; margin: 20px 0;'>";
    echo "<h3>Login Credentials:</h3>";
    echo "<strong>Email:</strong> nabibo2@yahoo.co.uk<br>";
    echo "<strong>Password:</strong> Swanzy10@<br>";
    echo "<strong>Role:</strong> Superuser<br>";
    echo "</div>";
    echo "<br><a href='index.php' style='background: #3B82F6; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;'>Go to COP News Portal</a>";
    echo "<br><br><em>You can delete this setup.php file after successful setup.</em>";
    
} catch (PDOException $e) {
    echo "❌ Error: " . $e->getMessage() . "<br>";
    echo "<br>Please ensure:<br>";
    echo "1. XAMPP MySQL service is running<br>";
    echo "2. MySQL is accessible on localhost:3306<br>";
    echo "3. Root user has no password (default XAMPP setup)<br>";
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>COP News Portal - Setup</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 50px auto;
            padding: 20px;
            background: linear-gradient(135deg, #3B82F6 0%, #6B7280 100%);
            color: #333;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        h1 {
            color: #3B82F6;
            text-align: center;
            margin-bottom: 30px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🏛️ COP News Portal Setup</h1>
        <div style="font-size: 16px; line-height: 1.6;">

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