<?php
include 'includes/db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $id = $_POST['id'];
    $kra_name = $_POST['kra_name'];
    $measure_of_success = $_POST['measure_of_success'];
    $weightage = $_POST['weightage'];

$stmt = $conn->prepare("UPDATE PMS_Template SET kra_name = :kra_name, measure_of_success = :measure_of_success, weightage = :weightage WHERE id = :id");

    $stmt->bindParam(':kra_name', $kra_name);
$stmt->bindParam(':measure_of_success', $measure_of_success);
$stmt->bindParam(':weightage', $weightage, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);

    if ($stmt->execute()) {
        echo json_encode(['status' => 'success', 'message' => 'KRA Template updated successfully.']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Failed to update KRA Template.']);
    }
}
?>
