<?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"){

	$usql = "SELECT * FROM `Forecasts` WHERE `date` = '$date'";

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

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

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

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

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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

	

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



	$usql = "SELECT * FROM `Forecasts` WHERE `date` = '$date' AND `numbr` = '$num' ";

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

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

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

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

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

		$xml.="</item>";

	}

	

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

	echo $xml;

	

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



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

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

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

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

	

	$sql = "UPDATE `Forecasts` SET `numbr` = '$num', `title` = '$title', `desc` = '$desc', `icons` = '$icons' WHERE `date` = '$date' AND `numbr` = '$num'";

	

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

		$return = "success";

		echo $return; 

	}else{

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

		echo $return; 

	 }

	 

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

		

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

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

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

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

	

	$sql = "INSERT INTO `Forecasts` (`ID`, `date`, `title`, `desc`, `numbr`, `icons`, `language` ) VALUES ('', '$date', '$title', '$desc', '$num', '$icons', '0')";

	

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

		$return = "success";

		echo $return; 

	}else{

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

		echo $return; 

	 }

}



?>