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

This commit is contained in:
johnnyq
2026-10-17 01:28:27 -04:00
parent 59e75764f8
commit c6eadf3fa3
18 changed files with 2146 additions and 1062 deletions

View File

@@ -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()`

View File

@@ -56,7 +56,7 @@ $sql_activity = mysqli_query(
<?php } else { ?>
<table class="table table-striped table-bordered border border-dark dataTables" style="width:100%">
<table class="table table-striped table-bordered border border-dark dataTables w-100">
<thead class="table-dark">
<tr>
<?php /* Ordering off on this column deliberately. The cell reads

View File

@@ -132,7 +132,7 @@ if (mysqli_num_rows($sql_files) > 0) {
</div>
</div>
<div class="card-body text-center">
<img src="<?= $file_view_url ?>" alt="<?= $file_name ?>" class="img-fluid" style="max-height: 600px;">
<img src="<?= $file_view_url ?>" alt="<?= $file_name ?>" class="img-fluid itflow-portal-preview-image">
</div>
</div>
<?php

View File

@@ -16,6 +16,9 @@ function verifyContactTicketAccess($requested_ticket_id, $expected_ticket_state)
if ($expected_ticket_state == "Closed") {
// Closed tickets
$ticket_state_snippet = "ticket_status = 5";
} elseif ($expected_ticket_state == "Any") {
// Open or closed - reading, such as an attachment
$ticket_state_snippet = "1 = 1";
} else {
// Open (working/hold) tickets
$ticket_state_snippet = "ticket_status != 5";
@@ -140,17 +143,170 @@ function portalDateTime($datetime) {
}
/*
* The empty state for the portal's list pages.
* The empty state for the portal's list pages - the same one the agent lists
* use (emptyStateHtml()), so an empty list reads as empty rather than broken.
*
* Every list page here renders a header row and then a while loop, so a client
* with no assets, no quotes or no documents used to get a table with nothing
* under it - indistinguishable from a page that failed to load. This says so
* instead.
*
* Default is neutral, for a list that simply has nothing in it yet. Pass
* 'success' where empty is genuinely good news (nothing owed, nothing unpaid).
* Pass 'success' where empty is genuinely good news (nothing owed, nothing
* unpaid) and it shows a tick.
*/
function portalEmptyState($message, $icon = 'fa-inbox', $type = 'secondary') {
return '<div class="alert alert-' . $type . '"><i class="fa fa-fw ' . $icon . ' me-2"></i>' . $message . '</div>';
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 '<img class="' . $class . '" src="' . escapeHtml($photo_url) . '" alt="">';
}
$initials = personInitials((string) $name) ?: '?';
$tone = 1 + (abs(crc32((string) $name)) % 6);
return '<span class="' . $class . ' itflow-portal-avatar-tone-' . $tone . '" aria-hidden="true">' . escapeHtml($initials) . '</span>';
}
/*
* ---------- 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 '<span class="itflow-portal-state ' . $state['class'] . '"><i class="fas fa-fw ' . $state['icon'] . '"></i>' . escapeHtml($state['label']) . '</span>';
}
/** 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, '<img') !== false) {
return false;
}
return preg_replace('/[\s\x{00A0}]+/u', '', html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8')) === '';
}
/** The reply lines the portal writes itself when a contact resolves, reopens or closes - shown as a line in the conversation, not a message. */
function portalTicketEventText($html) {
$text = trim(html_entity_decode(strip_tags((string) $html), ENT_QUOTES, 'UTF-8'));
return preg_match('/^Ticket (resolved|reopened|closed) by .{1,200}\.$/', $text) ? $text : '';
}

View File

@@ -5,78 +5,28 @@
*/
?>
<!-- Close container -->
</div>
</main>
<?php /* This portal has no .app-wrapper grid - it is a plain navbar over a
.container - so the bottom edge is held by the body instead:
header.php gives the body d-flex flex-column min-vh-100, and mt-auto here
eats whatever height is left over. On a short page (an empty ticket
list, the statement) the bar lands on the bottom of the window rather
than directly under the content.
.app-footer is AdminLTE's own bar styling - border-top, body-bg,
min-height 3rem - which is what the old rule was standing in for, so
the trailing br and hr go with it. Its grid-area is inert outside a
grid.
Only the navbar, the .container and this become flex items: script
elements are display:none, and anything the libraries fix to the
viewport (sweetalert2, modal backdrops) is out of flow either way. */ ?>
<footer class="app-footer mt-auto py-2 text-center">
<?php
echo escapeHtml($session_company_name);
if (!$config_whitelabel_enabled) {
echo '<br><small class="text-muted">Powered by ITFlow</small>';
}
?>
<?php /* The body is a flex column (header.php), so mt-auto here takes up the
height a short page leaves and the bar sits on the bottom of the
window rather than right under the content. On a phone it clears the
tab bar along the bottom. */ ?>
<footer class="itflow-portal-footer mt-auto">
<div class="container d-flex flex-wrap justify-content-between gap-2">
<span><?= escapeHtml($session_company_name) ?></span>
<?php if (!$config_whitelabel_enabled) { ?>
<span>Powered by ITFlow</span>
<?php } ?>
</div>
</footer>
<!-- jQuery -->
<!-- Bootstrap 4 -->
<script src="/js/itflow_select.js"></script>
<script src="/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/js/http.js"></script>
<!--- TinyMCE -->
<!--- TinyMCE - set up on any .tinymce by js/portal.js -->
<script src="/libs/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
<script>
// Initialize TinyMCE
tinymce.init({
selector: '.tinymce',
browser_spellcheck: true,
resize: true,
min_height: 300,
max_height: 600,
promotion: false,
branding: false,
menubar: false,
statusbar: false,
license_key: 'gpl',
toolbar: [
{ name: 'styles', items: [ 'styles' ] },
{ name: 'formatting', items: [ 'bold', 'italic', 'forecolor' ] },
{ name: 'lists', items: [ 'bullist', 'numlist' ] },
{ name: 'alignment', items: [ 'alignleft', 'aligncenter', 'alignright', 'alignjustify' ] },
{ name: 'indentation', items: [ 'outdent', 'indent' ] },
{ name: 'table', items: [ 'table' ] },
{ name: 'extra', items: [ 'fullscreen' ] }
],
mobile: {
menubar: false,
plugins: 'autosave lists autolink',
toolbar: 'undo bold italic styles',
},
plugins: 'link image lists table code codesample fullscreen autoresize',
});
</script>
<script src="/js/pretty_content.js"></script>
<script src="/libs/sweetalert2/js/sweetalert2.min.js"></script>
@@ -94,6 +44,7 @@
<?php } ?>
<script src="/js/keepalive.js"></script>
<script src="/js/portal.js"></script>
</body>
</html>

View File

@@ -1,14 +1,40 @@
<?php
/*
* Client Portal
* HTML Header
* HTML Header - the portal's shell: a light top bar carrying the company's
* logo (or its initials on the theme colour), the sections this contact can
* open, New ticket and their account menu. On a phone the sections move to
* a bar along the bottom and a menu that slides in.
*
* Portal pages set a Content-Security-Policy of default-src 'self', so nothing
* in here - or in a page that sets it - may use an inline script or a style=""
* attribute: behaviour lives in js/portal.js, looks in css/itflow_custom.css.
*/
header("X-Frame-Options: DENY"); // Legacy
// A page that turned the policy on keeps it, with data: images allowed - the
// arrows on drop-downs, ticks in checkboxes and the close crosses are data:
// SVGs in Bootstrap's CSS, which default-src 'self' alone blocked
foreach (headers_list() as $portal_header) {
if (stripos($portal_header, 'Content-Security-Policy:') === 0) {
header("Content-Security-Policy: default-src 'self'; img-src 'self' data:");
break;
}
}
$portal_page = basename($_SERVER['PHP_SELF']);
$portal_nav = portalNav();
// Dark mode is the contact's own choice, kept in a cookie by js/portal.js -
// read here so the first paint is already the right colour
$portal_dark = ($_COOKIE['itflow_portal_theme'] ?? '') === 'dark';
$portal_contact_name = (string) ($contact['contact_name'] ?? '');
?>
<!DOCTYPE html>
<html lang="en" data-lte-print="plain">
<html lang="en" data-bs-theme="<?= $portal_dark ? 'dark' : 'light' ?>" data-lte-color-mode="off" data-lte-print="plain">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -17,6 +43,7 @@ header("X-Frame-Options: DENY"); // Legacy
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<meta name="color-scheme" content="<?= $portal_dark ? 'dark' : 'light' ?>">
<!-- Favicon: If Fav Icon exists, else use the default one -->
<?php if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/uploads/favicon.ico')) { ?>
@@ -35,9 +62,8 @@ header("X-Frame-Options: DENY"); // Legacy
<link rel="stylesheet" href="/libs/adminlte/css/adminlte-colors-v3.min.css">
<link rel="stylesheet" href="/libs/sweetalert2/css/sweetalert2.min.css">
<!-- ITFlow style: the AdminLTE 3 compatibility layer and the theme colours. Must load
last so it wins, and must load HERE too - it used to be on the agent header only,
which left this portal without .text-bold, the bg-dark text pairing or any theme. -->
<!-- ITFlow style: the AdminLTE 3 compatibility layer, the theme colours and the
portal's own look. Must load last so it wins. -->
<link rel="stylesheet" href="/css/itflow_custom.css">
<?php /* Only the pages that set this flag before including inc_all.php pull
@@ -59,134 +85,115 @@ header("X-Frame-Options: DENY"); // Legacy
(default-src 'self') would block outright. Empty when the company has
no country set, which js/phone_inputs.js reads as "let the library
decide". */ ?>
<body class="d-flex flex-column min-vh-100 bg-body-tertiary theme-<?= escapeHtml($config_theme) ?>" data-lte-primary="<?= escapeHtml($config_theme) ?>"
<body class="itflow-portal d-flex flex-column min-vh-100 bg-body-tertiary theme-<?= escapeHtml($config_theme) ?>" data-lte-primary="<?= escapeHtml($config_theme) ?>"
data-itflow-phone-country="<?= escapeHtml($country_iso2_array[$session_company_country] ?? '') ?>">
<!-- Navbar -->
<header class="itflow-portal-header">
<div class="container d-flex align-items-center gap-3">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php"><?= escapeHtml($session_company_name) ?></a>
<button class="navbar-toggler" aria-label="Toggle navigation" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
<i class="fas fa-bars text-white"></i>
</button>
<a class="itflow-portal-brand" href="/client/index.php">
<?php if ($session_company_logo) { ?>
<img src="/uploads/settings/<?= escapeHtml($session_company_logo) ?>" alt="<?= escapeHtml($session_company_name) ?>">
<?php } else { ?>
<span class="itflow-brand-mark itflow-brand-mark-initials" aria-hidden="true"><?= escapeHtml(clientInitials('', $session_company_name)) ?></span>
<span class="itflow-portal-brand-name"><?= escapeHtml($session_company_name) ?></span>
<?php } ?>
</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto">
<li class="nav-item <?php if (basename($_SERVER['PHP_SELF']) == "index.php") {echo "active";} ?>">
<a class="nav-link" href="/client/index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if (basename($_SERVER['PHP_SELF']) == "tickets.php" || basename($_SERVER['PHP_SELF']) == "ticket_add.php" || basename($_SERVER['PHP_SELF']) == "ticket.php") {echo "active";} ?>" href="/client/tickets.php">Tickets</a>
</li>
<?php if (contactCan('accounting') && $config_module_enable_accounting == 1) { ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle <?= in_array(basename($_SERVER['PHP_SELF']), ['invoices.php', 'quotes.php', 'autopay.php', 'statement.php']) ? 'active' : '' ?>" href="#" id="navbarDropdown1" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Finance
<nav class="itflow-portal-nav d-none d-lg-flex" aria-label="Portal">
<?php foreach ($portal_nav as $item) {
$active = in_array($portal_page, $item['pages'], true);
if (!empty($item['children'])) { ?>
<div class="dropdown">
<a class="itflow-portal-nav-link dropdown-toggle<?= $active ? ' active' : '' ?>" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fas fa-fw <?= escapeHtml($item['icon']) ?>"></i><?= escapeHtml($item['label']) ?>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown1">
<a class="dropdown-item" href="/client/invoices.php">Invoices</a>
<a class="dropdown-item" href="/client/recurring_invoices.php">Recurring Invoices</a>
<a class="dropdown-item" href="/client/quotes.php">Quotes</a>
<a class="dropdown-item" href="/client/statement.php">Account Statement</a>
<a class="dropdown-item" href="/client/saved_payment_methods.php">Saved Payments</a>
<div class="dropdown-menu">
<?php foreach ($item['children'] as $child) { ?>
<a class="dropdown-item<?= in_array($portal_page, $child['pages'], true) ? ' active' : '' ?>" href="<?= escapeHtml($child['href']) ?>">
<i class="fas fa-fw <?= escapeHtml($child['icon']) ?> me-2"></i><?= escapeHtml($child['label']) ?>
</a>
<?php } ?>
</div>
</li>
<?php } ?>
<?php if ($config_module_enable_itdoc && contactCan('itdoc')) { ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle <?= in_array(basename($_SERVER['PHP_SELF']), ['documents.php', 'contacts.php', 'domains.php', 'certificates.php']) ? 'active' : '' ?>" href="#" id="navbarDropdown2" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Technical
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown2">
<a class="dropdown-item" href="/client/contacts.php">Contacts</a>
<a class="dropdown-item" href="/client/assets.php">Assets</a>
<a class="dropdown-item" href="/client/documents.php">Documents</a>
<a class="dropdown-item" href="/client/domains.php">Domains</a>
<a class="dropdown-item" href="/client/certificates.php">Certificates</a>
<a class="dropdown-item" href="/client/ticket_view_all.php">All tickets</a>
</div>
</li>
<?php } ?>
<?php
$sql_custom_links = mysqli_query($mysqli, "SELECT 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_custom_links)) {
$custom_link_name = escapeHtml($row['custom_link_name']);
$custom_link_uri = escapeHtml($row['custom_link_uri']);
$custom_link_new_tab = intval($row['custom_link_new_tab']);
if ($custom_link_new_tab == 1) {
$target = "target='_blank' rel='noopener noreferrer'";
} else {
$target = "";
}
?>
<li class="nav-item">
<a href="<?= $custom_link_uri ?>" <?= $target ?> class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == basename($custom_link_uri)) { echo "active"; } ?>"><?= $custom_link_name ?></a>
</li>
<?php } ?>
</ul><!-- End left nav -->
<ul class="nav navbar-nav ms-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown">
<?= stripslashes(escapeHtml($session_contact_name)) ?>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="/client/profile.php"><i class="fas fa-fw fa-user me-2"></i>Account</a>
<a class="dropdown-item" href="/client/activity.php"><i class="fas fa-fw fa-list me-2"></i>Activity</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/client/post.php?logout"><i class="fas fa-fw fa-sign-out-alt me-2"></i>Sign out</a>
</div>
</li>
</ul>
<?php } else { ?>
<a class="itflow-portal-nav-link<?= $active ? ' active' : '' ?>" href="<?= escapeHtml($item['href']) ?>"<?= !empty($item['new_tab']) ? ' target="_blank" rel="noopener noreferrer"' : '' ?>>
<i class="<?= escapeHtml($item['icon_class'] ?? 'fas fa-fw ' . $item['icon']) ?>"></i><?= escapeHtml($item['label']) ?>
</a>
<?php } ?>
<?php } ?>
</nav>
<div class="ms-auto d-flex align-items-center gap-2">
<a class="btn btn-primary d-none d-sm-inline-flex align-items-center" href="/client/ticket_add.php"><i class="fas fa-plus me-2"></i>New ticket</a>
<div class="dropdown">
<button type="button" class="itflow-portal-account" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Your account">
<?= portalAvatarHtml($portal_contact_name, $session_contact_photo ? "/uploads/clients/$session_client_id/$session_contact_photo" : '') ?>
<span class="d-none d-md-inline text-truncate"><?= escapeHtml($portal_contact_name) ?></span>
<i class="fas fa-chevron-down small text-body-secondary d-none d-md-inline"></i>
</button>
<div class="dropdown-menu dropdown-menu-end">
<div class="dropdown-header">
<div class="fw-semibold text-body"><?= escapeHtml($portal_contact_name) ?></div>
<div class="small"><?= escapeHtml($session_client_name) ?></div>
</div>
<div class="dropdown-divider"></div>
<a class="dropdown-item<?= $portal_page === 'profile.php' ? ' active' : '' ?>" href="/client/profile.php"><i class="fas fa-fw fa-user me-2"></i>Your account</a>
<a class="dropdown-item<?= $portal_page === 'activity.php' ? ' active' : '' ?>" href="/client/activity.php"><i class="fas fa-fw fa-list me-2"></i>Activity</a>
<button type="button" class="dropdown-item" data-portal-theme-toggle>
<i class="fas fa-fw <?= $portal_dark ? 'fa-sun' : 'fa-moon' ?> me-2"></i><?= $portal_dark ? 'Light mode' : 'Dark mode' ?>
</button>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/client/post.php?logout"><i class="fas fa-fw fa-sign-out-alt me-2"></i>Sign out</a>
</div>
</div>
</div>
</div>
</header>
<?php /* Phone: the sections along the bottom of the screen, where a thumb
reaches them, and everything else in a menu that slides in. */ ?>
<nav class="itflow-portal-tabbar d-lg-none" aria-label="Portal">
<a href="/client/index.php" class="<?= $portal_page === 'index.php' ? 'active' : '' ?>"><i class="fas fa-home"></i><span>Home</span></a>
<a href="/client/tickets.php" class="<?= in_array($portal_page, $portal_nav['tickets']['pages'], true) && $portal_page !== 'ticket_add.php' ? 'active' : '' ?>"><i class="fas fa-life-ring"></i><span>Tickets</span></a>
<a href="/client/ticket_add.php" class="itflow-portal-tabbar-new<?= $portal_page === 'ticket_add.php' ? ' active' : '' ?>"><i class="fas fa-plus"></i><span>New</span></a>
<?php if (isset($portal_nav['billing'])) { ?>
<a href="/client/invoices.php" class="<?= in_array($portal_page, $portal_nav['billing']['pages'], true) ? 'active' : '' ?>"><i class="fas fa-file-invoice-dollar"></i><span>Billing</span></a>
<?php } ?>
<a href="#portalMenu" data-bs-toggle="offcanvas" role="button" aria-controls="portalMenu"><i class="fas fa-bars"></i><span>Menu</span></a>
</nav>
<?php /* The gap under the navbar used to be a bare line-break element sitting
directly in the body. That stopped working the moment the body became a
flex column: a break is only a break inside an inline formatting
context, and as a flex item it is blockified into an empty zero-height
box - so the gap vanished and the welcome row rode up against the
navbar.
Carried on the container as a real margin instead. mt-4 is 1.5rem,
exactly what the break was worth: one line box at the body's 1.5
line-height on a 1rem font. */ ?>
<!-- Page content container -->
<div class="container mt-4">
<!-- Flex row rather than col-md-1/col-md-11 -->
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
<div class="flex-shrink-0">
<?php if (!empty($session_contact_photo)) { ?>
<img src="/uploads/clients/<?= $session_client_id ?>/<?= $session_contact_photo ?>" alt="..." height="50" width="50" class="rounded-circle img-fluid">
<?php } else { ?>
<span class="fa-stack fa-2x rounded-start">
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
<span class="fa fa-stack-1x text-white"><?= $session_contact_initials ?></span>
</span>
<?php } ?>
<div class="offcanvas offcanvas-end itflow-portal-menu" tabindex="-1" id="portalMenu" aria-label="Menu">
<div class="offcanvas-header">
<div class="min-w-0">
<div class="fw-semibold text-truncate"><?= escapeHtml($portal_contact_name) ?></div>
<div class="small text-body-secondary text-truncate"><?= escapeHtml($session_client_name) ?></div>
</div>
<h4 class="mb-0 flex-grow-1">Welcome, <strong><?= stripslashes(escapeHtml($session_contact_name)) ?></strong>!</h4>
<?php if ($session_company_logo) { ?>
<img height="48" width="142" class="img-fluid flex-shrink-0" src="<?= "/uploads/settings/$session_company_logo" ?>">
<?php } ?>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<hr>
<div class="offcanvas-body">
<?php foreach ($portal_nav as $item) { ?>
<?php if (!empty($item['children'])) { ?>
<div class="itflow-portal-menu-heading"><?= escapeHtml($item['label']) ?></div>
<?php foreach ($item['children'] as $child) { ?>
<a class="itflow-portal-menu-link<?= in_array($portal_page, $child['pages'], true) ? ' active' : '' ?>" href="<?= escapeHtml($child['href']) ?>"><i class="fas fa-fw <?= escapeHtml($child['icon']) ?>"></i><?= escapeHtml($child['label']) ?></a>
<?php } ?>
<?php } else { ?>
<a class="itflow-portal-menu-link<?= in_array($portal_page, $item['pages'], true) ? ' active' : '' ?>" href="<?= escapeHtml($item['href']) ?>"<?= !empty($item['new_tab']) ? ' target="_blank" rel="noopener noreferrer"' : '' ?>><i class="<?= escapeHtml($item['icon_class'] ?? 'fas fa-fw ' . $item['icon']) ?>"></i><?= escapeHtml($item['label']) ?></a>
<?php } ?>
<?php } ?>
<div class="itflow-portal-menu-heading">Your account</div>
<a class="itflow-portal-menu-link<?= $portal_page === 'profile.php' ? ' active' : '' ?>" href="/client/profile.php"><i class="fas fa-fw fa-user"></i>Your account</a>
<a class="itflow-portal-menu-link<?= $portal_page === 'activity.php' ? ' active' : '' ?>" href="/client/activity.php"><i class="fas fa-fw fa-list"></i>Activity</a>
<button type="button" class="itflow-portal-menu-link" data-portal-theme-toggle><i class="fas fa-fw <?= $portal_dark ? 'fa-sun' : 'fa-moon' ?>"></i><?= $portal_dark ? 'Light mode' : 'Dark mode' ?></button>
<a class="itflow-portal-menu-link" href="/client/post.php?logout"><i class="fas fa-fw fa-sign-out-alt"></i>Sign out</a>
</div>
</div>
<!-- Page content container -->
<main class="itflow-portal-main container">
<?php
//Alert Feedback

View File

@@ -1,280 +1,334 @@
<?php
/*
* Client Portal
* Landing / Home page for the client portal
* Home - what needs this contact: tickets waiting on their reply or for them
* to confirm, approvals, invoices past due; their open tickets, the balance,
* renewals coming up and the devices they use.
*
* SCOPING: everything here is keyed to $session_client_id from the session,
* tickets through portalTicketScopeSql() (their own, or the whole company's
* for primary and technical contacts), and the money and IT sections are only
* read for a contact who may see them.
*/
header("Content-Security-Policy: default-src 'self'");
require_once "includes/inc_all.php";
// Billing Card Queries
//Add up all the payments for the invoice and get the total amount paid to the invoice
$sql_invoice_amounts = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS invoice_amounts FROM invoices WHERE invoice_client_id = $session_client_id AND invoice_status != 'Draft' AND invoice_status != 'Cancelled' AND invoice_status != 'Non-Billable'");
$row = mysqli_fetch_assoc($sql_invoice_amounts);
$scope_sql = portalTicketScopeSql();
$sees_all = portalSeesAllTickets();
$can_billing = contactCan('accounting') && $config_module_enable_accounting == 1;
$can_it = $config_module_enable_itdoc && contactCan('itdoc');
$ticket_from = "FROM tickets LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id WHERE $scope_sql AND tickets.ticket_archived_at IS NULL";
$invoice_amounts = floatval($row['invoice_amounts']);
// Tickets - counted, and the ones that need the contact
$tabs = portalTicketTabs();
$counts = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT
COALESCE(SUM({$tabs['open']['where']}), 0) AS open_count,
COALESCE(SUM({$tabs['resolved']['where']}), 0) AS resolved_count
$ticket_from"));
$open_count = intval($counts['open_count']);
$resolved_count = intval($counts['resolved_count']);
$you_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) $ticket_from AND {$tabs['you']['where']}"))[0]);
$sql_amount_paid = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS amount_paid FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_client_id = $session_client_id");
$row = mysqli_fetch_assoc($sql_amount_paid);
$needs_you = [];
$sql = mysqli_query($mysqli, "SELECT " . portalTicketColumnsSql() . " $ticket_from AND ({$tabs['you']['where']} OR {$tabs['resolved']['where']})
ORDER BY COALESCE(tickets.ticket_updated_at, tickets.ticket_created_at) DESC LIMIT 6");
while ($row = mysqli_fetch_assoc($sql)) {
$resolved = !empty($row['ticket_resolved_at']);
$needs_you[] = [
'href' => '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"
);
?>
<div class="row">
<div class="col-md-2">
<a href="ticket_add.php" class="btn btn-primary w-100 mb-3">New ticket</a>
</div>
</div>
<?php
// Billing Cards
if (contactCan('accounting')) { ?>
<div class="row">
<?php if ($balance > 0) { ?>
<div class="col-sm-3">
<a href="unpaid_invoices.php" class="card">
<div class="card-header">
<h3 class="card-title text-bold text-dark">Account Balance</h3>
</div>
<div class="card-body">
<div class="h4 text-danger"><b><?= numfmt_format_currency($currency_format, $balance, $session_company_currency) ?></b></div>
</div>
</a>
</div>
<?php } ?>
<?php if ($recurring_monthly > 0) { ?>
<div class="col-sm-3">
<a href="recurring_invoices.php" class="card text-dark">
<div class="card-header">
<h3 class="card-title">Recurring Monthly</h3>
</div>
<div class="card-body">
<div class="h4"><b><?= numfmt_format_currency($currency_format, $recurring_monthly, $session_company_currency) ?></b></div>
</div>
</a>
</div>
<?php } ?>
</div>
<?php } //End Billing Cards ?>
<?php
// Technical Cards
if (contactCan('itdoc')) {
$hour = intval(date('G'));
$greeting = $hour < 12 ? 'Good morning' : ($hour < 18 ? 'Good afternoon' : 'Good evening');
$first_name = strtok(trim((string) $contact['contact_name']), ' ') ?: '';
?>
<div class="row">
<div class="itflow-portal-page-head">
<div>
<h1><?= escapeHtml(rtrim("$greeting, $first_name", ', ')) ?></h1>
<p><?= escapeHtml($session_client_name) ?></p>
</div>
<div class="d-flex flex-wrap gap-2">
<?php if ($can_billing && $balance > 0) { ?>
<a class="btn btn-outline-primary" href="unpaid_invoices.php"><i class="fas fa-credit-card me-2"></i>Pay invoices</a>
<?php } ?>
</div>
</div>
<?php if (mysqli_num_rows($sql_domains_expiring) > 0) { ?>
<div class="col-sm-3">
<a href="domains.php">
<div class="card text-dark">
<div class="card-header">
<h3 class="card-title text-bold"><i class="fas fa-fw fa-globe me-2"></i>Domains Expiring</h3>
<div class="row g-3 mb-4">
<div class="col-6 col-lg-3">
<a class="itflow-portal-stat" href="tickets.php">
<span class="itflow-portal-stat-icon"><i class="fas fa-life-ring"></i></span>
<span>
<span class="itflow-portal-stat-value d-block"><?= $open_count ?></span>
<span class="itflow-portal-stat-label"><?= $open_count === 1 ? 'Open ticket' : 'Open tickets' ?><?= $sees_all ? '' : ' of yours' ?></span>
</span>
</a>
</div>
<div class="col-6 col-lg-3">
<a class="itflow-portal-stat<?= $you_count ? ' itflow-portal-stat-alert' : '' ?>" href="tickets.php?tab=you">
<span class="itflow-portal-stat-icon"><i class="fas fa-reply"></i></span>
<span>
<span class="itflow-portal-stat-value d-block"><?= $you_count ?></span>
<span class="itflow-portal-stat-label">Waiting on you</span>
</span>
</a>
</div>
<?php if ($can_billing) { ?>
<div class="col-6 col-lg-3">
<a class="itflow-portal-stat<?= $overdue > 0 ? ' itflow-portal-stat-danger' : '' ?>" href="<?= $balance > 0 ? 'unpaid_invoices.php' : 'invoices.php' ?>">
<span class="itflow-portal-stat-icon"><i class="fas fa-file-invoice-dollar"></i></span>
<span class="min-w-0">
<span class="itflow-portal-stat-value d-block"><?= numfmt_format_currency($currency_format, $balance, $client_currency) ?></span>
<span class="itflow-portal-stat-label">
<?php if ($overdue > 0) { ?>
<?= numfmt_format_currency($currency_format, $overdue, $client_currency) ?> past due
<?php } elseif ($balance > 0 && $next_due) { ?>
Due <?= date('M j', strtotime($next_due)) ?>
<?php } else { ?>
Nothing owed
<?php } ?>
</span>
</span>
</a>
</div>
<?php } ?>
<?php if ($can_it) { ?>
<div class="col-6 col-lg-3">
<a class="itflow-portal-stat" href="#renewals">
<span class="itflow-portal-stat-icon"><i class="fas fa-calendar-alt"></i></span>
<span>
<span class="itflow-portal-stat-value d-block"><?= count($renewals) ?></span>
<span class="itflow-portal-stat-label"><?= count($renewals) === 1 ? 'Renewal' : 'Renewals' ?> coming up</span>
</span>
</a>
</div>
<?php } ?>
</div>
<div class="row g-4">
<div class="col-lg-8">
<section class="itflow-portal-panel mb-4">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-bell"></i>Needs you</h2>
</div>
<?php if (!$needs_you) { ?>
<?= emptyStateHtml(['title' => "You're all caught up", 'text' => 'Nothing is waiting on you right now.', 'icon' => 'fa-check', 'filtered' => false]) ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php foreach (array_slice($needs_you, 0, 8) as $item) { ?>
<li>
<a class="itflow-portal-todo" href="<?= escapeHtml($item['href']) ?>">
<span class="itflow-portal-todo-icon <?= $item['tone'] ?>"><i class="fas <?= $item['icon'] ?>"></i></span>
<span class="itflow-portal-todo-main">
<div><?= escapeHtml($item['title']) ?></div>
<div><?= escapeHtml($item['line']) ?></div>
</span>
<i class="fas fa-chevron-right text-body-secondary small"></i>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
</section>
<section class="itflow-portal-panel">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-life-ring"></i><?= $sees_all ? 'Open tickets' : 'Your open tickets' ?></h2>
<a href="tickets.php">All tickets</a>
</div>
<?php if (!mysqli_num_rows($recent)) { ?>
<?= emptyStateHtml(['title' => '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']]]) ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php while ($row = mysqli_fetch_assoc($recent)) {
$updated = $row['ticket_updated_at'] ?: $row['ticket_created_at']; ?>
<li>
<a class="itflow-portal-ticket" href="ticket.php?id=<?= intval($row['ticket_id']) ?>">
<span class="itflow-portal-ticket-main">
<span class="itflow-portal-ticket-subject d-block"><?= escapeHtml($row['ticket_subject']) ?></span>
<span class="itflow-portal-ticket-meta">
<span><?= escapeHtml($row['ticket_prefix'] . $row['ticket_number']) ?></span>
<?php if ($sees_all && !empty($row['contact_name'])) { ?><span><i class="fas fa-user me-1"></i><?= escapeHtml($row['contact_name']) ?></span><?php } ?>
</span>
</span>
<span class="itflow-portal-ticket-side">
<?= portalTicketStateHtml($row) ?>
<small title="<?= escapeHtml($updated) ?>"><?= timeAgo($updated) ?></small>
</span>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
</section>
</div>
<div class="col-lg-4">
<?php if ($devices) { ?>
<section class="itflow-portal-panel mb-4">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-desktop"></i>Your devices</h2>
<?php if ($can_it) { ?><a href="assets.php">All assets</a><?php } ?>
</div>
<div class="card-body">
<?php
<ul class="itflow-portal-list">
<?php foreach ($devices as $device) {
$warranty = assetWarranty($device['asset_warranty_expire']);
$what = trim($device['asset_make'] . ' ' . $device['asset_model']) ?: $device['asset_type'];
$link = escapeUrl($device['asset_uri_client']); ?>
<li class="itflow-portal-todo">
<span class="itflow-portal-todo-icon is-info"><i class="fas fa-<?= getAssetIcon($device['asset_type']) ?>"></i></span>
<span class="itflow-portal-todo-main">
<div><?= escapeHtml($device['asset_name']) ?></div>
<div>
<?= escapeHtml($what) ?>
<?php if ($warranty && $warranty['tone'] !== 'success') { ?>
· <span class="text-<?= $warranty['tone'] ?>-emphasis">Warranty <?= escapeHtml(strtolower($warranty['short'])) ?></span>
<?php } ?>
</div>
</span>
<?php if ($link) { ?>
<a href="<?= $link ?>" target="_blank" rel="noopener noreferrer" class="text-body-secondary" title="Open"><i class="fas fa-external-link-alt"></i></a>
<?php } ?>
</li>
<?php } ?>
</ul>
</section>
<?php } ?>
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']);
?>
<p>
<strong><?= $domain_name ?></strong>
<br>
<small class="text-secondary"><?= $domain_expire ?> (<?= $domain_expire_human ?>)</small>
</p>
<?php
}
?>
<?php if ($can_it) { ?>
<section class="itflow-portal-panel mb-4" id="renewals">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-calendar-alt"></i>Coming up</h2>
</div>
</div>
</a>
<?php if (!$renewals) { ?>
<?= emptyStateHtml(['title' => 'Nothing renewing soon', 'text' => 'Domains, certificates, licenses and warranties due in the next 45 days show here.', 'icon' => 'fa-check', 'filtered' => false]) ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php foreach (array_slice($renewals, 0, 8) as $item) {
$lapsed = $item['date'] < date('Y-m-d'); ?>
<li class="itflow-portal-todo">
<span class="itflow-portal-todo-icon<?= $lapsed ? ' is-danger' : '' ?>"><i class="fas <?= $item['icon'] ?>"></i></span>
<span class="itflow-portal-todo-main">
<div><?= escapeHtml($item['name']) ?></div>
<div><?= escapeHtml($item['kind']) ?> · <?= $lapsed ? 'expired' : 'renews' ?> <?= escapeHtml(date('M j, Y', strtotime($item['date']))) ?> (<?= timeAgo($item['date']) ?>)</div>
</span>
</li>
<?php } ?>
</ul>
<?php } ?>
</section>
<?php } ?>
<?php if (!empty($company['company_phone']) || !empty($company['company_email'])) { ?>
<section class="itflow-portal-panel">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-headset"></i>Need us fast?</h2>
</div>
<div class="itflow-portal-panel-body">
<p class="text-body-secondary small mb-2">For anything urgent, call us - and raise a ticket so it is on record.</p>
<?php if (!empty($company['company_phone'])) { ?>
<div class="mb-1"><i class="fas fa-fw fa-phone me-2 text-body-secondary"></i><a href="tel:<?= escapeHtml(preg_replace('/[^0-9+]/', '', ($company['company_phone_country_code'] ? '+' . $company['company_phone_country_code'] : '') . $company['company_phone'])) ?>"><?= escapeHtml(formatPhoneNumber($company['company_phone'], $company['company_phone_country_code'])) ?></a></div>
<?php } ?>
<?php if (!empty($company['company_email'])) { ?>
<div><i class="fas fa-fw fa-envelope me-2 text-body-secondary"></i><a href="mailto:<?= escapeHtml($company['company_email']) ?>"><?= escapeHtml($company['company_email']) ?></a></div>
<?php } ?>
</div>
</section>
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
<?php
// Everone Cards
?>
<div class="row">
<?php if (mysqli_num_rows($sql_assigned_assets) > 0) { ?>
<div class="col-sm-3">
<a href="assets.php" class="card text-dark">
<div class="card-header">
<h3 class="card-title"><i class="fas fa-fw fa-desktop me-2"></i>Your Assigned Assets</h3>
</div>
<div class="card-body">
<table>
<?php
while ($row = mysqli_fetch_assoc($sql_assigned_assets)) {
$asset_name = escapeHtml($row['asset_name']);
$asset_type = escapeHtml($row['asset_type']);
$asset_uri_client = escapeUrl($row['asset_uri_client']);
?>
<tr>
<td><i class=" text-secondary me-2"></i><?php if ($asset_uri_client) { ?><a href="<?= $asset_uri_client ?>" target="_blank"><i class='fas fa-external-link-alt me-2'></i></a><?php } ?><?= $asset_name ?></td>
<td class="text-secondary">(<?= $asset_type ?>)</td>
</tr>
<?php
}
?>
</table>
</div>
</a>
</div>
<?php } ?>
</div>
<?php require_once "includes/footer.php"; ?>

View File

@@ -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();
}

View File

@@ -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']);

View File

@@ -1,7 +1,16 @@
<?php
/*
* Client Portal
* Ticket detail page
* A ticket - where it stands (received, in progress, resolved, closed), the
* conversation oldest first with the client's own messages on the right,
* approvals waiting on them, the details down the side, and what they can do
* next: reply with files, mark it resolved, close or reopen it, rate it.
*
* SCOPING: the ticket is read for the session's client, and only if it is the
* contact's own unless they see the company's (portalTicketScopeSql()), the
* same rule verifyContactTicketAccess() holds the handlers to.
*
* No Content-Security-Policy here: the editor needs inline styles.
*/
require_once "includes/inc_all.php";
@@ -14,364 +23,272 @@ $purifier_config->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) {
?>
<a class="itflow-portal-back" href="tickets.php"><i class="fas fa-chevron-left"></i>Tickets</a>
<section class="itflow-portal-panel">
<?= emptyStateHtml(['title' => "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']]]) ?>
</section>
<?php
require_once "includes/footer.php";
exit;
}
$ticket_contact_snippet = "AND ticket_contact_id = $session_contact_id";
// Bypass ticket contact being session_id for a primary / technical contact viewing all tickets
if ($session_contact_primary == 1 || $session_contact_is_technical_contact) {
$ticket_contact_snippet = '';
$state = portalTicketState($ticket);
$number = $ticket['ticket_prefix'] . $ticket['ticket_number'];
$resolved = !empty($ticket['ticket_resolved_at']);
$closed = !empty($ticket['ticket_closed_at']);
$csrf = $_SESSION['csrf_token'];
// Tasks - how far along, and the ones waiting on a client's approval
$tasks = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(*) AS total, COALESCE(SUM(task_completed_at IS NOT NULL), 0) AS done FROM tasks WHERE task_ticket_id = $ticket_id"));
$task_count = intval($tasks['total']);
$task_done = intval($tasks['done']);
$approvals = [];
$sql = mysqli_query($mysqli, "SELECT task_id, task_name, approval_id, approval_type, approval_url_key FROM tasks
JOIN task_approvals ON task_id = approval_task_id
WHERE task_ticket_id = $ticket_id AND task_completed_at IS NULL AND approval_scope = 'client' AND approval_status = 'pending' ORDER BY task_order ASC, task_id ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$type = (string) $row['approval_type'];
$row['can_approve'] = $type === 'any' || $session_contact_primary
|| ($type === 'technical' && $session_contact_is_technical_contact) || ($type === 'billing' && $session_contact_is_billing_contact);
$approvals[] = $row;
}
// Attachments, by the reply they came with (0 for the ticket itself) - never an internal note's
$attachments = [];
$sql = mysqli_query($mysqli, "SELECT ticket_attachment_id, ticket_attachment_name, ticket_attachment_reply_id FROM ticket_attachments
LEFT JOIN ticket_replies ON ticket_reply_id = ticket_attachment_reply_id
WHERE ticket_attachment_ticket_id = $ticket_id
AND (ticket_attachment_reply_id IS NULL OR (ticket_reply_type != 'Internal' AND ticket_reply_archived_at IS NULL))
ORDER BY ticket_attachment_id ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$attachments[intval($row['ticket_attachment_reply_id'])][] = $row;
}
// The conversation, oldest first
$replies = mysqli_query($mysqli, "SELECT ticket_reply_id, ticket_reply, ticket_reply_type, ticket_reply_by, ticket_reply_created_at,
contact_name, contact_photo, user_id, user_name, user_avatar
FROM ticket_replies
LEFT JOIN users ON ticket_reply_type != 'Client' AND ticket_reply_by = user_id
LEFT JOIN contacts ON ticket_reply_type = 'Client' AND ticket_reply_by = contact_id
WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL AND ticket_reply_type != 'Internal'
ORDER BY ticket_reply_id ASC");
/** One message in the conversation. */
function portalMessageHtml($name, $avatar_url, $when, $body_html, array $files, $mine, $agent) {
$html = '<div class="itflow-portal-msg' . ($mine ? ' itflow-portal-msg-mine' : '') . '">'
. portalAvatarHtml($name, $avatar_url, 'lg')
. '<div class="itflow-portal-msg-body">'
. '<div class="itflow-portal-msg-head"><strong>' . escapeHtml($mine ? 'You' : $name) . '</strong>'
. ($agent ? '<span>' . escapeHtml($GLOBALS['session_company_name']) . '</span>' : '')
. '<span title="' . escapeHtml($when) . '">' . portalDateTime($when) . '</span></div>'
. '<div class="itflow-portal-msg-bubble prettyContent">' . $body_html;
if ($files) {
$html .= '<div class="itflow-portal-files">';
foreach ($files as $file) {
$id = intval($file['ticket_attachment_id']);
$html .= '<a class="itflow-portal-file-chip" href="ticket_attachment.php?attachment_id=' . $id . '&amp;action=view" target="_blank" rel="noopener" title="Open">'
. '<i class="fas fa-paperclip"></i><span class="text-truncate">' . escapeHtml($file['ticket_attachment_name']) . '</span></a>'
. '<a class="itflow-portal-file-chip" href="ticket_attachment.php?attachment_id=' . $id . '" title="Download ' . escapeHtml($file['ticket_attachment_name']) . '" aria-label="Download"><i class="fas fa-download"></i></a>';
}
$html .= '</div>';
}
return $html . '</div></div></div>';
}
$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) {
<a class="itflow-portal-back" href="tickets.php"><i class="fas fa-chevron-left"></i>Tickets</a>
$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']);
<div class="itflow-portal-page-head">
<div class="min-w-0">
<h1><?= escapeHtml($ticket['ticket_subject']) ?></h1>
<p>
<?= escapeHtml($number) ?> · opened <?= portalDateTime($ticket['ticket_created_at']) ?>
<?php if ($requester !== '') { ?>by <?= intval($ticket['ticket_contact_id']) === $session_contact_id ? 'you' : escapeHtml($requester) ?><?php } ?>
</p>
</div>
<div class="d-flex flex-wrap align-items-center gap-2">
<?= portalTicketStateHtml($ticket) ?>
<?php if (!$resolved && !$closed && $task_count === $task_done) { ?>
<a href="post.php?resolve_ticket=<?= $ticket_id ?>&csrf_token=<?= $csrf ?>" class="btn btn-outline-success confirm-link" data-confirm-title="Is it fixed?" data-confirm-text="We will mark it resolved - you can reopen it if it comes back." data-confirm-button="Yes, it is fixed" data-confirm-icon="question"><i class="fas fa-check me-2"></i>It's fixed</a>
<?php } ?>
</div>
</div>
// 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"
);
<div class="row g-4">
<div class="col-lg-8">
// 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);
<section class="itflow-portal-panel itflow-portal-panel-body mb-4">
<ol class="itflow-portal-steps">
<?php foreach ($steps as $i => $step) { ?>
<li class="<?= $i < $at ? 'done' : ($i === $at ? 'current' : '') ?>"><?= $i === 1 && $state['key'] === 'you' ? 'Waiting on you' : ($i === 1 && $state['key'] === 'hold' ? escapeHtml($state['label']) : $step) ?></li>
<?php } ?>
</ol>
</section>
// 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'
");
?>
<ol class="breadcrumb d-print-none">
<li class="breadcrumb-item">
<a href="index.php">Home</a>
</li>
<li class="breadcrumb-item">
<a href="tickets.php">Tickets</a>
</li>
<li class="breadcrumb-item active">Ticket <?= $ticket_prefix . $ticket_number ?></li>
</ol>
<div class="card">
<div class="card-header bg-dark my-2">
<h4 class="card-title mt-1">
Ticket <?= $ticket_prefix, $ticket_number ?>
</h4>
<div class="card-tools">
<?php
if (empty($ticket_resolved_at) && $task_count == $completed_task_count) { ?>
<a href="post.php?resolve_ticket=<?= $ticket_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="btn btn-sm btn-outline-success float-end text-white confirm-link"><i class="fas fa-fw fa-check text-success"></i> Resolve ticket</a>
<?php } ?>
<?php if ($approvals) { ?>
<section class="itflow-portal-panel mb-4">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-clipboard-check"></i>Waiting for your approval</h2>
</div>
</div>
<div class="card-body prettyContent">
<h5><strong>Subject:</strong> <?= $ticket_subject ?></h5>
<p>
<strong>State:</strong> <?= $ticket_status ?><br>
<strong>Priority:</strong> <?= $ticket_priority ?><br>
<?php if (!empty($ticket_category)) { ?>
<strong>Category:</strong> <?= $ticket_category ?><br>
<ul class="itflow-portal-list">
<?php foreach ($approvals as $approval) { ?>
<li class="itflow-portal-todo">
<span class="itflow-portal-todo-icon"><i class="fas fa-clipboard-check"></i></span>
<span class="itflow-portal-todo-main">
<div><?= escapeHtml($approval['task_name']) ?></div>
<div><?= $approval['can_approve'] ? 'We need your go-ahead before we do this' : 'Your ' . escapeHtml($approval['approval_type']) . ' contact needs to approve this' ?></div>
</span>
<?php if ($approval['can_approve']) { ?>
<a class="btn btn-sm btn-success confirm-link" href="post.php?approve_ticket_task=<?= intval($approval['task_id']) ?>&approval_id=<?= intval($approval['approval_id']) ?>&approval_url_key=<?= escapeHtml(urlencode($approval['approval_url_key'])) ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-check me-1"></i>Approve</a>
<?php } ?>
</li>
<?php } ?>
<?php if (empty($ticket_closed_at)) { ?>
<?php if ($task_count) { ?>
<strong>Tasks: </strong> <?= $completed_task_count . " / " .$task_count ?>
<br>
<?php } ?>
<?php if (!empty($ticket_assigned_to)) { ?>
<strong>Assigned to: </strong> <?= $ticket_assigned_to ?>
<?php } ?>
<?php } ?>
</p>
<hr>
<?= $ticket_details ?>
<table class="table-sm">
<?php
while ($ticket_attachment = mysqli_fetch_assoc($sql_ticket_attachments)) {
$ticket_attachment_id = intval($ticket_attachment['ticket_attachment_id']);
$name = escapeHtml($ticket_attachment['ticket_attachment_name']);
?>
<tr>
<td><i class='fas fa-fw fa-paperclip text-secondary me-1'></i><?= $name ?></td>
<td>
<a target='_blank' class='me-1 ms-1' href='ticket_attachment.php?attachment_id=<?= $ticket_attachment_id; ?>&action=view'>[View]</a><a href='ticket_attachment.php?attachment_id=<?= $ticket_attachment_id; ?>'>[Download]</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<!-- Approvals -->
<?php if (mysqli_num_rows($sql_task_approvals) > 0) { ?>
<div class="card">
<div class="card-body">
<h5>Approvals</h5>
This ticket has tasks requiring approval:
<ul>
<?php
while ($approvals = mysqli_fetch_assoc($sql_task_approvals)) {
$task_id = intval($approvals['task_id']);
$approval_id = intval($approvals['approval_id']);
$task_name = escapeHtml($approvals['task_name']);
$approval_type = escapeHtml($approvals['approval_type']);
$approval_url_key = escapeHtml($approvals['approval_url_key']);
$contact_can_approve = false; // Default
if ($approval_type == 'any') {
$contact_can_approve = true;
}
if ($session_contact_primary) {
$contact_can_approve = true;
}
if ($approval_type == 'technical' && $session_contact_is_technical_contact) {
$contact_can_approve = true;
}
if ($approval_type == 'billing' && $session_contact_is_billing_contact) {
$contact_can_approve = true;
}
?>
<li>
<?php echo $task_name;
if ($contact_can_approve) { ?> - <a href="post.php?approve_ticket_task=<?= $task_id ?>&approval_id=<?= $approval_id ?>&approval_url_key=<?= $approval_url_key ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="confirm-link">Approve task</a> <?php }
else {?> - Please ask your <?= $approval_type ?> contact to approve this task <?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</ul>
</section>
<?php } ?>
<hr>
<div class="itflow-portal-thread mb-4">
<?= portalMessageHtml($requester ?: 'Request', $requester_photo, $ticket['ticket_created_at'], $purifier->purify($ticket['ticket_details']),
$attachments[0] ?? [], intval($ticket['ticket_contact_id']) === $session_contact_id, false) ?>
<!-- Either show the reply comments box, option to re-open ticket, show ticket smiley feedback or thanks for feedback -->
<?php while ($reply = mysqli_fetch_assoc($replies)) {
$client_reply = $reply['ticket_reply_type'] === 'Client';
$event = $client_reply ? portalTicketEventText($reply['ticket_reply']) : '';
if ($event !== '') { ?>
<div class="itflow-portal-event"><span><?= escapeHtml($event) ?> · <?= portalDateTime($reply['ticket_reply_created_at']) ?></span></div>
<?php continue;
}
if ($client_reply) {
$name = (string) ($reply['contact_name'] ?: 'You');
$photo = $reply['contact_photo'] ? "/uploads/clients/$session_client_id/" . $reply['contact_photo'] : '';
$mine = intval($reply['ticket_reply_by']) === $session_contact_id;
} else {
$name = (string) ($reply['user_name'] ?: $session_company_name);
$photo = $reply['user_avatar'] ? '/uploads/users/' . intval($reply['user_id']) . '/' . $reply['user_avatar'] : '';
$mine = false;
}
echo portalMessageHtml($name, $photo, $reply['ticket_reply_created_at'], $purifier->purify($reply['ticket_reply']),
$attachments[intval($reply['ticket_reply_id'])] ?? [], $mine, !$client_reply);
} ?>
</div>
<?php if (empty($ticket_resolved_at)) { ?>
<!-- Reply -->
<?php if (!$resolved && !$closed) { ?>
<form action="post.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<div class="mb-3">
<textarea class="form-control tinymce" name="comment" placeholder="Add comments.."></textarea>
<section class="itflow-portal-panel" id="reply">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-reply"></i><?= $state['key'] === 'you' ? 'Reply - we are waiting on you' : 'Add a reply' ?></h2>
</div>
<div class="mb-3">
<input type="file" class="form-control" name="file[]" multiple id="fileInput" accept=".jpg, .jpeg, .gif, .png, .webp, .pdf, .txt, .md, .doc, .docx, .odt, .csv, .xls, .xlsx, .ods, .pptx, .odp, .zip, .tar, .gz, .xml, .msg, .json, .wav, .mp3, .ogg, .mov, .mp4, .av1, .ovpn">
</div>
<button type="submit" class="btn btn-primary" name="add_ticket_comment">Reply</button>
</form>
<?php } elseif (empty($ticket_closed_at)) { ?>
<!-- Re-open -->
<h4>Your ticket has been resolved</h4>
<div class="col-6">
<div class="row">
<div class="col">
<a href="post.php?reopen_ticket=<?= $ticket_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="btn btn-secondary btn-lg"><i class="fas fa-fw fa-redo text-white"></i> Reopen ticket</a>
<form class="itflow-portal-panel-body" action="post.php" enctype="multipart/form-data" method="post" data-portal-once>
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<div class="mb-3">
<textarea class="form-control tinymce" name="comment" placeholder="Write your reply" data-required></textarea>
<div class="invalid-feedback d-block" data-editor-required-note hidden>Write a reply first.</div>
</div>
<div class="col">
<a href="post.php?close_ticket=<?= $ticket_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="btn btn-success btn-lg confirm-link"><i class="fas fa-fw fa-gavel text-white"></i> Close ticket</a>
<div class="itflow-portal-drop mb-3" data-portal-drop>
<input type="file" name="file[]" multiple id="replyFiles" accept=".jpg, .jpeg, .gif, .png, .webp, .pdf, .txt, .md, .doc, .docx, .odt, .csv, .xls, .xlsx, .ods, .pptx, .odp, .zip, .tar, .gz, .xml, .msg, .json, .wav, .mp3, .ogg, .mov, .mp4, .av1, .ovpn">
<i class="fas fa-paperclip me-2"></i>Drop files here, or <label for="replyFiles">choose files</label> - screenshots, documents, error logs
<div class="itflow-portal-files" data-portal-files hidden></div>
</div>
<button type="submit" class="btn btn-primary" name="add_ticket_comment"><i class="fas fa-paper-plane me-2"></i>Send reply</button>
</form>
</section>
<?php } elseif (!$closed) { ?>
<section class="itflow-portal-panel">
<?= emptyStateHtml(['title' => '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]) ?>
<div class="d-flex flex-wrap justify-content-center gap-2 pb-4 px-3">
<a href="post.php?close_ticket=<?= $ticket_id ?>&csrf_token=<?= $csrf ?>" class="btn btn-success confirm-link" data-confirm-title="Close this ticket?" data-confirm-text="Glad it is sorted. You can raise a new ticket any time." data-confirm-button="Close it" data-confirm-icon="question"><i class="fas fa-check-circle me-2"></i>Yes, close it</a>
<a href="post.php?reopen_ticket=<?= $ticket_id ?>&csrf_token=<?= $csrf ?>" class="btn btn-outline-secondary"><i class="fas fa-redo me-2"></i>No, reopen it</a>
</div>
</div>
<br>
</section>
<?php } elseif (empty($ticket_feedback)) { ?>
<?php } elseif (empty($ticket['ticket_feedback'])) { ?>
<h4>Ticket closed. Please rate your ticket</h4>
<form action="post.php" method="post">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<button type="submit" class="btn btn-primary btn-lg" name="add_ticket_feedback" value="Good" onclick="this.form.submit()">
<span class="fa fa-smile" aria-hidden="true"></span> Good
</button>
<button type="submit" class="btn btn-danger btn-lg" name="add_ticket_feedback" value="Bad" onclick="this.form.submit()">
<span class="fa fa-frown" aria-hidden="true"></span> Bad
</button>
</form>
<section class="itflow-portal-panel">
<?= emptyStateHtml(['title' => 'How did we do?', 'text' => 'One click tells us how this one went.', 'icon' => 'fa-star', 'filtered' => false]) ?>
<form action="post.php" method="post" class="d-flex flex-wrap justify-content-center gap-2 pb-4 px-3">
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<button type="submit" class="btn btn-outline-success" name="add_ticket_feedback" value="Good"><i class="far fa-smile me-2"></i>Good</button>
<button type="submit" class="btn btn-outline-danger" name="add_ticket_feedback" value="Bad"><i class="far fa-frown me-2"></i>Not good</button>
</form>
</section>
<?php } else { ?>
<h4>Rated <?= $ticket_feedback ?> -- Thanks for your feedback!</h4>
<div class="itflow-portal-event"><span>Closed and rated <?= $ticket['ticket_feedback'] === 'Good' ? 'good' : 'not good' ?> - thank you for the feedback.</span></div>
<div class="text-center mt-3">
<a class="btn btn-outline-primary" href="ticket_add.php"><i class="fas fa-plus me-2"></i>Raise a new ticket</a>
</div>
<?php } ?>
<!-- End comments/reopen/feedback -->
<hr>
<br>
<?php
$sql = mysqli_query($mysqli, "SELECT contact_name, contact_photo, ticket_reply, ticket_reply_by, ticket_reply_created_at,
ticket_reply_id, ticket_reply_type, ticket_reply_updated_at, user_avatar, user_id,
user_name FROM ticket_replies LEFT JOIN users ON ticket_reply_by = user_id LEFT JOIN contacts ON ticket_reply_by = contact_id WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL AND ticket_reply_type != 'Internal' ORDER BY ticket_reply_id DESC");
while ($row = mysqli_fetch_assoc($sql)) {
$ticket_reply_id = intval($row['ticket_reply_id']);
$ticket_reply = $purifier->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"
);
?>
<div class="card card-outline <?php if ($ticket_reply_type == 'Client') { echo "card-warning"; } else { echo "card-info"; } ?> mb-3">
<div class="card-header">
<h3 class="card-title">
<div class="d-flex">
<?php
if (!empty($user_avatar)) {
?>
<img src="<?= $avatar_link ?>" alt="User Avatar" class="img-size-50 me-3 rounded-circle">
<?php
} else {
?>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
<span class="fa fa-stack-1x text-white"><?= $user_initials ?></span>
</span>
<?php
}
?>
<div class="flex-grow-1">
<?= $ticket_reply_by_display ?>
<br>
<small class="text-muted"><?= $ticket_reply_created_at ?> <?php if (!empty($ticket_reply_updated_at)) { echo "(edited: $ticket_reply_updated_at)"; } ?></small>
</div>
</div>
</h3>
</div>
<div class="card-body prettyContent">
<?= $ticket_reply ?>
<table class="table-sm">
<?php
while ($ticket_attachment = mysqli_fetch_assoc($sql_ticket_reply_attachments)) {
$ticket_attachment_id = intval($ticket_attachment['ticket_attachment_id']);
$name = escapeHtml($ticket_attachment['ticket_attachment_name']);
?>
<tr>
<td><i class='fas fa-fw fa-paperclip text-secondary me-1'></i><?= $name ?></td>
<td>
<a target='_blank' class='me-1 ms-1' href='ticket_attachment.php?attachment_id=<?= $ticket_attachment_id; ?>&action=view'>[View]</a><a href='ticket_attachment.php?attachment_id=<?= $ticket_attachment_id; ?>'>[Download]</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<div class="col-lg-4">
<section class="itflow-portal-panel">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-info-circle"></i>Details</h2>
</div>
<dl class="itflow-portal-facts itflow-portal-panel-body py-1">
<div><dt>Ticket</dt><dd><?= escapeHtml($number) ?></dd></div>
<div><dt>Status</dt><dd><?= escapeHtml($state['label']) ?></dd></div>
<div><dt>Priority</dt><dd><?= escapeHtml($ticket['ticket_priority']) ?></dd></div>
<?php if (!empty($ticket['category_name'])) { ?>
<div><dt>Category</dt><dd><?= escapeHtml($ticket['category_name']) ?></dd></div>
<?php } ?>
<?php if ($requester !== '') { ?>
<div><dt>Raised by</dt><dd><?= escapeHtml($requester) ?></dd></div>
<?php } ?>
<?php if ($agent_name !== '' && !$closed) { ?>
<div>
<dt>Working on it</dt>
<dd class="d-flex align-items-center justify-content-end gap-2">
<?= portalAvatarHtml($agent_name, $ticket['user_avatar'] ? '/uploads/users/' . intval($ticket['ticket_assigned_to']) . '/' . $ticket['user_avatar'] : '', 'sm') ?>
<?= escapeHtml($agent_name) ?>
</dd>
</div>
<?php } ?>
<?php if (!empty($ticket['asset_name'])) { ?>
<div><dt>Device</dt><dd><i class="fas fa-<?= getAssetIcon($ticket['asset_type']) ?> me-1 text-body-secondary"></i><?= escapeHtml($ticket['asset_name']) ?></dd></div>
<?php } ?>
<?php if ($task_count && !$closed) { ?>
<div><dt>Tasks</dt><dd><?= $task_done ?> of <?= $task_count ?> done</dd></div>
<?php } ?>
<div><dt>Opened</dt><dd><?= portalDateTime($ticket['ticket_created_at']) ?></dd></div>
<?php if ($closed) { ?>
<div><dt>Closed</dt><dd><?= portalDateTime($ticket['ticket_closed_at']) ?></dd></div>
<?php } elseif ($resolved) { ?>
<div><dt>Resolved</dt><dd><?= portalDateTime($ticket['ticket_resolved_at']) ?></dd></div>
<?php } elseif (!empty($ticket['ticket_updated_at'])) { ?>
<div><dt>Last update</dt><dd><?= portalDateTime($ticket['ticket_updated_at']) ?></dd></div>
<?php } ?>
</dl>
</section>
</div>
</div>
<?php
}
?>
<script src="../js/pretty_content.js"></script>
<?php
} else {
echo "Ticket ID not found!";
}
} else {
header("Location: index.php");
}
require_once "includes/footer.php";
<?php require_once "includes/footer.php"; ?>

View File

@@ -1,112 +1,142 @@
<?php
/*
* Client Portal
* New ticket form
* New ticket - what's wrong, how much it is getting in the way, which device,
* and any screenshots or files, with what happens next alongside.
*
* No Content-Security-Policy here: the editor needs inline styles.
*/
require_once 'includes/inc_all.php';
// Allow clients to select a related asset when raising a ticket
$sql_assets = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type 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");
// The devices they can pick: their own, or the company's for a primary or
// technical contact - add_ticket in post.php holds the choice to the same rule
$sees_all = portalSeesAllTickets();
$assets = [];
$sql = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_contact_id FROM assets
WHERE asset_client_id = $session_client_id AND asset_archived_at IS NULL" . ($sees_all ? '' : " AND asset_contact_id = $session_contact_id") . "
ORDER BY asset_contact_id = $session_contact_id DESC, asset_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$assets[] = $row;
}
$categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories
WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
$priorities = [
'Low' => ['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"));
?>
<ol class="breadcrumb d-print-none">
<li class="breadcrumb-item">
<a href="index.php">Home</a>
</li>
<li class="breadcrumb-item">
<a href="tickets.php">Tickets</a>
</li>
<li class="breadcrumb-item active">New Ticket</li>
</ol>
<a class="itflow-portal-back" href="tickets.php"><i class="fas fa-chevron-left"></i>Tickets</a>
<h3>Raise a new ticket</h3>
<div class="itflow-portal-page-head">
<div>
<h1>New ticket</h1>
<p>Tell us what is wrong and we will get on it.</p>
</div>
</div>
<div class="col-md-8">
<form action="post.php" method="post">
<div class="row g-4">
<div class="col-lg-8">
<form class="itflow-portal-panel itflow-portal-panel-body" action="post.php" method="post" enctype="multipart/form-data" data-portal-once>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="mb-3">
<label>Subject <strong class="text-danger">*</strong></label>
<label class="form-label" for="ticketSubject">Subject <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<input type="text" class="form-control" name="subject" placeholder="Subject" required>
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<input type="text" class="form-control" id="ticketSubject" name="subject" placeholder="In a few words - &quot;Outlook keeps asking for my password&quot;" maxlength="500" required autofocus>
</div>
</div>
<div class="mb-3">
<label class="form-label">What is happening? <strong class="text-danger">*</strong></label>
<textarea class="form-control tinymce" name="details" data-required placeholder="What you were doing, any error message, and when it started"></textarea>
<div class="invalid-feedback d-block" data-editor-required-note hidden>Tell us what is happening.</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3">
<label>Priority <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<select class="form-select select2" name="priority" required>
<option data-color="var(--bs-info)">Low</option>
<option selected data-color="var(--bs-warning)">Medium</option>
<option data-color="var(--bs-danger)">High</option>
<option data-color="var(--bs-emphasis-color)">Urgent</option>
</select>
</div>
</div>
</div>
<div class="col">
<div class="mb-3">
<label>Category</label>
<div class="col-md-6 mb-3">
<label class="form-label">How much is it getting in the way?</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category">
<option value="0">- No Category -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<select class="form-select select2" name="priority" required>
<?php foreach ($priorities as $priority => [$color, $hint]) { ?>
<option value="<?= $priority ?>" data-color="<?= $color ?>" data-description="<?= escapeHtml($hint) ?>"<?= $priority === 'Medium' ? ' selected' : '' ?>><?= $priority ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">What is it about?</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category">
<option value="0">Not sure</option>
<?php while ($row = mysqli_fetch_assoc($categories)) { ?>
<option value="<?= intval($row['category_id']) ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= escapeHtml($row['category_name']) ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<?php if (mysqli_num_rows($sql_assets) > 0) { ?>
<?php if ($assets) { ?>
<div class="mb-3">
<label>Asset</label>
<label class="form-label">Which device?</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<select class="form-select select2" name="asset">
<option value="0">- None -</option>
<?php
while ($row = mysqli_fetch_assoc($sql_assets)) {
$asset_id = intval($row['asset_id']);
$asset_name = escapeSql($row['asset_name']);
$asset_type = escapeSql($row['asset_type']);
?>
<option value="<?= $asset_id ?>"><?= "$asset_name ($asset_type)" ?></option>
<?php
}
?>
<option value="0">None, or not sure</option>
<?php foreach ($assets as $asset) { ?>
<option value="<?= intval($asset['asset_id']) ?>" data-icon="fas fa-<?= getAssetIcon($asset['asset_type']) ?>"
data-description="<?= escapeHtml($asset['asset_type'] . (intval($asset['asset_contact_id']) === $session_contact_id ? ' - yours' : '')) ?>"><?= escapeHtml($asset['asset_name']) ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="mb-3">
<label>Details <strong class="text-danger">*</strong></label>
<textarea class="form-control tinymce" name="details"></textarea>
<div class="mb-4">
<label class="form-label">Screenshots or files</label>
<div class="itflow-portal-drop" data-portal-drop>
<input type="file" name="file[]" multiple id="ticketFiles" accept=".jpg, .jpeg, .gif, .png, .webp, .pdf, .txt, .md, .doc, .docx, .odt, .csv, .xls, .xlsx, .ods, .pptx, .odp, .zip, .tar, .gz, .xml, .msg, .json, .wav, .mp3, .ogg, .mov, .mp4, .av1, .ovpn">
<i class="fas fa-paperclip me-2"></i>Drop files here, or <label for="ticketFiles">choose files</label>
<div class="itflow-portal-files" data-portal-files hidden></div>
</div>
</div>
<button class="btn btn-primary" name="add_ticket">Raise ticket</button>
<button type="submit" class="btn btn-primary" name="add_ticket"><i class="fas fa-paper-plane me-2"></i>Send ticket</button>
</form>
</div>
<div class="col-lg-4">
<section class="itflow-portal-panel">
<div class="itflow-portal-panel-head">
<h2><i class="fas fa-route"></i>What happens next</h2>
</div>
<div class="itflow-portal-panel-body">
<ol class="ps-3 mb-0 small">
<li class="mb-2">We get your ticket straight away and pick it up.</li>
<li class="mb-2">You hear from us by email, and every reply shows on the ticket here.</li>
<li class="mb-2">Answer us by replying to the email or on the ticket - whichever is easier.</li>
<li>When it is fixed we mark it resolved, and you close it - or reopen it if it is not.</li>
</ol>
<?php if (!empty($company['company_phone'])) { ?>
<hr>
<p class="small mb-1"><strong>Stopping everyone?</strong> Call us as well:</p>
<a href="tel:<?= escapeHtml(preg_replace('/[^0-9+]/', '', ($company['company_phone_country_code'] ? '+' . $company['company_phone_country_code'] : '') . $company['company_phone'])) ?>"><i class="fas fa-phone me-2"></i><?= escapeHtml(formatPhoneNumber($company['company_phone'], $company['company_phone_country_code'])) ?></a>
<?php } ?>
</div>
</section>
</div>
</div>
<?php
require_once 'includes/footer.php';

View File

@@ -26,8 +26,13 @@ if (isset($_GET['action']) && $_GET['action'] == "view") {
$disposition = "inline";
}
// Look up the attachment
$sql = mysqli_query($mysqli, "SELECT * FROM ticket_attachments WHERE ticket_attachment_id = $attachment_id LIMIT 1");
// Look up the attachment - one on the ticket itself, or on a reply the client
// can read: never one on an internal note, or on a reply that was archived
$sql = mysqli_query($mysqli, "SELECT ticket_attachments.* FROM ticket_attachments
LEFT JOIN ticket_replies ON ticket_reply_id = ticket_attachment_reply_id
WHERE ticket_attachment_id = $attachment_id
AND (ticket_attachment_reply_id IS NULL OR (ticket_reply_type != 'Internal' AND ticket_reply_archived_at IS NULL))
LIMIT 1");
if (mysqli_num_rows($sql) !== 1) {
http_response_code(404);

View File

@@ -1,87 +1,11 @@
<?php
/*
* Client Portal
* Primary contact view: all tickets
* The company's tickets now live on tickets.php, under Everyone - an old link
* here lands there, on the tab its status picked.
*/
require_once 'includes/inc_all.php';
$tab = ['Open' => '', '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");
?>
<h2>All tickets</h2>
<div class="col-md-2">
<div class="mb-3">
<form method="get">
<label>Ticket Status</label>
<select class="form-select" name="status" data-autosubmit>
<option value="%" <?php if ($status == "%") {echo "selected";}?> >Any</option>
<option value="Open" <?php if ($status == "Open") {echo "selected";}?> >Open</option>
<option value="Closed" <?php if ($status == "Closed") {echo "selected";}?> >Closed</option>
</select>
</form>
</div>
</div>
<?php if (mysqli_num_rows($all_tickets) == 0) { ?>
<?= portalEmptyState('There are no tickets for this account.') ?>
<?php } else { ?>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Subject</th>
<th scope="col">Contact</th>
<th scope="col">Status</th>
<th scope="col">Updated</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($all_tickets)) {
$ticket_id = intval($row['ticket_id']);
$ticket_prefix = escapeHtml($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_subject = escapeHtml($row['ticket_subject']);
$ticket_status = escapeHtml($row['ticket_status_name']);
$ticket_contact_name = escapeHtml($row['contact_name']);
echo "<tr>";
echo "<td> <a href='ticket.php?id=$ticket_id'> $ticket_prefix$ticket_number</a></td>";
echo "<td> <a href='ticket.php?id=$ticket_id'> $ticket_subject</a></td>";
echo "<td>$ticket_contact_name</td>";
$ticket_updated = $row['ticket_updated_at'] ?: $row['ticket_created_at'];
echo "<td>" . ticketPortalStatusHtml($row) . "</td>";
echo "<td class='text-nowrap' title='" . escapeHtml($ticket_updated) . "'>" . timeAgo($ticket_updated) . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<?php } ?>
</div>
<?php
require_once 'includes/footer.php';
header('Location: tickets.php' . ($tab !== '' ? '?tab=' . $tab : ''));
exit;

View File

@@ -1,123 +1,152 @@
<?php
/*
* Client Portal
* Landing / Home page for the client portal
* Tickets - this contact's, or the whole company's for a primary or technical
* contact, in tabs by where they stand for the client: open, waiting on them,
* resolved for them to confirm, closed, all. Searchable, 20 a page.
*
* SCOPING: portalTicketScopeSql() keeps every query to the session's client,
* and to the contact's own tickets unless they may see the company's.
*/
header("Content-Security-Policy: default-src 'self'");
require_once "includes/inc_all.php";
$per_page = 20;
$sees_all = portalSeesAllTickets();
$scope = $sees_all && ($_GET['scope'] ?? '') === 'mine' ? 'mine' : ($sees_all ? 'all' : 'mine');
$tabs = portalTicketTabs();
$tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : 'open';
$q = trim((string) ($_GET['q'] ?? ''));
$page = max(1, intval($_GET['page'] ?? 1));
// 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 '%'";
$where = portalTicketScopeSql($scope === 'mine') . " AND tickets.ticket_archived_at IS NULL";
if ($q !== '') {
$q_sql = escapeSql($q);
$q_number = intval(preg_replace('/\D/', '', $q));
$where .= " AND (tickets.ticket_subject LIKE '%$q_sql%' OR CONCAT(tickets.ticket_prefix, tickets.ticket_number) LIKE '%$q_sql%'" . ($q_number ? " OR tickets.ticket_number = $q_number" : '') . ")";
}
$from = "FROM tickets
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
LEFT JOIN contacts ON contact_id = tickets.ticket_contact_id
LEFT JOIN categories ON category_id = tickets.ticket_category
WHERE $where";
// One pass for every tab's count
$count_sql = [];
foreach ($tabs as $key => $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'],
];
?>
<h3>Tickets</h3>
<div class="row">
<div class="col-md-10">
<?php if (mysqli_num_rows($contact_tickets) == 0) { ?>
<?= portalEmptyState($status === '%' ? 'You have no tickets.' : 'You have no ' . strtolower($status) . ' tickets.') ?>
<?php } else { ?>
<table class="table table-bordered border border-dark">
<thead class="table-dark">
<tr>
<th>#</th>
<th>Subject</th>
<th>Status</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($contact_tickets)) {
$ticket_id = intval($row['ticket_id']);
$ticket_prefix = escapeHtml($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_subject = escapeHtml($row['ticket_subject']);
$ticket_updated = $row['ticket_updated_at'] ?: $row['ticket_created_at'];
?>
<tr>
<td>
<a href="ticket.php?id=<?= $ticket_id ?>"><?= "$ticket_prefix$ticket_number" ?></a>
</td>
<td>
<a href="ticket.php?id=<?= $ticket_id ?>"><?= $ticket_subject ?></a>
</td>
<td><?= ticketPortalStatusHtml($row) ?></td>
<td class="text-nowrap" title="<?= escapeHtml($ticket_updated) ?>"><?= timeAgo($ticket_updated) ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php } ?>
<div class="itflow-portal-page-head">
<div>
<h1>Tickets</h1>
<p><?= $scope === 'all' ? 'Everyone at ' . escapeHtml($session_client_name) : 'The ones you raised' ?></p>
</div>
<div class="col-md-2">
<a href="ticket_add.php" class="btn btn-primary w-100">New ticket</a>
<hr>
<a href="?status=Open" class="btn btn-danger w-100 p-3 mb-3 text-start">My Open tickets | <strong><?= $total_tickets_open ?></strong></a>
<a href="?status=Closed" class="btn btn-success w-100 p-3 mb-3 text-start">Closed tickets | <strong><?= $total_tickets_closed ?></strong></a>
<a href="?status=%" class="btn btn-secondary w-100 p-3 mb-3 text-start">All my tickets | <strong><?= $total_tickets ?></strong></a>
<?php
if ($session_contact_primary == 1 || $session_contact_is_technical_contact) {
?>
<hr>
<a href="ticket_view_all.php" class="btn btn-dark w-100 p-2 mb-3">All Tickets</a>
<?php
}
?>
<div class="d-flex flex-wrap align-items-center gap-2">
<?php if ($sees_all) { ?>
<div class="btn-group" role="group" aria-label="Whose tickets">
<a class="btn btn-outline-secondary<?= $scope === 'all' ? ' active' : '' ?>" href="<?= escapeHtml(ticketsUrl(['scope' => null, 'page' => null])) ?>"><i class="fas fa-users me-2"></i>Everyone</a>
<a class="btn btn-outline-secondary<?= $scope === 'mine' ? ' active' : '' ?>" href="<?= escapeHtml(ticketsUrl(['scope' => 'mine', 'page' => null])) ?>"><i class="fas fa-user me-2"></i>Mine</a>
</div>
<?php } ?>
<form method="get" class="d-flex" role="search">
<input type="hidden" name="tab" value="<?= escapeHtml($tab) ?>">
<?php if ($sees_all && $scope === 'mine') { ?><input type="hidden" name="scope" value="mine"><?php } ?>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-search"></i></span>
<input type="search" class="form-control" name="q" value="<?= escapeHtml($q) ?>" placeholder="Search subject or number" aria-label="Search tickets" maxlength="200">
</div>
</form>
</div>
</div>
<?php require_once "includes/footer.php";
?>
<nav class="itflow-portal-tabs" aria-label="Ticket status">
<?php foreach ($tabs as $key => $t) { ?>
<a class="<?= $key === $tab ? 'active' : '' ?><?= $key === 'you' && $counts['you'] ? ' itflow-portal-tab-alert' : '' ?>" href="<?= escapeHtml(ticketsUrl(['tab' => $key, 'page' => null])) ?>">
<i class="fas <?= $t['icon'] ?>"></i><?= escapeHtml($t['label']) ?>
<span class="badge rounded-pill"><?= $counts[$key] ?></span>
</a>
<?php } ?>
</nav>
<section class="itflow-portal-panel">
<?php if (!$total) { ?>
<?php if ($q !== '') { ?>
<?= emptyStateHtml(['thing' => 'tickets', 'filtered' => true, 'match_text' => 'Nothing here has &ldquo;' . escapeHtml($q) . '&rdquo; in its subject or number.', 'clear_url' => ticketsUrl(['q' => null, 'page' => null])]) ?>
<?php } else {
[$title, $text, $icon] = $empty_titles[$tab]; ?>
<?= emptyStateHtml(['title' => $title, 'text' => $text, 'icon' => $icon, 'filtered' => false,
'actions' => in_array($tab, ['open', 'all'], true) ? [['label' => 'New ticket', 'href' => 'ticket_add.php']] : []]) ?>
<?php } ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php while ($row = mysqli_fetch_assoc($tickets)) {
$updated = $row['ticket_closed_at'] ?: ($row['ticket_updated_at'] ?: $row['ticket_created_at']); ?>
<li>
<a class="itflow-portal-ticket" href="ticket.php?id=<?= intval($row['ticket_id']) ?>">
<span class="itflow-portal-ticket-main">
<span class="itflow-portal-ticket-subject d-block"><?= escapeHtml($row['ticket_subject']) ?></span>
<span class="itflow-portal-ticket-meta">
<span><?= escapeHtml($row['ticket_prefix'] . $row['ticket_number']) ?></span>
<?php if ($scope === 'all' && !empty($row['contact_name'])) { ?>
<span><i class="fas fa-user me-1"></i><?= escapeHtml($row['contact_name']) ?></span>
<?php } ?>
<?php if (!empty($row['category_name'])) { ?>
<span><i class="fas fa-layer-group me-1"></i><?= escapeHtml($row['category_name']) ?></span>
<?php } ?>
<span>Opened <?= escapeHtml(date('M j, Y', strtotime($row['ticket_created_at']))) ?></span>
</span>
</span>
<span class="itflow-portal-ticket-side">
<?= portalTicketStateHtml($row) ?>
<small title="<?= escapeHtml($updated) ?>"><?= $row['ticket_closed_at'] ? 'Closed ' : 'Updated ' ?><?= timeAgo($updated) ?></small>
</span>
</a>
</li>
<?php } ?>
</ul>
<?php if ($pages > 1) { ?>
<div class="itflow-portal-pager">
<span><?= $offset + 1 ?>-<?= min($offset + $per_page, $total) ?> of <?= $total ?></span>
<div class="btn-group">
<a class="btn btn-sm btn-outline-secondary<?= $page <= 1 ? ' disabled' : '' ?>" href="<?= escapeHtml(ticketsUrl(['page' => $page - 1 > 1 ? $page - 1 : null])) ?>" aria-label="Newer"><i class="fas fa-chevron-left"></i></a>
<a class="btn btn-sm btn-outline-secondary<?= $page >= $pages ? ' disabled' : '' ?>" href="<?= escapeHtml(ticketsUrl(['page' => $page + 1])) ?>" aria-label="Older"><i class="fas fa-chevron-right"></i></a>
</div>
</div>
<?php } ?>
<?php } ?>
</section>
<?php require_once "includes/footer.php"; ?>

View File

@@ -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']);

View File

@@ -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;
}

View File

@@ -736,23 +736,6 @@ function ticketActivityHtml($reply, $row) {
. ($who !== '' ? '<div class="small text-body-secondary text-truncate itflow-ticket-who">' . escapeHtml($who) . '</div>' : '');
}
/**
* 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 = '<span class="badge rounded-pill ' . $class . '">' . escapeHtml($row['ticket_status_name'] ?? '') . '</span>';
if (!$closed && !$resolved && ($row['ticket_last_spoke'] ?? null) === 'Public') {
$html .= '<div class="small text-warning-emphasis mt-1"><i class="fas fa-reply me-1"></i>Waiting on your reply</div>';
}
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'],

199
js/portal.js Normal file
View File

@@ -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() && !/<img/i.test(editor.getContent());
if (empty) {
ev.preventDefault();
ev.stopImmediatePropagation();
var holder = editor.getContainer();
holder.classList.add('is-invalid');
var note = form.querySelector('[data-editor-required-note]');
if (note) {
note.hidden = false;
}
editor.focus();
}
}, true);
editor.on('input change', function () {
editor.getContainer().classList.remove('is-invalid');
var note = form.querySelector('[data-editor-required-note]');
if (note) {
note.hidden = true;
}
});
}
});
}
});
}
// ---------- Attachments ----------
function formatSize(bytes) {
if (bytes >= 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);
});
})();