45 lines
2.3 KiB
PHP
45 lines
2.3 KiB
PHP
<?php
|
|
$file = 'index.php';
|
|
$content = file_get_contents($file);
|
|
|
|
// add_user backend
|
|
$old_add = <<<EOD
|
|
\$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]);
|
|
EOD;
|
|
|
|
$new_add = <<<EOD
|
|
\$outlet_ids = !empty(\$_POST['outlet_ids']) && is_array(\$_POST['outlet_ids']) ? \$_POST['outlet_ids'] : [];
|
|
\$outlet_id = !empty(\$outlet_ids) ? (int)\$outlet_ids[0] : null;
|
|
\$assigned_outlets = !empty(\$outlet_ids) ? implode(',', array_map('intval', \$outlet_ids)) : null;
|
|
|
|
\$stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
try {
|
|
\$stmt->execute([\$username, \$hashed_password, \$email, \$phone, \$group_id, \$outlet_id, \$assigned_outlets]);
|
|
EOD;
|
|
$content = str_replace($old_add, $new_add, $content);
|
|
|
|
// edit_user backend
|
|
$old_edit = <<<EOD
|
|
\$outlet_id = !empty(\$_POST['outlet_id']) ? (int)\$_POST['outlet_id'] : null;
|
|
if (\$id && \$username) {
|
|
\$stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ? WHERE id = ?");
|
|
\$stmt->execute([\$username, \$email, \$phone, \$group_id, \$status, \$outlet_id, \$id]);
|
|
EOD;
|
|
|
|
$new_edit = <<<EOD
|
|
\$outlet_ids = !empty(\$_POST['outlet_ids']) && is_array(\$_POST['outlet_ids']) ? \$_POST['outlet_ids'] : [];
|
|
\$outlet_id = !empty(\$outlet_ids) ? (int)\$outlet_ids[0] : null;
|
|
\$assigned_outlets = !empty(\$outlet_ids) ? implode(',', array_map('intval', \$outlet_ids)) : null;
|
|
|
|
if (\$id && \$username) {
|
|
\$stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?");
|
|
\$stmt->execute([\$username, \$email, \$phone, \$group_id, \$status, \$outlet_id, \$assigned_outlets, \$id]);
|
|
EOD;
|
|
$content = str_replace($old_edit, $new_edit, $content);
|
|
|
|
file_put_contents($file, $content);
|
|
echo "Patch 2 applied.\n";
|