diff --git a/admin.php b/admin.php index 22fa861..e8ccd7e 100644 --- a/admin.php +++ b/admin.php @@ -170,8 +170,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $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; - $orbital_dominance = $_POST['orbital_dominance'] ?: null; - $terrestrial_dominance = $_POST['terrestrial_dominance'] ?: null; + $orbital_dominance = isset($_POST['orbital_dominance']) ? implode(',', (array)$_POST['orbital_dominance']) : null; + $terrestrial_dominance = isset($_POST['terrestrial_dominance']) ? implode(',', (array)$_POST['terrestrial_dominance']) : null; $is_empty_case = isset($_POST['is_empty_case']) ? 1 : 0; if ($id > 0) { @@ -551,6 +551,19 @@ if ($tab === 'users') { /* Color picker custom style */ .color-group { display: flex; gap: 5px; } .color-picker-input { width: 45px !important; height: 34px !important; padding: 2px !important; border: 1px solid #334155 !important; background: #0f172a !important; cursor: pointer; } + + /* Multi-select dropdown */ + .ms-container { position: relative; width: 100%; } + .ms-display { + background: #0f172a; border: 1px solid #334155; color: #fff; padding: 8px; cursor: pointer; min-height: 34px; box-sizing: border-box; font-size: 12px; display: flex; align-items: center; justify-content: space-between; + } + .ms-display:after { content: '▼'; font-size: 8px; color: #8c92a3; } + .ms-dropdown { + position: absolute; top: 100%; left: 0; right: 0; background: #1a202c; border: 1px solid #334155; z-index: 1000; display: none; max-height: 200px; overflow-y: auto; padding: 5px; + } + .ms-item { padding: 5px 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 11px; } + .ms-item:hover { background: #2d3545; } + .ms-item input { width: auto !important; } @@ -955,29 +968,35 @@ if ($tab === 'users') { -
-
FACTION DOMINANTE :
+
+
FILTRE DOMINANCE :
+ +
- +
+
Toutes / Peu importe
+
+ + + + +
+
+ +
- +
+
Toutes / Peu importe
+
+ + + + +
+
@@ -1007,8 +1026,8 @@ if ($tab === 'users') { 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 Dom: " . $r['orbital_dominance']; - if($r['terrestrial_dominance']) $conds[] = "Ground Dom: " . $r['terrestrial_dominance']; + 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) : 'Toujours vrai'; ?> @@ -1290,7 +1309,28 @@ if ($tab === 'users') { document.getElementById('log_id').value = 0; document.getElementById('logForm').reset(); } - + + function toggleMS(id) { + const d = document.getElementById(id); + d.style.display = d.style.display === 'block' ? 'none' : 'block'; + } + function updateMSLabel(containerId) { + const container = document.getElementById(containerId); + const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked'); + const display = container.querySelector('.ms-display'); + if (checkboxes.length === 0) { + display.innerText = "Toutes / Peu importe"; + } else { + const labels = Array.from(checkboxes).map(cb => cb.parentElement.innerText.trim()); + display.innerText = labels.join(', '); + } + } + document.addEventListener('click', function(e) { + if (!e.target.closest('.ms-container')) { + document.querySelectorAll('.ms-dropdown').forEach(d => d.style.display = 'none'); + } + }); +

Système de Lootboxes

@@ -1484,12 +1524,29 @@ function editStatus(data) { 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 : ""; - document.getElementById('rule_orb_dom').value = data.orbital_dominance || ""; - document.getElementById('rule_terr_dom').value = data.terrestrial_dominance || ""; + + // Set multi-selects + const orbVals = (data.orbital_dominance || "").split(","); + document.querySelectorAll('#ms_orb_list input').forEach(cb => { + cb.checked = orbVals.includes(cb.value); + }); + updateMSLabel('ms_orb'); + + const terrVals = (data.terrestrial_dominance || "").split(","); + document.querySelectorAll('#ms_terr_list input').forEach(cb => { + cb.checked = terrVals.includes(cb.value); + }); + updateMSLabel('ms_terr'); + document.getElementById('rule_empty').checked = data.is_empty_case == 1; window.scrollTo(0,0); } - function resetRuleForm() { document.getElementById('ruleForm').reset(); document.getElementById('rule_id').value = 0; } + function resetRuleForm() { + document.getElementById('ruleForm').reset(); + document.getElementById('rule_id').value = 0; + updateMSLabel('ms_orb'); + updateMSLabel('ms_terr'); + } function editSettlementType(data) { document.getElementById('set_t_id').value = data.id; @@ -1651,6 +1708,27 @@ function editStatus(data) { if (document.getElementById('items_container').children.length === 0) addItemRow(); }; - + + function toggleMS(id) { + const d = document.getElementById(id); + d.style.display = d.style.display === 'block' ? 'none' : 'block'; + } + function updateMSLabel(containerId) { + const container = document.getElementById(containerId); + const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked'); + const display = container.querySelector('.ms-display'); + if (checkboxes.length === 0) { + display.innerText = "Toutes / Peu importe"; + } else { + const labels = Array.from(checkboxes).map(cb => cb.parentElement.innerText.trim()); + display.innerText = labels.join(', '); + } + } + document.addEventListener('click', function(e) { + if (!e.target.closest('.ms-container')) { + document.querySelectorAll('.ms-dropdown').forEach(d => d.style.display = 'none'); + } + }); + diff --git a/db/migrate_rules_minimal.php b/db/migrate_rules_minimal.php new file mode 100644 index 0000000..bb1ffbc --- /dev/null +++ b/db/migrate_rules_minimal.php @@ -0,0 +1,17 @@ +exec("ALTER TABLE celestial_object_status_rules MODIFY COLUMN orbital_dominance TEXT NULL"); + $db->exec("ALTER TABLE celestial_object_status_rules MODIFY COLUMN terrestrial_dominance TEXT NULL"); + + // Migration: ensure we handle ANY and IN/NOT IN appropriately + // Actually, I'll just use these two columns to store comma-separated IDs now. + + echo "Columns modified successfully.\n"; + +} catch (PDOException $e) { + echo "Error: " . $e->getMessage() . "\n"; +} \ No newline at end of file diff --git a/fix_admin_table.php b/fix_admin_table.php new file mode 100644 index 0000000..85a28bf --- /dev/null +++ b/fix_admin_table.php @@ -0,0 +1,13 @@ +\n
\n \n ", " \n ", $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"; + diff --git a/fix_admin_table_v2.php b/fix_admin_table_v2.php new file mode 100644 index 0000000..ca65832 --- /dev/null +++ b/fix_admin_table_v2.php @@ -0,0 +1,14 @@ +', $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."; diff --git a/patch_admin_v4.php b/patch_admin_v4.php new file mode 100644 index 0000000..b06bda1 --- /dev/null +++ b/patch_admin_v4.php @@ -0,0 +1,240 @@ + 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_dominant_factions = ?, ground_dominant_factions = ?, is_empty_case = ?, 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_dominant_factions, $ground_dominant_factions, $is_empty_case, $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_dominant_factions, ground_dominant_factions, is_empty_case, 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_dominant_factions, $ground_dominant_factions, $is_empty_case, $dominance_diff_required]); + } + header("Location: admin.php?tab=statuses&success=1"); + exit; +} +PHP; + +// Update UI +$new_ui = <<<'HTML' +
+
FILTRE DOMINANCE :
+ + +
+ +
+
N'importe laquelle
+
+
+ + +
+ + +
+ + + +
+
+
+ + +
+ +
+
N'importe laquelle
+
+
+ + +
+ + +
+ + + +
+
+
+
+HTML; + +// Update JS +$js_code = <<<'JS' + function toggleMS(id) { + const menu = document.getElementById(id + '_menu'); + const isVisible = menu.classList.contains('show'); + document.querySelectorAll('.multi-select-menu').forEach(m => m.classList.remove('show')); + if (!isVisible) menu.classList.add('show'); + } + document.addEventListener('click', function(e) { + if (!e.target.closest('.multi-select-dropdown')) { + document.querySelectorAll('.multi-select-menu').forEach(m => m.classList.remove('show')); + } + }); + function updateMSLabel(prefix) { + const any = document.getElementById(prefix + '_any'); + const cbs = document.querySelectorAll('.' + prefix + '-cb:checked'); + const btn = document.getElementById(prefix + '_btn'); + if (any && any.checked) { + btn.innerHTML = 'N\'importe laquelle '; + } else if (cbs.length === 0) { + if(any) any.checked = true; + btn.innerHTML = 'N\'importe laquelle '; + } else { + const names = Array.from(cbs).map(c => c.dataset.name); + if (names.length > 2) btn.innerHTML = names.length + ' sélectionnés '; + else btn.innerHTML = names.join(', ') + ' '; + } + } + function handleMSChange(cb, prefix, isAny) { + const any = document.getElementById(prefix + '_any'); + const others = document.querySelectorAll('.' + prefix + '-cb'); + if (isAny && cb.checked) { + others.forEach(o => o.checked = false); + } else if (!isAny && cb.checked) { + if(any) any.checked = false; + } + updateMSLabel(prefix); + } + function msAll(prefix, state) { + const any = document.getElementById(prefix + '_any'); + const others = document.querySelectorAll('.' + prefix + '-cb'); + if (state) { + if(any) any.checked = false; + others.forEach(o => o.checked = true); + } else { + others.forEach(o => o.checked = false); + if(any) any.checked = true; + } + updateMSLabel(prefix); + } + + function editRule(data) { + document.getElementById('rule_id').value = data.id; + document.getElementById('rule_name').value = data.name; + document.getElementById('rule_profile_id').value = data.profile_id || ""; + document.getElementById('rule_status_id').value = data.status_id; + document.getElementById('rule_priority').value = data.priority || 0; + 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 : ""; + + // Orbital Multi-select + const orbFactions = (data.orbital_dominant_factions || "").split(',').filter(x => x); + msAll('orb', false); + if (orbFactions.length === 0) { + document.getElementById('orb_any').checked = true; + } else { + document.getElementById('orb_any').checked = false; + orbFactions.forEach(val => { + const cb = document.querySelector(`.orb-cb[value="${val}"]`); + if(cb) cb.checked = true; + }); + } + updateMSLabel('orb'); + + // Ground Multi-select + const terrFactions = (data.ground_dominant_factions || "").split(',').filter(x => x); + msAll('terr', false); + if (terrFactions.length === 0) { + document.getElementById('terr_any').checked = true; + } else { + document.getElementById('terr_any').checked = false; + terrFactions.forEach(val => { + const cb = document.querySelector(`.terr-cb[value="${val}"]`); + if(cb) cb.checked = true; + }); + } + updateMSLabel('terr'); + + document.getElementById('rule_empty').checked = data.is_empty_case == 1; + document.getElementById('rule_diff').checked = data.dominance_diff_required == 1; + window.scrollTo(0,0); + } + + function resetRuleForm() { + document.getElementById('ruleForm').reset(); + document.getElementById('rule_id').value = 0; + msAll('orb', false); + msAll('terr', false); + } +JS; + +// Apply changes to admin.php +$content = file_get_contents('admin.php'); + +// Handler +$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', $handler_code, $content); + +// UI +$content = preg_replace('/
.*?FILTRE DOMINANCE :.*?Cas \"CASE VIDE\".*?<\/div>.*?<\/div>/s', $new_ui . "\n" . '
+
+ + +
+
+ + +
+
+
', $content); + +// JS +$content = preg_replace('/function editRule\(data\) \{.*?function resetSettlementTypeForm\(\) \{.*?\}/s', $js_code . "\n\n function editSettlementType(data) {\n document.getElementById('set_t_id').value = data.id;\n document.getElementById('set_t_name').value = data.name;\n document.getElementById('set_t_slug').value = data.slug;\n document.getElementById('set_t_desc').value = data.description;\n window.scrollTo(0,0);\n }\n function resetSettlementTypeForm() { document.getElementById('settlementTypeForm').reset(); document.getElementById('set_t_id').value = 0; }", $content); + +// Table Display - use preg_quote for exact matches or simplified regex +$content = preg_replace('/if\(\$r\[\'orbital_dominance_mode\'\] !== \'ANY\'\) \$conds\[\] = \"Orbital \" \. \$r\[\'orbital_dominance_mode\'\] \. \" \\\[\.\.\.\\\]\";/s', 'if($r[\'orbital_dominant_factions\']) $conds[] = "Orbital IN (" . $r[\'orbital_dominant_factions\'] . ")";', $content); +$content = preg_replace('/if\(\$r\[\'terrestrial_dominance_mode\'\] !== \'ANY\'\) \$conds\[\] = \"Ground \" \. \$r\[\'terrestrial_dominance_mode\'\] \. \" \\\[\.\.\.\\\]\";/s', 'if($r[\'ground_dominant_factions\']) $conds[] = "Ground IN (" . $r[\'ground_dominant_factions\'] . ")";', $content); + +file_put_contents('admin.php', $content); +echo "admin.php updated.\n"; \ No newline at end of file diff --git a/patch_css.php b/patch_css.php new file mode 100644 index 0000000..3aa7ab1 --- /dev/null +++ b/patch_css.php @@ -0,0 +1,24 @@ +"; + +$content = str_replace(' ', $css, $content); + +file_put_contents($file, $content); +echo "CSS patched"; +?> diff --git a/patch_handler_v2.php b/patch_handler_v2.php new file mode 100644 index 0000000..2deb70c --- /dev/null +++ b/patch_handler_v2.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/patch_js.php b/patch_js.php new file mode 100644 index 0000000..d9dec72 --- /dev/null +++ b/patch_js.php @@ -0,0 +1,61 @@ + x); + msAll('orb', false); + if (orbFactions.length === 0) { + document.getElementById('orb_any').checked = true; + } else { + document.getElementById('orb_any').checked = false; + orbFactions.forEach(val => { + const cb = document.querySelector(`.orb-cb[value="${val}"]`); + if(cb) cb.checked = true; + }); + } + updateMSLabel('orb'); + + // Ground Multi-select + const terrFactions = (data.ground_dominant_factions || "").split(',').filter(x => x); + msAll('terr', false); + if (terrFactions.length === 0) { + document.getElementById('terr_any').checked = true; + } else { + document.getElementById('terr_any').checked = false; + terrFactions.forEach(val => { + const cb = document.querySelector(`.terr-cb[value="${val}"]`); + if(cb) cb.checked = true; + }); + } + updateMSLabel('terr'); + + document.getElementById('rule_empty').checked = data.is_empty_case == 1; + if(document.getElementById('rule_diff')) document.getElementById('rule_diff').checked = data.dominance_diff_required == 1; + window.scrollTo(0,0); + } + + function resetRuleForm() { + document.getElementById('ruleForm').reset(); + document.getElementById('rule_id').value = 0; + msAll('orb', false); + msAll('terr', false); + } +JS; + +$content = preg_replace('/function editRule\(data\) \{.*?function resetRuleForm\(\)\{.*?\}/s', $newJs, $content); + +file_put_contents('admin.php', $content); +echo "editRule and resetRuleForm updated.\n"; + diff --git a/patch_js_v2.php b/patch_js_v2.php new file mode 100644 index 0000000..04250fc --- /dev/null +++ b/patch_js_v2.php @@ -0,0 +1,32 @@ + cb.parentElement.innerText.trim()); + display.innerText = labels.join(', '); + } + } + document.addEventListener('click', function(e) { + if (!e.target.closest('.ms-container')) { + document.querySelectorAll('.ms-dropdown').forEach(d => d.style.display = 'none'); + } + }); + "; + +$content = str_replace(' ', $js, $content); + +file_put_contents($file, $content); +echo "JS patched"; +?> diff --git a/patch_js_v3.php b/patch_js_v3.php new file mode 100644 index 0000000..b1a8e3a --- /dev/null +++ b/patch_js_v3.php @@ -0,0 +1,60 @@ + { + cb.checked = orbVals.includes(cb.value); + }); + updateMSLabel(\'ms_orb\'); + + const terrVals = (data.terrestrial_dominance || "").split(","); + document.querySelectorAll(\'#ms_terr_list input\').forEach(cb => { + cb.checked = terrVals.includes(cb.value); + }); + updateMSLabel(\'ms_terr\'); + + document.getElementById(\'rule_empty\').checked = data.is_empty_case == 1; + window.scrollTo(0,0); + } + function resetRuleForm() { + document.getElementById(\'ruleForm\').reset(); + document.getElementById(\'rule_id\').value = 0; + updateMSLabel(\'ms_orb\'); + updateMSLabel(\'ms_terr\'); + }'; + +$content = str_replace($oldJs, $newJs, $content); + +file_put_contents($file, $content); +echo "editRule and resetRuleForm updated"; +?> diff --git a/patch_table_v2.php b/patch_table_v2.php new file mode 100644 index 0000000..6a6706b --- /dev/null +++ b/patch_table_v2.php @@ -0,0 +1,16 @@ + + diff --git a/patch_ui.php b/patch_ui.php new file mode 100644 index 0000000..f435011 --- /dev/null +++ b/patch_ui.php @@ -0,0 +1,151 @@ + +
FILTRE DOMINANCE :
+ + +
+ +
+
N'importe laquelle
+
+
+ + +
+ + +
+ + + +
+
+
+ + +
+ +
+
N'importe laquelle
+
+
+ + +
+ + +
+ + + +
+
+
+ +
+
+ + +
+
+ + +
+
+HTML; + +$content = preg_replace('/
+
FACTION DOMINANTE :
+ + +
+ +
+
N\'importe laquelle
+
+
+ + +
+ + +
+ + +
+
+
+ + +
+ +
+
N\'importe laquelle
+
+
+ + +
+ + +
+ + +
+
+
+
+
+
+ + +
+
+ + +
+
/s', $content); + +file_put_contents('admin.php', $content); +echo "UI updated.\n"; diff --git a/patch_ui_v3.php b/patch_ui_v3.php new file mode 100644 index 0000000..e41ae18 --- /dev/null +++ b/patch_ui_v3.php @@ -0,0 +1,67 @@ + +
FACTION DOMINANTE :
+
+ + +
+
+ + +
+ '; + +$newUi = '
+
FILTRE DOMINANCE :
+ + +
+ +
+
Toutes / Peu importe
+
+ + + + +
+
+
+ + +
+ +
+
Toutes / Peu importe
+
+ + + + +
+
+
+
'; + +$content = str_replace($oldUi, $newUi, $content); + +file_put_contents($file, $content); +echo "UI patched"; +?>