Sindbad~EG File Manager

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

<?php
/**
 * Installation script for Membership Issues System
 * Run this file once to set up the membership issues 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 Membership Issues System</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'>
</head>
<body class='bg-gray-100 p-8'>
    <div class='max-w-4xl mx-auto'>
        <div class='bg-white rounded-lg shadow-lg p-8'>
            <h1 class='text-3xl font-bold text-gray-800 mb-6'>
                <i class='fas fa-cog text-blue-600 mr-2'></i>
                Membership Issues System Installation
            </h1>";

// Step 1: Create membership_issues tables
echo "<div class='mb-6'>
        <h2 class='text-xl font-semibold text-gray-800 mb-3'>
            <i class='fas fa-database mr-2 text-blue-500'></i>
            Step 1: Creating Database Tables
        </h2>";

try {
    $sql = file_get_contents(__DIR__ . '/sql/membership_issues.sql');
    
    // Split by semicolons and execute each statement
    $statements = array_filter(array_map('trim', explode(';', $sql)));
    
    foreach ($statements as $statement) {
        if (!empty($statement)) {
            $db->exec($statement);
        }
    }
    
    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 membership_issues and membership_issue_comments tables
          </div>";
    $success[] = "Database tables 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 tables: " . htmlspecialchars($e->getMessage()) . "
          </div>";
    $errors[] = "Database creation failed: " . $e->getMessage();
}

echo "</div>";

// Step 2: Add module to module_management
echo "<div class='mb-6'>
        <h2 class='text-xl font-semibold text-gray-800 mb-3'>
            <i class='fas fa-th-large mr-2 text-blue-500'></i>
            Step 2: Registering Module
        </h2>";

try {
    $sql = file_get_contents(__DIR__ . '/sql/add_membership_issues_module.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 registered Membership Issues 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>";

// Step 3: Verify installation
echo "<div class='mb-6'>
        <h2 class='text-xl font-semibold text-gray-800 mb-3'>
            <i class='fas fa-check-double mr-2 text-blue-500'></i>
            Step 3: Verifying Installation
        </h2>";

try {
    // Check if tables exist
    $tables = ['membership_issues', 'membership_issue_comments'];
    $allTablesExist = true;
    
    foreach ($tables as $table) {
        $result = $db->query("SHOW TABLES LIKE '$table'");
        if ($result->rowCount() == 0) {
            $allTablesExist = false;
            echo "<div class='bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 rounded mb-2'>
                    <i class='fas fa-exclamation-triangle mr-2'></i>
                    Warning: Table '$table' not found
                  </div>";
        }
    }
    
    if ($allTablesExist) {
        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>
                All required tables verified successfully
              </div>";
    }
    
    // Check if module is registered
    $moduleCheck = $db->query("SELECT * FROM module_management WHERE module_name = 'Membership Issues'");
    if ($moduleCheck->rowCount() > 0) {
        echo "<div class='bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded mt-2'>
                <i class='fas fa-check-circle mr-2'></i>
                Module successfully registered and will appear in the dashboard sidebar
              </div>";
    } else {
        echo "<div class='bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 rounded mt-2'>
                <i class='fas fa-exclamation-triangle mr-2'></i>
                Warning: Module not found in module_management table
              </div>";
    }
    
} 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 during verification: " . htmlspecialchars($e->getMessage()) . "
          </div>";
}

echo "</div>";

// Summary
echo "<div class='border-t-2 border-gray-200 pt-6 mt-6'>
        <h2 class='text-2xl font-bold text-gray-800 mb-4'>Installation Summary</h2>";

if (empty($errors)) {
    echo "<div class='bg-green-50 border-2 border-green-500 rounded-lg p-6'>
            <div class='flex items-start'>
                <i class='fas fa-check-circle text-green-600 text-3xl mr-4'></i>
                <div>
                    <h3 class='text-xl font-bold text-green-800 mb-2'>Installation Successful!</h3>
                    <p class='text-green-700 mb-4'>The Membership Issues System has been installed successfully.</p>
                    <ul class='list-disc list-inside text-green-700 space-y-1 mb-4'>";
    
    foreach ($success as $item) {
        echo "<li>$item</li>";
    }
    
    echo "      </ul>
                    <div class='bg-white border border-green-300 rounded p-4 mt-4'>
                        <h4 class='font-bold text-gray-800 mb-2'>What's Next?</h4>
                        <ul class='text-sm text-gray-700 space-y-2'>
                            <li>✓ The <strong>Membership Issues</strong> module is now available in your dashboard sidebar</li>
                            <li>✓ Public users can report issues from the search page at: <code class='bg-gray-100 px-2 py-1 rounded'>public-search.php</code></li>
                            <li>✓ When no member is found, users can click <strong>\"Report Missing Member\"</strong></li>
                            <li>✓ When viewing results, users can click <strong>\"Report Issue\"</strong> to report incorrect details</li>
                            <li>✓ Admin users can manage all issues from the <strong>Membership Issues</strong> dashboard</li>
                        </ul>
                    </div>
                    <div class='mt-6 flex gap-4'>
                        <a href='dashboard.php' class='bg-blue-600 text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition inline-flex items-center'>
                            <i class='fas fa-tachometer-alt mr-2'></i>Go to Dashboard
                        </a>
                        <a href='modules/membership-issues/index.php' class='bg-green-600 text-white px-6 py-3 rounded-lg hover:bg-green-700 transition inline-flex items-center'>
                            <i class='fas fa-exclamation-circle mr-2'></i>View Membership Issues
                        </a>
                        <a href='public-search.php' class='bg-purple-600 text-white px-6 py-3 rounded-lg hover:bg-purple-700 transition inline-flex items-center'>
                            <i class='fas fa-search mr-2'></i>Test Search Page
                        </a>
                    </div>
                </div>
            </div>
          </div>";
} else {
    echo "<div class='bg-red-50 border-2 border-red-500 rounded-lg p-6'>
            <div class='flex items-start'>
                <i class='fas fa-times-circle text-red-600 text-3xl mr-4'></i>
                <div>
                    <h3 class='text-xl font-bold text-red-800 mb-2'>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-4 bg-yellow-50 border-l-4 border-yellow-500 rounded'>
                <p class='text-sm 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_membership_issues.php) after successful installation.
                </p>
            </div>
        </div>
    </div>
</body>
</html>";
?>

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