QoL 45: intval and floatval in place of int and float casts and a string cast in place of strval, redirect in place of raw Location headers wherever functions.php is loaded, redirect fallback escapes the URL with json_encode and escapeHtml, escapeHtml for the last htmlspecialchars on a page, and the plain-HTTP cookie notice through flashAlert

This commit is contained in:
johnnyq
2026-11-21 00:20:16 -05:00
parent 5cb09cee0b
commit eb79252ca0
78 changed files with 169 additions and 193 deletions

View File

@@ -438,6 +438,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Pickers: the 78 plain `<select class="form-select">` left in `agent/modals` and `admin/modals` are `select2`, so `js/itflow_select.js` draws them; it now carries `w-auto`, `flex-grow-0`, `flex-shrink-0` and an inline `max-width` from the `<select>` to the picker, so one set narrow inside an input group stays narrow. Every select in a window is the picker now - new ones should be too.
- Money: the 51 places that called `numfmt_format_currency($currency_format, ...)` themselves - client and vendor lists and pages, payment and credit messages, the client portal's home, the guest card payment page, and the report, dashboard and search helpers - call `billingMoney($amount, $currency)`, the one formatter. Left as they are: `billingMoney()` itself, `reportMoneyWhole()` (whole amounts), the trip rate (more decimals) and the localization settings' sample.
- Windows: submit buttons say Create on new-record windows and Save on edit windows; Add stays where a window adds existing things to the record it names. Every field `<label>` in `agent/modals`, `admin/modals` and `agent/user/modals` (and `agent/dispatch.php`, `inc_recurring_ticket_ahead.php`, `inc_ticket_tasks_section.php`) has `form-label` - Bootstrap 5 gives a bare label no bottom margin. `fa-file-invoice-dollar` is the invoice icon everywhere, the menus included; `fa-file-invoice` stays for statements. `agent/js/client_delete_confirm.js` toggles `disabled` on the Delete link.
- Code: `intval()` and `floatval()` in place of `(int)` and `(float)` casts, and `(string)` in place of `strval()`, as the rest of the code has them. `redirect()` in place of a raw `Location` header wherever `functions.php` is loaded - the sign-in check, the client portal's sign-up, join, reset and Microsoft 365 sign-in, the guest Knowledge Base and card payment pages and the tax package report. `redirect()`'s fallback for when output has already started writes the URL with `json_encode()` (tags, quotes and ampersands escaped) and `escapeHtml()` rather than `addslashes()` and a bare `htmlspecialchars()`. `escapeHtml()` replaces the last `htmlspecialchars()` on a page, and the plain-HTTP cookie notice goes through `flashAlert()` as a warning. Raw `mysqli_real_escape_string()` stays where HTML is stored (ticket details, replies, documents, signatures), since `escapeSql()` strips tags.
## [26.11.8]

View File

@@ -149,7 +149,7 @@ $type_noun = function ($type) {
$install_root = dirname(__DIR__);
$file_owner = '';
if (function_exists('posix_getpwuid')) {
$file_owner = (string) (posix_getpwuid((int) @fileowner($install_root . '/scripts/restore_cli.php'))['name'] ?? '');
$file_owner = (string) (posix_getpwuid(intval(@fileowner($install_root . '/scripts/restore_cli.php')))['name'] ?? '');
}
$shell_word = function ($word) {
return preg_match('/^[A-Za-z0-9_\/.@%+=:,-]+$/', $word) ? $word : escapeshellarg($word);

View File

@@ -137,7 +137,7 @@ $csrf = $_SESSION['csrf_token'];
};
$cover = array_filter([
$row['contract_template_support_hours'],
$row['contract_template_rate_standard'] !== null ? number_format((float) $row['contract_template_rate_standard'], 2) . '/hr'
$row['contract_template_rate_standard'] !== null ? number_format(floatval($row['contract_template_rate_standard']), 2) . '/hr'
: ($template_defaults['rate'] > 0 ? number_format($template_defaults['rate'], 2) . '/hr (default)' : ''),
$row['contract_template_net_terms'] !== null ? $net_text($row['contract_template_net_terms']) : $net_text($template_defaults['net_terms']) . ' (default)',
]);

View File

@@ -43,7 +43,7 @@ $managed_kept = $managed_mode === 'active' ? [] : (MANAGED_KEEP_JOBS[$managed_mo
$install_root = dirname(__DIR__);
$file_owner = '';
if (function_exists('posix_getpwuid')) {
$file_owner = (string) (posix_getpwuid((int) @fileowner($install_root . '/cron/cron.php'))['name'] ?? '');
$file_owner = (string) (posix_getpwuid(intval(@fileowner($install_root . '/cron/cron.php')))['name'] ?? '');
}
$shell_word = function ($word) {
return preg_match('/^[A-Za-z0-9_\/.@%+=:,-]+$/', $word) ? $word : escapeshellarg($word);
@@ -194,9 +194,9 @@ $took = function ($seconds) {
if ($seconds < 60) {
return round($seconds) . ' s';
}
$minutes = intdiv((int) round($seconds), 60);
$minutes = intdiv(intval(round($seconds)), 60);
if ($minutes < 60) {
return $minutes . ' min ' . ((int) round($seconds) % 60) . ' s';
return $minutes . ' min ' . (intval(round($seconds)) % 60) . ' s';
}
return intdiv($minutes, 60) . ' h ' . ($minutes % 60) . ' min';
};

View File

@@ -14,7 +14,7 @@ $t_value = function ($key, $default = '') use ($t) {
return $t !== null && array_key_exists("contract_template_$key", $t) && $t["contract_template_$key"] !== null ? $t["contract_template_$key"] : $default;
};
$t_money = function ($value) {
return $value === '' || $value === null ? '' : number_format((float) $value, 2, '.', '');
return $value === '' || $value === null ? '' : number_format(floatval($value), 2, '.', '');
};
$t_hours = function ($value) {
return floatval($value) > 0 ? rtrim(rtrim(number_format(floatval($value), 2, '.', ''), '0'), '.') : '';

View File

@@ -90,7 +90,7 @@ if (!$template) { ?>
break;
}
}
$default = $default ?: (int) array_key_first($options);
$default = $default ?: intval(array_key_first($options));
?>
<tr data-bill-id="<?= $software_id ?>">
<td class="ps-2"><input class="form-check-input" type="checkbox" name="software_ids[]" value="<?= $software_id ?>" aria-label="Bill <?= escapeHtml($row['client_name']) ?>" <?= $options ? 'checked' : 'disabled' ?>></td>

View File

@@ -83,7 +83,7 @@ if (!is_array($json) || empty($json['refresh_token']) || empty($json['access_tok
$refresh_token = (string) $json['refresh_token'];
$access_token = (string) $json['access_token'];
$expires_at = date('Y-m-d H:i:s', time() + (int)($json['expires_in'] ?? 3600));
$expires_at = date('Y-m-d H:i:s', time() + intval($json['expires_in'] ?? 3600));
$refresh_token_esc = mysqli_real_escape_string($mysqli, $refresh_token);
$access_token_esc = mysqli_real_escape_string($mysqli, $access_token);

View File

@@ -403,7 +403,7 @@ function demoIsFuture($date) {
// How much history a client gets - their whole life with us, capped at the two
// year window. Newer clients ramp up rather than appearing fully formed.
function demoClientMonths($profile) {
return max(3, min(24, (int)floor($profile['age_days'] / 30)));
return max(3, min(24, intval(floor($profile['age_days'] / 30))));
}
// ------------------------------
@@ -1978,8 +1978,8 @@ function demoBuildAssets($mysqli, $profile, $index, $client_id, $location_id, $c
// this properly is what makes the warranty, end of life and refresh
// reports show anything - a fleet where nothing is ever old is not a
// fleet anyone recognises.
$batch = (int)floor(($number - 1) / 4);
$purchase_months = min(70, 3 + ($batch * 12) + (($seed + $index) % 7) + (int)floor($profile['age_days'] / 120));
$batch = intval(floor(($number - 1) / 4));
$purchase_months = min(70, 3 + ($batch * 12) + (($seed + $index) % 7) + intval(floor($profile['age_days'] / 120)));
// A few of the oldest Windows machines never made the move to Windows 11
$os = $model[2];
if (strpos($os, 'Windows 11') === 0 && $purchase_months >= 50 && ($seed + $index) % 3 === 0) {
@@ -2561,8 +2561,8 @@ function demoSeedTicket($mysqli, $fields, $trail, $context, &$counts) {
if ($stopped_at) {
// Business minutes, approximated at eight hours to the day rather
// than pulling the business hours calculation in here
$elapsed = max(1, (int)round((strtotime($stopped_at) - strtotime($fields['ticket_created_at'])) / 60));
$days = max(1, (int)ceil($elapsed / 1440));
$elapsed = max(1, intval(round((strtotime($stopped_at) - strtotime($fields['ticket_created_at'])) / 60)));
$days = max(1, intval(ceil($elapsed / 1440)));
starterInsert($mysqli, 'sla_history', [
'sla_history_started_at' => $fields['ticket_created_at'],
'sla_history_ended_at' => $stopped_at,
@@ -2739,7 +2739,7 @@ function demoBuildTickets($mysqli, $profile, $index, $client_id, $contact_ids, $
}
// ---- Two years of closed work ----
$per_month = max(2, (int)floor($profile['seats'] / 10));
$per_month = max(2, intval(floor($profile['seats'] / 10)));
$sequence = 0;
for ($month = $months - 1; $month >= 1; $month--) {
@@ -3661,7 +3661,7 @@ function demoBuildCompanyFinancials($mysqli, $context, &$counts) {
continue;
}
// Last year's plan was set a little lower than this year's
$amount = $year < (int)date('Y') ? $budget[1] * 0.94 : $budget[1];
$amount = $year < intval(date('Y')) ? $budget[1] * 0.94 : $budget[1];
for ($month = 1; $month <= 12; $month++) {
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT budget_id FROM budget WHERE budget_category_id = $category_id AND budget_month = $month AND budget_year = $year LIMIT 1"));
if (!empty($row['budget_id'])) {
@@ -3885,7 +3885,7 @@ function demoBuildInternalDiary($mysqli, $context, &$counts) {
foreach ($fixtures as $fixture) {
// Monday a quarter back, then the weekday offset
$days_ago = (13 * 7) - $fixture[3] + (int)date('N') - 1;
$days_ago = (13 * 7) - $fixture[3] + intval(date('N')) - 1;
$start = demoDateTime($days_ago, $fixture[4], 0);
$end = date('Y-m-d H:i:s', strtotime($start . ' +' . $fixture[5] . ' hours'));
@@ -5310,7 +5310,7 @@ function demoExpandProfile($spec) {
}
// Quotes in flight
$refresh_count = max(2, (int)floor($seats / 5));
$refresh_count = max(2, intval(floor($seats / 5)));
$quotes = [
['Workstation refresh - machines past five years old', [
['Business Desktop', $refresh_count, 985.00, $foss ? 'Small form factor desktop supplied with Linux Mint and LibreOffice' : 'Small form factor desktop, 16GB memory, 512GB NVMe', 1],

View File

@@ -274,7 +274,7 @@ if (isset($_POST['test_email_imap'])) {
}
$host = $config_imap_host;
$port = (int) $config_imap_port;
$port = intval($config_imap_port);
$encryption = strtolower(trim($config_imap_encryption)); // e.g. "ssl", "tls", "none"
$username = $config_imap_username;
$password = $config_imap_password;
@@ -386,7 +386,7 @@ if (isset($_POST['test_email_imap'])) {
}
$password = $json['access_token'];
$expires_at = date('Y-m-d H:i:s', time() + (int)($json['expires_in'] ?? 3600));
$expires_at = date('Y-m-d H:i:s', time() + intval($json['expires_in'] ?? 3600));
$refresh_token_to_save = $json['refresh_token'] ?? null;
$token_esc = mysqli_real_escape_string($mysqli, $password);
@@ -501,7 +501,7 @@ if (isset($_POST['test_oauth_token_refresh'])) {
}
$new_access_token = escapeSql($json['access_token']);
$new_expires_at = date('Y-m-d H:i:s', time() + (int)($json['expires_in'] ?? 3600));
$new_expires_at = date('Y-m-d H:i:s', time() + intval($json['expires_in'] ?? 3600));
$new_refresh_token = !empty($json['refresh_token']) ? escapeSql($json['refresh_token']) : '';
$new_access_token_esc = mysqli_real_escape_string($mysqli, $new_access_token);

View File

@@ -409,7 +409,7 @@ if (!$config_module_enable_ticketing) {
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="tab" value="tests">
<input type="hidden" name="oauth_provider" value="<?= htmlspecialchars($oauth_provider_for_test) ?>">
<input type="hidden" name="oauth_provider" value="<?= escapeHtml($oauth_provider_for_test) ?>">
<p class="text-muted mb-2">Validates the refresh token and stores a new access token for <?= $oauth_provider_for_test === 'microsoft_oauth' ? 'Microsoft 365' : 'Google Workspace' ?>.</p>
<button type="submit" name="test_oauth_token_refresh" class="btn btn-success"><i class="fas fa-fw fa-sync-alt me-2"></i>Test OAuth Token Refresh</button>
</form>

View File

@@ -170,7 +170,7 @@ $confirm_text .= " Make sure you have a backup first.";
$install_root = dirname(__DIR__);
$file_owner = '';
if (function_exists('posix_getpwuid')) {
$file_owner = (string) (posix_getpwuid((int) @fileowner($install_root . '/scripts/update_cli.php'))['name'] ?? '');
$file_owner = (string) (posix_getpwuid(intval(@fileowner($install_root . '/scripts/update_cli.php')))['name'] ?? '');
}
$shell_word = function ($word) {
return preg_match('/^[A-Za-z0-9_\/.@%+=:,-]+$/', $word) ? $word : escapeshellarg($word);

View File

@@ -633,7 +633,7 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
<?php if ($open_invoices['invoices']) { ?>
<div class="list-group list-group-flush">
<?php foreach ($open_invoices['invoices'] as $invoice) {
$days_over = (int) (new DateTime('today'))->diff(new DateTime($invoice['invoice_due']))->format('%r%a') * -1;
$days_over = intval((new DateTime('today'))->diff(new DateTime($invoice['invoice_due']))->format('%r%a')) * -1;
?>
<a href="invoice.php?client_id=<?= $client_id ?>&invoice_id=<?= intval($invoice['invoice_id']) ?>" class="list-group-item list-group-item-action d-flex align-items-center gap-3 py-2">
<span class="flex-grow-1 overflow-hidden">

View File

@@ -81,7 +81,7 @@ if (!$contract || ($client_url && intval($contract['contract_client_id']) !== in
$can_link = $billing_on && $can_edit && !$recurring && (contractRecurringShouldRun($contract) || $status === 'Draft');
$currency = $session_company_currency ?? '';
$money = function ($amount) use ($currency) {
return escapeHtml(function_exists('billingMoney') ? billingMoney($amount, $currency) : number_format((float) $amount, 2));
return escapeHtml(function_exists('billingMoney') ? billingMoney($amount, $currency) : number_format(floatval($amount), 2));
};
// How far through its term it is

View File

@@ -29,7 +29,7 @@ $c_start = $c_new ? date('Y-m-d') : (string) $c_value('start_date');
$c_term = intval($c_value('term_months', 12));
$c_end = $c_new ? contractTermEnd($c_start, $c_term) : (string) $c_value('end_date');
$c_money = function ($value) {
return $value === '' || $value === null ? '' : number_format((float) $value, 2, '.', '');
return $value === '' || $value === null ? '' : number_format(floatval($value), 2, '.', '');
};
$c_hours = function ($value) {
return floatval($value) > 0 ? rtrim(rtrim(number_format(floatval($value), 2, '.', ''), '0'), '.') : '';

View File

@@ -33,7 +33,7 @@ if (!$cards) {
// What is charged - agent/post/payment.php works it out the same way
$currency = (string) $invoice['invoice_currency_code'];
$fee_rates = billingCardFeeFor($client_id);
$invoice_cents = (int) round(floatval($invoice['invoice_amount']) * 100);
$invoice_cents = intval(round(floatval($invoice['invoice_amount']) * 100));
$fee = billingCardFeeCents($invoice_cents, $fee_rates) / 100;
$charge = $invoice_cents / 100 + $fee;

View File

@@ -39,8 +39,8 @@ if (isset($_POST['add_payment'])) {
redirect();
}
$amount_cents = (int) round($amount * 100);
if ($amount_cents <= 0 || $amount_cents > (int) round($state['balance'] * 100)) {
$amount_cents = intval(round($amount * 100));
if ($amount_cents <= 0 || $amount_cents > intval(round($state['balance'] * 100))) {
flashAlert("The payment must be more than 0 and no more than the balance of " . escapeHtml(billingMoney($state['balance'], $invoice['invoice_currency_code'])), 'error');
redirect();
} else {
@@ -327,7 +327,7 @@ if (isset($_POST['add_payment_stripe'])) {
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT invoice_amount, invoice_status FROM invoices WHERE invoice_id = $invoice_id"));
$invoice_status = (string) ($row['invoice_status'] ?? '');
$invoice_amount = round(floatval($row['invoice_amount'] ?? 0) - invoicePaid($invoice_id), 2);
if (($invoice_status !== 'Sent' && $invoice_status !== 'Viewed') || (int) round($invoice_amount * 100) <= 0) {
if (($invoice_status !== 'Sent' && $invoice_status !== 'Viewed') || intval(round($invoice_amount * 100)) <= 0) {
mysqli_query($mysqli, "SELECT RELEASE_LOCK('$pay_lock')");
flashAlert("This invoice is paid, or no longer waiting for a payment", 'error');
redirect();
@@ -339,7 +339,7 @@ if (isset($_POST['add_payment_stripe'])) {
$balance_to_pay = round($invoice_amount, 2);
// The card fee, when the client pays it - as the Charge Saved Card window showed it (functions/billing_pay.php)
$balance_cents = (int) round($balance_to_pay * 100);
$balance_cents = intval(round($balance_to_pay * 100));
$fee_cents = billingCardFeeCents($balance_cents, billingCardFeeFor($client_id));
$pi_metadata = [
'itflow_client_id' => $client_id,
@@ -369,7 +369,7 @@ if (isset($_POST['add_payment_stripe'])) {
// Get details from PI
$pi_id = escapeSql($payment_intent->id);
$pi_date = date('Y-m-d', $payment_intent->created);
$pi_amount_paid = floatval(($payment_intent->amount_received / 100));
$pi_amount_paid = floatval($payment_intent->amount_received / 100);
$pi_currency = strtoupper(escapeSql($payment_intent->currency));
$pi_livemode = $payment_intent->livemode;
@@ -465,13 +465,13 @@ if (isset($_POST['add_bulk_payment'])) {
// a payment that pays the invoices exactly leaves every one of them Paid
$owed = [];
while ($row = mysqli_fetch_assoc($result_invoices)) {
$owed_cents = (int) round((floatval($row['invoice_amount']) - invoicePaid($row['invoice_id'])) * 100);
$owed_cents = intval(round((floatval($row['invoice_amount']) - invoicePaid($row['invoice_id'])) * 100));
// Nothing owed on this one - a zero-value invoice, or one paid without its status catching up
if ($owed_cents > 0) {
$owed[] = [$row, $owed_cents];
}
}
$bulk_payment_cents = (int) round($bulk_payment_amount * 100);
$bulk_payment_cents = intval(round($bulk_payment_amount * 100));
$total_owed_cents = array_sum(array_column($owed, 1));
if ($bulk_payment_cents <= 0 || $bulk_payment_cents > $total_owed_cents) {
flashAlert("The payment must be more than 0 and no more than the client's balance of " . escapeHtml(billingMoney($total_owed_cents / 100, stripslashes($currency_code))), 'error');
@@ -624,7 +624,7 @@ if (isset($_GET['refund_payment_stripe'])) {
$stripe_payment_intent_id = $matches['payment_intent'];
}
// Only this payment's part - one card payment from the client portal can pay several invoices
$refund_cents = (int) round(floatval($row['payment_amount']) * 100);
$refund_cents = intval(round(floatval($row['payment_amount']) * 100));
// Get invoice details
$sql = mysqli_query($mysqli,"SELECT client_id, client_name, contact_email, contact_extension, contact_mobile,

View File

@@ -62,9 +62,9 @@ if (mysqli_num_rows($sql) == 0) {
$rack_rows = rackLoadUnits([$rack_id])[$rack_id];
$rack_items = array_map('rackUnitView', $rack_rows);
$occupancy = rackOccupancy($rack_rows, $rack_units);
$used_percent = (int) round($occupancy['any'] / $rack_units * 100);
$used_percent = intval(round($occupancy['any'] / $rack_units * 100));
$power_used = array_sum(array_column($rack_items, 'power'));
$power_percent = $rack_power_capacity ? (int) round($power_used / $rack_power_capacity * 100) : 0;
$power_percent = $rack_power_capacity ? intval(round($power_used / $rack_power_capacity * 100)) : 0;
$item_count = count($rack_items);
$gap = $occupancy['largest_gap'];

View File

@@ -217,7 +217,7 @@ foreach ($racks as $rack_id => $row) {
$rack_client_name = escapeHtml($row['client_name']);
$rack_archived_at = $row['rack_archived_at'];
$occupancy = $row['occupancy'];
$used_percent = (int) round($occupancy['any'] / $rack_units * 100);
$used_percent = intval(round($occupancy['any'] / $rack_units * 100));
$usage_tone = $used_percent >= 90 ? 'danger' : ($used_percent >= 75 ? 'warning' : 'primary');
$rack_items = array_map('rackUnitView', $racks_units[$rack_id]);
$power_used = array_sum(array_column($rack_items, 'power'));

View File

@@ -450,8 +450,7 @@ function taxPackageSend($writer, array $tables, $from, $to, $rate, $label, $pack
$zip = new ZipArchive();
if ($zip->open($zip_path, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
flashAlert('The package could not be made - the server could not write to uploads/tmp.', 'error');
header('Location: ' . reportUrl(['export' => null]));
return;
redirect(reportUrl(['export' => null]));
}
// Whatever ends the request, the package does not stay on the server
register_shutdown_function(function () use ($zip_path) {
@@ -598,8 +597,7 @@ function taxPackageSend($writer, array $tables, $from, $to, $rate, $label, $pack
if (!$zip->close()) {
flashAlert('The package could not be made - the server could not write to uploads/tmp.', 'error');
header('Location: ' . reportUrl(['export' => null]));
return;
redirect(reportUrl(['export' => null]));
}
// $session_name is SQL-safe already - see reportCsv()

View File

@@ -124,9 +124,9 @@ $sql_api_perms = mysqli_query($mysqli,
"SELECT client_id, permission_type FROM user_client_permissions WHERE user_id = $session_user_id");
while ($sql_api_perms && $prow = mysqli_fetch_assoc($sql_api_perms)) {
if ($prow['permission_type'] === 'deny') {
$client_deny_array[] = (int) $prow['client_id'];
$client_deny_array[] = intval($prow['client_id']);
} else {
$client_access_array[] = (int) $prow['client_id'];
$client_access_array[] = intval($prow['client_id']);
}
}

View File

@@ -91,7 +91,7 @@ if ($client_ok) {
$invoice = billingRow('invoice', $invoice_id, false);
$reference = billingNumber('invoice', $invoice);
$return_arr['invoice_reference'] = $reference;
$return_arr['amount'] = (float) $invoice['invoice_amount'];
$return_arr['amount'] = floatval($invoice['invoice_amount']);
$return_arr['url'] = billingGuestUrl('invoice', $invoice);
$reference = escapeSql($reference);

View File

@@ -70,7 +70,7 @@ if ($invoice) {
$reference = $payment_set['reference'] ?? '';
$refuse = '';
if ((int) round($amount * 100) > (int) round($state['balance'] * 100)) {
if (intval(round($amount * 100)) > intval(round($state['balance'] * 100))) {
$refuse = 'amount is more than is owed on ' . $reference_text . ' - ' . billingMoney($state['balance'], $currency) . '.';
} elseif (!isset(paymentAccounts()[$account_id])) {
$refuse = 'account_id is needed - the account it went into. There is no default payment account (Admin > Settings > Invoices and billing).';

View File

@@ -55,7 +55,7 @@ if ($payment_row) {
// No more than the invoice's total with its other payments
$others = invoicePaid($invoice_id) - floatval($payment_row['payment_amount']);
$room = round(floatval($payment_row['invoice_amount']) - $others, 2);
if ((int) round($amount * 100) > (int) round($room * 100)) {
if (intval(round($amount * 100)) > intval(round($room * 100))) {
http_response_code(400);
$return_arr['success'] = "False";
$return_arr['message'] = "amount is more than $reference_text has left to pay with its other payments - " . billingMoney(max(0, $room), $payment_row['invoice_currency_code']) . '.';

View File

@@ -92,7 +92,7 @@ if ($client_ok) {
$quote = billingRow('quote', $quote_id, false);
$reference = billingNumber('quote', $quote);
$return_arr['quote_reference'] = $reference;
$return_arr['amount'] = (float) $quote['quote_amount'];
$return_arr['amount'] = floatval($quote['quote_amount']);
$return_arr['url'] = billingGuestUrl('quote', $quote);
$reference = escapeSql($reference);

View File

@@ -51,7 +51,7 @@ $insert_id = $recurring_invoice_id;
$recurring = billingRow('recurring', $recurring_invoice_id, false);
$reference = billingNumber('recurring', $recurring);
$return_arr['recurring_invoice_reference'] = $reference;
$return_arr['amount'] = (float) $recurring['recurring_invoice_amount'];
$return_arr['amount'] = floatval($recurring['recurring_invoice_amount']);
logAudit("Recurring Invoice", "Create", escapeSql("Created recurring invoice $reference - " . $recurring['recurring_invoice_scope'] . " via API ($api_key_name)"), $client_id, $recurring_invoice_id);
logAudit("API", "Success", escapeSql("Created recurring invoice $reference via API ($api_key_name)"), $client_id);
@@ -72,7 +72,7 @@ if (intval($_POST['invoice_now'] ?? 0) === 1) {
$return_arr['invoice'] = [
'invoice_id' => $invoice_id,
'reference' => billingNumber('invoice', $invoice),
'amount' => (float) $invoice['invoice_amount'],
'amount' => floatval($invoice['invoice_amount']),
'currency' => (string) $invoice['invoice_currency_code'],
'due' => (string) $invoice['invoice_due'],
'status' => (string) $invoice['invoice_status'],

View File

@@ -29,7 +29,7 @@ foreach ($tabs as $key => $info) {
$counts[$key] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM logs WHERE $scope AND {$info['where']}"))[0]);
}
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -35,7 +35,7 @@ $counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT "
$tab = isset($groups[$_GET['tab'] ?? '']) ? $_GET['tab'] : 'all';
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -37,7 +37,7 @@ $counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT "
// The tab with something to sign when there is one, else the ones in force, else all
$tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : ($counts['waiting'] ? 'waiting' : ($counts['active'] ? 'active' : 'all'));
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -37,7 +37,7 @@ if ($q !== '') {
$where .= " AND (document_name LIKE '%$q_sql%' OR document_description LIKE '%$q_sql%' OR document_content_raw LIKE '%$q_sql%')";
}
$total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM documents WHERE $where"))[0]);
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -42,7 +42,7 @@ $cards = billingStripeProvider() !== null;
$can_pay = $owing && $cards && billingOnlinePayAllowed($state['balance']);
// The card fee on paying the balance by card, when the client pays one - autopay adds it too
$fee_rates = $cards ? billingCardFeeFor($session_client_id) : null;
$card_fee = billingCardFeeCents((int) round($state['balance'] * 100), $fee_rates) / 100;
$card_fee = billingCardFeeCents(intval(round($state['balance'] * 100)), $fee_rates) / 100;
// The other invoices still owed, to pay with this one
$others = array_filter(billingClientOpenInvoices($session_client_id), function ($row) use ($invoice_id) {

View File

@@ -39,7 +39,7 @@ $counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT "
// The To pay tab when there is something to pay, else all of them
$tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : ($counts['open'] ? 'open' : 'all');
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -19,8 +19,7 @@ require_once '../functions.php';
require_once '../includes/load_global_settings.php';
if (intval($config_client_portal_enable) !== 1 || !portalInvitesReady()) {
header("Location: /login.php");
exit();
redirect("/login.php");
}
require_once __DIR__ . "/../includes/session_init.php";
@@ -65,8 +64,7 @@ if ($invite && $link['state'] === 'pending') {
? 'Sign in with your Microsoft 365 account below.'
: 'Sign in with ' . $invite['invite_email'] . ' and your new password.');
$_SESSION['login_message_type'] = 'success';
header("Location: /login.php");
exit();
redirect("/login.php");
}
// Used in the meantime - say so rather than show the form again
$link = portalInviteByLink($invite_id, $token);

View File

@@ -45,7 +45,7 @@ $total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM kb_
if ($q !== '' && !$total && $category === null && !portalViewingAs()) {
kbSearchMissSave($q, 'portal', $session_client_id);
}
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -23,8 +23,7 @@ $settings = mysqli_fetch_assoc($sql_settings);
// No portal, no portal sign-in - as with a password
if (intval($settings['config_client_portal_enable'] ?? 0) !== 1) {
header("Location: ../login.php");
exit();
redirect("../login.php");
}
$client_id = $settings['config_azure_client_id'];
@@ -61,8 +60,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && !isset($_GET['code']) && !isset($_GET
'scope' => 'https://graph.microsoft.com/User.Read',
'state' => $state);
header('Location: '.$auth_code_url.'?'.http_build_query($params));
exit();
redirect($auth_code_url . '?' . http_build_query($params));
}
@@ -79,14 +77,12 @@ if (isset($_GET['code']) || isset($_GET['error'])) {
if (!empty($_GET['error'])) {
$_SESSION['login_message'] = 'Something went wrong with logging you in: Microsoft returned an error. Please try again.';
header("Location: ../login.php");
exit();
redirect("../login.php");
}
if (empty($state) || empty($session_state) || !hash_equals($session_state, $state) || time() > $session_state_expires) {
$_SESSION['login_message'] = 'Something went wrong with logging you in: the sign-in request could not be verified. Please try again.';
header("Location: ../login.php");
exit();
redirect("../login.php");
}
$params = array (
@@ -132,8 +128,7 @@ if (isset($_GET['code']) || isset($_GET['error'])) {
// Something went wrong verifying the token/using the Graph API - quit
error_log("ITFlow: MS Graph API error during client portal Entra login: " . json_encode($msgraph_response['error']));
$_SESSION['login_message'] = 'Something went wrong with logging you in: could not read your profile from Microsoft. Please try again.';
header("Location: ../login.php");
exit();
redirect("../login.php");
} elseif (isset($msgraph_response['id'])) {
@@ -177,7 +172,7 @@ if (isset($_GET['code']) || isset($_GET['error'])) {
// Logging
logAudit("Client Login", "Success", "Client contact $upn successfully logged in via Entra", $client_id, $user_id);
header("Location: index.php");
redirect("index.php");
} else {
@@ -187,27 +182,22 @@ if (isset($_GET['code']) || isset($_GET['error'])) {
$_SESSION['login_message'] = 'Something went wrong with logging you in: Your account is not configured for Entra SSO. Please ensure you are setup in ITFlow as a contact and have Entra SSO configured.';
header("Location: ../login.php");
redirect("../login.php");
}
exit();
}
header('Location: index.php');
exit();
redirect('index.php');
} else {
error_log("ITFlow: no access_token returned during client portal Entra login");
$_SESSION['login_message'] = 'Something went wrong with logging you in: Microsoft did not return an access token. Please try again.';
header("Location: ../login.php");
exit();
redirect("../login.php");
}
}
// If the user is just sat on the page, send them back to log in to try again
header("Location: ../login.php");
exit();
redirect("../login.php");

View File

@@ -19,8 +19,7 @@ require_once '../functions.php';
require_once '../includes/load_global_settings.php';
if (intval($config_client_portal_enable) !== 1) {
header("Location: /login.php");
exit();
redirect("/login.php");
}
require_once __DIR__ . "/../includes/session_init.php";
@@ -99,8 +98,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password_reset_email_
portalMailAccountChange($link_user['user_email'], $link_user['contact_name'], 'password_link');
$_SESSION['login_message'] = 'Your password is set - sign in with it below.';
$_SESSION['login_message_type'] = 'success';
header("Location: /login.php");
exit();
redirect("/login.php");
}
} elseif (isset($_GET['token'])) {

View File

@@ -18,7 +18,7 @@ $per_page = 20;
$page = max(1, intval($_GET['page'] ?? 1));
$list = billingClientPayments($session_client_id, $per_page, ($page - 1) * $per_page);
$total = $list['total'];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
if ($page > $pages) {
$page = $pages;
$list = billingClientPayments($session_client_id, $per_page, ($page - 1) * $per_page);

View File

@@ -36,7 +36,7 @@ $counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT "
// The waiting tab when something is waiting, else all of them
$tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : ($counts['waiting'] ? 'waiting' : 'all');
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -17,8 +17,7 @@ require_once '../functions.php';
require_once '../includes/load_global_settings.php';
if (!portalSignupOpen()) {
header("Location: /login.php");
exit();
redirect("/login.php");
}
require_once __DIR__ . "/../includes/session_init.php";

View File

@@ -41,7 +41,7 @@ foreach ($tabs as $key => $t) {
$counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " $from")));
$total = $counts[$tab];
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min($page, $pages);
$offset = ($page - 1) * $per_page;

View File

@@ -30,7 +30,7 @@ $ticked = [];
$total_cents = 0;
$currency = '';
foreach ($open as $i => $row) {
$cents = (int) round((floatval($row['invoice_amount']) - floatval($row['paid'])) * 100);
$cents = intval(round((floatval($row['invoice_amount']) - floatval($row['paid'])) * 100));
$open[$i]['cents'] = $cents;
$currency = $currency ?: strtoupper((string) $row['invoice_currency_code']);
// One payment can carry so many invoices - the oldest are ticked first
@@ -39,7 +39,7 @@ foreach ($open as $i => $row) {
$total_cents += $cents;
}
}
$limit_cents = $provider ? (int) round(floatval($provider['payment_provider_threshold']) * 100) : 0;
$limit_cents = $provider ? intval(round(floatval($provider['payment_provider_threshold']) * 100)) : 0;
// The card fee, worked out again by js/portal.js as the ticks change - in hundredths of a percent and cents
$fee_rates = $provider ? billingCardFeeFor($session_client_id) : null;
$fee_cents = billingCardFeeCents($total_cents, $fee_rates);
@@ -72,7 +72,7 @@ $pay_token = bin2hex(random_bytes(16));
<form action="post.php" method="post" data-portal-pay data-portal-once
data-pay-currency="<?= escapeHtml($currency) ?>" data-pay-locale="<?= escapeHtml($locale) ?>" data-pay-limit="<?= $limit_cents ?>" data-pay-max="<?= BILLING_PAY_MAX_INVOICES ?>"<?php if ($fee_rates) { ?>
data-pay-fee-percent="<?= (int) round($fee_rates['percent'] * 100) ?>" data-pay-fee-fixed="<?= (int) round($fee_rates['fixed'] * 100) ?>"<?php } ?>>
data-pay-fee-percent="<?= intval(round($fee_rates['percent'] * 100)) ?>" data-pay-fee-fixed="<?= intval(round($fee_rates['fixed'] * 100)) ?>"<?php } ?>>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="pay_token" value="<?= $pay_token ?>">

View File

@@ -111,7 +111,7 @@ function apiKeyStatePill(array $row, $role) {
if ($problem !== '') {
return '<span class="badge rounded-pill bg-danger-subtle text-danger-emphasis fw-normal" title="Every call is turned away until it acts as an active agent with a role"><i class="fas fa-exclamation-triangle me-1"></i>Won\'t work - ' . escapeHtml($problem) . '</span>';
}
$days = (int) floor((strtotime($row['api_key_expire']) - strtotime(date('Y-m-d'))) / 86400);
$days = intval(floor((strtotime($row['api_key_expire']) - strtotime(date('Y-m-d'))) / 86400));
if ($days <= 14) {
return '<span class="badge rounded-pill bg-warning-subtle text-warning-emphasis fw-normal" title="It stops working on ' . $expire . '"><i class="fas fa-hourglass-half me-1"></i>Expires in ' . $days . ' day' . ($days === 1 ? '' : 's') . '</span>';
}

View File

@@ -189,7 +189,7 @@ function getFieldById($table, $id, $field) {
}
// Sanitize id as an integer
$id = (int)$id;
$id = intval($id);
/*
* Get the list of columns from the table, to find the primary key and to
@@ -808,12 +808,12 @@ function addToMailQueue($data) {
global $mysqli;
foreach ($data as $email) {
$from = strval($email['from']);
$from_name = strval($email['from_name']);
$recipient = strval($email['recipient']);
$recipient_name = strval($email['recipient_name']);
$subject = strval($email['subject']);
$body = strval($email['body']);
$from = (string) $email['from'];
$from_name = (string) $email['from_name'];
$recipient = (string) $email['recipient'];
$recipient_name = (string) $email['recipient_name'];
$subject = (string) $email['subject'];
$body = (string) $email['body'];
$cal_str = '';
if (isset($email['cal_str'])) {
@@ -832,8 +832,8 @@ function addToMailQueue($data) {
}
// A picture in the message goes in inline, where its cid: points (emailInlineImages())
$attachment_manifest[] = [
'path' => strval($attachment['path']),
'name' => strval($attachment['name'])
'path' => (string) $attachment['path'],
'name' => (string) $attachment['name']
] + (!empty($attachment['cid']) ? ['cid' => preg_replace('/[^A-Za-z0-9@._-]/', '', (string) $attachment['cid'])] : []);
}
if ($attachment_manifest) {

View File

@@ -131,7 +131,7 @@ function assetWarranty($warranty_expire, $soon_days = 90) {
return null;
}
$today = new DateTime('today');
$days = (int) $today->diff($expires)->format('%r%a');
$days = intval($today->diff($expires)->format('%r%a'));
$date = $expires->format('Y-m-d');
if ($days < 0) {

View File

@@ -287,7 +287,7 @@ function assetSpecs($asset_id) {
/** A number as it was meant - 16, not 16.00; 1.5 as typed. */
function assetSpecNumber($value) {
$value = (float) $value;
$value = floatval($value);
return rtrim(rtrim(number_format($value, 2, '.', ''), '0'), '.');
}
@@ -314,8 +314,8 @@ function assetSpecsFromInput($asset_type, $input, $client_id, $asset_id = 0, &$p
switch ($spec['input']) {
case 'number':
$number = str_replace(',', '', $value);
if (!is_numeric($number) || (float) $number < ($spec['min'] ?? 0) || (float) $number > ($spec['max'] ?? PHP_INT_MAX)
|| (($spec['step'] ?? 'any') === 1 && floor((float) $number) != (float) $number)) {
if (!is_numeric($number) || floatval($number) < ($spec['min'] ?? 0) || floatval($number) > ($spec['max'] ?? PHP_INT_MAX)
|| (($spec['step'] ?? 'any') === 1 && floor(floatval($number)) != floatval($number))) {
$problems[] = $spec['label'] . ': ' . (($spec['step'] ?? 'any') === 1 ? 'a whole number' : 'a number') . ' from ' . ($spec['min'] ?? 0) . ' to ' . ($spec['max'] ?? '') . (isset($spec['unit']) ? ' ' . $spec['unit'] : '');
continue 2;
}

View File

@@ -249,8 +249,8 @@ function enforceClientAccess($client_id = null) {
return true;
}
$client_id = (int) $client_id;
$session_user_id = (int) $session_user_id;
$client_id = intval($client_id);
$session_user_id = intval($session_user_id);
if (empty($client_id) || empty($session_user_id)) {
flashAlert('Access Denied.', 'error');

View File

@@ -1474,7 +1474,7 @@ function backupParseIniBytes($value): int
}
$unit = strtolower(substr($value, -1));
$number = (int)$value;
$number = intval($value);
switch ($unit) {
case 'g':
@@ -1490,7 +1490,7 @@ function backupParseIniBytes($value): int
function backupFormatBytes($bytes): string
{
$bytes = (float)$bytes;
$bytes = floatval($bytes);
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$i = 0;
while ($bytes >= 1024 && $i < count($units) - 1) {

View File

@@ -123,7 +123,7 @@ function billingReminderNext(array $invoice, ?array $rules = null, $late_only =
}
$today = new DateTime('today');
$due_date = new DateTime($due);
$from = (int) $due_date->diff($today)->format('%r%a') + 1;
$from = intval($due_date->diff($today)->format('%r%a')) + 1;
if ($late_only) {
$from = max($from, 1);
}

View File

@@ -198,8 +198,8 @@ function billingCardFeeCents($cents, $rates) {
if (!$rates || $cents <= 0) {
return 0;
}
$keep = 10000 - (int) round(floatval($rates['percent']) * 100); // what Stripe leaves, in hundredths of a percent
$fixed = (int) round(floatval($rates['fixed']) * 100);
$keep = 10000 - intval(round(floatval($rates['percent']) * 100)); // what Stripe leaves, in hundredths of a percent
$fixed = intval(round(floatval($rates['fixed']) * 100));
if ($keep <= 0) {
return 0;
}
@@ -502,7 +502,7 @@ function billingPaySelection($client_id, array $invoice_ids, &$error = '') {
return null;
}
$row = $open[$id];
$cents = (int) round((floatval($row['invoice_amount']) - floatval($row['paid'])) * 100);
$cents = intval(round((floatval($row['invoice_amount']) - floatval($row['paid'])) * 100));
$currency = strtoupper((string) $row['invoice_currency_code']);
if ($selection['currency'] !== '' && $currency !== $selection['currency']) {
$error = 'Those invoices are in different currencies - pay each currency on its own';

View File

@@ -335,7 +335,7 @@ function expandRecurringEvent(array $event, $window_start, $window_end, $limit =
$until = !empty($event['event_repeat_until']) ? substr($event['event_repeat_until'], 0, 10) . ' 23:59:59' : null;
$skip = array_flip(calendarSkippedDates($event));
$step = ['Day' => 'day', 'Week' => 'week', 'Month' => 'month', 'Year' => 'year'][$repeat];
$base_day = (int) $base->format('j');
$base_day = intval($base->format('j'));
$by_day = calendarEventByDay($event);
$occurrences = [];
@@ -344,12 +344,12 @@ function expandRecurringEvent(array $event, $window_start, $window_end, $limit =
$candidate = clone $base;
if ($i > 0 && $by_day !== '') {
// Stepped from the 1st, so no month is passed over, then put on the rule's day - at the same time
$candidate->setDate((int) $base->format('Y'), (int) $base->format('n'), 1);
$candidate->setDate(intval($base->format('Y')), intval($base->format('n')), 1);
$candidate->modify('+' . ($i * $interval) . " $step");
$candidate->setDate((int) $candidate->format('Y'), (int) $candidate->format('n'), (int) substr(byDayDate((int) $candidate->format('Y'), (int) $candidate->format('n'), $by_day), 8, 2));
$candidate->setDate(intval($candidate->format('Y')), intval($candidate->format('n')), intval(substr(byDayDate(intval($candidate->format('Y')), intval($candidate->format('n')), $by_day), 8, 2)));
} elseif ($i > 0) {
$candidate->modify('+' . ($i * $interval) . " $step");
if (($step === 'month' || $step === 'year') && (int) $candidate->format('j') !== $base_day) {
if (($step === 'month' || $step === 'year') && intval($candidate->format('j')) !== $base_day) {
if ($candidate > $to) {
break;
}

View File

@@ -483,7 +483,7 @@ function clientOverviewRenewals($client_id, $days = 45) {
$items[] = [
'kind' => $kind, 'icon' => $icon, 'label' => $label,
'name' => $row['name'], 'date' => $row['d'],
'days' => (int) $today->diff($date)->format('%r%a'),
'days' => intval($today->diff($date)->format('%r%a')),
'url' => in_array($kind, ['domain', 'certificate', 'warranty', 'retire', 'software'], true) ? $url . intval($row['id']) : $url . rawurlencode($row['name']),
];
}

View File

@@ -448,9 +448,9 @@ function getDomainExpirationDate($domain) {
// Fallback - handles ISO 8601 (2026-07-05T04:00:00Z) and most everything else
$parsedDate = date_create($expireDate);
if ($parsedDate) {
$year = (int) $parsedDate->format('Y');
$year = intval($parsedDate->format('Y'));
// Reject obviously bogus parses
if ($year >= 1995 && $year <= ((int) date('Y') + 100)) {
if ($year >= 1995 && $year <= (intval(date('Y')) + 100)) {
return $parsedDate->format('Y-m-d');
}
}

View File

@@ -375,7 +375,7 @@ function expenseImportLines(array $rows, array $map) {
} else {
$debit = $map['debit'] !== null ? expenseImportAmount($cells[$map['debit']] ?? '') : null;
$credit = $map['credit'] !== null ? expenseImportAmount($cells[$map['credit']] ?? '') : null;
$amount = $debit === null && $credit === null ? null : round(abs((float) $debit) - abs((float) $credit), 2);
$amount = $debit === null && $credit === null ? null : round(abs(floatval($debit)) - abs(floatval($credit)), 2);
}
// Totals and notes - nothing like a date where the date goes
if (($date === null && $amount === null) || ($date === null && !preg_match('/\d/', (string) ($cells[$map['date']] ?? '')))) {
@@ -570,7 +570,7 @@ function expenseImportMatch(array $lines) {
function expenseImportKeys($account_id, array $lines) {
$seen = [];
foreach ($lines as $i => $line) {
$base = intval($account_id) . '|' . $line['date'] . '|' . number_format((float) $line['amount'], 2, '.', '') . '|' . mb_strtolower(preg_replace('/\s+/u', ' ', $line['description']));
$base = intval($account_id) . '|' . $line['date'] . '|' . number_format(floatval($line['amount']), 2, '.', '') . '|' . mb_strtolower(preg_replace('/\s+/u', ' ', $line['description']));
$seen[$base] = ($seen[$base] ?? 0) + 1;
$lines[$i]['key_hash'] = hash('sha256', $base . '|' . $seen[$base]);
}

View File

@@ -254,7 +254,7 @@ function saveTicketAttachments($ticket_id, $reply_id = null, $field_name = 'atta
$stored_attachments[] = [
'name' => $single_file['name'],
'path' => "uploads/tickets/$ticket_id/$attachment_reference_name",
'size' => (int) $single_file['size']
'size' => intval($single_file['size'])
];
}

View File

@@ -451,7 +451,7 @@ function selectOptionAsset($asset_type, $description = '') {
}
function roundUpToNearestMultiple($n, $increment = 1000) {
return (int) ($increment * ceil($n / $increment));
return intval($increment * ceil($n / $increment));
}
@@ -562,10 +562,10 @@ function secondsToTime($inputSeconds) {
// Format and return
$timeParts = [];
$sections = [
'day' => (int)$days,
'hour' => (int)$hours,
'minute' => (int)$minutes,
'second' => (int)$seconds,
'day' => intval($days),
'hour' => intval($hours),
'minute' => intval($minutes),
'second' => intval($seconds),
];
foreach ($sections as $name => $value) {

View File

@@ -185,9 +185,9 @@ function incomeImportPickInvoices(array $invoices, $amount) {
if (!$invoices || $amount <= 0) {
return [[], ''];
}
$cents = (int) round($amount * 100);
$cents = intval(round($amount * 100));
foreach ($invoices as $invoice) {
if ((int) round($invoice['balance'] * 100) === $cents) {
if (intval(round($invoice['balance'] * 100)) === $cents) {
return [[$invoice['invoice_id']], 'exact'];
}
}
@@ -199,7 +199,7 @@ function incomeImportPickInvoices(array $invoices, $amount) {
$ids = [];
for ($i = 0; $i < $count; $i++) {
if ($mask & (1 << $i)) {
$sum += (int) round($invoices[$i]['balance'] * 100);
$sum += intval(round($invoices[$i]['balance'] * 100));
$ids[] = $invoices[$i]['invoice_id'];
}
}
@@ -214,7 +214,7 @@ function incomeImportPickInvoices(array $invoices, $amount) {
$ids = [];
foreach ($invoices as $invoice) {
$ids[] = $invoice['invoice_id'];
$total += (int) round($invoice['balance'] * 100);
$total += intval(round($invoice['balance'] * 100));
if ($total >= $cents) {
return [$ids, 'oldest'];
}
@@ -338,13 +338,13 @@ function incomeImportMatch(array $lines, $account_id, $default_method = '') {
foreach ($by_client as $client_id => $invoices) {
$cents = 0;
foreach ($invoices as $invoice) {
$cents += (int) round($invoice['balance'] * 100);
$cents += intval(round($invoice['balance'] * 100));
}
$client_totals[$cents][] = $client_id;
}
$balances = [];
foreach ($open as $invoice) {
$balances[(int) round($invoice['balance'] * 100)][] = $invoice['invoice_id'];
$balances[intval(round($invoice['balance'] * 100))][] = $invoice['invoice_id'];
}
$money = function ($amount, $currency = '') {
return billingMoney($amount, $currency);
@@ -361,7 +361,7 @@ function incomeImportMatch(array $lines, $account_id, $default_method = '') {
continue;
}
$amount = $line['amount'];
$cents = (int) round($amount * 100);
$cents = intval(round($amount * 100));
$pay = function ($client_id, $invoices, $matched, $note) use (&$line, $amount) {
[$ids, $how] = incomeImportPickInvoices($invoices, $amount);
$line['action'] = 'payment';
@@ -388,7 +388,7 @@ function incomeImportMatch(array $lines, $account_id, $default_method = '') {
$line['action'] = 'payment';
$line['client_id'] = $client_id;
$line['invoice_ids'] = array_column($named, 'invoice_id');
$owed = (int) round(array_sum(array_column($named, 'balance')) * 100);
$owed = intval(round(array_sum(array_column($named, 'balance')) * 100));
$line['how'] = $owed === $cents ? (count($named) > 1 ? 'sum' : 'exact') : ($owed > $cents ? 'oldest' : 'over');
$line['matched'] = 'number';
$line['match_note'] = "$refs in the text";
@@ -543,9 +543,9 @@ function incomeImportDuplicates($account_id, array $lines) {
WHERE payment_account_id = $account_id AND payment_import_key IS NULL AND payment_archived_at IS NULL AND payment_date BETWEEN '$from' AND '$to'
ORDER BY payment_date, payment_id");
while ($row = mysqli_fetch_assoc($sql)) {
$singles[] = ['type' => 'payment', 'ids' => [intval($row['payment_id'])], 'date' => $row['payment_date'], 'cents' => (int) round($row['payment_amount'] * 100),
$singles[] = ['type' => 'payment', 'ids' => [intval($row['payment_id'])], 'date' => $row['payment_date'], 'cents' => intval(round($row['payment_amount'] * 100)),
'label' => 'Payment on ' . ($row['what'] !== '' ? $row['what'] : 'an invoice') . ' on ' . $row['payment_date']];
$days[$row['payment_date']][] = ['id' => intval($row['payment_id']), 'cents' => (int) round($row['payment_amount'] * 100), 'what' => $row['what']];
$days[$row['payment_date']][] = ['id' => intval($row['payment_id']), 'cents' => intval(round($row['payment_amount'] * 100)), 'what' => $row['what']];
}
$sql = mysqli_query($mysqli, "SELECT revenue_id, revenue_date, revenue_amount, revenue_description, category_name, transfer_id FROM revenues
LEFT JOIN categories ON category_id = revenue_category_id
@@ -554,7 +554,7 @@ function incomeImportDuplicates($account_id, array $lines) {
ORDER BY revenue_date, revenue_id");
while ($row = mysqli_fetch_assoc($sql)) {
$what = $row['transfer_id'] !== null ? 'A transfer in' : (trim(strtok((string) $row['revenue_description'], "\n")) ?: ($row['category_name'] ?: 'Other income'));
$singles[] = ['type' => 'revenue', 'ids' => [intval($row['revenue_id'])], 'date' => $row['revenue_date'], 'cents' => (int) round($row['revenue_amount'] * 100),
$singles[] = ['type' => 'revenue', 'ids' => [intval($row['revenue_id'])], 'date' => $row['revenue_date'], 'cents' => intval(round($row['revenue_amount'] * 100)),
'label' => $what . ' on ' . $row['revenue_date'], 'transfer' => $row['transfer_id'] !== null];
}
}
@@ -577,7 +577,7 @@ function incomeImportDuplicates($account_id, array $lines) {
if ($lines[$i]['imported'] !== '' || $line['problem'] !== '') {
continue;
}
$cents = (int) round($line['amount'] * 100);
$cents = intval(round($line['amount'] * 100));
foreach ([$singles, $groups] as $pool) {
$best = null;
foreach ($pool as $j => $candidate) {
@@ -672,7 +672,7 @@ function incomeImportSave(array $import, array $picks, array $opts, &$error = ''
// Check every ticked deposit first, working out what each payment leaves owing
$bring = [];
$balances = array_map(function ($invoice) { return (int) round($invoice['balance'] * 100); }, $open);
$balances = array_map(function ($invoice) { return intval(round($invoice['balance'] * 100)); }, $open);
foreach ($lines as $line) {
$pick = $picks[$line['n']] ?? null;
if (!$pick || empty($pick['take']) || !in_array($line['state'], ['new', 'entered', 'recorded'], true)) {
@@ -705,7 +705,7 @@ function incomeImportSave(array $import, array $picks, array $opts, &$error = ''
$invoices[] = $open[$id];
}
usort($invoices, function ($a, $b) { return [$a['due'], $a['invoice_id']] <=> [$b['due'], $b['invoice_id']]; });
$left = (int) round($line['amount'] * 100);
$left = intval(round($line['amount'] * 100));
foreach ($invoices as $invoice) {
$owed = $balances[$invoice['invoice_id']];
if ($left <= 0 || $owed <= 0) {

View File

@@ -202,7 +202,7 @@ function mailGraphHttp($method, $url, array $headers = [], $body = null, $timeou
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$raw = curl_exec($ch);
$error = curl_error($ch);
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$status = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close($ch);
$json = is_string($raw) ? json_decode($raw, true) : null;
return ['status' => $status, 'json' => is_array($json) ? $json : [], 'body' => (string) $raw, 'error' => $error];

View File

@@ -135,7 +135,7 @@ function managedHttpJson(string $url, array $body, array $headers = []): array
]);
$raw = curl_exec($ch);
$err = curl_error($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close($ch);
$json = is_string($raw) ? json_decode($raw, true) : null;

View File

@@ -35,8 +35,8 @@ function updateInvoiceStatusFromPayments($invoice_id)
$amount_paid = floatval($row['amount_paid']);
// Compare in whole cents - float equality on decimal(15,2) values is not reliable
$paid_cents = (int) round($amount_paid * 100);
$total_cents = (int) round($invoice_amount * 100);
$paid_cents = intval(round($amount_paid * 100));
$total_cents = intval(round($invoice_amount * 100));
if ($paid_cents <= 0) {
$new_status = 'Sent';

View File

@@ -635,7 +635,7 @@ function productHardwareSql() {
/** How many units a line stands for - its quantity rounded up, none for a credit. */
function productHardwareUnits($qty) {
$qty = round(floatval($qty), 2);
return $qty > 0 ? (int) ceil($qty) : 0;
return $qty > 0 ? intval(ceil($qty)) : 0;
}
/** When a warranty of $months from $date (Y-m-d) runs out - the 31st becomes the month's last day. Null for none. */

View File

@@ -90,8 +90,8 @@ function quoteImageStore($bytes) {
$width = imagesx($source);
$height = imagesy($source);
$scale = min(1, QUOTE_IMAGE_MAX_SIDE / max($width, $height));
$new_width = max(1, (int) round($width * $scale));
$new_height = max(1, (int) round($height * $scale));
$new_width = max(1, intval(round($width * $scale)));
$new_height = max(1, intval(round($height * $scale)));
$alpha = in_array($info[2], [IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_WEBP], true);
$image = imagecreatetruecolor($new_width, $new_height);
if ($alpha) {
@@ -187,7 +187,7 @@ function quoteImageIpIsPublic($ip) {
*/
function quoteImageFetch($url, $deadline) {
for ($hop = 0; $hop < 4; $hop++) {
$time_left = (int) floor($deadline - microtime(true));
$time_left = intval(floor($deadline - microtime(true)));
if ($time_left < 2) {
throw new RuntimeException('The website took too long to answer.');
}
@@ -237,7 +237,7 @@ function quoteImageFetch($url, $deadline) {
},
]);
curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$status = intval(curl_getinfo($ch, CURLINFO_RESPONSE_CODE));
$type = strtolower((string) curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
$redirect = (string) curl_getinfo($ch, CURLINFO_REDIRECT_URL);
$error = curl_error($ch);

View File

@@ -438,7 +438,7 @@ class ReportPdfWriter {
if (!$tiles) {
return;
}
$per_row = count($tiles) <= 5 ? count($tiles) : (int) ceil(count($tiles) / ceil(count($tiles) / 4));
$per_row = count($tiles) <= 5 ? count($tiles) : intval(ceil(count($tiles) / ceil(count($tiles) / 4)));
$width = round(100 / $per_row, 3);
$html = '<table cellpadding="5" cellspacing="0" width="100%">';
foreach (array_chunk($tiles, $per_row) as $row) {

View File

@@ -1905,7 +1905,7 @@ function reportLifecycleAssets($client_id = 0, $type = '') {
$date = $physical ? DateTime::createFromFormat('!Y-m-d', substr((string) $row[$column], 0, 10)) : false;
if ($date && $date->format('Y') > 1900) {
$row['age_date'] = $date->format('Y-m-d');
$row['age_days'] = max(0, (int) $date->diff($today)->format('%r%a'));
$row['age_days'] = max(0, intval($date->diff($today)->format('%r%a')));
break;
}
}
@@ -1964,7 +1964,7 @@ function reportRenewals($client_id, $ahead, array $kinds = []) {
$rows[] = [
'kind' => $kind, 'id' => intval($id), 'name' => (string) $name, 'detail' => trim((string) $detail, " ·"),
'client_id' => intval($row['client_id']), 'client' => $row['client_name'], 'abbr' => $row['client_abbreviation'],
'date' => $due->format('Y-m-d'), 'days' => (int) $today->diff($due)->format('%r%a'), 'auto' => (bool) $auto, 'url' => $url, 'tile' => $tile,
'date' => $due->format('Y-m-d'), 'days' => intval($today->diff($due)->format('%r%a')), 'auto' => (bool) $auto, 'url' => $url, 'tile' => $tile,
];
};

View File

@@ -113,8 +113,8 @@ function redirect($url = null, $permanent = false) {
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>';
echo '<script>window.location.href = ' . json_encode((string) $url, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_SLASHES) . ';</script>';
echo '<noscript><meta http-equiv="refresh" content="0;url=' . escapeHtml($url) . '"></noscript>';
exit;
}
}

View File

@@ -206,7 +206,7 @@ function rmmHttp(array $provider, string $method, string $url, array $headers =
curl_setopt_array($ch, $options);
$raw = curl_exec($ch);
$transport = curl_error($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close($ch);
$host = (string) parse_url($url, PHP_URL_HOST);
@@ -894,7 +894,7 @@ function rmmSyncAll(int $max_seconds = 120): array
if (!rmmProviderUsable($provider)) {
continue;
}
$left = $max_seconds - (int) (microtime(true) - $clock);
$left = $max_seconds - intval(microtime(true) - $clock);
if ($left < 5) {
$results[rmmProviderName($provider)] = ['ok' => true, 'note' => 'Left for the next run - out of time', 'counts' => []];
continue;
@@ -1271,7 +1271,7 @@ function rmmAlertsPollAll(int $max_seconds = 50): array
if (!rmmAlertsOn($provider)) {
continue;
}
$left = $max_seconds - (int) (microtime(true) - $clock);
$left = $max_seconds - intval(microtime(true) - $clock);
if ($left < 5) {
break;
}

View File

@@ -108,7 +108,7 @@ function checkFileUpload($file, $allowed_extensions) {
}
// Reject empty files and enforce the 500 MB ceiling
$size = (int) $file['size'];
$size = intval($file['size']);
if ($size <= 0 || $size > 500 * 1024 * 1024) {
return false;
}

View File

@@ -6,7 +6,7 @@
// Function to generate both crypto & URL safe random strings
function randomString(int $length = 16): string {
$bytes = random_bytes((int) ceil($length * 3 / 4));
$bytes = random_bytes(intval(ceil($length * 3 / 4)));
return substr(
rtrim(strtr(base64_encode($bytes), '+/', '-_'), '='),
0,
@@ -135,7 +135,7 @@ function generateUserSessionKey($site_encryption_master_key) {
} else {
// Not secure without HTTPS, but still out of reach of page scripts
setcookie("user_encryption_session_key", base64_encode($user_encryption_session_key), ['path' => '/', 'httponly' => true, 'samesite' => 'Lax']);
$_SESSION['alert_message'] = "Unencrypted connection flag set: Using non-secure cookies.";
flashAlert("Unencrypted connection flag set: Using non-secure cookies.", 'warning');
}
}

View File

@@ -757,7 +757,7 @@ function settingsSame($a, $b) {
return $a === $b || (in_array($a, ['', '0'], true) && in_array($b, ['', '0'], true));
}
if (is_numeric($a) && is_numeric($b)) {
return (float) $a === (float) $b;
return floatval($a) === floatval($b);
}
return rtrim(str_replace("\r\n", "\n", (string) $a)) === rtrim(str_replace("\r\n", "\n", (string) $b));
}

View File

@@ -39,7 +39,7 @@ function getSlaSettings($refresh = false)
// ISO weekday numbers (1 = Monday .. 7 = Sunday)
$business_days = [];
foreach (explode(',', strval($row['config_business_days'])) as $day) {
foreach (explode(',', (string) $row['config_business_days']) as $day) {
$day = intval($day);
if ($day >= 1 && $day <= 7) {
$business_days[] = $day;

View File

@@ -696,7 +696,7 @@ function smsSkyetelSend(array $provider, string $to, string $text, array $media
]);
$raw = curl_exec($ch);
$curl_error = curl_error($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close($ch);
if ($raw === false) {
@@ -1058,7 +1058,7 @@ function smsSaveMedia(array $urls, int $ticket_id, ?int $reply_id, int $message_
},
]);
$ok = curl_exec($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$type = strtolower(trim(explode(';', (string) curl_getinfo($ch, CURLINFO_CONTENT_TYPE))[0]));
curl_close($ch);
if (strlen($data) > SMS_MEDIA_MAX_BYTES) {

View File

@@ -110,7 +110,7 @@ function softwareRenewal($expire, $soon_days = 30) {
if (!$date) {
return null;
}
$days = (int) (new DateTime('today'))->diff($date)->format('%r%a');
$days = intval((new DateTime('today'))->diff($date)->format('%r%a'));
$ymd = $date->format('Y-m-d');
if ($days < 0) {
@@ -153,7 +153,7 @@ function softwareSeats($used, $total) {
$text = ['over' => "$over over", 'full' => 'All in use', 'unused' => 'None in use', 'ok' => "$free free"][$state];
return [
'used' => $used, 'total' => $total, 'free' => $free, 'over' => $over,
'pct' => min(100, (int) round($used / $total * 100)),
'pct' => min(100, intval(round($used / $total * 100))),
'state' => $state,
'tone' => ['over' => 'danger', 'full' => 'warning', 'unused' => 'secondary', 'ok' => 'primary'][$state],
'text' => $text,

View File

@@ -59,7 +59,7 @@ if (isset($_GET['stripe_create_pi'])) {
$balance_to_pay = round($balance_to_pay, 2);
// In whole cents - a balance under 1.00 can still be paid, and nothing owed (or overpaid) can't
if ((int) round($balance_to_pay * 100) <= 0) {
if (intval(round($balance_to_pay * 100)) <= 0) {
exit(json_encode(['error' => 'Nothing is owed on this invoice']));
}
@@ -87,7 +87,7 @@ if (isset($_GET['stripe_create_pi'])) {
$stripe_customer_id = $stripe_customer ? escapeSql($stripe_customer['payment_provider_client']) : null;
// The card fee, when the client pays it - as guest_pay_invoice_stripe.php showed it, and booked from itflow_fees on the way back
$balance_cents = (int) round($balance_to_pay * 100);
$balance_cents = intval(round($balance_to_pay * 100));
$fee_cents = billingCardFeeCents($balance_cents, billingCardFeeFor($client_id));
$pi_metadata = [
'itflow_client_id' => $client_id,

View File

@@ -79,7 +79,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// The card fee, when the client pays it - guest_ajax.php charges the same
$fee_rates = billingCardFeeFor($client_id);
$card_fee = billingCardFeeCents((int) round($balance_to_pay * 100), $fee_rates) / 100;
$card_fee = billingCardFeeCents(intval(round($balance_to_pay * 100)), $fee_rates) / 100;
// Get invoice items
$sql_invoice_items = mysqli_query($mysqli, "SELECT item_name, item_quantity, item_total FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_id ASC");
@@ -207,7 +207,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
$pi_date = date('Y-m-d', $pi_obj->created);
$pi_invoice_id = intval($pi_obj->metadata->itflow_invoice_id);
$pi_client_id = intval($pi_obj->metadata->itflow_client_id);
$pi_amount_paid = floatval(($pi_obj->amount_received / 100));
$pi_amount_paid = floatval($pi_obj->amount_received / 100);
$pi_currency = strtoupper(escapeSql($pi_obj->currency));
$pi_livemode = $pi_obj->livemode;
@@ -261,7 +261,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// Compare in whole cents - intval() truncates, which silently accepted an underpayment
// of up to 99c as payment in full while rejecting a 1c overpayment.
if ((int) round($balance_to_pay * 100) + $pi_fee_cents !== (int) round($pi_amount_paid * 100)) {
if (intval(round($balance_to_pay * 100)) + $pi_fee_cents !== intval(round($pi_amount_paid * 100))) {
error_log("Stripe payment error - Invoice balance does not match amount paid for $pi_id");
exit(WORDING_PAYMENT_FAILED);
}
@@ -269,8 +269,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// A payment already booked - here, or in the client portal - is never booked again, even
// when its invoice has been reopened since (an edit, a payment deleted) and owes it again
if (mysqli_num_rows(mysqli_query($mysqli, "SELECT payment_id FROM payments WHERE payment_reference = 'Stripe - $pi_id' LIMIT 1"))) {
header('Location: //' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
exit();
redirect('//' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
}
// Claim the invoice - the conditional UPDATE is the lock, and the row lock it takes
@@ -279,8 +278,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $invoice_id AND invoice_status NOT IN ('Draft', 'Paid', 'Cancelled')");
if (mysqli_affected_rows($mysqli) !== 1) {
error_log("Stripe payment - invoice $invoice_id was already settled by a concurrent request; skipping duplicate booking of $pi_id");
header('Location: //' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
exit();
redirect('//' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
}
// The card fee goes on the invoice first, so the payment - balance and fee - pays it to the cent
@@ -309,7 +307,7 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
}
// Redirect user to invoice
header('Location: //' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
redirect('//' . $config_base_url . '/guest/guest_view_invoice.php?invoice_id=' . $invoice_id . '&url_key=' . $invoice_url_key);
} else {
exit(WORDING_PAYMENT_FAILED);

View File

@@ -50,7 +50,7 @@ if ($stripe && invoiceCanPay($invoice, $state) && (floatval($stripe['payment_pro
$pay_url = ($stripe_customer ? 'guest_pay_invoice_stripe.php' : 'guest_pay_setup_stripe_customer.php') . "?invoice_id=$invoice_id&url_key=$query_key";
}
// The card fee on paying by card, when the client pays one (functions/billing_pay.php)
$card_fee = $pay_url ? billingCardFeeCents((int) round($state['balance'] * 100), billingCardFeeFor($client_id)) / 100 : 0;
$card_fee = $pay_url ? billingCardFeeCents(intval(round($state['balance'] * 100)), billingCardFeeFor($client_id)) / 100 : 0;
// Paid by its recurring invoice's autopay on the due date - said, so it isn't paid twice, while that will go through
$autopay = $state['state'] === 'open' ? invoiceAutopay($invoice) : null;
if ($autopay && $autopay['problem'] !== '') {

View File

@@ -53,8 +53,7 @@ if ($open && $_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['kb_feedback
kbFeedbackComment($kb_article_id, $_POST['comment'] ?? '');
}
}
header('Location: ' . ($row ? kbPublicArticleUrl($row) . '#kb-feedback' : 'kb.php'));
exit;
redirect($row ? kbPublicArticleUrl($row) . '#kb-feedback' : 'kb.php');
}
$article = null;
@@ -107,7 +106,7 @@ if ($open && isset($_GET['article'])) {
if ($q !== '' && !$total && $category === null) {
kbSearchMissSave($q, 'public');
}
$pages = max(1, (int) ceil($total / $per_page));
$pages = max(1, intval(ceil($total / $per_page)));
$page = min(max(1, intval($_GET['page'] ?? 1)), $pages);
$offset = ($page - 1) * $per_page;
$order = $q !== '' ? "(kb_article_title LIKE '%$q_sql%') DESC, MATCH(kb_article_content_raw) AGAINST ('$q_sql') DESC" : 'COALESCE(kb_article_updated_at, kb_article_created_at) DESC';

View File

@@ -2,10 +2,5 @@
// Check user is logged in with a valid session
if (!isset($_SESSION['logged']) || !$_SESSION['logged']) {
if ($_SERVER["REQUEST_URI"] == "/") {
header("Location: /login.php");
} else {
header("Location: /login.php?last_visited=" . base64_encode($_SERVER["REQUEST_URI"]) );
}
exit;
redirect($_SERVER["REQUEST_URI"] == "/" ? "/login.php" : "/login.php?last_visited=" . base64_encode($_SERVER["REQUEST_URI"]));
}

View File

@@ -16,7 +16,7 @@
require __DIR__ . '/inc_empty_state.php';
$total_found_rows = $num_rows[0];
$total_pages = (int) ceil($total_found_rows / $user_config_records_per_page);
$total_pages = intval(ceil($total_found_rows / $user_config_records_per_page));
if ($total_found_rows > 5) {
?>

View File

@@ -135,4 +135,4 @@ if ($itflow_pulse) { ?>
//$time_end = microtime(true);
//$execution_time = ($time_end - $time_start);
//echo '<h2>Total Execution Time: '.number_format((float) $execution_time, 10) .' seconds</h2>';
//echo '<h2>Total Execution Time: '.number_format(floatval($execution_time), 10) .' seconds</h2>';

View File

@@ -91,8 +91,8 @@ $client_access_array = []; // allow
$client_deny_array = []; // deny
while ($row = mysqli_fetch_assoc($user_client_access_result)) {
if ($row['permission_type'] === 'deny') {
$client_deny_array[] = (int) $row['client_id'];
$client_deny_array[] = intval($row['client_id']);
} else {
$client_access_array[] = (int) $row['client_id'];
$client_access_array[] = intval($row['client_id']);
}
}