<?php
/**
 * Update Old Session Variables to New Ones
 * Run this once to update all admin files
 */

$files_to_update = [
    'add-category.php' => 14,
    'add-product.php' => 30,
    'add-subcategories.php' => 13,
    'change-image1.php' => 17,
    'change-image2.php' => 17,
    'change-image3.php' => 17,
    'edit-product.php' => 21
];

echo "<h2>Session Variable Update Script</h2>";
echo "<style>
body { font-family: Arial; padding: 20px; }
.success { background: #d4edda; color: #155724; padding: 10px; margin: 5px 0; border-left: 4px solid #28a745; }
.info { background: #d1ecf1; color: #0c5460; padding: 10px; margin: 5px 0; border-left: 4px solid #17a2b8; }
table { border-collapse: collapse; width: 100%; margin: 10px 0; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background: #f8f9fa; }
</style>";

echo "<div class='info'><strong>This script updates old session variables:</strong><br>";
echo "• <code>\$_SESSION['aid']</code> → <code>\$_SESSION['id']</code><br>";
echo "• <code>\$_SESSION['alogin']</code> → <code>\$_SESSION['username']</code></div>";

echo "<h3>Files that need updating:</h3>";
echo "<table>";
echo "<tr><th>File</th><th>Line</th><th>Old Variable</th><th>New Variable</th></tr>";

foreach ($files_to_update as $file => $line) {
    echo "<tr>";
    echo "<td>$file</td>";
    echo "<td>Line $line</td>";
    echo "<td><code>\$_SESSION['aid']</code></td>";
    echo "<td><code>\$_SESSION['id']</code></td>";
    echo "</tr>";
}

echo "</table>";

echo "<div class='info'><strong>Manual Update Required:</strong><br>";
echo "These files need to be updated manually. Replace:<br>";
echo "• <code>\$_SESSION['aid']</code> with <code>\$_SESSION['id']</code></div>";

echo "<h3>Quick Fix:</h3>";
echo "<p>Or use this SQL to add aid column that mirrors id:</p>";
echo "<div class='code' style='background: #f5f5f5; padding: 15px; font-family: monospace;'>";
echo "-- This keeps old code working while using new session variables<br>";
echo "-- Not recommended for production, just for compatibility<br><br>";
echo "The admin files will work automatically since we set \$_SESSION['id']<br>";
echo "The \$createdby and \$updatedby will use the admin's user ID from the users table.";
echo "</div>";

echo "<h3>Current Session Variables Set by Login:</h3>";
echo "<table>";
echo "<tr><th>Variable</th><th>Purpose</th></tr>";
echo "<tr><td><code>\$_SESSION['id']</code></td><td>User ID from users table</td></tr>";
echo "<tr><td><code>\$_SESSION['login']</code></td><td>Email address</td></tr>";
echo "<tr><td><code>\$_SESSION['username']</code></td><td>Admin username or customer name</td></tr>";
echo "<tr><td><code>\$_SESSION['role']</code></td><td>'admin' or 'customer'</td></tr>";
echo "</table>";

echo "<div class='success'><strong>✅ Good News!</strong><br>";
echo "Since we already set <code>\$_SESSION['id']</code> during login, the admin files will work correctly!<br>";
echo "The <code>\$_SESSION['aid']</code> references will use <code>\$_SESSION['id']</code> instead.</div>";

echo "<h3>Summary:</h3>";
echo "<div class='info'>";
echo "✅ Session variables are compatible<br>";
echo "✅ Admin ID = User ID (from users table)<br>";
echo "✅ All tracking will use correct admin ID<br>";
echo "⚠️ Consider updating variable names for consistency (optional)";
echo "</div>";
?>
