Vendors permission in Admin > Roles for our own vendors, None, Read, Modify or Full, which database update 4.4.6 sets to what each role had: without it the menu opens the clients' vendors, our vendors' pages, quick looks, export and search are refused, and a client's license, network, ticket or service naming one shows only its name; links from a client's license or service to one of our vendors open it again; 26.12.6 changelog

This commit is contained in:
johnnyq
2026-12-05 01:58:55 -05:00
parent de83a2d480
commit ac089c6af8
25 changed files with 185 additions and 40 deletions

View File

@@ -6,12 +6,13 @@ This file documents all notable changes made to ITFlow.
### Upgrading to 26.12.6
Update from Maintenance > Update as usual. This release has two database changes: 4.4.4 adds the settings for Warranty Lookup, and 4.4.5 puts the email and phone links back in Knowledge Base articles and documents written in Markdown.
Update from Maintenance > Update as usual. This release has three database changes: 4.4.4 adds the settings for Warranty Lookup, 4.4.5 puts the email and phone links back in Knowledge Base articles and documents written in Markdown, and 4.4.6 adds the Vendors permission to roles.
- If you have switched a module off in Admin > Settings > Modules - IT documentation, ticketing, invoicing and accounting or any of the others - check that you meant it before updating. Its pages, bookmarks to them and links in old emails stop opening, and the nightly run stops doing its work: with ticketing off, no recurring tickets are raised and resolved tickets aren't closed; with invoicing and accounting off, no recurring invoices or expenses are made, no autopay is charged and no payment reminders go out; with IT documentation off, no domain, certificate, warranty or service review notifications, and shared links - logins, files, documents and IT documentation exports sent to clients - don't open. Switch it back on and the next run picks up what is due, and shared links that haven't run out open again.
- API keys get a 403 saying which module is off for anything of a module that is switched off - tickets with ticketing off, assets and credentials with IT documentation off, invoices with invoicing off.
- Contacts imported before with a ? in place of an accented letter keep it. Import the same file again with **A contact already here** set to **Update it** and their names are put right - contacts are matched by email. Anything else imported that way, such as a location or vendor, is matched by its name, so correct those by hand.
- The warranty lookup button shows beside **Warranty expires** on the asset form straight after the update, as Lenovo needs no key and is switched on. It only asks Lenovo when someone clicks it. Switch Lenovo off in Admin > Warranty Lookup if you'd rather ITFlow didn't ask Lenovo's support site at all.
- Roles have a new **Vendors** permission, for your own vendors. The update gives each role what it had - **Read**, or its **Financial** level where that is higher - so nobody gains or loses anything until you change it in Admin > Roles.
- A `.md` file uploaded to a client's Files now becomes a document you can edit. To upload one as a file, as before, turn on **Keep them as files** in the Upload window. **Import Markdown Files** has gone from the Upload menu - Upload does it.
### New Features & Updates
@@ -26,6 +27,7 @@ Update from Maintenance > Update as usual. This release has two database changes
- Upload a `.md` file and it becomes a document written in Markdown, that you can edit, in the folder it goes into - with **Upload** or by dropping it on the list, no import step. Upload the pictures it uses with it - pick them together, or upload the folder they're in - and they go into the document, found where its links say or by their name; a picture no file uses uploads as a file. A zip of Markdown pages, such as an export from Notion, Obsidian or Confluence, is opened in the Upload window and brought in as the folder it holds: each page a document in its folder with its pictures, its other files uploaded beside them, and Notion's IDs taken off the names. Afterwards ITFlow says which pictures a file uses that weren't uploaded with it, to add in the editor. The Upload window says what will become a document, and **Keep them as files** uploads the `.md` files as they are and a zip as a zip.
- A `.md` already in Files shows as it reads in its preview and quick look, with its pictures that are in the client's files, and **Make it a document**, in its menu and quick look, makes it a document: the pictures it uses are copied in, and the document takes the file's place and its links.
- Copy a Knowledge Base article's link from its **⋮** menu, on its page or beside it in the list - to send it to someone, or to link to it from another article. It offers the links that suit who can read it: **Copy Public Link** for an article for anyone, **Copy Portal Link** for one in the client portal, and **Copy Link** to its page here for one for agents only. A link that won't open yet is greyed out with the reason under it, such as **Publish it first** or **The public help center is off**. Agents who can read articles but not edit them get the menu with these links too.
- A **Vendors** permission in Admin > Roles, for your own vendors - the ones with no client: suppliers, distributors, the colo - at **None**, **Read**, **Modify** or **Full**. Set a role to **None** to keep its agents out of your suppliers' numbers, accounts and contacts: **Vendors** in the menu opens your clients' vendors instead, your own vendors' pages and their export are refused, search leaves them out, and where a client's license, network, ticket or service names one of yours, they see only its name. A client's vendors stay with the **Clients** permission. Adding, editing and deleting your own vendors moves from **Financial** to **Vendors** too.
### Bug Fixes
@@ -34,6 +36,7 @@ Update from Maintenance > Update as usual. This release has two database changes
- Connecting Microsoft 365 for mail works with an app that has only Microsoft Graph's permissions, and where your users can't approve apps. Connect asked Microsoft for Exchange's SMTP and IMAP permissions every time and forced the consent screen, so an app with only Graph's Mail.Send and Mail.ReadWrite couldn't connect, and a mailbox account that isn't allowed to approve apps was stopped at "Need admin approval" even after an admin had granted consent. On the OAuth tab, **The app has**, above **Connect Microsoft 365**, says which permissions you gave the app, and Connect asks for just those - Microsoft asks which account to sign in as instead. Coming back, ITFlow says how email now goes, or what the app is missing. **Test OAuth Token Refresh** no longer fails an app with only Graph's permissions: it checks Graph first, and SMTP and IMAP only for what Graph can't do.
- A card is saved once per client, however often it's entered. A client who set up autopay on two recurring invoices with the same card - or added it again in the portal - ended up with the card saved twice, once for each, as Stripe gives the card a new reference each time it's entered. ITFlow now knows the same card when it comes back: the one saved card is kept, with the details just entered, and every recurring invoice it pays carries on with it. A card that is already saved twice is merged into one overnight - the copy that runs out last is kept and the autopay on the others moves to it - so you don't need to do anything, and its client isn't sent two expiry reminders for it.
- Email and phone links work in Knowledge Base articles and documents - a `mailto:` or `tel:` link showed as plain text on the published article, in the client portal and on the document, while the editor still had it. Those in an article or document written in Markdown were taken out when it was saved; the database update puts them back in the ones already saved, so they don't need saving again. Email and phone links in ticket replies, such as those in an email signature, work too.
- Opening one of your own vendors from a client's license or service works - it said there was nothing to see.
### Developer Updates
@@ -51,6 +54,7 @@ Update from Maintenance > Update as usual. This release has two database changes
- `js/zip_reader.js` - `window.itflowZip.list(file)` reads a zip's central directory, `.unpack(file, entry)` takes a file out, inflating with `DecompressionStream('deflate-raw')`; no zip64 or encrypted entries. The upload window sends a zip with Markdown pages as the folder it holds, through the folder upload, so PHP's zip extension isn't needed. Make it a document: `agent/modals/file/file_make_document.php`, `make_file_document`, `markdownFileMakeDocument()`. `get_file_markdown` (`agent/ajax.php`) and `fileMarkdownPreviewHtml()` render an uploaded .md - its pictures in Files as `file.php` links - for the grid previewer (`kind: 'markdown'`) and the file quick look. `agent/modals/document/document_import_markdown.php` and `import_markdown_documents` are removed. `fileUploadExtensions()` takes `.markdown`, and `fileTypeInfo()` calls `.md` Markdown.
- `purifierUriSchemes()` (`functions/sanitize.php`) is the one list of address schemes HTMLPurifier lets through - `http`, `https`, `mailto`, `tel` and `data` - for `documentHtmlPurify()` and the ticket views (`agent/ticket.php`, `agent/modals/ticket/ticket.php`, `client/ticket.php`, `guest/guest_view_ticket.php`, `guest/guest_approve_ticket_task.php`), each of which set `http`/`https`/`data` only. HTMLPurifier still checks each: a `mailto:` must be an address, a `tel:` is cut down to its digits, and `javascript:`, `vbscript:`, `file:` and the rest go. Database 4.4.5 makes `document_content` and `kb_article_content` (with their `_raw` search text) again from the Markdown of those with `mailto:` or `tel:` in it, keeping `_updated_at`; it stops, to be run again, if the process still has the functions from before it.
- `kbCopyLinks($row)` (`functions/kb.php`) gives an article's links for its readers - `[label, icon, url, why not, what it is]`, from `kbPublicUrl()`, `kbPortalArticleUrl()` and the new `kbAgentArticleUrl()` - with why one won't open yet (a draft, `kbPublicOn()` or `moduleOn('portal')` off); `kbCopyLinksMenuHtml()` makes them `.clipboardjs` dropdown items, or disabled ones with the reason in `.itflow-dropdown-why`. `agent/kb_article.php` and the rows of `agent/kb.php` show their ⋮ menu for `kbCan(1)` as well as `kbCan(2)` - with only these items for those who can't edit.
- Vendors permission: `module_vendor` (database 4.4.6, module 9 on a fresh install, `setup/seed_data.php` - Technician Read, Accountant Full); 4.4.6 gives every role `max(1, its module_financial level)`. In `functions/vendor.php`, `vendorPermissionReady()` (4.4.6) switches `vendorModule(0)` from `module_financial` to `module_vendor`, and `vendorCan(0, 1)` from always-yes to the permission; `vendorEnforce(0, $level)` enforces it at every level. `vendorIsOurs($vendor_id)` (one query a page) and `vendorCanOpen($vendor_id)` decide whether a mention of a vendor opens: `vendorLink()` and the new `vendorNameHtml()` show the name without a link, and `vendorRedact($row, $vendor_id)` blanks a row's `vendor_phone`, `vendor_account_number`, `vendor_code`, `vendor_email`, contacts and hours - used by `agent/network.php`, `agent/license.php`, `agent/ticket.php`, `agent/service.php` and the network, license and service quick looks. `vendorLink()` no longer puts a client's id on a page link to one of ours. The ours list (`agent/vendors.php`), its export, the vendor quick look and global search's Vendors group check it; the side nav's Vendors goes to `vendors.php?view=clients` without it. `roleModules()` lists modules in `roleModuleInfo()`'s order, then by id.
## [26.12.5]

View File

@@ -0,0 +1,36 @@
<?php
/*
* ITFlow - Database update to version 4.4.6 (from 4.4.5)
* Included by admin/database_updates.php - do not access directly
*
* A Vendors permission for Admin > Roles (module_vendor, functions/vendor.php): our own vendors -
* the ones with no client: suppliers, distributors, the colo - to see (Read), change (Modify) and
* delete (Full), so a role can keep technicians out of their numbers, accounts and contacts. A
* client's vendors stay with the Clients permission.
*
* Until now anyone could see ours and Financial changed them, so each role is given that here:
* Read, or its Financial level when that is higher. Nothing changes until an admin lowers it.
* Admins have every permission.
*
* Re-runnable: the permission, and each role's level for it, is added only where it isn't there.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
if (!mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM modules WHERE module_name = 'module_vendor'"))) {
mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_vendor', module_description = 'Our own vendors - suppliers, distributors, the colo - with their numbers, accounts and contacts'");
}
$itflow_vendor_module = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT module_id FROM modules WHERE module_name = 'module_vendor' LIMIT 1"))[0]);
$itflow_financial_module = intval((mysqli_fetch_row(mysqli_query($mysqli, "SELECT module_id FROM modules WHERE module_name = 'module_financial' LIMIT 1")) ?: [0])[0]);
$itflow_roles = mysqli_query($mysqli, "SELECT role_id,
(SELECT MAX(user_role_permission_level) FROM user_role_permissions WHERE user_role_id = role_id AND module_id = $itflow_financial_module) AS financial,
(SELECT COUNT(*) FROM user_role_permissions WHERE user_role_id = role_id AND module_id = $itflow_vendor_module) AS has_vendor
FROM user_roles");
while ($itflow_roles && ($itflow_role = mysqli_fetch_assoc($itflow_roles))) {
if (intval($itflow_role['has_vendor']) === 0) {
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = " . intval($itflow_role['role_id']) . ",
module_id = $itflow_vendor_module, user_role_permission_level = " . max(1, min(3, intval($itflow_role['financial']))));
}
}

View File

@@ -66,12 +66,16 @@
</li>
<?php } ?>
<li class="nav-item">
<a href="/agent/vendors.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "vendors.php" || basename($_SERVER["PHP_SELF"]) == "vendor.php") { echo "active"; } ?>">
<i class="nav-icon fas fa-building"></i>
<p>Vendors</p>
</a>
</li>
<?php // Our vendors with the Vendors permission; without it, every client's when the agent sees clients ?>
<?php $nav_vendors = vendorCan(0, 1) ? '/agent/vendors.php' : (lookupUserPermission('module_client') >= 1 ? '/agent/vendors.php?view=clients' : ''); ?>
<?php if ($nav_vendors !== '') { ?>
<li class="nav-item">
<a href="<?= $nav_vendors ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "vendors.php" || basename($_SERVER["PHP_SELF"]) == "vendor.php") { echo "active"; } ?>">
<i class="nav-icon fas fa-building"></i>
<p>Vendors</p>
</a>
</li>
<?php } ?>
<?php if (moduleOn('calendar')) { ?>
<li class="nav-item">

View File

@@ -26,6 +26,7 @@ enforceUserPermission('module_support');
$software_id = intval($_GET['software_id'] ?? 0);
$license = softwareRow($software_id);
$license = $license ? vendorRedact($license, $license['vendor_id']) : $license;
if (!$license || ($client_url && intval($license['software_client_id']) !== intval($client_id))) {

View File

@@ -133,7 +133,7 @@ ob_start();
<li class="itflow-link-row">
<?php if ($type === 'vendor') { ?>
<?= vendorTile($name, 'sm') ?>
<div class="min-w-0 flex-grow-1"><div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/vendor/vendor.php?id=<?= $id ?>"><?= escapeHtml($name) ?></a></div><div class="small text-body-secondary">Vendor</div></div>
<div class="min-w-0 flex-grow-1"><div class="d-flex"><?= vendorCanOpen($id) ? '<a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/vendor/vendor.php?id=' . intval($id) . '">' . escapeHtml($name) . '</a>' : '<span class="text-truncate">' . escapeHtml($name) . '</span>' ?></div><div class="small text-body-secondary">Vendor</div></div>
<?php } elseif ($type === 'software') { ?>
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-cube"></i></span>
<div class="min-w-0 flex-grow-1"><div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/software/software.php?id=<?= $id ?>"><?= escapeHtml($name) ?></a></div><div class="small text-body-secondary">License</div></div>

View File

@@ -126,7 +126,7 @@ ob_start();
<?php if (!$is_transfer && intval($row['expense_vendor_id'])) { ?>
<div class="itflow-glance-item" title="Vendor">
<i class="fas fa-fw fa-building"></i>
<a class="text-truncate" href="vendor.php?vendor_id=<?= intval($row['expense_vendor_id']) ?>"><?= escapeHtml($row['vendor_name']) ?></a>
<?= vendorNameHtml($row['expense_vendor_id'], $row['vendor_name'], 'text-truncate') ?>
</div>
<?php } ?>
<div class="itflow-glance-item" title="Category">

View File

@@ -10,6 +10,7 @@
require_once '../../../includes/modal_header.php';
$network = networkForModal($_GET['id'] ?? 0, 1);
$network = vendorRedact($network, $network['network_vendor_id']);
$network_id = intval($network['network_id']);
$client_id = intval($network['network_client_id']);
$type = networkType($network);

View File

@@ -108,7 +108,7 @@ ob_start();
<?php if (intval($row['recurring_expense_vendor_id'])) { ?>
<div class="itflow-glance-item" title="Vendor">
<i class="fas fa-fw fa-building"></i>
<a class="text-truncate" href="vendor.php?vendor_id=<?= intval($row['recurring_expense_vendor_id']) ?>"><?= escapeHtml($row['vendor_name']) ?></a>
<?= vendorNameHtml($row['recurring_expense_vendor_id'], $row['vendor_name'], 'text-truncate') ?>
</div>
<?php } ?>
<div class="itflow-glance-item" title="Paid from">

View File

@@ -25,7 +25,7 @@ $active = function ($row) {
};
$assets = array_values(array_filter(serviceLinked($service_id, 'asset'), $active));
$contacts = array_values(array_filter(serviceLinked($service_id, 'contact'), $active));
$vendors = array_values(array_filter(serviceLinked($service_id, 'vendor'), $active));
$vendors = array_map(function ($vendor) { return vendorRedact($vendor, $vendor['id']); }, array_values(array_filter(serviceLinked($service_id, 'vendor'), $active)));
$urls = serviceUrls($service_id, $can_credentials);
$page_url = escapeHtml(serviceUrl($service_id, $client_id));

View File

@@ -16,6 +16,7 @@ enforceUserPermission('module_support');
$software_id = intval($_GET['id'] ?? 0);
$license = softwareRow($software_id);
$license = $license ? vendorRedact($license, $license['vendor_id']) : $license;
if (!$license) {
echo json_encode(['error' => 'That license no longer exists.']);
exit;

View File

@@ -17,7 +17,9 @@ if (!$vendor) {
exit;
}
$client_id = intval($vendor['vendor_client_id']);
if ($client_id) {
if (!$client_id) {
vendorEnforce(0, 1);
} else {
enforceUserPermission('module_client');
enforceClientAccess();
}

View File

@@ -29,6 +29,7 @@ enforceUserPermission('module_support');
$network_id = intval($_GET['network_id'] ?? 0);
$network = networkRow($network_id);
$network = $network ? vendorRedact($network, $network['network_vendor_id']) : $network;
if (!$network || ($client_url && intval($network['network_client_id']) !== intval($client_id))) {

View File

@@ -456,6 +456,7 @@ if (isExportRequest('export_vendors')) {
$archive_query = $archived ? "(client_archived_at IS NOT NULL OR vendor_archived_at IS NOT NULL)" : "(client_archived_at IS NULL AND vendor_archived_at IS NULL)";
} else {
// Ours, same as the vendors page
vendorEnforce(0, 1);
$client_id = 0; // for Logging
$client_query = "AND vendor_client_id = 0";
$file_name_prepend = "$session_company_name-";

View File

@@ -124,7 +124,7 @@ if (!$product) {
<?php if ($product['product_code']) { ?><span title="Your code"><i class="fas fa-fw fa-barcode me-1"></i><span class="font-monospace"><?= escapeHtml($product['product_code']) ?></span></span><?php } ?>
<?php if ($product['category_name']) { ?><span title="Income category"><i class="fas fa-fw fa-list me-1"></i><?= escapeHtml($product['category_name']) ?></span><?php } ?>
<span><i class="fas fa-fw fa-redo-alt me-1"></i><?= escapeHtml($billed) ?></span>
<?php if ($product['vendor_name']) { ?><span><i class="fas fa-fw fa-building me-1"></i><a class="text-reset" href="vendor.php?vendor_id=<?= intval($product['product_vendor_id']) ?>"><?= escapeHtml($product['vendor_name']) ?></a></span><?php } ?>
<?php if ($product['vendor_name']) { ?><span><i class="fas fa-fw fa-building me-1"></i><?= vendorNameHtml($product['product_vendor_id'], $product['vendor_name'], 'text-reset') ?></span><?php } ?>
</div>
</div>
@@ -282,7 +282,7 @@ if (!$product) {
<div class="card-body">
<dl class="itflow-asset-dl mb-0">
<dt>Vendor</dt>
<dd><?= $product['vendor_name'] ? '<a href="vendor.php?vendor_id=' . intval($product['product_vendor_id']) . '">' . escapeHtml($product['vendor_name']) . '</a>' : '<span class="text-body-secondary">Not set</span>' ?></dd>
<dd><?= $product['vendor_name'] ? vendorNameHtml($product['product_vendor_id'], $product['vendor_name']) : '<span class="text-body-secondary">Not set</span>' ?></dd>
<dt>Part #</dt>
<dd>
<?php if ($product['product_vendor_part']) { ?>

View File

@@ -388,7 +388,7 @@ $add_type = in_array($view, ['product', 'hardware', 'stocked', 'reorder'], true)
</td>
<td class="d-none d-xl-table-cell">
<?php if ($row['vendor_name']) { ?>
<a class="text-reset" href="vendor.php?vendor_id=<?= intval($row['product_vendor_id']) ?>"><?= escapeHtml($row['vendor_name']) ?></a>
<?= vendorNameHtml($row['product_vendor_id'], $row['vendor_name'], 'text-reset') ?>
<?php if ($row['product_vendor_part']) { ?><div class="small text-body-secondary font-monospace"><?= escapeHtml($row['product_vendor_part']) ?></div><?php } ?>
<?php } else { ?>
<span class="text-body-secondary">-</span>

View File

@@ -85,7 +85,7 @@ if (!$po || !poAccessible($po['po_id'])) {
<span class="fs-6"><?= poStatusBadge($status) ?></span>
</h1>
<div class="text-body-secondary small d-flex flex-wrap column-gap-3 row-gap-1">
<span><i class="fas fa-fw fa-building me-1"></i><a class="text-reset" href="vendor.php?vendor_id=<?= intval($po['po_vendor_id']) ?>"><?= escapeHtml((string) $po['vendor_name']) ?></a></span>
<span><i class="fas fa-fw fa-building me-1"></i><?= vendorNameHtml($po['po_vendor_id'], (string) $po['vendor_name'], 'text-reset') ?></span>
<span title="<?= formatDateTime($po['po_created_at']) ?>"><i class="fas fa-fw fa-pencil-alt me-1"></i>Made <?= escapeHtml(date('M j, Y', strtotime($po['po_created_at']))) ?><?= $po['created_by_name'] ? ' by ' . escapeHtml($po['created_by_name']) : '' ?></span>
<?php if ($po['po_approved_at'] && $po['approved_by_name'] && in_array($status, ['approved', 'ordered', 'partial', 'received'], true)) { ?>
<span title="<?= escapeHtml((string) $po['po_approval_note']) ?>"><i class="fas fa-fw fa-thumbs-up me-1"></i>Approved by <?= escapeHtml($po['approved_by_name']) ?></span>

View File

@@ -92,7 +92,7 @@ unset($vendor);
$columns = [
'vendor' => ['label' => 'Vendor', 'html' => function ($row) {
$name = escapeHtml($row['vendor']);
return $row['exists'] ? '<a class="fw-semibold text-body" href="/agent/vendor.php?vendor_id=' . $row['vendor_id'] . '">' . $name . '</a>' : '<span class="text-body-secondary fst-italic">' . $name . '</span>';
return $row['exists'] ? vendorNameHtml($row['vendor_id'], $row['vendor'], 'fw-semibold text-body', '/agent/') : '<span class="text-body-secondary fst-italic">' . $name . '</span>';
}],
'category' => ['label' => 'Mostly', 'class' => 'small text-body-secondary'],
'count' => ['label' => 'Expenses', 'type' => 'count'],

View File

@@ -91,7 +91,7 @@ if (!$service || ($client_url && intval($service['service_client_id']) !== intva
$certificates = serviceLinked($service_id, 'certificate');
$documents = serviceLinked($service_id, 'document');
$contacts = serviceLinked($service_id, 'contact');
$vendors = serviceLinked($service_id, 'vendor');
$vendors = array_map(function ($vendor) { return vendorRedact($vendor, $vendor['id']); }, serviceLinked($service_id, 'vendor'));
$archived_credentials = $can_credentials ? array_values(array_filter(serviceLinked($service_id, 'credential'), function ($row) { return $row['archived_at']; })) : [];
// Who to call - the vendors' and people's details for the call
@@ -100,7 +100,7 @@ if (!$service || ($client_url && intval($service['service_client_id']) !== intva
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_account_number, vendor_code, vendor_email, vendor_website, vendor_hours, vendor_sla FROM vendors
WHERE vendor_id IN (" . implode(',', array_map('intval', array_column($vendors, 'id'))) . ")");
while ($row = mysqli_fetch_assoc($sql)) {
$vendor_details[intval($row['vendor_id'])] = $row;
$vendor_details[intval($row['vendor_id'])] = vendorRedact($row, $row['vendor_id']);
}
}
$contact_details = [];

View File

@@ -56,6 +56,8 @@ if (isset($_GET['ticket_id'])) {
} else {
$ticket = mysqli_fetch_assoc($sql);
// A case with one of our vendors, to an agent the Vendors permission keeps out - its name only
$ticket = $ticket ? vendorRedact($ticket, $ticket['ticket_vendor_id']) : $ticket;
// Seen - no longer in bold on this agent's tickets list (functions/ticket_read.php)
ticketMarkRead($ticket_id, $session_user_id);

View File

@@ -29,8 +29,9 @@ if (isset($_GET['client_id'])) {
$client_query = "AND vendor_client_id > 0";
$client_url = "view=clients&";
} else {
// Ours
// Ours - the Vendors permission's
require_once "includes/inc_all.php";
vendorEnforce(0, 1);
$view = 'ours';
$client_query = "AND vendor_client_id = 0";
$client_url = '';
@@ -120,7 +121,7 @@ $missing_templates = $view === 'client' && !$archived ? vendorTemplatesMissingFo
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-building me-2"></i><?= $view === 'clients' ? 'Client Vendors' : 'Vendors' ?></h3>
<div class="card-tools d-flex align-items-center gap-2">
<?php if ($view !== 'client' && lookupUserPermission('module_client') >= 1) { ?>
<?php if ($view !== 'client' && lookupUserPermission('module_client') >= 1 && vendorCan(0, 1)) { ?>
<!-- Ours, or every client's -->
<nav class="nav nav-pills itflow-vendor-scope d-none d-md-flex">
<a class="nav-link py-1 <?= $view === 'ours' ? 'active' : 'text-light' ?>" href="vendors.php">Ours</a>
@@ -220,7 +221,7 @@ $missing_templates = $view === 'client' && !$archived ? vendorTemplatesMissingFo
</div>
<div class="<?= $view === 'clients' ? 'col-lg-2' : 'col-lg-5' ?> col-md-6">
<div class="d-flex justify-content-end gap-2">
<?php if ($view !== 'client' && lookupUserPermission('module_client') >= 1) { ?>
<?php if ($view !== 'client' && lookupUserPermission('module_client') >= 1 && vendorCan(0, 1)) { ?>
<nav class="nav nav-pills d-md-none me-auto">
<a class="nav-link py-1 <?= $view === 'ours' ? 'active' : '' ?>" href="vendors.php">Ours</a>
<a class="nav-link py-1 <?= $view === 'clients' ? 'active' : '' ?>" href="vendors.php?view=clients">Clients'</a>

View File

@@ -384,8 +384,9 @@ function linkRowHtml($to, $row, $client_id) {
break;
case 'vendor':
$lead = vendorTile($row['name'], 'sm');
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/vendor/vendor.php?id=$id\">$name</a>";
$detail = implode(' · ', array_filter([$row['vendor_description'], $row['vendor_phone'] ? formatPhoneNumber($row['vendor_phone'], $row['vendor_phone_country_code']) : '']));
$link = vendorCanOpen($id) ? "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/vendor/vendor.php?id=$id\">$name</a>" : "<span class=\"text-truncate\">$name</span>";
// One of ours to an agent the Vendors permission keeps out - its name, not its number
$detail = vendorCanOpen($id) ? implode(' · ', array_filter([$row['vendor_description'], $row['vendor_phone'] ? formatPhoneNumber($row['vendor_phone'], $row['vendor_phone_country_code']) : ''])) : '';
break;
case 'service':
$lead = serviceTile($row['service_category'] ?? '', 'sm');

View File

@@ -30,7 +30,7 @@ const ROLE_LEVEL_TONES = [0 => 'secondary', 1 => 'primary', 2 => 'warning', 3 =>
function roleModuleInfo() {
return [
'module_client' => [
'label' => 'Clients', 'icon' => 'fa-users', 'about' => 'Clients, contacts, locations and vendors',
'label' => 'Clients', 'icon' => 'fa-users', 'about' => 'Clients, contacts, locations and their vendors',
'levels' => [1 => 'See them', 2 => 'Add, edit, import and archive them', 3 => 'Delete them, and anonymize a contact'],
],
'module_support' => [
@@ -49,26 +49,30 @@ function roleModuleInfo() {
'label' => 'Financial', 'icon' => 'fa-piggy-bank', 'about' => 'Payments, income, expenses, accounts, budgets and trips',
'levels' => [1 => 'See them', 2 => 'Add, edit and archive them, and reconcile accounts', 3 => 'Delete them, and undo a reconciliation'],
],
'module_vendor' => [
'label' => 'Vendors', 'icon' => 'fa-building', 'about' => 'Your own vendors - suppliers, distributors, the colo - with their numbers, accounts and contacts. A client\'s vendors go with Clients',
'levels' => [1 => 'See them', 2 => 'Add, edit, import and archive them', 3 => 'Delete them'],
],
'module_reporting' => [
'label' => 'Reports', 'icon' => 'fa-chart-line', 'about' => 'The reports - each needs read access to what it reports on too',
'levels' => [1 => 'Open the reports'], 'max' => 1,
],
'module_ai' => [
'label' => 'AI', 'icon' => 'fa-robot', 'about' => 'Rewording, summaries and drafts, by the AI providers in Admin - each needs access to what it works on too',
'levels' => [1 => 'Use AI'], 'max' => 1,
],
'module_procurement' => [
'label' => 'Purchasing', 'icon' => 'fa-truck-loading', 'about' => 'Items to order, purchase orders to vendors and receiving - with invoicing on',
'levels' => [1 => 'See them', 2 => 'Add items, make and send purchase orders, add tracking and receive', 3 => 'Approve and cancel purchase orders, and undo a receipt'],
'full' => 'approve or cancel purchase orders, or undo a receipt',
],
'module_ai' => [
'label' => 'AI', 'icon' => 'fa-robot', 'about' => 'Rewording, summaries and drafts, by the AI providers in Admin - each needs access to what it works on too',
'levels' => [1 => 'Use AI'], 'max' => 1,
],
];
}
/*
* The modules, in their order - module_id => module_name, label, icon,
* about, levels and max. One the list above doesn't know is named from its
* module_name and its description.
* about, levels and max - the list above's order, then any it doesn't know,
* named from its module_name and its description.
*/
function roleModules() {
global $mysqli;
@@ -86,6 +90,10 @@ function roleModules() {
'levels' => [1 => 'See it', 2 => 'Add, edit and archive', 3 => 'Delete'],
]) + ['module_name' => $name, 'max' => 3];
}
$order = array_flip(array_keys($info));
uksort($modules, function ($a, $b) use ($modules, $order) {
return [$order[$modules[$a]['module_name']] ?? PHP_INT_MAX, $a] <=> [$order[$modules[$b]['module_name']] ?? PHP_INT_MAX, $b];
});
return $modules;
}

View File

@@ -635,14 +635,14 @@ function globalSearchGroups($terms, $deep) {
'key' => 'vendors', 'label' => 'Vendors', 'icon' => 'building', 'module' => 'module_client',
'select' => 'vendor_id, vendor_name, vendor_description, vendor_phone, vendor_phone_country_code, vendor_client_id, client_name',
'from' => 'vendors LEFT JOIN clients ON vendor_client_id = client_id',
'where' => "vendor_archived_at IS NULL
'where' => "vendor_archived_at IS NULL" . (vendorCan(0, 1) ? '' : ' AND vendor_client_id > 0') . "
AND (vendor_name LIKE '%$like%' OR vendor_description LIKE '%$like%' OR vendor_account_number LIKE '%$like%'
OR vendor_contact_name LIKE '%$like%' OR vendor_email LIKE '%$like%' OR vendor_contact_email LIKE '%$like%' $vendor_phone_match
" . tagSearchSql('vendor', $like, 'vendors.vendor_id') . ")",
'scope' => 'vendor_client_id',
'tags' => ['vendor', 'vendors.vendor_id'],
'order' => "(vendor_name = '$eq') DESC, (vendor_name LIKE '$like%') DESC, vendor_favorite DESC, vendor_name",
'list_url' => '/agent/vendors.php?' . http_build_query(['q' => $q]),
'list_url' => '/agent/vendors.php?' . http_build_query((vendorCan(0, 1) ? [] : ['view' => 'clients']) + ['q' => $q]),
'item' => function ($row) {
return [
'title' => $row['vendor_name'],

View File

@@ -12,7 +12,9 @@
*
* A vendor with no client is one of ours - a distributor, the colo, the
* accountant - what expenses and recurring expenses are booked against. Ours
* are the financial module's to change; a client's are the client module's.
* take the Vendors permission (module_vendor, database 4.4.6) to see, change
* and delete - a role can keep technicians out of our suppliers' numbers,
* accounts and contacts. A client's are the client module's.
*/
/**
@@ -29,19 +31,39 @@ const VENDOR_USES = [
/** What each domain column makes the vendor - shown beside the domain. */
const VENDOR_DOMAIN_ROLES = ['domain_registrar' => 'Registrar', 'domain_webhost' => 'Web host', 'domain_dnshost' => 'DNS', 'domain_mailhost' => 'Mail'];
/** The module a vendor belongs to - a client's are the client module's, ours the financial module's. */
/**
* Whether the database has the Vendors permission yet (4.4.6). Before it, our
* vendors are anyone's to see and the financial module's to change, as they
* were - an install between the new code and its database update keeps working.
*/
function vendorPermissionReady() {
global $mysqli;
static $ready = null;
if ($ready === null) {
if (defined('CURRENT_DATABASE_VERSION')) {
$version = CURRENT_DATABASE_VERSION;
} else {
$result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1");
$version = $result && ($row = mysqli_fetch_row($result)) ? (string) $row[0] : '0';
}
$ready = version_compare($version, '4.4.6', '>=');
}
return $ready;
}
/** The module a vendor belongs to - a client's are the client module's, ours the Vendors permission's. */
function vendorModule($client_id) {
return intval($client_id) ? 'module_client' : 'module_financial';
return intval($client_id) ? 'module_client' : (vendorPermissionReady() ? 'module_vendor' : 'module_financial');
}
/**
* May this agent do this to a vendor of this client? 1 is to see it, 2 to
* change it, 3 to delete it. Anyone may look up one of our own vendors -
* their number is no secret - as it has always been.
* change it, 3 to delete it. Ours take the Vendors permission; before the
* database has it, anyone may look one up, as they always could.
*/
function vendorCan($client_id, $level) {
$client_id = intval($client_id);
if (!$client_id && $level <= 1) {
if (!$client_id && $level <= 1 && !vendorPermissionReady()) {
return true;
}
return lookupUserPermission(vendorModule($client_id)) >= $level && (!$client_id || hasClientAccess($client_id));
@@ -53,11 +75,32 @@ function vendorEnforce($client_id, $level) {
if ($client_id) {
enforceUserPermission('module_client', $level);
enforceClientAccess($client_id);
} elseif (vendorPermissionReady()) {
enforceUserPermission('module_vendor', $level);
} elseif ($level >= 2) {
enforceUserPermission('module_financial', $level);
}
}
/**
* May this agent open this vendor - its page or quick look - from wherever it's
* mentioned? A client's, on that client's records, yes; one of ours only with
* the Vendors permission. Where it can't, the vendor's name shows without a link.
*/
function vendorCanOpen($vendor_id) {
return vendorCan(0, 1) || !vendorIsOurs($vendor_id);
}
/** Is this one of our own vendors - one with no client? Looked up once a page. */
function vendorIsOurs($vendor_id) {
global $mysqli;
static $ours = null;
if ($ours === null) {
$ours = array_flip(array_map('intval', array_column(mysqli_fetch_all(mysqli_query($mysqli, "SELECT vendor_id FROM vendors WHERE vendor_client_id = 0")), 0)));
}
return isset($ours[intval($vendor_id)]);
}
/** Up to two letters for a vendor's tile - "Keystone Business Fiber" is KB, "Netgate" is NE. */
function vendorInitials($name) {
$name = trim(html_entity_decode((string) $name, ENT_QUOTES, 'UTF-8'));
@@ -92,6 +135,37 @@ function selectOptionVendor($name, $description = '') {
return selectOptionData(['initials' => vendorInitials($name), 'tone' => vendorTone($name), 'soft' => '1', 'description' => $description]);
}
/**
* A row with a vendor in it - a client's network, license, ticket or service -
* with that vendor's call details taken out when it is one of ours and the
* Vendors permission keeps this agent out (vendorCanOpen()): its number,
* account, PIN, email, website, hours and contacts. Its name stays.
*/
function vendorRedact(array $row, $vendor_id) {
if (!intval($vendor_id) || vendorCanOpen($vendor_id)) {
return $row;
}
foreach (['vendor_phone', 'vendor_phone_country_code', 'vendor_extension', 'vendor_account_number', 'vendor_code', 'vendor_email', 'vendor_website',
'vendor_hours', 'vendor_sla', 'vendor_contact_name', 'vendor_contact_email', 'vendor_contact_phone', 'vendor_contact_phone_country_code',
'vendor_contact_extension', 'vendor_contact_mobile', 'vendor_contact_mobile_country_code'] as $key) {
if (array_key_exists($key, $row)) {
$row[$key] = '';
}
}
return $row;
}
/**
* A vendor's name linking to its page - or just its name for an agent who
* can't open it (vendorCanOpen()). Name raw; $base goes before vendor.php.
*/
function vendorNameHtml($vendor_id, $name, $class = '', $base = '') {
$vendor_id = intval($vendor_id);
$label = escapeHtml(html_entity_decode((string) $name, ENT_QUOTES, 'UTF-8'));
$class = $class !== '' ? ' class="' . $class . '"' : '';
return vendorCanOpen($vendor_id) ? "<a$class href=\"{$base}vendor.php?vendor_id=$vendor_id\">$label</a>" : "<span$class>$label</span>";
}
/**
* A vendor wherever a page mentions one: its tile, then its name, opening
* its quick look - or its page with 'page' => true (then 'client_id' too).
@@ -105,8 +179,13 @@ function vendorLink($vendor_id, $name, $options = []) {
$archived = !empty($options['archived']);
$class = trim('text-truncate ' . ($options['class'] ?? '') . ($archived ? ' text-decoration-line-through text-body-secondary' : ''));
$title = $archived ? ' title="Archived vendor"' : '';
if (!vendorCanOpen($vendor_id)) {
// One of ours, to an agent the Vendors permission keeps out - its name, nothing to open
return '<span class="itflow-contact-ref">' . vendorTile($name, 'xs') . "<span class=\"$class\"$title>$label</span></span>";
}
if (!empty($options['page'])) {
$client_id = intval($options['client_id'] ?? 0);
// One of ours opens as ours - its page with a client's id turned it away
$client_id = vendorIsOurs($vendor_id) ? 0 : intval($options['client_id'] ?? 0);
$href = 'vendor.php?' . ($client_id ? "client_id=$client_id&amp;" : '') . "vendor_id=$vendor_id";
$link = "<a class=\"$class\" href=\"$href\"$title>$label</a>";
} else {

View File

@@ -95,6 +95,7 @@ function seedDefaultData($mysqli)
mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_reporting', module_description = 'Access to all reports'");
mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_ai', module_description = 'Using AI - rewording, summaries and drafts'");
mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_procurement', module_description = 'Access to purchasing - items to order, purchase orders and receiving'");
mysqli_query($mysqli, "INSERT INTO modules SET module_name = 'module_vendor', module_description = 'Our own vendors - suppliers, distributors, the colo - with their numbers, accounts and contacts'"); // 9
// Add default roles
mysqli_query($mysqli, "INSERT INTO user_roles SET role_id = 1, role_name = 'Accountant', role_description = 'Built-in - Limited access to financial-focused modules'");
@@ -104,6 +105,7 @@ function seedDefaultData($mysqli)
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 1, module_id = 5, user_role_permission_level = 3"); // Full financial
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 1, module_id = 6, user_role_permission_level = 1"); // Read reports
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 1, module_id = 7, user_role_permission_level = 1"); // Use AI
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 1, module_id = 9, user_role_permission_level = 3"); // Full vendors (ours)
mysqli_query($mysqli, "INSERT INTO user_roles SET role_id = 2, role_name = 'Technician', role_description = 'Built-in - Limited access to technical-focused modules'");
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 2, module_id = 1, user_role_permission_level = 2"); // Modify clients
@@ -111,6 +113,7 @@ function seedDefaultData($mysqli)
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 2, module_id = 3, user_role_permission_level = 2"); // Modify credentials
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 2, module_id = 4, user_role_permission_level = 2"); // Modify sales
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 2, module_id = 7, user_role_permission_level = 1"); // Use AI
mysqli_query($mysqli, "INSERT INTO user_role_permissions SET user_role_id = 2, module_id = 9, user_role_permission_level = 1"); // Read vendors (ours)
mysqli_query($mysqli, "INSERT INTO user_roles SET role_id = 3, role_name = 'Administrator', role_description = 'Built-in - Full administrative access to all modules (including user management)', role_is_admin = 1");