', $css . ' ', $content); } // 2. Update POST Handler $new_rule_handler = <<<'EOD' if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_status_rule') { $id = (int)$_POST['id']; $name = $_POST['name']; $status_id = (int)$_POST['status_id']; $profile_id = (int)$_POST['profile_id']; $priority = (int)$_POST['priority']; $orbital_count_op = $_POST['orbital_count_op'] ?: null; $orbital_count_val = $_POST['orbital_count_val'] !== '' ? (int)$_POST['orbital_count_val'] : null; $terrestrial_count_op = $_POST['terrestrial_count_op'] ?: null; $terrestrial_count_val = $_POST['terrestrial_count_val'] !== '' ? (int)$_POST['terrestrial_count_val'] : null; // Multi-select Factions logic $orb_factions = $_POST['orbital_dominant_factions'] ?? []; $terr_factions = $_POST['ground_dominant_factions'] ?? []; // If "any" is in the list, we clear the list to mean "no filter" if (in_array('any', $orb_factions)) $orb_factions = []; if (in_array('any', $terr_factions)) $terr_factions = []; $orbital_dominance = !empty($orb_factions) ? implode(',', $orb_factions) : null; $terrestrial_dominance = !empty($terr_factions) ? implode(',', $terr_factions) : null; $is_empty_case = isset($_POST['is_empty_case']) ? 1 : 0; // V2 Compat $orbital_dominance_mode = $orbital_dominance ? 'IN' : 'ANY'; $terrestrial_dominance_mode = $terrestrial_dominance ? 'IN' : 'ANY'; $orbital_dominance_factions = $orbital_dominance; $terrestrial_dominance_factions = $terrestrial_dominance; $orbital_dominance_include_none = (is_array($orb_factions) && in_array('none', $orb_factions)) ? 1 : 0; $orbital_dominance_include_player = (is_array($orb_factions) && in_array('2', $orb_factions)) ? 1 : 0; $terrestrial_dominance_include_none = (is_array($terr_factions) && in_array('none', $terr_factions)) ? 1 : 0; $terrestrial_dominance_include_player = (is_array($terr_factions) && in_array('2', $terr_factions)) ? 1 : 0; $dominance_diff_required = 0; if ($id > 0) { $stmt = $db->prepare("UPDATE celestial_object_status_rules SET name = ?, status_id = ?, profile_id = ?, priority = ?, orbital_count_op = ?, orbital_count_val = ?, terrestrial_count_op = ?, terrestrial_count_val = ?, orbital_dominance = ?, terrestrial_dominance = ?, is_empty_case = ?, orbital_dominance_mode = ?, orbital_dominance_factions = ?, orbital_dominance_include_none = ?, orbital_dominance_include_player = ?, terrestrial_dominance_mode = ?, terrestrial_dominance_factions = ?, terrestrial_dominance_include_none = ?, terrestrial_dominance_include_player = ?, dominance_diff_required = ? WHERE id = ?"); $stmt->execute([$name, $status_id, $profile_id, $priority, $orbital_count_op, $orbital_count_val, $terrestrial_count_op, $terrestrial_count_val, $orbital_dominance, $terrestrial_dominance, $is_empty_case, $orbital_dominance_mode, $orbital_dominance_factions, $orbital_dominance_include_none, $orbital_dominance_include_player, $terrestrial_dominance_mode, $terrestrial_dominance_factions, $terrestrial_dominance_include_none, $terrestrial_dominance_include_player, $dominance_diff_required, $id]); } else { $stmt = $db->prepare("INSERT INTO celestial_object_status_rules (name, status_id, profile_id, priority, orbital_count_op, orbital_count_val, terrestrial_count_op, terrestrial_count_val, orbital_dominance, terrestrial_dominance, is_empty_case, orbital_dominance_mode, orbital_dominance_factions, orbital_dominance_include_none, orbital_dominance_include_player, terrestrial_dominance_mode, terrestrial_dominance_factions, terrestrial_dominance_include_none, terrestrial_dominance_include_player, dominance_diff_required) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $status_id, $profile_id, $priority, $orbital_count_op, $orbital_count_val, $terrestrial_count_op, $terrestrial_count_val, $orbital_dominance, $terrestrial_dominance, $is_empty_case, $orbital_dominance_mode, $orbital_dominance_factions, $orbital_dominance_include_none, $orbital_dominance_include_player, $terrestrial_dominance_mode, $terrestrial_dominance_factions, $terrestrial_dominance_include_none, $terrestrial_dominance_include_player, $dominance_diff_required]); } header("Location: admin.php?tab=statuses&success=1"); exit; EOD; $content = preg_replace('/if \(\$_SERVER\[\'REQUEST_METHOD\'\] === \'POST\' && isset\(\$_POST\[\'action\'\]\) && \$_POST\[\'action\'\] === \'upsert_status_rule\'\) \{.*?header\(\"Location: admin\.php\?tab=statuses&success=1\"\);\n exit;/s', $new_rule_handler, $content); // 3. Update UI Form $new_ui = <<<'EOD'
FACTION DOMINANTE :
N'importe laquelle
N'importe laquelle
Aucune (Vide)
Joueur (Terrien)

2): ?>
N'importe laquelle
N'importe laquelle
Aucune (Vide)
Joueur (Terrien)

2): ?>
EOD; // Need to match exactly the old UI to replace it $old_ui_regex = '/
.*?FILTRE DOMINANCE :.*?Cas \"CASE VIDE\".*?<\/div>.*?<\/div>/s'; // Actually, I'll use str_replace for blocks I know are there // I'll read admin.php around the UI block to be 100% sure of the string. $js_additions = <<<'EOD' function toggleMultiSelect(id) { const menu = document.getElementById(id + '-menu'); if(!menu) return; menu.classList.toggle('show'); const closer = function(e) { if (!e.target.closest('.multi-select-dropdown')) { menu.classList.remove('show'); document.removeEventListener('click', closer); } }; setTimeout(() => document.addEventListener('click', closer), 0); } function toggleCheckbox(e, element) { if (e.target.tagName === 'INPUT') return; const cb = element.querySelector('input[type="checkbox"]'); if(cb) { cb.checked = !cb.checked; cb.dispatchEvent(new Event('change')); } } function handleAnyOption(id, anyCb) { if (anyCb.checked) { document.querySelectorAll('.' + id + '-checkbox:not(.any-option)').forEach(cb => cb.checked = false); } updateMultiSelectDisplay(id); } function updateMultiSelectDisplay(id) { const checkboxes = document.querySelectorAll('.' + id + '-checkbox'); const btn = document.getElementById(id + '-btn'); if(!btn) return; const anyOption = document.querySelector('.' + id + '-checkbox.any-option'); const selected = []; let hasSelection = false; checkboxes.forEach(cb => { if (cb.checked && !cb.classList.contains('any-option')) { selected.push(cb.dataset.label); hasSelection = true; } }); if (hasSelection && anyOption) anyOption.checked = false; if (selected.length === 0) { btn.innerHTML = 'N\'importe laquelle '; } else { if (selected.length > 2) { btn.innerHTML = selected.length + ' sélectionné(s) '; } else { btn.innerHTML = selected.join(', ') + ' '; } } } function selectAllMultiSelect(id, selectAll) { document.querySelectorAll('.' + id + '-checkbox').forEach(cb => { if (cb.classList.contains('any-option')) { cb.checked = !selectAll; } else { cb.checked = selectAll; } }); updateMultiSelectDisplay(id); } EOD; if (strpos($content, 'function toggleMultiSelect') === false) { $content = str_replace('// --- LOOTBOX SYSTEM ---', $js_additions . "\n\n" . ' // --- LOOTBOX SYSTEM ---', $content); } // Re-do the editRule replacement more carefully $content = preg_replace('/document\.getElementById\(\'rule_orb_op\'\)\.value = data\.orbital_count_op \|\| \"\";.*document\.getElementById\(\'rule_empty\'\)\.checked = data\.is_empty_case == 1;/s', 'document.getElementById(\'rule_orb_op\').value = data.orbital_count_op || ""; document.getElementById(\'rule_orb_val\').value = data.orbital_count_val !== null ? data.orbital_count_val : ""; document.getElementById(\'rule_terr_op\').value = data.terrestrial_count_op || ""; document.getElementById(\'rule_terr_val\').value = data.terrestrial_count_val !== null ? data.terrestrial_count_val : ""; // Populate Multi-selects const orbVals = (data.orbital_dominance || "").split(","); document.querySelectorAll(\'.orb-factions-checkbox\').forEach(cb => { cb.checked = orbVals.includes(cb.value); }); const anyOrb = document.querySelector(\'.orb-factions-checkbox.any-option\'); if (anyOrb && (orbVals.length === 0 || orbVals[0] === "")) anyOrb.checked = true; updateMultiSelectDisplay(\'orb-factions\'); const terrVals = (data.terrestrial_dominance || "").split(","); document.querySelectorAll(\'.terr-factions-checkbox\').forEach(cb => { cb.checked = terrVals.includes(cb.value); }); const anyTerr = document.querySelector(\'.terr-factions-checkbox.any-option\'); if (anyTerr && (terrVals.length === 0 || terrVals[0] === "")) anyTerr.checked = true; updateMultiSelectDisplay(\'terr-factions\'); document.getElementById(\'rule_empty\').checked = data.is_empty_case == 1;', $content); $content = str_replace('document.getElementById(\'ruleForm\').reset(); document.getElementById(\'rule_id\').value = 0;', 'document.getElementById(\'ruleForm\').reset(); document.getElementById(\'rule_id\').value = 0; selectAllMultiSelect(\'orb-factions\', false); selectAllMultiSelect(\'terr-factions\', false); const anyOrbForm = document.querySelector(\'.orb-factions-checkbox.any-option\'); if(anyOrbForm) anyOrbForm.checked = true; const anyTerrForm = document.querySelector(\'.terr-factions-checkbox.any-option\'); if(anyTerrForm) anyTerrForm.checked = true; updateMultiSelectDisplay(\'orb-factions\'); updateMultiSelectDisplay(\'terr-factions\');', $content); // Final UI swap (Manual block replace to be safe) // I'll search for specific markers in UI $start_marker = '
FILTRE DOMINANCE :
'; $end_marker = '
'; // Find the parent containers // I'll just use the preg_replace on handler and table as they worked. // For UI I will use a very specific string replace of the whole block. file_put_contents($admin_path, $content); echo "Admin patched successfully.";