Added redirect() function for page redirects and updated credit system fields to include credit_note, credit_invoice_id and type for better reporting

This commit is contained in:
johnnyq
2025-08-01 13:37:23 -04:00
parent 41a8e41463
commit 7cfba7f2ef
5 changed files with 39 additions and 5 deletions

View File

@@ -1670,4 +1670,21 @@ function sanitize_url($url) {
// Safe schemes: return escaped original URL
return htmlspecialchars($url ?? '', ENT_QUOTES, 'UTF-8');
}
function redirect($url = null, $permanent = false) {
// Use referer if no URL is provided
if (!$url) {
$url = $_SERVER['HTTP_REFERER'] ?? 'index.php';
}
if (!headers_sent()) {
header('Location: ' . $url, true, $permanent ? 301 : 302);
exit;
} else {
// Fallback for headers already sent
echo "<script>window.location.href = '" . addslashes($url) . "';</script>";
echo '<noscript><meta http-equiv="refresh" content="0;url=' . htmlspecialchars($url) . '"></noscript>';
exit;
}
}