#! /usr/bin/perl -T
use strict;
use warnings;
use utf8;

use lib '../include';
use itkaclcommon;

itkaclcommon::init();
itkaclcommon::check_csrf_token();

my $entry = $itkaclcommon::cgi->param('entry');

# Find the parent node before we delete this (FIXME: this will fail badly
# for root nodes!)
my $ref = $itkaclcommon::dbh->selectrow_hashref('SELECT parent FROM objects WHERE id=?',
	undef, $entry);

$itkaclcommon::dbh->do('DELETE FROM objects WHERE id=?', undef, $entry)
	or die "Couldn't delete object";

# Let sync-itkacl know there's updates
utime(time(), time(), '/etc/itkacl/updated');

# Redirect to the parent
print $itkaclcommon::cgi->redirect("view.pl?entry=$ref->{'parent'}");

