<?php
	require 'autoload.php';
	use Parse\ParseClient;
	use Parse\ParseObject;
	use Parse\ParseQuery;
	use Parse\ParseACL;
	use Parse\ParsePush;
	use Parse\ParseUser;
	use Parse\ParseInstallation;
	use Parse\ParseException;
	use Parse\ParseAnalytics;
	use Parse\ParseFile;
	use Parse\ParseCloud;
	
	include 'includes/func.php';
	include 'config.php';
	
	ParseClient::initialize($ApplicationID, $RestAPIKEY, $MasterKey);
	ParseClient::setServerURL($serverURLB4APP, '/');
	
	if(isset($_GET["uTp"])){
		$beaconID = $_GET["uTp"];
		$objBeacons = new ParseQuery("beacon");
		$beacon = $objBeacons->get($beaconID);
		$objBeaconsForRemoval = new ParseQuery("ad_beacon");
		$objBeaconsForRemoval->equalTo('beacon',$beacon);
		$objBeaconsResult = $objBeaconsForRemoval->find();
		if(!empty($objBeaconsResult)){
			foreach($objBeaconsResult as $oldBecn){
				$oldBecn->destroy();
			}
		}
		$beacon->destroy();		
	}
	header('Location: manage-beacons.php');
?>