#!/usr/bin/perl # # Asterisk(tm) Calling Card Platform # # Copyright (C) 2004, Digium, Inc. # # Mark Spencer ) { chomp; my ($var, $val) = split(/\s*\=\s*/); $config{$var} = $val; } close(CFG); } sub connect_db() { my $dsn = "DBI:mysql:database=$config{'dbname'};host=$config{'dbhost'}"; $dbh->disconnect if $dbh; $dbh = DBI->connect($dsn, $config{'dbuser'}, $config{'dbpass'}); } sub build_home() { return "
Welcome to the Asterisk™ Calling Card User Sheet. Please select " . "a function from the menu on the left.
" } sub getcard() { my ($cardno) = @_; my $res; $sth = $dbh->prepare("SELECT * FROM cards WHERE number=" . $dbh->quote($cardno)); $sth->execute; $res = $sth->fetchrow_hashref; $sth->finish; return $res; } sub build_cards() { my $total, $used; my $pennies, $count, $brand; return "Cannot edit cards until database is configured" unless $dbh; # my $brands = list_brands(); # return "Please define at least one brand before creating cards" unless $brands; $body = ""; $body .= ""; $body .= "
" . start_form . "
Get information on card  " . hidden(-name => "mode", -value => "Cards") . textfield(-name => "cardnum", -size => 15) . "    " . submit(-name => "action", -value => "Information...") . "
"; if ((param('action') eq "Information...") && length(param('cardnum'))) { my $cardinfo; my $status; $cardinfo = &getcard(param('cardnum')); if ($cardinfo->{'number'}) { $status = "Card  " . param('cardnum') . "   has used  " . "$cardinfo->{used}" . "  of  " . "$cardinfo->{facevalue}  units\n"; } else { $status = "No such card number '" . param('cardnum') . "' found!\n"; } $body .= ""; $body .= "" . $status . "\n"; if ($cardinfo->{'number'}) { $body .= "\n"; my $sth = $dbh->prepare("SELECT * FROM cdrs WHERE cardnum=" . $dbh->quote($cardinfo->{'number'})); my $res; my $count; my $callerid; $sth->execute; while(($res = $sth->fetchrow_hashref)) { $callerid = $res->{callerid}; $callerid = "<unknown>" unless $callerid; $count++; if (!($count % 2)) { $color = "#ccffcc"; } else { $color = "#ffffcc"; } $body .= "" . ""; } } $body .= "
Caller*IDCalled NumberTrunkDispositionBillable SecondsBilled Cost
$callerid$res->{callednum}$res->{trunk}$res->{disposition}$res->{billseconds}$res->{billcost}
"; } return $body; } sub build_body() { my ($mode) = @_; my $body; return &build_cards(); } my $body; $mode = "Cards"; &load_config; &connect_db; $msg = " "; $body = &build_body($mode); #$menu = &build_menu($mode); $msg = "Database unavailable -- please check configuration" unless $dbh; print "Asterisk™ Calling Card Info Sheet\n"; print "\n"; print " "; print " "; print "\n"; print "
Asterisk™ Calling Card Info Sheet" . "
$msg
$menu$body

$copyright
\n";