<?php

include ('dbConnect.php');

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

switch($ui){
	case "get_forecast":
	
	//Personal Day Value
	$num = intval($_POST["num"]);
	
	//Current Month
	$month = intval($_POST["month"]);
	
	//Current Day
	$day = intval($_POST["day"]);

	//////////////////////////////////
	$usql = "SELECT * FROM `DailyForecast` WHERE `month` = '$month' AND `day` = '$day' AND `num` = '$num' ";

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

		$cnt=0;

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

			//$row = mysqli_fetch_assoc($result);

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

				$xml.="<item>";

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

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

				$xml.="</item>";

			}

			

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

			echo $xml;
			
			break;
			
	case "analyze_male":
	
		$core1 = intval($_POST['core1']);
		$core2 = intval($_POST['core2']);
		$core3 = intval(_POST['core3']);

		$usql = "SELECT * FROM `Name_Analyzer_M` 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>";
			$xml.="<desc><![CDATA[".$row['desc']."]]></desc>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
		
	case "analyze_female":
	
		$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>";
			$xml.="<desc><![CDATA[".$row['desc']."]]></desc>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_singlechapter":
	
		$id = $_POST['id'];
		
		$usql = "SELECT * FROM `Chapters` WHERE `ID` = '$id'";
	
		$result = mysqli_query($hookup, $usql);
		
		$xml="<xml><data>";
		//$row = mysqli_fetch_assoc($result);
		while($row = mysqli_fetch_assoc($result)) {
			$xml.="<item>";
			$xml.="<title><![CDATA[".$row['title']."]]></title>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br/>",$row['desc'])."]]></desc>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_chapters":
	
		$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.="<title><![CDATA[".$row['title']."]]></title>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br/>",$row['desc'])."]]></desc>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_readings":
	
		$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.="</item>";
		
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_core":
		$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>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_challenges":
		$usql = "SELECT * FROM `Challenges`";

		$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.="<title>".$row['title']."</title>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
			$xml.="<num>".$row['num']."</num>";
			$xml.="<phase>".$row['phase']."</phase>";

			$xml.="</item>";

		}	

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

		echo $xml;
		break;
		
	case "get_codex":
		$usql = "SELECT * FROM `Traits` ORDER BY `group` ASC, `rank` ASC";
	
		$result = mysqli_query($hookup, $usql);
		$cnt=0;
		$xml="<xml><data>";
		//$row = mysqli_fetch_assoc($result);
		while($row = mysqli_fetch_assoc($result)) {
			$xml.="<item>";
			$xml.="<title><![CDATA[".$row['title']."]]></title>";
			$xml.="<codex><![CDATA[".$row['codex']."]]></codex>";
			$xml.="<group><![CDATA[".$row['group']."]]></group>";
			$xml.="<rank><![CDATA[".$row['rank']."]]></rank>";
			$xml.="</item>";
		}
		
		$xml.="</data></xml>";
		echo $xml;
		
		break;
		
	case "get_personalmonths":
		$year = intval($_POST['year']);	

		$usql = "SELECT * FROM `PersonalMonths` WHERE `year` = '$year'";

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

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

		//$row = mysqli_fetch_assoc($result);

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

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

		}		

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

		echo $xml;
		break;
		
	case "get_dualities":
		$year = intval($_POST['year']);
		$essence = intval($_POST['essence']);		

		$usql = "SELECT * FROM `Dualities` WHERE `year` = '$year' AND `essence` = '$essence'";

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

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

		//$row = mysqli_fetch_assoc($result);

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

			$xml.="<item>";
			$xml.="<title><![CDATA[".$row['title']."]]></title>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
			$xml.="</item>";

		}		

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

		echo $xml;
		break;
		
	case "get_compatibilities":
	
		$one = intval($_POST["one"]);

		$two = intval($_POST["two"]);			

		$usql = "SELECT * FROM `RelationshipCompatability` WHERE `num_one` = '$one' AND `num_two` = '$two' ";			

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

		$cnt=0;

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

		//$row = mysqli_fetch_assoc($result);

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

			$xml.="<item>";
			$xml.="<title>".$row['title']."</title>";
			$xml.="<desc><![CDATA[".str_replace("\n", "<br>",$row['desc'])."]]></desc>";
			$xml.="</item>";

		}				

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

		echo $xml;
		break;
}

?>