#!/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 $cust_id = "0";
my $tariff_id = "0";
my $dbh;
my $sth;
my $refer=$q->referer();
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('cust') ne "") && ($q->param('tar') ne "")) {
	$cust_id = $q->param('cust');
	$tariff_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 where cust_id=? and tariff_id=?}, undef, 
				$cust_id, $tariff_id) or die $dbh->errstr;
$dbh->commit();
$dbh->disconnect  or warn $dbh->errstr;
reconfig();
print "Location: $refer\n";
print $q->header;
