Sindbad~EG File Manager

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

<?php
require_once 'config/config.php';

// Session is already started in config.php
// Check if user is logged in (any admin user can run this)
if (!isset($_SESSION['user_id'])) {
    die('Access denied. Please <a href="login.php">login</a> first.');
}

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

echo "<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Fix Member Codes Columns</title>
    <script src='https://cdn.tailwindcss.com'></script>
</head>
<body class='bg-gray-100'>
    <div class='container mx-auto px-4 py-8 max-w-4xl'>
        <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-wrench'></i> Fix Member Codes Database Columns
            </h1>";

try {
    // Alter barcode column
    echo "<div class='mb-4'><strong>Updating barcode column...</strong><br>";
    $db->exec("ALTER TABLE memberuser_codes MODIFY COLUMN barcode MEDIUMTEXT");
    echo "<span class='text-green-600'>✓ Successfully changed barcode to MEDIUMTEXT</span></div>";
    $success[] = "Barcode column updated";
} catch (Exception $e) {
    echo "<span class='text-red-600'>✗ Error: " . htmlspecialchars($e->getMessage()) . "</span></div>";
    $errors[] = "Failed to update barcode column: " . $e->getMessage();
}

try {
    // Alter qrcode column
    echo "<div class='mb-4'><strong>Updating qrcode column...</strong><br>";
    $db->exec("ALTER TABLE memberuser_codes MODIFY COLUMN qrcode MEDIUMTEXT");
    echo "<span class='text-green-600'>✓ Successfully changed qrcode to MEDIUMTEXT</span></div>";
    $success[] = "QR code column updated";
} catch (Exception $e) {
    echo "<span class='text-red-600'>✗ Error: " . htmlspecialchars($e->getMessage()) . "</span></div>";
    $errors[] = "Failed to update qrcode column: " . $e->getMessage();
}

// Show updated structure
try {
    echo "<div class='mt-6 mb-4'><h2 class='text-xl font-bold mb-2'>Updated Table Structure:</h2>";
    $stmt = $db->query("DESCRIBE memberuser_codes");
    $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<table class='w-full border-collapse border border-gray-300'>";
    echo "<thead class='bg-gray-100'>";
    echo "<tr><th class='border border-gray-300 px-4 py-2'>Field</th><th class='border border-gray-300 px-4 py-2'>Type</th></tr>";
    echo "</thead><tbody>";
    
    foreach ($columns as $col) {
        $highlight = ($col['Field'] === 'barcode' || $col['Field'] === 'qrcode') ? 'bg-green-100 font-bold' : '';
        echo "<tr class='$highlight'>";
        echo "<td class='border border-gray-300 px-4 py-2'>" . htmlspecialchars($col['Field']) . "</td>";
        echo "<td class='border border-gray-300 px-4 py-2'>" . htmlspecialchars($col['Type']) . "</td>";
        echo "</tr>";
    }
    echo "</tbody></table></div>";
} catch (Exception $e) {
    echo "<div class='text-red-600'>Error showing structure: " . htmlspecialchars($e->getMessage()) . "</div>";
}

echo "<div class='mt-6 p-4 bg-yellow-100 border-l-4 border-yellow-500'>
        <h3 class='font-bold text-yellow-800 mb-2'>⚠️ Important Next Steps:</h3>
        <ol class='list-decimal list-inside text-yellow-800'>
            <li>The database columns have been fixed to support larger data.</li>
            <li><strong>All existing codes are still truncated at 255 characters.</strong></li>
            <li>You need to <strong>regenerate all codes</strong> or <strong>delete and recreate them</strong>.</li>
            <li>New codes created from now on will have full barcode/QR code images.</li>
        </ol>
      </div>";

if (!empty($errors)) {
    echo "<div class='mt-4 p-4 bg-red-100 border-l-4 border-red-500'>
            <h3 class='font-bold text-red-800 mb-2'>Errors:</h3>
            <ul class='list-disc list-inside text-red-800'>";
    foreach ($errors as $error) {
        echo "<li>" . htmlspecialchars($error) . "</li>";
    }
    echo "</ul></div>";
}

if (!empty($success)) {
    echo "<div class='mt-4 p-4 bg-green-100 border-l-4 border-green-500'>
            <h3 class='font-bold text-green-800 mb-2'>✓ Success:</h3>
            <ul class='list-disc list-inside text-green-800'>";
    foreach ($success as $msg) {
        echo "<li>" . htmlspecialchars($msg) . "</li>";
    }
    echo "</ul></div>";
}

echo "<div class='mt-6 flex gap-4'>
        <a href='modules/membership/codes.php' class='px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition'>
            Go to Member Codes Page
        </a>
        <a href='dashboard.php' class='px-6 py-3 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition'>
            Back to Dashboard
        </a>
      </div>";

echo "</div></div>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'>
</body>
</html>";
?>

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