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

$oldDisplay = '                                            <?php 
                                                $conds = [];
                                                if($r[\'is_empty_case\']) $conds[] = "Case Vide";
                                                if($r[\'orbital_count_op\']) $conds[] = "Orbital Factions " . $r[\'orbital_count_op\'] . " " . $r[\'orbital_count_val\'];
                                                if($r[\'terrestrial_count_op\']) $conds[] = "Ground Factions " . $r[\'terrestrial_count_op\'] . " " . $r[\'terrestrial_count_val\'];
                                                if($r[\'orbital_dominance\']) $conds[] = "Orbital IN (" . $r[\'orbital_dominance\'] . ")";
                                                if($r[\'terrestrial_dominance\']) $conds[] = "Ground IN (" . $r[\'terrestrial_dominance\'] . ")";
                                                echo !empty($conds) ? implode(\' AND \', $conds) : \'<em>Toujours vrai</em>\';
                                            ?>';

$newDisplay = '                                            <?php 
                                                $orb_conds = [];
                                                if($r[\'orbital_count_op\']) $orb_conds[] = "Factions " . $r[\'orbital_count_op\'] . " " . $r[\'orbital_count_val\'];
                                                if($r[\'orbital_dominance\']) $orb_conds[] = "IN (" . $r[\'orbital_dominance\'] . ")";
                                                
                                                $terr_conds = [];
                                                if($r[\'terrestrial_count_op\']) $terr_conds[] = "Factions " . $r[\'terrestrial_count_op\'] . " " . $r[\'terrestrial_count_val\'];
                                                if($r[\'terrestrial_dominance\']) $terr_conds[] = "IN (" . $r[\'terrestrial_dominance\'] . ")";

                                                $final_parts = [];
                                                if ($r[\'is_empty_case\']) $final_parts[] = "Case Vide";
                                                
                                                $orb_str = !empty($orb_conds) ? "Orbital (" . implode(\' AND \', $orb_conds) . ")" : "";
                                                $terr_str = !empty($terr_conds) ? "Ground (" . implode(\' AND \', $terr_conds) . ")" : "";
                                                
                                                if ($orb_str && $terr_str) {
                                                    $sep = ($r[\'combine_mode\'] == \'AND\') ? \' AND \' : \' OR \';
                                                    $final_parts[] = $orb_str . $sep . $terr_str;
                                                } elseif ($orb_str) {
                                                    $final_parts[] = $orb_str;
                                                } elseif ($terr_str) {
                                                    $final_parts[] = $terr_str;
                                                }

                                                echo !empty($final_parts) ? implode(\' AND \', $final_parts) : \'<em>Toujours vrai</em>\';
                                            ?>';

$content = str_replace($oldDisplay, $newDisplay, $content);

file_put_contents($file, $content);
echo "admin.php table display updated successfully.\n";

