2010-11-29 22:41:08 +00:00
< ? php defined ( 'SYSPATH' ) or die ( 'No direct access allowed.' );
/**
* This class provides the default template controller for rendering pages .
*
2012-12-10 21:48:30 +00:00
* @ package OSB
2010-11-29 22:41:08 +00:00
* @ category Controllers
* @ author Deon George
2013-03-19 22:35:19 +00:00
* @ copyright ( c ) 2009 - 2013 Open Source Billing
* @ license http :// dev . osbill . net / license . html
2010-11-29 22:41:08 +00:00
*/
2012-01-29 10:08:54 +00:00
class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
2013-04-04 22:42:29 +00:00
protected $auth_required = TRUE ;
// Our acccount object
protected $ao ;
2012-01-29 06:23:24 +00:00
public function __construct ( Request $request , Response $response ) {
if ( Config :: theme ())
2013-04-04 22:42:29 +00:00
$this -> template = 'theme/' . Config :: theme () . '/page' ;
2012-01-29 06:23:24 +00:00
return parent :: __construct ( $request , $response );
}
2011-09-29 07:13:32 +00:00
protected function _headimages () {
// This is where we should be able to change our country
// @todo To implement
2013-02-12 11:14:59 +00:00
$co = Config :: country ();
2011-09-29 07:13:32 +00:00
HeadImages :: add ( array (
'img' => sprintf ( 'img/country/%s.png' , strtolower ( $co -> two_code )),
'attrs' => array ( 'onclick' => " target='_blank'; " , 'title' => $co -> display ( 'name' ))
));
return HeadImages :: factory ();
}
2010-11-29 22:41:08 +00:00
protected function _left () {
if ( $this -> template -> left )
return $this -> template -> left ;
elseif ( Auth :: instance () -> logged_in ( NULL , get_class ( $this ) . '|' . __METHOD__ ))
return Controller_Tree :: js ();
}
protected function _right () {
2013-04-04 22:42:29 +00:00
return ( $this -> template -> right ) ? $this -> template -> right : '' ;
}
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 ()])))
throw new Kohana_Exception ( 'Class has no security defined :class, or no security configured for :method' , array ( ':class' => get_class ( $this ), ':method' => Request :: current () -> action ()));
$this -> ao = Auth :: instance () -> get_user ();
if ( ! is_null ( $this -> ao ) AND ( is_string ( $this -> ao ) OR ! $this -> ao -> loaded ()))
2013-04-18 08:17:33 +00:00
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 ));
2013-04-04 22:42:29 +00:00
}
parent :: before ();
2010-11-29 22:41:08 +00:00
}
2013-04-04 22:42:29 +00:00
public function after () {
$dc = Kohana :: $config -> load ( 'config' , 'user_default_method' );
$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
*/
protected function filter ( $o , $af , $sort = NULL , $afid = NULL ) {
$result = array ();
foreach ( $o as $x ) {
if ( ! is_null ( $afid ) AND isset ( $x -> $afid )) {
if (( is_array ( $af ) AND in_array ( $x -> $afid , $af )) OR ( $x -> $afid == $af ))
array_push ( $result , $x );
} elseif ( method_exists ( $x , 'list_reseller' )) {
if ( in_array ( $af , $x -> list_reseller ()))
array_push ( $result , $x );
}
}
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 ,
));
}
2010-11-29 22:41:08 +00:00
}
}
?>