fix: address code review - prepared stmt, first-radio auto-select, remove unused var, clarify comment
Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/4a9c8aab-3782-44a8-a5e4-01b50a813cc0 Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
parent
b3d677035b
commit
7f6fe9a39a
3 changed files with 24 additions and 15 deletions
|
|
@ -71,7 +71,6 @@ if (isset($_POST['save_matrix'])) {
|
||||||
|
|
||||||
$price_col = $period === 'daily' ? 'price_daily' : ($period === 'yearly' ? 'price_year' : 'price_monthly');
|
$price_col = $period === 'daily' ? 'price_daily' : ($period === 'yearly' ? 'price_year' : 'price_monthly');
|
||||||
$base_esc = $db->real_escape_string($base_price);
|
$base_esc = $db->real_escape_string($base_price);
|
||||||
$period_esc = $db->real_escape_string($period);
|
|
||||||
|
|
||||||
$db->query(
|
$db->query(
|
||||||
"UPDATE `{$table_prefix}billing_services`
|
"UPDATE `{$table_prefix}billing_services`
|
||||||
|
|
@ -88,23 +87,29 @@ if (isset($_POST['save_matrix'])) {
|
||||||
$allServerIds[] = (int)$rsRow['remote_server_id'];
|
$allServerIds[] = (int)$rsRow['remote_server_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stmt = $db->prepare(
|
||||||
|
"INSERT INTO `{$table_prefix}billing_service_remote_servers`
|
||||||
|
(service_id, remote_server_id, enabled, override_price)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
enabled = VALUES(enabled),
|
||||||
|
override_price = VALUES(override_price)"
|
||||||
|
);
|
||||||
foreach ((array)$postedServices as $sid => $ignored) {
|
foreach ((array)$postedServices as $sid => $ignored) {
|
||||||
$sid = (int)$sid;
|
$sid = (int)$sid;
|
||||||
foreach ($allServerIds as $rid) {
|
foreach ($allServerIds as $rid) {
|
||||||
$mapEnabled = isset($postedMappings[$sid][$rid]['enabled']) ? 1 : 0;
|
$mapEnabled = isset($postedMappings[$sid][$rid]['enabled']) ? 1 : 0;
|
||||||
$ovRaw = $postedMappings[$sid][$rid]['override_price'] ?? '';
|
$ovRaw = $postedMappings[$sid][$rid]['override_price'] ?? '';
|
||||||
$override = (trim($ovRaw) === '') ? 'NULL' : "'" . $db->real_escape_string(number_format((float)$ovRaw, 2, '.', '')) . "'";
|
$ovPrice = (trim($ovRaw) === '') ? null : number_format((float)$ovRaw, 2, '.', '');
|
||||||
|
if ($stmt) {
|
||||||
$db->query(
|
$stmt->bind_param('iisd', $sid, $rid, $mapEnabled, $ovPrice);
|
||||||
"INSERT INTO `{$table_prefix}billing_service_remote_servers`
|
$stmt->execute();
|
||||||
(service_id, remote_server_id, enabled, override_price)
|
}
|
||||||
VALUES ({$sid}, {$rid}, {$mapEnabled}, {$override})
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
enabled = VALUES(enabled),
|
|
||||||
override_price = VALUES(override_price)"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($stmt) {
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
|
||||||
$flash[] = "Matrix saved successfully.";
|
$flash[] = "Matrix saved successfully.";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,8 @@ $install_queries[1] = array(
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Version 3: Add override_price to service-to-server mapping table
|
// Version 3 (array index 2, because install_queries is zero-indexed starting from version 1):
|
||||||
|
// Add override_price to service-to-server mapping table
|
||||||
$install_queries[2] = array(
|
$install_queries[2] = array(
|
||||||
"ALTER TABLE `".OGP_DB_PREFIX."billing_service_remote_servers` ADD COLUMN `override_price` DECIMAL(10,2) NULL AFTER `enabled`"
|
"ALTER TABLE `".OGP_DB_PREFIX."billing_service_remote_servers` ADD COLUMN `override_price` DECIMAL(10,2) NULL AFTER `enabled`"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -201,12 +201,15 @@ if ($row['price_monthly'] == 0.0) {
|
||||||
ORDER BY r.remote_server_name";
|
ORDER BY r.remote_server_name";
|
||||||
$mappedResult = $db->query($mappedQuery);
|
$mappedResult = $db->query($mappedQuery);
|
||||||
if ($mappedResult) {
|
if ($mappedResult) {
|
||||||
|
$firstServer = true;
|
||||||
while ($rs = $mappedResult->fetch_assoc()) {
|
while ($rs = $mappedResult->fetch_assoc()) {
|
||||||
$rsID = (int)$rs['remote_server_id'];
|
$rsID = (int)$rs['remote_server_id'];
|
||||||
$rsNAME = htmlspecialchars((string)$rs['remote_server_name'], ENT_QUOTES, 'UTF-8');
|
$rsNAME = htmlspecialchars((string)$rs['remote_server_name'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$checked = $firstServer ? ' checked' : '';
|
||||||
$available_server = true;
|
$available_server = true;
|
||||||
|
$firstServer = false;
|
||||||
echo "<div>\n"
|
echo "<div>\n"
|
||||||
. " <input type='radio' name='ip_id' id='rs_{$rsID}' value='{$rsID}' required>\n"
|
. " <input type='radio' name='ip_id' id='rs_{$rsID}' value='{$rsID}' required{$checked}>\n"
|
||||||
. " <label for='rs_{$rsID}'>{$rsNAME}</label>\n"
|
. " <label for='rs_{$rsID}'>{$rsNAME}</label>\n"
|
||||||
. "</div>\n";
|
. "</div>\n";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue