Sindbad~EG File Manager

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

<?php
/**
 * Installation script for Page Content Management
 * Run this file once to set up the page content editor feature
 */

require_once 'config/config.php';

// Check if user is logged in and is superuser
if (!isLoggedIn() || !isSuperuser()) {
    die("Access denied. Only superusers can run this installation.");
}

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

echo "<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Install Page Content Management</title>
    <script src='https://cdn.tailwindcss.com'></script>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #1E40AF 0%, #9333EA 50%, #F97316 100%);
        }
    </style>
</head>
<body class='bg-gray-100'>
    <div class='min-h-screen py-8 px-4'>
        <div class='max-w-5xl mx-auto'>
            <div class='gradient-bg rounded-2xl shadow-2xl p-8 mb-8 text-white'>
                <h1 class='text-4xl font-bold mb-2'>
                    <i class='fas fa-cog mr-3'></i>
                    Page Content Management Installation
                </h1>
                <p class='text-white/90'>Setting up the dynamic content editor for your pages</p>
            </div>";

// Step 1: Create page_content table
echo "<div class='bg-white rounded-xl shadow-lg p-6 mb-6'>
        <h2 class='text-2xl font-semibold text-gray-800 mb-4'>
            <i class='fas fa-database mr-2 text-blue-600'></i>
            Step 1: Creating Database Table
        </h2>";

try {
    $sql = file_get_contents(__DIR__ . '/sql/page_content.sql');
    
    // Execute SQL
    $db->exec($sql);
    
    echo "<div class='bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded'>
            <i class='fas fa-check-circle mr-2'></i>
            Successfully created page_content table with default content
          </div>";
    $success[] = "Database table created";
    
} catch (PDOException $e) {
    echo "<div class='bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded'>
            <i class='fas fa-times-circle mr-2'></i>
            Error creating table: " . htmlspecialchars($e->getMessage()) . "
          </div>";
    $errors[] = "Database creation failed: " . $e->getMessage();
}

echo "</div>";

// Step 2: Add module to module_management
echo "<div class='bg-white rounded-xl shadow-lg p-6 mb-6'>
        <h2 class='text-2xl font-semibold text-gray-800 mb-4'>
            <i class='fas fa-th-large mr-2 text-orange-600'></i>
            Step 2: Registering Module
        </h2>";

try {
    $stmt = $db->prepare("
        INSERT INTO module_management (
            module_name, module_description, module_url, module_icon, 
            is_active, required_role, display_order, created_at
        ) VALUES (
            'Page Content Editor', 
            'Manage content for About, Features, and Contact pages',
            'modules/page-content/index.php',
            'edit',
            1,
            'superuser',
            150,
            NOW()
        ) ON DUPLICATE KEY UPDATE
            module_description = VALUES(module_description)
    ");
    $stmt->execute();
    
    echo "<div class='bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded'>
            <i class='fas fa-check-circle mr-2'></i>
            Successfully registered Page Content Editor module in the system
          </div>";
    $success[] = "Module registered";
    
} catch (PDOException $e) {
    echo "<div class='bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded'>
            <i class='fas fa-times-circle mr-2'></i>
            Error registering module: " . htmlspecialchars($e->getMessage()) . "
          </div>";
    $errors[] = "Module registration failed: " . $e->getMessage();
}

echo "</div>";

// Summary
echo "<div class='bg-white rounded-xl shadow-lg p-8'>
        <h2 class='text-3xl font-bold text-gray-800 mb-6'>Installation Summary</h2>";

if (empty($errors)) {
    echo "<div class='bg-green-50 border-2 border-green-500 rounded-xl p-8'>
            <div class='flex items-start'>
                <i class='fas fa-check-circle text-green-600 text-4xl mr-4'></i>
                <div class='flex-1'>
                    <h3 class='text-2xl font-bold text-green-800 mb-3'>Installation Successful!</h3>
                    <p class='text-green-700 mb-4'>The Page Content Management system has been installed successfully.</p>
                    
                    <div class='bg-white border border-green-300 rounded-lg p-6 mb-6'>
                        <h4 class='font-bold text-gray-800 mb-3 text-lg'>What's Installed:</h4>
                        <ul class='text-gray-700 space-y-2'>
                            <li class='flex items-start'>
                                <i class='fas fa-check text-green-600 mr-2 mt-1'></i>
                                <span><strong>Database Table:</strong> page_content table with default content for About, Features, and Contact pages</span>
                            </li>
                            <li class='flex items-start'>
                                <i class='fas fa-check text-green-600 mr-2 mt-1'></i>
                                <span><strong>Admin Module:</strong> Page Content Editor now available in your dashboard sidebar</span>
                            </li>
                            <li class='flex items-start'>
                                <i class='fas fa-check text-green-600 mr-2 mt-1'></i>
                                <span><strong>Dynamic Pages:</strong> About, Features, and Contact pages now pull content from database</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class='bg-blue-50 border border-blue-300 rounded-lg p-6 mb-6'>
                        <h4 class='font-bold text-gray-800 mb-3 text-lg'>How to Use:</h4>
                        <ol class='text-gray-700 space-y-2 list-decimal list-inside'>
                            <li>Go to Dashboard → <strong>Page Content Editor</strong></li>
                            <li>Select the page you want to edit (About, Features, or Contact)</li>
                            <li>Update the content in the form fields</li>
                            <li>Click <strong>Save All Changes</strong></li>
                            <li>Preview your changes by clicking the preview button</li>
                        </ol>
                    </div>
                    
                    <div class='flex gap-4 mt-6'>
                        <a href='dashboard.php' class='px-6 py-3 rounded-full text-white font-semibold transition shadow-lg hover:shadow-xl' style='background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%);'>
                            <i class='fas fa-tachometer-alt mr-2'></i>Go to Dashboard
                        </a>
                        <a href='modules/page-content/index.php' class='px-6 py-3 rounded-full text-white font-semibold transition shadow-lg hover:shadow-xl' style='background: linear-gradient(135deg, #F97316 0%, #FBBF24 100%);'>
                            <i class='fas fa-edit mr-2'></i>Edit Page Content
                        </a>
                        <a href='about.php' target='_blank' class='px-6 py-3 rounded-full border-2 border-purple-600 text-purple-600 font-semibold hover:bg-purple-50 transition'>
                            <i class='fas fa-eye mr-2'></i>View About Page
                        </a>
                    </div>
                </div>
            </div>
          </div>";
} else {
    echo "<div class='bg-red-50 border-2 border-red-500 rounded-xl p-8'>
            <div class='flex items-start'>
                <i class='fas fa-times-circle text-red-600 text-4xl mr-4'></i>
                <div>
                    <h3 class='text-2xl font-bold text-red-800 mb-3'>Installation Failed</h3>
                    <p class='text-red-700 mb-4'>There were errors during installation:</p>
                    <ul class='list-disc list-inside text-red-700 space-y-1'>";
    
    foreach ($errors as $error) {
        echo "<li>" . htmlspecialchars($error) . "</li>";
    }
    
    echo "      </ul>
                    <p class='text-red-700 mt-4'>Please check the errors above and try again.</p>
                </div>
            </div>
          </div>";
}

echo "        </div>
            <div class='mt-6 p-6 bg-yellow-50 border-l-4 border-yellow-500 rounded-lg'>
                <p class='text-gray-700'>
                    <i class='fas fa-info-circle text-yellow-600 mr-2'></i>
                    <strong>Note:</strong> For security reasons, you should delete this installation file (install_page_content.php) after successful installation.
                </p>
            </div>
        </div>
    </div>
</body>
</html>";
?>

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