<?php
$content = file_get_contents('admin.php');

// Fix double div from previous patch if any
$content = str_replace("                                </div>\n                            </div>\n                                </div>\n                            </div>", "                                </div>\n                            </div>", $content);

// Correct table display logic
$content = preg_replace('/if(\$r[\'orbital_dominance_mode\'].*?Orbital.*?;/s', 'if(!empty($r[\'orbital_dominant_factions\'])) $conds[] = "Orbital IN (" . $r[\'orbital_dominant_factions\'] . ")";', $content);
$content = preg_replace('/if(\$r[\'terrestrial_dominance_mode\'].*?Ground.*?;/s', 'if(!empty($r[\'ground_dominant_factions\'])) $conds[] = "Ground IN (" . $r[\'ground_dominant_factions\'] . ")";', $content);

file_put_contents('admin.php', $content);
echo "admin.php table logic fixed.\n";

