'success', 'message' => 'Rectangle updated']); } else { throw new Exception('Missing data for update'); } } else if (isset($inputData['action_type']) && $inputData['action_type'] == 'save') { if (isset($inputData['data'])) { PACommonHereCom_UpdateGeoFences($inputData['data']); echo json_encode(['status' => 'success', 'message' => 'Rectangle Save']); } else { throw new Exception('Missing data for update'); } } else if (isset($inputData['action_type']) && $inputData['action_type'] == 'delete') { if (isset($inputData['data'])) { PACommonHereCom_DeleteGeoFence($inputData['data']['DeviceID'], $inputData['data']['GeofenceID']); echo json_encode(['status' => 'success', 'message' => 'Rectangle Delete']); } else { throw new Exception('Missing data for update'); } } else { if (empty($inputData['deviceId'])) { throw new Exception('Device ID is required'); } $GeoFences = json_decode(PACommonHereCom_GetGeoFences(4, $inputData['deviceId'], true)); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('JSON decoding error: ' . json_last_error_msg()); } echo json_encode($GeoFences); } } catch (Throwable $e) { echo json_encode(['error' => $e->getMessage()]); } ?>