<?php



include ('dbConnect.php');



$ui= $_POST['ui'];



if($ui=="getref"){





	$usql = "SELECT * FROM `Profileref` ORDER BY `ID` ASC";

	

	$result = mysqli_query($hookup, $usql);

	$cnt=0;

	$xml="<xml><data>";

	//$row = mysqli_fetch_assoc($result);

	while($row = mysqli_fetch_assoc($result)) {

		$xml.="<item><id>".$row['ID']."</id>";

		$xml.="<ref><![CDATA[".$row['reference']."]]></ref>";

		$xml.="<title><![CDATA[".$row['title']."]]></title>";

		$xml.="<numset><![CDATA[".$row['numset']."]]></numset>";

		$xml.="</item>";

	}

	

	$xml.="</data></xml>";

	echo $xml;

	

}else if($ui=="getreadings"){



$id = intval($_POST['id']);

	

	

	$usql = "SELECT * FROM `Profiles` WHERE `ref_ID`= '$id' ORDER BY `ID` ASC";

	

	$result = mysqli_query($hookup, $usql);

	$cnt=0;

	$xml="<xml><data>";

	//$row = mysqli_fetch_assoc($result);

	while($row = mysqli_fetch_assoc($result)) {

		$xml.="<item><id>".$row['ID']."</id>";

		$xml.="<ref_id><![CDATA[".$row['ref_ID']."]]></ref_id>";

		$xml.="<desc><![CDATA[".$row['desc']."]]></desc>";

		$xml.="<key><![CDATA[".$row['num']."]]></key>";

		$xml.="</item>";

	}

	

	$xml.="</data></xml>";

	echo $xml;

	

	 

}else if($ui=="save"){



$ref_id = intval($_POST['ref_id']);

$key = mysqli_real_escape_string($hookup, $_POST['key']);

$desc = mysqli_real_escape_string($hookup, $_POST['desc']);

	

		$sql = "INSERT INTO `Profiles` (`ID`, `ref_id`, `num`, `desc`) VALUES ('', '$ref_id', '$key', '$desc')";

	$result=mysqli_query($hookup, $sql);

	$used_id = "<result>".mysqli_insert_id($hookup)."</result>";

	if($result){

		

		$return = $used_id;

		echo $return; 

	}else{

		$return = "error=" . $type. " / ". mysqli_error($hookup);

		echo $return; 

	 }

	 

}else if($ui=="update"){



$desc = mysqli_real_escape_string($hookup, $_POST['desc']);

$id = intval($_POST['id']);

	

	$sql = "UPDATE `Profiles` SET `desc` = '$desc' WHERE `ID` = '$id'";

	

	if(mysqli_query($hookup, $sql)){

		$return = "success";

		echo $return; 

	}else{

		$return = "error=" . $type. " / ". mysqli_error($hookup);

		echo $return; 

	 }

	 

}



?>