<?php
require_once __DIR__.'/../../config/functions.php';
requireLogin();
if(!isAdmin())jsonResponse(false,'Akses ditolak.');
if(!verifyCsrfToken($_GET['csrf']??''))jsonResponse(false,'CSRF Error');
$id=intval($_GET['id']??0);
if(!$id)jsonResponse(false,'ID tidak sah.');
$p=$pdo->prepare("SELECT gambar,nama FROM pegawai WHERE id=?");$p->execute([$id]);$p=$p->fetch();
if(!$p)jsonResponse(false,'Rekod tidak dijumpai.');
if($p['gambar']&&$p['gambar']!='default.png')deleteFile('pegawai/'.$p['gambar']);
$pdo->prepare("DELETE FROM pegawai WHERE id=?")->execute([$id]);
logActivity('Padam','pegawai',$id,'Padam pegawai: '.$p['nama']);
jsonResponse(true,'Pegawai berjaya dipadam.');
