<?php 
	require $_SERVER["DOCUMENT_ROOT"].'/inc/conexao.php';
	require $_SERVER["DOCUMENT_ROOT"].'/inc/functions.php';
	require $_SERVER["DOCUMENT_ROOT"].'/api/api.php';

	$urlbase = $_SERVER['SERVER_NAME'].$_SERVER ['REQUEST_URI'];
	$parts = parse_url($urlbase);
	parse_str($parts['query'], $query);
	$code = $_GET["registro"];
	$_GET = $query;

	if(!isset($_GET["confirmed"])){
		echo '<script> var r = confirm("Tem certeza que deseja cancelar o bilhete #'.$code.'?"); if (r == true) { location.href = "?confirmed=1"; } else {  } </script>'; exit;
	}

	// Parametros
	$params['code'] = $code;
	$params['token'] = $_SESSION["usuario"]["api_token"];
	$api = api('/cancellCoupon', $params);
	$api = json_decode($api, 1);

	if(isset($api["success"])){ echo '<script> alert("O bilhete foi cancelado com sucesso!"); parent.location.reload(); </script>'; } 
	else { echo '<script> alert("ERRO! '.$api["error"].'"); </script>'; }
?>