diff --git a/modules/adsl/views/service/admin/adslstat/body_data.php b/modules/adsl/views/service/admin/adslstat/body_data.php new file mode 100644 index 00000000..41a521c9 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/body_data.php @@ -0,0 +1 @@ + diff --git a/modules/adsl/views/service/admin/adslstat/body_end.php b/modules/adsl/views/service/admin/adslstat/body_end.php new file mode 100644 index 00000000..23019526 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/body_end.php @@ -0,0 +1 @@ + diff --git a/modules/adsl/views/service/admin/adslstat/body_head.php b/modules/adsl/views/service/admin/adslstat/body_head.php new file mode 100644 index 00000000..a36ffa79 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/body_head.php @@ -0,0 +1,4 @@ + + + + diff --git a/modules/adsl/views/service/admin/adslstat/foot.php b/modules/adsl/views/service/admin/adslstat/foot.php new file mode 100644 index 00000000..000ca4b0 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/foot.php @@ -0,0 +1 @@ + diff --git a/modules/adsl/views/service/admin/adslstat/head.php b/modules/adsl/views/service/admin/adslstat/head.php new file mode 100644 index 00000000..baa32e3b --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/head.php @@ -0,0 +1,3 @@ + + + diff --git a/modules/adsl/views/service/admin/adslstat/head_data.php b/modules/adsl/views/service/admin/adslstat/head_data.php new file mode 100644 index 00000000..96181072 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/head_data.php @@ -0,0 +1 @@ + diff --git a/modules/adsl/views/service/admin/adslstat/head_end.php b/modules/adsl/views/service/admin/adslstat/head_end.php new file mode 100644 index 00000000..23019526 --- /dev/null +++ b/modules/adsl/views/service/admin/adslstat/head_end.php @@ -0,0 +1 @@ + diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php index 1578ece0..5185585c 100644 --- a/modules/service/classes/controller/admin/service.php +++ b/modules/service/classes/controller/admin/service.php @@ -13,6 +13,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { protected $secure_actions = array( 'autolist'=>FALSE, // @todo To Change + 'adslstat'=>TRUE, 'list'=>TRUE, 'listbycheckout'=>TRUE, 'listadslbilling'=>TRUE, @@ -680,7 +681,76 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { 'title'=>sprintf('%s: %s',$so->id(),$so->service_name()), 'body'=>$output, )); + } + public function action_adslstat() { + $output = ''; + $svs = ORM::factory('service')->list_bylistgroup('ADSL'); + $stats = array(); + // @todo This needs to be configurable. + $traffic = array(1000,2000,5000,10000,25000,50000,75000,100000); + $ts = 0; + + foreach ($svs as $a=>$so) { + // Number of services + if (! isset($stats[$so->product->plugin()->speed]['c'])) + $stats[$so->product->plugin()->speed]['c'] = 0; + + $stats[$so->product->plugin()->speed]['c']++; + $ts++; + + // Amount of traffic + $t = array_sum($so->plugin()->traffic_lastmonth(FALSE)); + $a = 0; + foreach (array_reverse($traffic) as $i) { + if ($i < $t) + break; + $a = $i; + } + + if (! isset($stats[$so->product->plugin()->speed]['d'][$a])) + $stats[$so->product->plugin()->speed]['d'][$a] = 0; + + $stats[$so->product->plugin()->speed]['d'][$a]++; + } + + if (count($stats)) { + $output .= View::factory($this->viewpath().'/head') + ->set('name','SPEED'); + $output .= View::factory($this->viewpath().'/head_data') + ->set('name','#'); + foreach ($traffic as $i) + $output .= View::factory($this->viewpath().'/head_data') + ->set('name',$i); + $output .= View::factory($this->viewpath().'/head_data') + ->set('name','Other'); + $output .= View::factory($this->viewpath().'/head_end'); + + foreach ($stats as $speed => $details) { + $output .= View::factory($this->viewpath().'/body_head') + ->set('count',$details['c']) + ->set('percent',sprintf('%2.1f',$details['c']/$ts*100)) + ->set('speed',$speed); + + foreach ($traffic as $i) { + $output .= View::factory($this->viewpath().'/body_data') + ->set('count',$c=isset($details['d'][$i]) ? $details['d'][$i] : 0) + ->set('percent',sprintf('%2.1f',$c/$details['c']*100)); + } + + $output .= View::factory($this->viewpath().'/body_data') + ->set('count',$c=isset($details['d'][0]) ? $details['d'][0] : 0) + ->set('percent',sprintf('%2.1f',$c/$details['c']*100)); + $output .= View::factory($this->viewpath().'/body_end'); + } + + $output .= View::factory($this->viewpath().'/foot'); + } + + Block::add(array( + 'title'=>_('ADSL Traffic Summary Stats - Last Month'), + 'body'=>$output, + )); } } ?>
%