Starter Content (admin/starter_content.php) and the Starter
* content step of Get started (admin/getting_started/content.php) both offer
* it. Each item is shown as it will look - a tag as its pill, a category as
* its chip, a product with its price - with what it is for, and a template or
* canned response has Preview, the whole of it in a window
* (admin/starter_content_preview.php answers it). js/starter_content.js keeps
* the ticks and counts in step and opens the previews.
*
* The form sends picked[pack] (the list was there) and items[pack][] (what is
* ticked, by starterItemKey()); the item lists come from
* starterContentItems() in post/starter_content_model.php, which has to be
* loaded first.
*/
defined('FROM_STARTER_CONTENT') || die("Direct file access is not allowed");
/* What an item is for, in a line - '' when the library says nothing. */
function starterItemAbout($pack, $row) {
switch ($pack) {
case 'categories':
return (string) ($row['description'] ?? '');
case 'tags':
return '';
case 'products':
return (string) ($row[5] ?? '');
}
return (string) ($row['description'] ?? '');
}
/*
* An item as it will look - a tag as its pill, a category as its chip, a
* product with its price and how it is billed, anything else its name.
*/
function starterItemLook($pack, $row) {
switch ($pack) {
case 'tags':
return tagPill(['tag_name' => $row[1], 'tag_color' => $row[2], 'tag_icon' => $row[3]]);
case 'categories':
return categoryChip(['category_name' => $row['name'], 'category_type' => $row['type'], 'category_color' => $row['color'], 'category_icon' => $row['icon']]);
case 'products':
[$frequency, $seat] = array_pad(explode(':', (string) ($row[6] ?? '')), 2, '');
return '' . escapeHtml($row[0]) . ''
. escapeHtml(billingMoney(floatval($row[3])) . ' · ' . productBilledText($frequency, $seat)) . '';
}
return '' . escapeHtml(starterItemName($pack, $row)) . '';
}
/* The packs whose items have more to them than a line - shown whole by Preview. */
function starterPreviewPacks() {
return ['ticket_templates', 'project_templates', 'canned_responses', 'vendor_templates', 'document_templates', 'license_templates', 'products'];
}
/* [Words in brackets] in a template, marked as the bits filled in as it is used. */
function starterPreviewFills($html) {
return preg_replace('/\[([A-Za-z][A-Za-z0-9 ,.\'\/&;-]{0,40})\]/', '[$1]', (string) $html);
}
/* A fact of a preview - its label and the value (html), or nothing when there isn't one. */
function starterPreviewFact($label, $html) {
return trim((string) $html) === '' ? '' : '
' . escapeHtml($label) . '
' . $html . '
';
}
/* What a template asks for, as a list - each with its kind, choices and whether it has to be answered. */
function starterPreviewFillIns(array $fill_ins) {
if (!$fill_ins) {
return '';
}
$kinds = ['text' => 'text', 'textarea' => 'longer text', 'date' => 'a date', 'number' => 'a number', 'yesno' => 'yes or no', 'list' => 'one of', 'email' => 'an email address'];
$html = '
';
}
/* A web address as a link out - its host and path as given, https:// in front. */
function starterPreviewLink($address) {
$address = trim((string) $address);
if ($address === '') {
return '';
}
$url = preg_match('#^https?://#i', $address) ? $address : "https://$address";
return '' . escapeHtml($address) . '';
}
/*
* An item whole, for Preview - what it says and sets up, as it will come in.
* '' for a pack whose items are all there is to them (starterItemLook()).
*/
function starterItemPreview($pack, $row) {
$about = starterItemAbout($pack, $row);
$html = $about !== '' && $pack !== 'products' ? '
Prices are starting points - change them once it is here.
';
}
return '';
}
/* Minutes as words without the business-hours qualifier - "3 hours 15 minutes". */
function starterMinutesText($minutes) {
$minutes = intval($minutes);
if ($minutes < 60) {
return $minutes . ' minute' . ($minutes === 1 ? '' : 's');
}
$hours = intdiv($minutes, 60);
$rest = $minutes % 60;
return $hours . ' hour' . ($hours === 1 ? '' : 's') . ($rest ? " $rest minutes" : '');
}
/*
* A pack's Pick which - its items not here yet, each ticked, shown as they
* will look with what they are for, and Preview where there is more to see.
* $form is the id of the form the ticks go with, when they sit outside it (a
* table row's Add). $items from starterContentItems().
*/
function starterPickHtml($pack, array $items, $form = '') {
if (!$items) {
return '';
}
$form_attr = $form !== '' ? ' form="' . escapeHtml($form) . '"' : '';
$previews = in_array($pack, starterPreviewPacks(), true);
$kind = $pack === 'tags' ? ' is-pills' : '';
ob_start(); ?>
Pick which
>