$items_added items: $summary");
} else {
flashAlert("Nothing to add - everything in that selection is already here", 'info');
}
redirect();
}
/*
* Clear out unused - a pack's items that are here and nothing uses, archived
* (admin/modals/starter_content/starter_clear.php ticks which). Checked again
* here, so one put to use since the window opened stays. Undo puts them back.
*/
if (isset($_POST['clear_starter_unused'])) {
validateCSRFToken();
require_once 'starter_content_model.php';
$starter_content_packs = starterContentPacks();
$pack = (string) $_POST['clear_starter_unused'];
if (!isset($starter_content_packs[$pack]) || !starterPackRecords($pack)) {
flashAlert("Unknown starter content pack", 'error');
redirect();
}
$only = null;
if (isset($_POST['picked'][$pack])) {
$only = array_map('strval', array_filter((array) ($_POST['items'][$pack] ?? []), 'is_string'));
if (!$only) {
flashAlert("Nothing is ticked - tick what to archive", 'info');
redirect();
}
}
$label = $starter_content_packs[$pack]['label'];
[$archived, $before] = starterClearUnused($mysqli, $pack, $only);
$count = count($archived);
if ($count) {
logAudit("Starter Content", "Archive", "$session_name archived $count unused from the starter $label pack");
flashAlert("Archived $count unused from " . escapeHtml($label), 'error');
undoOfferChanges($before, "{n} from " . escapeHtml($label) . " put back", 'module_client');
} else {
flashAlert("Nothing to archive - those are in use now, or already archived", '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 {$counts['replaced']} starter ticket templates up to date" . ($counts['forms'] ? " - {$counts['forms']} 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 {$counts['replaced']} 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 {$counts['replaced']} 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['update_starter_vendor_templates'])) {
// The starter vendor templates already here, brought up to this version - the vendors made from them following
validateCSRFToken();
require_once 'starter_content_model.php';
$counts = starterUpdateVendorTemplates();
vendorTemplatesImportLogFollowed($counts);
$followed = vendorTemplatesImportFollowedCount($counts);
if ($counts['replaced']) {
logAudit("Starter Content", "Edit", "$session_name brought {$counts['replaced']} starter vendor templates up to date" . ($followed ? " - $followed vendors changed with them" : ''));
flashAlert("Brought {$counts['replaced']} starter vendor templates up to date" . ($followed ? " - $followed vendor" . ($followed === 1 ? '' : 's') . " made from them changed with them" : ''));
} else {
flashAlert("None of the starter vendor templates are here to update - add them instead", 'info');
}
redirect();
}
if (isset($_POST['update_starter_license_templates'])) {
// The starter license templates already here, brought up to this version
validateCSRFToken();
require_once 'starter_content_model.php';
$counts = starterUpdateLicenseTemplates();
if ($counts['replaced']) {
logAudit("Starter Content", "Edit", "$session_name brought {$counts['replaced']} starter license templates up to date");
flashAlert("Brought {$counts['replaced']} starter license templates up to date" . ($counts['vendors'] ? " - with {$counts['vendors']} vendor template" . ($counts['vendors'] === 1 ? '' : 's') . " they come from" : ''));
} else {
flashAlert("None of the starter license 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", "Delete", "$session_name removed demo data - $clients_removed demo clients and all associated records");
flashAlert("Removed $clients_removed demo clients and everything associated with them", 'error');
} else {
flashAlert("No demo clients found - nothing to remove", 'info');
}
redirect();
}