#!/usr/bin/perl

use CGI;
use DBI;
##use strict;
unshift(@INC, '.');
use ipac_cfg;

my $q = new CGI;
my $path="https://" . $q->server_name();            
my $cgi=$path . "/cgi-bin";
my $dbh;
my $sth;
my $tar_id;
my $user = $ENV{REMOTE_USER};

if ($ENV{HTTPS} ne "on" || $user ne "admin") {
    print $q->header(-type=>"text/html;", -status=>'403 Forbidden'),
	    $q->start_html('Forbidden'),
	    $q->h1('You dont have permission to access this script'),
	    $q->end_html;
    exit;
}

if ($q->param('tar')) {
	$tar_id = $q->param('tar');
} else {
	exit;
}

my $dbh = DBI->connect("dbi:Pg:dbname=$ipac_cfg::pg_dbname",       
                        $ipac_cfg::pg_login, $ipac_cfg::pg_pwd,    
	                             { RaiseError => 1, AutoCommit => 0 });

$dbh->do(q{delete from tariffs_names where tariff_id=?}, undef, $tar_id)
						    or die $dbh->errstr;
$dbh->commit();
$dbh->disconnect  or warn $dbh->errstr;
reconfig();
print $q->header(-Refresh=>"1; URL=$cgi/br_tar_name") ;
print $q->end_html;
