From c6eadf3fa31fee088413fd89501eb9a75887980a Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 17 Oct 2026 01:28:27 -0400 Subject: [PATCH] Client portal stage 1, look, home and tickets: a new light shell with the company logo or initials on the theme colour, sections shown by what each contact may open (Home, Tickets, Billing for billing contacts, Your IT for technical contacts, custom links), New ticket and an account menu with a dark mode switch kept in a cookie, a bottom tab bar and slide-in menu on phones, and the welcome banner removed; a rebuilt home showing what needs the contact (tickets waiting on their reply or to confirm, approvals, past-due invoices), open tickets, balance with Pay invoices, renewals in the next 45 days, their devices with warranty status and the company phone and email; tickets rebuilt with Open, Waiting on you, Resolved, Closed and All tabs with counts, search, paging and the whole company's tickets for primary and technical contacts with a Mine filter, the old all-tickets page redirecting there; a ticket page with progress steps, the conversation oldest first, approvals, details alongside, replies with drag and drop attachments, It's fixed, close or reopen and rating; New Ticket with priority, category, device and attachments; fixes downloading files from internal notes, files on closed tickets not downloading, new tickets linking to another client's device or a non-ticket category, empty replies and tickets being accepted, PHP warnings on Pay invoices and Recurring invoices with no payment provider, and Bootstrap icons and the editor setup blocked by the portal CSP, which now allows data: images; new js/portal.js and portal helpers in client/functions.php, ticketPortalStatusHtml removed; changelog updated --- CHANGELOG.md | 23 +- client/activity.php | 2 +- client/document.php | 2 +- client/functions.php | 174 +++++++- client/includes/footer.php | 77 +--- client/includes/header.php | 247 +++++------ client/index.php | 558 +++++++++++++----------- client/post.php | 41 +- client/recurring_invoices.php | 2 +- client/ticket.php | 579 +++++++++++-------------- client/ticket_add.php | 168 +++++--- client/ticket_attachment.php | 9 +- client/ticket_view_all.php | 86 +--- client/tickets.php | 239 ++++++----- client/unpaid_invoices.php | 2 +- css/itflow_custom.css | 783 ++++++++++++++++++++++++++++++++++ functions/ticket.php | 17 - js/portal.js | 199 +++++++++ 18 files changed, 2146 insertions(+), 1062 deletions(-) create mode 100644 js/portal.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d878de8..ff16fd504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run Click the value and pick a new one, or use the + at the end of a record's tags. Each change saves straight away. - Tickets: a closed ticket can no longer be changed, either from the ticket's windows or through the API. Merging is only offered between tickets of the same client. +- Client portal: primary and technical contacts' Tickets page now opens on everyone's tickets at their company, with Mine to see only their own. The separate All tickets page is gone, and links to it land on Tickets. A ticket shows the client where it stands - Received, In progress, Waiting on you, On hold, Resolved or Closed - rather than your ticket statuses. - Invoicing a ticket: - The invoice line now reads `Ticket TCK-123 - Subject - 10/14/2026`. It used to be a block of text with the agent, dates, contact, asset and time spent. You can still edit it before adding the line. - Billing a ticket goes in the ticket's history ("Billed on invoice INV-45"). It used to add an internal note to the conversation. @@ -421,7 +422,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run - New Ticket can start from an asset or contact, and shows when they already have open tickets. - Recurring tickets can be paused and resumed or raised now. Their schedules are written out in plain words with a preview of the next run, and bulk actions are available. - The ticket lists on asset, contact, location, vendor and project pages look and work like the main list. - - Client portal: a ticket waiting on the client says Waiting on your reply. + - Client portal: a ticket waiting on the client says Waiting on you (see Client portal). - **Projects** - The projects list has views for Active, Mine, Overdue, Due soon, Stalled, Over budget, Ready to close, Completed, Archived and All. - Each row shows ticket and task progress bars, time logged against the budget with unbilled hours, and due badges, and the manager can be changed in place. @@ -672,6 +673,14 @@ If you are coming from 26.08 or earlier, the database update still has to be run - A cleared line's quick look says which statement it cleared on, and its Edit window keeps its amount, date and account as they are (see Breaking Changes, Accounts, transactions and transfers). - Reconciling needs write access to Financial, and undoing a reconciled statement full access. Agents with read access can look at the statements. - The demo data reconciles Operating Checking and the Business Visa to each month's statement through last month. +- **Client portal** (rebuilt: the look, home and tickets) + - A new look: a light top bar with your logo, or your company's initials on your theme colour, and the sections the contact can open - Home, Tickets, Billing for billing contacts, Your IT for technical contacts, and your custom links - with New ticket and their account menu. On a phone the sections sit in a bar along the bottom and a menu that slides in. Contacts can switch to dark mode from their account menu, and it stays that way. The welcome banner along the top of every page is gone. + - Home shows what needs the contact first: tickets waiting on their reply or resolved for them to confirm, tasks waiting for their approval and invoices past due. Then their open tickets, what is owed with Pay invoices, the domains, certificates, licenses and warranties renewing in the next 45 days or lapsed in the last 30, the devices they use with any warranty that has run out or is about to, and your phone and email when they are set. + - Tickets has tabs for Open, Waiting on you, Resolved, Closed and All, each with its count, a search by subject or number, and 20 to a page. Primary and technical contacts see their whole company's, with who raised each, and Mine for their own. + - A ticket shows how far it has got - received, in progress, resolved, closed - and the conversation oldest first, with the contact's own messages on the right and the files that came with each. Tasks waiting for their approval have Approve. Alongside are the priority, category, who raised it, who is working on it, the device and how many tasks are done. + - Replies take files dropped onto the form or chosen, listed before they are sent. It's fixed marks a ticket resolved once its tasks are done, a resolved ticket asks them to close it or reopen it, and a closed one asks how you did. + - New Ticket asks how much it is getting in the way, what it is about and which device - their own, or any of their company's for primary and technical contacts - and takes screenshots and files. Alongside it is what happens next, and your phone number for anything urgent when it is set. + - The billing, Your IT and account pages are in the new look and work as before. They are rebuilt in the stages to come. ### Bug Fixes @@ -733,6 +742,12 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Accounts: New Account saved whatever was typed, such as no name, the name of another account or a balance of words. Edit could only change the name and notes. - Transfers: a transfer could be saved from an account to itself, for nothing, or with no date. Editing one took which expense and income to change from the form, so a changed form could rewrite any expense or income. Neither side recorded who entered it. - Transactions: opening it for an account that no longer exists wrote PHP warnings. It now says so and shows every account's. +- Client Portal: a file attached to an internal note could be downloaded from the client portal by a contact who could see the ticket, by its number. Only the ticket's own files and those on replies the client can read download now. +- Client Portal: files on a closed ticket could not be downloaded from the portal. +- Client Portal: a new ticket could be linked to another client's device, or to a category that isn't a ticket category, by changing the form. Those are ignored now, and a plain contact can only pick a device they use. +- Client Portal: a reply of nothing but empty lines was accepted, and a new ticket could be raised with no details. +- Client Portal: Pay invoices and Recurring invoices wrote PHP warnings onto the page when no payment provider was set up. +- Client Portal: on most pages the browser blocked the arrows on drop-downs, the close crosses and the editor setup, as the portal's security policy didn't allow them. - Client Portal: a ticket rating could be saved as any value. Only Good and Bad, the two buttons the portal shows, are accepted now. The demo data rated tickets Great and Ok, which the portal never offers, and now uses Good and Bad. - Notifications that linked to a page did not open correctly from Admin pages. - Messages showed a backslash before apostrophes and quotes in names, or showed `&` instead of `&`. @@ -1045,6 +1060,12 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Sidebar brand: `agent/css/sidebar_brand_fix.css` and `agent/js/sidebar_brand_fix.js` from 26.10 are replaced by CSS in `css/itflow_custom.css`. `includes/load_company_settings.php` now sets `$session_company_logo`. - `alertMessageHtml()` no longer double-encodes, and save messages built from `escapeSql()` values use `stripslashes()` at the flash. - CSS: `[hidden] { display: none !important; }` at the top of `css/itflow_custom.css`, so the `hidden` attribute wins over `d-flex` and the other display utilities. `.pagination` wraps. +- Client portal shell: `client/includes/header.php` and `footer.php` are rewritten - the top bar, the phone tab bar and the `#portalMenu` offcanvas all draw from `portalNav()`. A page that sets the Content-Security-Policy keeps it, and the header widens it to `default-src 'self'; img-src 'self' data:`. Dark mode is the `itflow_portal_theme` cookie (`dark` or `light`), read by the header for the first paint. + - The new `js/portal.js`, loaded on every portal page: the dark mode switch (`[data-portal-theme-toggle]`), TinyMCE on `textarea.tinymce` (moved out of the inline script in the footer that the policy blocked; `data-required` checks the editor on submit), attachment drop zones (`[data-portal-drop]` with a file input and `[data-portal-files]`), `form[data-portal-once]`, and `.table-responsive` round any table a page left bare. + - `client/functions.php` adds `portalNav()`, `portalAvatarHtml($name, $photo_url, $size)`, `portalSeesAllTickets()`, `portalTicketScopeSql($mine_only)`, `portalTicketState($row)` and `portalTicketStateHtml($row)`, `portalTicketTabs()`, `portalTicketColumnsSql()`, `portalTicketEventText($html)` and `portalHtmlIsEmpty($html)`. `portalEmptyState()` draws `emptyStateHtml()`, and `verifyContactTicketAccess()` takes `Any`. + - `client/tickets.php` takes `tab` (`open`, `you`, `resolved`, `closed`, `all`), `scope` (`mine`), `q` and `page`. `client/ticket_view_all.php` redirects there. `add_ticket` takes `file[]` and checks the subject, details, category and asset. `client/ticket_attachment.php` refuses a file on an internal or archived reply. + - Removed: `ticketPortalStatusHtml()` from `functions/ticket.php`, replaced by `portalTicketStateHtml()`. + - CSS: the `.itflow-portal-*` classes, from `-header`, `-nav`, `-tabbar` and `-menu` to `-panel`, `-state-*`, `-tabs`, `-ticket`, `-steps`, `-msg`, `-event`, `-drop`, `-file-chip`, `-facts`, `-stat` and `-todo`. The black table heads on the pages not rebuilt yet are softened to sit in the light shell. - 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()` and `clientOverviewPersonInitials()` diff --git a/client/activity.php b/client/activity.php index 04348808a..d83094b02 100644 --- a/client/activity.php +++ b/client/activity.php @@ -56,7 +56,7 @@ $sql_activity = mysqli_query( - +
0) {
- <?= $file_name ?> + <?= $file_name ?>
' . $message . ''; + return emptyStateHtml([ + 'title' => rtrim((string) $message, '.'), + 'icon' => $type === 'success' ? 'fa-check' : $icon, + 'filtered' => false, + ]); +} + +/* + * The portal's sections, in menu order, as this contact may see them - the top + * bar, the phone menu and the tab bar all draw from this. Each has a label, an + * icon, the pages that light it up, and an href or children. + */ +function portalNav() { + global $mysqli, $config_module_enable_accounting, $config_module_enable_itdoc; + + $nav = [ + 'home' => ['label' => 'Home', 'icon' => 'fa-home', 'href' => '/client/index.php', 'pages' => ['index.php']], + 'tickets' => ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'href' => '/client/tickets.php', 'pages' => ['tickets.php', 'ticket.php', 'ticket_add.php', 'ticket_view_all.php']], + ]; + + if (contactCan('accounting') && $config_module_enable_accounting == 1) { + $children = [ + ['label' => 'Invoices', 'icon' => 'fa-file-invoice-dollar', 'href' => '/client/invoices.php', 'pages' => ['invoices.php']], + ['label' => 'Pay invoices', 'icon' => 'fa-hand-holding-usd', 'href' => '/client/unpaid_invoices.php', 'pages' => ['unpaid_invoices.php']], + ['label' => 'Quotes', 'icon' => 'fa-comment-dollar', 'href' => '/client/quotes.php', 'pages' => ['quotes.php']], + ['label' => 'Recurring invoices', 'icon' => 'fa-redo-alt', 'href' => '/client/recurring_invoices.php', 'pages' => ['recurring_invoices.php']], + ['label' => 'Statement', 'icon' => 'fa-file-alt', 'href' => '/client/statement.php', 'pages' => ['statement.php']], + ['label' => 'Saved cards', 'icon' => 'fa-credit-card', 'href' => '/client/saved_payment_methods.php', 'pages' => ['saved_payment_methods.php']], + ]; + $nav['billing'] = ['label' => 'Billing', 'icon' => 'fa-file-invoice-dollar', 'children' => $children, 'pages' => array_merge(...array_column($children, 'pages'))]; + } + + if ($config_module_enable_itdoc && contactCan('itdoc')) { + $children = [ + ['label' => 'Assets', 'icon' => 'fa-desktop', 'href' => '/client/assets.php', 'pages' => ['assets.php']], + ['label' => 'Documents', 'icon' => 'fa-folder-open', 'href' => '/client/documents.php', 'pages' => ['documents.php', 'document.php', 'file.php']], + ['label' => 'Domains', 'icon' => 'fa-globe', 'href' => '/client/domains.php', 'pages' => ['domains.php']], + ['label' => 'Certificates', 'icon' => 'fa-lock', 'href' => '/client/certificates.php', 'pages' => ['certificates.php']], + ['label' => 'Contacts', 'icon' => 'fa-address-book', 'href' => '/client/contacts.php', 'pages' => ['contacts.php', 'contact_add.php', 'contact_edit.php']], + ]; + $nav['it'] = ['label' => 'Your IT', 'icon' => 'fa-laptop', 'children' => $children, 'pages' => array_merge(...array_column($children, 'pages'))]; + } + + // The links an admin set to show in the portal (Admin > Custom Links) + $sql = mysqli_query($mysqli, "SELECT custom_link_id, custom_link_icon, custom_link_name, custom_link_new_tab, custom_link_uri FROM custom_links + WHERE custom_link_location = 3 AND custom_link_archived_at IS NULL ORDER BY custom_link_order ASC, custom_link_name ASC"); + while ($row = mysqli_fetch_assoc($sql)) { + $icon = preg_replace('/[^a-z0-9-]/', '', strtolower((string) $row['custom_link_icon'])); + $nav['link-' . intval($row['custom_link_id'])] = [ + 'label' => (string) $row['custom_link_name'], + 'icon_class' => 'fas fa-fw fa-' . ($icon !== '' ? $icon : 'external-link-alt'), + 'href' => (string) $row['custom_link_uri'], + 'new_tab' => intval($row['custom_link_new_tab']) === 1, + 'pages' => [basename((string) $row['custom_link_uri'])], + ]; + } + + return $nav; +} + +/** A round avatar - the photo when there is one, else initials on a tone picked from the name. */ +function portalAvatarHtml($name, $photo_url = '', $size = '') { + $class = 'itflow-portal-avatar' . ($size !== '' ? " itflow-portal-avatar-$size" : ''); + if ($photo_url !== '') { + return ''; + } + $initials = personInitials((string) $name) ?: '?'; + $tone = 1 + (abs(crc32((string) $name)) % 6); + return ''; +} + +/* + * ---------- tickets ---------- + * + * A ticket as the client sees it. The statuses agents work with (New, Open, + * On Hold and any of their own) mean little to a client, so the portal says + * where it stands for them: received, being worked on, waiting on them, on + * hold, resolved for them to confirm, or closed. + */ + +/** Whether this contact sees every ticket of their company, not only their own - primary and technical contacts. */ +function portalSeesAllTickets() { + global $session_contact_primary, $session_contact_is_technical_contact; + return $session_contact_primary == 1 || $session_contact_is_technical_contact; +} + +/** SQL: the tickets this contact may open - their company's, and only their own unless they see them all. */ +function portalTicketScopeSql($mine_only = false) { + global $session_client_id, $session_contact_id; + $sql = "tickets.ticket_client_id = " . intval($session_client_id); + if ($mine_only || !portalSeesAllTickets()) { + $sql .= " AND tickets.ticket_contact_id = " . intval($session_contact_id); + } + return $sql; +} + +/** + * Where a ticket stands for the client - key, label, icon and the badge class. + * From a row with ticket_status, ticket_resolved_at, ticket_closed_at, + * ticket_last_spoke (ticketLastSpokeSql()) and ticket_status_pauses_sla. + */ +function portalTicketState($row) { + if (!empty($row['ticket_closed_at'])) { + return ['key' => 'closed', 'label' => 'Closed', 'icon' => 'fa-check-circle', 'class' => 'itflow-portal-state-closed']; + } + if (!empty($row['ticket_resolved_at'])) { + return ['key' => 'resolved', 'label' => 'Resolved', 'icon' => 'fa-check', 'class' => 'itflow-portal-state-resolved']; + } + if (($row['ticket_last_spoke'] ?? null) === 'Public') { + return ['key' => 'you', 'label' => 'Waiting on you', 'icon' => 'fa-reply', 'class' => 'itflow-portal-state-you']; + } + if (intval($row['ticket_status_pauses_sla'] ?? 0) === 1) { + return ['key' => 'hold', 'label' => $row['ticket_status_name'] ?: 'On hold', 'icon' => 'fa-pause', 'class' => 'itflow-portal-state-hold']; + } + if (intval($row['ticket_status'] ?? 0) === 1 && empty($row['ticket_last_spoke'])) { + return ['key' => 'new', 'label' => 'Received', 'icon' => 'fa-inbox', 'class' => 'itflow-portal-state-new']; + } + return ['key' => 'progress', 'label' => 'In progress', 'icon' => 'fa-tools', 'class' => 'itflow-portal-state-progress']; +} + +/** The state as a badge. */ +function portalTicketStateHtml($row) { + $state = portalTicketState($row); + return '' . escapeHtml($state['label']) . ''; +} + +/** The ticket list's tabs - each with its label, icon and SQL. Needs tickets joined to ticket_statuses. */ +function portalTicketTabs() { + $spoke = ticketLastSpokeSql(); + return [ + 'open' => ['label' => 'Open', 'icon' => 'fa-folder-open', 'where' => TICKET_OPEN_SQL], + 'you' => ['label' => 'Waiting on you', 'icon' => 'fa-reply', 'where' => TICKET_OPEN_SQL . " AND $spoke = 'Public'"], + 'resolved' => ['label' => 'Resolved', 'icon' => 'fa-check', 'where' => 'tickets.ticket_resolved_at IS NOT NULL AND tickets.ticket_closed_at IS NULL'], + 'closed' => ['label' => 'Closed', 'icon' => 'fa-check-circle', 'where' => 'tickets.ticket_closed_at IS NOT NULL'], + 'all' => ['label' => 'All', 'icon' => 'fa-list', 'where' => '1 = 1'], + ]; +} + +/** The columns a ticket list or page needs for portalTicketState(), with the ticket's own. */ +function portalTicketColumnsSql() { + return "tickets.ticket_id, tickets.ticket_prefix, tickets.ticket_number, tickets.ticket_subject, tickets.ticket_status, tickets.ticket_priority, + tickets.ticket_created_at, tickets.ticket_updated_at, tickets.ticket_resolved_at, tickets.ticket_closed_at, tickets.ticket_contact_id, + ticket_statuses.ticket_status_name, ticket_statuses.ticket_status_pauses_sla, " . ticketLastSpokeSql() . " AS ticket_last_spoke"; +} + +/** Whether what the editor sent says nothing - only tags, spaces and non-breaking spaces, and no picture. */ +function portalHtmlIsEmpty($html) { + $html = (string) $html; + if (stripos($html, ' - - + - -
- Powered by ITFlow'; - } - ?> + +
+
+ + + Powered by ITFlow + +
- - - - - - + - - @@ -94,6 +44,7 @@ + diff --git a/client/includes/header.php b/client/includes/header.php index f416dc26b..dfc3064bd 100644 --- a/client/includes/header.php +++ b/client/includes/header.php @@ -1,14 +1,40 @@ - + @@ -17,6 +43,7 @@ header("X-Frame-Options: DENY"); // Legacy + @@ -35,9 +62,8 @@ header("X-Frame-Options: DENY"); // Legacy - + - - +
+
- + +
+ New ticket + +
+
+
+ + + - - -
- - -
-
- - ... - - - - - - - +
+
+
+
+
- -

Welcome, !

- - - "> - +
-
+
+ + +
+ + + + + > + + +
Your account
+ Your account + Activity + + Sign out +
+
+ + +
'ticket.php?id=' . intval($row['ticket_id']), + 'icon' => $resolved ? 'fa-check' : 'fa-reply', + 'tone' => $resolved ? 'is-info' : '', + 'title' => $row['ticket_subject'], + 'line' => ($resolved ? 'Resolved - is it fixed? Close it, or reopen it' : 'We replied - waiting on you') . ' · ' . $row['ticket_prefix'] . $row['ticket_number'], + ]; +} -$amount_paid = floatval($row['amount_paid']); +// Tasks on their tickets waiting for the client's approval +$sql = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, task_name FROM task_approvals + JOIN tasks ON task_id = approval_task_id + JOIN tickets ON tickets.ticket_id = task_ticket_id + LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id + WHERE $scope_sql AND approval_scope = 'client' AND approval_status = 'pending' AND task_completed_at IS NULL AND tickets.ticket_closed_at IS NULL + ORDER BY approval_id DESC LIMIT 4"); +while ($row = mysqli_fetch_assoc($sql)) { + $needs_you[] = [ + 'href' => 'ticket.php?id=' . intval($row['ticket_id']), + 'icon' => 'fa-clipboard-check', + 'tone' => '', + 'title' => 'Approve: ' . $row['task_name'], + 'line' => 'Waiting for your approval · ' . $row['ticket_prefix'] . $row['ticket_number'], + ]; +} -$balance = $invoice_amounts - $amount_paid; +// Money - what is owed, and what is past due +$balance = 0.0; +$overdue = 0.0; +$overdue_count = 0; +$next_due = null; +$client_currency = $session_company_currency; +if ($can_billing) { + $client_currency = mysqli_fetch_row(mysqli_query($mysqli, "SELECT client_currency_code FROM clients WHERE client_id = $session_client_id"))[0] ?: $session_company_currency; + foreach (billingClientOpenInvoices($session_client_id) as $invoice) { + $left = round(floatval($invoice['invoice_amount']) - floatval($invoice['paid']), 2); + $balance += $left; + if ($invoice['invoice_due'] < date('Y-m-d')) { + $overdue += $left; + $overdue_count++; + $needs_you[] = [ + 'href' => 'unpaid_invoices.php', + 'icon' => 'fa-file-invoice-dollar', + 'tone' => 'is-danger', + 'title' => 'Invoice ' . $invoice['invoice_prefix'] . $invoice['invoice_number'] . ' is past due', + 'line' => numfmt_format_currency($currency_format, $left, $client_currency) . ' left - due ' . date('M j, Y', strtotime($invoice['invoice_due'])), + ]; + } elseif ($next_due === null || $invoice['invoice_due'] < $next_due) { + $next_due = $invoice['invoice_due']; + } + } +} -// What their recurring invoices come to a month - quarterly ones a third, yearly ones a twelfth -$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(" . recurringInvoiceMonthlySql() . "), 0) FROM recurring_invoices - WHERE recurring_invoice_status = 1 AND recurring_invoice_archived_at IS NULL AND recurring_invoice_client_id = $session_client_id")); -$recurring_monthly = floatval($row[0]); +// Open tickets, newest first +$recent = mysqli_query($mysqli, "SELECT " . portalTicketColumnsSql() . ", contact_name FROM tickets + LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id + LEFT JOIN contacts ON contact_id = tickets.ticket_contact_id + WHERE $scope_sql AND tickets.ticket_archived_at IS NULL AND {$tabs['open']['where']} + ORDER BY COALESCE(tickets.ticket_updated_at, tickets.ticket_created_at) DESC LIMIT 5"); -// Technical Card Queries -// 8 - 45 Day Warning +// Renewals coming up in the next 45 days, and anything that lapsed in the last 30 +$renewals = []; +if ($can_it) { + $window = "BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE() + INTERVAL 45 DAY"; + $sources = [ + ['domains.php', 'fa-globe', 'Domain', "SELECT domain_name, domain_expire FROM domains WHERE domain_client_id = $session_client_id AND domain_archived_at IS NULL AND domain_expire $window"], + ['certificates.php', 'fa-lock', 'Certificate', "SELECT certificate_name, certificate_expire FROM certificates WHERE certificate_client_id = $session_client_id AND certificate_archived_at IS NULL AND certificate_expire $window"], + ['', 'fa-cube', 'License', "SELECT software_name, software_expire FROM software WHERE software_client_id = $session_client_id AND software_archived_at IS NULL AND software_expire $window"], + ['assets.php', 'fa-shield-alt', 'Warranty', "SELECT asset_name, asset_warranty_expire FROM assets WHERE asset_client_id = $session_client_id AND asset_archived_at IS NULL AND asset_warranty_expire $window"], + ]; + foreach ($sources as [$href, $icon, $kind, $query]) { + $sql = mysqli_query($mysqli, $query); + while ($row = mysqli_fetch_row($sql)) { + $renewals[] = ['href' => $href, 'icon' => $icon, 'kind' => $kind, 'name' => $row[0], 'date' => $row[1]]; + } + } + usort($renewals, function ($a, $b) { return strcmp($a['date'], $b['date']); }); +} -// Get Domains Expiring -$sql_domains_expiring = mysqli_query( - $mysqli, - "SELECT domain_expire, domain_id, domain_name FROM domains - WHERE domain_client_id = $session_client_id - AND domain_expire IS NOT NULL - AND domain_archived_at IS NULL - AND domain_expire > CURRENT_DATE - AND domain_expire < CURRENT_DATE + INTERVAL 45 DAY - ORDER BY domain_expire ASC" -); +// The devices this contact uses +$devices = []; +$sql = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_make, asset_model, asset_warranty_expire, asset_uri_client FROM assets + WHERE asset_contact_id = $session_contact_id AND asset_client_id = $session_client_id AND asset_archived_at IS NULL ORDER BY asset_name ASC LIMIT 6"); +while ($row = mysqli_fetch_assoc($sql)) { + $devices[] = $row; +} -// Get Certificates Expiring -$sql_certificates_expiring = mysqli_query( - $mysqli, - "SELECT * FROM certificates - WHERE certificate_client_id = $session_client_id - AND certificate_expire IS NOT NULL - AND certificate_archived_at IS NULL - AND certificate_expire > CURRENT_DATE - AND certificate_expire < CURRENT_DATE + INTERVAL 45 DAY - ORDER BY certificate_expire ASC" -); +// How to reach us +$company = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT company_phone, company_phone_country_code, company_email, company_website FROM companies WHERE company_id = 1")); -// Get Licenses Expiring -$sql_licenses_expiring = mysqli_query( - $mysqli, - "SELECT * FROM software - WHERE software_client_id = $session_client_id - AND software_expire IS NOT NULL - AND software_archived_at IS NULL - AND software_expire > CURRENT_DATE - AND software_expire < CURRENT_DATE + INTERVAL 45 DAY - ORDER BY software_expire ASC" -); - -// Get Asset Warranties Expiring -$sql_asset_warranties_expiring = mysqli_query( - $mysqli, - "SELECT * FROM assets - WHERE asset_client_id = $session_client_id - AND asset_warranty_expire IS NOT NULL - AND asset_archived_at IS NULL - AND asset_warranty_expire > CURRENT_DATE - AND asset_warranty_expire < CURRENT_DATE + INTERVAL 45 DAY - ORDER BY asset_warranty_expire ASC" -); - -// Get Assets Retiring 7 Year -$sql_asset_retire = mysqli_query( - $mysqli, - "SELECT * FROM assets - WHERE asset_client_id = $session_client_id - AND asset_install_date IS NOT NULL - AND asset_archived_at IS NULL - AND asset_install_date + INTERVAL 7 YEAR > CURRENT_DATE - AND asset_install_date + INTERVAL 7 YEAR <= CURRENT_DATE + INTERVAL 45 DAY - ORDER BY asset_install_date ASC" -); - -/* - * EXPIRED ITEMS - */ - -// Get Domains Expired -$sql_domains_expired = mysqli_query( - $mysqli, - "SELECT * FROM domains - WHERE domain_client_id = $session_client_id - AND domain_expire IS NOT NULL - AND domain_archived_at IS NULL - AND domain_expire < CURRENT_DATE - ORDER BY domain_expire ASC" -); - -// Get Certificates Expired -$sql_certificates_expired = mysqli_query( - $mysqli, - "SELECT * FROM certificates - WHERE certificate_client_id = $session_client_id - AND certificate_expire IS NOT NULL - AND certificate_archived_at IS NULL - AND certificate_expire < CURRENT_DATE - ORDER BY certificate_expire ASC" -); - -// Get Licenses Expired -$sql_licenses_expired = mysqli_query( - $mysqli, - "SELECT * FROM software - WHERE software_client_id = $session_client_id - AND software_expire IS NOT NULL - AND software_archived_at IS NULL - AND software_expire < CURRENT_DATE - ORDER BY software_expire ASC" -); - -// Get Asset Warranties Expired -$sql_asset_warranties_expired = mysqli_query( - $mysqli, - "SELECT * FROM assets - WHERE asset_client_id = $session_client_id - AND asset_warranty_expire IS NOT NULL - AND asset_archived_at IS NULL - AND asset_warranty_expire < CURRENT_DATE - ORDER BY asset_warranty_expire ASC" -); - -// Get Retired Assets -$sql_asset_retired = mysqli_query( - $mysqli, - "SELECT * FROM assets - WHERE asset_client_id = $session_client_id - AND asset_install_date IS NOT NULL - AND asset_archived_at IS NULL - AND asset_install_date + INTERVAL 7 YEAR < CURRENT_DATE -- Assets retired (installed more than 7 years ago) - ORDER BY asset_install_date ASC" -); - -// Assigned Assets -$sql_assigned_assets = mysqli_query( - $mysqli, - "SELECT asset_name, asset_type, asset_uri_client FROM assets - WHERE asset_contact_id = $session_contact_id - AND asset_archived_at IS NULL - ORDER BY asset_name ASC" -); - -?> -
- -
- - - - - - - -
+
+
+

+

+
+
+ 0) { ?> + Pay invoices + +
+
- 0) { ?> -
- -
-
-

Domains Expiring

+
+ +
+
+ +
+
+

Needs you

+
+ + "You're all caught up", 'text' => 'Nothing is waiting on you right now.', 'icon' => 'fa-check', 'filtered' => false]) ?> + + + +
+ +
+
+

+ All tickets +
+ + 'No open tickets', 'text' => 'Something not working? Raise a ticket and we will pick it up.', 'icon' => 'fa-life-ring', 'filtered' => false, + 'actions' => [['label' => 'New ticket', 'href' => 'ticket_add.php']]]) ?> + + + +
+ +
+
+ + +
+
+

Your devices

+ All assets
-
- + +
  • + + +
    +
    + + + · Warranty + +
    +
    + + + +
  • + + +
    + - while ($row = mysqli_fetch_assoc($sql_domains_expiring)) { - $domain_id = intval($row['domain_id']); - $domain_name = escapeHtml($row['domain_name']); - $domain_expire = escapeHtml($row['domain_expire']); - $domain_expire_human = timeAgo($row['domain_expire']); - - ?> -

    - -
    - () -

    - + +
    +
    +

    Coming up

    -
    - + + 'Nothing renewing soon', 'text' => 'Domains, certificates, licenses and warranties due in the next 45 days show here.', 'icon' => 'fa-check', 'filtered' => false]) ?> + +
      + +
    • + + +
      +
      · ()
      +
      +
    • + +
    + + + + + +
    +
    +

    Need us fast?

    +
    +
    +

    For anything urgent, call us - and raise a ticket so it is on record.

    + +
    + + +
    + +
    +
    + +
    - - -
    - - - - -
    - - - - - - -
    ()
    - - - - diff --git a/client/post.php b/client/post.php index 636f12e76..53cb2d80b 100644 --- a/client/post.php +++ b/client/post.php @@ -14,10 +14,30 @@ if (isset($_POST['add_ticket'])) { validateCSRFToken(); - $subject = escapeSql($_POST['subject']); - $details = mysqli_real_escape_string($mysqli, ($_POST['details'])); - $category = intval($_POST['category']); - $asset = intval($_POST['asset']); + // A subject and something in the details - the editor checks this too, but + // a page that never loaded it would send them blank + $raw_details = (string) ($_POST['details'] ?? ''); + if (trim((string) ($_POST['subject'] ?? '')) === '' || portalHtmlIsEmpty($raw_details)) { + flashAlert("Give the ticket a subject and tell us what is happening", 'error'); + redirect('ticket_add.php'); + } + + $subject = escapeSql(mb_substr(trim($_POST['subject']), 0, 500)); + $details = mysqli_real_escape_string($mysqli, $raw_details); + $category = intval($_POST['category'] ?? 0); + $asset = intval($_POST['asset'] ?? 0); + + // Only a ticket category that is in use + if ($category && !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM categories WHERE category_id = $category AND category_type = 'Ticket' AND category_archived_at IS NULL"))) { + $category = 0; + } + + // Only one of their company's devices - their own, or any of the company's + // for a primary or technical contact, as the form offers + if ($asset && !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM assets WHERE asset_id = $asset AND asset_client_id = $session_client_id AND asset_archived_at IS NULL" + . (portalSeesAllTickets() ? '' : " AND asset_contact_id = $session_contact_id")))) { + $asset = 0; + } // Get settings from load_global_settings.php $config_ticket_prefix = escapeSql($config_ticket_prefix); @@ -51,6 +71,9 @@ if (isset($_POST['add_ticket'])) { $ticket_id = mysqli_insert_id($mysqli); applyTicketSla($ticket_id); + // Screenshots and files sent with it belong to the ticket itself + saveTicketAttachments($ticket_id, null, 'file'); + // Notify agent DL of the new ticket, if populated with a valid email if ($config_ticket_new_ticket_notification_email) { @@ -87,11 +110,13 @@ if (isset($_POST['add_ticket_comment'])) { validateCSRFToken(); $ticket_id = intval($_POST['ticket_id']); - $comment = mysqli_real_escape_string($mysqli, $_POST['comment']); + $raw_comment = (string) ($_POST['comment'] ?? ''); + $comment = mysqli_real_escape_string($mysqli, $raw_comment); - // After stripping bad HTML, check the comment isn't just empty - if (empty($comment)) { - flashAlert("You must enter a comment", 'danger'); + // Nothing but empty paragraphs from the editor is no reply - a picture on + // its own is + if (portalHtmlIsEmpty($raw_comment)) { + flashAlert("Write a reply first", 'error'); redirect(); } diff --git a/client/recurring_invoices.php b/client/recurring_invoices.php index 4ac5978af..367e34f60 100644 --- a/client/recurring_invoices.php +++ b/client/recurring_invoices.php @@ -23,7 +23,7 @@ $recurring_invoices_sql = mysqli_query($mysqli, "SELECT recurring_invoice_amount // Get Payment Provide Details $payment_provider_sql = mysqli_query($mysqli, "SELECT payment_provider_id, payment_provider_name, payment_provider_threshold FROM payment_providers WHERE payment_provider_active = 1 LIMIT 1"); -$row = mysqli_fetch_assoc($payment_provider_sql); +$row = mysqli_fetch_assoc($payment_provider_sql) ?: ['payment_provider_id' => 0, 'payment_provider_name' => '', 'payment_provider_threshold' => 0]; // none set up - nothing to pay with $payment_provider_id = intval($row['payment_provider_id']); $payment_provider_name = escapeHtml($row['payment_provider_name']); $payment_provider_threshold = floatval($row['payment_provider_threshold']); diff --git a/client/ticket.php b/client/ticket.php index 03ef07bbe..4544855ab 100644 --- a/client/ticket.php +++ b/client/ticket.php @@ -1,7 +1,16 @@ set('Cache.DefinitionImpl', null); // Disable cache by setting $purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]); $purifier = new HTMLPurifier($purifier_config); -$allowed_extensions = array('jpg', 'jpeg', 'gif', 'png', 'webp', 'pdf', 'txt', 'md', 'doc', 'docx', 'csv', 'xls', 'xlsx', 'xlsm', 'zip', 'tar', 'gz'); +$ticket_id = intval($_GET['id'] ?? 0); +$ticket = $ticket_id ? mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT " . portalTicketColumnsSql() . ", tickets.ticket_details, tickets.ticket_feedback, + tickets.ticket_assigned_to, tickets.ticket_asset_id, user_name, user_avatar, category_name, contact_name, contact_photo, asset_name, asset_type + FROM tickets + LEFT JOIN users ON ticket_assigned_to = user_id + LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id + LEFT JOIN categories ON ticket_category = category_id + LEFT JOIN contacts ON contact_id = tickets.ticket_contact_id + LEFT JOIN assets ON asset_id = tickets.ticket_asset_id AND asset_client_id = tickets.ticket_client_id + WHERE tickets.ticket_id = $ticket_id AND " . portalTicketScopeSql() . " LIMIT 1")) : null; -if (isset($_GET['id']) && intval($_GET['id'])) { - $ticket_id = intval($_GET['id']); +if (!$ticket) { + ?> + Tickets +
    + "That ticket isn't here", 'text' => 'It may belong to someone else at your company, or the link is out of date.', 'icon' => 'fa-life-ring', 'filtered' => false, + 'actions' => [['label' => 'Your tickets', 'href' => 'tickets.php', 'icon' => 'fa-list']]]) ?> +
    + ' + . portalAvatarHtml($name, $avatar_url, 'lg') + . '
    ' + . '
    ' . escapeHtml($mine ? 'You' : $name) . '' + . ($agent ? '' . escapeHtml($GLOBALS['session_company_name']) . '' : '') + . '' . portalDateTime($when) . '
    ' + . '
    ' . $body_html; + if ($files) { + $html .= '
    '; + foreach ($files as $file) { + $id = intval($file['ticket_attachment_id']); + $html .= '' + . '' . escapeHtml($file['ticket_attachment_name']) . '' + . ''; + } + $html .= '
    '; } + return $html . '
    '; +} - $ticket_sql = mysqli_query($mysqli, - "SELECT * FROM tickets - LEFT JOIN users on ticket_assigned_to = user_id - LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id - LEFT JOIN categories ON ticket_category = category_id - WHERE ticket_id = $ticket_id AND ticket_client_id = $session_client_id - $ticket_contact_snippet" - ); +// Where it has got to: received, in progress, resolved, closed +$steps = ['Received', 'In progress', 'Resolved', 'Closed']; +$at = $closed ? 3 : ($resolved ? 2 : ($state['key'] === 'new' ? 0 : 1)); - $ticket_row = mysqli_fetch_assoc($ticket_sql); +$requester = (string) ($ticket['contact_name'] ?? ''); +$requester_photo = $ticket['contact_photo'] ? "/uploads/clients/$session_client_id/" . $ticket['contact_photo'] : ''; +$agent_name = (string) ($ticket['user_name'] ?? ''); +?> - if ($ticket_row) { +Tickets - $ticket_prefix = escapeHtml($ticket_row['ticket_prefix']); - $ticket_number = intval($ticket_row['ticket_number']); - $ticket_status = escapeHtml($ticket_row['ticket_status_name']); - $ticket_priority = escapeHtml($ticket_row['ticket_priority']); - $ticket_subject = escapeHtml($ticket_row['ticket_subject']); - $ticket_details = $purifier->purify($ticket_row['ticket_details']); - $ticket_assigned_to = escapeHtml($ticket_row['user_name']); - $ticket_resolved_at = escapeHtml($ticket_row['ticket_resolved_at']); - $ticket_closed_at = escapeHtml($ticket_row['ticket_closed_at']); - $ticket_feedback = escapeHtml($ticket_row['ticket_feedback']); - $ticket_category = escapeHtml($ticket_row['category_name']); +
    +
    +

    +

    + · opened + by +

    +
    +
    + + + It's fixed + +
    +
    - // Get Ticket Attachments (not associated with a specific reply) - $sql_ticket_attachments = mysqli_query( - $mysqli, - "SELECT ticket_attachment_id, ticket_attachment_name FROM ticket_attachments - WHERE ticket_attachment_reply_id IS NULL - AND ticket_attachment_ticket_id = $ticket_id" - ); +
    +
    - // Get Tasks - $sql_tasks = mysqli_query( $mysqli, "SELECT 1 FROM tasks WHERE task_ticket_id = $ticket_id ORDER BY task_order ASC, task_id ASC"); - $task_count = mysqli_num_rows($sql_tasks); +
    +
      + $step) { ?> +
    1. + +
    +
    - // Get Completed Task Count - $sql_tasks_completed = mysqli_query($mysqli, - "SELECT 1 FROM tasks - WHERE task_ticket_id = $ticket_id - AND task_completed_at IS NOT NULL" - ); - $completed_task_count = mysqli_num_rows($sql_tasks_completed); - - // Get pending task approvals - $sql_task_approvals = mysqli_query($mysqli," - SELECT task_id, task_name, approval_id, approval_scope, approval_type, approval_required_user_id, approval_status, approval_url_key - FROM tasks - LEFT JOIN task_approvals ON task_id = task_approvals.approval_task_id - WHERE task_ticket_id = $ticket_id AND task_completed_at IS NULL AND approval_scope = 'client' AND approval_status = 'pending' - "); - ?> - - - -
    -
    -

    - Ticket -

    -
    - - Resolve ticket - + +
    +
    +

    Waiting for your approval

    -
    - -
    -
    Subject:
    -

    - State:
    - Priority:
    - - Category:
    +

      + +
    • + + +
      +
      +
      + + Approve + +
    • - - - - - Tasks: -
      - - - - Assigned to: - - - -

      -
      - - - - - - - - - - - - -
      - [View][Download] -
      -
    -
    - - - 0) { ?> -
    -
    -
    Approvals
    - This ticket has tasks requiring approval: - -
      - - -
    • - - Approve task - Please ask your contact to approve this task -
    • - - - -
    - - - -
    -
    + + -
    +
    + purify($ticket['ticket_details']), + $attachments[0] ?? [], intval($ticket['ticket_contact_id']) === $session_contact_id, false) ?> - + +
    ·
    + purify($reply['ticket_reply']), + $attachments[intval($reply['ticket_reply_id'])] ?? [], $mine, !$client_reply); + } ?> +
    - - + -
    - - -
    - +
    +
    +

    -
    - -
    - - - - - - -

    Your ticket has been resolved

    - -
    -
    -
    - Reopen ticket +
    + + +
    + +
    - -
    - Close ticket +
    + + Drop files here, or - screenshots, documents, error logs +
    + + +
    + + + +
    + 'We think this is fixed', 'text' => 'Close it if everything is working - or reopen it if it is not, and tell us what is still wrong.', 'icon' => 'fa-check', 'filtered' => false]) ?> + -
    -
    + - + -

    Ticket closed. Please rate your ticket

    - -
    - - - - - - -
    +
    + 'How did we do?', 'text' => 'One click tells us how this one went.', 'icon' => 'fa-star', 'filtered' => false]) ?> +
    + + + + +
    +
    -

    Rated -- Thanks for your feedback!

    +
    Closed and rated - thank you for the feedback.
    + - - -
    -
    - - purify($row['ticket_reply']); - $ticket_reply_created_at = escapeHtml($row['ticket_reply_created_at']); - $ticket_reply_updated_at = escapeHtml($row['ticket_reply_updated_at']); - $ticket_reply_by = intval($row['ticket_reply_by']); - $ticket_reply_type = $row['ticket_reply_type']; - - if ($ticket_reply_type == "Client") { - $ticket_reply_by_display = escapeHtml($row['contact_name']); - $user_initials = initials($row['contact_name']); - $user_avatar = $row['contact_photo']; - $avatar_link = "../uploads/clients/$session_client_id/$user_avatar"; - } else { - $ticket_reply_by_display = escapeHtml($row['user_name']); - $user_id = intval($row['user_id']); - $user_avatar = $row['user_avatar']; - $user_initials = initials($row['user_name']); - $avatar_link = "../uploads/users/$user_id/$user_avatar"; - } - - // Get attachments for this reply - $sql_ticket_reply_attachments = mysqli_query( - $mysqli, - "SELECT ticket_attachment_id, ticket_attachment_name FROM ticket_attachments - WHERE ticket_attachment_reply_id = $ticket_reply_id - AND ticket_attachment_ticket_id = $ticket_id" - ); - ?> - -
    mb-3"> -
    -

    -
    - - User Avatar - - - - - - - -
    - -
    - -
    -
    -

    -
    - -
    - - - - - - - - - - - - -
    - [View][Download] -
    -
    +
    +
    +
    +
    +

    Details

    +
    +
    Ticket
    +
    Status
    +
    Priority
    + +
    Category
    + + +
    Raised by
    + + +
    +
    Working on it
    +
    + + +
    +
    + + +
    Device
    + + +
    Tasks
    of done
    + +
    Opened
    + +
    Closed
    + +
    Resolved
    + +
    Last update
    + +
    +
    +
    +
    - - - - - diff --git a/client/ticket_add.php b/client/ticket_add.php index 2faabaa2c..34196437e 100644 --- a/client/ticket_add.php +++ b/client/ticket_add.php @@ -1,112 +1,142 @@ ['var(--bs-info)', 'Whenever you can get to it'], + 'Medium' => ['var(--bs-warning)', 'It is getting in the way'], + 'High' => ['var(--bs-danger)', 'It is stopping my work'], + 'Urgent' => ['var(--bs-emphasis-color)', 'It is stopping everyone'], +]; + +$company = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT company_phone, company_phone_country_code FROM companies WHERE company_id = 1")); ?> - +Tickets -

    Raise a new ticket

    +
    +
    +

    New ticket

    +

    Tell us what is wrong and we will get on it.

    +
    +
    -
    -
    +
    +
    +
    - +
    - - + +
    +
    + + + +
    +
    -
    -
    - -
    - - -
    -
    -
    - -
    -
    - +
    +
    - - + [$color, $hint]) { ?> + -
    +
    + +
    + + +
    - 0) { ?> +
    - +
    - +
    - -
    - - +
    + +
    + + Drop files here, or + +
    - - +
    +
    +
    +
    +

    What happens next

    +
    +
    +
      +
    1. We get your ticket straight away and pick it up.
    2. +
    3. You hear from us by email, and every reply shows on the ticket here.
    4. +
    5. Answer us by replying to the email or on the ticket - whichever is easier.
    6. +
    7. When it is fixed we mark it resolved, and you close it - or reopen it if it is not.
    8. +
    + +
    +

    Stopping everyone? Call us as well:

    + + +
    +
    +
    +
    + '', 'Closed' => 'closed'][$_GET['status'] ?? 'Open'] ?? 'all'; - -if ($session_contact_primary == 0 && !$session_contact_is_technical_contact) { - header("Location: post.php?logout"); - exit(); -} - -// Ticket status from GET -if (!isset($_GET['status']) || ($_GET['status']) == 'Open') { - // Default to showing open - $status = 'Open'; - $ticket_status_snippet = "ticket_closed_at IS NULL"; -} elseif (isset($_GET['status']) && ($_GET['status']) == 'Closed') { - $status = 'Closed'; - $ticket_status_snippet = "ticket_closed_at IS NOT NULL"; -} else { - $status = '%'; - $ticket_status_snippet = "ticket_status LIKE '%'"; -} - -$all_tickets = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, contact_name, ticket_created_at, ticket_updated_at, - ticket_resolved_at, ticket_closed_at, " . ticketLastSpokeSql() . " AS ticket_last_spoke - FROM tickets LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id - WHERE $ticket_status_snippet AND ticket_client_id = $session_client_id ORDER BY ticket_id DESC"); -?> - -

    All tickets

    -
    -
    -
    - - -
    -
    -
    - - - - - - - - - - - - - - - - "; - echo ""; - echo ""; - echo ""; - $ticket_updated = $row['ticket_updated_at'] ?: $row['ticket_created_at']; - echo ""; - echo ""; - echo ""; - } - ?> - -
    #SubjectContactStatusUpdated
    $ticket_prefix$ticket_number $ticket_subject$ticket_contact_name" . ticketPortalStatusHtml($row) . "" . timeAgo($ticket_updated) . "
    - -
    - - $t) { + $count_sql[] = "COALESCE(SUM({$t['where']}), 0) AS `$key`"; +} +$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)); +$page = min($page, $pages); +$offset = ($page - 1) * $per_page; + +$tickets = mysqli_query($mysqli, "SELECT " . portalTicketColumnsSql() . ", contact_name, category_name $from AND {$tabs[$tab]['where']} + ORDER BY " . ($tab === 'closed' ? 'tickets.ticket_closed_at' : 'COALESCE(tickets.ticket_updated_at, tickets.ticket_created_at)') . " DESC, tickets.ticket_id DESC + LIMIT $per_page OFFSET $offset"); + +/** This page's address with some of its settings changed. */ +function ticketsUrl(array $changes) { + global $tab, $scope, $q, $sees_all; + $params = array_merge(['tab' => $tab, 'scope' => $sees_all && $scope === 'mine' ? 'mine' : null, 'q' => $q !== '' ? $q : null], $changes); + if (($params['tab'] ?? '') === 'open') { + unset($params['tab']); + } + $params = array_filter($params, function ($v) { return $v !== null && $v !== ''; }); + return 'tickets.php' . ($params ? '?' . http_build_query($params) : ''); } -// Their tickets, newest first - with who wrote last, for "Waiting on your reply" -$contact_tickets = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, ticket_created_at, ticket_updated_at, - ticket_resolved_at, ticket_closed_at, " . ticketLastSpokeSql() . " AS ticket_last_spoke - FROM tickets LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id - WHERE $ticket_status_snippet AND ticket_contact_id = $session_contact_id AND ticket_client_id = $session_client_id ORDER BY ticket_id DESC"); - -//Get Total tickets closed -$sql_total_tickets_closed = mysqli_query($mysqli, "SELECT COUNT(ticket_id) AS total_tickets_closed FROM tickets WHERE ticket_closed_at IS NOT NULL AND ticket_client_id = $session_client_id AND ticket_contact_id = $session_contact_id"); -$row = mysqli_fetch_assoc($sql_total_tickets_closed); -$total_tickets_closed = intval($row['total_tickets_closed']); - -//Get Total tickets open -$sql_total_tickets_open = mysqli_query($mysqli, "SELECT COUNT(ticket_id) AS total_tickets_open FROM tickets WHERE ticket_closed_at IS NULL AND ticket_client_id = $session_client_id AND ticket_contact_id = $session_contact_id"); -$row = mysqli_fetch_assoc($sql_total_tickets_open); -$total_tickets_open = intval($row['total_tickets_open']); - -//Get Total tickets -$sql_total_tickets = mysqli_query($mysqli, "SELECT COUNT(ticket_id) AS total_tickets FROM tickets WHERE ticket_client_id = $session_client_id AND ticket_contact_id = $session_contact_id"); -$row = mysqli_fetch_assoc($sql_total_tickets); -$total_tickets = intval($row['total_tickets']); - - +$empty_titles = [ + 'open' => ['No open tickets', 'Nothing is being worked on right now.', 'fa-check'], + 'you' => ['Nothing waiting on you', 'When we need something from you, the ticket shows here.', 'fa-check'], + 'resolved' => ['Nothing to confirm', 'Tickets we have resolved wait here for you to close or reopen.', 'fa-check'], + 'closed' => ['No closed tickets', '', 'fa-check-circle'], + 'all' => ['No tickets yet', 'Something not working? Raise a ticket and we will pick it up.', 'fa-life-ring'], +]; ?> -

    Tickets

    -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - -
    #SubjectStatusUpdated
    - - - -
    - - +
    +
    +

    Tickets

    +

    - -
    - - New ticket - -
    - - My Open tickets | - - Closed tickets | - - All my tickets | - - -
    - - All Tickets - - - +
    + +
    + Everyone + Mine +
    + +
    - + + +
    + + + 'tickets', 'filtered' => true, 'match_text' => 'Nothing here has “' . escapeHtml($q) . '” in its subject or number.', 'clear_url' => ticketsUrl(['q' => null, 'page' => null])]) ?> + + $title, 'text' => $text, 'icon' => $icon, 'filtered' => false, + 'actions' => in_array($tab, ['open', 'all'], true) ? [['label' => 'New ticket', 'href' => 'ticket_add.php']] : []]) ?> + + + + 1) { ?> +
    + - of +
    + + +
    +
    + + +
    + + diff --git a/client/unpaid_invoices.php b/client/unpaid_invoices.php index 7bd75f2d1..b1f7e3e1a 100644 --- a/client/unpaid_invoices.php +++ b/client/unpaid_invoices.php @@ -19,7 +19,7 @@ $invoices_sql = mysqli_query($mysqli, "SELECT invoice_amount, invoice_date, invo // Payment Provider Active Query $sql_payment_provider = mysqli_query($mysqli, "SELECT payment_provider_active, payment_provider_id, payment_provider_threshold FROM payment_providers WHERE payment_provider_active = 1 LIMIT 1;"); -$row = mysqli_fetch_assoc($sql_payment_provider); +$row = mysqli_fetch_assoc($sql_payment_provider) ?: ['payment_provider_active' => 0, 'payment_provider_id' => 0, 'payment_provider_threshold' => 0]; // none set up - nothing to pay with $payment_provider_id = intval($row['payment_provider_id']); $payment_provider_active = intval($row['payment_provider_active']); $payment_provider_threshold = floatval($row['payment_provider_threshold']); diff --git a/css/itflow_custom.css b/css/itflow_custom.css index b8816d27a..8f7ac127c 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -6468,3 +6468,786 @@ a.itflow-billing-stat:hover { margin-top: 0; cursor: pointer; } + +/* ========================================================================== + Client portal (client/) - the shell from client/includes/header.php and + the pages built on it. The portal sets a CSP of default-src 'self', so + nothing here may lean on inline styles: every look is a class. + ========================================================================== */ +.itflow-portal { + --itflow-portal-header-height: 4rem; + --itflow-portal-tabbar-height: 3.75rem; +} +.itflow-portal-header { + position: sticky; + top: 0; + z-index: 1030; + display: flex; + align-items: center; + min-height: var(--itflow-portal-header-height); + background-color: var(--bs-body-bg); + border-bottom: 1px solid var(--bs-border-color-translucent); + box-shadow: 0 1px 3px rgba(0, 0, 0, .04); +} +.itflow-portal-brand { + display: inline-flex; + flex: 0 1 auto; + align-items: center; + gap: .6rem; + min-width: 0; + color: var(--bs-emphasis-color); + font-weight: 600; + text-decoration: none; +} +.itflow-portal-brand:hover { + color: var(--bs-emphasis-color); +} +.itflow-portal-brand img { + display: block; + height: 2.25rem; + max-width: 11rem; + object-fit: contain; +} +.itflow-portal-brand .itflow-brand-mark-initials { + width: 2.25rem; + height: 2.25rem; + font-size: .75rem; +} +.itflow-portal-brand-name { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.itflow-portal-nav { + align-items: center; + gap: .15rem; +} +.itflow-portal-nav-link { + display: inline-flex; + align-items: center; + gap: .45rem; + padding: .45rem .75rem; + border-radius: var(--bs-border-radius); + color: var(--bs-secondary-color); + font-weight: 500; + text-decoration: none; + white-space: nowrap; +} +.itflow-portal-nav-link:hover, +.itflow-portal-nav-link.show { + background-color: var(--bs-tertiary-bg); + color: var(--bs-emphasis-color); +} +.itflow-portal-nav-link.active { + background-color: color-mix(in srgb, var(--itflow-accent, #007bff) 12%, transparent); + color: var(--itflow-accent, #007bff); +} +.itflow-portal .dropdown-item.active, +.itflow-portal .dropdown-item:active { + background-color: color-mix(in srgb, var(--itflow-accent, #007bff) 12%, transparent); + color: var(--itflow-accent, #007bff); +} +.itflow-portal .dropdown-item i { + color: var(--bs-secondary-color); +} +.itflow-portal .dropdown-item.active i { + color: inherit; +} +.itflow-portal-account { + display: inline-flex; + align-items: center; + gap: .5rem; + max-width: 16rem; + padding: .25rem .5rem .25rem .25rem; + border: 0; + border-radius: 2rem; + background: transparent; + color: var(--bs-body-color); +} +.itflow-portal-account:hover, +.itflow-portal-account[aria-expanded="true"] { + background-color: var(--bs-tertiary-bg); +} + +/* Avatars - a photo, or initials on a soft tone picked from the name */ +.itflow-portal-avatar { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + width: 2rem; + height: 2rem; + border-radius: 50%; + object-fit: cover; + font-size: .75rem; + font-weight: 600; + line-height: 1; +} +.itflow-portal-avatar-sm { width: 1.75rem; height: 1.75rem; font-size: .65rem; } +.itflow-portal-avatar-lg { width: 2.5rem; height: 2.5rem; font-size: .85rem; } +.itflow-portal-avatar-xl { width: 3.25rem; height: 3.25rem; font-size: 1.05rem; } +.itflow-portal-avatar-tone-1 { background-color: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); } +.itflow-portal-avatar-tone-2 { background-color: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); } +.itflow-portal-avatar-tone-3 { background-color: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); } +.itflow-portal-avatar-tone-4 { background-color: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); } +.itflow-portal-avatar-tone-5 { background-color: var(--bs-info-bg-subtle); color: var(--bs-info-text-emphasis); } +.itflow-portal-avatar-tone-6 { background-color: var(--bs-secondary-bg); color: var(--bs-secondary-color); } + +.itflow-portal-main { + flex: 1 0 auto; + padding-top: 1.5rem; + padding-bottom: 2rem; +} +.itflow-portal-footer { + padding: .9rem 0; + border-top: 1px solid var(--bs-border-color-translucent); + background-color: var(--bs-body-bg); + color: var(--bs-secondary-color); + font-size: .8rem; +} + +/* Phone: the tab bar along the bottom, and the menu that slides in */ +.itflow-portal-tabbar { + position: fixed; + right: 0; + bottom: 0; + left: 0; + z-index: 1030; + display: flex; + height: calc(var(--itflow-portal-tabbar-height) + env(safe-area-inset-bottom, 0px)); + padding-bottom: env(safe-area-inset-bottom, 0px); + border-top: 1px solid var(--bs-border-color-translucent); + background-color: var(--bs-body-bg); + box-shadow: 0 -1px 4px rgba(0, 0, 0, .05); +} +.itflow-portal-tabbar a { + display: flex; + flex: 1 1 0; + flex-direction: column; + align-items: center; + justify-content: center; + gap: .2rem; + min-width: 0; + color: var(--bs-secondary-color); + font-size: .7rem; + text-decoration: none; +} +.itflow-portal-tabbar a i { + font-size: 1.1rem; +} +.itflow-portal-tabbar a.active { + color: var(--itflow-accent, #007bff); + font-weight: 600; +} +.itflow-portal-tabbar a.itflow-portal-tabbar-new i { + display: inline-flex; + align-items: center; + justify-content: center; + width: 2.1rem; + height: 2.1rem; + border-radius: 50%; + background-color: var(--bs-primary); + color: #fff; + font-size: .95rem; +} +@media (max-width: 991.98px) { + .itflow-portal { + padding-bottom: calc(var(--itflow-portal-tabbar-height) + env(safe-area-inset-bottom, 0px)); + } + .itflow-portal-main { + padding-top: 1rem; + } +} +.itflow-portal-menu { + --bs-offcanvas-width: min(20rem, 85vw); +} +.itflow-portal-menu-heading { + margin: 1rem 0 .35rem; + color: var(--bs-secondary-color); + font-size: .72rem; + font-weight: 600; + letter-spacing: .04em; + text-transform: uppercase; +} +.itflow-portal-menu-heading:first-child { + margin-top: 0; +} +.itflow-portal-menu-link { + display: flex; + align-items: center; + gap: .65rem; + width: 100%; + padding: .55rem .6rem; + border: 0; + border-radius: var(--bs-border-radius); + background: transparent; + color: var(--bs-body-color); + text-align: start; + text-decoration: none; +} +.itflow-portal-menu-link i { + color: var(--bs-secondary-color); +} +.itflow-portal-menu-link:hover { + background-color: var(--bs-tertiary-bg); + color: var(--bs-emphasis-color); +} +.itflow-portal-menu-link.active { + background-color: color-mix(in srgb, var(--itflow-accent, #007bff) 12%, transparent); + color: var(--itflow-accent, #007bff); + font-weight: 600; +} +.itflow-portal-menu-link.active i { + color: inherit; +} + +/* A page's title row: the title with a line under it, and its buttons */ +.itflow-portal-page-head { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + justify-content: space-between; + gap: .75rem 1rem; + margin-bottom: 1.25rem; +} +.itflow-portal-page-head h1 { + margin: 0; + font-size: 1.5rem; + font-weight: 600; +} +.itflow-portal-page-head p { + margin: .2rem 0 0; + color: var(--bs-secondary-color); +} +.itflow-portal-back { + display: inline-flex; + align-items: center; + gap: .4rem; + margin-bottom: .5rem; + color: var(--bs-secondary-color); + font-size: .875rem; + text-decoration: none; +} +.itflow-portal-back:hover { + color: var(--bs-emphasis-color); +} + +/* A plain panel - the portal's cards */ +.itflow-portal-panel { + overflow: hidden; + border: 1px solid var(--bs-border-color-translucent); + border-radius: var(--bs-border-radius-lg); + background-color: var(--bs-body-bg); +} +.itflow-portal-panel-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: .75rem; + padding: .85rem 1.1rem; + border-bottom: 1px solid var(--bs-border-color-translucent); +} +.itflow-portal-panel-head h2 { + margin: 0; + font-size: 1rem; + font-weight: 600; +} +.itflow-portal-panel-head h2 i { + margin-right: .45rem; + color: var(--bs-secondary-color); +} +.itflow-portal-panel-head a { + font-size: .85rem; + text-decoration: none; +} +.itflow-portal-panel-body { + padding: 1rem 1.1rem; +} +.itflow-portal-panel .itflow-empty-state { + padding: 2rem 1rem; +} + +/* Where a ticket stands, for the client */ +.itflow-portal-state { + display: inline-flex; + align-items: center; + gap: .3rem; + padding: .2rem .6rem; + border-radius: 2rem; + font-size: .75rem; + font-weight: 600; + line-height: 1.4; + white-space: nowrap; +} +.itflow-portal-state i { + width: auto; + font-size: .7rem; +} +.itflow-portal-state-new { background-color: var(--bs-info-bg-subtle); color: var(--bs-info-text-emphasis); } +.itflow-portal-state-progress { background-color: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); } +.itflow-portal-state-you { background-color: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); } +.itflow-portal-state-hold { background-color: var(--bs-secondary-bg); color: var(--bs-secondary-color); } +.itflow-portal-state-resolved { background-color: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); } +.itflow-portal-state-closed { background-color: var(--bs-tertiary-bg); color: var(--bs-secondary-color); } + +/* Tabs along the top of a list, underlined, each with its count */ +.itflow-portal-tabs { + display: flex; + gap: .25rem; + margin-bottom: 1rem; + border-bottom: 1px solid var(--bs-border-color-translucent); + overflow-x: auto; + scrollbar-width: none; +} +.itflow-portal-tabs a { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + gap: .45rem; + padding: .6rem .8rem; + border-bottom: 2px solid transparent; + margin-bottom: -1px; + color: var(--bs-secondary-color); + font-weight: 500; + text-decoration: none; + white-space: nowrap; +} +.itflow-portal-tabs a:hover { + color: var(--bs-emphasis-color); +} +.itflow-portal-tabs a.active { + border-bottom-color: var(--itflow-accent, #007bff); + color: var(--bs-emphasis-color); + font-weight: 600; +} +.itflow-portal-tabs .badge { + background-color: var(--bs-tertiary-bg); + color: var(--bs-secondary-color); + font-weight: 600; +} +.itflow-portal-tabs a.itflow-portal-tab-alert .badge { + background-color: var(--bs-warning-bg-subtle); + color: var(--bs-warning-text-emphasis); +} + +/* A list of tickets */ +.itflow-portal-list { + margin: 0; + padding: 0; + list-style: none; +} +.itflow-portal-list > li + li { + border-top: 1px solid var(--bs-border-color-translucent); +} +.itflow-portal-ticket { + display: flex; + align-items: center; + gap: 1rem; + padding: .85rem 1.1rem; + color: inherit; + text-decoration: none; +} +a.itflow-portal-ticket:hover { + background-color: var(--bs-tertiary-bg); + color: inherit; +} +.itflow-portal-ticket-main { + flex: 1 1 auto; + min-width: 0; +} +.itflow-portal-ticket-subject { + overflow: hidden; + color: var(--bs-emphasis-color); + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; +} +.itflow-portal-ticket-meta { + display: flex; + flex-wrap: wrap; + gap: .15rem .9rem; + margin-top: .15rem; + color: var(--bs-secondary-color); + font-size: .8rem; +} +.itflow-portal-ticket-side { + display: flex; + flex: 0 0 auto; + flex-direction: column; + align-items: flex-end; + gap: .3rem; + text-align: end; +} +.itflow-portal-ticket-side small { + color: var(--bs-secondary-color); +} +@media (max-width: 575.98px) { + .itflow-portal-ticket { + flex-wrap: wrap; + gap: .5rem; + padding: .8rem .9rem; + } + .itflow-portal-ticket-side { + flex-direction: row; + align-items: center; + gap: .6rem; + } +} + +/* Paging under a list */ +.itflow-portal-pager { + display: flex; + align-items: center; + justify-content: space-between; + gap: .75rem; + padding: .75rem 1.1rem; + border-top: 1px solid var(--bs-border-color-translucent); + color: var(--bs-secondary-color); + font-size: .85rem; +} + +/* A ticket's progress: received, in progress, resolved, closed */ +.itflow-portal-steps { + display: flex; + margin: 0; + padding: 0; + list-style: none; + counter-reset: step; +} +.itflow-portal-steps li { + position: relative; + flex: 1 1 0; + padding-top: 1.6rem; + color: var(--bs-secondary-color); + font-size: .78rem; + text-align: center; +} +.itflow-portal-steps li::before { + content: ""; + position: absolute; + top: .35rem; + left: 50%; + z-index: 1; + width: .8rem; + height: .8rem; + margin-left: -.4rem; + border: 2px solid var(--bs-border-color); + border-radius: 50%; + background-color: var(--bs-body-bg); +} +.itflow-portal-steps li + li::after { + content: ""; + position: absolute; + top: .7rem; + right: 50%; + left: -50%; + height: 2px; + background-color: var(--bs-border-color); +} +.itflow-portal-steps li.done::before, +.itflow-portal-steps li.current::before { + border-color: var(--itflow-accent, #007bff); + background-color: var(--itflow-accent, #007bff); +} +.itflow-portal-steps li.done + li::after, +.itflow-portal-steps li.done + li.current::after { + background-color: var(--itflow-accent, #007bff); +} +.itflow-portal-steps li.current { + color: var(--bs-emphasis-color); + font-weight: 600; +} +.itflow-portal-steps li.current::before { + box-shadow: 0 0 0 4px color-mix(in srgb, var(--itflow-accent, #007bff) 22%, transparent); +} + +/* The conversation on a ticket - oldest first, the client's own on the right */ +.itflow-portal-thread { + display: flex; + flex-direction: column; + gap: 1rem; +} +.itflow-portal-msg { + display: flex; + align-items: flex-start; + gap: .75rem; + max-width: 100%; +} +.itflow-portal-msg-mine { + flex-direction: row-reverse; +} +.itflow-portal-msg-body { + min-width: 0; + max-width: min(46rem, calc(100% - 3rem)); +} +.itflow-portal-msg-head { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: .2rem .6rem; + margin-bottom: .3rem; + font-size: .8rem; +} +.itflow-portal-msg-mine .itflow-portal-msg-head { + justify-content: flex-end; +} +.itflow-portal-msg-head strong { + color: var(--bs-emphasis-color); +} +.itflow-portal-msg-head span { + color: var(--bs-secondary-color); +} +.itflow-portal-msg-bubble { + padding: .75rem 1rem; + border: 1px solid var(--bs-border-color-translucent); + border-radius: var(--bs-border-radius-lg); + border-top-left-radius: .25rem; + background-color: var(--bs-body-bg); + overflow-wrap: anywhere; +} +.itflow-portal-msg-mine .itflow-portal-msg-bubble { + border-color: color-mix(in srgb, var(--itflow-accent, #007bff) 25%, transparent); + border-top-left-radius: var(--bs-border-radius-lg); + border-top-right-radius: .25rem; + background-color: color-mix(in srgb, var(--itflow-accent, #007bff) 7%, var(--bs-body-bg)); +} +.itflow-portal-msg-bubble > :last-child { + margin-bottom: 0; +} +.itflow-portal-msg-bubble img { + max-width: 100%; + height: auto; +} +.itflow-portal-event { + display: flex; + align-items: center; + gap: .75rem; + color: var(--bs-secondary-color); + font-size: .8rem; +} +.itflow-portal-event::before, +.itflow-portal-event::after { + content: ""; + flex: 1 1 auto; + height: 1px; + background-color: var(--bs-border-color-translucent); +} + +/* Attachments - on a message, and the drop zone on a form */ +.itflow-portal-files { + display: flex; + flex-wrap: wrap; + gap: .4rem; + margin-top: .6rem; +} +.itflow-portal-file-chip { + display: inline-flex; + align-items: center; + gap: .4rem; + max-width: 100%; + padding: .3rem .65rem; + border: 1px solid var(--bs-border-color-translucent); + border-radius: 2rem; + background-color: var(--bs-tertiary-bg); + color: var(--bs-body-color); + font-size: .8rem; + text-decoration: none; +} +a.itflow-portal-file-chip:hover { + border-color: var(--bs-primary-border-subtle); + color: var(--bs-emphasis-color); +} +.itflow-portal-file-chip i { + color: var(--bs-secondary-color); +} +.itflow-portal-drop { + position: relative; + padding: .9rem 1rem; + border: 1px dashed var(--bs-border-color); + border-radius: var(--bs-border-radius-lg); + color: var(--bs-secondary-color); + font-size: .875rem; + transition: border-color .12s ease-in-out, background-color .12s ease-in-out; +} +.itflow-portal-drop.is-dragging { + border-color: var(--itflow-accent, #007bff); + background-color: color-mix(in srgb, var(--itflow-accent, #007bff) 6%, transparent); +} +.itflow-portal-drop input[type=file] { + position: absolute; + width: 1px; + height: 1px; + opacity: 0; + pointer-events: none; +} +.itflow-portal-drop label { + color: var(--itflow-accent, #007bff); + font-weight: 600; + cursor: pointer; +} +.itflow-portal-drop input[type=file]:focus-visible + label { + outline: 2px solid var(--itflow-accent, #007bff); + outline-offset: 2px; +} +.itflow-portal-drop .itflow-portal-files { + margin-top: .6rem; +} +.tox-tinymce.is-invalid { + border-color: var(--bs-form-invalid-border-color) !important; +} + +/* Details down the side of a ticket */ +.itflow-portal-facts { + margin: 0; +} +.itflow-portal-facts > div { + display: flex; + justify-content: space-between; + gap: 1rem; + padding: .55rem 0; +} +.itflow-portal-facts > div + div { + border-top: 1px solid var(--bs-border-color-translucent); +} +.itflow-portal-facts dt { + color: var(--bs-secondary-color); + font-weight: 400; +} +.itflow-portal-facts dd { + margin: 0; + min-width: 0; + text-align: end; + overflow-wrap: anywhere; +} + +/* Home: the figures along the top and the "needs you" list */ +.itflow-portal-stat { + display: flex; + align-items: center; + gap: .9rem; + height: 100%; + padding: 1rem 1.1rem; + border: 1px solid var(--bs-border-color-translucent); + border-radius: var(--bs-border-radius-lg); + background-color: var(--bs-body-bg); + color: inherit; + text-decoration: none; +} +a.itflow-portal-stat:hover { + border-color: var(--bs-primary-border-subtle); + box-shadow: 0 1px 4px rgba(0, 0, 0, .06); + color: inherit; +} +.itflow-portal-stat-icon { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + width: 2.6rem; + height: 2.6rem; + border-radius: 50%; + background-color: var(--bs-secondary-bg); + color: var(--bs-secondary-color); + font-size: 1.05rem; +} +.itflow-portal-stat-value { + color: var(--bs-emphasis-color); + font-size: 1.35rem; + font-weight: 600; + line-height: 1.2; +} +.itflow-portal-stat-label { + color: var(--bs-secondary-color); + font-size: .8rem; +} +.itflow-portal-stat > span:last-child { + min-width: 0; + overflow-wrap: anywhere; +} +@media (max-width: 575.98px) { + .itflow-portal-stat { + flex-direction: column; + align-items: flex-start; + gap: .5rem; + padding: .85rem; + } + .itflow-portal-stat-icon { + width: 2.1rem; + height: 2.1rem; + font-size: .9rem; + } + .itflow-portal-stat-value { + font-size: 1.15rem; + } +} +.itflow-portal-stat-alert .itflow-portal-stat-icon { + background-color: var(--bs-warning-bg-subtle); + color: var(--bs-warning-text-emphasis); +} +.itflow-portal-stat-danger .itflow-portal-stat-icon { + background-color: var(--bs-danger-bg-subtle); + color: var(--bs-danger-text-emphasis); +} +.itflow-portal-todo { + display: flex; + align-items: center; + gap: .85rem; + padding: .75rem 1.1rem; + color: inherit; + text-decoration: none; +} +a.itflow-portal-todo:hover { + background-color: var(--bs-tertiary-bg); + color: inherit; +} +.itflow-portal-todo-icon { + display: inline-flex; + flex: 0 0 auto; + align-items: center; + justify-content: center; + width: 2rem; + height: 2rem; + border-radius: 50%; + background-color: var(--bs-warning-bg-subtle); + color: var(--bs-warning-text-emphasis); + font-size: .8rem; +} +.itflow-portal-todo-icon.is-danger { + background-color: var(--bs-danger-bg-subtle); + color: var(--bs-danger-text-emphasis); +} +.itflow-portal-todo-icon.is-info { + background-color: var(--bs-info-bg-subtle); + color: var(--bs-info-text-emphasis); +} +.itflow-portal-todo-main { + flex: 1 1 auto; + min-width: 0; +} +.itflow-portal-todo-main div:first-child { + overflow: hidden; + color: var(--bs-emphasis-color); + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; +} +.itflow-portal-todo-main div + div { + color: var(--bs-secondary-color); + font-size: .8rem; +} + +.itflow-portal-preview-image { + max-height: 600px; +} + +/* The pages not rebuilt yet: their black table heads and borders, softened to + sit in the light shell */ +.itflow-portal-main .table-dark { + --bs-table-color: var(--bs-emphasis-color); + --bs-table-bg: var(--bs-tertiary-bg); + --bs-table-border-color: var(--bs-border-color); +} +.itflow-portal-main .table.border-dark, +.itflow-portal-main .table .border-dark { + border-color: var(--bs-border-color) !important; +} diff --git a/functions/ticket.php b/functions/ticket.php index 1b9f73146..215e93d69 100644 --- a/functions/ticket.php +++ b/functions/ticket.php @@ -736,23 +736,6 @@ function ticketActivityHtml($reply, $row) { . ($who !== '' ? '
    ' . escapeHtml($who) . '
    ' : ''); } -/** - * For the client portal: the ticket's status as a badge, and under it - * "Waiting on your reply" when we wrote last on an open ticket. Classes only - - * the portal's content security policy turns inline styles off, so the - * status colours the agents see aren't used here. - */ -function ticketPortalStatusHtml($row) { - $closed = !empty($row['ticket_closed_at']); - $resolved = !$closed && !empty($row['ticket_resolved_at']); - $class = $closed ? 'text-bg-secondary' : ($resolved ? 'text-bg-success' : 'text-bg-primary'); - $html = '' . escapeHtml($row['ticket_status_name'] ?? '') . ''; - if (!$closed && !$resolved && ($row['ticket_last_spoke'] ?? null) === 'Public') { - $html .= '
    Waiting on your reply
    '; - } - return $html; -} - /** Where it came in from, as an icon - '' for one an agent raised. */ function ticketSourceIcon($source) { $icons = ['Email' => ['fa-envelope', 'Came in by email'], 'Portal' => ['fa-globe', 'Raised in the client portal'], diff --git a/js/portal.js b/js/portal.js new file mode 100644 index 000000000..41333de35 --- /dev/null +++ b/js/portal.js @@ -0,0 +1,199 @@ +/* + * Client portal behaviour - everything the portal pages need from script, in + * one file, because the portal's Content-Security-Policy (default-src 'self') + * turns inline scripts off: + * + * - Dark mode, the contact's own choice, kept in a cookie the header reads + * - The editor on any .tinymce textarea, in the light or dark skin + * - Attachment drop zones: drop files on [data-portal-drop] and they go into + * its file input, listed by name and size + * - A form marked data-portal-once can't be sent twice + * - Tables a page left unwrapped scroll sideways on a phone instead of the page + */ +(function () { + 'use strict'; + + // ---------- Dark mode ---------- + document.addEventListener('click', function (e) { + var toggle = e.target.closest('[data-portal-theme-toggle]'); + if (!toggle) { + return; + } + e.preventDefault(); + var dark = document.documentElement.getAttribute('data-bs-theme') !== 'dark'; + document.cookie = 'itflow_portal_theme=' + (dark ? 'dark' : 'light') + '; path=/; max-age=31536000; SameSite=Lax'; + // The editor draws its own chrome and content, so a reload is what + // brings it round with the page + window.location.reload(); + }); + + // ---------- The editor ---------- + function editorSkin() { + var dark = document.documentElement.getAttribute('data-bs-theme') === 'dark'; + var root = getComputedStyle(document.documentElement); + var body = getComputedStyle(document.body); + function v(name, fallback) { + return root.getPropertyValue(name).trim() || fallback; + } + return { + skin: dark ? 'oxide-dark' : 'oxide', + content_css: dark ? 'dark' : 'default', + content_style: 'body{background-color:' + v('--bs-body-bg', '#fff') + ';color:' + v('--bs-body-color', '#212529') + ';' + + 'font-family:' + body.fontFamily + ';font-size:' + body.fontSize + ';}' + + 'a{color:' + v('--itflow-accent', '#007bff') + ';}' + + '.mce-content-body[data-mce-placeholder]:not(.mce-visualblocks)::before{color:' + v('--bs-secondary-color', '#6c757d') + ';}' + }; + } + + if (window.tinymce && document.querySelector('textarea.tinymce')) { + var skin = editorSkin(); + tinymce.init({ + selector: 'textarea.tinymce', + browser_spellcheck: true, + resize: true, + min_height: 220, + max_height: 600, + promotion: false, + branding: false, + menubar: false, + statusbar: false, + license_key: 'gpl', + skin: skin.skin, + content_css: skin.content_css, + content_style: skin.content_style, + toolbar: 'bold italic forecolor | bullist numlist | link table | removeformat', + mobile: { + menubar: false, + plugins: 'autosave lists autolink', + toolbar: 'bold italic bullist numlist' + }, + plugins: 'link image lists table autoresize', + setup: function (editor) { + // A required field the editor hides can't take the browser's + // own "fill this in" - so the form is checked here instead + editor.on('init', function () { + var textarea = editor.getElement(); + textarea.removeAttribute('required'); + var form = textarea.form; + if (form && textarea.hasAttribute('data-required') && !form.hasAttribute('data-editor-checked')) { + form.setAttribute('data-editor-checked', ''); + form.addEventListener('submit', function (ev) { + tinymce.triggerSave(); + var empty = !editor.getContent({format: 'text'}).trim() && !/= 1048576) { + return (bytes / 1048576).toFixed(1) + ' MB'; + } + return Math.max(1, Math.round(bytes / 1024)) + ' KB'; + } + + function listFiles(zone) { + var input = zone.querySelector('input[type=file]'); + var list = zone.querySelector('[data-portal-files]'); + if (!input || !list) { + return; + } + list.replaceChildren(); + Array.prototype.forEach.call(input.files, function (file) { + var chip = document.createElement('span'); + chip.className = 'itflow-portal-file-chip'; + var icon = document.createElement('i'); + icon.className = 'fas fa-paperclip'; + var name = document.createElement('span'); + name.className = 'text-truncate'; + name.textContent = file.name; + var size = document.createElement('span'); + size.className = 'text-body-secondary'; + size.textContent = formatSize(file.size); + chip.append(icon, name, size); + list.append(chip); + }); + list.hidden = input.files.length === 0; + } + + document.querySelectorAll('[data-portal-drop]').forEach(function (zone) { + var input = zone.querySelector('input[type=file]'); + if (!input) { + return; + } + input.addEventListener('change', function () { + listFiles(zone); + }); + ['dragenter', 'dragover'].forEach(function (type) { + zone.addEventListener(type, function (e) { + e.preventDefault(); + zone.classList.add('is-dragging'); + }); + }); + ['dragleave', 'drop'].forEach(function (type) { + zone.addEventListener(type, function (e) { + e.preventDefault(); + if (type === 'dragleave' && zone.contains(e.relatedTarget)) { + return; + } + zone.classList.remove('is-dragging'); + }); + }); + zone.addEventListener('drop', function (e) { + if (!e.dataTransfer || !e.dataTransfer.files.length) { + return; + } + // Add to what was already picked rather than replace it + var merged = new DataTransfer(); + Array.prototype.forEach.call(input.files, function (f) { merged.items.add(f); }); + Array.prototype.forEach.call(e.dataTransfer.files, function (f) { merged.items.add(f); }); + input.files = merged.files; + listFiles(zone); + }); + }); + + // ---------- Sent once ---------- + document.querySelectorAll('form[data-portal-once]').forEach(function (form) { + form.addEventListener('submit', function (e) { + if (e.defaultPrevented) { + return; + } + form.querySelectorAll('button[type=submit], button:not([type])').forEach(function (button) { + // Disabled after this tick, so the button's own name=value still goes with the form + setTimeout(function () { button.disabled = true; }, 0); + }); + }); + }); + + // ---------- Tables ---------- + document.querySelectorAll('.itflow-portal-main table.table').forEach(function (table) { + if (table.closest('.table-responsive')) { + return; + } + var wrap = document.createElement('div'); + wrap.className = 'table-responsive'; + table.parentNode.insertBefore(wrap, table); + wrap.appendChild(table); + }); +})();