diff --git a/admin.php b/admin.php
index e8ccd7e..478f108 100644
--- a/admin.php
+++ b/admin.php
@@ -1022,13 +1022,30 @@ if ($tab === 'users') {
Toujours vrai';
+ $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) : 'Toujours vrai';
?>
@@ -1539,6 +1556,7 @@ function editStatus(data) {
updateMSLabel('ms_terr');
document.getElementById('rule_empty').checked = data.is_empty_case == 1;
+ document.getElementById('rule_combine').value = data.combine_mode || "OR";
window.scrollTo(0,0);
}
function resetRuleForm() {
diff --git a/db/add_combine_mode_to_rules.php b/db/add_combine_mode_to_rules.php
new file mode 100644
index 0000000..9e61355
--- /dev/null
+++ b/db/add_combine_mode_to_rules.php
@@ -0,0 +1,10 @@
+exec("ALTER TABLE celestial_object_status_rules ADD COLUMN combine_mode VARCHAR(10) DEFAULT 'OR'");
+ echo "Column combine_mode added successfully.\n";
+} catch (Exception $e) {
+ echo "Error adding column: " . $e->getMessage() . "\n";
+}
+
diff --git a/includes/status_helper.php b/includes/status_helper.php
index 474de87..be53a95 100644
--- a/includes/status_helper.php
+++ b/includes/status_helper.php
@@ -54,51 +54,75 @@ function calculateCelestialStatus($planet, $db, $statuses_map) {
// Évaluation des règles
foreach ($rules as $rule) {
- $match = true;
+ // Condition Case Vide (doit matcher avant de tester le reste)
+ if ($rule['is_empty_case'] && !$is_empty) continue;
- // Condition Case Vide
- if ($rule['is_empty_case'] && !$is_empty) $match = false;
+ $match_orbite = true;
+ $match_sol = true;
+
+ $has_orb_cond = !empty($rule['orbital_count_op']) || !empty($rule['orbital_dominance']);
+ $has_sol_cond = !empty($rule['terrestrial_count_op']) || !empty($rule['terrestrial_dominance']);
- // Condition Nombre Factions Orbite
- if ($match && $rule['orbital_count_op']) {
- $match = evaluateOperator($orb_count, $rule['orbital_count_op'], $rule['orbital_count_val']);
+ // Evaluation Orbite
+ if ($rule['orbital_count_op']) {
+ if (!evaluateOperator($orb_count, $rule['orbital_count_op'], $rule['orbital_count_val'])) {
+ $match_orbite = false;
+ }
}
-
- // Condition Nombre Factions Sol
- if ($match && $rule['terrestrial_count_op']) {
- $match = evaluateOperator($terr_count, $rule['terrestrial_count_op'], $rule['terrestrial_count_val']);
- }
-
- // Condition Dominance Orbite (Multi-select)
- if ($match && !empty($rule['orbital_dominant_factions'])) {
- $allowed = explode(',', $rule['orbital_dominant_factions']);
+ if ($match_orbite && !empty($rule['orbital_dominance'])) {
+ $allowed = explode(',', $rule['orbital_dominance']);
$isIn = false;
if (!$orb_dom) {
if (in_array('none', $allowed)) $isIn = true;
} else {
if (in_array((string)$orb_dom, $allowed)) $isIn = true;
}
- if (!$isIn) $match = false;
+ if (!$isIn) $match_orbite = false;
}
- // Condition Dominance Sol (Multi-select)
- if ($match && !empty($rule['ground_dominant_factions'])) {
- $allowed = explode(',', $rule['ground_dominant_factions']);
+ // Evaluation Sol
+ if ($rule['terrestrial_count_op']) {
+ if (!evaluateOperator($terr_count, $rule['terrestrial_count_op'], $rule['terrestrial_count_val'])) {
+ $match_sol = false;
+ }
+ }
+ if ($match_sol && !empty($rule['terrestrial_dominance'])) {
+ $allowed = explode(',', $rule['terrestrial_dominance']);
$isIn = false;
if (!$terr_dom) {
if (in_array('none', $allowed)) $isIn = true;
} else {
if (in_array((string)$terr_dom, $allowed)) $isIn = true;
}
- if (!$isIn) $match = false;
+ if (!$isIn) $match_sol = false;
}
- // Condition Croisée
- if ($match && ($rule['dominance_diff_required'] ?? 0)) {
- if ($orb_dom == $terr_dom) $match = false;
+ // Application de la combinaison
+ $combine = $rule['combine_mode'] ?? 'OR';
+ $final_match = false;
+
+ if (!$has_orb_cond && !$has_sol_cond) {
+ // Pas de conditions spécifiques (ex: règle par défaut ou juste is_empty_case)
+ $final_match = true;
+ } elseif ($has_orb_cond && !$has_sol_cond) {
+ $final_match = $match_orbite;
+ } elseif (!$has_orb_cond && $has_sol_cond) {
+ $final_match = $match_sol;
+ } else {
+ // Les deux côtés ont des conditions
+ if ($combine === 'AND') {
+ $final_match = $match_orbite && $match_sol;
+ } else {
+ $final_match = $match_orbite || $match_sol;
+ }
}
- if ($match) {
+ // Condition Croisée (Dominance différente requise)
+ if ($final_match && ($rule['dominance_diff_required'] ?? 0)) {
+ if ($orb_dom == $terr_dom) $final_match = false;
+ }
+
+ if ($final_match) {
return $rule['status_slug'];
}
}
@@ -117,4 +141,4 @@ function evaluateOperator($val, $op, $target) {
case '!=': return $val != $target;
}
return true;
-}
\ No newline at end of file
+}
diff --git a/patch_admin_v5.php b/patch_admin_v5.php
new file mode 100644
index 0000000..2747e1d
--- /dev/null
+++ b/patch_admin_v5.php
@@ -0,0 +1,187 @@
+ 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 = ? 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, $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) 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]);
+ }';
+
+$handlerNew = '$terrestrial_dominance = isset($_POST[\'terrestrial_dominance\']) ? implode(\'\',\',(array)$_POST[\'terrestrial_dominance\']) : null;
+ $is_empty_case = isset($_POST[\'is_empty_case\']) ? 1 : 0;
+ $combine_mode = $_POST[\'combine_mode\'] ?? \'OR\';
+
+ 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 = ?, combine_mode = ? 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, $combine_mode, $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, combine_mode) 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, $combine_mode]);
+ }';
+
+$content = str_replace($handlerOld, $handlerNew, $content);
+
+// 2. Update UI
+$uiOld = '