<?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(empty($_GET['uTp'])){
		header('Location: manage-ad.php');
	}
	$objID	=	$_GET['uTp'];

	$qury = new ParseQuery("ads");
	$result = $qury->get($objID);
	if(empty($result)){
		header('Location: manage-ad.php');
	}
	$objBeaconsForRemoval = new ParseQuery("ad_beacon");
	$objBeaconsForRemoval->equalTo('ad',$result);
	$objBeaconsResult = $objBeaconsForRemoval->find();
	if(!empty($objBeaconsResult)){
		foreach($objBeaconsResult as $oldBecn){
			$oldBecn->destroy();
		}
	}
	$result->destroy();
	header('Location: manage-ad.php');	
?>