<?php
declare(strict_types=1);ini_set('display_errors','0');header('Cache-Control: private,no-store,no-cache,must-revalidate,max-age=0');
require_once __DIR__.'/../includes/console_shell.php';require_login();$pageLink='reports/monthly-attendance-log.php';require_acl('can_view',$pageLink);require_once __DIR__.'/monthly-attendance-log-common.php';
$errors=[];try{$options=mal_options($con);$filters=mal_filters($con,$_GET,$options);}catch(Throwable $e){$options=['mode'=>0,'months'=>[],'years'=>[],'intervals'=>[],'employees'=>[]];$filters=['interval'=>0,'month'=>(int)date('n'),'year'=>0,'employee'=>0];$errors[]='Unable to load report filters.';}
$field='mt-2 w-full rounded-xl border border-slate-200 bg-white px-3 py-3 text-sm font-semibold text-slate-700 outline-none focus:border-brand-500 focus:ring-4 focus:ring-brand-100';$sel=static fn($a,$b)=>$a==$b?'selected':'';
console_header('Monthly Attendance Log Filters',$pageLink);?>
<div class="mb-6"><div class="mb-2 flex items-center gap-2 text-xs font-semibold text-slate-500"><span>Reports</span><i class="fa-solid fa-chevron-right text-[9px]"></i><span>Attendance Report</span><i class="fa-solid fa-chevron-right text-[9px]"></i><a href="/reports/monthly-attendance-log.php">Monthly Attendance Log</a><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Filters</span></div><h1 class="text-2xl font-bold text-slate-900">Monthly Attendance Log</h1><p class="mt-1 text-sm text-slate-500">Select the employee and attendance period.</p></div>
<?php foreach($errors as $e):?><div class="mb-5 rounded-xl border border-red-100 bg-red-50 px-5 py-4 text-sm font-semibold text-red-700"><?=h($e)?></div><?php endforeach;?>
<section class="overflow-hidden rounded-2xl border border-slate-100 bg-white shadow-sm"><div class="border-b border-slate-100 px-5 py-4"><h2 class="text-lg font-bold text-slate-800">Report Filters</h2><p class="mt-1 text-sm font-medium text-slate-400">Results open on a separate report page.</p></div><form method="post" action="/reports/monthly-attendance-log.php" class="grid gap-4 p-5 md:grid-cols-2 xl:grid-cols-4"><input type="hidden" name="_csrf" value="<?=h(csrf_token())?>">
<?php if($options['mode']===1):?><label class="text-sm font-bold text-slate-700">Salary Interval<select required name="filt_intervals" class="<?=$field?>"><option value="">Select Salary Interval</option><?php foreach($options['intervals'] as $r):?><option value="<?=(int)$r['id']?>" <?=$sel($filters['interval'],(int)$r['id'])?>><?=h(date('d-m-Y',strtotime($r['fromdate'])).' - '.date('d-m-Y',strtotime($r['todate'])))?></option><?php endforeach;?></select></label><?php else:?>
<label class="text-sm font-bold text-slate-700">Month<select required name="filt_month" class="<?=$field?>"><option value="">Select Month</option><?php foreach($options['months'] as $r):?><option value="<?=(int)$r['id']?>" <?=$sel($filters['month'],(int)$r['id'])?>><?=h($r['name'])?></option><?php endforeach;?></select></label>
<label class="text-sm font-bold text-slate-700">Year<select required name="filt_year" class="<?=$field?>"><option value="">Select Year</option><?php foreach($options['years'] as $r):?><option value="<?=(int)$r['id']?>" <?=$sel($filters['year'],(int)$r['id'])?>><?=h($r['name'])?></option><?php endforeach;?></select></label><?php endif;?>
<label class="text-sm font-bold text-slate-700">Employee Name<select required name="filter_name1" class="<?=$field?>"><option value="">Select Employee</option><?php foreach($options['employees'] as $r):?><option value="<?=(int)$r['id']?>" <?=$sel($filters['employee'],(int)$r['id'])?>><?=h($r['name'])?></option><?php endforeach;?></select></label>
<div class="flex flex-wrap items-end gap-2 xl:col-span-4"><button class="rounded-xl bg-brand-600 px-6 py-3 text-sm font-bold text-white"><i class="fa-solid fa-magnifying-glass mr-2"></i>Go</button><a href="/reports/monthly-attendance-log.php" class="rounded-xl border border-slate-200 px-6 py-3 text-sm font-bold text-slate-600">Cancel</a></div></form></section>
<?php console_footer();?>
