From 388f083a2b11a8eb78bf283b831315218d559d22 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sun, 22 Nov 2026 21:56:35 -0500 Subject: [PATCH] Add phone system integration with FusionPBX: Admin Phone Systems with setup lines for mod_xml_cdr and mod_cidlookup, domains linked to clients with suggestions, a Calls page per client and contact with calls matched to contacts, Add to Ticket with talk time as time worked, and caller ID names from ITFlow on desk phones --- CHANGELOG.md | 8 +- admin/database_updates/4.1.4.php | 127 +++ admin/includes/side_nav.php | 7 + admin/modals/phone/phone_domain_link.php | 55 ++ admin/modals/phone/phone_system_add.php | 9 + admin/modals/phone/phone_system_edit.php | 88 +++ admin/modals/phone/phone_system_setup.php | 77 ++ admin/phone_domains.php | 277 +++++++ admin/phone_systems.php | 181 +++++ admin/post/phone.php | 167 ++++ agent/calls.php | 257 ++++++ agent/contact.php | 24 + agent/includes/client_side_nav.php | 15 + agent/includes/inc_all_client.php | 3 + agent/includes/side_nav.php | 14 + agent/modals/phone/phone_call_ticket.php | 109 +++ agent/modals/ticket/ticket_add.php | 10 + agent/post/client.php | 6 + agent/post/phone.php | 45 ++ agent/post/ticket.php | 8 + api/phone/cdr.php | 27 + api/phone/cid.php | 21 + api/phone/phone_system.php | 41 + cron/nightly_tasks.php | 3 + css/itflow_custom.css | 22 + db.sql | 136 ++++ functions.php | 1 + functions/audit_log.php | 1 + functions/client.php | 1 + functions/phone.php | 902 ++++++++++++++++++++++ functions/ticket.php | 3 +- 31 files changed, 2643 insertions(+), 2 deletions(-) create mode 100644 admin/database_updates/4.1.4.php create mode 100644 admin/modals/phone/phone_domain_link.php create mode 100644 admin/modals/phone/phone_system_add.php create mode 100644 admin/modals/phone/phone_system_edit.php create mode 100644 admin/modals/phone/phone_system_setup.php create mode 100644 admin/phone_domains.php create mode 100644 admin/phone_systems.php create mode 100644 admin/post/phone.php create mode 100644 agent/calls.php create mode 100644 agent/modals/phone/phone_call_ticket.php create mode 100644 agent/post/phone.php create mode 100644 api/phone/cdr.php create mode 100644 api/phone/cid.php create mode 100644 api/phone/phone_system.php create mode 100644 functions/phone.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 13a43244b..c3c79d695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's two database changes (4.1.1 to 4.1.3) in the same pass. They add a column to RMM providers for the asset type each kind of device comes in as, and three to rack items for devices side by side in a holder, and change nothing that is there. Nothing else is required. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's three database changes (4.1.1 to 4.1.4) in the same pass. They add a column to RMM providers for the asset type each kind of device comes in as, three to rack items for devices side by side in a holder, and the tables for phone systems, and change nothing that is there. Nothing else is required. ### New Features & Updates @@ -18,6 +18,9 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - API: assets read through the API come with asset_rmm - each of the asset's devices in an RMM, with its status, when it was last seen, who is signed in, its IPs, and whether it needs a reboot, has patches waiting or has checks failing. - RMM Providers: most of a client's devices gone from the RMM at once - three or more, and at least half of them - are kept as they were for a day instead of being marked gone straight away. That is far more often the RMM, or a change to what its API key can see, than the devices, and marking them gone dropped them from managed device counts on recurring invoices. The provider's row names the client and how many, and the sync shows as failed so it is noticed. Still missing after a day, they are marked gone. A client deleted in the RMM is treated the same way, and agents reinstalled all at once are still matched to their assets. - Racks: more than one device on a rack row - two Tiny PCs in a 1U bracket, eight PLCs on a shelf, the cards in a media converter chassis. Turn on Holds devices side by side on a rack item - a shelf, bracket or chassis, an asset or not - and say how many fit across. What is in it is drawn side by side in it, and past that many it wraps onto another row, for stacks. Click an empty slot to add something there, or pick the holder under Goes in when you add it. Drag an asset from Not racked yet or an item from the rack onto an empty slot, or a device to another slot, with Undo. Moving the holder moves what is in it, and removing it takes what is in it out of the rack too, after asking - the assets stay. An asset's page and the assets list show its slot, the page with a link to the holder when that is an asset - a server node to its chassis - and a holder's own page has Devices in it, listing what is in each slot. The client export and the API have slots too. +- Phone Systems: Admin > Phone Systems takes FusionPBX - without its API or its database. FreeSWITCH, underneath it, sends ITFlow each call's record as it hangs up and asks ITFlow for caller ID names; the system's Setup window gives the lines to paste, with its own key in them. Each of its domains is linked to the client it is, with the client it looks like suggested. A call on a client's domain is that client's; on your own company's domain it goes to whoever called, from any client. +- Calls: a new Calls page, on the menu and on each client, lists the calls with who they were with - matched to a contact by their number, or to a client by its main number - the extension and agent that took them, how long they talked, and whether they were missed or went to voicemail, with a link to the call's page in FusionPBX and its recording. A contact's page has a Calls tab, and the menu counts the calls missed today that aren't on a ticket. Add to Ticket puts a call on one of the client's open tickets, or a new one, as an internal note with its talk time as time worked. +- Phone Systems: as a call rings, desk phones show the contact and their client - Marla Whitfield - Ravenwood Dental - when ITFlow knows the number, and the carrier's name otherwise. ### Bug Fixes @@ -50,6 +53,9 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `reportQuarters($year, $current_year)` in `functions/reports.php` gives a year's quarters - label, months, first and last month, `done`, `now` or `later`, and what each is compared with - and `reportQuarterSum($months, $quarter)` a quarter's share of a year of months. A report puts its `rows` (`label`, `now`, `prev`, `good`, `strong`) on each and `reportQuarterCards($quarters, $whole)` draws them, in the `.itflow-report-stats` strip, laid out by a container query on its own width: four across, two by two, or one a row. `agent/reports/profit_loss.php` and `agent/reports/tax_summary.php` show them on Quarterly in place of the chart, the latter adding up last year's tax paid on purchases for net tax. `reportChartColumns($months, $columns, $months_shown)` sums a year's months into a report's columns for a chart, null for a column still to come. - Database 4.1.3: `rack_units.unit_slots` (how many a holder takes side by side, 0 for any other item), `unit_parent_id` (the holder a device is in - a foreign key to `rack_units` that cascades on delete) and `unit_position` (its slot, 1 the first, counting across and then a row on). Re-runnable. A device in a holder keeps its holder's units, face and depth in its own columns - `rackSyncChildren($holder_id)` after the holder moves or changes - so whatever reads where an asset is racked reads it as before, and `rackOccupancy()` and `rackUnitConflict()` skip devices in a holder. `rackPositionForAsset()` adds `unit_id`, `unit_slots`, `unit_position`, `holder_name` and `holder_asset_id`. `rackSlotHtml()` links the holder from an asset's page, and `rackHolderChildren($unit_id)` lists what is in a holder for its own page, from `rackUnitRows($where)`, which `rackLoadUnits()` now uses too. - `rackPlacement($rack_id, $unit_id, $want)` in `functions/rack.php` checks where an item goes - in the rack (bounds, overlaps, and that a holder with devices in it still holds devices) or in a slot (the holder is in the same rack and holds devices, the item holds none, the slot is free and at most a row past the last one used, `rackSlotLimit()`) - and `rackPlacementSet()` writes it. The rack item form, the drag (`move_rack_unit` with `holder` and `slot`), Undo (`['rack_place', ...]`) and the API's `rack_units` endpoints (`unit_slots`, `unit_parent_id`, `unit_position`) all go through it. `rackNestItems()` and `rackHolderCells()` lay a holder out for `agent/includes/rack_elevation.php`, its rows counting the way the rack's units do. +- Database 4.1.4: `phone_systems`, `phone_domains`, `phone_calls`, `phone_devices`, `phone_events` and `user_settings.user_config_phone_line`. Re-runnable. `functions/phone.php` has them; nothing in ITFlow connects to a phone system - it sends to `api/phone/`, keyed by the address's `key` or the HTTP Basic password (`phoneSystemByKey()`), 404 for an unknown key and 503 for a system turned off. +- `api/phone/cdr.php` takes mod_xml_cdr's post - the `cdr` field URL-encoded or base64, or the body - through `phoneCdrParse()` (its variables URL-decoded, the rest from the first caller profile) and `phoneCallFromCdr()` (FusionPBX's `call_direction`, else worked out from the numbers). A second leg (`originating_leg_uuid`, or `uuid` starting `b_`) is set aside, and a call is kept once per uuid. `api/phone/cid.php` answers mod_cidlookup with `phoneCallerName()`. +- `phoneWho($number, $domain_client_id)` matches a number with `smsContactsFor()` - a mobile before an office number many share - then clients' location phones; a number more than one client has is nobody's. On a client's domain only that client counts; on your own company's (`config_internal_client_id`) or one not linked, every client does. `phoneDomainLink()` matches a domain's calls again. `phoneCallToTicket()` adds the internal note, its talk time as `ticket_reply_time_worked` with the work start and end, and `add_ticket` takes `phone_call_id` (ticket source Phone). `phoneCleanup()` runs nightly: calls over 400 days old that aren't on a ticket go. Client delete and merge take the phone tables. ## [26.12] diff --git a/admin/database_updates/4.1.4.php b/admin/database_updates/4.1.4.php new file mode 100644 index 000000000..7d5720b7d --- /dev/null +++ b/admin/database_updates/4.1.4.php @@ -0,0 +1,127 @@ +RMM Providers

+ + + + + + diff --git a/agent/includes/inc_all_client.php b/agent/includes/inc_all_client.php index b7deda352..cdbb282c7 100644 --- a/agent/includes/inc_all_client.php +++ b/agent/includes/inc_all_client.php @@ -279,6 +279,9 @@ if (isset($_GET['client_id'])) { // The trips this agent may see - all of them with Financial access, else their own [$num_trips] = tripTotalsFor('trip_client_id', $client_id); + // Calls from the phone systems in the last 30 days (functions/phone.php) - the menu shows Calls once there are any + $num_phone_calls = phoneSystemsExist() ? intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM phone_calls WHERE phone_call_client_id = $client_id AND phone_call_started_at >= NOW() - INTERVAL 30 DAY"))[0]) : 0; + } } diff --git a/agent/includes/side_nav.php b/agent/includes/side_nav.php index 1952a0907..54a3b28ed 100644 --- a/agent/includes/side_nav.php +++ b/agent/includes/side_nav.php @@ -131,6 +131,20 @@ + + +