Categories stage 2: every form and Bulk Action window picks a category the same way through categoryPicker and categoryOptionsHtml, in the kind's order with each category's color, icon and description, keeping a record's archived category marked (archived) and a status, type or referral that isn't a category marked (not set up) so saving changes neither; the + beside a category picker is admins only and opens the category window stacked over the form, saving in the background as JSON, picking the new category and leaving the form as it was, with a taken name shown in the window, on every form that picks one including a ticket's quote and invoice, Unbilled Time, payment providers, canned responses, the mileage setting and the Bulk Action windows; stacked windows shade the one underneath; agent/post/category.php removed so the window posts to admin/post.php from any page; typed referrals go through categoryEnsure, taking an existing referral's spelling in any case, matching archived ones and no longer making an empty referral on client add, edit and import; fixes the + reloading the page and losing the form, the quote made from a ticket creating an expense category, and a stray < in the license template type picker; changelog updated

This commit is contained in:
johnnyq
2026-10-17 20:41:26 -04:00
parent 8a992039fb
commit 2b087c8f46
54 changed files with 395 additions and 498 deletions

View File

@@ -144,6 +144,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- A category can only be deleted while nothing uses it - merge it into another, or archive it. Deleting one in use used to leave expenses, invoices and tickets with no category, and clients and assets with a name that could no longer be picked. Delete is now on current categories too, not only archived ones.
- A category's name is now unique within its kind, in any case: a second expense category called Travel can't be made, though an income category can be. Categories already named alike keep their names.
- Interface types and rack types are held to 50 characters, which is all an interface or a rack keeps.
- The + beside a category picker shows for admins only, on every form. It opened Admin's New Category window, which refused anyone else. Agents typing a referral that isn't one yet into a client's form still make it, as before.
- Notifications now follow access too. An agent only sees notifications for clients and areas they can open, so someone without sales access no longer sees invoice and quote notifications.
- Drop-downs: Tom Select is gone, replaced by ITFlow's own picker. It works the way you are used to: type to search, tick several in a multi-select, and type a new value in fields that allow it, such as ticket watchers. See Developer Updates if you have custom pages that used Tom Select.
- Several small windows are gone because the change is now made where the value is shown:
@@ -794,6 +795,10 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- Merge moves everything with the merged categories onto the one you keep, and the others are deleted: expenses, recurring expenses, budget months (a month budgeted under both becomes one line of their total), import rules, a payment provider's fees and the mileage setting, invoices, quotes, recurring invoices, other income, products, tickets, recurring tickets and canned responses - and for the kinds kept by name, the clients, assets, interfaces, licenses, license templates, racks and notes that have them.
- Names that records have but aren't categories - notes typed General, referrals entered before there was a list - are listed under the kind's categories with how many have each, linked to them where there is a list, and Add makes one a category. To fold one into another, add it, then merge it.
- Renaming or merging doesn't mark the records it changes as edited.
- Every form that picks a category picks it the same way, from the categories in the order they are offered in, each with its color, its icon and its description underneath. A record keeps a category archived since it was picked, marked (archived), and a status, type or referral it has that isn't a category, marked (not set up), so saving it changes neither.
- The + beside a category picker opens the category window over the form. What you make there is picked in the picker and the window closes, leaving the form as it was - nothing reloads and nothing typed is lost. A name that is taken is said in the window. It is on every form that picks one: expenses, recurring expenses, other income, invoices, quotes and recurring invoices (and a ticket's quote and invoice, and Unbilled Time), products, tickets and recurring tickets, a client's referral, an asset's status, an interface's type, a license's and a license template's type, a rack's type, a contact or asset note's type, payment providers, canned responses and the mileage setting - and their Bulk Action windows.
- A referral typed into a client's form that matches one in another case takes its spelling.
- A window opened over another shades the one underneath, rather than drawing its shade behind it.
### Bug Fixes
@@ -884,6 +889,9 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- Tags: the Archived button on Admin > Tags showed the same tags as without it, as nothing could be archived.
- Categories: editing a category whose color was saved as a word, such as lightblue, turned it black, as the color picker can't show words. The ticket list, a ticket's quick look and the recurring tickets list left those colors out, and the reports drew them in a color of their own.
- Categories: the icons of contact and asset note types didn't show in the type pickers, and making a category from the + beside a category picker left out its description.
- Categories: the + beside a category picker reloaded the page once the category was made, losing the form that was being filled in. On the quote made from a ticket it made an expense category, for a picker of income categories.
- Clients: saving a client with no referral made a referral with no name, and typing one that matched an archived referral made a second of it.
- License templates: the type picker showed a stray "<" at the top.
- Admin > Settings > Defaults: Payment Method and Expense Payment Method listed the payment method categories that moved to Admin > Payment Methods in 2.3.1, so a new install had nothing to pick. They list Admin > Payment Methods now.
- Messages, hints and window titles were reworded where they were unclear, and bulk windows say "1 asset" or "3 assets" correctly.
@@ -1268,7 +1276,11 @@ If you are coming from 26.08 or earlier, the database update still has to be run
- 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.
- `agent/post/category.php` (what the + window posts to from an agent page) takes the same fields through `categoryFromInput()` and is admins only, like the window. Removed: `admin/post/category_model.php` and `agent/post/category_model.php`.
- 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 list filters and exports are unchanged.
- 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`.
- `categoryEnsure($kind, $name)` - a name typed for a kind held by name as its category's own spelling, matched in any case, archived or not, or made (with the next color, logged); `''` for none. `add_client`, `edit_client` and the client import use it for the referral, in place of their own insert.
- `js/app.js`: a modal shown over another (`show.bs.modal`) takes a z-index 20 above it, its backdrop just under it, and `modal-open` goes back on the body when the top one closes.
- `selectOptionColor()` turns an icon kept as `fa-name` into `fas fa-name`.
- `admin/settings_default.php` reads `paymentMethods()`, keeping a saved value that is no longer one.
- CSS: `.itflow-category`, `-mark`, `-name` and `-badge` (`categoryChip()`), `.itflow-category-swatch-none`, `.itflow-category-kinds` and `.itflow-category-grip`.

View File

@@ -28,16 +28,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="category">
<option value="0">- All ticket categories -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id_select = intval($row['category_id']);
$category_name_select = escapeHtml($row['category_name']); ?>
<option value="<?= $category_id_select ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
<small class="text-secondary">Leave this on all categories for a response that should be offered on every ticket.</small>
</div>

View File

@@ -42,16 +42,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="category">
<option value="0" <?php if ($canned_response_category_id == 0) { echo "selected"; } ?>>- All ticket categories -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($category_row = mysqli_fetch_assoc($sql_categories)) {
$category_id_select = intval($category_row['category_id']);
$category_name_select = escapeHtml($category_row['category_name']); ?>
<option value="<?= $category_id_select ?>" <?php if ($canned_response_category_id == $category_id_select) { echo "selected"; } ?><?= selectOptionColor($category_row['category_color'] ?? '', $category_row['category_icon'] ?? '') ?>><?= $category_name_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket', $canned_response_category_id) ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
<small class="text-secondary">Leave this on all categories for a response that should be offered on every ticket.</small>
</div>

View File

@@ -2,8 +2,10 @@
/*
* New category - from Admin > Categories (?category= the kind), or the +
* beside a category picker in a form (which posts to the agent's post.php).
* The fields are category_form.php.
* beside a category picker in a form (categoryAddButtonHtml(), &inline=1),
* where js/category_form.js saves it in the background and puts it in that
* picker, picked, leaving the form as it was. The fields are
* category_form.php.
*/
require_once '../../includes/modal_header.php';
@@ -11,6 +13,7 @@ require_once '../../includes/modal_header.php';
$category = null;
$kind = categoryKind($_GET['category'] ?? '') ? (string) $_GET['category'] : '';
$kind_config = $kind !== '' ? categoryKind($kind) : null;
$inline = !empty($_GET['inline']);
ob_start();
@@ -20,10 +23,12 @@ ob_start();
<h5 class="modal-title"><i class="fas fa-fw <?= $kind_config['icon'] ?? 'fa-list-ul' ?> me-2"></i>New <?= escapeHtml($kind_config ? ucwords($kind_config['one']) : 'Category') ?></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<form action="/admin/post.php" method="post" autocomplete="off"<?= $inline ? ' data-category-inline' : '' ?>>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php if ($inline) { ?><input type="hidden" name="inline" value="1"><?php } ?>
<div class="modal-body">
<div class="alert alert-danger small py-2" role="alert" data-category-error hidden></div>
<?php require __DIR__ . '/category_form.php'; ?>
</div>
<div class="modal-footer">

View File

@@ -23,7 +23,7 @@ if (!$category) { ?>
<h5 class="modal-title"><i class="fas fa-fw <?= $kind_config['icon'] ?? 'fa-list-ul' ?> me-2"></i><?= escapeHtml(ucwords($kind_config['one'] ?? 'Category')) ?>: <strong><?= escapeHtml($category['category_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<form action="/admin/post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="category_id" value="<?= $category_id ?>">

View File

@@ -70,7 +70,7 @@ ob_start();
<?php } elseif (!$into) { ?>
<div class="modal-body text-center text-secondary py-5">There's no other <?= escapeHtml($config['one']) ?> to merge it into yet.</div>
<?php } else { ?>
<form action="post.php" method="post" autocomplete="off">
<form action="/admin/post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($merging as $merge_id => $row) { ?>
<input type="hidden" name="category_ids[]" value="<?= $merge_id ?>">

View File

@@ -132,22 +132,12 @@ ob_start();
<select class="form-select select2" name="expense_category" required>
<option value="">- Select a Category -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Expense' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option <?php if ($category_name === 'Processing Fee') { echo "selected"; } ?> value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php
}
// Processing Fee to start with, when there is one
$fee_category = mysqli_fetch_row(mysqli_query($mysqli, "SELECT category_id FROM categories WHERE category_type = 'Expense' AND category_name = 'Processing Fee' AND category_archived_at IS NULL LIMIT 1"));
?>
<?= categoryOptionsHtml('Expense', $fee_category ? intval($fee_category[0]) : null) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Expense">
<i class="fas fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Expense', 'btn btn-secondary') ?>
</div>
<small class="form-text text-muted">Processing Fee, Credit Card Fee etc</small>
</div>

View File

@@ -134,23 +134,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select select2" name="expense_category" required>
<option value="">- Select a Category -</option>
<?php
$sql_category = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Expense' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_category)) {
$category_id_select = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option <?php if ($category_id === $category_id_select) { echo "selected"; } ?> value="<?= $category_id_select ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php
}
?>
<?= categoryOptionsHtml('Expense', $category_id) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Expense">
<i class="fas fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Expense', 'btn btn-secondary') ?>
</div>
<small class="form-text text-muted">Processing Fee, Credit Card Fee etc</small>
</div>

View File

@@ -48,19 +48,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="type" required>
<option value="">- Select Type -</option>
<<?php
$sql_software_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'software_type'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_software_types_select)) {
$software_type_select = escapeHtml($row['category_name']);
?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $software_type_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('software_type') ?>
</select>
<?= categoryAddButtonHtml('software_type', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -64,21 +64,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="type" required>
<option value="">- Select Type -</option>
<<?php
$sql_software_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'software_type'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_software_types_select)) {
$software_type_select = escapeHtml($row['category_name']);
?>
<option <?php if($software_type == $software_type_select) { echo "selected"; } ?><?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>>
<?= $software_type_select ?>
</option>
<?php } ?>
<?= categoryOptionsHtml('software_type', html_entity_decode($software_type, ENT_QUOTES, 'UTF-8')) ?>
</select>
<?= categoryAddButtonHtml('software_type', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -21,8 +21,16 @@ if (isset($_POST['add_category'])) {
validateCSRFToken();
// From the + beside a picker in a form - answered with JSON, the picker's new option included (js/category_form.js)
$inline = !empty($_POST['inline']);
[$fields, $error] = categoryFromInput($_POST);
if ($error !== '') {
if ($inline) {
header('Content-Type: application/json');
echo json_encode(['ok' => false, 'error' => $error]);
exit;
}
flashAlert(escapeHtml($error), 'error');
redirect();
}
@@ -32,9 +40,22 @@ if (isset($_POST['add_category'])) {
logAudit("Category", "Create", "$session_name created $kind " . escapeSql($fields['name']), 0, $category_id);
if ($inline) {
$row = categoryRow($category_id);
header('Content-Type: application/json');
echo json_encode([
'ok' => true,
'value' => categoryKind($fields['type'])['by'] === 'name' ? $row['category_name'] : (string) $category_id,
'option' => categoryOptionHtml($row, true),
'message' => ucfirst($kind) . ' ' . $row['category_name'] . ' created',
]);
exit;
}
flashAlert(ucfirst($kind) . " <strong>" . escapeHtml($fields['name']) . "</strong> created");
redirect($category_page($fields['type']));
// Back to its kind in Admin > Categories, or to the page the window was opened on
redirect(str_contains($_SERVER['HTTP_REFERER'] ?? '', '/admin/categories.php') ? $category_page($fields['type']) : null);
}

View File

@@ -308,12 +308,11 @@ require_once "includes/inc_all_admin.php";
<label>Mileage goes under</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select" name="config_mileage_category_id">
<select class="form-select select2" name="config_mileage_category_id">
<option value="0">- Mileage, or Travel -</option>
<?php foreach (expenseCategories($trip_rules['category_id']) as $category_id => $category) { ?>
<option value="<?= intval($category_id) ?>" <?= intval($category_id) === $trip_rules['category_id'] ? 'selected' : '' ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Expense', $trip_rules['category_id']) ?>
</select>
<?= categoryAddButtonHtml('Expense', 'btn btn-secondary') ?>
</div>
<small class="text-secondary">The expense category of the mileage paid back. The expenses are to the vendor Mileage, made the first time.</small>
</div>

View File

@@ -57,17 +57,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="bulk_category">
<option value="0">- Not Categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -26,19 +26,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-circle"></i></span>
<select class="form-select select2" name="bulk_status">
<option value="">- Select Status -</option>
<?php
$sql_interface_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'asset_status'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_interface_types_select)) {
$asset_status_select = escapeHtml($row['category_name']);
?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $asset_status_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('asset_status') ?>
</select>
<?= categoryAddButtonHtml('asset_status', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -18,18 +18,10 @@
isset($mysqli) || die("Direct file access is not allowed");
// Status - from Admin > Categories, keeping a retired value that is still set
$status_options = [];
$sql_status_select = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'asset_status' AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC");
// Status - from Admin > Categories, keeping one the asset has that is archived or isn't a status any more
$status_colors = [];
while ($row = mysqli_fetch_assoc($sql_status_select)) {
$status_options[escapeHtml($row['category_name'])] = selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '');
$status_colors[$row['category_name']] = assetStatusColor($row['category_name'], $row['category_color'] ?? '');
}
if ($asset_status !== '' && !isset($status_options[$asset_status])) {
$status_options[$asset_status] = '';
foreach (categoryPicker('asset_status', [html_entity_decode($asset_status)]) as $status_name => $status_row) {
$status_colors[$status_name] = assetStatusColor($status_name, $status_row['category_color'] ?? '');
}
// The client's own lists - only once the client is known
@@ -169,10 +161,9 @@ $asset_form_icons = [
<span class="input-group-text"><i class="fas fa-circle fa-fw" data-asset-form-icon="status" style="color: <?= $asset_form_icons['status'] ?>"></i></span>
<select class="form-select select2" name="status">
<option value="">- Status -</option>
<?php foreach ($status_options as $status_option => $status_option_data) { ?>
<option <?php if ($status_option === $asset_status) { echo "selected"; } ?><?= $status_option_data ?>><?= $status_option ?></option>
<?php } ?>
<?= categoryOptionsHtml('asset_status', html_entity_decode($asset_status)) ?>
</select>
<?= categoryAddButtonHtml('asset_status', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-md-7">

View File

@@ -29,19 +29,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
<select class="form-select select2" id="interface_type" name="bulk_type">
<option value="">- No type -</option>
<?php
$sql_interface_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'network_interface'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_interface_types_select)) {
$interface_type_select = escapeHtml($row['category_name']);
?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $interface_type_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('network_interface') ?>
</select>
<?= categoryAddButtonHtml('network_interface', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -26,7 +26,6 @@ $form_id = 'interfaceForm' . ($form_interface_id ?: 'New');
$networks = interfaceNetworkOptions($form_client_id, $form_network_id);
$connections = interfaceConnectionOptions($form_client_id, $form_asset_id, $form_interface_id);
$types = interfaceTypes();
$form_type = (string) ($form['interface_type'] ?? '');
?>
@@ -68,13 +67,9 @@ $form_type = (string) ($form['interface_type'] ?? '');
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
<select class="form-select select2" name="type">
<option value="">- No type -</option>
<?php foreach ($types as $type => [$color, $icon]) { ?>
<option <?= $form_type === $type ? 'selected' : '' ?><?= selectOptionColor($color ?? '', $icon ?? '') ?>><?= escapeHtml($type) ?></option>
<?php }
if ($form_type !== '' && !isset($types[$form_type])) { ?>
<option selected><?= escapeHtml($form_type) ?></option>
<?php } ?>
<?= categoryOptionsHtml('network_interface', $form_type) ?>
</select>
<?= categoryAddButtonHtml('network_interface', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-md-7">

View File

@@ -102,10 +102,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-plug"></i></span>
<select class="form-select select2" name="type">
<option value="">- No type -</option>
<?php foreach ($types as $type => [$color, $icon]) { ?>
<option <?= $type === 'Ethernet' ? 'selected' : '' ?><?= selectOptionColor($color ?? '', $icon ?? '') ?>><?= escapeHtml($type) ?></option>
<?php } ?>
<?= categoryOptionsHtml('network_interface', isset($types['Ethernet']) ? 'Ethernet' : null) ?>
</select>
<?= categoryAddButtonHtml('network_interface', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-md-7">

View File

@@ -33,19 +33,9 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
<select class="form-select select2" name="type">
<?php
$sql_asset_note_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'asset_note_type'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_asset_note_types_select)) {
$asset_note_type_select = escapeHtml($row['category_name']);
?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $asset_note_type_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('asset_note_type') ?>
</select>
<?= categoryAddButtonHtml('asset_note_type', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -27,7 +27,6 @@ $form_value = function ($column, $default = '') use ($form_row, $form_c) {
};
$form_currency = $form_edit ? (string) $form_row["{$form_c}_currency_code"] : (string) $session_company_currency;
$form_category_id = intval($form_value('category_id', '0'));
$form_categories = billingCategories($form_edit ? $form_value('created_at') : null);
$form_discount = floatval($form_value('discount_amount', '0'));
// Net terms for a new invoice's due date - the client's (0 is On Receipt), as
@@ -91,13 +90,9 @@ $form_scope_placeholder = [
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="category" required>
<option value="">- Category -</option>
<?php foreach ($form_categories as $category_id => $category) { ?>
<option value="<?= intval($category_id) ?>" <?= $form_category_id === intval($category_id) ? 'selected' : '' ?><?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income', $form_category_id, ['since' => $form_edit ? $form_value('created_at') : null]) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Income">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -5,9 +5,6 @@ require_once '../../../includes/modal_header.php';
// Filters
$leads_filter = intval($_GET['lead'] ?? 0);
// Selects
$referral_sql = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = 'Referral' AND category_archived_at IS NULL ORDER BY category_name ASC");
$net_terms_array = array (
'0'=>'On Receipt',
'7'=>'7 Days',
@@ -92,18 +89,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-link"></i></span>
<select class="form-select select2" data-tags="true" name="referral">
<option value="">- Select Referral -</option>
<?php
while ($row = mysqli_fetch_assoc($referral_sql)) {
$referral = escapeHtml($row['category_name']); ?>
<option><?= $referral ?></option>
<?php } ?>
<?= categoryOptionsHtml('Referral') ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Referral">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Referral', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -58,17 +58,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="bulk_category">
<option value="0">- Not Categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -26,18 +26,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-link"></i></span>
<select class="form-select select2" name="bulk_referral">
<option value="">- Select a Referral -</option>
<?php
$referral_sql = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories WHERE category_type = 'Referral' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($referral_sql)) {
$referral = escapeHtml($row['category_name']); ?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $referral ?></option>
<?php } ?>
<?= categoryOptionsHtml('Referral') ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="/admin/modals/category/category_add.php?category=Referral">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Referral', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -20,6 +20,7 @@ $client_is_lead = intval($row['client_lead']);
$client_type = escapeHtml($row['client_type']);
$client_website = escapeHtml($row['client_website']);
$client_referral = escapeHtml($row['client_referral']);
$row_referral = (string) $row['client_referral'];
$client_net_terms = intval($row['client_net_terms']);
$client_reminders = intval($row['client_reminders'] ?? 1);
$client_tax_id_number = escapeHtml($row['client_tax_id_number']);
@@ -123,26 +124,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-link"></i></span>
<select class="form-select select2" data-tags="true" name="referral">
<option value="">- Select Referral -</option>
<?php
$referral_sql = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories WHERE category_type = 'Referral' AND (category_archived_at > '$client_created_at' OR category_archived_at IS NULL) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($referral_sql)) {
$referral = escapeHtml($row['category_name']);
?>
<option <?php if ($client_referral == $referral) {
echo "selected";
} ?><?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>>
<?= $referral ?>
</option>
<?php
}
?>
<?= categoryOptionsHtml('Referral', $row_referral) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Referral">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Referral', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -33,19 +33,9 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-comment"></i></span>
<select class="form-select select2" name="type">
<?php
$sql_contact_note_types_select = mysqli_query($mysqli, "
SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'contact_note_type'
AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC
");
while ($row = mysqli_fetch_assoc($sql_contact_note_types_select)) {
$contact_note_type_select = escapeHtml($row['category_name']);
?>
<option<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $contact_note_type_select ?></option>
<?php } ?>
<?= categoryOptionsHtml('contact_note_type') ?>
</select>
<?= categoryAddButtonHtml('contact_note_type', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -52,10 +52,9 @@ ob_start();
<?php if ($field === 'category') { ?>
<select class="form-select select2" name="value" required>
<option value="">- Pick a category -</option>
<?php foreach (expenseCategories() as $category_id => $category) { ?>
<option value="<?= $category_id ?>"<?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Expense') ?>
</select>
<?= categoryAddButtonHtml('Expense', 'btn btn-secondary') ?>
<?php } elseif ($field === 'account') { ?>
<select class="form-select select2" name="value" required>
<option value="">- Pick an account -</option>

View File

@@ -56,7 +56,6 @@ if ($form_refund) {
$form_currency = $form_row ? $form_value('expense_currency_code') : (string) $session_company_currency;
$form_vendors = expenseVendors($form_edit ? $form_vendor : 0);
$form_categories = expenseCategories($form_edit ? $form_category : 0);
$form_accounts = paymentAccounts($form_edit ? $form_account : 0);
// Cleared on a reconciled statement - its amount, date and account stay
$form_lock = $form_edit ? reconcileLock('expense', $form_row['expense_id']) : null;
@@ -148,13 +147,9 @@ $form_markup = $form_row && !$form_refund ? floatval($form_row['expense_markup']
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select select2" name="category" required data-expense-category>
<option value="">- What it was for -</option>
<?php foreach ($form_categories as $category_id => $category) { ?>
<option value="<?= $category_id ?>" <?= $form_category === $category_id ? 'selected' : '' ?><?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?><?= $category['category_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
<?= categoryOptionsHtml('Expense', $form_category) ?>
</select>
<?php if ($session_is_admin) { ?>
<button class="btn btn-outline-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Expense"><i class="fas fa-fw fa-plus"></i></button>
<?php } ?>
<?= categoryAddButtonHtml('Expense') ?>
</div>
</div>

View File

@@ -76,10 +76,9 @@ ob_start();
<?php if ($field === 'category') { ?>
<select class="form-select select2" name="value" required>
<option value="">- Pick a category -</option>
<?php foreach (incomeCategories() as $option_id => $category) { ?>
<option value="<?= $option_id ?>"<?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income', null, ['exclude' => ['Account Transfer']]) ?>
</select>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
<?php } elseif ($field === 'account') { ?>
<select class="form-select select2" name="value" required>
<option value="">- Pick the account it went into -</option>

View File

@@ -38,9 +38,8 @@ if (!$lines) {
}
$statuses = [];
$sql = mysqli_query($mysqli, "SELECT category_name, category_color FROM categories WHERE category_type = 'asset_status' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$statuses[$row['category_name']] = assetStatusColor($row['category_name'], $row['category_color'] ?? '');
foreach (categoryPicker('asset_status') as $status_name => $status_row) {
$statuses[$status_name] = assetStatusColor($status_name, $status_row['category_color'] ?? '');
}
$status_default = isset($statuses['Deployed']) ? 'Deployed' : (isset($statuses['Ready to Deploy']) ? 'Ready to Deploy' : (string) array_key_first($statuses));

View File

@@ -10,7 +10,6 @@ enforceUserPermission('module_sales', 2);
$invoice_ids = array_values(array_filter(array_map('intval', (array) ($_GET['invoice_ids'] ?? []))));
$count = count($invoice_ids);
$categories = billingCategories();
ob_start();
@@ -28,10 +27,10 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="bulk_category_id" required>
<?php foreach ($categories as $category_id => $category) { ?>
<option value="<?= intval($category_id) ?>"<?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<option value="">- Pick a category -</option>
<?= categoryOptionsHtml('Income') ?>
</select>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
<div class="form-text">Reports group income by it.</div>
</div>

View File

@@ -28,19 +28,9 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select select2" name="bulk_category_id">
<?php
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Income' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php
}
?>
<?= categoryOptionsHtml('Income') ?>
</select>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -39,12 +39,6 @@ $form_currency = $form_edit ? (string) $form_product['product_currency_code'] :
$form_asset_type = $form_value('product_asset_type');
$form_warranty = $form_edit && intval($form_product['product_warranty_months']) > 0 ? intval($form_product['product_warranty_months']) : '';
$form_categories = [];
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories
WHERE category_type = 'Income' AND (category_archived_at IS NULL OR category_id = $form_category_id) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$form_categories[] = $row;
}
$form_taxes = billingTaxes();
$form_vendors = productVendors();
if ($form_vendor_id && !isset($form_vendors[$form_vendor_id]) && $form_value('vendor_name') !== '') {
@@ -84,13 +78,9 @@ if ($form_vendor_id && !isset($form_vendors[$form_vendor_id]) && $form_value('ve
<span class="input-group-text"><i class="fas fa-fw fa-list"></i></span>
<select class="form-select select2" name="category" required>
<option value="">- Category -</option>
<?php foreach ($form_categories as $category) { ?>
<option value="<?= intval($category['category_id']) ?>" <?= $form_category_id === intval($category['category_id']) ? 'selected' : '' ?><?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income', $form_category_id) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button" data-modal-size="sm" data-modal-url="../admin/modals/category/category_add.php?category=Income">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-sm-5">

View File

@@ -7,20 +7,6 @@
isset($mysqli) || die("Direct file access is not allowed");
// Rack types come from Admin > Categories. A rack saved with a type that has
// since been renamed or archived keeps it as an option, or the required select
// would force the type to change on every edit.
$rack_type_options = [];
$sql_rack_types_select = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'rack_type' AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC");
while ($row = mysqli_fetch_assoc($sql_rack_types_select)) {
$rack_type_options[escapeHtml($row['category_name'])] = selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '');
}
if ($rack_type !== '' && !isset($rack_type_options[$rack_type])) {
$rack_type_options = [$rack_type => ''] + $rack_type_options;
}
?>
<ul class="nav nav-pills nav-justified mb-3">
@@ -52,10 +38,10 @@ if ($rack_type !== '' && !isset($rack_type_options[$rack_type])) {
<span class="input-group-text"><i class="fas fa-fw fa-server"></i></span>
<select class="form-select select2" name="type" required>
<option value="">- Type -</option>
<?php foreach ($rack_type_options as $rack_type_option => $rack_type_option_data) { ?>
<option <?php if ($rack_type === $rack_type_option) { echo "selected"; } ?><?= $rack_type_option_data ?>><?= $rack_type_option ?></option>
<?php } ?>
<?php // Rack types from Admin > Categories - one the rack has that is archived or isn't a type any more stays an option, or the required select would change it on every edit ?>
<?= categoryOptionsHtml('rack_type', html_entity_decode($rack_type, ENT_QUOTES, 'UTF-8')) ?>
</select>
<?= categoryAddButtonHtml('rack_type', 'btn btn-secondary') ?>
</div>
</div>

View File

@@ -42,7 +42,6 @@ $form_end = $form_value('recurring_expense_end_date');
$form_currency = $form_edit ? $form_value('recurring_expense_currency_code') : (string) $session_company_currency;
$form_vendors = expenseVendors($form_edit ? $form_vendor : 0);
$form_categories = expenseCategories($form_edit ? $form_category : 0);
$form_accounts = paymentAccounts($form_edit ? $form_account : 0);
$form_methods = paymentMethods();
if ($form_method !== '' && !in_array($form_method, $form_methods, true)) {
@@ -146,13 +145,9 @@ while ($row = mysqli_fetch_assoc($sql)) {
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select select2" name="category" required data-expense-category>
<option value="">- What it is for -</option>
<?php foreach ($form_categories as $category_id => $category) { ?>
<option value="<?= $category_id ?>" <?= $form_category === $category_id ? 'selected' : '' ?><?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?><?= $category['category_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
<?= categoryOptionsHtml('Expense', $form_category) ?>
</select>
<?php if ($session_is_admin) { ?>
<button class="btn btn-outline-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Expense"><i class="fas fa-fw fa-plus"></i></button>
<?php } ?>
<?= categoryAddButtonHtml('Expense') ?>
</div>
</div>

View File

@@ -130,21 +130,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- Not Categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Ticket">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -29,17 +29,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="bulk_category">
<option value="0">- Uncategorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -143,17 +143,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- Not categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories
WHERE category_type = 'Ticket' AND (category_archived_at IS NULL OR category_id = $category_id) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id_select = intval($row['category_id']); ?>
<option <?= $category_id === $category_id_select ? 'selected' : '' ?> value="<?= $category_id_select ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= escapeHtml($row['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket', $category_id) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Ticket">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -38,7 +38,6 @@ $form_lock = $form_edit ? reconcileLock('revenue', $form_row['revenue_id']) : nu
if (!isset($form_accounts[$form_account])) {
$form_account = 0;
}
$form_categories = incomeCategories($form_edit ? $form_category : 0);
$form_methods = paymentMethods();
if ($form_method !== '' && !in_array($form_method, $form_methods, true)) {
if ($form_edit) {
@@ -65,13 +64,9 @@ $form_currency = $form_account ? ($form_accounts[$form_account]['account_currenc
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select select2" name="category" required>
<option value="">- What it was -</option>
<?php foreach ($form_categories as $category_id => $category) { ?>
<option value="<?= $category_id ?>" <?= $form_category === $category_id ? 'selected' : '' ?><?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?><?= $category['category_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income', $form_category, ['exclude' => ['Account Transfer']]) ?>
</select>
<?php if ($session_is_admin) { ?>
<button class="btn btn-outline-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Income"><i class="fas fa-fw fa-plus"></i></button>
<?php } ?>
<?= categoryAddButtonHtml('Income') ?>
</div>
</div>

View File

@@ -17,16 +17,9 @@
isset($mysqli) || die("Direct file access is not allowed");
// Software types - from Admin > Categories, keeping a retired value that is still set
$type_options = [];
$sql = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = 'software_type' AND category_archived_at IS NULL ORDER BY category_order ASC, category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$type_options[] = $row['category_name'];
}
// Software types - from Admin > Categories, keeping one the license has that is archived or isn't a type any more
$software_type_raw = html_entity_decode($software_type, ENT_QUOTES, 'UTF-8');
if ($software_type_raw !== '' && !in_array($software_type_raw, $type_options, true)) {
$type_options[] = $software_type_raw;
}
$type_options = array_map('strval', array_keys(categoryPicker('software_type', [$software_type_raw])));
// License types - the usual ones, keeping whatever this one already has
$license_type_options = array_keys(SOFTWARE_LICENSE_TYPES);
@@ -165,10 +158,9 @@ $form_id = 'softwareForm' . ($software_form_mode === 'edit' ? $software_id : 'Ne
<span class="input-group-text"><i class="fas fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="type" required>
<option value="">- Select Type -</option>
<?php foreach ($type_options as $type_option) { ?>
<option <?= $type_option === $software_type_raw ? 'selected' : '' ?><?= selectOptionData(['icon' => 'fas ' . softwareTypeStyle($type_option)['icon']]) ?>><?= escapeHtml($type_option) ?></option>
<?php } ?>
<?= categoryOptionsHtml('software_type', $software_type_raw) ?>
</select>
<?= categoryAddButtonHtml('software_type', 'btn btn-secondary') ?>
</div>
</div>
<?php if ($client_id) { ?>

View File

@@ -180,20 +180,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- Not Categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button"
data-modal-url="../admin/modals/category/category_add.php?category=Ticket">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -31,17 +31,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="bulk_category">
<option value="0">- Uncategorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Ticket' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket') ?>
</select>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -132,17 +132,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- Not categorized -</option>
<?php
$sql_categories = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories
WHERE category_type = 'Ticket' AND (category_archived_at IS NULL OR category_id = $ticket_category) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql_categories)) {
$category_id = intval($row['category_id']); ?>
<option <?= $ticket_category === $category_id ? 'selected' : '' ?> value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= escapeHtml($row['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Ticket', $ticket_category) ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New category" type="button" data-modal-url="../admin/modals/category/category_add.php?category=Ticket">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Ticket', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -51,7 +51,6 @@ $sql = mysqli_query($mysqli, "SELECT invoice_id, invoice_prefix, invoice_number,
while ($draft = mysqli_fetch_assoc($sql)) {
$drafts[intval($draft['invoice_id'])] = $draft;
}
$categories = billingCategories();
$taxes = billingTaxes();
$scopes = ["Ticket $reference - " . $row['ticket_subject'], 'Support - ' . date('F Y')];
@@ -125,10 +124,9 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select" name="category" required>
<option value="">- Category -</option>
<?php foreach ($categories as $category_id => $category) { ?>
<option value="<?= intval($category_id) ?>"<?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income') ?>
</select>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-12" data-ticket-invoice-new>

View File

@@ -109,21 +109,11 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-list"></i></span>
<select class="form-select select2" name="category">
<select class="form-select select2" name="category" required>
<option value="">- Select a Category -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories WHERE category_type = 'Income' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"<?= selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '') ?>><?= $category_name ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income') ?>
</select>
<button type="button" class="btn btn-secondary ajax-modal" title="New category" data-modal-url="/admin/modals/category/category_add.php?category=Expense">
<i class="fas fa-fw fa-plus"></i>
</button>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>
</div>

View File

@@ -1,36 +0,0 @@
<?php
/*
* ITFlow - a new category from the + beside a category picker in a form on
* an agent page (admin/modals/category/category_add.php posts to the page's
* own post.php). Admins only, as the window is. The work is in
* functions/categories.php.
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['add_category'])) {
validateCSRFToken();
if (empty($session_is_admin)) {
flashAlert("Only an admin can add categories", 'error');
redirect();
}
[$fields, $error] = categoryFromInput($_POST);
if ($error !== '') {
flashAlert(escapeHtml($error), 'error');
redirect();
}
$category_id = categoryCreate($fields);
$kind = categoryKind($fields['type'])['one'] ?? 'category';
logAudit("Category", "Create", "$session_name created $kind " . escapeSql($fields['name']), 0, $category_id);
flashAlert(ucfirst($kind) . " <strong>" . escapeHtml($fields['name']) . "</strong> created");
redirect();
}

View File

@@ -38,6 +38,9 @@ if (isset($_POST['add_client'])) {
$extended_log_description = '';
// A referral typed in that isn't one yet is made one; one that is takes its own spelling
$referral = escapeSql(categoryEnsure('Referral', $_POST['referral'] ?? ''));
// Create client
mysqli_query($mysqli, "INSERT INTO clients SET client_name = '$name', client_type = '$type', client_website = '$website', client_referral = '$referral', client_rate = $rate, client_currency_code = '$session_company_currency', client_net_terms = $net_terms, client_reminders = " . ($reminders ?? 1) . ", client_tax_id_number = '$tax_id_number', client_lead = $lead, client_abbreviation = '$abbreviation', client_notes = '$notes', client_accessed_at = NOW()" . ($tax_input !== null ? ", " . taxClientSetSql($tax_input) : ''));
@@ -50,14 +53,6 @@ if (isset($_POST['add_client'])) {
file_put_contents("$client_folder/index.php", "");
}
// Create referral category if it doesn't exist
$sql = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = 'Referral' AND category_archived_at IS NULL AND category_name = '$referral'");
if (mysqli_num_rows($sql) == 0) {
mysqli_query($mysqli, "INSERT INTO categories SET category_name = '$referral', category_type = 'Referral'");
logAudit("Category", "Create", "$session_name created referral category $referral");
}
// Create primary location
if (!empty($location_phone) || !empty($address) || !empty($city) || !empty($state) || !empty($zip)) {
mysqli_query($mysqli, "INSERT INTO locations SET location_name = 'Primary', location_address = '$address', location_city = '$city', location_state = '$state', location_zip = '$zip', location_phone_country_code = '$location_phone_country_code', location_phone = '$location_phone', location_phone_extension = '$location_extension', location_fax_country_code = '$location_fax_country_code', location_fax = '$location_fax', location_country = '$country', location_primary = 1, location_client_id = $client_id");
@@ -128,17 +123,12 @@ if (isset($_POST['edit_client'])) {
$tax_set_sql = ", " . taxClientSetSql($tax_input, $tax_current);
}
// A referral typed in that isn't one yet is made one; one that is takes its own spelling
$referral = escapeSql(categoryEnsure('Referral', $_POST['referral'] ?? ''));
// Update client
mysqli_query($mysqli, "UPDATE clients SET client_name = '$name', client_type = '$type', client_website = '$website', client_referral = '$referral', client_rate = $rate, client_net_terms = $net_terms" . ($reminders !== null ? ", client_reminders = $reminders" : '') . ", client_tax_id_number = '$tax_id_number', client_lead = $lead, client_abbreviation = '$abbreviation', client_notes = '$notes'$tax_set_sql WHERE client_id = $client_id");
// Create referral category if it doesn't exist
$sql = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = 'Referral' AND category_archived_at IS NULL AND category_name = '$referral'");
if (mysqli_num_rows($sql) == 0) {
mysqli_query($mysqli, "INSERT INTO categories SET category_name = '$referral', category_type = 'Referral'");
logAudit("Category", "Create", "$session_name created referral category $referral");
}
// Tags - client tags only, and an admin can type a new one in (functions/tags.php)
tagSetForRecord('client', $client_id, (array) ($_POST['tags'] ?? []));
@@ -549,7 +539,7 @@ if (isset($_POST["import_clients_csv"])) {
$referral = '';
if (isset($column[2])) {
$referral = escapeSql($column[2]);
$referral = (string) $column[2];
}
$website = '';
@@ -650,6 +640,9 @@ if (isset($_POST["import_clients_csv"])) {
// Check if duplicate was detected
if ($duplicate_detect == 0) {
//Add
// A referral that isn't one yet is made one; one that is takes its own spelling
$referral = escapeSql(categoryEnsure('Referral', $referral));
// Create client
mysqli_query($mysqli, "INSERT INTO clients SET client_name = '$name', client_type = '$industry', client_website = '$website', client_referral = '$referral', client_rate = $hourly_rate, client_currency_code = '$currency_code', client_net_terms = $payment_terms, client_tax_id_number = '$tax_id_number', client_abbreviation = '$abbreviation'");
@@ -660,14 +653,6 @@ if (isset($_POST["import_clients_csv"])) {
file_put_contents("../uploads/clients/$client_id/index.php", "");
}
// Create Referral if it doesn't exist
$sql = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = 'Referral' AND category_archived_at IS NULL AND category_name = '$referral'");
if(mysqli_num_rows($sql) == 0) {
mysqli_query($mysqli, "INSERT INTO categories SET category_name = '$referral', category_type = 'Referral'");
// Logging
logAudit("Category", "Create", "$session_name created new refferal category $referral");
}
// Create Location
mysqli_query($mysqli, "INSERT INTO locations SET location_name = '$location_name', location_address = '$address', location_city = '$city', location_state = '$state', location_zip = '$zip', location_phone = '$location_phone', location_country = '$country', location_primary = 1, location_client_id = $client_id");

View File

@@ -4,7 +4,6 @@ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
$name = escapeSql($_POST['name']);
$type = escapeSql($_POST['type']);
$website = preg_replace("(^https?://)", "", escapeSql($_POST['website']));
$referral = escapeSql($_POST['referral']);
$rate = floatval($_POST['rate'] ?? 0);
$net_terms = intval($_POST['net_terms'] ?? $config_default_net_terms);
$tax_id_number = escapeSql($_POST['tax_id_number'] ?? '');

View File

@@ -83,7 +83,6 @@ $markup_text = function ($markup) {
return rtrim(rtrim(number_format(floatval($markup), 2, '.', ''), '0'), '.') . '%';
};
$categories = billingCategories();
$taxes = billingTaxes();
$scope_options = ['Support - ' . date('F Y'), 'Support - ' . date('F Y', strtotime('first day of last month'))];
@@ -500,10 +499,9 @@ $hours_text = function ($hours) {
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
<select class="form-select" name="category" required>
<option value="">- Category -</option>
<?php foreach ($categories as $category_id => $category) { ?>
<option value="<?= intval($category_id) ?>"<?= selectOptionColor($category['category_color'] ?? '', $category['category_icon'] ?? '') ?>><?= escapeHtml($category['category_name']) ?></option>
<?php } ?>
<?= categoryOptionsHtml('Income') ?>
</select>
<?= categoryAddButtonHtml('Income', 'btn btn-secondary') ?>
</div>
</div>
<div class="col-12" data-unbilled-new>

View File

@@ -141,17 +141,9 @@ function billingTaxes($since = null) {
return $taxes;
}
/** The income categories to offer - the same rule as billingTaxes(). */
function billingCategories($since = null) {
global $mysqli;
$since_sql = $since ? "OR category_archived_at > '" . escapeSql($since) . "'" : '';
$categories = [];
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon FROM categories
WHERE category_type = 'Income' AND (category_archived_at IS NULL $since_sql) ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$categories[intval($row['category_id'])] = $row;
}
return $categories;
/** The income categories to offer - the same rule as billingTaxes(): current ones, and those archived since $since (categoryPicker()). */
function billingCategories($since = null, $keep_id = 0) {
return categoryPicker('Income', [$keep_id], ['since' => $since]);
}
/** A line's subtotal, tax and total, each to the cent, at a single percent. */

View File

@@ -622,3 +622,133 @@ function categoryReorder($kind, array $ids) {
}
return $moved;
}
/*
* The categories a picker in a form offers - a kind's current ones, in its
* order, plus those in $keep (what the record already has: ids, or names
* for a kind held by name) even when archived. A kept name that isn't one
* of the kind's categories (typed in before there was a picker, or since
* deleted) is offered as it is, with no id, so saving the record keeps it.
* Rows keyed by the value the picker posts - the id, or the name. $opts:
* 'since' - also the ones archived after then (a billing record offers what
* was current when it was made); 'exclude' - names never offered unless kept.
*/
function categoryPicker($kind, $keep = [], array $opts = []) {
$config = categoryKind($kind);
if (!$config) {
return [];
}
$by_name = $config['by'] === 'name';
$keep_keys = [];
foreach ((array) $keep as $value) {
$value = $by_name ? trim((string) $value) : intval($value);
if ($value !== '' && $value !== 0) {
$keep_keys[$by_name ? categoryNameKey($value) : $value] = $value;
}
}
$since = !empty($opts['since']) ? strtotime($opts['since']) : null;
$exclude = array_map('categoryNameKey', (array) ($opts['exclude'] ?? []));
$rows = [];
foreach (categoryRows($kind) as $category_id => $row) {
$key = $by_name ? categoryNameKey($row['category_name']) : $category_id;
$kept = isset($keep_keys[$key]);
if (!$kept && in_array(categoryNameKey($row['category_name']), $exclude, true)) {
continue;
}
if (!$kept && $row['category_archived_at'] && !($since && strtotime($row['category_archived_at']) > $since)) {
continue;
}
$value = $by_name ? $row['category_name'] : $category_id;
if (!isset($rows[$value])) {
$rows[$value] = $row;
}
unset($keep_keys[$key]);
}
// Kept names no category has
if ($by_name) {
foreach ($keep_keys as $name) {
$rows[$name] = ['category_id' => 0, 'category_name' => $name, 'category_description' => null, 'category_type' => $config['kind'],
'category_color' => null, 'category_icon' => null, 'category_archived_at' => null, 'loose' => true];
}
}
return $rows;
}
/* One picker <option> for a categoryPicker() row - its colour, icon and description, the value as the kind is held, and a note when archived or not set up. */
function categoryOptionHtml(array $row, $selected = false) {
$config = categoryKind($row['category_type'] ?? '');
$value = $config && $config['by'] === 'name' ? (string) $row['category_name'] : (string) intval($row['category_id']);
$note = !empty($row['loose']) ? ' (not set up)' : ($row['category_archived_at'] ? ' (archived)' : '');
// An asset status in its badge's colour - its own, or the built-in status's
$color = categoryColor($row['category_color'] ?? '');
if (($row['category_type'] ?? '') === 'asset_status') {
$color = assetStatusColor((string) $row['category_name'], $color);
}
$icon = categoryIcon($row['category_icon'] ?? '');
if ($icon === '' && ($row['category_type'] ?? '') === 'software_type') {
// A software type without one of its own: the icon read from its name, as its licenses show
$icon = categoryIcon(softwareTypeStyle((string) $row['category_name'])['icon']);
}
$data = selectOptionData(['color' => $color, 'icon' => $icon !== '' ? "fas fa-$icon" : '', 'description' => trim((string) ($row['category_description'] ?? ''))]);
return '<option value="' . escapeHtml($value) . '"' . ($selected ? ' selected' : '') . $data . '>' . escapeHtml($row['category_name'] . $note) . '</option>';
}
/*
* A picker's <option>s for a kind - categoryPicker() with $selected kept and
* chosen (an id, or a name for a kind held by name). The form writes its own
* "nothing picked" option first. $opts as categoryPicker(). HTML.
*/
function categoryOptionsHtml($kind, $selected = null, array $opts = []) {
$config = categoryKind($kind);
if (!$config) {
return '';
}
$by_name = $config['by'] === 'name';
$selected_key = $by_name ? categoryNameKey(trim((string) $selected)) : intval($selected);
$html = '';
foreach (categoryPicker($kind, $selected === null ? [] : [$selected], $opts) as $value => $row) {
$key = $by_name ? categoryNameKey($value) : intval($value);
$html .= categoryOptionHtml($row, $selected !== null && $selected_key !== '' && $selected_key !== 0 && $key === $selected_key) . "\n";
}
return $html;
}
/*
* The + beside a category picker in a form: it opens the category window
* over the form, and what is made there is put in the picker and picked
* (js/category_form.js) - nothing reloads, nothing typed is lost. Admins
* only, as Admin > Categories is; '' for anyone else. $class matches the
* form's other buttons.
*/
function categoryAddButtonHtml($kind, $class = 'btn btn-outline-secondary') {
global $session_is_admin;
$config = categoryKind($kind);
if (empty($session_is_admin) || !$config) {
return '';
}
return '<button type="button" class="' . escapeHtml($class) . ' ajax-modal" title="New ' . escapeHtml($config['one']) . '" aria-label="New ' . escapeHtml($config['one']) . '"'
. ' data-modal-url="/admin/modals/category/category_add.php?category=' . urlencode($config['kind']) . '&amp;inline=1" data-category-add><i class="fas fa-fw fa-plus"></i></button>';
}
/*
* A name typed into a picker for a kind held by name (a client's referral)
* as the kind's category: the one with that name, any case, archived or not,
* or a new one made for it. The name to keep on the record - its
* category's own spelling - or '' for none.
*/
function categoryEnsure($kind, $name) {
global $mysqli, $session_name;
$config = categoryKind($kind);
$name = trim(mb_substr(preg_replace('/\s+/u', ' ', strip_tags((string) $name)), 0, $config['max'] ?? 200));
if (!$config || $config['by'] !== 'name' || $name === '') {
return $name;
}
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_type = '" . escapeSql($config['kind']) . "'
AND category_name = '" . escapeSql($name) . "' ORDER BY category_archived_at IS NOT NULL, category_id LIMIT 1"));
if ($row) {
return $row['category_name'];
}
$category_id = categoryCreate(['type' => $config['kind'], 'name' => $name, 'description' => '', 'color' => categoryNextColor($config['kind']), 'icon' => '']);
logAudit("Category", "Create", ($session_name ?? 'ITFlow') . " created " . $config['one'] . " " . escapeSql($name), 0, $category_id);
return $name;
}

View File

@@ -240,18 +240,9 @@ function expenseVendors($keep_id = 0) {
return $vendors;
}
/** Expense categories for a picker - not archived, plus $keep_id. */
/** Expense categories for a picker - not archived, plus $keep_id (categoryPicker()). */
function expenseCategories($keep_id = 0) {
global $mysqli;
$keep_id = intval($keep_id);
$categories = [];
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon, category_archived_at FROM categories
WHERE category_type = 'Expense' AND (category_archived_at IS NULL OR category_id = $keep_id)
ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$categories[intval($row['category_id'])] = $row;
}
return $categories;
return categoryPicker('Expense', [$keep_id]);
}
/**

View File

@@ -202,18 +202,9 @@ function incomeStats($client_id = 0) {
return $stats;
}
/** The income categories - id => row, archived ones left out but $keep_id. */
/** The income categories - id => row, archived ones left out but $keep_id, and the old Account Transfer one unless kept (categoryPicker()). */
function incomeCategories($keep_id = 0) {
global $mysqli;
$keep_id = intval($keep_id);
$categories = [];
$sql = mysqli_query($mysqli, "SELECT category_id, category_name, category_color, category_icon, category_archived_at FROM categories
WHERE category_type = 'Income' AND category_name <> 'Account Transfer' AND (category_archived_at IS NULL OR category_id = $keep_id)
ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$categories[intval($row['category_id'])] = $row;
}
return $categories;
return categoryPicker('Income', [$keep_id], ['exclude' => ['Account Transfer']]);
}
/* ---------------------------------------------------------- Other income */

View File

@@ -721,6 +721,43 @@ itflowBindOnce('itflowModalFocus', 'shown.bs.modal', '.modal', function () {
this.focus();
});
/**
* A window opened over another - the + beside a category picker opens the
* category window over the form - goes above it with its backdrop, so the
* form underneath is dimmed rather than drawn over the new window's shade.
* Bootstrap gives every modal the same z-index. Closing the top one takes the
* page's modal-open class off, so it is put back while one is still open.
*/
itflowBindOnce('itflowModalStack', 'show.bs.modal', '.modal', function () {
const below = document.querySelectorAll('.modal.show').length;
if (!below) {
return;
}
const z = 1055 + 20 * below;
this.style.zIndex = z;
// Bootstrap adds the backdrop straight after this event
setTimeout(function () {
const backdrops = document.querySelectorAll('.modal-backdrop');
if (backdrops.length) {
backdrops[backdrops.length - 1].style.zIndex = z - 5;
}
});
});
itflowBindOnce('itflowModalStackHidden', 'hidden.bs.modal', '.modal', function () {
if (document.querySelector('.modal.show')) {
document.body.classList.add('modal-open');
}
});
/**
* The + beside a category picker (categoryAddButtonHtml()): note which
* picker it is beside, for js/category_form.js to put the new category in.
*/
itflowBindOnce('itflowCategoryAdd', 'click', '[data-category-add]', function () {
const group = this.closest('.input-group') || this.parentElement;
window.itflowCategoryTarget = group ? group.querySelector('select') : null;
});
/**
* Warn before leaving the page with unsaved editor content.
*

View File

@@ -8,6 +8,12 @@
// held by name says the records will be renamed with it. The server checks
// it all again.
//
// Opened from the + beside a picker in a form (categoryAddButtonHtml() in
// functions/categories.php - js/app.js notes which picker), New Category
// saves in the background: the new category goes into that picker, picked,
// and the window closes, leaving the form underneath as it was. A refusal
// (a name already taken) shows in the window.
//
// Wrapped in an IIFE because a modal can be opened, closed and opened again
// in one page load, which re-runs this file.
@@ -196,6 +202,74 @@
setIcon(visible[0].dataset.categoryIconChoice);
}
});
// From the + beside a picker - saved in the background, into that picker
const inline = form.closest('form[data-category-inline]');
if (!inline) {
return;
}
const picker = window.itflowCategoryTarget || null;
window.itflowCategoryTarget = null;
const error = inline.querySelector('[data-category-error]');
inline.addEventListener('submit', function (e) {
if (!picker || !picker.isConnected) {
// Nothing to put it in - a plain post, back to the page
const flag = inline.querySelector('input[name="inline"]');
if (flag) {
flag.remove();
}
return;
}
e.preventDefault();
const button = inline.querySelector('button[name="add_category"]');
button.disabled = true;
const data = new FormData(inline);
data.append('add_category', '1');
fetch(inline.getAttribute('action'), { method: 'POST', body: data, credentials: 'same-origin', headers: { 'Accept': 'application/json' } })
.then(function (res) {
if (!res.ok) {
throw new Error('HTTP ' + res.status);
}
return res.json();
})
.then(function (result) {
if (!result.ok) {
throw new Error(result.error || 'It was not saved');
}
// Picked in the picker - an option already there for it is used as it is
let option = Array.prototype.find.call(picker.options, function (o) {
return o.value === result.value;
});
if (!option) {
const holder = document.createElement('select');
holder.innerHTML = result.option;
option = holder.options[0];
picker.appendChild(option);
}
if (!picker.multiple) {
Array.prototype.forEach.call(picker.options, function (o) {
o.selected = false;
});
}
option.selected = true;
picker.dispatchEvent(new Event('input', { bubbles: true }));
picker.dispatchEvent(new Event('change', { bubbles: true }));
const modal = inline.closest('.modal');
if (modal && window.bootstrap) {
bootstrap.Modal.getOrCreateInstance(modal).hide();
}
if (typeof itflowToast === 'function') {
itflowToast(result.message, 'success');
}
})
.catch(function (err) {
button.disabled = false;
if (error) {
error.textContent = err.message.indexOf('HTTP ') === 0 ? 'It could not be saved - reload the page and try again.' : err.message;
error.hidden = false;
}
});
});
});
})();