<?php



include ('dbConnect.php');
require 'boot.php';



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



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



$ui=  $_POST['ui'] ? $_POST['ui'] : $_GET['ui'];


if($ui=="get"){



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

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

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



	$usql = "SELECT * FROM `CoreProfile` 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.="<short><![CDATA[".$row['short']."]]></short>";

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

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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



	$usql = "SELECT * FROM `CoreProfile` 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.="<short><![CDATA[".$row['short']."]]></short>";

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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

		

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

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

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



	$usql = "SELECT * FROM `CoreProfile` 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.="<short><![CDATA[".$row['short']."]]></short>";

		$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']);

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

	

	$sql = "UPDATE `CoreProfile` SET `short` = '$short', `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']);

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

	

	$sql = "INSERT INTO `CoreProfile` (`ID`, `core1`, `core2`, `core3`,  `desc`, `short`, `language` ) VALUES ('', '$core1', '$core2', '$core3', '$desc', '$short', '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 `CoreProfile` 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; 

	 }

}



?>