128 lines
5.5 KiB
PHP
128 lines
5.5 KiB
PHP
<?php include(__DIR__ . '/../include/headscript.php'); ?>
|
|
<?php
|
|
require_once __DIR__ . '/include/functions.php';
|
|
|
|
// Cumulative calendar: deadlines + trainings + maintenances.
|
|
// Visible to anyone who can see at least one of the three modules; each
|
|
// layer is filtered again on the backend by its own permission.
|
|
$layers = [
|
|
'deadlines' => ['label' => 'Scadenze', 'permission' => 'deadlines.view', 'color' => '#6f42c1', 'icon' => '📅'],
|
|
'trainings' => ['label' => 'Formazione', 'permission' => 'hr.trainings.view', 'color' => '#198754', 'icon' => '🎓'],
|
|
'maintenances' => ['label' => 'Manutenzioni', 'permission' => 'maintenance.calendar.view', 'color' => '#2f7d8f', 'icon' => '🔧'],
|
|
];
|
|
|
|
$availableLayers = array_filter($layers, fn($layer) => userCan($layer['permission']));
|
|
|
|
if (!$availableLayers) {
|
|
http_response_code(403);
|
|
exit('Permesso negato.');
|
|
}
|
|
|
|
$MNT_TITLE = 'Calendario cumulativo';
|
|
$MNT_PLUGINS = ['fullcalendar'];
|
|
?>
|
|
<!doctype html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<?php include __DIR__ . '/include/page_head.php'; ?>
|
|
<style>
|
|
#mntGlobalCalendar { --fc-border-color: #e6eef0; }
|
|
#mntGlobalCalendar .fc-toolbar-title { font-size: 1.05rem; font-weight: 700; color: var(--mnt-heading); }
|
|
#mntGlobalCalendar .fc-event { cursor: pointer; font-size: 0.75rem; }
|
|
.mnt-layer-toggle { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.35rem 0.75rem; border-radius: 999px; border: 1.5px solid var(--layer-color); color: var(--layer-color); font-weight: 600; font-size: 0.8rem; cursor: pointer; user-select: none; transition: all 0.15s; }
|
|
.mnt-layer-toggle input { display: none; }
|
|
.mnt-layer-toggle.is-on { background: var(--layer-color); color: #fff; }
|
|
@media (max-width: 767.98px) {
|
|
#mntGlobalCalendar .fc-toolbar { flex-direction: column; gap: 0.5rem; }
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<?php include __DIR__ . '/include/wrapper_open.php'; ?>
|
|
<?php include(__DIR__ . '/../include/navbar.php'); ?>
|
|
<?php include(__DIR__ . '/../include/topbar.php'); ?>
|
|
|
|
<div class="page-wrapper">
|
|
<div class="page-content">
|
|
|
|
<div class="card mnt-card">
|
|
<div class="card-header d-flex align-items-center justify-content-between flex-wrap gap-2">
|
|
<h5><i class="fa-solid fa-layer-group me-2"></i>Calendario cumulativo</h5>
|
|
<div class="header-actions d-flex gap-2 flex-wrap">
|
|
<?php if (userCan('maintenance.calendar.view')): ?>
|
|
<a href="manutenzioni/calendar.php" class="btn btn-mnt-outline d-inline-flex align-items-center gap-2">
|
|
<i class="fa-solid fa-calendar-days"></i><span>Solo manutenzioni</span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="d-flex gap-2 flex-wrap mb-3">
|
|
<?php foreach ($availableLayers as $key => $layer): ?>
|
|
<label class="mnt-layer-toggle is-on" style="--layer-color: <?= mnt_h($layer['color']) ?>">
|
|
<input type="checkbox" class="layer-checkbox" value="<?= mnt_h($key) ?>" checked>
|
|
<span><?= $layer['icon'] ?> <?= mnt_h($layer['label']) ?></span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div id="mntGlobalCalendar"></div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<?php include(__DIR__ . '/../include/footer.php'); ?>
|
|
</div>
|
|
|
|
<?php include(__DIR__ . '/../jsinclude.php'); ?>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const el = document.getElementById('mntGlobalCalendar');
|
|
const isMobile = window.innerWidth < 768;
|
|
|
|
function activeLayers() {
|
|
return $('.layer-checkbox:checked').map((i, cb) => cb.value).get().join(',');
|
|
}
|
|
|
|
const calendar = new FullCalendar.Calendar(el, {
|
|
locale: 'it',
|
|
initialView: isMobile ? 'listMonth' : 'dayGridMonth',
|
|
headerToolbar: {
|
|
left: 'prev,next today',
|
|
center: 'title',
|
|
right: isMobile ? 'listMonth,dayGridMonth' : 'dayGridMonth,listMonth'
|
|
},
|
|
height: 'auto',
|
|
firstDay: 1,
|
|
events: function (info, success, failure) {
|
|
const layers = activeLayers();
|
|
if (!layers) { success([]); return; }
|
|
|
|
$.getJSON('manutenzioni/ajax/get_global_calendar_events.php', {
|
|
start: info.startStr,
|
|
end: info.endStr,
|
|
layers: layers
|
|
}).done(success).fail(failure);
|
|
},
|
|
eventClick: function (info) {
|
|
const url = info.event.extendedProps.url;
|
|
if (url) { window.location = url; }
|
|
}
|
|
});
|
|
|
|
calendar.render();
|
|
|
|
$('.layer-checkbox').on('change', function () {
|
|
$(this).closest('.mnt-layer-toggle').toggleClass('is-on', this.checked);
|
|
calendar.refetchEvents();
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|