80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Colori personalizzati della scuola corrente.
|
|
* Includere nel <head> DOPO app.min.css:
|
|
* <?php include('include/schooltheme.php'); ?>
|
|
* Se la scuola non ha colori impostati non stampa nulla.
|
|
*/
|
|
$__th = [
|
|
'primary' => SchoolSettings::get('theme_primary'),
|
|
'sidebar' => SchoolSettings::get('theme_sidebar'),
|
|
'topbar' => SchoolSettings::get('theme_topbar'),
|
|
];
|
|
|
|
if (!function_exists('th_valid')) {
|
|
function th_valid($c): bool
|
|
{
|
|
return is_string($c) && preg_match('/^#[0-9a-fA-F]{6}$/', $c) === 1;
|
|
}
|
|
/** Colore del testo leggibile sopra lo sfondo indicato */
|
|
function th_text(string $hex): string
|
|
{
|
|
$r = hexdec(substr($hex, 1, 2));
|
|
$g = hexdec(substr($hex, 3, 2));
|
|
$b = hexdec(substr($hex, 5, 2));
|
|
return (0.299 * $r + 0.587 * $g + 0.114 * $b) > 160 ? '#374151' : '#ffffff';
|
|
}
|
|
/** Schiarisce/scurisce un colore (percentuale -100..100) */
|
|
function th_shade(string $hex, int $pct): string
|
|
{
|
|
$out = '#';
|
|
for ($i = 1; $i <= 5; $i += 2) {
|
|
$c = hexdec(substr($hex, $i, 2));
|
|
$c = $pct < 0 ? $c * (1 + $pct / 100) : $c + (255 - $c) * ($pct / 100);
|
|
$out .= str_pad(dechex((int) max(0, min(255, round($c)))), 2, '0', STR_PAD_LEFT);
|
|
}
|
|
return $out;
|
|
}
|
|
}
|
|
|
|
$__css = '';
|
|
|
|
if (th_valid($__th['primary'])) {
|
|
$p = $__th['primary'];
|
|
$pt = th_text($p);
|
|
$pd = th_shade($p, -12);
|
|
$__css .= ":root{--os-primary:$p;--bs-primary:$p;}
|
|
.btn-primary,.btn-success{background-color:$p!important;border-color:$p!important;color:$pt!important;}
|
|
.btn-primary:hover,.btn-success:hover{background-color:$pd!important;border-color:$pd!important;}
|
|
.bg-primary{background-color:$p!important;}
|
|
.text-primary{color:$p!important;}
|
|
.filter-chip.active,.view-switcher button.active,.count-chip.active{background:$p!important;border-color:$p!important;color:$pt!important;}
|
|
.page-item.active .page-link{background-color:$p;border-color:$p;}
|
|
.form-check-input:checked{background-color:$p;border-color:$p;}
|
|
";
|
|
}
|
|
|
|
if (th_valid($__th['sidebar'])) {
|
|
$s = $__th['sidebar'];
|
|
$st = th_text($s);
|
|
$sh = th_shade($s, $st === '#ffffff' ? 12 : -6);
|
|
$__css .= ".vertical-menu,.navbar-brand-box{background:$s!important;}
|
|
#sidebar-menu ul li a,#sidebar-menu ul li a i,.view-switcher,.vertical-menu .vertical-menu-btn{color:$st!important;}
|
|
#sidebar-menu ul li a:hover,#sidebar-menu ul li.mm-active>a{background:$sh!important;}
|
|
#sidebar-menu .menu-title{color:$st!important;opacity:.6;}
|
|
";
|
|
}
|
|
|
|
if (th_valid($__th['topbar'])) {
|
|
$t = $__th['topbar'];
|
|
$tt = th_text($t);
|
|
$__css .= "#page-topbar,.isvertical-topbar{background:$t!important;}
|
|
#page-topbar .header-item,#page-topbar .page-title,#page-topbar .header-item i{color:$tt!important;}
|
|
";
|
|
}
|
|
|
|
if ($__css !== '') {
|
|
echo "<style id=\"school-theme\">\n" . $__css . "</style>\n";
|
|
}
|