<?php

include ('dbConnect.php');

$ui= $_POST['ui'];

if($ui=="getchapters"){


	$usql = "SELECT * FROM `Chapters` 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.="<desc><![CDATA[".str_replace("\n", "<br/>",$row['desc'])."]]></desc>";
		$xml.="<image>".$row['image']."</image>";
		$xml.="<order>".$row['order']."</order>";
		$xml.="<boss>".$row['parent']."</boss>";
		$xml.="</item>";
	}
	
	$xml.="</data></xml>";
	echo $xml;
	
}else if($ui=="getsinglechapters"){

	$id = $_POST['id'];

	$usql = "SELECT * FROM `Chapters` WHERE `ID` = '$id'";
	
	$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.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
		$xml.="<image>".$row['image']."</image>";
		$xml.="<order>".$row['order']."</order>";
		$xml.="<boss>".$row['parent']."</boss>";
		$xml.="</item>";
	}
	
	$xml.="</data></xml>";
	echo $xml;
	 
}else if($ui=="getcore"){

	$core1 = $_POST['core1'];
	$core2 = $_POST['core2'];
	$core3 = $_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[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
		$xml.="</item>";
	}
	
	$xml.="</data></xml>";
	echo $xml;
	 
}else if($ui=="getprofile"){

	$ref = $_POST['ref'];
	$num = $_POST['num'];

	$usql = "SELECT * FROM `Profiles` WHERE `num` = '$num' AND `ref_ID` = '$ref'";
	
	$result = mysqli_query($hookup, $usql);
	$cnt=0;
	$xml="<xml><data>";
	//$row = mysqli_fetch_assoc($result);
	$row = mysqli_fetch_assoc($result);
	$xml.="<item><id>".$row['ID']."</id>";
	$xml.="<desc><![CDATA[".str_replace("\n", "<br/>",$row['desc'])."]]></desc>";
	$xml.="<num><![CDATA[".$row['num']."]]></num>";
	$xml.="</item>";
	
	
	$xml.="</data></xml>";
	echo $xml;
	 
}else if($ui=="getallprofile"){

	$ref = $_POST['ref'];
	$num = $_POST['num'];

	$usql = "SELECT * FROM `Profiles` WHERE `ref_ID` = '$ref'";
	
	$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[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
		$xml.="<num><![CDATA[".$row['num']."]]></num>";
		$xml.="</item>";
	}
	
	$xml.="</data></xml>";
	echo $xml;
	 
}else if($ui=="getduality"){

	$year = $_POST['year'];
	$essence = $_POST['essence'];

	$usql = "SELECT * FROM `Dualities` WHERE `year` = '$year' AND `essence` = '$essence'";
	
	$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.="<essence>".$row['essence']."</essence>";
		$xml.="<title><![CDATA[".$row['title']."]]></title>";
		$xml.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
		$xml.="</item>";
	}
	
	
	$xml.="</data></xml>";
	echo $xml;
	 
}

?>