diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0b1ab89b..38b3aea8f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -210,6 +210,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- Deleting an asset, contact, client or location through the API now also cleans up whatever pointed at it, the same as deleting it in ITFlow.
- New endpoint to read services, under the Support permission. Vendors take the account manager's phone and email.
- A call the key's role doesn't allow is refused with what it needs and what the key's user has - "This needs Modify on Support - the key's user, Tess Tech (Technician), has Read." - in place of "The user linked to this API key does not have permission for this action." It is still a 403. Anything that matches on the old text needs changing.
+- Audit log for agents: each client now has an Audit Log, and record pages show their history, to anyone who can open them - not only admins. An agent sees the kinds of entry their role covers - a technician without Financial sees no expenses or trips, someone without Credentials no passwords looked at - and never sign-ins, users, settings or another agent turned away from a client, which stay in Admin > Audit Logs. The client overview's Recent activity follows the same rule, so it can show a restricted role less than before.
- Audit log: each thing done now has one name, in the entries already there as well as new ones. Unarchive and Restored are Restore, Deleted is Delete, and Closed, Resolved, Reopened, Merged and Sent are Close, Resolve, Reopen, Merge and Send. An agent turned away from a client they can't open is Denied, where it was Access. A saved card or payment provider deleted is Delete and a card saved is Create, where both were Update, and a contract template changed is Edit. A report or script that reads the `logs` table by the old names needs the new ones.
### New Features & Updates
@@ -937,6 +938,11 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- The quick look on each entry shows all of it: the whole description, who with their email, the IP address with everything else from it, the browser as it reported itself, the record's other entries with a link to all of them, and what the same person did in the quarter hour either side, each of those opening in turn.
- Export downloads what you are looking at, or whatever you pick in the window, as a CSV or PDF, with the columns you choose - who, the record by name and the device among them. Each export is itself in the audit log.
- Entries that pointed at the wrong record now point at the right one, old ones included: editing or redacting a ticket reply is on the ticket, a document changed through the API on the document, paying an agent back on the expense that recorded it, and a client restored through the API on the client.
+ - Records show their own history: a History tab on contacts, assets, networks and projects, a History card on racks, documents and the ticket, project, document and license templates, and History folded at the foot of the file, expense, recurring expense and trip quick looks. Vendors, locations, licenses, services and products keep their History tab, in the same look. Each entry says what was done, who did it with their picture and when - and, for an admin, from which IP address - newest first, the latest 50 with how many more there are and a link to all of them in the audit log.
+ - Each client has an Audit Log in its menu, after Calendar: everything done for the client, searched and filtered by date, who, type and action, with views for Changes, Deletions, Sign-ins (their contacts signing in to the portal) and Data out, each entry linking to its record. Agents see the kinds of entry their role covers (see Breaking Changes). An admin also gets each entry's quick look and a button to Admin > Audit Logs. A record's history links here for all of it, showing that one record by name.
+ - The client overview's Recent activity links to the client's Audit Log, for everyone rather than admins only.
+ - Your account > Activity is rebuilt on the same list: everything you did, searched and filtered by date, a page at a time, with views for Changes, Deletions, Sign-ins and Data out, each entry with its client, its record and where you did it from. Sign-ins says what to do about one that wasn't you.
+ - A document's earlier versions are now in a card called Versions, with its history under it.
- **Emails** (rebuilt)
- Ticket emails to clients now look like the billing emails: your logo or name, a coloured heading saying what it is, the ticket's number, subject, status and priority in a box, the reply or the details quoted as they were written with who wrote them, a button to open the ticket, and your details at the foot. This covers a ticket opened by an agent, on a schedule or from an email, a reply, resolved, closed, being made a watcher, replying to a closed ticket, a reply through the API and a task needing their approval.
- Each says under it why they get it - the contact on the ticket, watching it, or asking for every update on their company's tickets - in place of the YOU ARE A COLLABORATOR block.
@@ -1588,6 +1594,10 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- New `functions/audit_log.php`: `auditLogKinds()` (by `log_type`: `icon`, and for a record its `table`, `id`, `name` - a column or expression - `client` and `url`, with `{id}`, `{client}` and `{client_q}`), `auditLogTypeIcon()`, `auditLogActionStyle()` (`tone`, `icon`), `auditLogActionPill()`, `auditLogViews()` (`label`, `icon`, `title`, `where`), `auditLogFiltersSql($src, &$summary)` (`q`, `client`, `user` - an id or `system` - `type`, `action`, `entity`, `view`, `dtf`, `dtt`), `auditLogJoinsSql()`, `auditLogRecords($rows)` (one query per kind), `auditLogRecordLink($row, $records, $label)`, `auditLogDescription($row)` (without the name in front), `auditLogWho($row)` (`name`, `kind` - agent, portal or system - `html`) and `auditLogDevice($user_agent)`.
- Admin: `admin/audit_logs.php` is rebuilt (`q`, `client`, `user`, `type`, `action`, `entity`, `view` - `changes`, `deletions`, `signins`, `security` or `data` - the date filter, `sort` - `log_created_at`, `user_name`, `client_name`, `log_type`, `log_action`, `log_ip` or `log_id` - `order` and `page`). New `admin/modals/audit_log/audit_log.php` (`id`) and `audit_log_export.php`, and `admin/post/audit_log.php` with `export_audit_logs` (the same filters, `columns[]` from the `audit_logs` export columns), written 500 rows at a time and audited as Audit Log Export.
- `agent/files.php` takes `open` (a file's id) to open its quick look, as the credential, certificate, domain, expense, recurring expense and trip lists do.
+ - Record history: `auditLogKinds()` gives each kind the `module` whose read access shows it to an agent (none: admins only). New `auditLogRoleSql()` (everything for an admin; else those kinds, and no Denied), `auditLogHistory($type, $id, $limit = 50)` (`type`, `id`, `client_id`, `rows`, `count`; role-scoped), `auditLogHistoryUrl($history, $client_id)` (Admin > Audit Logs for an admin, the client's Audit Log for an agent, '' otherwise), `auditLogHistoryHtml($history, $opts)` (`client_id`, `empty`, `flush`, `compact`), `auditLogHistoryCard()` (compact) and `auditLogHistorySection()` (collapsed, nothing when empty). Contacts, assets, networks and projects add a `history` tab; `agent/rack.php`, `agent/document.php` and the four admin template pages a card; the file, expense, recurring expense and trip quick looks a section. `vendorHistory()`, `locationHistory()`, `softwareHistory()`, `serviceHistory()` and `productHistory()` are removed - their pages use `auditLogHistory()`, whose count is now the tab's.
+ - New `agent/audit_log.php` (`client_id` - without it, admins go to Admin > Audit Logs and agents to the clients - `q`, `user`, `type`, `action`, `entity`, `view` - `changes`, `deletions`, `signins` or `data` - the date filter, `sort` - `log_created_at`, `user_name`, `log_type`, `log_action`, `log_ip` or `log_id` - `order` and `page`), scoped to the client and `auditLogRoleSql()`, in `client_side_nav.php` after Calendar. `clientOverviewActivity()` applies `auditLogRoleSql()`.
+ - `agent/user/user_activity.php` is rebuilt (`q`, `view`, the date filter, `sort` - `log_created_at`, `log_type`, `log_action`, `client_name`, `log_ip` or `log_id` - `order` and `page`), on the agent's own entries.
+ - The admin quick look's links to itself are absolute, so it opens from agent pages too.
- Empty states: every list page sets `$empty_state` before including `includes/filter_footer.php`, and `includes/inc_empty_state.php` draws it with `emptyStateHtml()` (`functions/format.php`) when the list has nothing - `thing`, `icon`, `title`, `text`, `actions` (`label`, `modal` or `href`, `size`, `icon`; the first is the main one), `archived`, `view`, `filtered`, `views`, `match_title`, `match_text` and `clear_url`. `emptyStateFiltered($views)` reads the GET string for a search or filter, leaving out paging, sorting, `client_id`, `archived` and the page's views, and `emptyStateClearUrl($views)` is the page without them. `emptyStatePill($pills, $key, $default, $good)` builds a pill's own state from the page's pill array (`label`, `icon`, `title`, `alarm`), with a tick for `alarm` pills and the keys in `$good`. Files, notifications and racks call `emptyStateHtml()` in their own layout; files and notifications set `$empty_state_skip`. A page that sets nothing still gets one, worded from `$page_title`. The pages' own empty blocks (`.itflow-asset-empty` under a list) are gone. CSS: `.itflow-empty-state` with `-icon` (a grey round tile), `-title`, `-text` and `-actions`.
- Removed unused helpers and files:
- `credentialLink()`, `projectLink()`, `linkCounts()`, `assetContactAvatar()`, `clientOverviewPersonInitials()`, and `getMonthlyTax()` and `getQuarterlyTax()`, which looked a tax up by name
diff --git a/admin/document_template.php b/admin/document_template.php
index 19130e071..9e175674e 100644
--- a/admin/document_template.php
+++ b/admin/document_template.php
@@ -326,6 +326,9 @@ $required_url = "modals/document_template/document_template_required.php?id=$doc
+
+ = auditLogHistoryCard(auditLogHistory('Document Template', $document_template_id, 10)) ?>
+
diff --git a/admin/modals/audit_log/audit_log.php b/admin/modals/audit_log/audit_log.php
index 94b9326ee..1027263ca 100644
--- a/admin/modals/audit_log/audit_log.php
+++ b/admin/modals/audit_log/audit_log.php
@@ -64,7 +64,7 @@ if ($user_id > 0) {
$entry_line = function ($entry, $show_when_as = 'date') {
$time = strtotime($entry['log_created_at']);
$when = $show_when_as === 'time' ? date('g:i A', $time) : date('M j, Y g:i A', $time);
- return ''
+ return ''
. '' . escapeHtml($when) . ''
. '' . auditLogActionPill($entry['log_action']) . ''
. '' . escapeHtml($entry['log_description']) . ''
diff --git a/admin/project_template.php b/admin/project_template.php
index 0dded67cd..25623fddf 100644
--- a/admin/project_template.php
+++ b/admin/project_template.php
@@ -159,6 +159,10 @@ $archived = !empty($template['project_template_archived_at']);
diff --git a/agent/contact.php b/agent/contact.php
index acbd0fbdf..c667b47e4 100644
--- a/agent/contact.php
+++ b/agent/contact.php
@@ -7,7 +7,7 @@
* with a click to call or email them; how to reach them and the details a
* tech needs on a call (location, PIN, portal access) down the side; and
* everything linked to them - assets, credentials, tickets, licenses,
- * documents, files, services, notes - in tabs with counts. The open tab
+ * documents, files, services, notes - and their history in tabs with counts. The open tab
* follows the URL hash (#tickets) and is remembered between visits.
*/
@@ -171,6 +171,9 @@ while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
}
// The tabs, in the order a tech reaches for them
+// Its history, from the audit log
+$history = auditLogHistory('Contact', $contact_id);
+
$contact_tabs = [
'assets' => ['label' => 'Assets', 'icon' => 'fa-desktop', 'count' => $asset_count],
'credentials' => ['label' => 'Credentials', 'icon' => 'fa-key', 'count' => $credential_count],
@@ -181,6 +184,7 @@ $contact_tabs = [
'files' => ['label' => 'Files', 'icon' => 'fa-paperclip', 'count' => $file_count],
'services' => ['label' => 'Services', 'icon' => 'fa-stream', 'count' => $service_count],
'notes' => ['label' => 'Notes', 'icon' => 'fa-sticky-note', 'count' => $note_count],
+ 'history' => ['label' => 'History', 'icon' => 'fa-history', 'count' => $history['count']],
];
if (!$can_credentials) {
unset($contact_tabs['credentials']);
@@ -773,6 +777,14 @@ if (!$can_support) {
+
+
+
+ Changes to them, their portal access and notes - newest first.
+
diff --git a/agent/project.php b/agent/project.php
index b6fd7ea3f..a8a684cbb 100644
--- a/agent/project.php
+++ b/agent/project.php
@@ -3,8 +3,9 @@
/*
* A project - what it is, who it is for and who runs it, how far along it
* is, the time logged against the hours budgeted and when it is due, then
- * its tickets, all their tasks and what has been said on them lately. The
- * side shows the scope, the details and the team that has worked on it.
+ * its tickets, all their tasks, what has been said on them lately and its
+ * history. The side shows the scope, the details and the team that has
+ * worked on it.
*
* Progress and time count every ticket on the project; the lists show the
* tickets this agent may reach (an internal project can hold any client's).
@@ -118,10 +119,14 @@ $team = projectTeam($project_id);
// Templates to add tickets from
$has_templates = $can_edit && $is_open && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM project_templates WHERE project_template_archived_at IS NULL LIMIT 1"));
+// Its history, from the audit log
+$history = auditLogHistory('Project', $project_id);
+
$project_tabs = [
'tickets' => ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'count' => count($tickets), 'badge' => $stats['open']],
'tasks' => ['label' => 'Tasks', 'icon' => 'fa-tasks', 'count' => $stats['tasks']],
'activity' => ['label' => 'Activity', 'icon' => 'fa-comments', 'count' => count($activity)],
+ 'history' => ['label' => 'History', 'icon' => 'fa-history', 'count' => $history['count']],
];
$new_ticket_url = "modals/ticket/ticket_add.php?" . ($project_client_id ? "client_id=$project_client_id&" : '') . "project_id=$project_id";
@@ -543,6 +548,14 @@ $contact_archived = !empty($project['contact_archived_at']);
diff --git a/agent/rack.php b/agent/rack.php
index 4f7e58793..a9dd04063 100644
--- a/agent/rack.php
+++ b/agent/rack.php
@@ -7,8 +7,8 @@
* position on the face it is mounted on, every empty U a click away from
* adding something there. Around it, how full the rack is (units, the largest
* gap a full-depth item could still go in, power against the budget), the
- * rack's details and photos, the item list for print and search, and the
- * client's network gear that isn't racked anywhere yet.
+ * rack's details and photos, the item list for print and search, the
+ * client's network gear that isn't racked anywhere yet, and its history.
*/
require_once "includes/inc_all_client.php";
@@ -441,6 +441,11 @@ if (mysqli_num_rows($sql) == 0) {
';
+ }
+ return $html;
+}
+
+/** A record's history as a card of its own, for a page without tabs - narrow, so compact. $opts as auditLogHistoryHtml(), and 'title'. */
+function auditLogHistoryCard(array $history, array $opts = []) {
+ $opts += ['compact' => true];
+ return '
';
+}
+
+/*
+ * A record's history folded away at the foot of its quick look - History
+ * with its count, opening to the list. Nothing when it has none.
+ */
+function auditLogHistorySection(array $history, array $opts = []) {
+ if (!$history['count']) {
+ return '';
+ }
+ $id = 'auditHistory' . bin2hex(random_bytes(4));
+ return '