<?php
header('Content-Type: application/json');
require_once('../libs/classes/DbPathsArray.php');
require_once('../libs/classes/App_DB.php');

$db = new App_DB(DBU::$dba_user);

$response = [
    'success' => false,
    'message' => ''
];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    $attSno = $data['attSno'] ?? '';

    if (empty($attSno)) {
        $response['message'] = 'حاضری کا نمبر فراہم کریں';
        echo json_encode($response);
        exit;
    }

    try {
        $sql = "DELETE FROM attendence WHERE sno = :sno";
        $db->dbQuery($sql, ['sno' => $attSno]);

        $response['success'] = true;
        $response['message'] = 'حاضری کامیابی کے ساتھ حذف کر دی گئی';
    } catch (Exception $e) {
        $response['message'] = 'ڈیٹابیس کی خرابی: ' . $e->getMessage();
    }
}

echo json_encode($response);
