32 lines
847 B
PHP
32 lines
847 B
PHP
<?php
|
|
/**
|
|
* Shared helpers for ABHI MIS HTML + PDF embed mode.
|
|
* Expects: $vm, $fmt, $embed, $charts
|
|
*/
|
|
|
|
$charts = $charts ?? [];
|
|
$embed = !empty($embed);
|
|
|
|
$chartHtml = static function (string $key, string $canvasId) use ($embed, $charts): string {
|
|
if ($embed && !empty($charts[$key]) && is_file((string) $charts[$key])) {
|
|
return '<img class="chart-img" src="' . htmlspecialchars((string) $charts[$key], ENT_QUOTES) . '" alt="">';
|
|
}
|
|
|
|
return '<canvas id="' . htmlspecialchars($canvasId, ENT_QUOTES) . '"></canvas>';
|
|
};
|
|
|
|
$num = static function ($n, int $d = 0) use ($fmt): string {
|
|
return esc($fmt($n, $d));
|
|
};
|
|
|
|
$dash = static function ($v) use ($fmt): string {
|
|
if ($v === '' || $v === null) {
|
|
return '—';
|
|
}
|
|
if (is_numeric($v)) {
|
|
return esc($fmt($v));
|
|
}
|
|
|
|
return esc((string) $v);
|
|
};
|