Files
itflow/admin/modals/document_template/document_template_form.php
johnnyq 9fdc2f7032 Document templates stage 1: Admin > Document Templates on the standard list with full search across name, summary and what it says, Active and Archived tabs with counts, sortable Used (documents made from it and for how many clients), Last used and Changed (when and by whom), paging, and a row menu with Edit, New document for a client, Copy, Archive/Restore and Delete; the template page rebuilt on the ticket template page's layout showing what it says made safe with its bracketed words marked and listed as left to fill in, its use and latest documents with their client, who made and last changed it and its images, with New document for a client opening a window that makes one for the client picked and opens it; one shared New/Edit window with icons in front of each field, a summary, and Draft it with AI only when an AI model is set up for documentation; Copy takes copies of its images, Delete takes its image folder and unlinks its documents, and archived templates aren't offered for new documents; migration 3.2.5 adds documents.document_template_id so documents remember their template and its use is counted from the update, and the document page says which template it came from; new functions/document_template.php shared by the admin pages and add_document_from_template, which now takes the template's name and summary when none are given and checks the client exists; the Document from template window shows each template's summary and how often it has been used and can open with one picked, and its Add one in Admin link checks for an admin rather than role id 3; changelog updated
2026-10-18 15:37:03 -04:00

98 lines
4.4 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.
*
* 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">Words in square brackets - <span class="font-monospace">[Client]</span>, <span class="font-monospace">[Date]</span> - are left in the document for whoever writes it to fill in. Pasted images are kept with the template and copied into each document made from it.</div>
<?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 } ?>