11<?php
22
3+ use App \Facades \LibrenmsConfig ;
34use App \Models \Bill ;
45use Illuminate \Support \Facades \Gate ;
56use LibreNMS \Billing ;
67use LibreNMS \Util \Html ;
78use LibreNMS \Util \Number ;
9+ use LibreNMS \Util \Url ;
810
911$ bill_id = (int ) ($ vars ['bill_id ' ] ?? 0 );
1012$ bill = Bill::find ($ bill_id );
5759 $ bill_color = '#0000cc ' ;
5860 }
5961
60- $ fromtext = dbFetchCell ("SELECT DATE_FORMAT( $ datefrom, ' " . \ App \ Facades \ LibrenmsConfig::get ('dateformat.mysql.date ' ) . "') " );
61- $ totext = dbFetchCell ("SELECT DATE_FORMAT( $ dateto, ' " . \ App \ Facades \ LibrenmsConfig::get ('dateformat.mysql.date ' ) . "') " );
62+ $ fromtext = dbFetchCell ("SELECT DATE_FORMAT( $ datefrom, ' " . LibrenmsConfig::get ('dateformat.mysql.date ' ) . "') " );
63+ $ totext = dbFetchCell ("SELECT DATE_FORMAT( $ dateto, ' " . LibrenmsConfig::get ('dateformat.mysql.date ' ) . "') " );
6264 $ unixfrom = dbFetchCell ("SELECT UNIX_TIMESTAMP(' $ datefrom') " );
6365 $ unixto = dbFetchCell ("SELECT UNIX_TIMESTAMP(' $ dateto') " );
6466
@@ -175,7 +177,7 @@ function print_port_list($ports)
175177 $ percent = Number::calculatePercent ($ total_data , $ bill_data ['bill_quota ' ]);
176178 $ unit = 'MB ' ;
177179 $ total_data = round ($ total_data , 2 );
178- $ type = ' & ave= yes ' ; ?>
180+ $ graph_type = [ ' ave ' => ' yes '] ; ?>
179181 <td>
180182 <?php echo Billing::formatBytes ($ total_data ) ?> of <?php echo Billing::formatBytes ($ bill_data ['bill_quota ' ]) . ' ( ' . $ percent . '%) ' ?>
181183 - Average rate <?php echo Number::formatSi ($ rate_average , 2 , 0 , 'bps ' ) ?>
@@ -194,7 +196,7 @@ function print_port_list($ports)
194196 $ cdr = $ bill_data ['bill_cdr ' ];
195197 $ rate_95th = round ($ rate_95th , 2 );
196198 $ percent = Number::calculatePercent ($ rate_95th , $ cdr );
197- $ type = ' & 95th= yes ' ; ?>
199+ $ graph_type = [ ' 95th ' => ' yes '] ; ?>
198200 <td>
199201 <?php echo Number::formatSi ($ rate_95th , 2 , 0 , '' ) . 'bps ' ?> of <?php echo Number::formatSi ($ cdr , 2 , 0 , '' ) . 'bps ( ' . $ percent . '%) ' ?> (95th%ile)
200202 </td>
@@ -222,65 +224,51 @@ function print_port_list($ports)
222224 $ yesterday = dbFetchCell ('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) ' );
223225 $ rightnow = date ('U ' );
224226
227+ $ graph_args = [
228+ 'id ' => $ bill_id ,
229+ 'width ' => 1190 ,
230+ 'height ' => 250 ,
231+ ];
232+ if (isset ($ graph_type )) {
233+ $ graph_args = array_merge ($ graph_args , $ graph_type );
234+ }
235+
225236 if ($ vars ['view ' ] == 'accurate ' ) {
226- $ bill_code = (string ) ($ _GET ['bill_code ' ] ?? '' );
227- $ bi = "<img src='billing-graph.php?bill_id= " . $ bill_id . '&bill_code= ' . htmlspecialchars ($ bill_code );
228- $ bi .= '&from= ' . $ unixfrom . '&to= ' . $ unixto ;
229- $ bi .= '&x=1190&y=250 ' ;
230- $ bi .= "$ type'> " ;
231-
232- $ li = "<img src='billing-graph.php?bill_id= " . $ bill_id . '&bill_code= ' . htmlspecialchars ($ bill_code );
233- $ li .= '&from= ' . $ unix_prev_from . '&to= ' . $ unix_prev_to ;
234- $ li .= '&x=1190&y=250 ' ;
235- $ li .= "$ type'> " ;
236-
237- $ di = "<img src='billing-graph.php?bill_id= " . $ bill_id . '&bill_code= ' . htmlspecialchars ($ bill_code );
238- $ di .= '&from= ' . \App \Facades \LibrenmsConfig::get ('time.day ' ) . '&to= ' . \App \Facades \LibrenmsConfig::get ('time.now ' );
239- $ di .= '&x=1190&y=250 ' ;
240- $ di .= "$ type'> " ;
241-
242- $ mi = "<img src='billing-graph.php?bill_id= " . $ bill_id . '&bill_code= ' . htmlspecialchars ($ bill_code );
243- $ mi .= '&from= ' . $ lastmonth . '&to= ' . $ rightnow ;
244- $ mi .= '&x=1190&y=250 ' ;
245- $ mi .= "$ type'> " ;
237+ $ graph_args ['type ' ] = 'bill_historicbits ' ;
238+ $ graph_args ['bill_code ' ] = (string ) ($ _GET ['bill_code ' ] ?? '' );
246239 } else {
247- $ bi = "<img src='graph.php?type=bill_bits&id= " . $ bill_id ;
248- $ bi .= '&from= ' . $ unixfrom . '&to= ' . $ unixto ;
249- $ bi .= '&width=1000&height=200&total=1&dir= ' . $ dir_95th . "'> " ;
250-
251- $ li = "<img src='graph.php?type=bill_bits&id= " . $ bill_id ;
252- $ li .= '&from= ' . $ unix_prev_from . '&to= ' . $ unix_prev_to ;
253- $ li .= '&width=1000&height=200&total=1&dir= ' . $ dir_95th . "'> " ;
254-
255- $ di = "<img src='graph.php?type=bill_bits&id= " . $ bill_id ;
256- $ di .= '&from= ' . \App \Facades \LibrenmsConfig::get ('time.day ' ) . '&to= ' . \App \Facades \LibrenmsConfig::get ('time.now ' );
257- $ di .= '&width=1000&height=200&total=1&dir= ' . $ dir_95th . "'> " ;
240+ $ graph_args ['type ' ] = 'bill_bits ' ;
241+ $ graph_args ['width ' ] = 1000 ;
242+ $ graph_args ['height ' ] = 200 ;
243+ $ graph_args ['total ' ] = 1 ;
244+ $ graph_args ['dir ' ] = $ dir_95th ;
245+ }
258246
259- $ mi = " <img src='graph.php?type=bill_bits&id= " . $ bill_id ;
260- $ mi .= ' & from= ' . $ lastmonth . ' &to= ' . $ rightnow ;
261- $ mi .= ' &width=1000&height=200&total=1&dir= ' . $ dir_95th . " '> " ;
262- } //end if
247+ $ bi = array_merge ( $ graph_args , [ ' from ' => $ unixfrom , ' to ' => $ unixto ]) ;
248+ $ li = array_merge ( $ graph_args , [ ' from ' => $ unix_prev_from , ' to ' => $ unix_prev_to ]) ;
249+ $ di = array_merge ( $ graph_args , [ ' from ' => LibrenmsConfig:: get ( ' time.day ' ), ' to ' => LibrenmsConfig:: get ( ' time.now ' )]) ;
250+ $ mi = array_merge ( $ graph_args , [ ' from ' => $ lastmonth , ' to ' => $ rightnow ]);
263251
264252 ?>
265253<div class="panel panel-default">
266254<div class="panel-heading">
267255 <h3 class="panel-title">Billing View</h3>
268256</div>
269- <?php echo $ bi ?>
257+ <?php echo Url:: graphTag ( $ bi) ?>
270258</div>
271259
272260<div class="panel panel-default">
273261<div class="panel-heading">
274262 <h3 class="panel-title">24 Hour View</h3>
275263</div>
276- <?php echo $ di ?>
264+ <?php echo Url:: graphTag ( $ di) ?>
277265</div>
278266
279267<div class="panel panel-default">
280268<div class="panel-heading">
281269 <h3 class="panel-title">Monthly View</h3>
282270</div>
283- <?php echo $ mi ?>
271+ <?php echo Url:: graphTag ( $ mi) ?>
284272</div>
285273 <?php
286274 } //end if
0 commit comments