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



			

			$usql = "SELECT * FROM `Blogs` ORDER BY `date` DESC LIMIT 20";

			

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

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

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

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

				$xml.="</item>";

			}	

			

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

			echo $xml;

	



	

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

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

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

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

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

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

			$usql = "INSERT INTO `Blogs` (`ID`, `title`, `subtitle`, `desc`,  `image`, `date`) VALUES ('', '$title', '$subtitle', '$desc', '$path', '$date')";

			

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

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

			if($result){

				

				$return = $blog_id;

				echo $return; 

			}else{

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

				echo $return; 

			 }

	

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

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

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

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

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

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

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

			$usql = "UPDATE `Blogs` set `title`= '$title', `subtitle`='$subtitle', `desc`='$desc',  `date`='$date', `path`=`$path` WHERE `ID` = '$id' ";

			

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

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

			if($result){

				

				$return = $blog_id;

				echo $return; 

			}else{

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

				echo $return; 

			 }

	

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



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

	

	$sql = "DELETE FROM `Blogs` 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; 

	 }

	 

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



			

			$usql = "SELECT * FROM `News` ORDER BY `date` DESC LIMIT 20";

			

			$result = mysqli_query($hookup, $usql);
			
			if($result){
				$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.="<date>".$row['date']."</date>";

					$xml.="</item>";

				}	

				

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

				echo $xml;

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

				echo $return; 
				
			}
	
	

			


	

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



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

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

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



			$usql = "INSERT INTO `News` (`ID`, `title`,  `desc`,  `date`) VALUES ('', '$title', '$desc', '$date')";

			

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

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

			if($result){

				

				$return = $blog_id;

				echo $return; 

			}else{

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

				echo $return; 

			 }

	

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

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

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

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

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

			$usql = "UPDATE `News` set `title`= '$title', `desc`='$desc',  `date`='$date' WHERE `ID` = '$id' ";

			

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

			if($result){

				

				$return = "Entry ID: "+$id;

				echo $return; 

			}else{

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

				echo $return; 

			 }

	

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



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

	

	$sql = "DELETE FROM `News` 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; 

	 }

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

	$device = intval($_POST['device']);;
	
	$sql = "SELECT * FROM `Puchase_Images` WHERE `device` = '$device';";

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

	if($result){	

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

		//$row = mysqli_fetch_assoc($result);

		while ($row = mysqli_fetch_assoc($result)) {
	
			$xml.="<ftitle>".$row['full_title']."</ftitle>";

			$xml.= "<ltitle>".$row['limited_title']."</ltitle>";
			
			$xml.="<utitle>".$row['upgrade_title']."</utitle>";

			$xml.= "<fimage>".$row['full_path']."</fimage>";
			
			$xml.= "<limage>".$row['limited_path']."</limage>";
			
			$xml.="<uimage>".$row['upgrade_path']."</uimage>";

		}

		

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

		echo $xml;
		
	}else{

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

		echo $return; 

	}
}




?>