mirror of
https://github.com/itflow-org/itflow
synced 2026-11-30 16:19:00 +00:00
Admin lists on the standard list pattern: Ticket Templates, Roles, API Keys, Taxes, Categories and Tags now have the full-size search with the dark button, Active and Archived pills with counts, sortable table-light column headings, paging through filter_footer.php with records per page, and the btn-light row menu, with old archived=1 links still opening Archived; Ticket Templates sorts by name, tasks, use or last use, gains a Last used column and moves Import, Export, the report and Starter templates onto the New button's split menu; Roles sorts by name with admin roles first, agents or last change; API Keys sorts by name, end date, agent or last use, with Active and Expired pills so a revoked key moves to Expired to be deleted; Taxes sorts by name, rate or use; Categories and Tags keep their kinds in the left nav with the pills beside the list, sort by name or use (and in order for the ordered category kinds), and page in PHP; dragging categories into order and Move up and Move down work on every page (reorder_categories takes offset); bulk actions move to the right of the search row; descriptions wrap so rows and their menus fit on a phone; the help lines above the lists are dropped, with a category kind's purpose on its nav link; apiKeyRows() removed as unused; category and tag redirects use show=archived; changelog updated
This commit is contained in:
27
CHANGELOG.md
27
CHANGELOG.md
@@ -501,7 +501,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Request forms in the client portal: a template can be offered there, under a title, a line about it and an icon of its own - "Onboard a new employee" - to everyone with portal access or the primary and technical contacts only, at every client or the ones you pick. The client answers its fill-ins (a fill-in can be kept for agents to answer instead), adds anything else and any files, and the ticket is raised set up as the template says: category, priority, billing, the agent it goes to (who is told), due time, tags and the tasks for those answers. With [Asset] in the template, the form asks which device. The template's page shows how it appears, who and where it is offered and how many requests it has brought in, and the list marks the ones in the portal. A copy of one starts off not offered.
|
||||
- Export and import: Admin > Ticket Templates exports every current template, the ones picked, or one from its page, as a file to import into another ITFlow or keep. Each goes with its tasks, fill-ins, request form, category and tags - not the agent it goes to or the clients its request form is for. Importing matches categories and tags by name and makes the ones missing, and one already here by name is left as it is, added as well under a name of its own, or replaced - keeping its tickets, its agent and its request form's switch and clients. A request form comes in turned off.
|
||||
- The MSP starter templates in Starter Content are rebuilt on all of this: each asks what it needs (New Hire Onboarding asks the start date, job title, manager, whose access to copy and whether they need a computer or a phone extension), is set up with its category, priority, tags and due time, adds the tasks for the answers given, and the ones clients raise come with a request form - Onboard a new employee, Someone is leaving, Ask for a new computer and Report a suspicious email. Two new ones, Software Request and Access Change Request, have request forms too. An install that added the starter templates before can bring them up to date with Update - their tickets, agent and request form switch stay.
|
||||
- A ticket keeps which template it came from, and its history says so. Admin > Ticket Templates shows what each sets up, its tasks and their time, how many tickets it has raised and the recurring tickets and project templates that raise it. A template's page shows the ticket it starts with its placeholders marked, its tasks (added with their time, dragged into order) and its latest tickets, and New ticket from it opens New Ticket with it filled in.
|
||||
- A ticket keeps which template it came from, and its history says so. Admin > Ticket Templates shows what each sets up, its tasks and their time, how many tickets it has raised and when it was last used, and the recurring tickets and project templates that raise it - searched, sorted by name, tasks, use or last use from the column headings, a page at a time, with Active and Archived tabs. A template's page shows the ticket it starts with its placeholders marked, its tasks (added with their time, dragged into order) and its latest tickets, and New ticket from it opens New Ticket with it filled in.
|
||||
- Templates can be copied, archived - not offered for new tickets, while the recurring tickets and project templates that use them keep them - restored and deleted.
|
||||
- **Assets**
|
||||
- The asset list has:
|
||||
@@ -776,7 +776,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- View as contact: on a contact's page, View portal as them opens the portal in a new tab as they see it, read only - nothing can be sent, paid or changed, opening an invoice doesn't mark it viewed, and a strip along the top says whose view it is, with Exit. It needs read access to clients and support and to the client; billing shows only when your role reads sales and financial too. Each one is in the audit log.
|
||||
- The agent's contact page shows whether a contact signs in with a code too, when they last signed in, and the ticket emails they chose.
|
||||
- **Taxes** (rebuilt)
|
||||
- Admin > Taxes lists each rate with what it comes to, its parts, its registration number and what uses it: the invoices, quotes and recurring invoices with a line at it, and the products and clients that pick it. Current and Archived tabs, with what replaced a rate and when, Restore, Make default, and Delete for a rate nothing has used.
|
||||
- Admin > Taxes lists each rate with what it comes to, its parts, its registration number and what uses it: the invoices, quotes and recurring invoices with a line at it, and the products and clients that pick it. Active and Archived tabs, with what replaced a rate and when, Restore, Make default, and Delete for a rate nothing has used. Sort by name, rate or use from the column headings.
|
||||
- A rate can be made of parts, such as a state's 6% and a county's 1%, or GST and QST. A part can be charged on top of the parts above it. The whole rate shows as you type. Invoices, quotes, their PDFs and the client's views show each part on its own line in the totals, such as Pennsylvania 6% and Allegheny County 1%.
|
||||
- Rates go to four decimal places, such as Quebec's 9.975%, and lines and the Tax Collected report show the exact rate.
|
||||
- Each rate takes a description and a registration number, and each part can have its own number. The numbers a document charges under print with your company's details on the invoice or quote and its PDF, such as GST No. 123456789 RT0001.
|
||||
@@ -799,7 +799,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Demo data: both taxes have a registration number, Allegheny County Sales Tax is made of the state's 6% - named PA Sales Tax, so Tax Collected adds the two up together - and the county's 1%, each client has its rate, the church and the charter school are tax exempt, one with a certificate that has run out, and what the company buys for its own use pays sales tax.
|
||||
- **Tags** (rebuilt)
|
||||
- Admin > Tags lists each kind's tags - clients, locations, contacts, credentials, assets, vendors, domains, licenses, services, networks, documents and tickets, down the side with how many each has. Each tag shows as it looks on a record, with its description, how many records have it (and how many of those are archived), opening that list filtered by it, and the recurring invoice lines that count users or devices by it.
|
||||
- Search by name or description, sort by name or by most used, and Current and Archived tabs.
|
||||
- Search by name or description, sort by name or by how many records have each from the column headings, a page at a time, and Active and Archived tabs.
|
||||
- Each tag has Edit, Merge into..., a link to its records, Archive or Restore, and Delete, which asks first and says how many records lose the tag. Tick several for Merge into one, Archive or Restore, and Delete.
|
||||
- The tag window shows the tag as it will look while you change it:
|
||||
- its name, and what it is for, which can be changed while nothing has the tag yet
|
||||
@@ -819,9 +819,9 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- API: read the tags, one record's tags or the records with a tag, set a record's tags or add and take some off, and make a tag (admin keys only). Every record read now includes its tags.
|
||||
- Starter Content: the Tags pack has tags for licenses, services, networks, documents and tickets - We Resell, Managed, PCI, Runbook, Escalated and so on. Demo data tags its licenses, services, documents and tickets with them.
|
||||
- **Categories** (rebuilt)
|
||||
- Admin > Categories lists each kind - expense, income, referral, ticket, network interface, asset status, software type, rack type, and contact and asset note types - down the side with how many each has, and says under the heading what the kind is for.
|
||||
- Admin > Categories lists each kind - expense, income, referral, ticket, network interface, asset status, software type, rack type, and contact and asset note types - down the side with how many each has, and what each kind is for when you point at it.
|
||||
- Each category shows as it looks on records - its icon, or a dot, in its color, and an asset status as its badge - with its description and what uses it, such as "42 expenses · 3 recurring expenses · 24 budget months" (and how many of those are archived). Each opens its list filtered by the category where there is one: expenses, recurring expenses, invoices, other income, products, tickets, recurring tickets, and clients by referral.
|
||||
- Search by name or description, sort by name or by most used, and Current and Archived tabs. The kinds offered in an order of their own - interface types, asset statuses, software types, rack types and note types - list in that order first, and are dragged into it, or moved with Move up and Move down.
|
||||
- Search by name or description, sort by name or by what uses each most from the column headings, a page at a time, and Active and Archived tabs. The kinds offered in an order of their own - interface types, asset statuses, software types, rack types and note types - list in that order first (in order, next to the column heading, puts them back in it), and are dragged into it, or moved with Move up and Move down - on any page, the first of a page moving up past the last of the one before.
|
||||
- Each category has Edit, Merge into..., Archive or Restore, and Delete while nothing uses it - otherwise Delete is greyed out and says what uses it. Tick several for Merge into one, Archive or Restore, and Delete, which keeps the ones in use and says which.
|
||||
- The category window shows it as it will look while you change it:
|
||||
- its name and a description, shown when you point at it
|
||||
@@ -842,7 +842,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Admin > Categories links what uses a category to these lists filtered by it too: quotes, recurring invoices, assets, licenses and racks.
|
||||
- API: read the categories - every kind the key can see, one kind, one by id or by name, archived ones too - with how many records have each.
|
||||
- **Roles** (rebuilt)
|
||||
- Admin > Roles shows what each role opens at a glance - its level of each part of ITFlow in that level's color, or Admin - everything - and its agents, opening Users filtered to them. Search, and Current and Archived tabs.
|
||||
- Admin > Roles shows what each role opens at a glance - its level of each part of ITFlow in that level's color, or Admin - everything - and its agents, opening Users filtered to them. Search, sort by name, agents or when it was last changed, and Active and Archived tabs.
|
||||
- New, Edit and Copy are one window. Admin is a switch; otherwise each part of ITFlow - Clients, Support, Credentials, Sales, Financial and Reports - gets None, Read, Modify or Full, with a line for each level saying what it lets them do, ticked as you pick. Reports only has None and Read, all it uses. A change reaches the role's agents from the next page they open.
|
||||
- Copy starts a new role from another's levels.
|
||||
- Archive a role nobody has to stop it being given out, and Restore it. Delete one no agent has, archived ones included. Archive and Delete are greyed out with the reason when they can't be used.
|
||||
@@ -859,7 +859,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Accounting is the Accountant's job: with Financial and Sales at Read, a role can take payments - one, a saved card or a batch - change them and email receipts, reminders and statements, and with full access to Financial delete and refund them (see Breaking Changes, Roles). The invoice, the invoice list, Income and the payment quick looks offer what the role can do, and the reminder window offers only the reminder to a role that can't send the invoice itself. The built-in Accountant role now has full access to Financial.
|
||||
- Calendar events follow the role, through the client they are for (see Breaking Changes, Roles). A role that can't add to a client's calendar isn't offered New event there, or a client in the event window, which says why, and its events can't be dragged.
|
||||
- **API Keys** (rebuilt)
|
||||
- Admin > API Keys shows, for each key, the agent it acts as and their role, what it can open and for which clients, whether it works and when it was last used. Whether it works reads Works until a day, Expires in so many days in its last two weeks, Expired, or Won't work with why: its agent is disabled, archived or has no role, or it acts as nobody. Search finds keys by their name or their agent's.
|
||||
- Admin > API Keys shows, for each key, the agent it acts as and their role, what it can open and for which clients, whether it works and when it was last used. Whether it works reads Works until a day, Expires in so many days in its last two weeks, Expired, or Won't work with why: its agent is disabled, archived or has no role, or it acts as nobody. Search finds keys by their name or their agent's, and they sort by name, end date, agent or last use. Active and Expired tabs - a revoked key moves to Expired, where it can be deleted.
|
||||
- The New API Key and Edit windows show what the picked agent can open as you pick them, and offer only active agents. A new key lasts a year unless you change it, and its last day has to be after today. An expired key can be renamed and stays expired; a later day brings it back.
|
||||
- Create on the Details tab before ticking that the key and password were copied opens the Key tab, rather than doing nothing.
|
||||
- Revoke ends a key today. Delete is for expired keys, as before, one at a time or several from the bulk menu.
|
||||
@@ -1351,7 +1351,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- The new `functions/tax.php` (loaded after `billing_pay.php`): `taxSettings()`, `taxRow($tax_id)` (cached, with `components` - name, percent, compound, registration - and `grouped`) and `taxForget()`, `taxPercentText()`, `taxLabel()`, `taxEffectivePercent($components)`, `taxAmounts($base, $tax)` (`tax` and `parts` - label, name, percent, amount, registration, registration_for - each part to the cent), `taxCurrent($tax_id)` (follows `tax_replaced_by` to a current rate, else 0), `taxClient($client_id)`, `taxClientSetSql($in, $current)`, `taxExemptText($client, $with_expiry)`, `taxDocWarning($type, $doc_id, $client_id, $items, $open, $can_edit)`, `taxDefaultFor($client_id, $kind, $product_tax_id)` (`goods`, `time`, `trip`, `expense`, `product`), `TAX_USUAL` (-1) and `taxChoice($input, $client_id, $kind)`, `taxUsage()`, `taxUsageAll()`, `taxBilled($tax_id)` (on an invoice or quote past draft), `taxFromInput($in)`, `taxSameRate()`, `taxCreate()`, `taxUpdate($tax_id, $fields, $move_drafts)`, `taxChangeRate()`, `taxRepoint($from, $to, $move_drafts)`, `taxDocIds($type, $tax_id)`, `taxRecalcOpen()`, `taxArchive($tax_id, $move_to)`, `taxRestore()`, `taxUnused()`, `taxDelete()`, `taxSetDefault()`, `taxMovedText()`, `taxOptionsHtml($taxes, $selected, $usual_label, $usual_percent)` and `taxSelectOptions()`.
|
||||
- `functions/billing.php`: `billingLineTax($quantity, $price, $tax_id, $base)`, `billingLinesOpen($type, $status)`, `billingDiscountShares($items, $discount)` (by subtotal, to the cent, largest remainder), `billingRecalcTaxes($type, $doc_id, $discount)`, `billingTaxParts($items)`, `billingRemoveTax($type, $doc_id)` and `billingTaxRegistrationLines($totals)`. `billingRecalc()` works each line's tax out again while its lines can change - on a quote, the discount comes off the one-time group, else the first recurring one. `billingTotals()` `taxes` are by part, with `tax_registrations` added, and `quoteLineGroups()` the same per group. `billingBillTo()` adds `tax_exempt_text`. `recurringInvoiceRefresh()` updates quantities and subtotals and leaves the tax to `billingRecalc()`. `billingItemSave()` checks the rate exists. `billingTimeInvoice()`, `expenseBillInvoice()` and `tripBillInvoice()` take `TAX_USUAL`.
|
||||
- `getProductsForAutocomplete($mysqli, $client_id)` gives each product's `tax` and `tax_percent` for that client. The line windows, the add-a-line row, Unbilled Time and the ticket Invoice and Quote windows build their tax select with `taxOptionsHtml()`.
|
||||
- Admin: `admin/tax_rates.php` is rebuilt, with `admin/modals/tax/tax_form.php` shared by `tax_add.php` and `tax_edit.php`, the new `tax_archive.php`, and `js/tax_form.js`. `admin/post/tax.php`: `add_tax` (`name`, `description`, `registration`, `percent`, or `part_name[key]`, `part_percent[key]`, `part_compound[key]` and `part_registration[key]`; `make_default`), `edit_tax` (`tax_id`, `drafts_asked`, `move_drafts`), `archive_tax` (now POST, `tax_id`, `move_to`), GET `restore_tax`, `default_tax` and `delete_tax`, and `edit_tax_settings` (`default_tax_id`, `tax_time`, `tax_trips`, `tax_expenses`, `tax_discount_before`).
|
||||
- Admin: `admin/tax_rates.php` is rebuilt (`q`, `sort` - `tax_name`, `tax_percent` or `invoice_count` - `order`, `page` and `show=archived`, `archived=1` still taken), with `admin/modals/tax/tax_form.php` shared by `tax_add.php` and `tax_edit.php`, the new `tax_archive.php`, and `js/tax_form.js`. `admin/post/tax.php`: `add_tax` (`name`, `description`, `registration`, `percent`, or `part_name[key]`, `part_percent[key]`, `part_compound[key]` and `part_registration[key]`; `make_default`), `edit_tax` (`tax_id`, `drafts_asked`, `move_drafts`), `archive_tax` (now POST, `tax_id`, `move_to`), GET `restore_tax`, `default_tax` and `delete_tax`, and `edit_tax_settings` (`default_tax_id`, `tax_time`, `tax_trips`, `tax_expenses`, `tax_discount_before`).
|
||||
- Clients: `agent/modals/client/client_tax_fields.php` on the Billing tab of `client_add.php` and `client_edit.php` posts `tax_fields`, `default_tax_id`, `tax_exempt`, `tax_exempt_number` and `tax_exempt_expires`, saved by `agent/post/client.php` through `taxClientSetSql()`. `api/v1/clients/client_model.php` does the same from the API fields. GET `billing_remove_tax` (the document's id, `type`) in `agent/post/billing.php`, at Sales 2.
|
||||
- `api/v1/invoice_items/create.php` takes `tax_id` `default` (a product's line by `taxDefaultFor()` with `product`) and works the invoice out again with `billingRecalc()`.
|
||||
- Seeds: `demoDataTaxes()` rows add a description, registration number and parts, demo clients get `client_default_tax_id`, and a profile's `tax_exempt` (number, expiry) makes it exempt. `demoDataRemove()` counts clients using a rate and removes its parts.
|
||||
@@ -1370,7 +1370,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- `tagSetForRecord()` is the one save for a record form's `tags[]`: numeric values are tag ids, anything else (from an admin) a typed name, matched case-insensitively or made with `tagNextColor()`. Only that kind's tags are kept, each once, and an archived tag only on a record that already had it. `agent/post/client.php`, `contact.php` and `asset.php` call it, and `locationSetTags()`, `credentialSetTags()`, `vendorSetTags()` and `domainSetTags()` now wrap it.
|
||||
- The record forms' Tags fields are `<?= tagOptionsHtml($entity, $selected) ?>` with `data-tags="true"` for admins, and their links to `admin/modals/tag/tag_add.php` are gone. The list pages' tag filters and the seven export windows leave out archived tags that aren't chosen.
|
||||
- `tagPills()` and `tagPill()` set `--itflow-tag-text` beside `--itflow-tag-color`, and a pill's title leads with the description. `agent/ajax.php`: `tag_picker` returns each tag's `description` (with "Archived"), `tag_picker_set` refuses putting an archived tag on (409), and `tag_picker_create` matches case-insensitively and restores an archived match. `js/tag_picker.js` shows and searches the description.
|
||||
- Admin: `admin/tags.php` is rebuilt (`type`, `q`, `sort=use`, `archived`), with `admin/modals/tag/tag_form.php` shared by `tag_add.php` (`type`) and `tag_edit.php` (`id`), the new `tag_merge.php` (`tag_ids[]`), and `js/tag_form.js`. `admin/post/tag.php`: `add_tag` and `edit_tag` (`tag_id`, `name`, `type`, `description`, `color`, `icon`), GET `archive_tag`, `restore_tag` and `delete_tag`, POST `merge_tags` (`tag_ids[]`, `into_tag_id`), and `bulk_archive_tags`, `bulk_restore_tags` and `bulk_delete_tags` (`tag_ids[]`). Audit entries are Tag Create, Edit, Archive, Restore, Delete and Merge, naming the kind.
|
||||
- Admin: `admin/tags.php` is rebuilt (`type`, `q`, `sort` - `tag_name` or `used` - `order`, `page` and `show=archived`, `archived=1` still taken; sorted and paged in PHP), with `admin/modals/tag/tag_form.php` shared by `tag_add.php` (`type`) and `tag_edit.php` (`id`), the new `tag_merge.php` (`tag_ids[]`), and `js/tag_form.js`. `admin/post/tag.php`: `add_tag` and `edit_tag` (`tag_id`, `name`, `type`, `description`, `color`, `icon`), GET `archive_tag`, `restore_tag` and `delete_tag`, POST `merge_tags` (`tag_ids[]`, `into_tag_id`), and `bulk_archive_tags`, `bulk_restore_tags` and `bulk_delete_tags` (`tag_ids[]`). Audit entries are Tag Create, Edit, Archive, Restore, Delete and Merge, naming the kind.
|
||||
- Removed: `agent/post/tag.php` and `agent/post/tag_model.php` (an older copy of `add_tag` for the window opened from agent pages), and `admin/post/tag_model.php`.
|
||||
- `agent/modals/billing/billing_item.php` adds a seat line's own tag to its choices when `recurringSeatOptions()` leaves it out.
|
||||
- CSS: `.itflow-tag` takes its text color from `--itflow-tag-text`; new `.itflow-tag-swatch`, `.itflow-tag-icons`, `.itflow-tag-icon` and `.itflow-tag-icon-custom`.
|
||||
@@ -1386,7 +1386,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Categories (database 3.1.5):
|
||||
- The migration writes every `category_color` as `#rrggbb` - short hex grows, an eight-digit one loses its alpha, the 148 CSS color words become their own hex, anything else NULL - and every `category_icon` as `fa-` and the name (`fas fa-`, markup and anything but `a-z0-9-` taken off, NULL when empty), leaving `category_updated_at` alone. No column changes; `setup/seed_data.php` writes hex colors.
|
||||
- New `functions/categories.php`, loaded by `functions.php`: `categoryKinds()` - each `category_type` with `label`, `one`, `many`, `icon`, `about`, `by` (`id` or `name`), `ordered`, `max` (name length), and `uses` (`table`, `column`, `one`, `many`, `url` with `{id}` or `{name}`, `archived` and `updated` columns, and `text` for an id kept as text, `tickets.ticket_category` and `recurring_tickets.recurring_ticket_category`). Also `categoryKind()` (adds `kind`), `categoryKindPhrase()`, `categoryUseText()`, `CATEGORY_COLORS`, `CATEGORY_ICONS`, `categoryColor()` (`#rrggbb` or `''`), `categoryIcon()` (the bare name or `''`), `categoryNextColor()`, `categoryChip($row)`, `categoryRow()`, `categoryRows($kind)` (in picker order), `categoryNameKey()`, `categoryUsage($kind)` (id => `all`, `archived`, `uses`), `categoryLooseNames($kind)`, `categoryUsageFor()`, `categoryUsageHtml()`, `categoryUsageText()`, `categoryFromInput($in, $existing)` (`[$fields, $error]`: `type`, `name`, `description`, `color`, `icon`), `categorySetSql()`, `categoryCreate()` (last in the order), `categoryUpdate($row, $fields)` (renames a by-name kind on its records; returns how many), `categoryMoveRecords($config, $where_sql, $to_sql)` (keeps each record's `*_updated_at`), `categoryArchive()`, `categoryRestore()`, `categoryDeleteBlocker($row, $used)`, `categoryDelete($id, &$error)`, `categoryMerge($from_ids, $into_id)` (same kind; returns records moved), `categoryFoldBudget()` and `categoryReorder($kind, $ids)`.
|
||||
- Admin: `admin/categories.php` is rebuilt (`category`, `q`, `sort` - `order`, `name` or `use` - and `archived`; no paging), with `admin/modals/category/category_form.php` shared by `category_add.php` (`category`, or none to pick the kind) and `category_edit.php` (`id`), the new `category_merge.php` (`category_ids[]`), and `js/category_form.js`. `admin/post/category.php`: `add_category` and `edit_category` (`category_id`, `type`, `name`, `description`, `color`, `icon`), GET `archive_category`, `restore_category`, `delete_category` and `move_category` (`direction` `up` or `down`), POST `merge_categories` (`category_ids[]`, `into_category_id`), `reorder_categories` (`category`, `category_ids[]`; answers JSON), and `bulk_archive_categories`, `bulk_restore_categories` and `bulk_delete_categories` (`category_ids[]`). Audit entries are Category Create, Edit, Archive, Restore, Delete and Merge, naming the kind.
|
||||
- Admin: `admin/categories.php` is rebuilt (`category`, `q`, `sort` - `category_order`, `category_name` or `used` - `order`, `page` and `show=archived`, `archived=1` still taken; sorted and paged in PHP, as what uses each is counted there), with `admin/modals/category/category_form.php` shared by `category_add.php` (`category`, or none to pick the kind) and `category_edit.php` (`id`), the new `category_merge.php` (`category_ids[]`), and `js/category_form.js`. `admin/post/category.php`: `add_category` and `edit_category` (`category_id`, `type`, `name`, `description`, `color`, `icon`), GET `archive_category`, `restore_category`, `delete_category` and `move_category` (`direction` `up` or `down`), POST `merge_categories` (`category_ids[]`, `into_category_id`), `reorder_categories` (`category`, `category_ids[]` - a page of the current ones - and `offset`, how many come before them; answers JSON), and `bulk_archive_categories`, `bulk_restore_categories` and `bulk_delete_categories` (`category_ids[]`). Audit entries are Category Create, Edit, Archive, Restore, Delete and Merge, naming the kind.
|
||||
- Removed: `agent/post/category.php` (the + window posts to `admin/post.php` from any page), and `admin/post/category_model.php` and `agent/post/category_model.php`.
|
||||
- Pickers: `categoryPicker($kind, $keep, $opts)` - the current ones in the kind's order plus `$keep` (ids, or names for a kind held by name) even when archived, a kept name that is no category as a row with `loose` and no id, keyed by the value posted; `$opts` `since` (also those archived after then) and `exclude` (names). `categoryOptionHtml($row, $selected)` (`data-color` - an asset status's badge color, `data-icon` - a software type's icon from its name when it has none, `data-description`, and "(archived)" or "(not set up)"), `categoryOptionsHtml($kind, $selected, $opts)`. `expenseCategories()`, `incomeCategories()` and `billingCategories($since, $keep_id)` return `categoryPicker()`. Every record form and Bulk Action window that picks a category writes its options with `categoryOptionsHtml()`.
|
||||
- The +: `categoryAddButtonHtml($kind, $class)` - admins only, opening `admin/modals/category/category_add.php?category=&inline=1`, marked `data-category-add`. `js/app.js` notes the picker beside it in `window.itflowCategoryTarget`; `js/category_form.js` posts the inline window with fetch, and `add_category` with `inline` answers JSON - `ok`, `value`, `option` (the picker's `<option>`, selected) and `message`, or `ok` false and `error`. Without `inline` it goes back to the page it came from, or to the kind in Admin > Categories. The category windows post to `/admin/post.php`.
|
||||
@@ -1404,7 +1404,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- The migration deletes `user_role_permissions` rows of a role or module that is gone or of level 0 or less, keeps the highest level (held to 3) where a role has a module twice, and adds `PRIMARY KEY (user_role_id, module_id)`.
|
||||
- `lookupUserPermission()` reads the session role's levels in one query and keeps them for the request (a `static`, keyed by role). It still returns `3` for an admin and `false` for none.
|
||||
- New `functions/roles.php`, loaded by `functions.php`: `ROLE_LEVELS`, `ROLE_LEVEL_TONES`, `roleModuleInfo()` (by `module_name`: `label`, `icon`, `about`, `levels` - what each adds - and `max`), `roleModules()` (`module_id` => that, from the `modules` table, a module it doesn't know named from its row), `roleLevels($role_ids)`, `roleRows($archived)` (with `levels`, `agents` and `agents_archived`), `roleRow()`, `roleAgents($role_ids, $limit)`, `roleAccessHtml($row)`, `roleFromInput($in, $role_id)` (`[$fields, $error]`: `name`, `description`, `admin`, `levels`), `roleAdminBlocker()`, `roleArchiveBlocker()`, `roleDeleteBlocker()`, `roleChangeText($before, $fields)`, `roleSave($fields, $role_id)` (an admin role keeps its levels), `roleSetArchived()` and `roleDelete()`.
|
||||
- Admin: `admin/roles.php` is rebuilt (`q`, `archived`; no paging or sorting). `admin/modals/role/role_form.php` is shared by `role_add.php` (`copy` - a role to start from) and `role_edit.php` (`id`), with `js/role_form.js`. `admin/post/roles.php`: `add_role` and `edit_role` (`role_id`, `name`, `description`, `admin`, `levels[module_id]` 0 to 3 - the old `role_name`, `role_description`, `role_is_admin` and `module_id##module_name` fields are gone), and GET `archive_role`, `restore_role` and `delete_role`. Audit entries are User Role Create, Edit (with what changed), Archive, Restore and Delete.
|
||||
- Admin: `admin/roles.php` is rebuilt (`q`, `sort` - `role_name`, `agents` or `role_updated_at` - `order`, `page` and `show=archived`, `archived=1` still taken). `admin/modals/role/role_form.php` is shared by `role_add.php` (`copy` - a role to start from) and `role_edit.php` (`id`), with `js/role_form.js`. `admin/post/roles.php`: `add_role` and `edit_role` (`role_id`, `name`, `description`, `admin`, `levels[module_id]` 0 to 3 - the old `role_name`, `role_description`, `role_is_admin` and `module_id##module_name` fields are gone), and GET `archive_role`, `restore_role` and `delete_role`. Audit entries are User Role Create, Edit (with what changed), Archive, Restore and Delete.
|
||||
- The hard-coded `role_id !== 3` checks on the roles page are gone; the guards are `roleAdminBlocker()` and the archive and delete blockers.
|
||||
- CSS: `.itflow-role-agents` and `.itflow-role-level-list`.
|
||||
- Refusals: `enforceUserPermission()` and `enforceAdminPermission()` go through `permissionRefuse($message)` in `functions/auth.php`. It answers a window (`ITFLOW_MODAL`, now defined by `includes/modal_header.php`) with its own JSON `content`, `ajax.php` with a 403 and `{ok: false, error}`, a handler or a page that hasn't drawn anything yet with `flashAlert()` and `redirect(permissionBackUrl())`, and a page already drawing with a `.itflow-refused` card and the footer. Also `permissionRefusedText($module, $level, $has)`, `permissionRoleName()` and `permissionBackUrl()` (the referrer on this host unless it is this page, else the dashboard). The session alert is no longer set before the old `exit`. `WORDING_ROLECHECK_FAILED` is kept but no longer used.
|
||||
@@ -1414,8 +1414,8 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- The role window marks each module `data-role-module="module_name"` and has `data-role-needs-clients`; the user form has a `data-user-role-access` block per role.
|
||||
- API Keys (database 3.1.7):
|
||||
- The migration adds `api_keys.api_key_last_used_at` (DATETIME, null). `api/v1/validate_api_key.php` sets it on a call that gets past the key check, at most once a minute, in `config_timezone`, as the API doesn't set PHP's or MySQL's clock to it.
|
||||
- New `functions/api_keys.php`, loaded by `functions.php`: `apiKeyRows($search)` and `apiKeyRow($id)` (the key with its agent's `user_name`, `user_avatar`, `user_type`, `user_status`, `user_archived_at` and `user_role_id`), `apiKeyExpired($row)`, `apiKeyAgentProblem($row, $role)`, `apiKeyStatePill($row, $role)`, `apiKeyAgents()` (active agents), `apiKeyFromInput($in, $current_expire)` (`[$fields, $error]`: `name`, `expire`, `user_id`) and `apiKeyAgentFieldHtml($selected)` (the `run_as_user` picker, with a `data-api-key-access` block per agent).
|
||||
- Admin: `admin/api_keys.php` is rebuilt (`q`; no paging or sorting). `admin/post/api_keys.php`: `add_api_key` (`name`, `expire`, `run_as_user`, `key` - 32 of `A-Za-z0-9_-` - and `password`), `edit_api_key` (`api_key_id`, `name`, `expire`, `run_as_user`), GET `revoke_api_key` (`api_key_expire` to today) and `delete_api_key`, and `bulk_delete_api_keys` (`api_key_ids[]`). Each checks the key exists, and add and edit take an active agent only. Audit entries are API Key Create, Edit (with what changed, and only when something did), Revoke and Delete, each linked to its key. The Bulk Delete summary entry is gone, as each key logs its own Delete.
|
||||
- New `functions/api_keys.php`, loaded by `functions.php`: `apiKeyRow($id)` (the key with its agent's `user_name`, `user_avatar`, `user_type`, `user_status`, `user_archived_at` and `user_role_id`), `apiKeyExpired($row)`, `apiKeyAgentProblem($row, $role)`, `apiKeyStatePill($row, $role)`, `apiKeyAgents()` (active agents), `apiKeyFromInput($in, $current_expire)` (`[$fields, $error]`: `name`, `expire`, `user_id`) and `apiKeyAgentFieldHtml($selected)` (the `run_as_user` picker, with a `data-api-key-access` block per agent).
|
||||
- Admin: `admin/api_keys.php` is rebuilt (`q`, `sort` - `api_key_name`, `api_key_expire`, `user_name` or `api_key_last_used_at` - `order`, `page` and `show=expired`). `admin/post/api_keys.php`: `add_api_key` (`name`, `expire`, `run_as_user`, `key` - 32 of `A-Za-z0-9_-` - and `password`), `edit_api_key` (`api_key_id`, `name`, `expire`, `run_as_user`), GET `revoke_api_key` (`api_key_expire` to today) and `delete_api_key`, and `bulk_delete_api_keys` (`api_key_ids[]`). Each checks the key exists, and add and edit take an active agent only. Audit entries are API Key Create, Edit (with what changed, and only when something did), Revoke and Delete, each linked to its key. The Bulk Delete summary entry is gone, as each key logs its own Delete.
|
||||
- API: `api/v1/roles/read.php` (GET; `role_id`, `archived`, `limit`, `offset`) answers `role_id`, `role_name`, `role_description`, `role_is_admin`, `role_levels` (`module_name` => 0 to 3), `role_agents`, `role_created_at`, `role_updated_at` and `role_archived_at`. A key whose user isn't an admin gets only `$session_user_role`. `enforce_api_rbac.php` maps `roles` to `''`. `api/v1/technicians/read.php` (GET, `module_support`; `technician_id`, `archived`, `limit`, `offset`) answers `technician_id`, `technician_name`, `technician_email`, `technician_status`, `role_id`, `role_name`, `role_is_admin`, `technician_created_at` and `technician_archived_at`.
|
||||
- `enforce_api_rbac.php`: `apiPermissionText($module, $level)` words the module refusal, and `$operation_level` maps `time.php` to 1.
|
||||
- Payments, calendar events and the API's clock (database 3.1.8):
|
||||
@@ -1451,6 +1451,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
|
||||
- Export and import: new `functions/ticket_template_transfer.php` - `ticketTemplatesExport($ids, $archived)` (the file's contents: `format` itflow-ticket-templates, `version` 1, `templates`), `ticketTemplatesExportFileName()`, `ticketTemplatesImportRead($contents, &$error)` (checks and tidies a file - details through `documentHtmlPurify()` - and takes the starter pack's array the same way), `ticketTemplatesImport($templates, $existing, $only_existing)` (`skip`, `copy` or `replace`; categories through `categoryFromInput()`/`categoryCreate()`, tags through `tagCreate()`) and `ticketTemplatesImportSummary()`. Handlers `export_ticket_templates` (POST, `ticket_template_ids[]` and `archived`), `export_ticket_template` (GET, one) and `import_ticket_templates`, with `ticket_template_export.php` and `ticket_template_import.php` windows.
|
||||
- Starter Content: `starterContentTicketTemplates()` is written in the file format and `starterLoadTicketTemplates()` loads it through `ticketTemplatesImport()`; new `starterUpdateTicketTemplates()` and the `update_starter_ticket_templates` handler replace the ones already here.
|
||||
- Report: `agent/reports/ticket_templates.php`, `ticket_templates` in `reportCatalog()` under Service Desk.
|
||||
- `admin/ticket_templates.php` takes `q`, `sort` - `ticket_template_name`, `task_count`, `used_count` or `last_used` - `order`, `page` and `show=archived` (`archived=1` still taken); its use is counted in the query, as `ticketTemplateUsage()` counts it.
|
||||
- Database 3.2.1: request forms. `ticket_templates` gains `ticket_template_portal`, `ticket_template_portal_title`, `ticket_template_portal_description`, `ticket_template_portal_icon` (one of `TICKET_TEMPLATE_PORTAL_ICONS`), `ticket_template_portal_who` (`everyone` or `managers`) and `ticket_template_portal_all_clients`; new `ticket_template_portal_clients` (cascading with the template and the client). `fill_in_client`, `ticket_fill_in_client` and `recurring_ticket_fill_in_client` say whether the client is asked a fill-in and sees its answer (default yes).
|
||||
- Request forms: `ticketTemplatePortalForms($client_id, $manager)` and `ticketTemplatePortalForm()` (what a contact may use - `$manager` is `portalSeesAllTickets()`), `ticketTemplatePortalTitle()`, `ticketTemplatePortalIcon()`, `ticketTemplateMentionsAsset()`, `ticketTemplatePortalAnswers()` (the client's answers checked, the agents' left blank), `ticketTemplatePortalRaise()` and `ticketTemplatePortalRequests($ids)`; `ticketTemplatePortalClientIds()` and `ticketTemplateSetPortalClients()`. `ticketTemplateFields()` and `ticketTemplateSave()` take the portal fields, and `ticketTemplateFinish()` takes the history line. `client/ticket_add.php` takes `?form=` (`problem` for the usual form) and posts `add_ticket_from_form` to `client/post.php`; its What happens next is `client/includes/ticket_next_steps.php`. `[Agent]` is no longer filled in with a client's name for a ticket raised in the portal with no agent - only an agent who raised it counts.
|
||||
- `inc_ticket_template_select.php` draws a `[data-fill-ins-box]` under the picker (`$ticket_template_fill_in_values` starts it with answers) and the options carry `data-template-fill-ins`; `ticket_tasks_modal.js` draws the fields, hides and disables the task rows for other answers, and binds its document listeners once (a window flag). `js/app.js` opens the tab of a required field left empty on a hidden tab (a capturing `invalid` listener).
|
||||
|
||||
@@ -5,16 +5,59 @@
|
||||
* an agent, so each shows who, what their role opens and which clients
|
||||
* they see, whether the key works (it expires, and an agent who is
|
||||
* disabled, archived or has no role turns every call away) and when it was
|
||||
* last used. The work is in functions/api_keys.php; the handlers are
|
||||
* last used. A revoked key has expired, so it moves to Expired, where it can
|
||||
* be deleted. The work is in functions/api_keys.php; the handlers are
|
||||
* admin/post/api_keys.php.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "api_key_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$search = trim((string) ($_GET['q'] ?? ''));
|
||||
$keys = apiKeyRows($search);
|
||||
$show_expired = ($_GET['show'] ?? '') === 'expired';
|
||||
|
||||
// Only these sort - an unknown column would take the page down
|
||||
$sortable_columns = [
|
||||
'api_key_name' => "api_key_name $order",
|
||||
'api_key_expire' => "api_key_expire $order, api_key_name ASC",
|
||||
'user_name' => "user_name IS NULL, user_name $order, api_key_name ASC",
|
||||
'api_key_last_used_at' => "api_key_last_used_at IS NULL, api_key_last_used_at $order, api_key_name ASC",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'api_key_name';
|
||||
}
|
||||
|
||||
// It works until the start of its expiry date - as apiKeyExpired() has it
|
||||
$today = date('Y-m-d');
|
||||
$search = "(api_key_name LIKE '%$q%' OR user_name LIKE '%$q%')";
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS api_key_id, api_key_name, api_key_secret, api_key_created_at, api_key_expire, api_key_user_id, api_key_last_used_at,
|
||||
user_name, user_avatar, user_type, user_status, user_archived_at, user_role_id
|
||||
FROM api_keys
|
||||
LEFT JOIN users ON user_id = api_key_user_id
|
||||
WHERE $search AND api_key_expire " . ($show_expired ? '<=' : '>') . " '$today'
|
||||
ORDER BY {$sortable_columns[$sort]}, api_key_id ASC
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$keys = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$keys[intval($row['api_key_id'])] = $row;
|
||||
}
|
||||
$roles = roleRows();
|
||||
$access = userClientAccess(array_filter(array_map('intval', array_column($keys, 'api_key_user_id'))));
|
||||
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(api_key_expire > '$today'), 0), COALESCE(SUM(api_key_expire <= '$today'), 0)
|
||||
FROM api_keys LEFT JOIN users ON user_id = api_key_user_id WHERE $search"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
?>
|
||||
@@ -26,55 +69,64 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/api/api_key_add.php"><i class="fas fa-plus me-2"></i>New API Key</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-2 border-bottom">
|
||||
<p class="small text-secondary mb-2">A key lets another system use ITFlow's API as one of your agents - it can do what their <a href="roles.php">role</a> allows, for the clients they see, until it expires.</p>
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<div class="input-group input-group-sm w-auto me-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search keys and agents">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-1"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<button class="dropdown-item text-danger text-bold confirm-link" type="submit" form="bulkActions" name="bulk_delete_api_keys"
|
||||
data-confirm-title="Delete these keys?" data-confirm-text="Anything using them stops working." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<?php if ($show_expired) { ?><input type="hidden" name="show" value="expired"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-5">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search API keys..." title="Key name or the agent it acts as">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<button class="dropdown-item text-danger text-bold confirm-link" type="submit" form="bulkActions" name="bulk_delete_api_keys"
|
||||
data-confirm-title="Delete these keys?" data-confirm-text="Anything using them stops working." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_expired ? '' : 'active' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '']))) ?>"><i class="fas fa-fw fa-key me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_expired ? 'active' : '' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => 'expired']))) ?>" title="Expired or revoked - nothing can use them"><i class="fas fa-fw fa-ban me-1"></i>Expired <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($keys) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3" style="width: 1%">
|
||||
<div class="form-check mb-0">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all">
|
||||
</div>
|
||||
</th>
|
||||
<th>Key</th>
|
||||
<th class="d-none d-md-table-cell">Acts as</th>
|
||||
<th class="d-none d-lg-table-cell">Can open</th>
|
||||
<th class="d-none d-sm-table-cell">Last used</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="checkbox-column border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all on this page">
|
||||
</div>
|
||||
</th>
|
||||
<th><?= $sort_link('api_key_name', 'Key') ?> <span class="fw-normal text-body-secondary small ms-2"><?= $sort_link('api_key_expire', 'by expiry') ?></span></th>
|
||||
<th class="d-none d-md-table-cell"><?= $sort_link('user_name', 'Acts as') ?></th>
|
||||
<th class="d-none d-lg-table-cell">Can open</th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('api_key_last_used_at', 'Last used') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($keys as $api_key_id => $row) {
|
||||
$name = escapeHtml($row['api_key_name']);
|
||||
$role = $roles[intval($row['user_role_id'])] ?? null;
|
||||
$expired = apiKeyExpired($row);
|
||||
$agent_name = trim(str_replace(' (archived)', '', (string) $row['user_name']));
|
||||
$last_used = $row['api_key_last_used_at'] ? '<span title="' . escapeHtml($row['api_key_last_used_at']) . '">' . escapeHtml(timeAgo($row['api_key_last_used_at'])) . '</span>' : '<span class="text-secondary">Never</span>';
|
||||
$last_used = $row['api_key_last_used_at'] ? '<span title="' . escapeHtml($row['api_key_last_used_at']) . '">' . escapeHtml(timeAgo($row['api_key_last_used_at'])) . '</span>' : '<span class="text-body-secondary">Never</span>';
|
||||
ob_start(); ?>
|
||||
<?php if ($row['user_name'] !== null && intval($row['user_type']) === 1) { ?>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
@@ -88,38 +140,49 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<span class="small text-danger-emphasis"><i class="fas fa-exclamation-triangle me-1"></i>Nobody</span>
|
||||
<?php }
|
||||
$agent_html = ob_get_clean();
|
||||
$can_html = $role ? roleAccessHtml($role) . '<div class="small text-body-secondary mt-1"><i class="fas fa-fw fa-building me-1"></i>' . escapeHtml(userClientAccessText($access[intval($row['api_key_user_id'])] ?? ['allow' => [], 'deny' => []], intval($role['role_is_admin']))) . '</div>' : '<span class="small text-secondary">Nothing</span>';
|
||||
$can_html = $role ? roleAccessHtml($role) . '<div class="small text-body-secondary mt-1"><i class="fas fa-fw fa-building me-1"></i>' . escapeHtml(userClientAccessText($access[intval($row['api_key_user_id'])] ?? ['allow' => [], 'deny' => []], intval($role['role_is_admin']))) . '</div>' : '<span class="small text-body-secondary">Nothing</span>';
|
||||
?>
|
||||
<tr data-api-key-id="<?= $api_key_id ?>" class="<?= $expired ? 'text-body-secondary' : '' ?>">
|
||||
<td class="ps-3">
|
||||
<div class="form-check mb-0">
|
||||
<td class="checkbox-column bg-light border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="api_key_ids[]" value="<?= $api_key_id ?>" aria-label="Select <?= $name ?>">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a class="ajax-modal fw-semibold <?= $expired ? 'text-body-secondary' : 'text-body' ?>" href="#" data-modal-url="modals/api/api_key_edit.php?id=<?= $api_key_id ?>" title="Edit <?= $name ?>"><?= $name ?></a>
|
||||
<div class="small text-body-secondary"><span class="font-monospace">••••<?= escapeHtml(substr((string) $row['api_key_secret'], -4)) ?></span> · made <?= date('M j, Y', strtotime($row['api_key_created_at'])) ?></div>
|
||||
<div class="mt-1"><?= apiKeyStatePill($row, $role) ?></div>
|
||||
<!-- On a phone, who it acts as and when it was used come along -->
|
||||
<div class="d-md-none mt-2"><?= $agent_html ?></div>
|
||||
<div class="d-lg-none mt-2"><?= $can_html ?></div>
|
||||
<div class="d-sm-none small mt-1">Last used <?= $last_used ?></div>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-tone-other d-none d-sm-inline-flex" aria-hidden="true"><i class="fas fa-fw fa-key"></i></span>
|
||||
<div class="min-w-0">
|
||||
<a class="ajax-modal fw-semibold <?= $expired ? 'text-body-secondary' : 'text-body' ?>" href="#" data-modal-url="modals/api/api_key_edit.php?id=<?= $api_key_id ?>" title="Edit <?= $name ?>"><?= $name ?></a>
|
||||
<div class="small text-body-secondary"><span class="font-monospace">••••<?= escapeHtml(substr((string) $row['api_key_secret'], -4)) ?></span> · made <?= date('M j, Y', strtotime($row['api_key_created_at'])) ?></div>
|
||||
<div class="mt-1"><?= apiKeyStatePill($row, $role) ?></div>
|
||||
<!-- On a phone, who it acts as and when it was used come along -->
|
||||
<div class="d-md-none mt-2"><?= $agent_html ?></div>
|
||||
<div class="d-lg-none mt-2"><?= $can_html ?></div>
|
||||
<div class="d-sm-none small mt-1">Last used <?= $last_used ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell"><?= $agent_html ?></td>
|
||||
<td class="d-none d-lg-table-cell"><?= $can_html ?></td>
|
||||
<td class="d-none d-sm-table-cell small text-nowrap"><?= $last_used ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/api/api_key_edit.php?id=<?= $api_key_id ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/api/api_key_edit.php?id=<?= $api_key_id ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if (!$expired) { // revoked first, then deleted ?>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?revoke_api_key=<?= $api_key_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Revoke <?= $name ?>?" data-confirm-text="It stops working now. Anything using it is turned away." data-confirm-button="Revoke"><i class="fas fa-fw fa-ban me-2"></i>Revoke</a>
|
||||
data-confirm-title="Revoke <?= $name ?>?" data-confirm-text="It stops working now. Anything using it is turned away." data-confirm-button="Revoke">
|
||||
<i class="fas fa-fw fa-ban me-2"></i>Revoke
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_api_key=<?= $api_key_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="It has expired, so nothing can be using it." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="It has expired, so nothing can be using it." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,17 +193,19 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if (!$keys) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => 'API keys',
|
||||
'icon' => 'fa-key',
|
||||
'text' => 'A key lets another system read and write ITFlow through its API, as one of your agents.',
|
||||
'filtered' => $search !== '',
|
||||
'clear_url' => 'api_keys.php',
|
||||
'actions' => [['label' => 'New API Key', 'modal' => 'modals/api/api_key_add.php']],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => 'API keys',
|
||||
'icon' => 'fa-key',
|
||||
'filtered' => $q !== '',
|
||||
'archived' => $show_expired,
|
||||
'archived_title' => 'No expired API keys',
|
||||
'views' => ['show'],
|
||||
'text' => 'A key lets another system read and write ITFlow through its API, as one of your agents - it can do what their role allows, for the clients they see, until it expires.',
|
||||
'actions' => [['label' => 'New API Key', 'modal' => 'modals/api/api_key_add.php']],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
</div>
|
||||
|
||||
<script src="../js/bulk_actions.js"></script>
|
||||
|
||||
@@ -9,71 +9,85 @@
|
||||
* (opening the list of them, where there is one). A category can be
|
||||
* changed, merged into another of its kind, archived - it stays on its
|
||||
* records but isn't offered for new ones - or, while nothing uses it,
|
||||
* deleted. The kinds pickers list in an order set here are dragged into it.
|
||||
* The work is in functions/categories.php; the handlers are
|
||||
* deleted. The kinds pickers list in an order set here are listed in it, and
|
||||
* dragged into it. The work is in functions/categories.php; the handlers are
|
||||
* admin/post/category.php.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter - the column is the kind's, set below
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$kinds = categoryKinds();
|
||||
$kind = isset($kinds[$_GET['category'] ?? '']) ? (string) $_GET['category'] : 'Expense';
|
||||
$config = categoryKind($kind);
|
||||
$show_archived = isset($_GET['archived']);
|
||||
// ?archived=1 is how older links asked for the archived ones
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']);
|
||||
$search = trim((string) ($_GET['q'] ?? ''));
|
||||
|
||||
// How the list is sorted - the order pickers use first, for the kinds that keep one
|
||||
$sorts = ($config['ordered'] ? ['order' => ['Order', 'fa-sort-numeric-down', 'The order they are offered in']] : [])
|
||||
+ ['name' => ['Name', 'fa-sort-alpha-down', 'A to Z'], 'use' => ['Most used', 'fa-sort-amount-down', 'The ones on the most records first']];
|
||||
$sort_by = isset($sorts[$_GET['sort'] ?? '']) ? (string) $_GET['sort'] : array_key_first($sorts);
|
||||
$default_sort = array_key_first($sorts);
|
||||
// Only these sort - by name, by use, and in the order pickers use for the kinds that keep one (and are listed in it)
|
||||
$sort_first = ['category_name' => 'ASC', 'used' => 'DESC'] + ($config['ordered'] ? ['category_order' => 'ASC'] : []);
|
||||
$default_sort = $config['ordered'] ? 'category_order' : 'category_name';
|
||||
if (!isset($sort) || !isset($sort_first[$sort])) {
|
||||
$sort = $default_sort;
|
||||
}
|
||||
|
||||
// The kind's categories, what the search leaves - counted for the pills, then this pill's
|
||||
$usage = categoryUsage($kind);
|
||||
$empty_use = ['all' => 0, 'archived' => 0, 'uses' => []];
|
||||
$categories = [];
|
||||
$counts = [0, 0];
|
||||
foreach (categoryRows($kind) as $category_id => $row) {
|
||||
if ((bool) $row['category_archived_at'] !== $show_archived) {
|
||||
if ($search !== '' && mb_stripos($row['category_name'], $search) === false && mb_stripos((string) $row['category_description'], $search) === false) {
|
||||
continue;
|
||||
}
|
||||
if ($search !== '' && mb_stripos($row['category_name'], $search) === false && mb_stripos((string) $row['category_description'], $search) === false) {
|
||||
$counts[$row['category_archived_at'] ? 1 : 0]++;
|
||||
if ((bool) $row['category_archived_at'] !== $show_archived) {
|
||||
continue;
|
||||
}
|
||||
$row['used'] = $usage[$category_id] ?? $empty_use;
|
||||
$categories[$category_id] = $row;
|
||||
}
|
||||
if ($sort_by === 'name') {
|
||||
uasort($categories, function ($a, $b) {
|
||||
return strnatcasecmp($a['category_name'], $b['category_name']);
|
||||
|
||||
// categoryRows() has them in the order pickers use
|
||||
$direction = $order === 'DESC' ? -1 : 1;
|
||||
if ($sort === 'category_name') {
|
||||
uasort($categories, function ($a, $b) use ($direction) {
|
||||
return $direction * strnatcasecmp($a['category_name'], $b['category_name']);
|
||||
});
|
||||
} elseif ($sort_by === 'use') {
|
||||
uasort($categories, function ($a, $b) {
|
||||
return $b['used']['all'] <=> $a['used']['all'] ?: strnatcasecmp($a['category_name'], $b['category_name']);
|
||||
} elseif ($sort === 'used') {
|
||||
uasort($categories, function ($a, $b) use ($direction) {
|
||||
return $direction * ($a['used']['all'] <=> $b['used']['all']) ?: strnatcasecmp($a['category_name'], $b['category_name']);
|
||||
});
|
||||
} elseif ($direction === -1) {
|
||||
$categories = array_reverse($categories, true);
|
||||
}
|
||||
|
||||
// A page of them
|
||||
$num_rows = [count($categories)];
|
||||
$categories = array_slice($categories, $record_from, $record_to, true);
|
||||
|
||||
// Names records have that aren't categories - a kind held by name, in the plain current view
|
||||
$loose = !$show_archived && $search === '' ? categoryLooseNames($kind) : [];
|
||||
|
||||
// Dragged into order - in the order view, with the whole current list showing
|
||||
$can_reorder = $config['ordered'] && $sort_by === 'order' && !$show_archived && $search === '' && count($categories) > 1;
|
||||
// Dragged into order - in order, first to last, with every current one in it
|
||||
$can_reorder = $config['ordered'] && $sort === 'category_order' && $order === 'ASC' && !$show_archived && $search === '' && $num_rows[0] > 1;
|
||||
|
||||
// Current categories of each kind for the nav, and this kind's archived ones for the tab
|
||||
// Current categories of each kind for the nav
|
||||
$kind_counts = [];
|
||||
$archived_count = 0;
|
||||
$sql = mysqli_query($mysqli, "SELECT category_type, SUM(category_archived_at IS NULL), SUM(category_archived_at IS NOT NULL) FROM categories GROUP BY category_type");
|
||||
$sql = mysqli_query($mysqli, "SELECT category_type, SUM(category_archived_at IS NULL) FROM categories GROUP BY category_type");
|
||||
while ($row = mysqli_fetch_row($sql)) {
|
||||
$kind_counts[$row[0]] = intval($row[1]);
|
||||
if ($row[0] === $kind) {
|
||||
$archived_count = intval($row[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// This page with some of its query changed - null drops a key
|
||||
$page_url = function (array $change = []) use ($kind, $show_archived, $sort_by, $default_sort, $search) {
|
||||
$query = array_merge(['category' => $kind, 'q' => $search !== '' ? $search : null, 'sort' => $sort_by !== $default_sort ? $sort_by : null, 'archived' => $show_archived ? 1 : null], $change);
|
||||
return 'categories.php?' . http_build_query(array_filter($query, function ($v) {
|
||||
return $v !== null;
|
||||
}));
|
||||
// A column first sorts the way it reads best - A to Z, most used, first to last - then flips
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon, $sort_first) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . ($sort === $column ? $disp : $sort_first[$column]) . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
$pill_url = function ($archived) use ($kind) {
|
||||
return '?' . http_build_query(array_filter(['category' => $kind, 'q' => $_GET['q'] ?? '', 'show' => $archived ? 'archived' : '']));
|
||||
};
|
||||
|
||||
$new_label = 'New ' . ucwords($config['one']);
|
||||
@@ -95,7 +109,7 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<div class="col-md-4 col-lg-3 border-end">
|
||||
<nav class="nav nav-pills flex-nowrap flex-md-column overflow-auto p-2 gap-1 itflow-category-kinds" aria-label="Kinds of category">
|
||||
<?php foreach ($kinds as $kind_key => $kind_config) { ?>
|
||||
<a class="nav-link d-flex align-items-center gap-2 text-nowrap<?= $kind_key === $kind ? ' active' : '' ?>" href="categories.php?category=<?= urlencode($kind_key) ?>"<?= $kind_key === $kind ? ' aria-current="page"' : '' ?>>
|
||||
<a class="nav-link d-flex align-items-center gap-2 text-nowrap<?= $kind_key === $kind ? ' active' : '' ?>" href="categories.php?category=<?= urlencode($kind_key) ?>" title="<?= escapeHtml($kind_config['about']) ?>"<?= $kind_key === $kind ? ' aria-current="page"' : '' ?>>
|
||||
<i class="fas fa-fw <?= $kind_config['icon'] ?>"></i><span class="text-truncate"><?= escapeHtml($kind_config['label']) ?></span>
|
||||
<span class="badge rounded-pill ms-auto <?= $kind_key === $kind ? 'text-bg-light' : 'text-bg-secondary' ?>"><?= $kind_counts[$kind_key] ?? 0 ?></span>
|
||||
</a>
|
||||
@@ -105,129 +119,145 @@ $csrf = $_SESSION['csrf_token'];
|
||||
|
||||
<!-- This kind's categories -->
|
||||
<div class="col-md-8 col-lg-9">
|
||||
<div class="p-2 border-bottom">
|
||||
<p class="small text-secondary mb-2"><?= escapeHtml($config['about']) ?></p>
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<input type="hidden" name="category" value="<?= escapeHtml($kind) ?>">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<?php if ($sort_by !== $default_sort) { ?><input type="hidden" name="sort" value="<?= escapeHtml($sort_by) ?>"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search <?= escapeHtml($config['many']) ?>">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Sort">
|
||||
<?php foreach ($sorts as $sort_key => [$sort_label, $sort_icon, $sort_title]) { ?>
|
||||
<a class="btn btn-outline-secondary<?= $sort_by === $sort_key ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['sort' => $sort_key !== $default_sort ? $sort_key : null])) ?>" title="<?= $sort_title ?>"><i class="fas <?= $sort_icon ?> me-1"></i><?= $sort_label ?></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm me-auto" role="group" aria-label="Current or archived">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
</div>
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-1"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php" data-bulk="true">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into one...
|
||||
</a>
|
||||
<?php if ($show_archived) { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_categories">
|
||||
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_archive_categories">
|
||||
<i class="fas fa-fw fa-archive text-secondary me-2"></i>Archive
|
||||
</button>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_delete_categories"
|
||||
data-confirm-title="Delete these <?= escapeHtml($config['many']) ?>?"
|
||||
data-confirm-text="Only the ones nothing uses are deleted - the rest are kept, to merge into another or archive."
|
||||
data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-lg-6 col-md-8">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search <?= escapeHtml($config['many']) ?>..." title="Name or description">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-4">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php" data-bulk="true">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into one...
|
||||
</a>
|
||||
<?php if ($show_archived) { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_categories">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_archive_categories">
|
||||
<i class="fas fa-fw fa-archive text-secondary me-2"></i>Archive
|
||||
</button>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_delete_categories"
|
||||
data-confirm-title="Delete these <?= escapeHtml($config['many']) ?>?"
|
||||
data-confirm-text="Only the ones nothing uses are deleted - the rest are kept, to merge into another or archive."
|
||||
data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="<?= escapeHtml($pill_url(false)) ?>"><i class="fas fa-fw <?= $config['icon'] ?> me-1"></i>Active <span class="badge rounded-pill ms-1"><?= $counts[0] ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="<?= escapeHtml($pill_url(true)) ?>" title="They stay on their records, but aren't offered for new ones"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= $counts[1] ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($categories) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3" style="width: 1%">
|
||||
<div class="form-check mb-0">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all">
|
||||
</div>
|
||||
</th>
|
||||
<?php if ($can_reorder) { ?><th style="width: 1%"><span class="visually-hidden">Order</span></th><?php } ?>
|
||||
<th><?= escapeHtml(ucfirst($config['one'])) ?></th>
|
||||
<th class="d-none d-sm-table-cell">Used on</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<tbody<?= $can_reorder ? ' data-category-sortable data-category-kind="' . escapeHtml($kind) . '"' : '' ?>>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="checkbox-column border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all on this page">
|
||||
</div>
|
||||
</th>
|
||||
<?php if ($can_reorder) { ?><th style="width: 1%"><span class="visually-hidden">Order</span></th><?php } ?>
|
||||
<th>
|
||||
<?= $sort_link('category_name', escapeHtml(ucfirst($config['one']))) ?>
|
||||
<?php if ($config['ordered']) { ?><span class="fw-normal text-body-secondary small ms-2" title="The order they are offered in"><?= $sort_link('category_order', 'in order') ?></span><?php } ?>
|
||||
</th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('used', 'Used on') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody<?= $can_reorder ? ' data-category-sortable data-category-kind="' . escapeHtml($kind) . '" data-category-offset="' . intval($record_from) . '"' : '' ?>>
|
||||
<?php
|
||||
$positions = array_keys($categories);
|
||||
$position = $record_from - 1;
|
||||
foreach ($categories as $category_id => $row) {
|
||||
$position++;
|
||||
$name = escapeHtml($row['category_name']);
|
||||
$used = $row['used'];
|
||||
$edit_url = "modals/category/category_edit.php?id=$category_id";
|
||||
$used_html = $used['all'] ? categoryUsageHtml($row, $used) : '<span class="text-secondary">' . ($row['category_archived_at'] ? 'Nothing uses it' : 'Nothing yet') . '</span>';
|
||||
$used_html = $used['all'] ? categoryUsageHtml($row, $used) : '<span class="text-body-secondary">' . ($row['category_archived_at'] ? 'Nothing uses it' : 'Nothing yet') . '</span>';
|
||||
$blocker = categoryDeleteBlocker($row, $used);
|
||||
$position = array_search($category_id, $positions, true);
|
||||
?>
|
||||
<tr data-category-id="<?= $category_id ?>">
|
||||
<td class="ps-3">
|
||||
<div class="form-check mb-0">
|
||||
<td class="checkbox-column bg-light border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="category_ids[]" value="<?= $category_id ?>" aria-label="Select <?= $name ?>">
|
||||
</div>
|
||||
</td>
|
||||
<?php if ($can_reorder) { ?>
|
||||
<td class="pe-0"><span class="itflow-category-grip text-secondary" title="Drag to move" data-category-grip><i class="fas fa-grip-vertical" aria-hidden="true"></i></span></td>
|
||||
<td class="pe-0"><span class="itflow-category-grip text-body-secondary" title="Drag to move" data-category-grip><i class="fas fa-grip-vertical" aria-hidden="true"></i></span></td>
|
||||
<?php } ?>
|
||||
<td>
|
||||
<a class="ajax-modal text-decoration-none text-reset" href="#" data-modal-url="<?= $edit_url ?>" title="Edit <?= $name ?>"><?= categoryChip($row) ?></a>
|
||||
<?php if (trim((string) $row['category_description']) !== '') { ?>
|
||||
<div class="small text-secondary mt-1"><?= escapeHtml($row['category_description']) ?></div>
|
||||
<div class="small text-body-secondary mt-1"><?= escapeHtml($row['category_description']) ?></div>
|
||||
<?php } ?>
|
||||
<div class="small d-sm-none mt-1"><?= $used_html ?></div>
|
||||
<?php if ($row['category_archived_at']) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['category_archived_at'])) ?></div>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['category_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="d-none d-sm-table-cell small"><?= $used_html ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php?category_ids[]=<?= $category_id ?>"><i class="fas fa-fw fa-compress-alt me-2"></i>Merge into...</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php?category_ids[]=<?= $category_id ?>">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into...
|
||||
</a>
|
||||
<?php if ($can_reorder) { ?>
|
||||
<?php if ($position > 0) { ?>
|
||||
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=up&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-arrow-up me-2"></i>Move up</a>
|
||||
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=up&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-arrow-up text-secondary me-2"></i>Move up
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($position < count($positions) - 1) { ?>
|
||||
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=down&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-arrow-down me-2"></i>Move down</a>
|
||||
<?php if ($position < $num_rows[0] - 1) { ?>
|
||||
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=down&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-arrow-down text-secondary me-2"></i>Move down
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($row['category_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<a class="dropdown-item" href="post.php?restore_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>" title="It stays on its records, but isn't offered for new ones"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>" title="It stays on its records, but isn't offered for new ones">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($blocker !== '') { ?>
|
||||
<span class="dropdown-item disabled" title="<?= escapeHtml($blocker) ?>"><i class="fas fa-fw fa-trash me-2"></i>Delete</span>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Nothing uses it, so no record changes." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Nothing uses it, so no record changes." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -240,27 +270,28 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</form>
|
||||
|
||||
<?php if ($can_reorder) { ?>
|
||||
<div class="small text-secondary px-3 py-2 border-top"><i class="fas fa-fw fa-grip-vertical me-1"></i>Drag them into the order they're offered in.</div>
|
||||
<?php } elseif ($config['ordered'] && $sort_by === 'order' && !$show_archived && $search !== '') { ?>
|
||||
<div class="small text-secondary px-3 py-2 border-top">Clear the search to drag them into order.</div>
|
||||
<div class="small text-body-secondary px-3 py-2 border-top"><i class="fas fa-fw fa-grip-vertical me-1"></i>Drag them into the order they're offered in.</div>
|
||||
<?php } elseif ($config['ordered'] && $sort === 'category_order' && !$show_archived && $search !== '') { ?>
|
||||
<div class="small text-body-secondary px-3 py-2 border-top">Clear the search to drag them into order.</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!$categories) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => $config['many'],
|
||||
'title' => $show_archived ? 'No archived ' . $config['many'] : 'No ' . $config['many'] . ' yet',
|
||||
'text' => $show_archived ? 'An archived category stays on its records, but isn\'t offered for new ones.' : $config['about'],
|
||||
'icon' => $config['icon'],
|
||||
'filtered' => $search !== '',
|
||||
'clear_url' => $page_url(['q' => null]),
|
||||
'actions' => $show_archived ? [] : [['label' => $new_label, 'modal' => $add_url]],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => $config['many'],
|
||||
'icon' => $config['icon'],
|
||||
'filtered' => $search !== '',
|
||||
'archived' => $show_archived,
|
||||
'views' => ['category', 'show'],
|
||||
'text' => escapeHtml($config['about']),
|
||||
'actions' => [['label' => $new_label, 'modal' => $add_url]],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
|
||||
<?php if ($loose) { ?>
|
||||
<div class="border-top px-3 py-2 itflow-category-loose">
|
||||
<div class="fw-semibold"><i class="fas fa-fw fa-question-circle text-secondary me-1"></i>In use, but not set up here</div>
|
||||
<p class="small text-secondary mb-1">Records have these, but they aren't <?= escapeHtml($config['many']) ?> - so they can't be picked again, and have no color or icon. Add one to make it <?= escapeHtml(categoryKindPhrase($kind)) ?>; to fold it into another, add it, then merge it.</p>
|
||||
<p class="small text-body-secondary mb-1">Records have these, but they aren't <?= escapeHtml($config['many']) ?> - so they can't be picked again, and have no color or icon. Add one to make it <?= escapeHtml(categoryKindPhrase($kind)) ?>; to fold it into another, add it, then merge it.</p>
|
||||
<ul class="list-unstyled mb-0">
|
||||
<?php foreach ($loose as $loose_name => $loose_used) { ?>
|
||||
<li class="d-flex flex-wrap align-items-center gap-2 py-1">
|
||||
@@ -286,7 +317,8 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<script src="/libs/SortableJS/Sortable.min.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
// Dragged into order - saved as soon as one is dropped; a failure reloads the page to show the order kept
|
||||
// Dragged into order - saved as soon as one is dropped, in their place among the rest (offset - the ones on the pages before);
|
||||
// a failure reloads the page to show the order kept
|
||||
const body = document.querySelector('[data-category-sortable]');
|
||||
new Sortable(body, {
|
||||
handle: '[data-category-grip]',
|
||||
@@ -298,7 +330,7 @@ $csrf = $_SESSION['csrf_token'];
|
||||
const ids = Array.from(body.querySelectorAll('tr[data-category-id]')).map(function (row) {
|
||||
return row.dataset.categoryId;
|
||||
});
|
||||
itflowPost('post.php', { reorder_categories: 1, csrf_token: '<?= $csrf ?>', category: body.dataset.categoryKind, category_ids: ids })
|
||||
itflowPost('post.php', { reorder_categories: 1, csrf_token: '<?= $csrf ?>', category: body.dataset.categoryKind, offset: body.dataset.categoryOffset, category_ids: ids })
|
||||
.then(function (text) {
|
||||
const result = JSON.parse(text);
|
||||
if (!result.ok) {
|
||||
|
||||
@@ -14,7 +14,7 @@ $category_kind_word = function ($row) {
|
||||
|
||||
// Admin > Categories on a kind, to go back to after making one
|
||||
$category_page = function ($kind, $archived = false) {
|
||||
return 'categories.php?category=' . urlencode($kind) . ($archived ? '&archived=1' : '');
|
||||
return 'categories.php?category=' . urlencode($kind) . ($archived ? '&show=archived' : '');
|
||||
};
|
||||
|
||||
if (isset($_POST['add_category'])) {
|
||||
@@ -221,12 +221,16 @@ if (isset($_POST['reorder_categories'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// The current ones in the order dragged, the archived ones after them
|
||||
// The ones dragged, a page of them, in the order dragged in their place among the current ones - offset is how many
|
||||
// come before them, on the pages before - and the archived ones after them all
|
||||
$rows = categoryRows($config['kind']);
|
||||
$ids = array_values(array_filter(array_map('intval', (array) ($_POST['category_ids'] ?? [])), function ($id) use ($rows) {
|
||||
return isset($rows[$id]);
|
||||
$current = array_keys(array_filter($rows, function ($row) {
|
||||
return !$row['category_archived_at'];
|
||||
}));
|
||||
if (categoryReorder($config['kind'], $ids)) {
|
||||
$ids = array_values(array_intersect(array_unique(array_map('intval', (array) ($_POST['category_ids'] ?? []))), $current));
|
||||
$new_order = array_values(array_diff($current, $ids));
|
||||
array_splice($new_order, min(max(0, intval($_POST['offset'] ?? 0)), count($new_order)), 0, $ids);
|
||||
if (categoryReorder($config['kind'], $new_order)) {
|
||||
logAudit("Category", "Edit", "$session_name reordered the " . $config['many']);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ if (isset($_POST['edit_tag'])) {
|
||||
|
||||
flashAlert("Tag <strong>" . escapeHtml($fields['name']) . "</strong> saved" . ($moved ? " - it's " . tagKindPhrase($fields['type']) . " now" : ''));
|
||||
|
||||
redirect($moved ? "tags.php?type=" . intval($fields['type']) . ($row['tag_archived_at'] ? '&archived=1' : '') : null);
|
||||
redirect($moved ? "tags.php?type=" . intval($fields['type']) . ($row['tag_archived_at'] ? '&show=archived' : '') : null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
173
admin/roles.php
173
admin/roles.php
@@ -10,32 +10,53 @@
|
||||
* admin/post/roles.php.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "role_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$show_archived = isset($_GET['archived']);
|
||||
$search = trim((string) ($_GET['q'] ?? ''));
|
||||
// ?archived=1 is how older links asked for the archived ones
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']);
|
||||
|
||||
$all_roles = roleRows();
|
||||
// Only these sort - an unknown column would take the page down. Admin roles stay first, as on Users
|
||||
$sortable_columns = [
|
||||
'role_name' => "role_is_admin DESC, role_name $order",
|
||||
'agents' => "agents $order, role_name ASC",
|
||||
'role_updated_at' => "COALESCE(role_updated_at, role_created_at) $order",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'role_name';
|
||||
}
|
||||
|
||||
$search = "role_type = 1 AND (role_name LIKE '%$q%' OR role_description LIKE '%$q%')";
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS role_id, role_name, role_description, role_is_admin, role_created_at, role_updated_at, role_archived_at,
|
||||
(SELECT COUNT(*) FROM users WHERE user_role_id = role_id AND user_type = 1 AND user_archived_at IS NULL) AS agents,
|
||||
(SELECT COUNT(*) FROM users WHERE user_role_id = role_id AND user_type = 1 AND user_archived_at IS NOT NULL) AS agents_archived
|
||||
FROM user_roles
|
||||
WHERE $search AND role_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
ORDER BY {$sortable_columns[$sort]}, role_id ASC
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
// Each with its levels, as roleRows() gives them
|
||||
$roles = [];
|
||||
$archived_count = 0;
|
||||
foreach ($all_roles as $role_id => $row) {
|
||||
$archived_count += $row['role_archived_at'] ? 1 : 0;
|
||||
if ((bool) $row['role_archived_at'] !== $show_archived) {
|
||||
continue;
|
||||
}
|
||||
if ($search !== '' && mb_stripos($row['role_name'], $search) === false && mb_stripos((string) $row['role_description'], $search) === false) {
|
||||
continue;
|
||||
}
|
||||
$roles[$role_id] = $row;
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$roles[intval($row['role_id'])] = $row;
|
||||
}
|
||||
$levels = roleLevels(array_keys($roles));
|
||||
foreach ($roles as $role_id => $row) {
|
||||
$roles[$role_id]['levels'] = $levels[$role_id] ?? [];
|
||||
}
|
||||
$agents = roleAgents(array_keys($roles), 5);
|
||||
|
||||
// This page with some of its query changed - null drops a key
|
||||
$page_url = function (array $change = []) use ($show_archived, $search) {
|
||||
$query = array_merge(['q' => $search !== '' ? $search : null, 'archived' => $show_archived ? 1 : null], $change);
|
||||
return 'roles.php' . (($query = http_build_query(array_filter($query, function ($v) {
|
||||
return $v !== null;
|
||||
}))) ? "?$query" : '');
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(role_archived_at IS NULL), 0), COALESCE(SUM(role_archived_at IS NOT NULL), 0) FROM user_roles WHERE $search"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
@@ -49,34 +70,34 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/role/role_add.php"><i class="fas fa-plus me-2"></i>New Role</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-2 border-bottom">
|
||||
<p class="small text-secondary mb-2">A role sets what its agents can open - an admin role everything, including Admin; any other a level of each part of ITFlow. Which clients an agent sees is set on the agent, in <a href="users.php">Users</a>.</p>
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search roles">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Current or archived">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-5">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search roles..." title="Name or description">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '']))) ?>"><i class="fas fa-fw fa-user-shield me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => 'archived']))) ?>" title="Kept for the agents archived with them, not given to anyone new"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($roles) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3">Role</th>
|
||||
<th class="d-none d-md-table-cell">Access</th>
|
||||
<th class="d-none d-sm-table-cell">Agents</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="ps-3"><?= $sort_link('role_name', 'Role') ?></th>
|
||||
<th class="d-none d-md-table-cell">Access</th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('agents', 'Agents') ?></th>
|
||||
<th class="d-none d-lg-table-cell"><?= $sort_link('role_updated_at', 'Updated') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($roles as $role_id => $row) {
|
||||
$name = escapeHtml($row['role_name']);
|
||||
@@ -86,6 +107,7 @@ $csrf = $_SESSION['csrf_token'];
|
||||
$agent_count = intval($row['agents']);
|
||||
$archive_blocker = roleArchiveBlocker($row);
|
||||
$delete_blocker = roleDeleteBlocker($row);
|
||||
$updated = $row['role_updated_at'] ?: $row['role_created_at'];
|
||||
// The agents with it - a few faces and how many, opening Users filtered to them
|
||||
ob_start();
|
||||
if ($agent_count) { ?>
|
||||
@@ -96,10 +118,10 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<span class="small text-nowrap"><?= $agent_count ?> agent<?= $agent_count === 1 ? '' : 's' ?></span>
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<span class="small text-secondary">Nobody</span>
|
||||
<span class="small text-body-secondary">Nobody</span>
|
||||
<?php }
|
||||
if (intval($row['agents_archived'])) { ?>
|
||||
<div class="small text-secondary"><?= intval($row['agents_archived']) ?> archived</div>
|
||||
<div class="small text-body-secondary"><?= intval($row['agents_archived']) ?> archived</div>
|
||||
<?php }
|
||||
$agents_html = ob_get_clean();
|
||||
?>
|
||||
@@ -111,10 +133,10 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<a class="ajax-modal fw-semibold text-body" href="#" data-modal-size="lg" data-modal-url="<?= $edit_url ?>" title="Edit <?= $name ?>"><?= $name ?></a>
|
||||
<?php if ($is_mine) { ?><span class="badge rounded-pill bg-primary-subtle text-primary-emphasis fw-normal ms-1">Yours</span><?php } ?>
|
||||
<?php if (trim((string) $row['role_description']) !== '') { ?>
|
||||
<div class="small text-secondary"><?= escapeHtml($row['role_description']) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($row['role_description']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($row['role_archived_at']) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['role_archived_at'])) ?></div>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['role_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
<!-- On a phone, access and agents come along under the name -->
|
||||
<div class="d-md-none mt-1"><?= roleAccessHtml($row) ?></div>
|
||||
@@ -124,28 +146,41 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell"><?= roleAccessHtml($row) ?></td>
|
||||
<td class="d-none d-sm-table-cell"><?= $agents_html ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="d-none d-lg-table-cell small text-body-secondary text-nowrap" title="<?= escapeHtml($updated) ?>"><?= timeAgo($updated) ?></td>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/role/role_add.php?copy=<?= $role_id ?>" title="A new role starting from this one"><i class="fas fa-fw fa-copy me-2"></i>Copy</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $edit_url ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/role/role_add.php?copy=<?= $role_id ?>" title="A new role starting from this one">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>Copy
|
||||
</a>
|
||||
<?php if ($agent_count) { ?>
|
||||
<a class="dropdown-item" href="users.php?role=<?= $role_id ?>"><i class="fas fa-fw fa-users me-2"></i>Its agents</a>
|
||||
<a class="dropdown-item" href="users.php?role=<?= $role_id ?>">
|
||||
<i class="fas fa-fw fa-users text-secondary me-2"></i>Its agents
|
||||
</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($row['role_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_role=<?= $role_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<a class="dropdown-item" href="post.php?restore_role=<?= $role_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } elseif ($archive_blocker !== '') { ?>
|
||||
<span class="dropdown-item disabled" title="<?= escapeHtml($archive_blocker) ?>"><i class="fas fa-fw fa-archive me-2"></i>Archive</span>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_role=<?= $role_id ?>&csrf_token=<?= $csrf ?>" title="Kept for agents archived with it, but not given to anyone new"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_role=<?= $role_id ?>&csrf_token=<?= $csrf ?>" title="Kept for agents archived with it, but not given to anyone new">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($delete_blocker !== '') { ?>
|
||||
<span class="dropdown-item disabled" title="<?= escapeHtml($delete_blocker) ?>"><i class="fas fa-fw fa-trash me-2"></i>Delete</span>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_role=<?= $role_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Nobody has it, so no agent changes." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Nobody has it, so no agent changes." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -155,18 +190,18 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php if (!$roles) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => 'roles',
|
||||
'title' => $show_archived ? 'No archived roles' : 'No roles yet',
|
||||
'text' => $show_archived ? 'An archived role stays with the agents archived with it, but isn\'t given to anyone new.' : 'A role sets what its agents can open.',
|
||||
'icon' => 'fa-user-shield',
|
||||
'filtered' => $search !== '',
|
||||
'clear_url' => $page_url(['q' => null]),
|
||||
'actions' => $show_archived ? [] : [['label' => 'New Role', 'modal' => 'modals/role/role_add.php', 'size' => 'lg']],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => 'roles',
|
||||
'icon' => 'fa-user-shield',
|
||||
'filtered' => $q !== '',
|
||||
'archived' => $show_archived,
|
||||
'views' => ['show'],
|
||||
'text' => 'A role sets what its agents can open - an admin role everything, including Admin; any other a level of each part of ITFlow.',
|
||||
'actions' => [['label' => 'New Role', 'modal' => 'modals/role/role_add.php', 'size' => 'lg']],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
232
admin/tags.php
232
admin/tags.php
@@ -11,6 +11,10 @@
|
||||
* functions/tags.php; the handlers are admin/post/tag.php.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "tag_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$kinds = [];
|
||||
@@ -20,45 +24,57 @@ foreach (tagKinds() as $kind_type => $kind_entity) {
|
||||
$type = intval($_GET['type'] ?? 1);
|
||||
$type = isset($kinds[$type]) ? $type : 1;
|
||||
$kind = $kinds[$type];
|
||||
$show_archived = isset($_GET['archived']);
|
||||
$by_use = ($_GET['sort'] ?? '') === 'use';
|
||||
// ?archived=1 is how older links asked for the archived ones
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']);
|
||||
|
||||
// Only these sort - by name, and by how many records have each, which is worked out here rather than in the query
|
||||
$sortable_columns = ['tag_name' => true, 'used' => true];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'tag_name';
|
||||
}
|
||||
|
||||
$usage = tagUsageBreakdown();
|
||||
$seat_lines = tagSeatLineCounts();
|
||||
|
||||
$search_sql = $q !== '' ? "AND (tag_name LIKE '%$q%' OR tag_description LIKE '%$q%')" : '';
|
||||
$search = "tag_type = $type AND (tag_name LIKE '%$q%' OR tag_description LIKE '%$q%')";
|
||||
$tags = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_description, tag_type, tag_color, tag_icon, tag_created_at, tag_archived_at FROM tags
|
||||
WHERE tag_type = $type AND tag_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . " $search_sql ORDER BY tag_name ASC");
|
||||
WHERE $search AND tag_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . " ORDER BY tag_name $order, tag_id ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$row['used'] = $usage[intval($row['tag_id'])] ?? ['all' => 0, 'archived' => 0];
|
||||
$row['lines'] = $seat_lines[intval($row['tag_id'])] ?? 0;
|
||||
$tags[] = $row;
|
||||
}
|
||||
if ($by_use) {
|
||||
// Most used first; the query put them in name order, and usort keeps that order for equal counts
|
||||
usort($tags, function ($a, $b) {
|
||||
return $b['used']['all'] <=> $a['used']['all'];
|
||||
if ($sort === 'used') {
|
||||
// By use, ties A to Z - usort keeps the order it is given for equal counts, so the query's name order goes back to A to Z first
|
||||
if ($order === 'DESC') {
|
||||
$tags = array_reverse($tags);
|
||||
}
|
||||
$direction = $order === 'DESC' ? -1 : 1;
|
||||
usort($tags, function ($a, $b) use ($direction) {
|
||||
return $direction * ($a['used']['all'] <=> $b['used']['all']);
|
||||
});
|
||||
}
|
||||
|
||||
// Current tags of each kind for the nav, and this kind's archived ones for the tab
|
||||
// A page of them
|
||||
$num_rows = [count($tags)];
|
||||
$tags = array_slice($tags, $record_from, $record_to);
|
||||
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(tag_archived_at IS NULL), 0), COALESCE(SUM(tag_archived_at IS NOT NULL), 0) FROM tags WHERE $search"));
|
||||
|
||||
// Current tags of each kind for the nav
|
||||
$kind_counts = [];
|
||||
$archived_count = 0;
|
||||
$sql = mysqli_query($mysqli, "SELECT tag_type, SUM(tag_archived_at IS NULL), SUM(tag_archived_at IS NOT NULL) FROM tags GROUP BY tag_type");
|
||||
$sql = mysqli_query($mysqli, "SELECT tag_type, SUM(tag_archived_at IS NULL) FROM tags GROUP BY tag_type");
|
||||
while ($row = mysqli_fetch_row($sql)) {
|
||||
$kind_counts[intval($row[0])] = intval($row[1]);
|
||||
if (intval($row[0]) === $type) {
|
||||
$archived_count = intval($row[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// This page with some of its query changed - null drops a key
|
||||
$page_url = function (array $change = []) use ($type, $show_archived, $by_use, $q) {
|
||||
$query = array_merge(['type' => $type, 'q' => $q !== '' ? stripslashes($q) : null, 'sort' => $by_use ? 'use' : null, 'archived' => $show_archived ? 1 : null], $change);
|
||||
return 'tags.php?' . http_build_query(array_filter($query, function ($v) {
|
||||
return $v !== null;
|
||||
}));
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
$pill_url = function ($archived) use ($type) {
|
||||
return '?' . http_build_query(array_filter(['type' => $type, 'q' => $_GET['q'] ?? '', 'show' => $archived ? 'archived' : '']));
|
||||
};
|
||||
|
||||
// "12 assets" / "1 asset"
|
||||
@@ -93,70 +109,71 @@ $csrf = $_SESSION['csrf_token'];
|
||||
|
||||
<!-- This kind's tags -->
|
||||
<div class="col-md-9 col-xl-10">
|
||||
<div class="p-2 border-bottom">
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<input type="hidden" name="type" value="<?= $type ?>">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<?php if ($by_use) { ?><input type="hidden" name="sort" value="use"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml(stripslashes($q)) ?>" placeholder="Search <?= $kind_word ?> tags">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Sort">
|
||||
<a class="btn btn-outline-secondary<?= $by_use ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['sort' => null])) ?>" title="A to Z"><i class="fas fa-sort-alpha-down me-1"></i>Name</a>
|
||||
<a class="btn btn-outline-secondary<?= $by_use ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['sort' => 'use'])) ?>" title="The tags on the most records first"><i class="fas fa-sort-amount-down me-1"></i>Most used</a>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm me-auto" role="group" aria-label="Current or archived">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
</div>
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-1"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tag/tag_merge.php" data-bulk="true">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into one...
|
||||
</a>
|
||||
<?php if ($show_archived) { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_tags">
|
||||
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_archive_tags">
|
||||
<i class="fas fa-fw fa-archive text-secondary me-2"></i>Archive
|
||||
</button>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_delete_tags"
|
||||
data-confirm-title="Delete these tags?"
|
||||
data-confirm-text="They come off every <?= $kind_word ?> that has them. Any that a recurring invoice line counts by are kept."
|
||||
data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-lg-6 col-md-8">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search <?= $kind_word ?> tags..." title="Name or description">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-4">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tag/tag_merge.php" data-bulk="true">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into one...
|
||||
</a>
|
||||
<?php if ($show_archived) { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_tags">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_archive_tags">
|
||||
<i class="fas fa-fw fa-archive text-secondary me-2"></i>Archive
|
||||
</button>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_delete_tags"
|
||||
data-confirm-title="Delete these tags?"
|
||||
data-confirm-text="They come off every <?= $kind_word ?> that has them. Any that a recurring invoice line counts by are kept."
|
||||
data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="<?= escapeHtml($pill_url(false)) ?>"><i class="fas fa-fw fa-tags me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="<?= escapeHtml($pill_url(true)) ?>" title="They stay on their records, but aren't offered for tagging or in the filters"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($tags) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3" style="width: 1%">
|
||||
<div class="form-check mb-0">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all">
|
||||
</div>
|
||||
</th>
|
||||
<th>Tag</th>
|
||||
<th class="d-none d-sm-table-cell">On</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="checkbox-column border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all on this page">
|
||||
</div>
|
||||
</th>
|
||||
<th><?= $sort_link('tag_name', 'Tag') ?></th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('used', 'On') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($tags as $tag) {
|
||||
$tag_id = intval($tag['tag_id']);
|
||||
@@ -168,49 +185,59 @@ $csrf = $_SESSION['csrf_token'];
|
||||
$list_url = tagListUrl(tagKinds()[$type], $tag);
|
||||
$used_html = $used
|
||||
? '<a href="' . escapeHtml($list_url) . '" title="Show the ' . $kind['plural'] . ' tagged ' . $name . '">' . $records_text($used) . '</a>'
|
||||
. ($used_archived ? ' <span class="text-secondary">(' . number_format($used_archived) . ' archived)</span>' : '')
|
||||
: '<span class="text-secondary">' . ($tag['tag_archived_at'] ? 'Nothing has it' : 'Nothing yet') . '</span>';
|
||||
. ($used_archived ? ' <span class="text-body-secondary">(' . number_format($used_archived) . ' archived)</span>' : '')
|
||||
: '<span class="text-body-secondary">' . ($tag['tag_archived_at'] ? 'Nothing has it' : 'Nothing yet') . '</span>';
|
||||
$lines_html = $lines
|
||||
? '<div class="small text-secondary" title="Recurring invoice lines that count the ' . ($type === 3 ? 'users' : 'devices') . ' with this tag"><i class="fas fa-fw fa-redo-alt me-1"></i>Counted on ' . $lines . ' recurring invoice ' . ($lines === 1 ? 'line' : 'lines') . '</div>'
|
||||
? '<div class="small text-body-secondary" title="Recurring invoice lines that count the ' . ($type === 3 ? 'users' : 'devices') . ' with this tag"><i class="fas fa-fw fa-redo-alt me-1"></i>Counted on ' . $lines . ' recurring invoice ' . ($lines === 1 ? 'line' : 'lines') . '</div>'
|
||||
: '';
|
||||
$delete_text = $used
|
||||
? 'It comes off the ' . $records_text($used) . ' that ' . ($used === 1 ? 'has' : 'have') . ' it. To keep it on them but stop offering it, archive it instead.'
|
||||
: 'Nothing has it, so no record changes.';
|
||||
?>
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<div class="form-check mb-0">
|
||||
<td class="checkbox-column bg-light border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="tag_ids[]" value="<?= $tag_id ?>" aria-label="Select <?= $name ?>">
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a class="ajax-modal text-decoration-none" href="#" data-modal-url="<?= $edit_url ?>" title="Edit <?= $name ?>"><?= tagPill($tag) ?></a>
|
||||
<?php if (trim((string) $tag['tag_description']) !== '') { ?>
|
||||
<div class="small text-secondary mt-1"><?= escapeHtml($tag['tag_description']) ?></div>
|
||||
<div class="small text-body-secondary mt-1"><?= escapeHtml($tag['tag_description']) ?></div>
|
||||
<?php } ?>
|
||||
<div class="small d-sm-none mt-1"><?= $used_html ?><?= $lines_html ?></div>
|
||||
<?php if ($tag['tag_archived_at']) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($tag['tag_archived_at'])) ?></div>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($tag['tag_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="d-none d-sm-table-cell small">
|
||||
<?= $used_html ?>
|
||||
<?= $lines_html ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tag/tag_merge.php?tag_ids[]=<?= $tag_id ?>"><i class="fas fa-fw fa-compress-alt me-2"></i>Merge into...</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tag/tag_merge.php?tag_ids[]=<?= $tag_id ?>">
|
||||
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into...
|
||||
</a>
|
||||
<?php if ($used) { ?>
|
||||
<a class="dropdown-item" href="<?= escapeHtml($list_url) ?>"><i class="fas fa-fw <?= $kind['icon'] ?> me-2"></i>Show the <?= $kind['plural'] ?></a>
|
||||
<a class="dropdown-item" href="<?= escapeHtml($list_url) ?>">
|
||||
<i class="fas fa-fw <?= $kind['icon'] ?> text-secondary me-2"></i>Show the <?= $kind['plural'] ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($tag['tag_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_tag=<?= $tag_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<a class="dropdown-item" href="post.php?restore_tag=<?= $tag_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_tag=<?= $tag_id ?>&csrf_token=<?= $csrf ?>" title="It stays on its <?= $kind['plural'] ?>, but isn't offered for tagging or in the filters"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_tag=<?= $tag_id ?>&csrf_token=<?= $csrf ?>" title="It stays on its <?= $kind['plural'] ?>, but isn't offered for tagging or in the filters">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($lines) { ?>
|
||||
<span class="dropdown-item disabled" title="Recurring invoice lines count by it - archive it, or merge it into another tag"><i class="fas fa-fw fa-trash me-2"></i>Delete</span>
|
||||
@@ -228,17 +255,18 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if (!$tags) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => "$kind_word tags",
|
||||
'title' => $show_archived ? "No archived $kind_word tags" : "No $kind_word tags yet",
|
||||
'text' => $show_archived ? 'An archived tag stays on its records, but isn\'t offered for tagging or in the filters.' : 'Tags sort and filter ' . $kind['plural'] . ' - "VIP", "Managed", "Retiring soon".',
|
||||
'icon' => 'fa-tags',
|
||||
'filtered' => $q !== '',
|
||||
'clear_url' => $page_url(['q' => null]),
|
||||
'actions' => $show_archived ? [] : [['label' => "New {$kind['title']} Tag", 'modal' => "modals/tag/tag_add.php?type=$type"]],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => "$kind_word tags",
|
||||
'icon' => 'fa-tags',
|
||||
'filtered' => $q !== '',
|
||||
'archived' => $show_archived,
|
||||
'views' => ['type', 'show'],
|
||||
'text' => 'Tags sort and filter ' . $kind['plural'] . ' - "VIP", "Managed", "Retiring soon".',
|
||||
'actions' => [['label' => "New {$kind['title']} Tag", 'modal' => "modals/tag/tag_add.php?type=$type"]],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,21 +11,41 @@
|
||||
* replaced it. A rate nothing has used can be deleted.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "tax_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$show_archived = isset($_GET['archived']);
|
||||
$search_sql = $q !== '' ? "AND (tax_name LIKE '%$q%' OR tax_description LIKE '%$q%' OR tax_registration_number LIKE '%$q%')" : '';
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT tax_id FROM taxes
|
||||
WHERE tax_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . " $search_sql
|
||||
ORDER BY " . ($show_archived ? 'tax_archived_at DESC, ' : '') . "tax_name ASC, tax_percent ASC"
|
||||
);
|
||||
// ?archived=1 is how older links asked for the archived ones
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']);
|
||||
|
||||
// Only these sort - an unknown column would take the page down. Used on sorts by the invoices with a line at it
|
||||
$sortable_columns = [
|
||||
'tax_name' => "tax_name $order, tax_percent ASC",
|
||||
'tax_percent' => "tax_percent $order, tax_name ASC",
|
||||
'invoice_count' => "invoice_count $order, tax_name ASC",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'tax_name';
|
||||
}
|
||||
|
||||
$search = "(tax_name LIKE '%$q%' OR tax_description LIKE '%$q%' OR tax_registration_number LIKE '%$q%')";
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS tax_id, COALESCE(invoices.invoice_count, 0) AS invoice_count
|
||||
FROM taxes
|
||||
LEFT JOIN (SELECT item_tax_id, COUNT(DISTINCT item_invoice_id) AS invoice_count FROM invoice_items WHERE item_tax_id > 0 GROUP BY item_tax_id) invoices ON invoices.item_tax_id = tax_id
|
||||
WHERE $search AND tax_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
ORDER BY {$sortable_columns[$sort]}, tax_id ASC
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$rates = [];
|
||||
while ($row = mysqli_fetch_row($sql)) {
|
||||
$rates[] = taxRow($row[0]);
|
||||
}
|
||||
$archived_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM taxes WHERE tax_archived_at IS NOT NULL"))[0]);
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(tax_archived_at IS NULL), 0), COALESCE(SUM(tax_archived_at IS NOT NULL), 0) FROM taxes WHERE $search"));
|
||||
$usage = taxUsageAll();
|
||||
$tax_settings = taxSettings();
|
||||
$active_taxes = billingTaxes();
|
||||
@@ -43,6 +63,11 @@ $used_text = function (array $u) {
|
||||
return $parts;
|
||||
};
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
@@ -54,32 +79,34 @@ $used_text = function (array $u) {
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/tax/tax_add.php" data-modal-size="lg"><i class="fas fa-plus me-2"></i>New Tax</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-header py-2">
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto me-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml(stripslashes($q)) ?>" placeholder="Search taxes">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="tax_rates.php">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="tax_rates.php?archived=1">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-7">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search taxes..." title="Name, description or registration number">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '']))) ?>"><i class="fas fa-fw fa-balance-scale me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => 'archived']))) ?>" title="Kept on what was billed with them, not offered for new lines"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover mb-0 align-middle">
|
||||
<?php if ($rates) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3">Tax</th>
|
||||
<th>Rate</th>
|
||||
<th>Used on</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="ps-3"><?= $sort_link('tax_name', 'Tax') ?></th>
|
||||
<th><?= $sort_link('tax_percent', 'Rate') ?></th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('invoice_count', 'Used on') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($rates as $rate) {
|
||||
$tax_id = intval($rate['tax_id']);
|
||||
@@ -89,45 +116,52 @@ $used_text = function (array $u) {
|
||||
$unused = !$used && !$u['default'] && taxUnused($tax_id); ?>
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<a class="ajax-modal fw-semibold" href="#" data-modal-url="modals/tax/tax_edit.php?id=<?= $tax_id ?>" data-modal-size="lg"><?= escapeHtml($rate['tax_name']) ?></a>
|
||||
<?php if ($u['default']) { ?>
|
||||
<span class="badge rounded-pill text-bg-primary ms-1" title="New lines get this rate unless the client or product has its own">Default</span>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_description']) { ?>
|
||||
<div class="small text-secondary"><?= escapeHtml($rate['tax_description']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_registration_number']) { ?>
|
||||
<div class="small text-secondary" title="Registration number - printed on invoices"><i class="fas fa-fw fa-id-card me-1"></i><?= escapeHtml($rate['tax_registration_number']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_archived_at']) { ?>
|
||||
<div class="small text-secondary">
|
||||
<i class="fas fa-fw fa-archive me-1"></i><?= $replaced_by ? 'Replaced by ' . escapeHtml(taxLabel($replaced_by)) . ' on ' : 'Archived ' ?><?= date('M j, Y', strtotime($rate['tax_archived_at'])) ?>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-tone-other d-none d-sm-inline-flex" aria-hidden="true"><i class="fas fa-fw fa-balance-scale"></i></span>
|
||||
<div class="min-w-0">
|
||||
<a class="ajax-modal fw-semibold text-body" href="#" data-modal-url="modals/tax/tax_edit.php?id=<?= $tax_id ?>" data-modal-size="lg"><?= escapeHtml($rate['tax_name']) ?></a>
|
||||
<?php if ($u['default']) { ?>
|
||||
<span class="badge rounded-pill text-bg-primary ms-1" title="New lines get this rate unless the client or product has its own">Default</span>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_description']) { ?>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($rate['tax_description']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_registration_number']) { ?>
|
||||
<div class="small text-body-secondary" title="Registration number - printed on invoices"><i class="fas fa-fw fa-id-card me-1"></i><?= escapeHtml($rate['tax_registration_number']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($rate['tax_archived_at']) { ?>
|
||||
<div class="small text-body-secondary">
|
||||
<i class="fas fa-fw fa-archive me-1"></i><?= $replaced_by ? 'Replaced by ' . escapeHtml(taxLabel($replaced_by)) . ' on ' : 'Archived ' ?><?= date('M j, Y', strtotime($rate['tax_archived_at'])) ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<!-- On a phone what uses it comes along under the name -->
|
||||
<div class="d-sm-none small text-body-secondary mt-1"><?= $used ? escapeHtml(implode(', ', $used)) : 'Not used yet' ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="fw-semibold"><?= taxPercentText($rate['tax_percent']) ?>%</span>
|
||||
<?php if ($rate['grouped']) { ?>
|
||||
<div class="small text-secondary">
|
||||
<div class="small text-body-secondary">
|
||||
<?php foreach ($rate['components'] as $i => $part) { ?>
|
||||
<?= $i ? '<span class="mx-1">+</span>' : '' ?><span class="text-nowrap"<?= $part['registration'] !== '' ? ' title="Registration number ' . escapeHtml($part['registration']) . '"' : '' ?>><?= escapeHtml($part['name']) ?> <?= taxPercentText($part['percent']) ?>%<?= $part['compound'] ? ' <em>on top</em>' : '' ?><?= $part['registration'] !== '' ? '<i class="fas fa-id-card ms-1"></i>' : '' ?></span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="small">
|
||||
<?= $used ? escapeHtml(implode(', ', $used)) : '<span class="text-secondary">Not used yet</span>' ?>
|
||||
<td class="d-none d-sm-table-cell small">
|
||||
<?= $used ? escapeHtml(implode(', ', $used)) : '<span class="text-body-secondary">Not used yet</span>' ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tax/tax_edit.php?id=<?= $tax_id ?>" data-modal-size="lg"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/tax/tax_edit.php?id=<?= $tax_id ?>" data-modal-size="lg"><i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit</a>
|
||||
<?php if ($rate['tax_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_tax=<?= $tax_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<a class="dropdown-item" href="post.php?restore_tax=<?= $tax_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore</a>
|
||||
<?php } else { ?>
|
||||
<?php if (!$u['default']) { ?>
|
||||
<a class="dropdown-item" href="post.php?default_tax=<?= $tax_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-star me-2"></i>Make default</a>
|
||||
<a class="dropdown-item" href="post.php?default_tax=<?= $tax_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-star text-secondary me-2"></i>Make default</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger ajax-modal" href="#" data-modal-url="modals/tax/tax_archive.php?id=<?= $tax_id ?>"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
@@ -144,17 +178,18 @@ $used_text = function (array $u) {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php if (!$rates) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => 'taxes',
|
||||
'title' => $show_archived ? 'No archived taxes' : 'No taxes yet',
|
||||
'text' => $show_archived ? '' : 'Sales tax, VAT or GST - one rate, or parts like a state\'s and a county\'s charged together.',
|
||||
'icon' => 'fa-balance-scale',
|
||||
'filtered' => $q !== '',
|
||||
'clear_url' => 'tax_rates.php' . ($show_archived ? '?archived=1' : ''),
|
||||
'actions' => $show_archived ? [] : [['label' => 'New Tax', 'modal' => 'modals/tax/tax_add.php', 'size' => 'lg']],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => 'taxes',
|
||||
'icon' => 'fa-balance-scale',
|
||||
'filtered' => $q !== '',
|
||||
'archived' => $show_archived,
|
||||
'views' => ['show'],
|
||||
'text' => 'Sales tax, VAT or GST - one rate, or parts like a state\'s and a county\'s charged together.',
|
||||
'actions' => [['label' => 'New Tax', 'modal' => 'modals/tax/tax_add.php', 'size' => 'lg']],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,44 +10,70 @@
|
||||
* in functions/ticket_template.php; the handlers are admin/post/ticket_template.php.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "ticket_template_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$show_archived = isset($_GET['archived']);
|
||||
$search = trim((string) ($_GET['q'] ?? ''));
|
||||
$search_sql = escapeSql($search);
|
||||
// ?archived=1 is how older links asked for the archived ones
|
||||
$show_archived = ($_GET['show'] ?? '') === 'archived' || !empty($_GET['archived']);
|
||||
|
||||
$templates = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_templates.*, category_name, category_color, category_icon, user_name AS assignee_name,
|
||||
// Only these sort - an unknown column would take the page down
|
||||
$sortable_columns = [
|
||||
'ticket_template_name' => "ticket_template_name $order",
|
||||
'task_count' => "task_count $order, ticket_template_name ASC",
|
||||
'used_count' => "used_count $order, ticket_template_name ASC",
|
||||
'last_used' => "last_used IS NULL, last_used $order, ticket_template_name ASC",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'ticket_template_name';
|
||||
}
|
||||
|
||||
$search = "(ticket_template_name LIKE '%$q%' OR ticket_template_description LIKE '%$q%' OR ticket_template_subject LIKE '%$q%')";
|
||||
|
||||
// Its use is the tickets raised from it that are not archived - as ticketTemplateUsage() counts them
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS ticket_templates.*, category_name, category_color, category_icon, user_name AS assignee_name,
|
||||
(SELECT COUNT(*) FROM task_templates WHERE task_template_ticket_template_id = ticket_templates.ticket_template_id) AS task_count,
|
||||
(SELECT COALESCE(SUM(task_template_completion_estimate), 0) FROM task_templates WHERE task_template_ticket_template_id = ticket_templates.ticket_template_id) AS task_minutes,
|
||||
(SELECT COUNT(*) FROM recurring_tickets WHERE recurring_ticket_ticket_template_id = ticket_templates.ticket_template_id) AS recurring_count,
|
||||
(SELECT COUNT(*) FROM project_template_ticket_templates WHERE project_template_ticket_templates.ticket_template_id = ticket_templates.ticket_template_id) AS project_count
|
||||
(SELECT COUNT(*) FROM project_template_ticket_templates WHERE project_template_ticket_templates.ticket_template_id = ticket_templates.ticket_template_id) AS project_count,
|
||||
COALESCE(used.used_count, 0) AS used_count, COALESCE(used.open_count, 0) AS open_count, used.last_used
|
||||
FROM ticket_templates
|
||||
LEFT JOIN categories ON category_id = ticket_template_category_id AND ticket_template_category_id > 0
|
||||
LEFT JOIN users ON user_id = ticket_template_assigned_to AND ticket_template_assigned_to > 0
|
||||
WHERE ticket_template_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
" . ($search !== '' ? "AND (ticket_template_name LIKE '%$search_sql%' OR ticket_template_description LIKE '%$search_sql%' OR ticket_template_subject LIKE '%$search_sql%')" : '') . "
|
||||
ORDER BY ticket_template_name ASC");
|
||||
LEFT JOIN (
|
||||
SELECT ticket_template_id AS used_template_id, COUNT(*) AS used_count, SUM(ticket_closed_at IS NULL AND ticket_resolved_at IS NULL) AS open_count, MAX(ticket_created_at) AS last_used
|
||||
FROM tickets WHERE ticket_template_id > 0 AND ticket_archived_at IS NULL GROUP BY ticket_template_id
|
||||
) used ON used.used_template_id = ticket_templates.ticket_template_id
|
||||
WHERE $search AND ticket_template_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
ORDER BY {$sortable_columns[$sort]}, ticket_templates.ticket_template_id ASC
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$templates = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$templates[intval($row['ticket_template_id'])] = $row;
|
||||
}
|
||||
$usage = ticketTemplateUsage(array_keys($templates));
|
||||
|
||||
// What each asks for - its fill-ins, from its rows and the bracketed words in its text
|
||||
$template_tasks = ticketTemplateTasksFor(array_keys($templates));
|
||||
$template_fill_in_rows = ticketTemplateFillInRowsFor(array_keys($templates));
|
||||
$archived_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM ticket_templates WHERE ticket_template_archived_at IS NOT NULL"))[0]);
|
||||
$tag_rows = [];
|
||||
$sql_tags = mysqli_query($mysqli, "SELECT ticket_template_id, tags.* FROM ticket_template_tags JOIN tags ON tags.tag_id = ticket_template_tags.tag_id ORDER BY tag_name");
|
||||
while ($row = mysqli_fetch_assoc($sql_tags)) {
|
||||
$tag_rows[intval($row['ticket_template_id'])][] = $row;
|
||||
if ($templates) {
|
||||
$sql_tags = mysqli_query($mysqli, "SELECT ticket_template_id, tags.* FROM ticket_template_tags JOIN tags ON tags.tag_id = ticket_template_tags.tag_id
|
||||
WHERE ticket_template_id IN (" . implode(',', array_keys($templates)) . ") ORDER BY tag_name");
|
||||
while ($row = mysqli_fetch_assoc($sql_tags)) {
|
||||
$tag_rows[intval($row['ticket_template_id'])][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// This page with some of its query changed - null drops a key
|
||||
$page_url = function (array $change = []) use ($show_archived, $search) {
|
||||
$query = array_merge(['q' => $search !== '' ? $search : null, 'archived' => $show_archived ? 1 : null], $change);
|
||||
return 'ticket_templates.php' . (($query = http_build_query(array_filter($query, function ($v) {
|
||||
return $v !== null;
|
||||
}))) ? "?$query" : '');
|
||||
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(ticket_template_archived_at IS NULL), 0), COALESCE(SUM(ticket_template_archived_at IS NOT NULL), 0) FROM ticket_templates WHERE $search"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
@@ -57,58 +83,66 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-life-ring me-2"></i>Ticket Templates</h3>
|
||||
<div class="card-tools d-flex gap-2">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/ticket_template/ticket_template_add.php" data-modal-size="lg"><i class="fas fa-plus me-2"></i>New Ticket Template</button>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-light" type="button" data-bs-toggle="dropdown" title="More"><i class="fas fa-fw fa-ellipsis-h"></i></button>
|
||||
<div class="card-tools">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/ticket_template/ticket_template_add.php">
|
||||
<i class="fas fa-plus"></i><span class="d-none d-lg-inline ms-2">New Ticket Template</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-label="More"></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket_template/ticket_template_import.php"><i class="fas fa-fw fa-file-upload me-2"></i>Import</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket_template/ticket_template_export.php"><i class="fas fa-fw fa-file-download me-2"></i>Export</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket_template/ticket_template_import.php">
|
||||
<i class="fas fa-fw fa-file-upload text-secondary me-2"></i>Import
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket_template/ticket_template_export.php">
|
||||
<i class="fas fa-fw fa-file-download text-secondary me-2"></i>Export
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="/agent/reports/ticket_templates.php"><i class="fas fa-fw fa-chart-bar me-2"></i>How they are used</a>
|
||||
<a class="dropdown-item" href="starter_content.php"><i class="fas fa-fw fa-seedling me-2"></i>Starter templates</a>
|
||||
<a class="dropdown-item" href="/agent/reports/ticket_templates.php">
|
||||
<i class="fas fa-fw fa-chart-bar text-secondary me-2"></i>How they are used
|
||||
</a>
|
||||
<a class="dropdown-item" href="starter_content.php">
|
||||
<i class="fas fa-fw fa-seedling text-secondary me-2"></i>Starter templates
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-2 border-bottom">
|
||||
<p class="small text-secondary mb-2">
|
||||
A ticket ready to raise - its subject, details and tasks, and how it is set up. Pick one on New Ticket, when raising tickets for several assets or clients, and on recurring tickets;
|
||||
project templates raise theirs. <span class="font-monospace">[Client]</span>, <span class="font-monospace">[Contact]</span>, <span class="font-monospace">[Month]</span> and the like are filled in when a ticket is raised.
|
||||
</p>
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search templates">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Current or archived">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="show" value="archived"><?php } ?>
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-5">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search ticket templates..." title="Name, description or subject">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2">
|
||||
<a class="nav-link <?= $show_archived ? '' : 'active' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '']))) ?>"><i class="fas fa-fw fa-life-ring me-1"></i>Active <span class="badge rounded-pill ms-1"><?= intval($counts[0]) ?></span></a>
|
||||
<a class="nav-link <?= $show_archived ? 'active' : '' ?>" href="?<?= escapeHtml(http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'show' => 'archived']))) ?>" title="Not offered for new tickets - recurring tickets and project templates that use them keep them"><i class="fas fa-fw fa-archive me-1"></i>Archived <span class="badge rounded-pill ms-1"><?= intval($counts[1]) ?></span></a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($templates) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3">Template</th>
|
||||
<th class="d-none d-lg-table-cell">Sets up</th>
|
||||
<th class="d-none d-sm-table-cell">Tasks</th>
|
||||
<th class="d-none d-md-table-cell">Used</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="ps-3"><?= $sort_link('ticket_template_name', 'Template') ?></th>
|
||||
<th class="d-none d-lg-table-cell">Sets up</th>
|
||||
<th class="d-none d-sm-table-cell text-center"><?= $sort_link('task_count', 'Tasks') ?></th>
|
||||
<th class="d-none d-md-table-cell"><?= $sort_link('used_count', 'Used') ?></th>
|
||||
<th class="d-none d-md-table-cell"><?= $sort_link('last_used', 'Last used') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($templates as $template_id => $row) {
|
||||
$name = escapeHtml($row['ticket_template_name']);
|
||||
$task_count = intval($row['task_count']);
|
||||
$minutes = intval($row['task_minutes']);
|
||||
$used = $usage[$template_id] ?? ['count' => 0, 'open' => 0, 'last' => null];
|
||||
$used_count = intval($row['used_count']);
|
||||
$open_count = intval($row['open_count']);
|
||||
$tags = $tag_rows[$template_id] ?? [];
|
||||
$defaults = ticketTemplateDefaultsHtml($row);
|
||||
$fill_in_count = count(ticketTemplateFillIns($row, $template_tasks[$template_id] ?? [], $template_fill_in_rows[$template_id] ?? []));
|
||||
@@ -127,15 +161,7 @@ $csrf = $_SESSION['csrf_token'];
|
||||
if (intval($row['project_count'])) {
|
||||
$linked[] = intval($row['project_count']) . ' project template' . (intval($row['project_count']) === 1 ? '' : 's');
|
||||
}
|
||||
ob_start(); ?>
|
||||
<?php if ($used['count']) { ?>
|
||||
<div class="small text-nowrap"><?= $used['count'] ?> ticket<?= $used['count'] === 1 ? '' : 's' ?><?= $used['open'] ? ' <span class="text-secondary">· ' . $used['open'] . ' open</span>' : '' ?></div>
|
||||
<div class="small text-secondary text-nowrap" title="<?= escapeHtml($used['last']) ?>">Last <?= timeAgo($used['last']) ?></div>
|
||||
<?php } else { ?>
|
||||
<span class="small text-secondary">Not yet</span>
|
||||
<?php } ?>
|
||||
<?php if ($linked) { ?><div class="small text-secondary"><i class="fas fa-fw fa-link me-1"></i><?= escapeHtml(implode(', ', $linked)) ?></div><?php } ?>
|
||||
<?php $used_html = ob_get_clean();
|
||||
$used_text = $used_count . ' ticket' . ($used_count === 1 ? '' : 's');
|
||||
?>
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
@@ -144,46 +170,66 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold text-body" href="ticket_template.php?ticket_template_id=<?= $template_id ?>"><?= $name ?></a>
|
||||
<?php if (trim((string) $row['ticket_template_description']) !== '') { ?>
|
||||
<div class="small text-secondary"><?= escapeHtml($row['ticket_template_description']) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($row['ticket_template_description']) ?></div>
|
||||
<?php } elseif (trim((string) $row['ticket_template_subject']) !== '') { ?>
|
||||
<div class="small text-secondary text-truncate"><?= escapeHtml($row['ticket_template_subject']) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($row['ticket_template_subject']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($row['ticket_template_archived_at']) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['ticket_template_archived_at'])) ?></div>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['ticket_template_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
<!-- On smaller screens what it sets up and its use come along under the name -->
|
||||
<?php if ($set_up !== '') { ?><div class="d-lg-none mt-1"><?= $set_up ?></div><?php } ?>
|
||||
<div class="d-md-none mt-1"><?= $used_html ?></div>
|
||||
<div class="d-md-none small text-body-secondary mt-1"><?= $used_count ? $used_text . ' · last ' . timeAgo($row['last_used']) : 'Not used yet' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="d-none d-lg-table-cell"><?= $set_up !== '' ? $set_up : '<span class="small text-secondary">Just the subject and details</span>' ?></td>
|
||||
<td class="d-none d-sm-table-cell text-nowrap">
|
||||
<td class="d-none d-lg-table-cell"><?= $set_up !== '' ? $set_up : '<span class="small text-body-secondary">Just the subject and details</span>' ?></td>
|
||||
<td class="d-none d-sm-table-cell text-center text-nowrap">
|
||||
<?php if ($task_count) { ?>
|
||||
<div class="small"><?= $task_count ?> task<?= $task_count === 1 ? '' : 's' ?></div>
|
||||
<?php if ($minutes) { ?><div class="small text-secondary"><i class="far fa-fw fa-clock me-1"></i><?= escapeHtml(ticketTemplateMinutesText($minutes)) ?></div><?php } ?>
|
||||
<div><?= $task_count ?></div>
|
||||
<?php if ($minutes) { ?><div class="small text-body-secondary"><i class="far fa-fw fa-clock me-1"></i><?= escapeHtml(ticketTemplateMinutesText($minutes)) ?></div><?php } ?>
|
||||
<?php } else { ?>
|
||||
<span class="small text-secondary">None</span>
|
||||
<span class="text-body-secondary">-</span>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell"><?= $used_html ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<td class="d-none d-md-table-cell">
|
||||
<?php if ($used_count) { ?>
|
||||
<div class="small text-nowrap"><?= $used_text ?><?= $open_count ? ' <span class="text-body-secondary">· ' . $open_count . ' open</span>' : '' ?></div>
|
||||
<?php } else { ?>
|
||||
<span class="small text-body-secondary">Not yet</span>
|
||||
<?php } ?>
|
||||
<?php if ($linked) { ?><div class="small text-body-secondary"><i class="fas fa-fw fa-link me-1"></i><?= escapeHtml(implode(', ', $linked)) ?></div><?php } ?>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell small text-body-secondary text-nowrap"<?= $row['last_used'] ? ' title="' . escapeHtml($row['last_used']) . '"' : '' ?>><?= $row['last_used'] ? timeAgo($row['last_used']) : '-' ?></td>
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/ticket_template/ticket_template_edit.php?id=<?= $template_id ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/ticket_template/ticket_template_edit.php?id=<?= $template_id ?>">
|
||||
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<?php if (!$row['ticket_template_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="/agent/tickets.php?new_from_template=<?= $template_id ?>"><i class="fas fa-fw fa-plus me-2"></i>New ticket from it</a>
|
||||
<a class="dropdown-item" href="/agent/tickets.php?new_from_template=<?= $template_id ?>">
|
||||
<i class="fas fa-fw fa-plus text-secondary me-2"></i>New ticket from it
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="post.php?copy_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="A new template starting from this one"><i class="fas fa-fw fa-copy me-2"></i>Copy</a>
|
||||
<a class="dropdown-item" href="post.php?copy_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="A new template starting from this one">
|
||||
<i class="fas fa-fw fa-copy text-secondary me-2"></i>Copy
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($row['ticket_template_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<a class="dropdown-item" href="post.php?restore_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="Not offered for new tickets - recurring tickets and project templates that use it keep it"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="Not offered for new tickets - recurring tickets and project templates that use it keep it">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Its tasks go with it<?= $linked ? ', and ' . escapeHtml(implode(' and ', $linked)) . ' stop using it' : '' ?>. Tickets raised from it stay as they are." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Its tasks go with it<?= $linked ? ', and ' . escapeHtml(implode(' and ', $linked)) . ' stop using it' : '' ?>. Tickets raised from it stay as they are." data-confirm-button="Delete">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@@ -192,18 +238,18 @@ $csrf = $_SESSION['csrf_token'];
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php if (!$templates) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => 'ticket templates',
|
||||
'title' => $show_archived ? 'No archived ticket templates' : 'No ticket templates yet',
|
||||
'text' => $show_archived ? 'An archived template isn\'t offered for new tickets, but the recurring tickets and project templates that use it keep it.' : 'A ticket ready to raise - its subject, details and tasks, and how it is set up.',
|
||||
'icon' => 'fa-life-ring',
|
||||
'filtered' => $search !== '',
|
||||
'clear_url' => $page_url(['q' => null]),
|
||||
'actions' => $show_archived ? [] : [['label' => 'New Ticket Template', 'modal' => 'modals/ticket_template/ticket_template_add.php', 'size' => 'lg']],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => 'ticket templates',
|
||||
'icon' => 'fa-life-ring',
|
||||
'filtered' => $q !== '',
|
||||
'archived' => $show_archived,
|
||||
'views' => ['show'],
|
||||
'text' => 'A ticket ready to raise - its subject, details and tasks, and how it is set up. <span class="font-monospace">[Client]</span>, <span class="font-monospace">[Contact]</span>, <span class="font-monospace">[Month]</span> and the like are filled in when a ticket is raised.',
|
||||
'actions' => [['label' => 'New Ticket Template', 'modal' => 'modals/ticket_template/ticket_template_add.php', 'size' => 'lg']],
|
||||
];
|
||||
require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -9,24 +9,7 @@
|
||||
* Shared by admin/api_keys.php, admin/modals/api/* and admin/post/api_keys.php.
|
||||
*/
|
||||
|
||||
/** The keys, by name - the row with its agent's name, picture, type, status, archived and role. */
|
||||
function apiKeyRows($search = '') {
|
||||
global $mysqli;
|
||||
$where = $search !== '' ? "WHERE api_key_name LIKE '%" . escapeSql($search) . "%' OR user_name LIKE '%" . escapeSql($search) . "%'" : '';
|
||||
$rows = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT api_key_id, api_key_name, api_key_secret, api_key_created_at, api_key_expire, api_key_user_id, api_key_last_used_at,
|
||||
user_name, user_avatar, user_type, user_status, user_archived_at, user_role_id
|
||||
FROM api_keys
|
||||
LEFT JOIN users ON user_id = api_key_user_id
|
||||
$where
|
||||
ORDER BY api_key_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$rows[intval($row['api_key_id'])] = $row;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/* One key as apiKeyRows() gives it, or null. */
|
||||
/* One key - the row with its agent's name, picture, type, status, archived and role - or null. Admin > API Keys lists them the same way. */
|
||||
function apiKeyRow($api_key_id) {
|
||||
global $mysqli;
|
||||
$api_key_id = intval($api_key_id);
|
||||
|
||||
Reference in New Issue
Block a user