#!/usr/bin/perl

##############################################################################
#
# Print billing management system - admin tools, version 4.1.2
#
# Copyright (C) 2000, 2001, 2002, 2003 Daniel Franklin
#
# This program is distributed under the terms of the GNU General Public
# License Version 2.
#
# This utility allows users to check their own quota.
#
##############################################################################

use Printbill::PTDB_File;
use Printbill::printbill_pcfg;
use Getopt::Long;
use POSIX;
use Fcntl;
use strict;

my $config = '/etc/printbill/printbillrc';
my %params = pcfg ($config);
my ($opt_user, $user, %userhash);

GetOptions ('user=s' => \$opt_user);

if (defined ($opt_user)) {
	$user = $opt_user;
} else {
	$user = getpwuid ($<);
}

tie %userhash, "Printbill::PTDB_File", "$params{'db_home'}/users/$user.db", "TRUE"
	or die "Cannot open file $params{'db_home'}/users/$user.db: $!\n";

if (defined ($opt_user)) {
	printf ("%.2f\n", $userhash{"quota"});
} else {
	printf ("You (%s) currently have $params{'currency_symbol'}%.2f credit.\n", $user, $userhash{"quota"});
}

untie %userhash;

exit 0;
