<?php
Template::stop();


$data = file_get_contents("php://input");
$data = json_decode($data);

if (!empty($data))
{
	global $_database;

	// clear table data
	$query = ' 	TRUNCATE configuration
			';
	$_database->setQuery($query);


	// set table data - sensor configurations
	$query = '	INSERT INTO configuration (sensor_id, relay_1, relay_2, commode)
				VALUES 
			';
	$values = array();
	foreach ($data as $i => $sensor)
	{
		if ( (int) $sensor->sensor_id == 0)
		{
			continue;
		}

		$values[] = '("' . $sensor->sensor_id . '", "' . $sensor->relay_1 . '", "' . $sensor->relay_2 . '", "' . $sensor->commode . '")';
	}
	$values_str = implode(',', $values);
	$query 		.= $values_str;

	$_database->setQuery($query);
}


print_r($query);
print_r($data);