<?php  
// Konfigurasi database  
define('DB_HOST', 'localhost');          // Set database host  
define('DB_USER', 'wiselie_nanda');      // Set database user     
define('DB_PASS', 'Clemira123');         // Set database password    
define('DB_NAME', 'wiselie_inventory');  // Set database name  
  
// Membuat koneksi ke database  
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);  
  
// Memeriksa koneksi  
if ($conn->connect_error) {  
    die("Koneksi gagal: " . $conn->connect_error);  
}  
  
// Mengambil data JSON dari permintaan  
$data = json_decode(file_get_contents('php://input'), true);  
$taskId = intval($data['id']);  
$isCompleted = intval($data['completed']);  
  
// Memperbarui status tugas di database  
$stmt = $conn->prepare("UPDATE checklist SET is_completed = ? WHERE id = ?");  
$stmt->bind_param("ii", $isCompleted, $taskId);  
$response = ['success' => false];  
  
if ($stmt->execute()) {  
    $response['success'] = true;  
}  
  
$stmt->close();  
$conn->close();  
  
// Mengembalikan respons JSON  
header('Content-Type: application/json');  
echo json_encode($response);  
?>  
