[Astpp-commit] SF.net SVN: astpp:[2221] trunk
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2009-01-17 17:21:26
|
Revision: 2221
http://astpp.svn.sourceforge.net/astpp/?rev=2221&view=rev
Author: darrenkw
Date: 2009-01-17 17:21:21 +0000 (Sat, 17 Jan 2009)
Log Message:
-----------
A whole bunch more cleanup of the svn tree. Try to put everything in a logical location.
Modified Paths:
--------------
trunk/Makefile
Added Paths:
-----------
trunk/images/astpp.png
trunk/scripts/
trunk/scripts/astpp-callingcards-daily.pl
trunk/scripts/astpp-common.pl
trunk/scripts/astpp-device-monitor.pl
trunk/scripts/astpp-email-incoming.pl
trunk/scripts/astpp-generate-invoices.pl
trunk/scripts/astpp-low-balance.pl
trunk/scripts/astpp-rate-engine.pl
trunk/scripts/astpp-update-balance.pl
trunk/web_interface/
trunk/web_interface/astpp-admin.cgi
trunk/web_interface/astpp-auto-admin.cgi
trunk/web_interface/astpp-callback.cgi
trunk/web_interface/astpp-pricelist.cgi
trunk/web_interface/astpp-refill.cgi
trunk/web_interface/astpp-users.cgi
trunk/web_interface/menu.js
trunk/web_interface/style.css
Removed Paths:
-------------
trunk/astpp-admin.cgi
trunk/astpp-auto-admin.cgi
trunk/astpp-callback.cgi
trunk/astpp-callingcards-daily.pl
trunk/astpp-common.pl
trunk/astpp-device-monitor.pl
trunk/astpp-email-incoming.pl
trunk/astpp-generate-invoices.pl
trunk/astpp-low-balance.pl
trunk/astpp-pricelist.cgi
trunk/astpp-rate-engine.pl
trunk/astpp-refill.cgi
trunk/astpp-update-balance.pl
trunk/astpp-users.cgi
trunk/astpp.jpg
trunk/astpp.png
trunk/menu.js
trunk/style.css
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2009-01-17 17:13:20 UTC (rev 2220)
+++ trunk/Makefile 2009-01-17 17:21:21 UTC (rev 2221)
@@ -36,14 +36,14 @@
# Install Freeswitch .pl files as .cgi files
install -m 755 -o $(OWNER) -g $(GROUP) freeswitch/astpp-fs-xml.pl $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-fs-xml.cgi
#
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-callback.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-callback.cgi
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-pricelist.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-pricelist.cgi
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-refill.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-refill.cgi
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-admin.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-admin/astpp-admin.cgi
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-auto-admin.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-admin/astpp-auto-admin.cgi
- install -m 755 -o $(OWNER) -g $(GROUP) astpp-users.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp/astpp-users.cgi
- install -m 644 -o $(OWNER) -g $(GROUP) style.css $(DESTDIR)$(WWWDIR)/html/_astpp/
- install -m 644 -o $(OWNER) -g $(GROUP) menu.js $(DESTDIR)$(WWWDIR)/html/_astpp/
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-callback.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-callback.cgi
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-pricelist.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-pricelist.cgi
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-refill.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-refill.cgi
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-admin.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-admin/astpp-admin.cgi
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-auto-admin.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp-admin/astpp-auto-admin.cgi
+ install -m 755 -o $(OWNER) -g $(GROUP) web_interface/astpp-users.cgi $(DESTDIR)$(WWWDIR)/cgi-bin/astpp/astpp-users.cgi
+ install -m 644 -o $(OWNER) -g $(GROUP) web_interface/style.css $(DESTDIR)$(WWWDIR)/html/_astpp/
+ install -m 644 -o $(OWNER) -g $(GROUP) web_interface/menu.js $(DESTDIR)$(WWWDIR)/html/_astpp/
# Install Sample Configuration Files
# install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.reseller-config.conf $(DESTDIR)$(ASTPPDIR)/sample.reseller-config.conf
install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-config.conf $(DESTDIR)$(ASTPPDIR)/sample.astpp-config.conf
@@ -69,7 +69,7 @@
done
install_astpp_exec:
- for x in ./*.pl; do \
+ for x in scripts/*.pl; do \
echo $$x; \
install -m 755 -o $(OWNER) -g $(GROUP) $$x $(PREFIX)$(ASTPPEXECDIR); \
done
@@ -92,6 +92,10 @@
install -m 644 $$x $(DESTDIR)$(WWWDIR)/html/_astpp/; \
done
install -m 644 images/favicon.ico $(DESTDIR)$(WWWDIR)/html/_astpp/;
+ for x in images/*.png; do \
+ echo $$x;\
+ install -m 644 $$x $(DESTDIR)$(WWWDIR)/html/_astpp/; \
+ done
resolve_perl_dep:
perl -MCPAN -e "install Text::Template";
Deleted: trunk/astpp-admin.cgi
===================================================================
--- trunk/astpp-admin.cgi 2009-01-17 17:13:20 UTC (rev 2220)
+++ trunk/astpp-admin.cgi 2009-01-17 17:21:21 UTC (rev 2221)
@@ -1,11806 +0,0 @@
-#!/usr/bin/perl
-#
-# ASTPP - Open Source Voip Billing
-#
-# Copyright (C) 2006, Aleph Communications
-#
-# Darren Wiebe (da...@al...)
-# Sergey Tamkovich was hired by Aleph Communications to add
-# the import ability and some of the "statistics" features.
-#
-# This program is Free Software and is distributed under the
-# terms of the GNU General Public License version 2.
-############################################################
-# Account Status Info
-# 0 = Account InActive
-# 1 = Account Active
-# 2 = Account Deactivated
-#
-# CDR Status Info
-# 0 - New line
-# 1 - Billed Line
-# 2 - Deactivated Line
-#
-#
-# Account Type
-# 0 - Regular User (Has login permissions for astpp-users.cgi)
-# 1 - Reseller (Has login permissions for astpp-users.cgi and has reduced permissions for astpp-admin.cgi)
-# 2 - Admin (Has login permissions everywhere)
-# 3 - Vendor (Has reduced login permissions in astpp-admin.cgi)
-# 4 - Customer Service (Has reduced login permissions in astpp-admin.cgi)
-# 5 - Call shop (Has reduced login permissions in astpp-admin.cgi)
-# 6 - Booth (No login permissions)
-###############################################################################
-use POSIX;
-use POSIX qw(strftime);
-use DBI;
-use CGI;
-use CGI qw/:standard Vars/;
-use Getopt::Long;
-use Locale::Country;
-use Locale::Language;
-use Locale::gettext_pp qw(:locale_h);
-use Data::Dumper;
-use lib './lib', '../lib';
-use warnings;
-use Asterisk::Manager;
-use Text::CSV;
-use HTML::Template;
-use HTML::Template::Expr;
-use Time::HiRes qw( gettimeofday tv_interval );
-use Data::Paginate;
-use DateTime;
-use DateTime::TimeZone;
-use ASTPP;
-
-; # We use DateTime::TimeZone to show users cdrs in their own timezones.
-
-require "/usr/local/astpp/astpp-common.pl";
-$ENV{LANGUAGE} = "en"; # de, es, br - whatever
-print STDERR "Interface language is set to: " . $ENV{LANGUAGE} . "\n";
-bindtextdomain( "astpp", "/usr/local/share/locale" );
-textdomain("astpp");
-use vars qw(@output $astpp_db $params $config
- $status $config $limit $accountinfo
- $freepbx_db $rt_db $openser_db $ASTPP);
-my $starttime = [gettimeofday];
-$ASTPP = ASTPP->new;
-$ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be.
-$ASTPP->set_asterisk_agi($AGI);
-$ASTPP->set_pagination_script("astpp-admin.cgi");
-my @Home = ( gettext("Home Page") );
-my @Accounts = (
- gettext("Create Account"), gettext("Process Payment"),
- gettext("Remove Account"), gettext("Edit Account"),
- gettext("List Accounts"), gettext("View Details")
-);
-my @Rates = (
- gettext("Pricelists"), gettext("Calc Charge"),
- gettext("Routes"), gettext("Import Routes"),
- gettext("Periodic Charges"), gettext("Packages"),
- gettext("Counters")
-);
-my @DIDs = ( gettext("Manage DIDs"), gettext("Import DIDs") );
-my @LCR = (
- gettext("Providers"), gettext("Trunks"),
- gettext("Outbound Routes"),
- gettext("Import Outbound Routes")
-);
-my @System = ( gettext("Purge Deactivated"), gettext("Configuration") );
-my @Statistics = (
- gettext("Asterisk Stats"), gettext("List Errors"),
- gettext("Trunk stats"), gettext("View CDRs"),
- gettext("LCR Tables")
-);
-
-my @Callingcards = (
- gettext("List Cards"), gettext("Add Cards"),
- gettext("Delete Card"), gettext("Refill Card"),
- gettext("View Card"), gettext("Update Card(s) Status"),
- gettext("Reset InUse"), gettext("CC Brands")
-);
-my @SwitchConfig = ();
-my @CallShops = ( gettext("Create CallShop"), gettext("Remove CallShop") );
-my @Booths = (
- gettext("Create Booth"), gettext("Remove Booth"),
- gettext("List Booths"), gettext("View Booth")
-);
-
-# Report added by Sonia Ali Khan <son...@gm...>
-my @AdminReports = ( gettext("Reseller Report"), gettext("Vendor Report") );
-
-my @CallShopReports = ( gettext("Booth Report") );
-
-my @ResellerReports = (
-
- # gettext("Brand Report"),
- gettext("CallShop Report"),
- gettext("Reseller Report"),
- gettext("User Report")
-);
-
-my %menumap = (
- gettext('Accounts') => \@Accounts,
- gettext('Rates') => \@Rates,
- gettext('DIDs') => \@DIDs,
- gettext('Statistics') => \@Statistics,
- gettext('System') => \@System,
- gettext('LCR') => \@LCR,
- gettext('Calling Cards') => \@Callingcards,
- gettext('Switch Config') => \@SwitchConfig,
- gettext('Booths') => \@Booths,
- gettext('Call Shops') => \@CallShops,
- gettext('Admin Reports') => \@AdminReports,
- gettext('CallShop Reports') => \@CallShopReports,
- gettext('Reseller Reports') => \@ResellerReports
-);
-my @months = (
- 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
-);
-my @techs = ( "SIP", "IAX2", "Zap", "Local", "OH323", "OOH323C" );
-my @incs = ( "1", "6", "30", "60" );
-my @devicetypes = ( gettext("friend"), gettext("user"), gettext("peer") );
-my %yesno = (
- '0' => gettext("NO"),
- '1' => gettext("YES")
-);
-my @cardstatus = ( gettext("ACTIVE"), gettext("INACTIVE"), gettext("DELETED") );
-my %sweeplist = (
- '0' => gettext("daily"),
- '1' => gettext("weekly"),
- '2' => gettext("monthly"),
- '3' => gettext("quarterly"),
- '4' => gettext("semi-annually"),
- '5' => gettext("annually")
-);
-my @output = ("STDERR"); # "LOGFILE" );
-my @language = all_language_codes;
-@language = sort @language;
-my @currency;
-my @deviceprotocol = ("SIP");
-my @countries = all_country_names();
-@countries = sort @countries;
-my @timezones = DateTime::TimeZone->all_names;
-@timezones = sort(@timezones);
-my (
- $rt_db, $astpp_db, $config, $params, $param,
- $cdr_db, $agile_db, $body, $menu, $status,
- $msg, $loginstat, @modes, $openser_db
-);
-
-$params->{mode} = "";
-$params->{username} = "";
-$params->{password} = "";
-$loginstat = 0;
-
-sub login() {
- my ( $sql, $count, $record, $cookie, $cookie1, $accountinfo );
- $sql =
- $astpp_db->prepare( "SELECT COUNT(*) FROM accounts WHERE number = "
- . $astpp_db->quote( $params->{username} )
- . " AND password = "
- . $astpp_db->quote( $params->{password} )
- . " AND status = 1 AND type IN (1,2,3,4,5)" );
- $sql->execute;
- $record = $sql->fetchrow_hashref;
- $count = $record->{"COUNT(*)"};
- $sql->finish;
- $cookie = cookie(
- -name => 'ASTPP_User',
- -value => $params->{username},
- -expires => '+8h',
- -domain => $ENV->{SERVER_NAME},
- -path => $ENV->{SCRIPT_NAME}
- );
- $cookie1 = cookie(
- -name => 'ASTPP_Password',
- -value => $params->{password},
- -expires => '+8h',
- -domain => $ENV->{SERVER_NAME},
- -path => $ENV->{SCRIPT_NAME}
- );
-
- if ( $count == 1 ) {
- $status .= gettext("Successful Login!") . "<br>";
- print header( -cookie => [ $cookie, $cookie1, ] );
- $accountinfo = &get_account( $astpp_db, $params->{username} );
- $params->{logintype} = $accountinfo->{type};
- }
- if ( !$params->{username} && $config->{auth} eq $params->{password} ) {
- $status .= gettext("Successful Login!") . "<br>";
- $count = 1;
- print header( -cookie => [ $cookie, $cookie1 ] );
- $params->{logintype} = 2;
- }
- if ( $count == 0 && $params->{password} eq "" ) {
- $params->{mode} = "";
- $status .= gettext("Please Login") . "<br>";
- print header();
- }
- elsif ( $count == 0 ) {
- $params->{mode} = "";
- $status .= gettext("Login Failed") . "<br>";
- print header();
- }
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-USER:") . " $params->{username}"
- );
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-PASS:") . " $params->{password}"
- );
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-AUTHCODE:") . " $config->{auth}"
- );
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-USER-COUNT:") . " $count"
- );
- return ( $params->{mode}, $count );
-}
-
-sub verify_login() {
- my ( $sql, $count, $record, $username, $password );
- $params->{username} = cookie('ASTPP_User');
- $params->{password} = cookie('ASTPP_Password');
- if ( !$params->{username} ) {
- $params->{username} = "";
- }
- if ( !$params->{password} ) {
- $params->{password} = "";
- }
- if ( $params->{username} && $params->{password} ) {
- $sql =
- $astpp_db->prepare( "SELECT COUNT(*) FROM accounts WHERE number = "
- . $astpp_db->quote( $params->{username} )
- . " AND password = "
- . $astpp_db->quote( $params->{password} )
- . " AND status = 1 AND type IN (1,2,3,4,5)" );
- $sql->execute;
- $record = $sql->fetchrow_hashref;
- $count = $record->{"COUNT(*)"};
- $sql->finish;
- $count = 0 if !$count;
- if ( $count == 1 ) {
- $accountinfo = &get_account( $astpp_db, $params->{username} );
- $params->{logintype} = $accountinfo->{type};
- }
- }
- if ( !$params->{username} && $config->{auth} eq $params->{password} ) {
- $count = 1;
- $params->{logintype} = 2;
- }
- if ( $count != 1 && !$params->{password} ) {
- $params->{mode} = "";
- $status .= "" . "<br>";
- $count = 0;
- }
- elsif ( $count != 1 ) {
- $params->{mode} = "";
- $status .= gettext("Login Failed") . "<br>";
- $count = 0;
- }
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-USER:") . " $params->{username}"
- ) if $config->{debug} == 1 && $params->{username};
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-PASS:") . " $params->{password}"
- ) if $config->{debug} == 1 && $params->{password};
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-AUTHCODE:") . " $config->{auth}"
- ) if $config->{debug} == 1;
- $ASTPP->debug(
- user => $param->{username},
- debug => gettext("ASTPP-USER-COUNT:") . " $count"
- ) if $config->{debug} == 1;
- print header();
- return $count;
-}
-
-sub logout() {
- my ( $cookie, $cookie1 );
- $cookie = cookie(
- -name => 'ASTPP_User',
- -value => 'loggedout',
- -expires => 'now'
- );
- $cookie1 = cookie(
- -name => 'ASTPP_Password',
- -value => 'loggedout',
- -expires => 'now'
- );
- print header( -cookie => [ $cookie, $cookie1 ] );
- $status .= "Successfully Logged User Out" . "<br>";
- return "";
-}
-
-sub build_menu_ts() {
- my ($selected) = @_;
- my ( $tmp, $body, $x );
- my $i = 0;
- foreach $tmp (@modes) {
- $body .=
-"<div class=\"ts_ddm\" name=tt$i id=tt$i style=\"visibility:hidden;width:200;background-color:#CCCCFF;\"onMouseover=\"clearhidemenu()\" onMouseout=\"dynamichide(event)\"><table width=100\% border=0 cellspacing=0 cellpadding=0>";
- my $j = 0;
- foreach $x ( @{ $menumap{$tmp} } ) {
- $body .=
-"<tr><td name=t$i\_$j id=t$i\_$j><a href=\"?mode=$x\" onmouseover='light_on(t$i\_$j);' onmouseout='light_off(t$i\_$j);'> $x </a></td></tr>
-\n";
- $j++;
- }
- $body .= "</table>
-</div>";
- $i++;
- }
- $body .= "<table width=900 cellpadding=0 class=ts_menu><tr>\n";
- $i = 0;
- foreach $tmp (@modes) {
- $body .=
-"<td name=t$i id=t$i><a href=\"?mode=$tmp\" onmouseover='light_on(t$i);dropdownmenu(this, event,\"tt$i\");' onmouseout='light_off(t$i);delayhidemenu();'> $tmp </a></td>\n";
- $i++;
- }
- $body .= "</tr></table>";
- return $body;
-}
-
-sub build_body() {
- if ( $params->{logintype} == 2 ) { #Admin Login
- return &build_providers() if $params->{mode} eq gettext("Providers");
- return &build_trunks() if $params->{mode} eq gettext("Trunks");
- return &build_outbound_routes()
- if $params->{mode} eq gettext("Outbound Routes");
- return &build_pricelists() if $params->{mode} eq gettext("Pricelists");
- return &build_routes() if $params->{mode} eq gettext("Routes");
- return &build_calc_charge()
- if $params->{mode} eq gettext("Calc Charge");
- return &build_list_errors()
- if $params->{mode} eq gettext("List Errors");
- return &build_lcr_tables()
- if $params->{mode} eq gettext("LCR Tables");
- return &build_dids() if $params->{mode} eq gettext("Manage DIDs");
- return &build_import_dids()
- if $params->{mode} eq gettext("Import DIDs");
- return &build_purge_deactivated()
- if $params->{mode} eq gettext("Purge Deactivated");
- return &build_create_account()
- if $params->{mode} eq gettext("Create Account");
- return &build_remove_account()
- if $params->{mode} eq gettext("Remove Account");
- return &build_process_payment()
- if $params->{mode} eq gettext("Process Payment");
- return &build_account_info()
- if $params->{mode} eq gettext("View Details");
- return &build_list_accounts()
- if $params->{mode} eq gettext("Accounts");
- return &build_list_accounts()
- if $params->{mode} eq gettext("List Accounts");
- return &build_edit_account()
- if $params->{mode} eq gettext("Edit Account");
- return &build_import_routes()
- if $params->{mode} eq gettext("Import Routes");
- return &build_import_outbound_routes()
- if $params->{mode} eq gettext("Import Outbound Routes");
- return &logout()
- if $params->{mode} eq gettext("Logout");
- return &build_packages()
- if $params->{mode} eq gettext("Packages");
- return &build_counters()
- if $params->{mode} eq gettext("Counters");
- return &build_statistics()
- if $params->{mode} eq gettext("Asterisk Stats");
- return &build_create_card()
- if $params->{mode} eq gettext("Add Cards");
- return &build_list_cards()
- if $params->{mode} eq gettext("List Cards");
- return &build_list_cards()
- if $params->{mode} eq gettext("Calling Cards");
- return &build_update_card_status()
- if $params->{mode} eq gettext("Update Card(s) Status");
- return &build_reset_card_inuse()
- if $params->{mode} eq gettext("Reset InUse");
- return &build_view_card() if $params->{mode} eq gettext("View Card");
- return &build_cc_brands()
- if $params->{mode} eq gettext("CC Brands");
- return &build_delete_cards()
- if $params->{mode} eq gettext("Delete Card");
- return &build_refill_card()
- if $params->{mode} eq gettext("Refill Card");
- return &build_sip_devices()
- if $params->{mode} eq gettext("Asterisk(TM) SIP Devices");
- return &build_iax_devices()
- if $params->{mode} eq gettext("Asterisk(TM) IAX Devices");
- return &build_dialplan()
- if $params->{mode} eq gettext("Asterisk(TM) Dialplan");
- return &build_freeswitch_sip_devices()
- if $params->{mode} eq gettext("Freeswitch(TM) SIP Devices");
- return &build_stats_acd()
- if $params->{mode} eq gettext("Trunk stats");
- return &build_stats_acd()
- if $params->{mode} eq gettext("Statistics");
- return &build_periodic_charges()
- if $params->{mode} eq gettext("Periodic Charges");
- return &build_view_cdrs() if $params->{mode} eq gettext("View CDRs");
- return &build_configuration()
- if $params->{mode} eq gettext("Configuration");
-
- return &build_add_callshop()
- if $params->{mode} eq gettext("Create CallShop");
- return &build_remove_callshop()
- if $params->{mode} eq gettext("Remove CallShop");
-
- return &build_admin_reseller_report()
- if $params->{mode} eq gettext("Reseller Report");
- return &build_admin_vendor_report()
- if $params->{mode} eq gettext("Vendor Report");
-
- return &build_homepage()
- if $params->{mode} eq gettext("Home Page")
- || $params->{mode} eq gettext("Home")
- || $params->{mode} eq ""
- || $params->{mode} eq gettext("Login")
- || $params->{mode} eq gettext("Logout");
- return gettext("Not Available!") . "\n";
- }
- elsif ( $params->{logintype} == 3 ) { #Vendor Login
- return &build_stats_acd()
- if $params->{mode} eq gettext("Trunk Statistics");
- return &logout() if $params->{mode} eq gettext("Logout");
- return &build_view_cdrs() if $params->{mode} eq gettext("View CDRs");
- return &build_outbound_routes()
- if $params->{mode} eq gettext("Outbound Routes");
- $params->{mode} = gettext("Home");
- return gettext("Welcome to ASTPP!") . "\n"
- if $params->{mode} eq gettext("Home");
- }
- elsif ( $params->{logintype} == 4 ) { #Customer Service Login
- return &build_create_account()
- if $params->{mode} eq gettext("Create Account");
- return &build_remove_account()
- if $params->{mode} eq gettext("Remove Account");
- return &build_process_payment()
- if $params->{mode} eq gettext("Process Payment");
- return &build_account_info()
- if $params->{mode} eq gettext("View Details");
- return &build_list_accounts()
- if $params->{mode} eq gettext("List Accounts");
- return &build_edit_account()
- if $params->{mode} eq gettext("Edit Account");
- return &build_calc_charge()
- if $params->{mode} eq gettext("Calc Charge");
- return &build_dids()
- if $params->{mode} eq gettext("Manage DIDs");
- return &build_dids()
- if $params->{mode} eq gettext("DIDs");
- return &build_sip_devices()
- if $params->{mode} eq gettext("Asterisk(TM) SIP Devices");
- return &build_iax_devices()
- if $params->{mode} eq gettext("Asterisk(TM) IAX Devices");
- return &build_packages() if $params->{mode} eq gettext("Packages");
- return &build_counters() if $params->{mode} eq gettext("Counters");
- return &build_statistics()
- if $params->{mode} eq gettext("Asterisk Stats");
- return &build_create_card() if $params->{mode} eq gettext("Add Cards");
- return &build_list_cards() if $params->{mode} eq gettext("List Cards");
- return &build_update_card_status()
- if $params->{mode} eq gettext("Update Card(s) Status");
- return &build_reset_card_inuse()
- if $params->{mode} eq gettext("Reset InUse");
- return &build_view_card() if $params->{mode} eq gettext("View Card");
- return &build_cc_brands()
- if $params->{mode} eq gettext("CC Brands");
- return &build_delete_cards()
- if $params->{mode} eq gettext("Delete Card");
- return &build_refill_card()
- if $params->{mode} eq gettext("Refill Card");
-
- }
- elsif ( $params->{logintype} == 1 ) { #Reseller Login
- return &build_create_card() if $params->{mode} eq gettext("Add Cards");
- return &build_list_cards() if $params->{mode} eq gettext("List Cards");
- return &build_update_card_status()
- if $params->{mode} eq gettext("Update Card(s) Status");
- return &build_reset_card_inuse()
- if $params->{mode} eq gettext("Reset InUse");
- return &build_view_card() if $params->{mode} eq gettext("View Card");
- return &build_cc_brands()
- if $params->{mode} eq gettext("CC Brands");
- return &build_delete_cards()
- if $params->{mode} eq gettext("Delete Card");
- return &build_refill_card()
- if $params->{mode} eq gettext("Refill Card");
- return &build_pricelists() if $params->{mode} eq gettext("Pricelists");
- return &build_routes() if $params->{mode} eq gettext("Routes");
- return &build_create_account()
- if $params->{mode} eq gettext("Create Account");
- return &build_remove_account()
- if $params->{mode} eq gettext("Remove Account");
- return &build_process_payment()
- if $params->{mode} eq gettext("Process Payment");
- return &build_account_info()
- if $params->{mode} eq gettext("View Details");
- return &build_list_accounts()
- if $params->{mode} eq gettext("List Accounts");
- return &build_edit_account()
- if $params->{mode} eq gettext("Edit Account");
- return &build_calc_charge()
- if $params->{mode} eq gettext("Calc Charge");
- return &build_import_routes()
- if $params->{mode} eq gettext("Import Routes");
- return &build_dids_reseller()
- if $params->{mode} eq gettext("Manage DIDs");
- return &build_add_callshop()
- if $params->{mode} eq gettext("Create CallShop");
- return &build_remove_callshop()
- if $params->{mode} eq gettext("Remove CallShop");
-
- # return &build_reseller_brand_report()
- # if $params->{mode} eq gettext("Brand Report");
- return &build_reseller_callshop_report()
- if $params->{mode} eq gettext("CallShop Report");
- return &build_reseller_reseller_report()
- if $params->{mode} eq gettext("Reseller Report");
- return &build_reseller_user_report()
- if $params->{mode} eq gettext("User Report");
- return &build_packages()
- if $params->{mode} eq gettext("Packages");
- return &build_counters()
- if $params->{mode} eq gettext("Counters");
-
- return &build_homepage()
- if $params->{mode} eq gettext("Home Page")
- || $params->{mode} eq gettext("Home")
- || $params->{mode} eq ""
- || $params->{mode} eq gettext("Login")
- || $params->{mode} eq gettext("Logout");
- return gettext("Not Available!") . "\n";
- return gettext("Not Available!") . "\n";
- }
- elsif ( $params->{logintype} == 5 ) { #Call Shop Login
- return &build_pricelists() if $params->{mode} eq gettext("Pricelists");
- return &build_routes() if $params->{mode} eq gettext("Routes");
- return &build_add_booth() if $params->{mode} eq gettext("Create Booth");
- return &build_remove_booth()
- if $params->{mode} eq gettext("Remove Booth");
- return &build_list_booths()
- if $params->{mode} eq gettext("List Booths");
- return &build_view_booth() if $params->{mode} eq gettext("View Booth");
-
- return &build_create_card() if $params->{mode} eq gettext("Add Cards");
- return &build_list_cards() if $params->{mode} eq gettext("List Cards");
- return &build_list_cards()
- if $params->{mode} eq gettext("Calling Cards");
- return &build_update_card_status()
- if $params->{mode} eq gettext("Update Card(s) Status");
- return &build_reset_card_inuse()
- if $params->{mode} eq gettext("Reset InUse");
- return &build_view_card() if $params->{mode} eq gettext("View Card");
- return &build_cc_brands() if $params->{mode} eq gettext("CC Brands");
- return &build_delete_cards()
- if $params->{mode} eq gettext("Delete Card");
- return &build_refill_card()
- if $params->{mode} eq gettext("Refill Card");
- return &build_callshop_callshop_report()
- if $params->{mode} eq gettext("Booth Report");
-
- return &build_list_booths()
- if $params->{mode} eq gettext("Home Page")
- || $params->{mode} eq gettext("Home")
- || $params->{mode} eq ""
- || $params->{mode} eq gettext("Login")
- || $params->{mode} eq gettext("Logout");
- return gettext("Not Available!") . "\n";
- }
- else {
- $params->{mode} = gettext("Home");
- return gettext("Not Available!") . "\n";
- }
-}
-
-sub build_purge_deactivated() {
- my ( $status, $body );
- return gettext("Cannot drop items until database is configured")
- unless $astpp_db;
- if ( $params->{action} eq gettext("Yes, Drop Them") ) {
- if ( $astpp_db->do("DELETE FROM outbound_routes WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated outbound routes.") . "<br>";
- }
- else {
- $status .=
- gettext("Unable to drop deactivated outbound routes.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM routes WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated routes.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated routes.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM accounts WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated accounts.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated accounts.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM pricelists WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated pricelists.") . "<br>";
- }
- else {
- $status .=
- gettext("Unable to drop deactivated pricelists.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM cdrs WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated cdrs.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated cdrs.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM trunks WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated trunks.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated trunks.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM dids WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated DIDs.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated DIDs.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM packages WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated packages.") . "<br>";
- }
- else {
- $status .= gettext("Unable to drop deactivated packages.") . "<br>";
- }
- if ( $astpp_db->do("DELETE FROM callshops WHERE status = 2") ) {
- $status .= gettext("Dropped deactivated callshops.") . "<br>";
- }
- else {
- $status .=
- gettext("Unable to drop deactivated callshops.") . "<br>";
- }
- }
- $body = start_form();
- $body .= "<TABLE>";
- $body .=
- "<tr><td>"
- . gettext(
- "Remove records in your system that have been marked as deactivated.")
- . "</td></tr>\n";
- if ( $params->{action} eq gettext("Drop Deactivated Records") ) {
- $body .=
- "<tr><td>"
- . hidden( -name => "mode", -value => gettext("Purge Deactivated") )
- . submit( -name => "action", -value => gettext("Yes, Drop Them") )
- . "</td><td>"
- . submit( -name => "action", -value => gettext("Cancel") )
- . "</td></tr><tr><td>$status</td></tr></table>";
- }
- else {
- $body .=
- "<tr><td>"
- . hidden( -name => "mode", -value => gettext("Purge Deactivated") )
- . submit(
- -name => "action",
- -value => gettext("Drop Deactivated Records")
- )
- . "</td><td>"
- . submit( -name => "action", -value => gettext("Cancel") )
- . "</td></tr><tr><td>$status</td></tr></table>";
- }
- return $body;
-}
-
-######## Reporting Module ################
-#
-
-# Modified and Extended By Sonia Ali Khan <son...@gm...>
-# Last updated: Sept. 11, 2007 at 1445hours GMT.
-
-sub build_filter($$) {
- my ( $additional_fields, $submit_title ) = @_;
- my ($body);
- return gettext("ASTPP Database Not Available!") . "<br>" unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, @output );
- return gettext("Asterisk CDR Database Not Available!") . "<br>"
- unless $cdr_db;
-
- # Set the defaults for the date options
- my ( undef, undef, undef, $current_day, $current_month, $current_year ) =
- localtime();
- my (
- $start_year, $start_month, $start_day, $start_hour,
- $start_minute, $start_second, $end_year, $end_month,
- $end_day, $end_hour, $end_minute, $end_second
- );
- my $count = 0;
- if ( !$params->{start_month} ) {
- $start_year = $current_year + 1900;
- $start_month = sprintf( "%02d", $current_month + 1 );
- $start_day = "01";
- $start_hour = "00";
- $start_minute = "00";
- $start_second = "00";
- $end_year = $current_year + 1900;
- $end_month = sprintf( "%02d", $current_month + 1 );
- $end_day = $current_day;
- $end_hour = "23";
- $end_minute = "59";
- $end_second = "59";
- }
- else {
- $start_year = $params->{start_year};
- $start_month = sprintf( "%02d", $params->{start_month} + 1 );
- $start_day = sprintf( "%02d", $params->{start_day} );
- $start_hour = sprintf( "%02d", $params->{start_hour} );
- $start_minute = sprintf( "%02d", $params->{start_minute} );
- $start_second = sprintf( "%02d", $params->{start_second} );
- $end_year = $params->{end_year};
- $end_month = sprintf( "%02d", $params->{end_month} + 1 );
- $end_day = sprintf( "%02d", $params->{end_day} );
- $end_hour = sprintf( "%02d", $params->{end_hour} );
- $end_minute = sprintf( "%02d", $params->{end_minute} );
- $end_second = sprintf( "%02d", $params->{end_second} );
- }
-
- $body .=
- "<form method=get><input type=hidden name=mode value=\""
- . param('mode')
- . "\"><table class=\"default\" width=100%>";
- $body .=
- "<tr><td width=50%>"
- . gettext("Start date:")
- . "</td><td><input type=text name=start_year value=\"$start_year\" size=5><select name=start_month>";
-
- for ( $id = 0 ; $id < 12 ; $id++ ) {
- if ( $id == ( $start_month - 1 ) ) {
- $body .= "<option value=$id selected>$months[$id]";
- }
- else {
- $body .= "<option value=$id>$months[$id]";
- }
- }
- $body .=
-"</select><input type=text name=start_day value=\"$start_day\" size=3></td></tr>";
- $body .=
- "<tr><td>"
- . gettext("Start time:")
- . "</td><td><input type=text name=start_hour value=\"$start_hour\" size=3>"
- . "<input type=text name=start_minute value=\"$start_minute\" size=3>"
- . "<input type=text name=start_second value=\"$start_second\" size=3></td></tr>";
- $body .=
- "<tr><td>"
- . gettext("End date:")
- . "</td><td><input type=text name=end_year value=\"$end_year\" size=5><select name=end_month>";
- for ( $id = 0 ; $id < 12 ; $id++ ) {
- if ( $id == ( $end_month - 1 ) ) {
- $body .= "<option value=$id selected>$months[$id]";
- }
- else {
- $body .= "<option value=$id>$months[$id]";
- }
- }
-
- $submit_title = "Filter!" if !$submit_title;
- $body .=
-"</select><input type=text name=end_day value=\"$end_day\" size=3></td></tr>";
- $body .=
- "<tr><td>"
- . gettext("End time:")
- . "</td><td><input type=text name=end_hour value=\"$end_hour\" size=3>"
- . "<input type=text name=end_minute value=\"$end_minute\" size=3>"
- . "<input type=text name=end_second value=\"$end_second\" size=3></td></tr>\n";
- $body .= $additional_fields if $additional_fields;
- $body .=
-"<tr><td align=center colspan=2><input type=submit value=$submit_title></td></tr>";
- $body .= "</table>\n</form>";
-
- my %report_filter = (
- 'start_year' => $start_year,
- 'start_month' => $start_month,
- 'start_day' => $start_day,
- 'start_hour' => $start_hour,
- 'start_minute' => $start_minute,
- 'start_second' => $start_second,
- 'end_year' => $end_year,
- 'end_month' => $end_month,
- 'end_day' => $end_day,
- 'end_hour' => $end_hour,
- 'end_minute' => $end_minute,
- 'end_second' => $end_second,
- 'start_date' =>
-"$start_year-$start_month-$start_day $start_hour:$start_minute:$start_second",
- 'end_date' =>
- "$end_year-$end_month-$end_day $end_hour:$end_minute:$end_second",
- 'form_body' => $body
- );
- return \%report_filter;
-}
-
-sub build_admin_reseller_report() {
- return &build_report( "Reseller", "1" );
-}
-
-sub build_admin_vendor_report() {
- return &build_report( "Vendor", "3" );
-}
-
-sub build_callshop_callshop_report() {
- return &build_report( "Booth", "6" );
-}
-
-sub build_reseller_callshop_report() {
- return &build_report( "Booth", "6" );
-}
-
-sub build_reseller_reseller_report() {
- return &build_report( "Reseller", "1" );
-}
-
-sub build_reseller_user_report() {
- return &build_report( "User", "0" );
-}
-
-sub build_list_box($$) {
- my ( $in, $selected ) = @_;
- my $body = "";
- undef %list;
- @list{@$in} = ();
- my @out = sort keys %list; # remove sort if undesired
- for ( my $i = 0 ; $i < @out ; $i++ ) {
- if ( $out[$i] eq $selected ) {
- $body .= "<option value='$out[$i]' selected>$out[$i]</option>\n";
- }
- else {
- $body .= "<option value='$out[$i]'>$out[$i]</option>\n";
- }
- }
- return $body;
-}
-
-sub build_report($$) {
-
- return gettext("Cannot display reports until database is configured")
- unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, $enh_config, @output );
- return gettext("Cannot display reports until database is configured")
- unless $cdr_db;
-
- my $name = shift;
- my $type = shift;
- my ( $sth, $body );
-
- my $destination = $params->{destination};
- my $pattern = $params->{pattern};
-
- if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) {
- $sth =
- $astpp_db->prepare( "SELECT * FROM accounts WHERE reseller = "
- . $astpp_db->quote( $params->{username} )
- . " AND type IN ($type)" );
- }
- else {
- $sth =
- $astpp_db->prepare("SELECT * FROM accounts WHERE type IN ($type)");
- }
-
- $sth->execute()
- || return gettext("Something is wrong with astpp database") . "\n";
-
- $body = "<tr><td align=right> $name:"
- . "<select name=$name value='$params->{$name}'>\n<option value='ALL'>ALL</option>\n";
-
- while ( my $row = $sth->fetchrow_hashref ) {
- if ( $row->{'number'} eq $params->{$name} ) {
- $body .=
-"<option value='$row->{'number'}' selected>$row->{'number'}</option>\n";
- }
- else {
- $body .=
- "<option value='$row->{'number'}'>$row->{'number'}</option>\n";
- }
- }
-
- $sth->finish;
-
- $body .= "</select> <strong>AND</strong> ";
-
- if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) {
- $sth = $astpp_db->prepare(
- "SELECT DISTINCT notes FROM cdrs WHERE notes LIKE "
- . $astpp_db->quote( $params->{username} . "|%" ) );
- }
- else {
- $sth = $astpp_db->prepare("SELECT DISTINCT notes FROM cdrs");
- }
-
- $sth->execute()
- || return gettext("Something is wrong with astpp database") . "\n";
-
- my ( $dest, $ptrn );
- my ( @dst, @ptn, $i );
- $dest =
-"Destination: </td><td align=left><select name=destination value='Destination'>\n"
- . "<option value='ALL'>ALL</option>\n";
- $ptrn =
- " <strong>OR</strong> "
- . "IDD Code: <select name=pattern value='IDD Code'>\n"
- . "<option value='ALL'>ALL</option>\n";
-
- while ( my $notes = $sth->fetchrow_hashref ) {
- my @note = split( m/(\^|DID:)/, $notes->{'notes'}, 2 );
- $ptn[$i] = $note[1] . $note[2];
- @note = split( /\|/, $note[0] );
- $dst[$i] = ( @note == 1 ) ? $note[0] : $note[1] if $note[0] ne "";
- $i++;
- }
- $sth->finish;
-
- $dest .= build_list_box( \@dst, $destination );
- $dest .= "</select>\n";
-
- $ptrn .= build_list_box( \@ptn, $pattern );
- $ptrn .= "</select>\n";
-
- $body .= $dest . $ptrn . "</td></tr>";
-
- my $filter = build_filter( $body, undef );
- my $sd = $filter->{'start_date'};
- my $ed = $filter->{'end_date'};
- $body = $filter->{'form_body'};
-
- my $where =
- "callstart BETWEEN "
- . $astpp_db->quote($sd) . " AND "
- . $astpp_db->quote($ed) . " ";
-
- if ( $params->{$name} eq 'ALL' ) {
- if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) {
- $where .=
- "AND cardnum IN (SELECT `number` FROM accounts WHERE reseller = "
- . $astpp_db->quote( $params->{username} )
- . " AND type IN ($type)) ";
- }
- else {
- if ( index( $type, "1" ) != -1 ) {
- $where .=
-"AND cardnum IN (SELECT `number` FROM accounts WHERE type IN ($type)) ";
- }
- elsif ( index( $type, "3" ) != -1 ) {
- $where .=
- "AND provider = " . $astpp_db->quote( $params->{$name} );
- }
- }
- }
- else {
- if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) {
- $where .=
- "AND cardnum = " . $astpp_db->quote( $params->{$name} ) . " ";
- }
- else {
- if ( index( $type, "1" ) != -1 ) {
- $where .=
-"AND cardnum IN (SELECT `number` FROM accounts WHERE `number` = "
- . $astpp_db->quote( $params->{$name} )
- . " AND type IN ($type)) ";
- }
- elsif ( index( $type, "3" ) != -1 ) {
- $where .=
- "AND provider = " . $astpp_db->quote( $params->{$name} );
- }
- }
- }
-
- if ( $destination eq 'ALL' ) {
- if ( $pattern eq 'ALL' ) {
- $where .= "";
- }
- else {
- $where .=
- "AND notes LIKE " . $astpp_db->quote( "%|" . $pattern ) . " ";
- }
- }
- else {
- if ( $pattern eq 'ALL' ) {
- $where .= "AND notes LIKE "
- . $astpp_db->quote( "%|" . $destination . "|%" ) . " ";
- }
- else {
- $where .= "AND (notes LIKE "
- . $astpp_db->quote( "%|" . $destination . "|%" ) . " ";
- $where .=
- "OR notes LIKE " . $astpp_db->quote( "%|" . $pattern ) . ") ";
- }
- }
-
- $where = 0 if $param->{$name} eq "" && $destination eq "" && $pattern eq "";
-
- $body .=
- start_form()
- . "<table class=\"default\" width=100%><tr><td colspan=12 align=center><b>$sd - $ed</b></td></tr>"
- . "<tr class=\"header\"><td>"
- . gettext("$name")
- . "</td><td>"
- . gettext("Destination")
- . "</td><td>"
- . gettext("IDD Code")
- . "</td><td>"
- . gettext("Attempted Calls")
- . "</td><td>"
- . gettext("Completed Calls")
- . "</td><td>"
- . "<acronym title=\""
- . gettext("Answer Seizure Rate") . "\">"
- . gettext("ASR")
- . "</acronym>"
- . "</td><td>"
- . "<acronym title=\""
- . gettext("Average Call Duration") . "\">"
- . gettext("ACD")
- . "</acronym>"
- . "</td><td>"
- . "<acronym title=\""
- . gettext("Maximum Call Duration") . "\">"
- . gettext("MCD")
- . "</acronym>"
- . "</td><td>"
- . gettext("Actual")
- . "</td><td>"
- . gettext("Billable")
- . "</td><td>"
- . gettext("Price")
- . "</td><td>"
- . gettext("Cost")
- . "</td></tr>\n";
-
- my $table = "tmp_" . time();
- my (
- $bth, $dst, $idd, $atmpt, $cmplt, $asr,
- $acd, $mcd, $act, $bill, $price, $cost
- );
- my $query =
-"CREATE TEMPORARY TABLE $table SELECT * FROM cdrs WHERE uniqueid != '' AND $where";
- $sth = $astpp_db->do($query)
- || return gettext("Something is wrong with astpp database") . "\n";
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $query " );
-
- my $sql =
- $astpp_db->prepare("SELECT DISTINCT cardnum AS $name FROM $table");
- $sql->execute()
- || return gettext("Something is wrong with astpp database") . "\n";
-
- while ( my $row = $sql->fetchrow_hashref ) {
- $bth = $row->{$name};
- my $sql1 = $astpp_db->prepare(
- "SELECT notes, COUNT(*) AS attempts, AVG(billseconds) AS acd,
- MAX(billseconds) AS mcd, SUM(billseconds) AS billable,
- SUM(debit) AS cost, SUM(cost) AS price FROM $table
- WHERE (notes IS NOT NULL AND notes != '') AND cardnum = "
- . $astpp_db->quote($bth) . " GROUP BY notes"
- );
- $sql1->execute()
- || return gettext("Something is wrong with astpp database") . "\n";
-
- while ( my $row1 = $sql1->fetchrow_hashref() ) {
- my @note1 = split( m/(\^|DID:)/, $row1->{notes}, 2 );
- $idd = $note1[1] . $note1[2];
- @note1 = split( /\|/, $note1[0] );
- $dst = ( @note1 == 1 ) ? $note1[0] : $note1[1];
- $dst = 'N/A' if $dst eq "";
-
- $atmpt = $row1->{'attempts'};
- $acd = $row1->{'acd'};
- $mcd = $row1->{'mcd'};
- $bill = $row1->{'billable'};
- $price = $row1->{'price'};
- $cost = $row1->{'cost'};
-
- $notes = "notes = " . $astpp_db->quote( $row1->{notes} );
-
- my $sql2 = $astpp_db->prepare(
- "SELECT COUNT(*) AS completed FROM $table
- WHERE $notes AND disposition = 'ANSWERED'"
- );
- $sql2->execute()
- || return gettext("Something is wrong with astpp database")
- . "\n";
- my $row2 = $sql2->fetchrow_hashref();
- $cmplt = $row2->{'completed'} || 0;
- $sql2->finish;
-
- $asr = ( ( $atmpt - $cmplt ) / $atmpt ) * 100;
-
- my $in = "";
- my $sql3 =
- $astpp_db->prepare("SELECT uniqueid FROM $table WHERE $notes ");
- $sql3->execute()
- || return gettext("Something is wrong with astpp database")
- . "\n";
-
- while ( my $row3 = $sql3->fetchrow_hashref ) {
- $in .= "'" . $row3->{'uniqueid'} . "'," if $row3->{'uniqueid'};
- }
-
- $in = substr( $in, 0, -1 ) if length($in) > 0;
- $sql3->finish;
-
- my $sql4 = $cdr_db->prepare(
-"SELECT SUM(duration) AS actual FROM cdr WHERE uniqueid IN ($in)"
- );
- $sql4->execute()
- || return gettext("Something is wrong with cdr database") . "\n";
- my $row4 = $sql4->fetchrow_hashref();
- $act = $row4->{'actual'};
- $sql4->finish;
-
- $act = int( $act / 60 ) . ":" . ( $act % 60 );
- $acd = int( $acd / 60 ) . ":" . ( $acd % 60 );
- $mcd = int( $mcd / 60 ) . ":" . ( $mcd % 60 );
- $bill = int( $bill / 60 ) . ":" . ( $bill % 60 );
- $price = $price / 10000.0;
- $cost = $cost / 10000.0;
-
- $body .= "<tr>"
- . "<td>$bth</td><td>$dst</td><td>$idd</td><td>$atmpt</td><td>$cmplt</td><td>$asr</td>"
- . "<td align=right>$acd</td><td align=right>$mcd</td><td align=right>$act</td>"
- . "<td align=right>$bill</td><td>$price</td><td>$cost</td>"
- . "</tr>";
- }
- $sql1->finish;
- }
- $sql->finish;
-
- $sth = $astpp_db->do("DROP TEMPORARY TABLE $table")
- || return gettext("Something is wrong with astpp database") . "\n";
-
- $body .= "</table>";
- return $body;
-}
-
-sub build_admin_report() {
- my ($body);
- return gettext("Cannot display reports until database is configured")
- unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, $enh_config, @output );
- return gettext("Cannot display reports until database is configured")
- unless $cdr_db;
-
- return gettext("Comming Soon!");
-}
-
-sub build_reseller_report() {
- my ($body);
- return gettext("Cannot display reports until database is configured")
- unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, $enh_config, @output );
- return gettext("Cannot display reports until database is configured")
- unless $cdr_db;
-
- return gettext("Coming Soon!");
-}
-
-# End of code changes by Sonia Ali Khan.
-
-#################### Stats stuff ###########################
-sub build_stats_acd() {
- my ( $body, $id );
- return gettext("Cannot display stats until database is configured")
- unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, $enh_config, @output );
- return gettext("Cannot display stats until database is configured")
- unless $cdr_db;
-
- my $filter = build_filter( undef, undef );
- my $sd = $filter->{'start_date'};
- my $ed = $filter->{'end_date'};
- $body = $filter->{'form_body'};
-
- my $sth;
-
- if ( $params->{logintype} == 3 ) {
- $sth =
- $astpp_db->prepare( "SELECT * FROM trunks WHERE provider = "
- . $astpp_db->quote( $params->{username} ) );
- }
- else {
- $sth = $astpp_db->prepare("SELECT * FROM trunks");
- }
- $sth->execute
- || return gettext("Something is wrong with the trunks database") . "\n";
- $body .=
- start_form()
- . "<table class=\"default\" width=100%><tr><td colspan=5 align=center><b>$sd - $ed</b></td></tr>"
- . "<tr class=\"header\"><td>"
- . gettext("Trunk Name")
- . "</td><td>"
- . gettext("Calls")
- . "</td><td>"
- . "<acronym title=\""
- . gettext("Average Call Duration") . "\">"
- . gettext("ACD")
- . "</acronym>"
- . "</td><td>"
- . "<acronym title=\""
- . gettext("Average Call Wait Time") . "\">"
- . gettext("ACWT")
- . "</acronym>"
- . "</td><td>"
- . gettext("Success")
- . "</td><td>"
- . gettext("Congestion")
- . "</td></tr>\n";
-
- while ( my $row = $sth->fetchrow_hashref ) {
- $count++;
- my $sql1 = " SELECT COUNT(
- *) as calls,
- AVG(billsec) as bs,
- AVG( duration-billsec ) as acwt from cdr where lastapp = 'Dial'
- and disposition REGEXP '^ANSWERED$'
- and calldate >= " . $cdr_db->quote($sd) . "
- and calldate <= " . $cdr_db->quote($ed) . "
- and (dstchannel like '$row->{tech}/$row->{path}%'
- or dstchannel like '$row->{tech}\[$row->{path}\]%' ) ";
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql1 \n " );
- my $sth1 = $cdr_db->prepare($sql1);
- $sth1->execute();
- my $ref1 = $sth1->fetchrow_hashref();
- $sth1->finish;
- my $sql2 = " select count(
- *) as ct from cdr where calldate >=
- " . $cdr_db->quote($sd) . "
- and calldate <= " . $cdr_db->quote($ed) . "
- and disposition not in(
- 'ANSWERED','16'
- )
- and (dstchannel like '$row->{tech}/$row->{path}%'
- or dstchannel like '$row->{tech}\[$row->{path}\]%' )
- ";
- my $sth2 = $cdr_db->prepare($sql2);
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql2" );
- $sth2->execute();
- my $ref2 = $sth2->fetchrow_hashref();
- $sth2->finish;
- my $sql3 = " select count(
- *) as ct from cdr where calldate >=
- " . $cdr_db->quote($sd) . "
- and calldate <= " . $cdr_db->quote($ed) . "
- and disposition REGEXP '^CONGESTION$'
- and (dstchannel like '$row->{tech}/$row->{path}%'
- or dstchannel like '$row->{tech}\[$row->{path}\]%' )
- ";
- my $sth3 = $cdr_db->prepare($sql3);
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql3" );
- $sth3->execute();
- my $ref3 = $sth3->fetchrow_hashref();
- $sth3->finish;
- my $sql4 = " select count(
- *) as ct from cdr where calldate >=
- " . $cdr_db->quote($sd) . "
- and calldate <= " . $cdr_db->quote($ed) . "
- and (dstchannel like '$row->{tech}/$row->{path}%'
- or dstchannel like '$row->{tech}\[$row->{path}\]%' )
- ";
- my $sth4 = $cdr_db->prepare($sql4);
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql4" );
- $sth4->execute();
- my $ref4 = $sth4->fetchrow_hashref();
- $sth4->finish;
- my $success_rate = 0;
- my $congestion_rate = 0;
-
- if ( $ref4->{ct} > 0 && $ref1->{calls} > 0 ) {
- $success_rate = ( $ref1->{calls} / $ref4->{ct} ) * 100;
- }
- if ( $ref4->{ct} > 0 && $ref3->{ct} > 0 ) {
- $congestion_rate = ( $ref3->{ct} / $ref4->{ct} ) * 100;
- }
- if ( $count % 2 == 0 ) {
- $body .= "<tr class=\"rowtwo\">";
- }
- else {
- $body .= "<tr class=\"rowone\">";
- }
- $body .=
-"<td>$row->{tech}/$row->{path}</td><td align=right>$ref4->{ct}</td><td align=right>"
- . "$ref1->{bs}</td><td align=right>$ref1->{acwt}</td><td align=right>"
- . "$ref1->{calls} "
- . sprintf( "%.04f", $success_rate )
- . " %</td><td>"
- . "$ref3->{ct} "
- . sprintf( "%.04f", $congestion_rate )
- . "%</td></tr>\n";
- }
- $sth->finish;
- $body .= "</table>";
- return $body;
-}
-
-#################### Stats stuff ###########################
-sub build_view_cdrs() {
- my (
- @trunklist, $body, $id, $tmp,
- $row, $sql, $results, $pagesrequired,
- $pageno, $string, $sd_month
- );
- return gettext("Cannot display stats until database is configured")
- unless $astpp_db;
- $cdr_db = &cdr_connect_db( $config, @output );
- return gettext("Cannot display stats until database is configured")
- unless $cdr_db;
- if ( $params->{limit} < 1 || !$params->{limit} ) { $params->{limit} = 0 }
- my $results_per_page = $config->{results_per_page};
- if ( $results_per_page eq "" ) { $results_per_page = 25; }
- my ( undef, undef, undef, $day, $mnth, $yr ) = localtime();
-
- if ( $params->{logintype} == 3 ) {
- my $sql =
- $astpp_db->prepare( "SELECT * FROM trunks WHERE provider = "
- . $astpp_db->quote( $params->{username} ) );
- $sql->execute;
- while ( my $record = $sql->fetchrow_hashref ) {
- push @trunklist, $record->{name};
- }
- $sql->finish;
- }
- else {
- @trunklist = &list_trunks($astpp_db);
- push( @trunklist, "" );
- }
- @trunklist = sort @trunklist;
-
- $body =
- "<tr><td>"
- . gettext("Answered Calls Only?")
- . popup_menu(
- -name => "answered",
- -values => \%yesno
- ) . "</td><td>";
- if ( $params->{logintype} == 2 ) {
- $body .= gettext("AccountCode:")
- . textfield(
- -name => "accountcode",
- -width => 8
- );
- }
- $body .=
- "</td></tr>"
- . "<tr><td>"
- . gettext("Select Outbound Trunk?")
- . popup_menu(
- -name => "trunk",
- -values => \@trunklist
- ) . "</td></tr>";
-
- my $filter = build_filter( $body, undef );
- my $sd = $filter->{'start_date'};
- my $ed = $filter->{'end_date'};
- $body = $filter->{'form_body'};
-
- $body .= start_form()
- . "<table class=\"viewcdrs\" width=100%><tr><td colspan=5 align=center><b>$sd - $ed</b></td></tr>
-"
- . "<tr class=\"header\"><td>"
- . gettext("Date")
- . "</td><td>"
- . gettext("CallerID") . "</td>" . "<td>"
- . gettext("Source")
- . "</td><td>"
- . gettext("Dest") . "</td>" . "<td>"
- . gettext("D.Context")
- . "</td><td>"
- . gettext("Chan") . "</td>" . "<td>"
- . gettext("D.Chan")
- . "</td><td>"
- . gettext("Last App")
- . " </td>" . "<td>"
- . gettext("Last Data")
- . "</td><td>"
- . gettext("Duration") . "</td>" . "<td>"
- . gettext("BillSec")
- . "</td><td>"
- . gettext("Disposition") . "</td>" . "<td>"
- . gettext("AMAFlags")
- . "</td><td>";
-
- if ( $params->{logintype} == 2 ) {
- $body .= gettext("AccountCode");
- }
- $body .=
- "</td>" . "<td>"
- . gettext("U-ID")
- . "</td><td>"
- . gettext("UserField") . "</td>" . "<td>"
- . gettext("Cost")
- . "</td></tr>
-\n";
- if ( $params->{answered} == 1 ) {
- $tmp =
- " SELECT * from cdr where disposition = 'ANSWERED'"
- . " and calldate >= "
- . $cdr_db->quote($sd)
- . " and calldate <= "
- . $cdr_db->quote($ed);
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" );
- }
- else {
- $tmp =
- " SELECT * from cdr where calldate >= "
- . $cdr_db->quote($sd)
- . " and calldate <= "
- . $cdr_db->quote($ed);
- $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" );
- }
- if ( $params->{accountcode} && $params->{logintype} == 2 ) {
- $tmp .=
- " and accountcode = " . $cdr_db->quote( $params->{accountcode} );
- }
- if ( $params->{trunk} ) {
- my $tmpsql =
- "SELECT * FROM trunks WHERE name = "
- . $astpp_db->quote( $params->{trunk} )
- . " LIMIT 1";
- $ASTPP->debug( user => $param->{username}, debug => $tmpsql );
- $sql = $astpp_db->prepare($tmpsql);
- $sql->execute
- || return gettext("Something is wrong with the trunks database")
- . "\n";
- $row = $sql->fetchrow_hashref;
- $sql->finish;
- $tmp .= " and (dstchannel like '$row->{tech}/$row->{path}\%'"
- . " or dstchannel like '$row->{tech}\[$row->{path}\]\%')";
- }
- $ASTPP->debug( user => $param->{username}, debug => $tmp );
- $sql = $cdr_db->prepare($tmp);
- $sql->execute;
- $results = $sql->rows;
- $pagesrequired = ceil( $results / $results_per_page );
- $sql->finish;
- $tmp .= " limit $params->{limit} , $results_per_page";
- $sql = $cdr_db->prepare($tmp);
- $sql->execute;
-
- while ( my $record = $sql->fetchrow_hashref ) {
- $count++;
- if ( $count % 2 == 0 ) {
- $body .= "<tr class=\"rowtwo\">";
- }
- else {
- $body .= "<tr class=\"rowone\">";
- }
- my $dcontext = substr( $record->{dcontext}, 0, 4 ) . "..";
- my $channel = substr( $record->{channel}, 0, 9 ) . "..";
- my $dstchannel = substr( $record->{channel}, 0, 9 ) . "..";
- my $lastdata = substr( $record->{lastdata}, 0, 4 ) . "..";
- if ( $params->{logintype} != 2 ) {
- ...
[truncated message content] |