Files
itflow/admin/post/starter_content.php
johnnyq 5a3f4ba6f5 Document templates stage 4, export, import, starter pack and report: Admin > Document Templates gets a menu beside New with Import, Export, the report and the starter pack, and each template page gets an Export link; the file carries each template's summary, its text with images embedded, its fill-ins and review interval, leaving who should have one to each install; importing a template already there by name can leave it, add the file's copy alongside or replace it (keeping its documents and who should have one), new ones come in required of no one, content goes through the HTML purifier, and images that only point at the other install's uploads are left out with the message saying how many; the MSP starter pack is rebuilt as 14 templates (Asset Inventory and Vendors and Escalation new) that fill in from the client, pull in its sites, networks, equipment, servers, domains, licenses, vendors and contacts as tables, ask for the rest with typed fill-ins, set 6 or 12 month reviews on the ones that go stale, and are required of no one out of the box; Update on Starter Content now covers document templates, bringing older starter templates up to the new versions while keeping their documents and who should have one; new Document Templates report under Clients & Documentation by template (documents made in the period against the period before, current documents, clients with one, coverage of the clients it is required of, documents due a review) and by client (what each should have, has and is missing, and documents due), filtered by client or by the agent who made them, each table exportable as CSV, and client-restricted users seeing only their clients; no database change; changelog updated
2026-10-18 19:50:42 -04:00

155 lines
5.1 KiB
PHP

<?php
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['load_starter_content'])) {
validateCSRFToken();
require_once 'starter_content_model.php';
$starter_content_packs = starterContentPacks();
$requested_pack = $_POST['load_starter_content'];
// Only registry keys are accepted - the value goes nowhere near a query, but
// an unknown pack should say so rather than silently do nothing
if ($requested_pack === 'all') {
$selected_packs = array_keys($starter_content_packs);
} elseif (isset($starter_content_packs[$requested_pack])) {
$selected_packs = [$requested_pack];
} else {
flashAlert("Unknown starter content pack", 'error');
redirect();
}
// Registry order is load order - categories before products, ticket
// templates before the project templates that link to them
$items_added = 0;
$summary = [];
foreach ($selected_packs as $pack) {
$pack_added = starterContentLoad($mysqli, $pack);
if ($pack_added) {
$items_added = $items_added + $pack_added;
$summary[] = "$pack_added " . $starter_content_packs[$pack]['label'];
}
}
if ($items_added) {
$summary = implode(', ', $summary);
logAudit("Starter Content", "Create", "$session_name loaded starter content - $summary");
flashAlert("Added <strong>$items_added</strong> items: $summary");
} else {
flashAlert("Nothing to add - everything in that selection is already here", 'info');
}
redirect();
}
if (isset($_POST['update_starter_ticket_templates'])) {
// The starter ticket templates already here, brought up to this version
validateCSRFToken();
require_once 'starter_content_model.php';
$counts = starterUpdateTicketTemplates();
if ($counts['replaced']) {
logAudit("Starter Content", "Edit", "$session_name brought {$counts['replaced']} starter ticket templates up to date");
flashAlert("Brought <strong>{$counts['replaced']}</strong> starter ticket templates up to date" . ($counts['forms'] ? " - <strong>{$counts['forms']}</strong> have a request form, turned off until you turn it on in their Client portal tab" : ''));
} else {
flashAlert("None of the starter ticket templates are here to update - add them instead", 'info');
}
redirect();
}
if (isset($_POST['update_starter_canned_responses'])) {
// The starter canned responses already here, brought up to this version
validateCSRFToken();
require_once 'starter_content_model.php';
$counts = starterUpdateCannedResponses();
if ($counts['replaced']) {
logAudit("Starter Content", "Edit", "$session_name brought {$counts['replaced']} starter canned responses up to date");
flashAlert("Brought <strong>{$counts['replaced']}</strong> starter canned responses up to date");
} else {
flashAlert("None of the starter canned responses are here to update - add them instead", 'info');
}
redirect();
}
if (isset($_POST['update_starter_document_templates'])) {
// The starter document templates already here, brought up to this version
validateCSRFToken();
require_once 'starter_content_model.php';
$counts = starterUpdateDocumentTemplates();
if ($counts['replaced']) {
logAudit("Starter Content", "Edit", "$session_name brought {$counts['replaced']} starter document templates up to date");
flashAlert("Brought <strong>{$counts['replaced']}</strong> starter document templates up to date");
} else {
flashAlert("None of the starter document templates are here to update - add them instead", 'info');
}
redirect();
}
if (isset($_POST['load_demo_data'])) {
validateCSRFToken();
require_once 'demo_data_model.php';
$counts = demoDataLoad($mysqli);
if (!$counts['clients']) {
flashAlert("Nothing to add - every demo client is already here", 'info');
redirect();
}
$summary = "{$counts['clients']} clients, {$counts['contacts']} contacts, {$counts['assets']} assets, {$counts['documentation']} documentation records, {$counts['tickets']} tickets, {$counts['projects']} projects, {$counts['billing']} billing records, {$counts['company']} company records";
logAudit("Demo Data", "Create", "$session_name loaded demo data - $summary");
if ($counts['skipped_credentials']) {
flashAlert("Added demo data: $summary. Credentials were skipped - the credential vault did not open for this session", 'warning');
} else {
flashAlert("Added demo data: $summary");
}
redirect();
}
if (isset($_POST['remove_demo_data'])) {
validateCSRFToken();
require_once 'demo_data_model.php';
$clients_removed = demoDataRemove($mysqli);
if ($clients_removed) {
logAudit("Demo Data", "Deleted", "$session_name removed demo data - $clients_removed demo clients and all associated records");
flashAlert("Removed <strong>$clients_removed</strong> demo clients and everything associated with them", 'error');
} else {
flashAlert("No demo clients found - nothing to remove", 'info');
}
redirect();
}