[Astpp-commit] SF.net SVN: astpp:[2206] trunk/astpp-admin.cgi
Brought to you by:
darrenkw
From: <dar...@us...> - 2008-11-11 23:06:22
|
Revision: 2206 http://astpp.svn.sourceforge.net/astpp/?rev=2206&view=rev Author: darrenkw Date: 2008-11-11 23:06:16 +0000 (Tue, 11 Nov 2008) Log Message: ----------- Performed a "perl-tidy" and cleaned up all the code formatting. Modified Paths: -------------- trunk/astpp-admin.cgi Modified: trunk/astpp-admin.cgi =================================================================== --- trunk/astpp-admin.cgi 2008-11-11 22:57:53 UTC (rev 2205) +++ trunk/astpp-admin.cgi 2008-11-11 23:06:16 UTC (rev 2206) @@ -53,7 +53,7 @@ use DateTime::TimeZone; use ASTPP; - ; # We use DateTime::TimeZone to show users cdrs in their own timezones. +; # 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 @@ -65,11 +65,11 @@ $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_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 = ( +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") @@ -100,44 +100,39 @@ gettext("Reset InUse"), gettext("CC Brands") ); my @SwitchConfig = (); -my @CallShops = ( gettext("Create CallShop"), gettext("Remove CallShop") ); -my @Booths = ( +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 @AdminReports = ( gettext("Reseller Report"), gettext("Vendor Report") ); -my @CallShopReports = ( - gettext("Booth Report") -); +my @CallShopReports = ( gettext("Booth Report") ); my @ResellerReports = ( -# gettext("Brand Report"), - gettext("CallShop Report"), - gettext("Reseller Report"), - gettext("User Report") + + # 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 + 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', @@ -169,9 +164,9 @@ 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 + $rt_db, $astpp_db, $config, $params, $param, + $cdr_db, $agile_db, $body, $menu, $status, + $msg, $loginstat, @modes, $openser_db ); $params->{mode} = ""; @@ -228,10 +223,22 @@ $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"); + $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 ); } @@ -276,14 +283,22 @@ $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; + $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; } @@ -426,10 +441,10 @@ 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"); + || $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 @@ -523,8 +538,9 @@ 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_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() @@ -538,10 +554,10 @@ 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"); + || $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"; } @@ -574,10 +590,10 @@ 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"); + || $params->{mode} eq gettext("Home") + || $params->{mode} eq "" + || $params->{mode} eq gettext("Login") + || $params->{mode} eq gettext("Logout"); return gettext("Not Available!") . "\n"; } else { @@ -651,12 +667,14 @@ } $body = start_form(); $body .= "<TABLE>"; - $body .= "<tr><td>" + $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>" + $body .= + "<tr><td>" . hidden( -name => "mode", -value => gettext("Purge Deactivated") ) . submit( -name => "action", -value => gettext("Yes, Drop Them") ) . "</td><td>" @@ -664,7 +682,8 @@ . "</td></tr><tr><td>$status</td></tr></table>"; } else { - $body .= "<tr><td>" + $body .= + "<tr><td>" . hidden( -name => "mode", -value => gettext("Purge Deactivated") ) . submit( -name => "action", @@ -684,7 +703,7 @@ # Last updated: Sept. 11, 2007 at 1445hours GMT. sub build_filter($$) { - my ($additional_fields, $submit_title) = @_; + my ( $additional_fields, $submit_title ) = @_; my ($body); return gettext("ASTPP Database Not Available!") . "<br>" unless $astpp_db; $cdr_db = &cdr_connect_db( $config, @output ); @@ -729,10 +748,14 @@ $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>"; + $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 ) ) { @@ -742,13 +765,18 @@ $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>"; + $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]"; @@ -758,204 +786,242 @@ } } - $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>"; + $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; + 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"); + return &build_report( "Reseller", "1" ); } sub build_admin_vendor_report() { - return &build_report("Vendor","3"); + return &build_report( "Vendor", "3" ); } sub build_callshop_callshop_report() { - return &build_report("Booth","6"); + return &build_report( "Booth", "6" ); } sub build_reseller_callshop_report() { - return &build_report("Booth","6"); + return &build_report( "Booth", "6" ); } sub build_reseller_reseller_report() { - return &build_report("Reseller","1"); + return &build_report( "Reseller", "1" ); } sub build_reseller_user_report() { - return &build_report("User","0"); + 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; + 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") + + 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) { + 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)"); + . $astpp_db->quote( $params->{username} ) + . " AND type IN ($type)" ); } else { - $sth = $astpp_db->prepare("SELECT * FROM accounts WHERE type IN ($type)"); + $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"; + $sth->execute() + || return gettext("Something is wrong with astpp database") . "\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"; - } - } + $body = "<tr><td align=right> $name:" + . "<select name=$name value='$params->{$name}'>\n<option value='ALL'>ALL</option>\n"; - $sth->finish; + 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"; + } + } - $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}."|%")); + $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"; + $sth->execute() + || return gettext("Something is wrong with astpp database") . "\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 ( $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"; - 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}); - } - } - } + 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; - 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).") "; - } - } + $dest .= build_list_box( \@dst, $destination ); + $dest .= "</select>\n"; - $where = 0 if $param->{$name} eq "" && $destination eq "" && $pattern eq ""; + $ptrn .= build_list_box( \@ptn, $pattern ); + $ptrn .= "</select>\n"; - $body .= start_form() + $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") @@ -991,88 +1057,108 @@ . "</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"; + 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 " ); - while(my $row = $sql->fetchrow_hashref) { - $bth = $row->{$name}; - my $sql1 = $astpp_db->prepare("SELECT notes, COUNT(*) AS attempts, AVG(billseconds) AS acd, + 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 ""; + . $astpp_db->quote($bth) . " GROUP BY notes" + ); + $sql1->execute() + || return gettext("Something is wrong with astpp database") . "\n"; - $atmpt = $row1->{'attempts'}; - $acd = $row1->{'acd'}; - $mcd = $row1->{'mcd'}; - $bill = $row1->{'billable'}; - $price = $row1->{'price'}; - $cost = $row1->{'cost'}; + 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 ""; - $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; + $atmpt = $row1->{'attempts'}; + $acd = $row1->{'acd'}; + $mcd = $row1->{'mcd'}; + $bill = $row1->{'billable'}; + $price = $row1->{'price'}; + $cost = $row1->{'cost'}; - $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; + $notes = "notes = " . $astpp_db->quote( $row1->{notes} ); - 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; + 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; - $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; + $asr = ( ( $atmpt - $cmplt ) / $atmpt ) * 100; - $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>"; + 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; } @@ -1083,8 +1169,8 @@ $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!"); + + return gettext("Comming Soon!"); } sub build_reseller_report() { @@ -1094,8 +1180,8 @@ $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!"); + + return gettext("Coming Soon!"); } # End of code changes by Sonia Ali Khan. @@ -1108,14 +1194,14 @@ $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; + 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 = " @@ -1127,7 +1213,7 @@ $sth->execute || return gettext("Something is wrong with the trunks database") . "\n"; $body .= - start_form() + 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") @@ -1160,7 +1246,7 @@ 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 "); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql1 \n " ); my $sth1 = $cdr_db->prepare($sql1); $sth1->execute(); my $ref1 = $sth1->fetchrow_hashref(); @@ -1176,7 +1262,7 @@ or dstchannel like '$row->{tech}\[$row->{path}\]%' ) "; my $sth2 = $cdr_db->prepare($sql2); - $ASTPP->debug( user => $param->{username}, debug =>" SQL: $sql2"); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql2" ); $sth2->execute(); my $ref2 = $sth2->fetchrow_hashref(); $sth2->finish; @@ -1189,7 +1275,7 @@ or dstchannel like '$row->{tech}\[$row->{path}\]%' ) "; my $sth3 = $cdr_db->prepare($sql3); - $ASTPP->debug( user => $param->{username}, debug =>" SQL: $sql3"); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql3" ); $sth3->execute(); my $ref3 = $sth3->fetchrow_hashref(); $sth3->finish; @@ -1201,7 +1287,7 @@ or dstchannel like '$row->{tech}\[$row->{path}\]%' ) "; my $sth4 = $cdr_db->prepare($sql4); - $ASTPP->debug( user=> $param->{username}, debug => " SQL: $sql4"); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $sql4" ); $sth4->execute(); my $ref4 = $sth4->fetchrow_hashref(); $sth4->finish; @@ -1267,8 +1353,10 @@ push( @trunklist, "" ); } @trunklist = sort @trunklist; - - $body = "<tr><td>" . gettext("Answered Calls Only?") + + $body = + "<tr><td>" + . gettext("Answered Calls Only?") . popup_menu( -name => "answered", -values => \%yesno @@ -1280,21 +1368,21 @@ -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() + "</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>" @@ -1338,7 +1426,7 @@ . $cdr_db->quote($sd) . " and calldate <= " . $cdr_db->quote($ed); - $ASTPP->debug( user=> $param->{username}, debug => " SQL: $tmp"); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" ); } else { $tmp = @@ -1346,7 +1434,7 @@ . $cdr_db->quote($sd) . " and calldate <= " . $cdr_db->quote($ed); - $ASTPP->debug( user=> $param->{username}, debug => " SQL: $tmp"); + $ASTPP->debug( user => $param->{username}, debug => " SQL: $tmp" ); } if ( $params->{accountcode} && $params->{logintype} == 2 ) { $tmp .= @@ -1357,18 +1445,17 @@ "SELECT * FROM trunks WHERE name = " . $astpp_db->quote( $params->{trunk} ) . " LIMIT 1"; - $ASTPP->debug( user=> $param->{username}, debug => $tmpsql); + $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}\%'" + $tmp .= " and (dstchannel like '$row->{tech}/$row->{path}\%'" . " or dstchannel like '$row->{tech}\[$row->{path}\]\%')"; } - $ASTPP->debug( user=> $param->{username}, debug => $tmp); + $ASTPP->debug( user => $param->{username}, debug => $tmp ); $sql = $cdr_db->prepare($tmp); $sql->execute; $results = $sql->rows; @@ -1413,18 +1500,30 @@ $sql->finish; $filter{'start_month'} = $filter{'start_month'} - 1; $string = - "&start_year=" . $filter{'start_year'} - . "&start_month=" . $filter{'start_month'} - . "&start_day=" . $filter{'start_day'} - . "&start_hour=" . $filter{'start_hour'} - . "&start_minute=". $filter{'start_minute'} - . "&start_second=". $filter{'start_second'} - . "&end_year=" . $filter{'end_year'} - . "&end_month=" . $filter{'end_month'} - . "&end_day=" . $filter{'end_day'} - . "&end_hour=" . $filter{'end_hour'} - . "&end_minute=" . $filter{'end_minute'} - . "&end_second=" . $filter{'end_second'} + "&start_year=" + . $filter{'start_year'} + . "&start_month=" + . $filter{'start_month'} + . "&start_day=" + . $filter{'start_day'} + . "&start_hour=" + . $filter{'start_hour'} + . "&start_minute=" + . $filter{'start_minute'} + . "&start_second=" + . $filter{'start_second'} + . "&end_year=" + . $filter{'end_year'} + . "&end_month=" + . $filter{'end_month'} + . "&end_day=" + . $filter{'end_day'} + . "&end_hour=" + . $filter{'end_hour'} + . "&end_minute=" + . $filter{'end_minute'} + . "&end_second=" + . $filter{'end_second'} . "&trunk=" . $params->{trunk}; for ( my $i = 0 ; $i <= $pagesrequired - 1 ; $i++ ) { @@ -1475,8 +1574,10 @@ } sub build_homepage() { - my $template = - HTML::Template->new( filename => '/var/lib/astpp/templates/home.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); + my $template = HTML::Template->new( + filename => '/var/lib/astpp/templates/home.tpl', + die_on_bad_params => $config->{template_die_on_bad_params} + ); if ( $params->{logintype} == 1 || $params->{logintype} == 5 @@ -1493,7 +1594,7 @@ $accounts .= ","; } } - $ASTPP->debug( user=> $param->{username}, debug => $accounts); + $ASTPP->debug( user => $param->{username}, debug => $accounts ); $template->param( customer_count => &count_accounts( $astpp_db, "WHERE type = 0 AND reseller = '$params->{username}'" @@ -1520,9 +1621,13 @@ "WHERE type = 5 AND reseller = '$params->{username}'" ) ); - $template->param( total_owing => &accounts_total_balance($astpp_db,$params->{username})/10000 ); - $template->param( total_due => &accountbalance($astpp_db,$params->{username})/10000 ); + $template->param( total_owing => + &accounts_total_balance( $astpp_db, $params->{username} ) / + 10000 ); $template->param( + total_due => &accountbalance( $astpp_db, $params->{username} ) / + 10000 ); + $template->param( calling_cards_in_use => &count_callingcards( $astpp_db, "WHERE inuse = 1 AND status = 1 AND reseller = '$params->{username}'" @@ -1530,7 +1635,8 @@ ); $template->param( dids => &count_dids( $astpp_db, "" ) ); $template->param( - unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, $accounts ) ); + unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, $accounts ) + ); } elsif ( $params->{logintype} == 2 && $astpp_db && $cdr_db ) { $template->param( @@ -1548,28 +1654,31 @@ $astpp_db, "WHERE inuse = 1 AND status = 1" ) ); - $template->param( total_owing => &accounts_total_balance($astpp_db,"")/10000 ); + $template->param( + total_owing => &accounts_total_balance( $astpp_db, "" ) / 10000 ); $template->param( dids => &count_dids( $astpp_db, "" ) ); $template->param( - unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, "NULL,''" ) ); + unbilled_cdrs => &count_unbilled_cdrs( $config, $cdr_db, "NULL,''" ) + ); } return $template->output; } - sub build_account_info() { my ( $total, $body, $status, $description, $pricelists, $chargeid, $tmp, $number, $pagesrequired, $results_per_page, $results, $pageno ); - my $template = - HTML::Template->new( - filename => '/var/lib/astpp/templates/account-info.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); + my $template = HTML::Template->new( + filename => '/var/lib/astpp/templates/account-info.tpl', + die_on_bad_params => $config->{template_die_on_bad_params} + ); return gettext("Cannot view account until database is configured") unless $astpp_db; -@pricelists = $ASTPP->list_pricelists(reseller => $params->{logged_in_reseller}); + @pricelists = + $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); return gettext("Cannot view account until pricelists configured") unless @pricelists; @@ -1612,13 +1721,13 @@ &write_account_cdr( $astpp_db, $number, $params->{amount} * 10000, $params->{desc}, $timestamp, 0 ); - $status .= "Charge Posted"; + $status .= "Charge Posted"; } } else { &write_account_cdr( $astpp_db, $number, $params->{amount} * 10000, $params->{desc}, $timestamp, 0 ); - $status .= "Charge Posted"; + $status .= "Charge Posted"; } } elsif ( $params->{action} eq gettext("Add Charge...") ) { @@ -1662,15 +1771,13 @@ if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { $accountinfo = &get_account( $astpp_db, $number ); if ( $accountinfo->{reseller} eq $params->{username} ) { - $tmp = - "DELETE FROM charge_to_account WHERE id = " + $tmp = "DELETE FROM charge_to_account WHERE id = " . $astpp_db->quote( $params->{chargeid} ); $astpp_db->do($tmp); } } else { - $tmp = - "DELETE FROM charge_to_account WHERE id = " + $tmp = "DELETE FROM charge_to_account WHERE id = " . $astpp_db->quote( $params->{chargeid} ); $astpp_db->do($tmp); } @@ -1682,9 +1789,7 @@ else { $number = $params->{numberlist}; } - $status .= - &remove_did( $astpp_db, $config, $params->{DID}, - $number ); + $status .= &remove_did( $astpp_db, $config, $params->{DID}, $number ); } elsif ( $params->{action} eq gettext("Purchase DID") ) { if ( $params->{accountnum} ne "" ) { @@ -1694,8 +1799,7 @@ $number = $params->{numberlist}; } $status .= - &purchase_did( $astpp_db, $config, $params->{did_list}, - $number ); + &purchase_did( $astpp_db, $config, $params->{did_list}, $number ); } elsif ( $params->{action} eq gettext("Map ANI") ) { if ( $params->{accountnum} ne "" ) { @@ -1760,7 +1864,7 @@ . $astpp_db->quote($number) . ", " . $astpp_db->quote( $params->{prefix} ) . ", " . $astpp_db->quote( $params->{ipcontext} ) . ")"; - $ASTPP->debug( user=> $param->{username}, debug => $tmp); + $ASTPP->debug( user => $param->{username}, debug => $tmp ); if ( $astpp_db->do($tmp) ) { $status .= gettext("IP") . " '" @@ -1801,103 +1905,110 @@ . gettext("FAILED to remove!") . "<br>"; } } - if ( $number ne "" ) { - $accountinfo = &get_account( $astpp_db, $number ); - } - elsif ( $params->{accountnum} ne "" ) { - $accountinfo = &get_account( $astpp_db, $params->{accountnum} ); - } - else { - $accountinfo = &get_account( $astpp_db, $params->{numberlist} ); - } - if ( $accountinfo->{number} ) { - $accountinfo->{balance} = &accountbalance( $astpp_db, $accountinfo->{number} ); - $accountinfo->{balance} = sprintf( "%.2f", $accountinfo->{balance} / 10000 ); - $template->param(first_name => $accountinfo->{first_name}); - $template->param(middle_name => $accountinfo->{middle_name}); - $template->param(last_name => $accountinfo->{last_name}); - $template->param(company => $accountinfo->{company_name}); - $template->param(telephone_1 => $accountinfo->{telephone_1}); - $template->param(telephone_2 => $accountinfo->{telephone_2}); - $template->param(fascimilie => $accountinfo->{fascimilie}); - $template->param(address_1 => $accountinfo->{address_1}); - $template->param(address_2 => $accountinfo->{address_2}); - $template->param(address_3 => $accountinfo->{address_3}); - $template->param(email => $accountinfo->{email}); - $template->param(city =>$accountinfo->{city}); - $template->param(postal_code => $accountinfo->{postal_code}); - $template->param(country => $accountinfo->{country}); - $template->param(province => $accountinfo->{province}); - $template->param(dialed_modify => $accountinfo->{dialed_modify}); - $template->param(pin => $accountinfo->{pin}); - $template->param(accountnum => $accountinfo->{number}); - $template->param(balance => $accountinfo->{balance}); - $template->param(maxchannels => $accountinfo->{maxchannels}); - $template->param(credit_limit => $accountinfo->{credit_limit}); - my @chargelist; + if ( $number ne "" ) { + $accountinfo = &get_account( $astpp_db, $number ); + } + elsif ( $params->{accountnum} ne "" ) { + $accountinfo = &get_account( $astpp_db, $params->{accountnum} ); + } + else { + $accountinfo = &get_account( $astpp_db, $params->{numberlist} ); + } + if ( $accountinfo->{number} ) { + $accountinfo->{balance} = + &accountbalance( $astpp_db, $accountinfo->{number} ); + $accountinfo->{balance} = + sprintf( "%.2f", $accountinfo->{balance} / 10000 ); + $template->param( first_name => $accountinfo->{first_name} ); + $template->param( middle_name => $accountinfo->{middle_name} ); + $template->param( last_name => $accountinfo->{last_name} ); + $template->param( company => $accountinfo->{company_name} ); + $template->param( telephone_1 => $accountinfo->{telephone_1} ); + $template->param( telephone_2 => $accountinfo->{telephone_2} ); + $template->param( fascimilie => $accountinfo->{fascimilie} ); + $template->param( address_1 => $accountinfo->{address_1} ); + $template->param( address_2 => $accountinfo->{address_2} ); + $template->param( address_3 => $accountinfo->{address_3} ); + $template->param( email => $accountinfo->{email} ); + $template->param( city => $accountinfo->{city} ); + $template->param( postal_code => $accountinfo->{postal_code} ); + $template->param( country => $accountinfo->{country} ); + $template->param( province => $accountinfo->{province} ); + $template->param( dialed_modify => $accountinfo->{dialed_modify} ); + $template->param( pin => $accountinfo->{pin} ); + $template->param( accountnum => $accountinfo->{number} ); + $template->param( balance => $accountinfo->{balance} ); + $template->param( maxchannels => $accountinfo->{maxchannels} ); + $template->param( credit_limit => $accountinfo->{credit_limit} ); + my @chargelist; my @account_charge_list = &list_account_charges( $astpp_db, $accountinfo->{number} ); my @pricelist_charge_list = &list_pricelist_charges( $astpp_db, $accountinfo->{pricelist} ); + foreach my $charge (@account_charge_list) { - my ( %row ); - $row{accountnum} = $accountinfo->{number}; + my (%row); + $row{accountnum} = $accountinfo->{number}; my $chargeinfo = &get_charge( $astpp_db, $charge->{charge_id} ); - $row{sweep} = $sweeplist{$chargeinfo->{Sweep}}; - $row{cost} = sprintf( "%.2f", $chargeinfo->{charge} / 10000 ); - $row{id} = $charge->{id}; + $row{sweep} = $sweeplist{ $chargeinfo->{Sweep} }; + $row{cost} = sprintf( "%.2f", $chargeinfo->{charge} / 10000 ); + $row{id} = $charge->{id}; $row{description} = $chargeinfo->{description}; - push(@chargelist, \%row); + push( @chargelist, \%row ); } foreach my $charge (@pricelist_charge_list) { - my ( %row ); - $row{accountnum} = $accountinfo->{number}; + my (%row); + $row{accountnum} = $accountinfo->{number}; my $chargeinfo = &get_charge( $astpp_db, $charge ); - $row{sweep} = $sweeplist{$chargeinfo->{Sweep}}; - $row{cost} = sprintf( "%.2f", $chargeinfo->{charge} / 10000 ); - $row{id} = $charge; + $row{sweep} = $sweeplist{ $chargeinfo->{Sweep} }; + $row{cost} = sprintf( "%.2f", $chargeinfo->{charge} / 10000 ); + $row{id} = $charge; $row{charge} = $chargeinfo->{description}; - push(@chargelist, \%row); + push( @chargelist, \%row ); } - $template->param( chargelist => \@chargelist); + $template->param( chargelist => \@chargelist ); my %applyablecharges = &list_applyable_charges($astpp_db); - $template->param( applyable_charges => popup_menu( - -name => "id_list", - -values => \%applyablecharges - )); + $template->param( + applyable_charges => popup_menu( + -name => "id_list", + -values => \%applyablecharges + ) + ); - my (@account_did_list,$sql,$pagination); + my ( @account_did_list, $sql, $pagination ); my @did_list = &list_dids_account( $astpp_db, $accountinfo->{number} ); foreach my $did_info (@did_list) { - my (%row); - $row{accountnum} = $accountinfo->{number}; - $row{cost} = sprintf( "%.2f", $did_info->{monthlycost} / 10000 ); + my (%row); + $row{accountnum} = $accountinfo->{number}; + $row{cost} = sprintf( "%.2f", $did_info->{monthlycost} / 10000 ); $row{number} = $did_info->{number}; - push(@account_did_list, \%row); + push( @account_did_list, \%row ); } - $template->param( account_did_list => \@account_did_list); + $template->param( account_did_list => \@account_did_list ); my @availabledids = &list_available_dids( $astpp_db, $accountinfo->{number} ); - $template->param( available_dids => - popup_menu( - -name => "did_list", - -values => \@availabledids - )); + $template->param( + available_dids => popup_menu( + -name => "did_list", + -values => \@availabledids + ) + ); my $tmp = "SELECT * FROM ani_map WHERE account = " . $astpp_db->quote( $accountinfo->{'number'} ) . " ORDER BY number"; $sql = $astpp_db->prepare($tmp); $sql->execute; - my @account_ani_list; + my @account_ani_list; + while ( my $record = $sql->fetchrow_hashref ) { - my (%row); - $row{accountnum} = $accountinfo->{number}; - $row{number} = $record->{number}; - $row{context} = $record->{context}; - push(@account_ani_list, \%row); + my (%row); + $row{accountnum} = $accountinfo->{number}; + $row{number} = $record->{number}; + $row{context} = $record->{context}; + push( @account_ani_list, \%row ); } - $template->param( account_ani_list => \@account_ani_list); + $template->param( account_ani_list => \@account_ani_list ); $tmp = "SELECT * FROM ip_map WHERE account = " @@ -1905,119 +2016,146 @@ . " ORDER BY ip"; $sql = $astpp_db->prepare($tmp); $sql->execute; - my @account_ip_list; + my @account_ip_list; while ( my $record = $sql->fetchrow_hashref ) { - my %row; - $row{accountnum} = $accountinfo->{number}; - $row{ip} = $record->{ip}; - $row{prefix} = $record->{prefix}; - $row{context} = $record->{context}; - push(@account_ip_list, \%row); + my %row; + $row{accountnum} = $accountinfo->{number}; + $row{ip} = $record->{ip}; + $row{prefix} = $record->{prefix}; + $row{context} = $record->{context}; + push( @account_ip_list, \%row ); } - $template->param( account_ip_list => \@account_ip_list); - $template->param( currency => $currency[0]); + $template->param( account_ip_list => \@account_ip_list ); + $template->param( currency => $currency[0] ); ## List the SIP/IAX2 devices belonging to this account. ## - my @account_device_list; - if ($rt_db) { - my @sip_names = &list_sip_account_rt($rt_db,$config,$accountinfo->{number}, $accountinfo->{cc}); - my @iax_names = &list_iax_account_rt($rt_db,$config,$accountinfo->{number}, $accountinfo->{cc}); - foreach my $name (@sip_names) { - my $deviceinfo = &get_sip_account_rt($rt_db,$config,$name); - my %row; - $row{tech} = "SIP"; - $row{type} = $deviceinfo->{type}; - $row{username} = $deviceinfo->{username}; - $row{secret} = $deviceinfo->{secret}; - $row{context} = $deviceinfo->{context}; - push(@account_device_list, \%row); - } - foreach my $name (@iax_names) { - my $deviceinfo = &get_iax_account_rt($rt_db,$config,$name); - my %row; - $row{tech} = "IAX2"; - $row{type} = $deviceinfo->{type}; - $row{username} = $deviceinfo->{username}; - $row{secret} = $deviceinfo->{secret}; - $row{context} = $deviceinfo->{context}; - push(@account_device_list, \%row); - } - } - if ($fs_db) { - my (@sip_devices); - @sip_devices = $ASTPP->fs_list_sip_usernames( cc => $accountinfo->{cc}, accountcode => $accountinfo->{number}); - foreach my $record (@sip_devices) { - print STDERR $record->{username}; - my $deviceinfo = &get_sip_account_freeswitch($fs_db,$config,$record->{id}); - my %row; - $row{tech} = "SIP"; - $row{type} = "user@" . $record->{domain}; - $row{username} = $record->{username}; - $row{secret} = $deviceinfo->{password}; - $row{context} = $deviceinfo->{context}; - push(@account_device_list, \%row); - } - } - if ($freepbx_db) { - my @sip_names = &list_sip_account_freepbx($freepbx_db,$config,$accountinfo->{number}, $accountinfo->{cc}); - my @iax_names = &list_iax_account_freepbx($freepbx_db,$config,$accountinfo->{number}, $accountinfo->{cc}); - foreach my $name (@sip_names) { - my $deviceinfo = &get_sip_account_freepbx($freepbx_db,$config,$name); - my %row; - $row{tech} = "SIP"; - $row{type} = $deviceinfo->{type}; - $row{username} = $deviceinfo->{username}; - $row{secret} = $deviceinfo->{secret}; - $row{context} = $deviceinfo->{context}; - push(@account_device_list, \%row); - } - foreach my $name (@iax_names) { - my $deviceinfo = &get_iax_account_freepbx($freepbx_db,$config,$name); - my %row; - $row{tech} = "IAX2"; - $row{type} = $deviceinfo->{type}; - $row{username} = $deviceinfo->{username}; - $row{secret} = $deviceinfo->{secret}; - $row{context} = $deviceinfo->{context}; - push(@account_device_list, \%row); - } - } - $template->param(account_device_list => \@account_device_list); + my @account_device_list; + if ($rt_db) { + my @sip_names = + &list_sip_account_rt( $rt_db, $config, $accountinfo->{number}, + $accountinfo->{cc} ); + my @iax_names = + &list_iax_account_rt( $rt_db, $config, $accountinfo->{number}, + $accountinfo->{cc} ); + foreach my $name (@sip_names) { + my $deviceinfo = &get_sip_account_rt( $rt_db, $config, $name ); + my %row; + $row{tech} = "SIP"; + $row{type} = $deviceinfo->{type}; + $row{username} = $deviceinfo->{username}; + $row{secret} = $deviceinfo->{secret}; + $row{contex... [truncated message content] |