38471-vm/patch_users_5.php
2026-02-26 03:44:24 +00:00

44 lines
2.2 KiB
PHP

<?php
$file = 'index.php';
$content = file_get_contents($file);
$old_display = <<<EOD
<span class="badge rounded-pill bg-secondary bg-opacity-10 text-secondary px-3">
<?php
\$out_name = "Global / All Outlets";
foreach ((\$data["outlets"] ?? []) as \$out) {
if (\$out["id"] == \$u["outlet_id"]) {
\$out_name = \$out["name"];
break;
}
}
echo htmlspecialchars(\$out_name);
?>
</span>
EOD;
$new_display = <<<EOD
<div class="d-flex flex-wrap gap-1">
<?php
\$out_names = [];
\$assigned = array_filter(explode(',', \$u['assigned_outlets'] ?? ''));
if (empty(\$assigned) && !empty(\$u['outlet_id'])) {
\$assigned = [\$u['outlet_id']];
}
if (empty(\$assigned)) {
echo '<span class="badge rounded-pill bg-secondary bg-opacity-10 text-secondary px-3">Global / All Outlets</span>';
} else {
foreach ((\$data["outlets"] ?? []) as \$out) {
if (in_array(\$out["id"], \$assigned)) {
echo '<span class="badge rounded-pill bg-secondary bg-opacity-10 text-secondary px-2 py-1">' . htmlspecialchars(\$out["name"]) . '</span>';
}
}
}
?>
</div>
EOD;
$content = str_replace($old_display, $new_display, $content);
file_put_contents($file, $content);
echo "Patch 5 applied.\n";