<?php

include_once ("includes/setup.inc.php");
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_borangdiv', fetch_postget_val("id_borangdiv", $_POST, $_GET), PDO::PARAM_INT);
	//$indicator_Array[] = array('id_inputtype', fetch_postget_val("id_inputtype", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('label', fetch_postget_val("label", $_POST, $_GET), PDO::PARAM_STR, 1);
	$indicator_Array[] = array('label_show', fetch_postget_val("label_show", $_POST, $_GET), PDO::PARAM_STR, 1);
	$indicator_Array[] = array('help_text', fetch_postget_val("help_text", $_POST, $_GET), PDO::PARAM_STR, 1);
	//$indicator_Array[] = array('input_name', fetch_postget_val("input_name", $_POST, $_GET), PDO::PARAM_STR, 1);
	$indicator_Array[] = array('placeholder', fetch_postget_val("placeholder", $_POST, $_GET), PDO::PARAM_STR, 1);
	//$indicator_Array[] = array('value', fetch_postget_val("value", $_POST, $_GET), PDO::PARAM_STR, 1);
	$indicator_Array[] = array('div_size', fetch_postget_val("div_size", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('label_size', fetch_postget_val("label_size", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('input_size', fetch_postget_val("input_size", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('extra_param', fetch_postget_val("extra_param", $_POST, $_GET), PDO::PARAM_STR, 1);
	$indicator_Array[] = array('susunan', fetch_postget_val("susunan", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);

	if($id == 0)
	{
		$PASS_COUNTER += PDO_INSERT($PDO, 'u_borangitem', $indicator_Array);
	}
	else
	{
		$whereCondition = "WHERE id_borangitem = $id";
		$PASS_COUNTER += PDO_UPDATE($PDO, 'u_borangitem', $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();
}

?>