<?php use App\Core\Csrf; $csrf=Csrf::token(); $days=[];$cursor=new DateTimeImmutable($from);$limit=new DateTimeImmutable($to);while($cursor<$limit){$days[$cursor->format('Y-m-d')]=[];$cursor=$cursor->modify('+1 day');}foreach($events as $e){$days[substr((string)$e['start_at'],0,10)][]=$e;} $prev=(new DateTimeImmutable($anchor))->modify($viewMode==='month'?'-1 month':($viewMode==='day'?'-1 day':'-7 days'))->format('Y-m-d');$next=(new DateTimeImmutable($anchor))->modify($viewMode==='month'?'+1 month':($viewMode==='day'?'+1 day':'+7 days'))->format('Y-m-d'); ?>
<link rel="stylesheet" href="/public/assets/css/axiom-planning.css"><script defer src="/public/assets/js/axiom-planning.js"></script>
<main class="pl-wrap">
<header class="pl-hero"><div><span>AXIOM ENGINE</span><h2>Planning</h2><p>Agendas, ressources, événements, indisponibilités et conflits.</p></div><a class="pl-back" href="/public/administration/axiom">← Retour à AXIOM Studio</a></header>
<?php if($flashSuccess):?><div class="pl-alert ok"><?=htmlspecialchars($flashSuccess)?></div><?php endif;?><?php if($flashError):?><div class="pl-alert err"><?=htmlspecialchars($flashError)?></div><?php endif;?>
<section class="pl-toolbar"><div class="pl-nav"><a href="?view=<?=$viewMode?>&date=<?=$prev?>">‹</a><a href="?view=<?=$viewMode?>&date=<?=date('Y-m-d')?>">Aujourd’hui</a><a href="?view=<?=$viewMode?>&date=<?=$next?>">›</a></div><div class="pl-modes"><?php foreach(['day'=>'Jour','week'=>'Semaine','month'=>'Mois'] as $k=>$v):?><a class="<?=$viewMode===$k?'active':''?>" href="?view=<?=$k?>&date=<?=$anchor?>"><?=$v?></a><?php endforeach;?></div><form method="get"><input type="hidden" name="view" value="<?=$viewMode?>"><input type="date" name="date" value="<?=$anchor?>"><select name="calendar"><option value="0">Tous les agendas</option><?php foreach($calendars as $c):?><option value="<?=$c['id']?>" <?=$calendarId==(int)$c['id']?'selected':''?>><?=htmlspecialchars($c['name'])?></option><?php endforeach;?></select><button>Afficher</button></form></section>
<section class="pl-kpis"><article><strong><?=count($events)?></strong><span>événements</span></article><article><strong><?=count($resources)?></strong><span>ressources</span></article><article><strong><?=count($absences)?></strong><span>indisponibilités</span></article><article class="<?=count($conflicts)?'warn':''?>"><strong><?=count($conflicts)?></strong><span>conflits ouverts</span></article></section>
<section class="pl-layout"><div class="pl-main"><section class="pl-calendar view-<?=$viewMode?>"><?php foreach($days as $date=>$items):?><article class="pl-day <?=($date===date('Y-m-d'))?'today':''?>"><header><strong><?=htmlspecialchars((new DateTimeImmutable($date))->format('d/m'))?></strong><span><?=htmlspecialchars(ucfirst((new DateTimeImmutable($date))->format('D')))?></span></header><div class="pl-events"><?php foreach($items as $e):?><div class="pl-event" style="--event-color:<?=htmlspecialchars($e['calendar_color'])?>"><time><?=substr($e['start_at'],11,5)?>–<?=substr($e['end_at'],11,5)?></time><strong><?=htmlspecialchars($e['title'])?></strong><small><?=htmlspecialchars(($e['resource_name']?:$e['location'])?:$e['calendar_name'])?></small><?php if($canManage):?><form method="post" action="/public/administration/axiom/planning/event/delete" onsubmit="return confirm('Annuler cet événement ?')"><input type="hidden" name="_csrf" value="<?=htmlspecialchars($csrf)?>"><input type="hidden" name="event_id" value="<?=$e['id']?>"><button title="Annuler">×</button></form><?php endif;?></div><?php endforeach;?><?php if(!$items):?><span class="pl-empty">Libre</span><?php endif;?></div></article><?php endforeach;?></section>
<?php if($conflicts):?><section class="pl-panel"><h3>Conflits détectés</h3><?php foreach($conflicts as $c):?><div class="pl-conflict"><strong><?=htmlspecialchars($c['resource_name']??'Ressource')?></strong><span><?=htmlspecialchars($c['first_title'])?> ↔ <?=htmlspecialchars($c['second_title'])?></span></div><?php endforeach;?></section><?php endif;?></div>
<aside class="pl-side"><?php if($canManage):?><details open class="pl-panel"><summary>Nouvel événement</summary><form class="pl-form" method="post" action="/public/administration/axiom/planning/event/save"><input type="hidden" name="_csrf" value="<?=htmlspecialchars($csrf)?>"><label>Agenda *<select name="calendar_id" required><option value="">Choisir</option><?php foreach($calendars as $c):?><option value="<?=$c['id']?>"><?=htmlspecialchars($c['name'])?></option><?php endforeach;?></select></label><label>Titre *<input name="title" required></label><label>Ressource<select name="resource_id"><option value="">Aucune</option><?php foreach($resources as $r):?><option value="<?=$r['id']?>"><?=htmlspecialchars($r['name'].' · '.$r['type'])?></option><?php endforeach;?></select></label><div class="pl-two"><label>Début *<input type="datetime-local" name="start_at" required></label><label>Fin *<input type="datetime-local" name="end_at" required></label></div><label>Lieu<input name="location"></label><label>Description<textarea name="description"></textarea></label><button>Enregistrer</button></form></details>
<details class="pl-panel"><summary>Nouvel agenda</summary><form class="pl-form" method="post" action="/public/administration/axiom/planning/calendar/save"><input type="hidden" name="_csrf" value="<?=htmlspecialchars($csrf)?>"><label>Code *<input name="code" required></label><label>Nom *<input name="name" required></label><label>Couleur<input type="color" name="color" value="#365cf5"></label><label>Description<textarea name="description"></textarea></label><input type="hidden" name="timezone" value="Europe/Paris"><button>Créer</button></form></details>
<details class="pl-panel"><summary>Nouvelle ressource</summary><form class="pl-form" method="post" action="/public/administration/axiom/planning/resource/save"><input type="hidden" name="_csrf" value="<?=htmlspecialchars($csrf)?>"><label>Code *<input name="code" required></label><label>Nom *<input name="name" required></label><label>Type<select name="type"><option value="person">Personne</option><option value="room">Salle</option><option value="vehicle">Véhicule</option><option value="equipment">Matériel</option><option value="other">Autre</option></select></label><label>Capacité<input type="number" min="0" name="capacity"></label><label>Localisation<input name="location"></label><button>Créer</button></form></details>
<details class="pl-panel"><summary>Indisponibilité</summary><form class="pl-form" method="post" action="/public/administration/axiom/planning/absence/save"><input type="hidden" name="_csrf" value="<?=htmlspecialchars($csrf)?>"><label>Ressource *<select name="resource_id" required><?php foreach($resources as $r):?><option value="<?=$r['id']?>"><?=htmlspecialchars($r['name'])?></option><?php endforeach;?></select></label><label>Motif *<input name="label" required></label><div class="pl-two"><label>Début<input type="datetime-local" name="start_at" required></label><label>Fin<input type="datetime-local" name="end_at" required></label></div><label>Notes<textarea name="notes"></textarea></label><button>Enregistrer</button></form></details><?php endif;?></aside></section></main>
