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";