Files
itflow/admin/modals/document_template/document_template_form.php
johnnyq 3ee183a09a Document templates stage 2, filled in from the client: placeholders [Client], [Website], [Site], [Address], [Site Phone], [Contact], [First Name], [Contact Email], [Contact Phone], [Agent], [Date], [Month], [Quarter] and [Year] are filled in across a template's name, summary and content when a document is made, using the client's primary site and contact unless another or none is picked; tables of records [Contacts], [Locations], [Assets], [Servers], [Workstations], [Network Equipment], [Printers], [Networks], [Domains], [Certificates], [Licenses], [Vendors] and [Services] put in the client's current records, as a table on a line of their own (an empty row when there are none) or as names in a sentence, all made safe; any other bracketed word is a fill-in asked for when a document is made, set up on the template page as text, date, list or yes/no, required or with help, renamed along with the template text, reset or removed, and dragged into order, with answers checked by ticketFillInAnswers and blanks left in the document; the template page gets Fill-ins and Filled in from the client cards with each kind of word marked in its own colour, and the editor gets a button for each placeholder and table to insert it at the cursor (js/document_template_form.js); New document for a client and Document from template draw the site and contact pickers and fill-ins once the template and client are picked (agent/ajax.php document_template_asks, agent/js/document_template_make.js) and open larger; copying a template copies its fill-ins; Draft it with AI is told the placeholders and tables; migration 3.2.6 adds document_template_fill_ins; fixed the fill-in add and reset messages showing raw HTML around the bracketed name on document and ticket templates; changelog updated
2026-10-18 19:47:57 -04:00

114 lines
5.6 KiB
PHP

<?php
/*
* A document template's fields - shared by its New and Edit windows
* (document_template_add.php, document_template_edit.php), which set
* $template (documentTemplateRow(), or [] for a new one) before including it.
* Posts what documentTemplateFields() reads (functions/document_template.php).
* With an AI model set up for documentation, it can be drafted from a prompt.
* Under the editor, the placeholders filled in from the client and the tables
* of its records put themselves in where the cursor is
* (js/document_template_form.js).
*
* Should not be accessed directly.
*/
isset($mysqli) || die("Direct file access is not allowed");
$t = $template;
$ai_model = getAiModel('Documentation');
?>
<div class="row g-3 mb-3">
<div class="col-lg-5">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-file-alt"></i></span>
<input type="text" class="form-control" name="name" placeholder="What it is - Network Overview" maxlength="200" value="<?= escapeHtml($t['document_template_name'] ?? '') ?>" required autofocus>
</div>
</div>
<div class="col-lg-7">
<label class="form-label">Summary</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="One line on what it covers - shown when an agent picks a template" maxlength="500" value="<?= escapeHtml($t['document_template_description'] ?? '') ?>">
</div>
</div>
</div>
<?php if ($ai_model) { ?>
<div class="mb-3">
<label class="form-label" for="documentTemplatePrompt">Draft it with AI</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-magic"></i></span>
<input type="text" class="form-control" id="documentTemplatePrompt" placeholder="What it is for - a network troubleshooting guide for junior technicians" data-document-template-prompt>
<button class="btn btn-info" type="button" data-document-template-generate><i class="fa fa-fw fa-magic me-1"></i>Draft</button>
</div>
<small class="text-secondary">Replaces what is in the editor below.</small>
</div>
<?php } ?>
<div class="mb-2">
<label class="form-label" for="documentTemplateContent">What it says</label>
<textarea class="form-control tinymce" id="documentTemplateContent" name="content"><?= escapeHtml($t['document_template_content'] ?? '') ?></textarea>
</div>
<div class="small text-secondary mb-1">Filled in from the client as a document is made - click one to put it where the cursor is:</div>
<div class="d-flex flex-wrap gap-1 mb-2">
<?php foreach (DOCUMENT_TEMPLATE_PLACEHOLDERS as $placeholder => $means) { ?>
<button type="button" class="btn btn-sm btn-light border font-monospace" data-document-template-word="<?= escapeHtml($placeholder) ?>" title="<?= escapeHtml(ucfirst($means)) ?>">[<?= escapeHtml($placeholder) ?>]</button>
<?php } ?>
</div>
<div class="small text-secondary mb-1">The client's records as a table, on a line of their own - as they are when the document is made:</div>
<div class="d-flex flex-wrap gap-1 mb-2">
<?php foreach (DOCUMENT_TEMPLATE_TABLES as $table => $holds) { ?>
<button type="button" class="btn btn-sm btn-light border font-monospace text-info-emphasis" data-document-template-word="<?= escapeHtml($table) ?>" data-document-template-table title="<?= escapeHtml(ucfirst($holds)) ?>">[<?= escapeHtml($table) ?>]</button>
<?php } ?>
</div>
<div class="small text-secondary">Any other word in square brackets - <span class="font-monospace">[Firewall Model]</span> - is asked for when a document is made, and set up on the template's page. Pasted images are kept with the template and copied into each document made from it.</div>
<script src="/js/document_template_form.js"></script>
<?php if ($ai_model) { ?>
<script>
itflowBindOnce('itflowDocumentTemplateDraft', 'click', '[data-document-template-generate]', function () {
var button = this;
var prompt = document.querySelector('[data-document-template-prompt]');
if (!prompt || prompt.value.trim() === '') {
if (prompt) {
prompt.focus();
}
return;
}
var label = button.innerHTML;
button.disabled = true;
button.innerHTML = '<i class="fa fa-spinner fa-spin me-1"></i>Drafting...';
fetch('/agent/ajax.php?ai_create_document_template', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
credentials: 'same-origin',
body: new URLSearchParams({ prompt: prompt.value.trim() }).toString()
})
.then(function (res) {
if (!res.ok) {
throw new Error('HTTP ' + res.status);
}
return res.text();
})
.then(function (html) {
var editor = window.tinymce ? tinymce.get('documentTemplateContent') : null;
if (editor) {
editor.setContent(html);
} else {
document.getElementById('documentTemplateContent').value = html;
}
})
.catch(function () {
itflowToast('Could not draft it - try again.', 'error');
})
.finally(function () {
button.disabled = false;
button.innerHTML = label;
});
});
</script>
<?php } ?>