38471-vm/patch_users.php
2026-02-25 17:48:02 +00:00

47 lines
2.3 KiB
PHP

<?php
$c = file_get_contents('index.php');
// Fix Add User
$find_add = ' $stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id) VALUES (?, ?, ?, ?, ?)");
try {
$stmt->execute([$username, $hashed_password, $email, $phone, $group_id]);';
$repl_add = ' $outlet_id = !empty($_POST[\'outlet_id\']) ? (int)$_POST[\'outlet_id\'] : null;
$stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id) VALUES (?, ?, ?, ?, ?, ?)");
try {
$stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id]);';
$c = str_replace($find_add, $repl_add, $c);
// Fix Edit User
$find_edit = ' if ($password) {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("UPDATE users SET username = ?, password = ?, email = ?, phone = ?, group_id = ? WHERE id = ?");
$stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $id]);
} else {
$stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ? WHERE id = ?");
$stmt->execute([$username, $email, $phone, $group_id, $id]);
}';
$repl_edit = ' $outlet_id = !empty($_POST[\'outlet_id\']) ? (int)$_POST[\'outlet_id\'] : null;
if ($password) {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("UPDATE users SET username = ?, password = ?, email = ?, phone = ?, group_id = ?, outlet_id = ? WHERE id = ?");
$stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id, $id]);
} else {
$stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, outlet_id = ? WHERE id = ?");
$stmt->execute([$username, $email, $phone, $group_id, $outlet_id, $id]);
}';
$c = str_replace($find_edit, $repl_edit, $c);
// Fix login session
$c = str_replace(
"\$_SESSION['user_role_name'] = \$u['role_name'];",
"\$_SESSION['user_role_name'] = \$u['role_name'];\n \$_SESSION['outlet_id'] = \$u['outlet_id'];",
$c
);
file_put_contents('index.php', $c);
echo "Patched users.php\n";