From 9c65644adc39732632c8f8a4747384c6e1cbd077 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 23 Jul 2026 17:39:06 -0400 Subject: [PATCH] Update the rest of the PHP functions to use camelCase --- CONTRIBUTING.md | 2 +- admin/debug.php | 8 +-- admin/includes/side_nav.php | 2 +- admin/post/backup.php | 66 ++++++++++----------- admin/settings_mail.php | 6 +- agent/asset.php | 6 +- agent/assets.php | 6 +- agent/client_overview.php | 4 +- agent/credentials.php | 4 +- agent/files.php | 12 ++-- agent/includes/side_nav.php | 2 +- agent/modals/asset/asset.php | 6 +- agent/modals/client/client_add.php | 4 +- agent/modals/contact/contact_add.php | 4 +- agent/modals/credential/credential_edit.php | 4 +- agent/modals/domain/domain_add.php | 4 +- agent/modals/service/service.php | 4 +- agent/reports/includes/reports_side_nav.php | 2 +- agent/reports/ticket_by_client.php | 40 ------------- agent/reports/tickets_unbilled.php | 38 ------------ agent/reports/time_by_tech.php | 40 ------------- client/assets.php | 2 +- client/index.php | 2 +- functions/format.php | 41 +++++++++++++ functions/sanitize.php | 2 +- includes/top_nav.php | 2 +- setup/index.php | 6 +- 27 files changed, 121 insertions(+), 198 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d35972a..0acad1b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -128,7 +128,7 @@ That is the whole job. `LATEST_DATABASE_VERSION` is derived from the highest-num A single update run applies every pending migration in order, stopping at the first failure with the version left at the last file that completed, so a re-run resumes at the one that broke. **After acting, log and notify.** State changes call `logAudit($type, $action, $description, $client_id, $entity_id)` for the audit trail. User-facing events may also call `appNotify()`. Fire `triggerCustomAction()` where a site might reasonably want a hook. Then call `flashAlert($message, $type)` and `redirect()` (defaults to the referer) rather than setting session keys or `header()` manually. -**Function names (post-rename).** Helpers were renamed for clarity in 2026; the old names **no longer exist** — code calling them fatals. If you're rebasing an old PR or following an old tutorial, translate: `sanitizeInput` → `escapeSql`, `nullable_htmlentities` → `escapeHtml`, `logAction` → `logAudit`, `flash_alert` → `flashAlert`, `customAction` → `triggerCustomAction`, `encryptLoginEntry`/`decryptLoginEntry` → `encryptCredentialEntry`/`decryptCredentialEntry`, `strtoAZaz09` → `toAlphanumeric`, `fetchUpdates` → `checkForUpdates`. +**Function names (post-rename).** Helpers were renamed for clarity in 2026; the old names **no longer exist** — code calling them fatals. If you're rebasing an old PR or following an old tutorial, translate: `sanitizeInput` → `escapeSql`, `nullable_htmlentities` → `escapeHtml`, `logAction` → `logAudit`, `flash_alert` → `flashAlert`, `customAction` → `triggerCustomAction`, `encryptLoginEntry`/`decryptLoginEntry` → `encryptCredentialEntry`/`decryptCredentialEntry`, `strtoAZaz09` → `toAlphanumeric`, `fetchUpdates` → `checkForUpdates`, `sanitize_url` → `escapeUrl`. **Bulk vs. single actions.** If you change the behavior of a single action (e.g. resolving a ticket), check whether a `bulk_*` counterpart exists and update it too. They are currently parallel implementations and drift between them is a known bug source. diff --git a/admin/debug.php b/admin/debug.php index a0759651..16a7ef45 100644 --- a/admin/debug.php +++ b/admin/debug.php @@ -79,7 +79,7 @@ $phpConfig[] = [ ]; // Check upload_max_filesize and post_max_size >= 500M -function return_bytes($val) { +function toBytes($val) { $val = trim($val); $unit = strtolower(substr($val, -1)); $num = (float)$val; @@ -99,8 +99,8 @@ $required_bytes = 500 * 1024 * 1024; // 500M in bytes $upload_max_filesize = ini_get('upload_max_filesize'); $post_max_size = ini_get('post_max_size'); -$upload_passed = return_bytes($upload_max_filesize) >= $required_bytes; -$post_passed = return_bytes($post_max_size) >= $required_bytes; +$upload_passed = toBytes($upload_max_filesize) >= $required_bytes; +$post_passed = toBytes($post_max_size) >= $required_bytes; $phpConfig[] = [ 'name' => 'upload_max_filesize >= 500M', @@ -116,7 +116,7 @@ $phpConfig[] = [ // PHP Memory Limit >= 128M $memoryLimit = ini_get('memory_limit'); -$memoryLimitBytes = return_bytes($memoryLimit); +$memoryLimitBytes = toBytes($memoryLimit); $memoryLimitPassed = $memoryLimitBytes >= (128 * 1024 * 1024); $phpConfig[] = [ 'name' => 'PHP Memory Limit >= 128M', diff --git a/admin/includes/side_nav.php b/admin/includes/side_nav.php index 28f5a1bd..99a2666a 100644 --- a/admin/includes/side_nav.php +++ b/admin/includes/side_nav.php @@ -301,7 +301,7 @@ while ($row = mysqli_fetch_assoc($sql_custom_links)) { $custom_link_name = escapeHtml($row['custom_link_name']); - $custom_link_uri = sanitize_url($row['custom_link_uri']); + $custom_link_uri = escapeUrl($row['custom_link_uri']); $custom_link_icon = escapeHtml($row['custom_link_icon']); $custom_link_new_tab = intval($row['custom_link_new_tab']); if ($custom_link_new_tab == 1) { diff --git a/admin/post/backup.php b/admin/post/backup.php index b70a6ade..1635b693 100644 --- a/admin/post/backup.php +++ b/admin/post/backup.php @@ -18,7 +18,7 @@ if (function_exists('ini_set')) { /** * Write a line to a file handle with newline. */ -function fwrite_ln($fh, string $s): void { +function writeLine($fh, string $s): void { fwrite($fh, $s); fwrite($fh, PHP_EOL); } @@ -31,7 +31,7 @@ function fwrite_ln($fh, string $s): void { * * NOTE: Routines/events are not dumped here. Add if needed. */ -function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { +function dumpDatabase(mysqli $mysqli, string $sqlFile): void { $fh = fopen($sqlFile, 'wb'); if (!$fh) { http_response_code(500); @@ -39,12 +39,12 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { } // Preamble - fwrite_ln($fh, "-- UTF-8 + Foreign Key Safe Dump"); - fwrite_ln($fh, "SET NAMES 'utf8mb4';"); - fwrite_ln($fh, "SET FOREIGN_KEY_CHECKS = 0;"); - fwrite_ln($fh, "SET UNIQUE_CHECKS = 0;"); - fwrite_ln($fh, "SET AUTOCOMMIT = 0;"); - fwrite_ln($fh, ""); + writeLine($fh, "-- UTF-8 + Foreign Key Safe Dump"); + writeLine($fh, "SET NAMES 'utf8mb4';"); + writeLine($fh, "SET FOREIGN_KEY_CHECKS = 0;"); + writeLine($fh, "SET UNIQUE_CHECKS = 0;"); + writeLine($fh, "SET AUTOCOMMIT = 0;"); + writeLine($fh, ""); // Gather tables and views $tables = []; @@ -80,12 +80,12 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { $createSQL = array_values($createRow)[1] ?? ''; $createRes->close(); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "-- Table structure for `{$table}`"); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "DROP TABLE IF EXISTS `{$table}`;"); - fwrite_ln($fh, $createSQL . ";"); - fwrite_ln($fh, ""); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "-- Table structure for `{$table}`"); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "DROP TABLE IF EXISTS `{$table}`;"); + writeLine($fh, $createSQL . ";"); + writeLine($fh, ""); // Dump data in a streaming fashion $dataRes = $mysqli->query("SELECT * FROM `{$mysqli->real_escape_string($table)}`", MYSQLI_USE_RESULT); @@ -93,7 +93,7 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { $wroteHeader = false; while ($row = $dataRes->fetch_assoc()) { if (!$wroteHeader) { - fwrite_ln($fh, "-- Dumping data for table `{$table}`"); + writeLine($fh, "-- Dumping data for table `{$table}`"); $wroteHeader = true; } $cols = array_map(fn($c) => '`' . $mysqli->real_escape_string($c) . '`', array_keys($row)); @@ -103,10 +103,10 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { }, array_values($row) ); - fwrite_ln($fh, "INSERT INTO `{$table}` (" . implode(", ", $cols) . ") VALUES (" . implode(", ", $vals) . ");"); + writeLine($fh, "INSERT INTO `{$table}` (" . implode(", ", $cols) . ") VALUES (" . implode(", ", $vals) . ");"); } $dataRes->close(); - if ($wroteHeader) fwrite_ln($fh, ""); + if ($wroteHeader) writeLine($fh, ""); } } @@ -119,14 +119,14 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { $createView = $row['Create View'] ?? ''; $cRes->close(); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "-- View structure for `{$view}`"); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "DROP VIEW IF EXISTS `{$view}`;"); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "-- View structure for `{$view}`"); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "DROP VIEW IF EXISTS `{$view}`;"); // Ensure statement ends with semicolon if (!str_ends_with($createView, ';')) $createView .= ';'; - fwrite_ln($fh, $createView); - fwrite_ln($fh, ""); + writeLine($fh, $createView); + writeLine($fh, ""); } } @@ -142,22 +142,22 @@ function dump_database_streaming(mysqli $mysqli, string $sqlFile): void { $createTrig = $row['SQL Original Statement'] ?? ($row['Create Trigger'] ?? ''); $crt->close(); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "-- Trigger for `{$triggerName}`"); - fwrite_ln($fh, "-- ----------------------------"); - fwrite_ln($fh, "DROP TRIGGER IF EXISTS `{$triggerName}`;"); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "-- Trigger for `{$triggerName}`"); + writeLine($fh, "-- ----------------------------"); + writeLine($fh, "DROP TRIGGER IF EXISTS `{$triggerName}`;"); if (!str_ends_with($createTrig, ';')) $createTrig .= ';'; - fwrite_ln($fh, $createTrig); - fwrite_ln($fh, ""); + writeLine($fh, $createTrig); + writeLine($fh, ""); } } $tRes->close(); } // Postamble - fwrite_ln($fh, "SET FOREIGN_KEY_CHECKS = 1;"); - fwrite_ln($fh, "SET UNIQUE_CHECKS = 1;"); - fwrite_ln($fh, "COMMIT;"); + writeLine($fh, "SET FOREIGN_KEY_CHECKS = 1;"); + writeLine($fh, "SET UNIQUE_CHECKS = 1;"); + writeLine($fh, "COMMIT;"); fclose($fh); } @@ -235,7 +235,7 @@ if (isset($_GET['download_backup'])) { } // === Generate SQL Dump (streaming) === - dump_database_streaming($mysqli, $sqlFile); + dumpDatabase($mysqli, $sqlFile); // === Zip the uploads folder (strict) === zipFolderStrict("../uploads", $uploadsZip); diff --git a/admin/settings_mail.php b/admin/settings_mail.php index f07f6b71..d36d057d 100644 --- a/admin/settings_mail.php +++ b/admin/settings_mail.php @@ -2,7 +2,7 @@ require_once "includes/inc_all_admin.php"; // ---- Tiny status dot for tab labels ---------------------------------------- -function mail_status_dot($on) { +function renderMailStatusDot($on) { return $on ? '' : ''; @@ -64,12 +64,12 @@ $imap_ready = $imap_standard_ready || $imap_oauth_ready; diff --git a/agent/includes/side_nav.php b/agent/includes/side_nav.php index ccb60cbf..2680b350 100644 --- a/agent/includes/side_nav.php +++ b/agent/includes/side_nav.php @@ -212,7 +212,7 @@ while ($row = mysqli_fetch_assoc($sql_custom_links)) { $custom_link_name = escapeHtml($row['custom_link_name']); - $custom_link_uri = sanitize_url($row['custom_link_uri']); + $custom_link_uri = escapeUrl($row['custom_link_uri']); $custom_link_icon = escapeHtml($row['custom_link_icon']); $custom_link_new_tab = intval($row['custom_link_new_tab']); if ($custom_link_new_tab == 1) { diff --git a/agent/modals/asset/asset.php b/agent/modals/asset/asset.php index e1751ed9..929e4094 100644 --- a/agent/modals/asset/asset.php +++ b/agent/modals/asset/asset.php @@ -30,9 +30,9 @@ $asset_make = escapeHtml($row['asset_make']); $asset_model = escapeHtml($row['asset_model']); $asset_serial = escapeHtml($row['asset_serial']); $asset_os = escapeHtml($row['asset_os']); -$asset_uri = sanitize_url($row['asset_uri']); -$asset_uri_2 = sanitize_url($row['asset_uri_2']); -$asset_uri_client = sanitize_url($row['asset_uri_client']); +$asset_uri = escapeUrl($row['asset_uri']); +$asset_uri_2 = escapeUrl($row['asset_uri_2']); +$asset_uri_client = escapeUrl($row['asset_uri_client']); $asset_status = escapeHtml($row['asset_status']); $asset_purchase_reference = escapeHtml($row['asset_purchase_reference']); $asset_purchase_date = escapeHtml($row['asset_purchase_date']); diff --git a/agent/modals/client/client_add.php b/agent/modals/client/client_add.php index 237baad2..1a954281 100644 --- a/agent/modals/client/client_add.php +++ b/agent/modals/client/client_add.php @@ -66,7 +66,7 @@ ob_start();
- +
> @@ -393,7 +393,7 @@ ob_start();