Vendor templates stage 1: Admin > Vendor Templates rebuilt on the standard list with Active and Archived tabs, support line, hours and SLA, how many clients have a vendor from each, last used and changed by, sortable and searchable including by support line; new template page with what a vendor starts with, the clients with it and their account numbers, the license templates that use it, made and changed by, and history; shared New/Edit window on the vendor window's tabs with per-field push to the vendors made from it, each logged on the vendor; copy, archive, restore and delete with vendors and license templates unlinked on delete; Make a template from a client's vendor, linking the vendor to it, and the vendor page linking its template for admins; Delete offered to every admin role, not only the built-in Administrator; the admin handler no longer includes the agent vendor handler; database 3.3.4 adds vendor_template_created_by and vendor_template_updated_by, backfilled from the audit log

This commit is contained in:
johnnyq
2026-10-19 12:34:53 -04:00
parent a5a43e37ac
commit dfc708145d
36 changed files with 3514 additions and 780 deletions

View File

@@ -0,0 +1,155 @@
<?php
/*
* An app log entry's quick look - all of it: when, the level and category,
* the whole of what it says (to copy, for a bug report), then the other
* entries in the five minutes either side and what was done in the audit log
* then - so a payment error sits beside the payment, a mail error beside the
* ticket reply. Opened from Admin > App Logs.
*/
require_once '../../includes/modal_header.php';
$app_log_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM app_logs WHERE app_log_id = $app_log_id"));
if (!$row) {
echo json_encode(['error' => 'That app log entry no longer exists - it may have been cleared.']);
exit;
}
$level = appLogLevel($row['app_log_type']);
$style = appLogLevels()[$level];
$category = (string) $row['app_log_category'];
$created = strtotime($row['app_log_created_at']);
$at = escapeSql($row['app_log_created_at']);
$window = "BETWEEN '$at' - INTERVAL 5 MINUTE AND '$at' + INTERVAL 5 MINUTE";
// The other app log entries in the five minutes either side
$around_where = "app_log_created_at $window AND app_log_id <> $app_log_id";
$around_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM app_logs WHERE $around_where"))[0]);
$around = [];
$sql = mysqli_query($mysqli, "SELECT app_log_id, app_log_category, app_log_type, app_log_details, app_log_created_at FROM app_logs WHERE $around_where ORDER BY app_log_created_at ASC, app_log_id ASC LIMIT 8");
while ($around_row = mysqli_fetch_assoc($sql)) {
$around[] = $around_row;
}
// What was done in the audit log then
$audit_where = "log_created_at $window";
$audit_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM logs WHERE $audit_where"))[0]);
$audit = [];
$sql = mysqli_query($mysqli, "SELECT log_id, log_type, log_action, log_description, log_created_at FROM logs WHERE $audit_where ORDER BY log_created_at ASC, log_id ASC LIMIT 8");
while ($audit_row = mysqli_fetch_assoc($sql)) {
$audit[] = $audit_row;
}
$category_count = $category !== '' ? intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM app_logs WHERE app_log_category = '" . escapeSql($category) . "'"))[0]) : 0;
$day = date('Y-m-d', $created);
$day_query = 'canned_date=custom&dtf=' . $day . '&dtt=' . $day;
ob_start();
?>
<div class="modal-header bg-dark" data-bs-theme="dark">
<div class="d-flex align-items-center gap-3 min-w-0 flex-grow-1">
<span class="itflow-asset-icon itflow-asset-icon-lg bg-<?= $style['tone'] ?>-subtle text-<?= $style['tone'] ?>-emphasis" aria-hidden="true"><i class="<?= appLogCategoryIcon($category) ?>"></i></span>
<div class="min-w-0 flex-grow-1">
<h5 class="modal-title fw-semibold text-break"><?= escapeHtml($category !== '' ? $category : 'No category') ?> &middot; <?= $style['one'] ?></h5>
<div class="small text-body-secondary mt-1"><?= escapeHtml(date('D, M j, Y \a\t g:i:s A', $created)) ?> &middot; <?= escapeHtml(timeAgo($row['app_log_created_at'])) ?></div>
</div>
</div>
<button type="button" class="btn-close btn-close-white ms-3" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="p-3 rounded border bg-body-tertiary mb-3 position-relative">
<button type="button" class="btn btn-sm btn-light position-absolute top-0 end-0 m-2 clipboardjs" title="Copy" aria-label="Copy" data-clipboard-text="<?= escapeHtml($row['app_log_details']) ?>"><i class="far fa-fw fa-copy"></i></button>
<div class="text-break font-monospace small pe-5" style="white-space: pre-wrap;" data-app-log-full-details><?= escapeHtml((string) $row['app_log_details']) ?></div>
</div>
<div class="row g-2 itflow-asset-glance">
<div class="col-sm-6">
<div class="itflow-glance-item" title="Level">
<i class="fas fa-fw fa-signal"></i>
<span><?= appLogLevelPill($level) ?> <span class="small text-body-secondary ms-1"><?= escapeHtml($style['title']) ?></span></span>
</div>
<div class="itflow-glance-item" title="Category">
<i class="fas fa-fw fa-folder"></i>
<?php if ($category !== '') { ?>
<span><?= escapeHtml($category) ?> <a class="small ms-1" href="/admin/app_logs.php?category=<?= urlencode($category) ?>">All <?= number_format($category_count) ?> from it</a></span>
<?php } else { ?>
<span class="text-body-secondary">None</span>
<?php } ?>
</div>
</div>
<div class="col-sm-6">
<div class="itflow-glance-item" title="Entry">
<i class="fas fa-fw fa-hashtag"></i>
<span class="text-body-secondary">Entry <?= $app_log_id ?></span>
</div>
<div class="itflow-glance-item" title="When">
<i class="fas fa-fw fa-clock"></i>
<span class="font-monospace small"><?= escapeHtml($row['app_log_created_at']) ?></span>
</div>
</div>
</div>
<div class="mt-4" data-app-log-around>
<div class="d-flex align-items-center mb-2">
<div class="small fw-semibold text-uppercase text-body-secondary">The app logs around then</div>
<?php if ($around_count > 0) { ?>
<a class="small ms-auto" href="/admin/app_logs.php?<?= $day_query ?>">All of that day</a>
<?php } ?>
</div>
<?php if ($around) { ?>
<div class="list-group">
<?php foreach ($around as $entry) { ?>
<a href="#" class="list-group-item list-group-item-action d-flex align-items-start gap-2 small ajax-modal" data-modal-size="lg" data-modal-url="/admin/modals/app_log/app_log.php?id=<?= intval($entry['app_log_id']) ?>">
<span class="text-body-secondary text-nowrap flex-shrink-0" style="min-width: 4.5rem;" title="<?= escapeHtml($entry['app_log_created_at']) ?>"><?= escapeHtml(date('g:i:s A', strtotime($entry['app_log_created_at']))) ?></span>
<span class="flex-shrink-0"><?= appLogLevelPill($entry['app_log_type']) ?></span>
<span class="text-break"><span class="fw-semibold"><?= escapeHtml((string) $entry['app_log_category']) ?></span> <?= escapeHtml(mb_strimwidth((string) $entry['app_log_details'], 0, 160, '…')) ?></span>
</a>
<?php } ?>
</div>
<?php if ($around_count > count($around)) { ?>
<div class="small text-body-secondary mt-1">and <?= $around_count - count($around) ?> more</div>
<?php } ?>
<?php } else { ?>
<div class="small text-body-secondary">Nothing else in the five minutes either side.</div>
<?php } ?>
</div>
<div class="mt-4" data-app-log-audit>
<div class="d-flex align-items-center mb-2">
<div class="small fw-semibold text-uppercase text-body-secondary">The audit log then</div>
<?php if ($audit_count > 0) { ?>
<a class="small ms-auto" href="/admin/audit_logs.php?<?= $day_query ?>">All of that day</a>
<?php } ?>
</div>
<?php if ($audit) { ?>
<div class="list-group">
<?php foreach ($audit as $entry) { ?>
<a href="#" class="list-group-item list-group-item-action d-flex align-items-start gap-2 small ajax-modal" data-modal-size="lg" data-modal-url="/admin/modals/audit_log/audit_log.php?id=<?= intval($entry['log_id']) ?>">
<span class="text-body-secondary text-nowrap flex-shrink-0" style="min-width: 4.5rem;" title="<?= escapeHtml($entry['log_created_at']) ?>"><?= escapeHtml(date('g:i:s A', strtotime($entry['log_created_at']))) ?></span>
<span class="flex-shrink-0"><?= auditLogActionPill($entry['log_action']) ?></span>
<span class="text-break"><?= escapeHtml($entry['log_description']) ?></span>
</a>
<?php } ?>
</div>
<?php if ($audit_count > count($audit)) { ?>
<div class="small text-body-secondary mt-1">and <?= $audit_count - count($audit) ?> more</div>
<?php } ?>
<?php } else { ?>
<div class="small text-body-secondary">Nothing was done in the five minutes either side.</div>
<?php } ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Close</button>
</div>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,77 @@
<?php
/*
* Clear the app logs - the entries the list is showing, with its search,
* level, category and dates, or every one. Each clear is in the audit log,
* saying what went (clear_app_logs, admin/post/app_log.php). The audit log
* itself can't be cleared - it is only ever trimmed by its retention.
*/
require_once '../../includes/modal_header.php';
$views = appLogViews();
$src = [
'q' => is_string($_GET['q'] ?? null) ? $_GET['q'] : '',
'view' => is_string($_GET['view'] ?? null) && isset($views[$_GET['view']]) ? $_GET['view'] : '',
'category' => is_string($_GET['category'] ?? null) ? $_GET['category'] : '',
'dtf' => is_string($_GET['dtf'] ?? null) ? $_GET['dtf'] : '',
'dtt' => is_string($_GET['dtt'] ?? null) ? $_GET['dtt'] : '',
];
$summary = [];
$where = appLogFiltersSql($src, $summary);
$matching = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM app_logs WHERE $where"))[0]);
$total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM app_logs"))[0]);
$filtered = !empty($summary);
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-trash-alt me-2"></i>Clear App Logs</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($src as $name => $value) { if ($value !== '') { ?>
<input type="hidden" name="<?= $name ?>" value="<?= escapeHtml($value) ?>">
<?php } } ?>
<div class="modal-body">
<?php if (!$total) { ?>
<div class="text-center text-secondary py-4">There is nothing in the app logs to clear.</div>
<?php } else { ?>
<p class="mb-3">The entries are deleted for good. Clearing is in the audit log, with what was cleared.</p>
<?php if ($filtered) { ?>
<div class="form-check mb-2">
<input class="form-check-input" type="radio" name="scope" value="shown" id="appLogClearShown" <?= $matching ? 'checked' : 'disabled' ?>>
<label class="form-check-label" for="appLogClearShown">
<span class="fw-semibold" data-app-log-clear-matching="<?= $matching ?>"><?= number_format($matching) ?> entr<?= $matching === 1 ? 'y' : 'ies' ?></span> - the ones shown:
<span class="text-body-secondary" data-app-log-clear-filters><?= escapeHtml(appLogFiltersText($summary)) ?></span>
</label>
</div>
<?php } ?>
<div class="form-check">
<input class="form-check-input" type="radio" name="scope" value="all" id="appLogClearAll" <?= $filtered && $matching ? '' : 'checked' ?>>
<label class="form-check-label" for="appLogClearAll">
<span class="fw-semibold" data-app-log-clear-total="<?= $total ?>">Every entry - all <?= number_format($total) ?></span>
</label>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($total) { ?>
<button type="submit" name="clear_app_logs" class="btn btn-danger text-bold"><i class="fas fa-trash-alt me-2"></i>Clear</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,47 @@
<?php
/*
* Export the app logs to CSV or PDF - pre-filled from the list's filters and
* level, every one editable: the export runs what this form posts, not what
* the page happened to show (export_app_logs, admin/post/app_log.php).
*/
require_once '../../includes/modal_header.php';
$views = appLogViews();
$q_filter = is_string($_GET['q'] ?? null) ? $_GET['q'] : '';
$view_filter = is_string($_GET['view'] ?? null) && isset($views[$_GET['view']]) ? $_GET['view'] : '';
$category_filter = is_string($_GET['category'] ?? null) ? $_GET['category'] : '';
$date_from_filter = (is_string($_GET['dtf'] ?? null) && appLogDate($_GET['dtf']) && $_GET['dtf'] !== '1970-01-01') ? $_GET['dtf'] : '';
$date_to_filter = (is_string($_GET['dtt'] ?? null) && appLogDate($_GET['dtt']) && $_GET['dtt'] !== '2099-12-31') ? $_GET['dtt'] : '';
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-download me-2"></i>Export App Logs</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<?php exportTabsNav(); ?>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="modal-body">
<?php exportTabsFiltersOpen(); ?>
<?php require 'app_log_filters.php'; ?>
<?php exportTabsColumns('app_logs'); ?>
</div>
<div class="modal-footer">
<?php renderExportButtons('export_app_logs'); ?>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,62 @@
<?php
/*
* The app log filters, for the export and clear windows - search, level,
* category and dates, filled in from what the list shows. Expects
* $q_filter, $view_filter, $category_filter, $date_from_filter and
* $date_to_filter, and $views (appLogViews()).
*/
isset($mysqli, $views) || die("Direct file access is not allowed");
$filter_categories = appLogCategories();
?>
<div class="mb-3">
<label class="form-label">Search</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-search"></i></span>
<input type="text" class="form-control" name="q" value="<?= escapeHtml($q_filter) ?>" placeholder="The category or what it says">
</div>
</div>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label class="form-label">Level</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-signal"></i></span>
<select class="form-select select2" name="view">
<?php foreach ($views as $key => $definition) { ?>
<option value="<?= $key ?>" <?= $view_filter === $key ? 'selected' : '' ?><?= selectOptionData(['icon' => 'fas ' . $definition['icon'], 'description' => $definition['title']]) ?>><?= $key === '' ? 'Every level' : escapeHtml($definition['label']) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Category</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
<select class="form-select select2" name="category">
<option value="">- Any category -</option>
<?php foreach ($filter_categories as $category => $count) { ?>
<option value="<?= escapeHtml($category) ?>" <?= $category_filter === (string) $category ? 'selected' : '' ?><?= selectOptionData(['icon' => appLogCategoryIcon($category), 'description' => number_format($count) . ' entr' . ($count === 1 ? 'y' : 'ies')]) ?>><?= escapeHtml($category) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">From</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<input type="date" class="form-control" name="dtf" value="<?= $date_from_filter ?>" max="2999-12-31">
</div>
</div>
<div class="col-md-6">
<label class="form-label">To</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<input type="date" class="form-control" name="dtt" value="<?= $date_to_filter ?>" max="2999-12-31">
</div>
</div>
</div>

View File

@@ -1,147 +1,57 @@
<?php
/*
* New vendor template - the fields are vendor_template_form.php. With
* from_vendor (a vendor's id) it starts from that vendor - not its account
* number, PIN or account manager, which are its client's own - and the
* vendor is linked to the new template.
*/
require_once '../../includes/modal_header.php';
$vt_id = 0;
$vt = [];
$from_vendor = null;
$from_vendor_id = intval($_GET['from_vendor'] ?? 0);
if ($from_vendor_id) {
$from_vendor = vendorRow($from_vendor_id);
if ($from_vendor) {
$vt = [
'name' => $from_vendor['vendor_name'],
'description' => $from_vendor['vendor_description'],
'phone_country_code' => $from_vendor['vendor_phone_country_code'],
'phone' => $from_vendor['vendor_phone'],
'extension' => $from_vendor['vendor_extension'],
'hours' => $from_vendor['vendor_hours'],
'sla' => $from_vendor['vendor_sla'],
'email' => $from_vendor['vendor_email'],
'website' => $from_vendor['vendor_website'],
'notes' => $from_vendor['vendor_notes'],
];
}
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-building me-2"></i>New Vendor Template</h5>
<h5 class="modal-title"><i class="fa fa-fw fa-building me-2"></i>New Vendor Template</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'] ?>">
<div class="modal-body">
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-details">Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-support">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-notes">Notes</a>
</li>
</ul>
<hr>
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-details">
<div class="mb-3">
<label>Vendor Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
<input type="text" class="form-control" name="name" placeholder="Vendor Name" maxlength="200" required autofocus>
</div>
</div>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="description" placeholder="Description" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Account Number</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-fingerprint"></i></span>
<input type="text" class="form-control" name="account_number" placeholder="Account number" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Account Manager</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="contact_name" placeholder="Account manager's name" maxlength="200">
</div>
</div>
<?php if ($from_vendor) { ?>
<input type="hidden" name="from_vendor" value="<?= intval($from_vendor['vendor_id']) ?>">
<div class="alert alert-info small py-2" data-from-vendor>
<i class="fas fa-fw fa-info-circle me-1"></i>Starting from <strong><?= escapeHtml($from_vendor['vendor_name']) ?></strong><?= $from_vendor['client_name'] !== null ? ' for ' . escapeHtml($from_vendor['client_name']) : '' ?> - its account number, PIN and account manager stay its own. It is linked to the new template.
</div>
<div class="tab-pane fade" id="pills-support">
<label>Support Phone / <span class="text-secondary">Extension</span></label>
<div class="row g-2">
<div class="col-9">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-phone"></i></span>
<input type="hidden" name="phone_country_code">
<input type="tel" class="form-control" name="phone" placeholder="Phone Number" maxlength="200" data-itflow-phone="phone_country_code">
</div>
</div>
</div>
<div class="col-3">
<div class="mb-3">
<input type="text" class="form-control" name="extension" placeholder="ext." maxlength="200">
</div>
</div>
</div>
<div class="mb-3">
<label>Support Hours</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<input type="text" class="form-control" name="hours" placeholder="Support Hours" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Support Email</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
<input type="email" class="form-control" name="email" placeholder="Support Email" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Support Website URL</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
<input type="text" class="form-control" name="website" placeholder="Do not include http(s)://" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Pin/Code</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<input type="text" class="form-control" name="code" placeholder="Access Code or Pin" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>SLA</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-handshake"></i></span>
<input type="text" class="form-control" name="sla" placeholder="SLA Response Time" maxlength="200">
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-notes">
<div class="mb-3">
<textarea class="form-control" rows="8" placeholder="Enter some notes" name="notes"></textarea>
</div>
</div>
</div>
<?php } ?>
<?php require __DIR__ . '/vendor_template_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="add_vendor_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create Template</button>
<button type="submit" name="add_vendor_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create Vendor Template</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>

View File

@@ -1,217 +1,45 @@
<?php
/*
* Edit a vendor template - the fields are vendor_template_form.php, with
* the fields ticked changed on the vendors made from it too.
*/
require_once '../../includes/modal_header.php';
$vendor_template_id = intval($_GET['id']);
$template = vendorTemplateInfo($_GET['id'] ?? 0);
$sql = mysqli_query($mysqli, "SELECT vendor_template_account_number, vendor_template_code, vendor_template_contact_name,
vendor_template_description, vendor_template_email, vendor_template_extension,
vendor_template_hours, vendor_template_name, vendor_template_notes, vendor_template_phone,
vendor_template_phone_country_code, vendor_template_sla, vendor_template_website FROM vendor_templates WHERE vendor_template_id = $vendor_template_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$vendor_name = escapeHtml($row['vendor_template_name']);
$vendor_description = escapeHtml($row['vendor_template_description']);
$vendor_account_number = escapeHtml($row['vendor_template_account_number']);
$vendor_contact_name = escapeHtml($row['vendor_template_contact_name']);
$vendor_phone_country_code = intval($row['vendor_template_phone_country_code']);
$vendor_phone = formatPhoneNumber($row['vendor_template_phone'], $vendor_phone_country_code, false);
$vendor_extension = escapeHtml($row['vendor_template_extension']);
$vendor_email = escapeHtml($row['vendor_template_email']);
$vendor_website = escapeHtml($row['vendor_template_website']);
$vendor_hours = escapeHtml($row['vendor_template_hours']);
$vendor_sla = escapeHtml($row['vendor_template_sla']);
$vendor_code = escapeHtml($row['vendor_template_code']);
$vendor_notes = escapeHtml($row['vendor_template_notes']);
// Generate the HTML form content using output buffering.
ob_start();
?>
if (!$template) { ?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-building me-2"></i>Vendor template</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body text-center text-secondary py-5">That vendor template is gone - it may have been deleted.</div>
<?php } else {
$vt_id = intval($template['vendor_template_id']);
$vt = vendorTemplateRowFields($template);
$vt_vendors = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM vendors WHERE vendor_template_id = $vt_id"))[0]);
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-building me-2"></i>Editing vendor template: <strong><?= $vendor_name ?></strong></h5>
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-building me-2"></i>Vendor template: <strong><?= escapeHtml($template['vendor_template_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="vendor_template_id" value="<?= $vendor_template_id ?>">
<input type="hidden" name="vendor_template_id" value="<?= $vt_id ?>">
<div class="modal-body">
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-details<?= $vendor_template_id ?>">Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-support<?= $vendor_template_id ?>">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-notes<?= $vendor_template_id ?>">Notes</a>
</li>
</ul>
<hr>
<div class="alert alert-info">Check the fields you would like to update globally</div>
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-details<?= $vendor_template_id ?>">
<div class="mb-3">
<label>Vendor Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
<input type="text" class="form-control" name="name" placeholder="Vendor Name" maxlength="200" value="<?= "$vendor_name" ?>" required>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_name" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="description" placeholder="Description" maxlength="200" value="<?= $vendor_description ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_description" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Account Number</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-fingerprint"></i></span>
<input type="text" class="form-control" name="account_number" placeholder="Account number" maxlength="200" value="<?= $vendor_account_number ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_account_number" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Account Manager</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="contact_name" maxlength="200" value="<?= $vendor_contact_name ?>" placeholder="Vendor contact name">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_contact_name" value="1">
</div>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="updateVendorsCheckbox<?= $vendor_template_id ?>" name="update_base_vendors" value="1" >
<label class="form-check-label" for="updateVendorsCheckbox<?= $vendor_template_id ?>">Update All Base Vendors</label>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-support<?= $vendor_template_id ?>">
<label>Support Phone</label>
<div class="row g-2">
<div class="col-8">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-phone"></i></span>
<input type="hidden" name="phone_country_code" value="<?= $vendor_phone_country_code ?>">
<input type="tel" class="form-control" name="phone" maxlength="200" value="<?= $vendor_phone ?>" data-itflow-phone="phone_country_code">
</div>
</div>
</div>
<div class="col-4">
<div class="input-group">
<input type="text" class="form-control" name="extension" placeholder="Prompts" maxlength="200" value="<?= $vendor_extension ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_phone" value="1">
</div>
</div>
</div>
</div>
<div class="mb-3">
<label>Support Hours</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
<input type="text" class="form-control" name="hours" placeholder="Support Hours" maxlength="200" value="<?= $vendor_hours ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_hours" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Support Email</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
<input type="email" class="form-control" name="email" placeholder="Support Email" maxlength="200" value="<?= $vendor_email ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_email" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Support Website URL</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
<input type="text" class="form-control" name="website" placeholder="Do not include http(s)://" maxlength="200" value="<?= $vendor_website ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_website" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>SLA</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-handshake"></i></span>
<input type="text" class="form-control" name="sla" placeholder="SLA Response Time" maxlength="200" value="<?= $vendor_sla ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_sla" value="1">
</div>
</div>
</div>
<div class="mb-3">
<label>Pin/Code</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<input type="text" class="form-control" name="code" placeholder="Access Code or Pin" maxlength="200" value="<?= $vendor_code ?>">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="global_update_vendor_code" value="1">
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-notes<?= $vendor_template_id ?>">
<div class="mb-3">
<textarea class="form-control" rows="8" placeholder="Enter some notes" name="notes"><?= $vendor_notes ?></textarea>
</div>
<div class="mb-3">
<label>Update Notes Globally?</label>
<input class="form-check-input" type="checkbox" name="global_update_vendor_notes" value="1">
</div>
</div>
</div>
<?php require __DIR__ . '/vendor_template_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary text-bold" name="edit_vendor_template"><i class="fa fa-check me-2"></i>Update Template</button>
<button type="submit" name="edit_vendor_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
<?php }
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,186 @@
<?php
/*
* A vendor template's fields - for vendor_template_add.php and
* vendor_template_edit.php, which set $vt (vendorTemplateRowFields() of the
* template, or blanks when new), $vt_id (0 when new) and, editing, $vt_vendors
* (how many vendors were made from it). The same tabs as a vendor's own
* window - Details, Support, Account and Notes - as a vendor made from it
* gets every one of them. Editing, the fields can be changed on the vendors
* made from it too. Posts to admin/post.php (admin/post/vendor_template.php).
*/
isset($mysqli) || die("Direct file access is not allowed");
$form_id = 'vendorTemplateForm' . ($vt_id ?: 'New');
$value = function ($key) use ($vt) {
return escapeHtml((string) ($vt[$key] ?? ''));
};
$phone_value = ($vt['phone'] ?? '') !== '' ? escapeHtml(formatPhoneNumber($vt['phone'], $vt['phone_country_code'] ?? '', false)) : '';
?>
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#<?= $form_id ?>Details"><i class="fas fa-fw fa-building me-2 d-none d-lg-inline"></i>Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Support"><i class="fas fa-fw fa-headset me-2 d-none d-lg-inline"></i>Support</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Account"><i class="fas fa-fw fa-id-card me-2 d-none d-lg-inline"></i>Account</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Notes"><i class="fas fa-fw fa-sticky-note me-2 d-none d-lg-inline"></i>Notes</a>
</li>
</ul>
<div class="tab-content" id="<?= $form_id ?>">
<!-- Who they are -->
<div class="tab-pane fade show active" id="<?= $form_id ?>Details">
<div class="row g-3">
<div class="col-12">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-building"></i></span>
<input type="text" class="form-control" name="name" placeholder="Comcast Business, Dell, Microsoft" maxlength="200" value="<?= $value('name') ?>" required <?= $vt_id ? '' : 'autofocus' ?>>
</div>
</div>
<div class="col-12">
<label class="form-label">What they are</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
<input type="text" class="form-control" name="description" placeholder="Business internet and phone, servers and workstations" maxlength="200" value="<?= $value('description') ?>">
</div>
</div>
</div>
<div class="form-text mt-3">A vendor added to a client from it starts with everything here - their own account number and PIN go on after.</div>
</div>
<!-- How to reach support -->
<div class="tab-pane fade" id="<?= $form_id ?>Support">
<div class="row g-3">
<div class="col-md-8">
<label class="form-label">Support phone</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-phone"></i></span>
<input type="hidden" name="phone_country_code" value="<?= $value('phone_country_code') ?>">
<input type="tel" class="form-control" name="phone" value="<?= $phone_value ?>" placeholder="Phone number" maxlength="200" data-itflow-phone="phone_country_code">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Extension / option</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-hashtag"></i></span>
<input type="text" class="form-control" name="extension" value="<?= $value('extension') ?>" placeholder="ext." maxlength="200" inputmode="numeric">
</div>
</div>
<div class="col-md-6">
<label class="form-label">Support hours</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
<input type="text" class="form-control" name="hours" placeholder="24/7, Mon-Fri 8-6 ET" maxlength="200" value="<?= $value('hours') ?>">
</div>
</div>
<div class="col-md-6">
<label class="form-label">SLA</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-handshake"></i></span>
<input type="text" class="form-control" name="sla" placeholder="4 hour response, next business day" maxlength="200" value="<?= $value('sla') ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Support email</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
<input type="email" class="form-control" name="email" placeholder="support@vendor.com" maxlength="200" value="<?= $value('email') ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Support site or portal</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
<input type="text" class="form-control" name="website" placeholder="support.vendor.com" maxlength="200" value="<?= $value('website') ?>">
</div>
</div>
</div>
</div>
<!-- What they ask for, and who looks after us -->
<div class="tab-pane fade" id="<?= $form_id ?>Account">
<div class="row g-3">
<div class="col-md-7">
<label class="form-label">Account number</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-fingerprint"></i></span>
<input type="text" class="form-control" name="account_number" placeholder="Usually each client's own - leave blank" maxlength="200" value="<?= $value('account_number') ?>">
</div>
</div>
<div class="col-md-5">
<label class="form-label">PIN / passcode</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<input type="text" class="form-control" name="code" placeholder="Usually each client's own" maxlength="200" value="<?= $value('code') ?>" autocomplete="off">
</div>
</div>
<div class="col-12">
<div class="form-text mt-0">Fill these in only when every client uses the same one - your own partner or reseller account, say.</div>
</div>
<div class="col-12">
<label class="form-label">Account manager</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user-tie"></i></span>
<input type="text" class="form-control" name="contact_name" placeholder="Your rep there, when every client has the same one" maxlength="200" value="<?= $value('contact_name') ?>">
</div>
</div>
</div>
</div>
<!-- Everything else -->
<div class="tab-pane fade" id="<?= $form_id ?>Notes">
<label class="form-label">Notes</label>
<textarea class="form-control" rows="10" name="notes" placeholder="Escalation path, what they need before they will help, menu options, how to open a case online - what every client's vendor should say"><?= $value('notes') ?></textarea>
</div>
</div>
<?php if ($vt_id && !empty($vt_vendors)) { ?>
<!-- The vendors made from it, changed too - the fields ticked -->
<div class="border rounded p-3 mt-3 bg-body-tertiary" data-vendor-template-push>
<div class="fw-semibold mb-1"><i class="fas fa-fw fa-sync-alt text-secondary me-1"></i>Change them on the <?= $vt_vendors ?> vendor<?= $vt_vendors === 1 ? '' : 's' ?> made from it too</div>
<div class="small text-body-secondary mb-2">Ticked fields are set to what is here on each one - what a client's vendor says now is replaced.</div>
<div class="row row-cols-2 row-cols-md-3 g-1 small">
<?php foreach (vendorTemplateFieldLabels() as $key => $field) { ?>
<div class="col">
<div class="form-check mb-0">
<input class="form-check-input" type="checkbox" name="push[]" value="<?= $key ?>" id="<?= $form_id ?>Push<?= $key ?>">
<label class="form-check-label" for="<?= $form_id ?>Push<?= $key ?>"><i class="fas fa-fw <?= $field['icon'] ?> text-secondary me-1"></i><?= $field['label'] ?></label>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<script>
itflowReady(function () {
var form = document.getElementById(<?= json_encode($form_id) ?>).closest('form');
// A required field on a tab that isn't showing: show that tab and point at it
var reported = false;
form.addEventListener('invalid', function (e) {
var pane = e.target.closest('.tab-pane');
var tab = pane && form.querySelector('[data-bs-toggle="pill"][href="#' + pane.id + '"]');
if (!tab || pane.classList.contains('active') || reported) {
return;
}
reported = true;
tab.addEventListener('shown.bs.tab', function () {
reported = false;
e.target.reportValidity();
}, { once: true });
bootstrap.Tab.getOrCreateInstance(tab).show();
}, true);
});
</script>