2013-10-10 02:44:53 +00:00
< ? php defined ( 'SYSPATH' ) or die ( 'No direct access allowed.' );
/**
* This class provides the default template controller for rendering pages .
*
* @ package OSB
* @ category Controllers
* @ author Deon George
* @ copyright ( c ) 2009 - 2013 Open Source Billing
* @ license http :// dev . osbill . net / license . html
*/
class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
protected $auth_required = TRUE ;
// Our acccount object
protected $ao ;
public function __construct ( Request $request , Response $response ) {
2013-04-26 01:42:09 +00:00
$this -> template = Config :: theme () . '/page' ;
2013-10-10 02:44:53 +00:00
return parent :: __construct ( $request , $response );
}
public function before () {
// If our action doesnt exist, no point processing any further.
if ( ! method_exists ( $this , 'action_' . Request :: current () -> action ()))
return ;
if ( $this -> auth_required ) {
if ( ! count ( $this -> secure_actions ) OR ( ! isset ( $this -> secure_actions [ Request :: current () -> action ()])))
2013-05-10 10:48:10 +00:00
throw HTTP_Exception :: factory ( 403 , 'Class has no security defined :class, or no security configured for :method' , array ( ':class' => get_class ( $this ), ':method' => Request :: current () -> action ()));
2013-10-10 02:44:53 +00:00
$this -> ao = Auth :: instance () -> get_user ();
if ( ! is_null ( $this -> ao ) AND ( is_string ( $this -> ao ) OR ! $this -> ao -> loaded ()))
throw HTTP_Exception :: factory ( 501 , 'Account doesnt exist :account ?' , array ( ':account' => ( is_string ( $this -> ao ) OR is_null ( $this -> ao )) ? $this -> ao : Auth :: instance () -> get_user () -> id ));
}
parent :: before ();
}
2013-05-10 10:48:10 +00:00
// @todo To rework
2013-10-10 02:44:53 +00:00
public function after () {
2013-05-10 10:48:10 +00:00
$dc = 'u/welcome/index' ;
2013-10-10 02:44:53 +00:00
$m = sprintf ( '%s/%s' , Request :: current () -> directory (), Request :: current () -> controller ());
BreadCrumb :: URL ( Request :: current () -> directory (), sprintf ( '%s/%s' , Request :: current () -> directory (), $dc ), FALSE );
BreadCrumb :: URL ( $m , method_exists ( $this , 'action_menu' ) ? $m . '/menu' : sprintf ( '%s/%s' , Request :: current () -> directory (), $dc ), FALSE );
parent :: after ();
}
/**
* This will filter a search query to only return those accounts for a reseller
2013-06-04 11:50:41 +00:00
*
* @ param $o Our ORM Object that we are searching on
* @ param $fl Our array of items that we must return
* @ param $flid The ID that must be in the $fl
* @ param $sort Sort the results
2013-10-10 02:44:53 +00:00
*/
2013-06-04 11:50:41 +00:00
protected function filter ( $o , array $fl , $flid , $sort = NULL ) {
2013-10-10 02:44:53 +00:00
$result = array ();
2013-05-10 10:48:10 +00:00
foreach ( $o as $x )
if ( ! is_null ( $flid ) AND isset ( $x -> $flid ) AND in_array ( $x -> $flid , $fl ))
array_push ( $result , $x );
2013-10-10 02:44:53 +00:00
if ( $sort )
Sort :: MAsort ( $result , $sort );
return $result ;
}
protected function setup ( array $config_items = array ()) {
$module = Request :: current () -> controller ();
if ( $_POST AND isset ( $_POST [ 'module_config' ][ $module ]))
Config :: instance () -> module_config ( $module , $_POST [ 'module_config' ][ $module ]) -> save ();
if ( $config_items ) {
$output = '' ;
$mc = Config :: instance () -> module_config ( $module );
$output .= Form :: open ();
$output .= View :: factory ( 'setup/admin/module/head' );
foreach ( $config_items as $k => $v )
$output .= View :: factory ( 'setup/admin/module/body' )
-> set ( 'module' , $module )
-> set ( 'mc' , $mc )
-> set ( 'key' , $k )
-> set ( 'info' , $v )
-> set ( 'val' , isset ( $mc [ $k ]) ? $mc [ $k ] : '' );
$output .= View :: factory ( 'setup/admin/module/foot' );
$output .= Form :: submit ( 'submit' , _ ( 'Submit' ), array ( 'class' => 'form_button' ));
$output .= Form :: close ();
Block :: add ( array (
'title' => sprintf ( '%s: %s' , strtoupper ( $module ), _ ( 'Configuration' )),
'body' => $output ,
));
}
}
}
?>