<?php
	require_once '../../autoload.php';
	
	// RightsCheck ("VIEW_LOGINROLE");

	$afg_id		 	= -1;
		
	if ( isset ( $_REQUEST['afg_id'] ) 		)	$afg_id		 	= $_REQUEST['afg_id'];
	
	$conn = get_dbconnection();
	
	$response = -1;
	
	if ( $conn )
	{
		$sql = "";
		
		if ( $afg_id != -1 )
		{
			$sql = 'delete from alertfilter_group_link where afg_id = '.$afg_id.';';
  			$sql .= 'delete from alertfilter_group where afg_id = '.$afg_id.';';
  			$sql .= 'update account set alertfilter_group_id = null where alertfilter_group_id = '.$afg_id.';';
		}

		error_log ( "delete_plannedfilteralert : " .$sql );
		
		$result = pg_query ( $conn, $sql );
		
		if ( $result )
		{
			if ( $row = pg_fetch_row($result) )
			{
				$response = $afg_id;
			}
		}
	}
	
	header ('Content-type: text/xml' );
	
	echo $response;
?>