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

$num_errors = 0;

$id = fetch_postget_val("id", $_POST, $_GET);
$table = fetch_postget_val("table", $_POST, $_GET);
$field_name = str_replace('m_', 'id_', $table);

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();
	
	//*****************************************
	//DELETE FROM table
	//*****************************************
	$whereCondition = "WHERE $field_name = $id";
	$PASS_COUNTER += PDO_DELETE($PDO, $table, $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();
}


?>