[Astpp-commit] SF.net SVN: astpp:[2205] trunk
Brought to you by:
darrenkw
From: <dar...@us...> - 2008-11-11 22:57:57
|
Revision: 2205 http://astpp.svn.sourceforge.net/astpp/?rev=2205&view=rev Author: darrenkw Date: 2008-11-11 22:57:53 +0000 (Tue, 11 Nov 2008) Log Message: ----------- Added support to "deactivate" cdrs from the list_errors section. Modified Paths: -------------- trunk/astpp-admin.cgi trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/astpp-admin.cgi =================================================================== --- trunk/astpp-admin.cgi 2008-11-11 19:05:42 UTC (rev 2204) +++ trunk/astpp-admin.cgi 2008-11-11 22:57:53 UTC (rev 2205) @@ -3783,117 +3783,67 @@ sub build_list_errors() { my ( $results, $body, $status, $count, $pageno, $pagesrequired ); - $count = 0; $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot list errors until database is configured!") . "\n" unless $cdr_db; - if ( $params->{limit} < 1 ) { $params->{limit} = 0 } - my $results_per_page = $config->{results_per_page}; - if ( $results_per_page eq "" ) { $results_per_page = 25; } - my $sql = - $cdr_db->prepare( "SELECT * FROM cdr WHERE cost = 'error' OR " - . "accountcode IN (NULL,'') AND cost ='none'" ); - $sql->execute - || return gettext("Something is wrong with the cdr database!") . "\n"; - $results = $sql->rows; - $pagesrequired = ceil( $results / $results_per_page ); - print gettext("Pages Required:") . " $pagesrequired\n" - if ( $config->{debug} eq "YES" ); - $sql->finish; - $sql = - $cdr_db->prepare( " SELECT * FROM cdr WHERE cost = 'error' OR " - . "accountcode IN (NULL,'') AND cost ='none' ORDER BY calldate " - . "limit $params->{limit} , $results_per_page" ); - $sql->execute - || return gettext("Something is wrong with the cdr database!") . "\n"; - $body = - "<table class=\"viewcdrs\"><tr><td colspan=7>" - . start_form - . "</td></tr> -" - . "<tr class=\"header\"><td>" - . gettext("Date") - . "</td><td>" - . gettext("CallerID") . "</td>" . "<td>" - . gettext("Source") - . "</td><td>" - . gettext("Dest") . "</td>" . "<td>" - . gettext("Dest.Context") - . "</td><td>" - . gettext("Channel") . "</td>" . "<td>" - . gettext("Dest.Channel") - . "</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>" - . gettext("AccountCode") . "</td>" . "<td>" - . gettext("UniqueID") - . "</td><td>" - . gettext("UserField") . "</td>" . "<td>" - . gettext("Cost") - . "</td></tr> -\n"; + if ($params->{acount} eq "Deactivate..." || $params->{uniqueid}) { + $cdr_db->do("UPDATE cdr SET cost = 'dropped' AND vendor = 'dropped' WHERE uniqueid = " . $params->{uniqueid}); + } + $count = 0; + my $template = HTML::Template->new( + filename => '/var/lib/astpp/templates/list_errors.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); - while ( my $record = $sql->fetchrow_hashref ) { +my $sql_select = "SELECT * FROM cdr WHERE cost IN( 'error','rating') OR accountcode IN (NULL,'') AND cost ='none' ORDER BY calldate"; +my $sql_count = "SELECT COUNT(*) FROM cdr WHERE cost IN ( 'error','rating') OR accountcode IN (NULL,'') AND cost ='none'"; + + my ($sql, $pagination) = + $ASTPP->pagination( sql_select => $sql_select, + sql_count => $sql_count, + results_per_page=> $config->{results_per_page}, + ve => $params->{ve}, + te => $params->{ee}, + db => $cdr_db, + ); + + $ASTPP->debug( user=> $param->{username}, debug => $sql); + my $results = $cdr_db->prepare($sql); + + $results->execute; + + while ( my $record = $results->fetchrow_hashref ) { + $ASTPP->debug( user=> $param->{username}, debug => $record->{uniqueid}); + my %row; $count++; if ( $count % 2 == 0 ) { - $body .= "<tr class=\"rowtwo\">"; + %row->{class} = "rowtwo"; } else { - $body .= "<tr class=\"rowone\">"; + %row->{class} = "rowone"; } - $body .= -"<td>$record->{calldate}</td><td>$record->{clid}</td><td>$record->{src}</td>" - . "<td>$record->{dst}</td><td>$record->{dcontext}</td><td>$record->{channel}</td>" - . "<td>$record->{dstchannel}</td><td>$record->{lastapp}</td><td>$record->{lastdata}</td>" - . "<td>$record->{duration}</td><td>$record->{billsec}</td><td>$record->{disposition}</td>" - . "<td>$record->{amaflags}</td><td>$record->{accountcode}</td><td>$record->{uniqueid}</td>" - . "<td>$record->{userfield}</td><td>$record->{cost}</td></tr> -\n"; + %row->{uniqueid} = $record->{uniqueid}; + %row->{calldate} = $record->{calldate}; + %row->{clid} = $record->{clid}; + %row->{src} = $record->{src}; + %row->{dst} = $record->{dst}; + %row->{dcontext} = $record->{dcontext}; + %row->{channel} = $record->{channel}; + %row->{dstchannel} = $record->{dstchannel}; + %row->{lastapp} = $record->{lastpp}; + %row->{lastdata} = $record->{lastdata}; + %row->{duration} = $record->{duration}; + %row->{billsec} = $record->{billsec}; + %row->{disposition} = $record->{disposition}; + %row->{amaflags} = $record->{amaflags}; + %row->{accountcode} = $record->{acountcode}; + %row->{userfield} = $record->{userfield}; + %row->{cost} = $record->{cost}; + %row->{vendor} = $record->{vendor}; + push( @cdrlist,\%row); } - $body .= "</table> -"; - $sql->finish; - for ( my $i = 0 ; $i <= $pagesrequired - 1 ; $i++ ) { - if ( $i == 0 ) { - if ( $params->{limit} != 0 ) { - $body .= - "<a href=\"astpp-admin.cgi?mode=" - . gettext("List Errors") - . "&limit=0\">"; - $body .= $i + 1; - $body .= "</a>"; - } - else { - $body .= $i + 1; - } - } - if ( $i > 0 ) { - if ( $params->{limit} != ( $i * $results_per_page ) ) { - $body .= - "<a href=\"astpp-admin.cgi?mode=" - . gettext("List Errors") - . "&limit="; - $body .= ( $i * $results_per_page ); - $body .= "\">\n"; - $body .= $i + 1 . "</a>"; - } - else { - $pageno = $i + 1; - $body .= " |"; - } - } - } - $body .= ""; - $body .= gettext("Page") . " $pageno " . gettext("of") . " $pagesrequired"; - return $body; + $results->finish; + $template->param( cdrlist => \@cdrlist ); + $template->param( pagination => $pagination ); + return $template->output; } sub default_callback { Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2008-11-11 19:05:42 UTC (rev 2204) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2008-11-11 22:57:53 UTC (rev 2205) @@ -342,8 +342,10 @@ } sub pagination #Returns the pagination html code to assist with navigation. +#db = Database connection to use if w're not using the ASTPP database; { my ($self, %arg) = @_; + my $db; # We are using Data::Paginate for the real tough stuff. # Therefore we need to pass the Data::Paginate stuff # as well as the total number of pages. @@ -355,6 +357,11 @@ if (!$arg{results_per_page} || $arg{results_per_page} > 1 ) { $arg{results_per_page} = 25; } + if ($arg{db}) { + $db = $arg{db}; + } else { + $db = $self->{_astpp_db}; + } ## START PAGINATION CODE # set total_entries *once* then pass it around # in the object's links from then on for efficiency: @@ -365,7 +372,8 @@ ? Digest::MD5::md5_hex("unique_cypher-$total_entries-$arg{sql_check}") : ''; if ( !$total_entries || $verify ne $te_match ) { # its not ok so re-fetch - $sql = $self->{_astpp_db}->prepare($arg{sql_count}); +# $sql = $self->{_astpp_db}->prepare($arg{sql_count}); + $sql = $db->prepare($arg{sql_count}); $sql->execute; $record = $sql->fetchrow_hashref; $total_entries = $record->{"COUNT(*)"}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |