<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MAGEC DOC Cleanup (PHP)</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; }
        h1 { color: #d32f2f; }
        pre { background: #f4f4f4; padding: 15px; border: 1px solid #ddd; border-radius: 5px; overflow-x: auto; }
        .success { color: green; }
        .error { color: red; }
        button { padding: 12px 20px; font-size: 16px; background: #d32f2f; color: white; border: none; border-radius: 5px; cursor: pointer; }
        button:hover { background: #b71c1c; }
    </style>
</head>
<body>
    <h1>MAGEC /DOC/ Cleanup Tool (PHP Version)</h1>
    <p>This script will delete the unused / obsolete files from the DOC directory.</p>

    <h2>Files that will be deleted:</h2>
    <pre>
<?php
$safeToDelete = [
    "insert_main_OLD.htm",
    "install_mainSAVE.htm",
    "insxref_mainSAVE.htm",
    "masteridx_OLD.htm",
    "mastertoc.OLD.htm",
    "mastertoc_main_OLD.htm",
    "mastertoc_idx_OLD.htm",
    "msk_main.htm.old",
    "genmmp_tmp.htm",
    "CH12FIG01 - Copy.GIF",
    "old_tabs.htm",
    "oldtabs.htm",
    "magtemp.htm",
    "magtemp_idx.htm",
    "magtemp_main.htm",
    "magxref.htm",
    "magref.htm",
    "insxref.htm",
    "insxref_idx.htm",
    "insxref_main.htm",
    "box_table.htm",
    "rbdlm.htm"
];

echo implode("\n", $safeToDelete);
?>
    </pre>

    <form method="post">
        <button type="submit" name="delete" onclick="return confirm('Are you sure you want to delete these files? This action cannot be undone!')">DELETE ALL LISTED FILES</button>
    </form>

    <hr>

<?php
if (isset($_POST['delete'])) {

    $directory = __DIR__;   // Current directory (/DOC/)
    $deletedCount = 0;
    $errorCount = 0;

    echo "<h2>Deletion Results:</h2>";

    foreach ($safeToDelete as $file) {
        $filePath = $directory . DIRECTORY_SEPARATOR . $file;

        if (file_exists($filePath)) {
            if (unlink($filePath)) {
                echo '<span class="success">✅ Deleted:</span> ' . htmlspecialchars($file) . '<br>';
                $deletedCount++;
            } else {
                echo '<span class="error">❌ Failed to delete:</span> ' . htmlspecialchars($file) . '<br>';
                $errorCount++;
            }
        } else {
            echo '<span class="error">⚠️ Not found:</span> ' . htmlspecialchars($file) . '<br>';
        }
    }

    echo "<h3>Cleanup Completed!</h3>";
    echo "<p><strong>Files successfully deleted:</strong> $deletedCount</p>";
    echo "<p><strong>Errors:</strong> $errorCount</p>";
    echo "<p><a href='CleanUp.php'>Refresh Page</a></p>";
}
?>

    <p><strong>⚠️ Important:</strong> Only run this once. After deletion, you can safely delete this CleanuUp.php file.</p>
</body>
</html>
 