2013-10-11 04:02:56 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides Admin ADSL functions
|
|
|
|
*
|
|
|
|
* @package ADSL
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Admin_Adsl extends Controller_Adsl {
|
|
|
|
protected $secure_actions = array(
|
|
|
|
'index'=>TRUE,
|
2013-11-14 11:50:35 +00:00
|
|
|
'edit'=>TRUE,
|
|
|
|
'list'=>TRUE,
|
2013-11-15 10:05:22 +00:00
|
|
|
'stat'=>TRUE,
|
2013-10-11 04:02:56 +00:00
|
|
|
'traffic'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
public function action_index() {
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$output .= Form::open(URL::link('admin','adsl/traffic'));
|
|
|
|
$output .= Form::select('sid',ORM::factory('ADSL_Supplier')->list_select());
|
|
|
|
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
|
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title('Select ADSL Supplier')
|
|
|
|
->title_icon('icon-share')
|
|
|
|
->body($output);
|
|
|
|
}
|
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
public function action_list() {
|
2016-07-29 01:19:30 +00:00
|
|
|
$this->meta->title = 'ADSL Plans';
|
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
Block::factory()
|
|
|
|
->title('ADSL Plans')
|
|
|
|
->title_icon('icon-th-list')
|
|
|
|
->body(Table::factory()
|
|
|
|
->data(ORM::factory('Product_Plugin_Adsl')->find_all())
|
|
|
|
->jssort('adsl')
|
|
|
|
->columns(array(
|
|
|
|
'id'=>'ID',
|
2013-11-15 05:25:45 +00:00
|
|
|
'supplier_plan->name()'=>'Plan',
|
|
|
|
'supplier_plan->display("status")'=>'Avail',
|
2013-11-14 11:50:35 +00:00
|
|
|
'base_down_peak'=>'PD',
|
|
|
|
'base_down_offpeak'=>'OPD',
|
|
|
|
'base_up_peak'=>'PU',
|
|
|
|
'base_up_offpeak'=>'OPU',
|
|
|
|
'extra_charged'=>'$',
|
|
|
|
'extra_down_peak'=>'EPD',
|
|
|
|
'extra_down_offpeak'=>'EOPD',
|
|
|
|
'extra_up_peak'=>'EPU',
|
|
|
|
'extra_up_offpeak'=>'EOPU',
|
|
|
|
'contract_term'=>'Cont',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('admin','adsl/edit/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_edit() {
|
|
|
|
$apo = ORM::factory('Product_Plugin_Adsl',$this->request->param('id'));
|
2016-07-29 01:19:30 +00:00
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if (! $apo->loaded())
|
2016-07-29 01:19:30 +00:00
|
|
|
throw HTTP_Exception::factory(403,'Plan either doesnt exist, or you are not authorised to see it');
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
$this->meta->title = 'ADSL Plan: '.$apo->name();
|
2016-07-29 01:19:30 +00:00
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
$test_result = array();
|
|
|
|
|
|
|
|
if (! $apo->loaded())
|
|
|
|
HTTP::redirect(URL::link('admin','adsl/list'));
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post()) {
|
|
|
|
if ($apo->values($this->request->post())->changed() AND (! $this->save($apo)))
|
2013-11-22 04:36:50 +00:00
|
|
|
$apo->reload();
|
2013-11-14 11:50:35 +00:00
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post('test')) {
|
|
|
|
$charge = $this->request->post('test.charge');
|
|
|
|
$test_result = $apo->allowance($this->request->post('test'),FALSE,$charge,TRUE);
|
2013-11-14 11:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title('Update ADSL Plan')
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body(View::factory('adsl/admin/edit')
|
|
|
|
->set('test_result',$test_result)
|
|
|
|
->set('o',$apo));
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title('Products Using this Plan')
|
|
|
|
->title_icon('icon-th-list')
|
|
|
|
->body(Table::factory()
|
|
|
|
->jssort('traffic')
|
2013-11-28 06:41:34 +00:00
|
|
|
->data($apo->products())
|
2013-11-14 11:50:35 +00:00
|
|
|
->columns(array(
|
|
|
|
'id'=>'ID',
|
|
|
|
'title()'=>'Name',
|
|
|
|
'status'=>'Active',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('admin','product/edit/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-11-15 10:05:22 +00:00
|
|
|
/**
|
|
|
|
* Usage statistics for the previous moth
|
|
|
|
*/
|
|
|
|
public function action_stat() {
|
2016-07-29 01:19:30 +00:00
|
|
|
$this->meta->title = 'ADSL Stats';
|
|
|
|
|
2013-11-15 10:05:22 +00:00
|
|
|
// @todo This needs to be configurable.
|
2013-11-18 04:18:50 +00:00
|
|
|
$traffic = array(1,2,5,10,25,50,75,100,150,200);
|
2013-11-15 10:05:22 +00:00
|
|
|
|
|
|
|
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
|
|
|
|
$stats = array();
|
|
|
|
$output = '';
|
|
|
|
$ts = 0;
|
|
|
|
|
|
|
|
foreach ($svs as $a=>$so) {
|
|
|
|
// Number of services
|
|
|
|
if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['c']))
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['c'] = 0;
|
|
|
|
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['c']++;
|
|
|
|
$ts++;
|
|
|
|
|
|
|
|
$a = 0;
|
|
|
|
foreach (array_reverse($traffic) as $i) {
|
2013-12-31 06:18:49 +00:00
|
|
|
if ($i < $so->plugin()->traffic_month(strtotime('first day of last month'),TRUE))
|
2013-11-15 10:05:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
$a = $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['d'][$a]))
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['d'][$a] = 0;
|
|
|
|
|
|
|
|
$stats[$so->product->plugin()->supplier_plan->speed]['d'][$a]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title('ADSL Traffic Summary Stats - Last Month')
|
|
|
|
->title_icon('icon-list')
|
|
|
|
->body(
|
|
|
|
View::factory('adsl/admin/stats')
|
|
|
|
->set('stats',$stats)
|
|
|
|
->set('traffic',$traffic)
|
|
|
|
->set('ts',$ts)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-10-11 04:02:56 +00:00
|
|
|
/**
|
|
|
|
* Reconcile billing for an ADSL supplier
|
|
|
|
*/
|
|
|
|
public function action_traffic() {
|
2016-08-03 06:20:25 +00:00
|
|
|
if (! $this->request->post('sid'))
|
2013-10-11 04:02:56 +00:00
|
|
|
HTTP::redirect(URL::link('admin','adsl/index'));
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
$aso = ORM::factory('ADSL_Supplier',$this->request->post('sid'));
|
2013-10-11 04:02:56 +00:00
|
|
|
if (! $aso->loaded())
|
|
|
|
HTTP::redirect(URL::link('admin','adsl/index'));
|
|
|
|
|
|
|
|
$t = ORM::factory('Service_Plugin_Adsl_Traffic');
|
|
|
|
$date = date('Y-m-d',time()-86400);
|
|
|
|
|
|
|
|
Block::factory()
|
|
|
|
->title(sprintf('ADSL Traffic for %s',$date))
|
|
|
|
->title_icon('icon-th-list')
|
|
|
|
->body(Table::factory()
|
|
|
|
->jssort('traffic')
|
|
|
|
->data($aso->traffic->where('date','=',$date)->find_all())
|
|
|
|
->columns(array(
|
|
|
|
'service'=>'Service Login',
|
|
|
|
'plan->service->id'=>'Service',
|
|
|
|
'plan->service_number'=>'Service',
|
2013-11-08 11:02:32 +00:00
|
|
|
'plan->service->status'=>'Active',
|
2013-10-11 04:02:56 +00:00
|
|
|
'up_peak'=>'Up Peak',
|
|
|
|
'down_peak'=>'Down Peak',
|
|
|
|
'up_offpeak'=>'Up OffPeak',
|
|
|
|
'down_offpeak'=>'Down OffPeak',
|
|
|
|
'peer'=>'Peer',
|
|
|
|
'internal'=>'Internal',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'plan->service->id'=>array('url'=>URL::link('user','service/view/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|