diff --git a/CHANGELOG.md b/CHANGELOG.md
index 81efcf5da..6e77b0a58 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 twenty-three database changes (3.6.6 to 3.8.9) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, and a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, and two settings and a column on tickets for keeping project tickets apart, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates.
+Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's twenty-four database changes (3.6.6 to 3.9.0) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, and a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, and a table for your other offices with a column each on agents and invites for which one they work from, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates.
### Security
@@ -112,6 +112,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Quotes: a quote line can carry what it costs you, and its price can come from that cost. In a line's Edit window, Your cost has Cost each, Price by - Markup (a % added to the cost), Margin (a % of the price) or Set price - and the %, with buttons for the ones you use most: the Price is worked out as you type, and says what the line makes each. Typing the Price yourself makes it a set price. A line added from a product takes the product's cost and keeps its price. On the quote, while it can be changed, each line with a cost shows it under its name with its markup or margin, and the quote's Margin counts each line's own cost. Only agents see any of it - never the PDF, the guest link, the client portal or the invoice made from the quote. Admin > Settings > Quotes has what a line is priced by to start with, its % and the quick picks. From Mountaineer IT's build of ITFlow.
- Quotes: a quote line can have a picture beside its name - on the quote, the guest link, the client portal and the PDF. In the line's Edit window, upload one or paste a link: a picture, or the product's web page, whose main picture is taken. A product keeps a picture too, in its Edit window, and a quote line added from it takes a copy; copying a quote copies them. ITFlow keeps its own copy of each, made smaller, and only fetches from public websites. Admin > Settings > Quotes can switch pictures off. From Mountaineer IT's build of ITFlow.
- Projects: a project's tickets can be kept apart from the service desk - switch on Keep project tickets apart under Admin > Settings > Projects. A ticket in a project is then left off the tickets list's Open, Unassigned, Needs reply and other views - it has a Projects view of its own - and out of the dashboard's unassigned count, the count beside Tickets in the menu and the Dispatch queue, and has no SLA: the project's dates are what count. It stays under Mine, Mentioned me, Closed and All, in Dispatch's Workload and on the calendar and Dispatch, drawn in the project's calendar color with the project named under it and, on the calendar, a dot in the agent's color. A ticket taken out of its project gets its SLA back counted from then, so it isn't overdue at once - and so do they all when the setting is switched off. Off to start with, so nothing changes until you switch it on. From Mountaineer IT's build of ITFlow.
+- Offices: if you work from more than one place, list the others under Admin > Settings > Company Details, Offices - each with its name, address, phone and email, and who works there. An agent's office can also be picked in Admin > Users, and given with an invite. A new trip starts from the driver's office, From offers every office, and changing the driver on a new trip moves From to theirs unless you typed it. Emails about a ticket show the office of the agent on it - the one assigned, else the one sending - at the foot: its address, and its phone and email, or the main office's phone and the ticket email address when it has none. Invoices, quotes and contracts keep the main address. Removing an office puts those who worked there back in the main one. With no other office, nothing changes. From Mountaineer IT's build of ITFlow.
### Bug Fixes
@@ -244,6 +245,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Database 3.8.7: `quote_items.item_cost`, `item_price_method` (`markup`, `margin` or `price`) and `item_price_percent` - the names MountaineerIT's build uses - and `config_quote_price_method`, `config_quote_price_percent` and `config_quote_price_presets` - `quotePricingReady()`. `functions/quote_pricing.php`: `QUOTE_PRICE_METHODS`, `quotePricingSettings()` (read from `settings` directly, not `load_global_settings.php`), `quotePriceFromCost()`, `quotePricingFromInput()`, `quotePricingSetSql()` - `billingItemSave()` takes `pricing` with `cost`, `price_method` and `price_percent` on a quote, and gives a new line from a product its `product_cost` as a set price - `quotePricingCopySql()` (`add_quote_copy`, which now also keeps `item_product_id`, and `billingCopyLines()` to a quote), `quotePricingMethodNow()` (a markup or margin whose price was changed by hand reads as a set price), `quotePricingLineHtml()` (under the line in `includes/billing_paper.php` while `edit`) and `quotePricingFields()` with `itflowBillingPricingForm()` in `js/billing_items.js`. `billingItems()` returns the three columns for a quote; `billingMargin()` uses `item_cost` before the product's cost. The API's quote line read returns them as it returns every column. From Mountaineer IT's build of ITFlow.
- Database 3.8.8: `quote_items.item_image`, `products.product_image` (paths under `uploads/`, the names MountaineerIT's build uses; their `uploads/mit_images/` files are taken as they are) and `config_quote_show_images` - `quoteImagesReady()`, `quoteImagesShown()`. `functions/quote_images.php`: `quoteImageStore()` redraws a JPG, PNG, GIF or WebP with GD at up to 800 pixels a side into `uploads/quote_images/<32 hex>.jpg|png`; `quoteImageFromUpload()`, `quoteImageFromUrl()` (the image, or a page's `og:image` / `twitter:image` / `image_src`) through `quoteImageFetch()` - http(s) on ports 80, 443, 8080 and 8443, every resolved address checked by `quoteImageIpIsPublic()` and pinned with `CURLOPT_RESOLVE`, no proxy, three redirects each checked, 8 MB and 25 seconds in all; `quoteImageSave($table, $id, $in, $files)` for `item_image` / `product_image` with `_url` and `_remove`, `quoteImageField()`, `quoteImageThumbHtml()`, `quoteImageFromProduct()` (a new quote line in `billingItemSave()`), `quoteImageCopySql()` (`add_quote_copy`, `billingCopyLines()` to a quote) and `quoteImagesDeleteFor()` (`billingItemDelete()`, `delete_quote`, deleting a client from the page or the API, the API's quote delete, demo data); `productDelete()` throws the product's away. `includes/billing_paper.php` and `billingPdfRender()` show it; the Edit Line and product windows post `multipart/form-data`, and `js/app.js` previews the file picked. From Mountaineer IT's build of ITFlow.
- Database 3.8.9: `config_project_tickets_apart` (default 0), `config_project_ticket_color` (NULL is `PROJECT_TICKET_COLOR`) and `tickets.ticket_sla_from` (when the SLA counts from; NULL is `ticket_created_at`) - `projectTicketsReady()`. `functions/project_tickets.php`: `projectTicketsSettings()`, `projectTicketsApart()`, `projectTicketsServiceSql()` (the side menu's count, the dashboard's two unassigned counts, `dispatchQueue()`), `projectTicketsShows()` (`agent/tickets.php`'s views; not with a Project filter), `projectTicketsSlaOff()` - `applyTicketSla()` reads `ticket_project_id`, `ticket_sla_id`, `ticket_closed_at` and `ticket_sla_from`, gives an open project ticket SLA 0, leaves a done one with none, and counts targets from `ticket_sla_from` - `projectTicketLeft()` / `projectTicketMoved()` (`edit_ticket`, `edit_ticket_project`, bulk project, `projectAddTicket()`, `projectRemoveTicket()`, `projectDelete()`, the API's ticket update), `projectTicketsSwitched()` (the settings save) and `projectTicketsCalendarItems()` (the tickets source: `color`, `extendedProps.agent_color`, `project`; `agent/js/calendar.js` draws the dot). No cron job: every way a ticket's project changes calls it. From Mountaineer IT's build of ITFlow.
+- Database 3.9.0: the `offices` table (the same `office_` columns as Mountaineer IT's `mit_offices`; `office_archived_at` when removed), `users.user_office_id` and `user_invites.invite_office_id` (0 is the main office - the `companies` row) - `officesReady()`. `functions/offices.php`: `offices()`, `office()`, `officeMain()`, `officesAll()`, `officeIdForUser()`, `officeSetUser()`, `officePeople()`, `officeSave()` / `officeRemove()` (`admin/post/office.php`: `save_office`, `remove_office`; the window is `admin/modals/office/office.php`), `officesSection()` (Company Details), `officeUserField()` / `officeUserSave()` (`add_user`, `edit_user`; `userInviteSave()` takes `office_id` and `userInviteAccept()` sets it), `officeTripStart()` / `officeTripPlaces()` / `officeTripStarts()` (the trip form, `tripStartPlaces()` and the API's trip create), and `officeTicketFoot()` - an `office` key (`address`, `contact`) on the four ticket emails that set `contact`, which `emailHtml()` puts in the foot in place of the company's address and contact line. From Mountaineer IT's build of ITFlow.
## [26.11.8]
diff --git a/admin/database_updates/3.9.0.php b/admin/database_updates/3.9.0.php
new file mode 100644
index 000000000..d8a0fcb12
--- /dev/null
+++ b/admin/database_updates/3.9.0.php
@@ -0,0 +1,49 @@
+ Settings > Company Details:
+ * offices - one row an office: its name, address, phone and email. Removed
+ * ones are kept (office_archived_at) for the record.
+ * users.user_office_id - the office an agent works from; 0 (the default) is
+ * the main one.
+ * user_invites.invite_office_id - the office an invited agent will work from,
+ * given to them when they accept.
+ *
+ * Re-runnable: the table is made and each column added only where it isn't there yet.
+ */
+
+defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
+
+ $itflow_column = function ($table, $column) use ($mysqli) {
+ $result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column' LIMIT 1");
+ return $result && mysqli_num_rows($result) > 0;
+ };
+
+ mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `offices` (
+ `office_id` int(11) NOT NULL AUTO_INCREMENT,
+ `office_name` varchar(100) NOT NULL,
+ `office_address` varchar(200) NOT NULL DEFAULT '',
+ `office_city` varchar(200) NOT NULL DEFAULT '',
+ `office_state` varchar(200) NOT NULL DEFAULT '',
+ `office_zip` varchar(200) NOT NULL DEFAULT '',
+ `office_country` varchar(200) NOT NULL DEFAULT '',
+ `office_phone_country_code` varchar(10) NOT NULL DEFAULT '',
+ `office_phone` varchar(200) NOT NULL DEFAULT '',
+ `office_email` varchar(200) NOT NULL DEFAULT '',
+ `office_created_at` datetime NOT NULL DEFAULT current_timestamp(),
+ `office_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
+ `office_archived_at` datetime DEFAULT NULL,
+ PRIMARY KEY (`office_id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
+
+ if (!$itflow_column('users', 'user_office_id')) {
+ mysqli_query($mysqli, "ALTER TABLE `users` ADD `user_office_id` int(11) NOT NULL DEFAULT 0 AFTER `user_role_id`");
+ }
+ if (!$itflow_column('user_invites', 'invite_office_id')) {
+ mysqli_query($mysqli, "ALTER TABLE `user_invites` ADD `invite_office_id` int(11) NOT NULL DEFAULT 0 AFTER `invite_role_id`");
+ }
diff --git a/admin/modals/office/office.php b/admin/modals/office/office.php
new file mode 100644
index 000000000..c5c29a1cd
--- /dev/null
+++ b/admin/modals/office/office.php
@@ -0,0 +1,127 @@
+ Settings > Company Details, Offices
+ * (functions/offices.php; saved by save_office and taken away by remove_office
+ * in admin/post/office.php). ?office_id= to change one.
+ */
+
+require_once '../../includes/modal_header.php';
+
+$office_id = intval($_GET['office_id'] ?? 0);
+$office = $office_id ? office($office_id) : null;
+$office_id = $office ? $office_id : 0;
+$company = billingCompany();
+$localization = settingsLocalizationArrays();
+$agents = officeAgents();
+$people = officePeople();
+$offices = officesAll();
+$office_country = (string) ($office['country'] ?? $company['company_country'] ?? '');
+$phone_code = (string) ($office['phone_country_code'] ?? $company['company_phone_country_code'] ?? '');
+
+ob_start();
+
+if (!officesReady()) { ?>
+
Offices need the database update - run it from Maintenance > Update first.