<?php



include ('dbConnect.php');



$idate = explode("/", $_POST['date']);



$date= mysqli_real_escape_string($hookup, $idate[2]."-".$idate[0]."-".$idate[1]);



$ui= $_POST['ui'];



if($ui=="get"){



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

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

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



	$usql = "SELECT * FROM `Name_Analyzer_F` WHERE `core1` = '$core1' AND `core2` = '$core2' AND `core3` = '$core3'";

	

	$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.="<core1>".$row['core1']."</core1>";

		$xml.="<core2>".$row['core2']."</core2>";

		$xml.="<core3>".$row['core3']."</core3>";

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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





	$usql = "SELECT * FROM `Name_Analyzer_F` ORDER BY `core1` 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.="<core1>".$row['core1']."</core1>";

		$xml.="<core2>".$row['core2']."</core2>";

		$xml.="<core3>".$row['core3']."</core3>";

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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

		

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

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

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



	$usql = "SELECT * FROM `Name_Analyzer_F` WHERE `core1` = '$core1' AND `core2` = '$core2' AND `core3` = '$core3'";

	

	$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.="<desc><![CDATA[".$row['desc']."]]></desc>";

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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



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

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

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

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

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

//escape this if it ever gets used
$short = $_POST['short'];

	

	$sql = "UPDATE `Name_Analyzer_F` SET `desc` = '$desc' WHERE `core1` = '$core1' AND `core2` = '$core2' AND `core3` = '$core3'";

	

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

		$return = "success";

		echo $return; 

	}else{

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

		echo $return; 

	 }

	 

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



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

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

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

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

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

	

	$sql = "INSERT INTO `Name_Analyzer_F` (`ID`, `core1`, `core2`, `core3`,  `desc`, `language` ) VALUES ('', '$core1', '$core2', '$core3', '$desc', '0')";

	$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=="delete"){



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

	

	$sql = "DELETE FROM `Name_Analyzer_F` WHERE `ID` = '$id'";

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

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

	if($result){

		

		$return = "success";

		echo $return; 

	}else{

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

		echo $return; 

	 }

}



?>