<?php

include_once ("includes/setup.inc.php");
//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;
$id = fetch_postget_val("id", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

try
{
	$PASS_COUNTER = 0; //COUNTER FOR DOUBLE CONFIRM
	$PASS_VALUE = 1; //NUMBER OF QUERY TO EXECUTE. IMPORTANT FOR CHECKING!!

	//PDO INIT
	$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$PDO->beginTransaction();

	$indicator_Array = array();
	$indicator_Array[] = array('id_pemilik', fetch_postget_val("pemilik_pet", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('nama_pet', fetch_postget_val("nama_pet", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('id_haiwan_peliharaan', fetch_postget_val("id_haiwan_peliharaan", $_POST, $_GET), PDO::PARAM_STR);
	
	if($id == 0)
	{
		$PASS_COUNTER += PDO_INSERT($PDO, 'm_pemilik_pet', $indicator_Array);
	}
	else
	{
		$whereCondition = "WHERE id_pemilik_pet = $id";
		$PASS_COUNTER += PDO_UPDATE($PDO, 'm_pemilik_pet', $indicator_Array, $whereCondition);
	}

	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
	}
	else
	{
		$PDO->rollBack();
		echo -1;
	}
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}

?>