From 08eab4b5f9d9c1bb96960ebcd6a755ffe6f4af74 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 9 Dec 2011 15:10:53 +1100 Subject: [PATCH] Fixed breadcrumb, added submode() --- application/bootstrap.php | 2 +- .../classes/controller/admin/welcome.php | 3 +- .../controller/lnapp/templatedefault.php | 13 +++++++- application/classes/controller/lnapp/tree.php | 2 +- .../controller/templatedefault/user.php | 12 +++++++- .../classes/controller/user/welcome.php | 6 ++-- application/classes/controller/welcome.php | 6 ++++ application/classes/country.php | 4 +-- application/classes/lnapp/breadcrumb.php | 30 ++++++++++++++++--- application/classes/lnapp/config.php | 6 ++++ application/views/lnapp/default.php | 6 +--- .../classes/controller/hostserver.php | 4 --- .../classes/controller/user/invoice.php | 7 +++-- 13 files changed, 75 insertions(+), 26 deletions(-) diff --git a/application/bootstrap.php b/application/bootstrap.php index 9de4cbde..13df3f5e 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -141,7 +141,7 @@ Route::set('default/media', 'media(/)', array('file' => '.+')) * Set the routes. Each route must have a minimum of a name, a URI and a set of * defaults for the URI. */ -Route::set('default', '((/(/)))', array('id' => '[a-zA-Z0-9_.-]+')) +Route::set('default', '(/(/))', array('id' => '[a-zA-Z0-9_.-]+')) ->defaults(array( 'controller' => 'welcome', 'action' => 'index', diff --git a/application/classes/controller/admin/welcome.php b/application/classes/controller/admin/welcome.php index cc0d747e..50ea5440 100644 --- a/application/classes/controller/admin/welcome.php +++ b/application/classes/controller/admin/welcome.php @@ -10,8 +10,7 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Controller_Admin_Welcome extends Controller_TemplateDefault { - protected $auth_required = TRUE; +class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin { public $secure_actions = array( 'index'=>TRUE, ); diff --git a/application/classes/controller/lnapp/templatedefault.php b/application/classes/controller/lnapp/templatedefault.php index 1e401775..ea127494 100644 --- a/application/classes/controller/lnapp/templatedefault.php +++ b/application/classes/controller/lnapp/templatedefault.php @@ -39,9 +39,16 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { * @var array actions that require a valid user */ protected $secure_actions = array( - 'menu' => FALSE, ); + public function __construct(Request $request, Response $response) { + // Our Menu's can run without method authentication by default. + if (! isset($this->secure_actions['menu'])) + $this->secure_actions['menu'] = FALSE; + + return parent::__construct($request,$response); + } + /** * Check and see if this controller needs authentication * @@ -197,6 +204,10 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { // In case there any style sheets for this render. $this->response->bodyadd(Style::factory()); + // Since we are ajax, we should re-render the breadcrumb + Session::instance()->set('breadcrumb',(string)Breadcrumb::factory()); + $this->response->bodyadd(Script::add(array('type'=>'stdin','data'=>'$().ready($("#ajCONTROL").load("'.URL::site('welcome/breadcrumb').'",null,function(x,s,r) {}));'))); + // In case there any javascript for this render. $this->response->bodyadd(Script::factory()); diff --git a/application/classes/controller/lnapp/tree.php b/application/classes/controller/lnapp/tree.php index fb590970..0b6e0edb 100644 --- a/application/classes/controller/lnapp/tree.php +++ b/application/classes/controller/lnapp/tree.php @@ -101,7 +101,7 @@ $(function () { 'attr'=>array('id'=>sprintf('B_%s',$branch['id'])), 'state'=>$branch['state'], 'data'=>array('title'=>$branch['name']), - 'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']), + 'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('user/%s/menu',$branch['name'])) : $branch['attr_href']), ) ); } diff --git a/application/classes/controller/templatedefault/user.php b/application/classes/controller/templatedefault/user.php index da25c72d..186b7e0d 100644 --- a/application/classes/controller/templatedefault/user.php +++ b/application/classes/controller/templatedefault/user.php @@ -22,9 +22,19 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault { parent::before(); - $this->ao = ORM::factory('account',Auth::instance()->get_user()->id); + $this->ao = Auth::instance()->get_user(); if (! $this->ao->loaded()) throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id)); } + + public function after() { + $dc = 'welcome/index'; + $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(); + } } ?> diff --git a/application/classes/controller/user/welcome.php b/application/classes/controller/user/welcome.php index 635a7e8f..959f46f0 100644 --- a/application/classes/controller/user/welcome.php +++ b/application/classes/controller/user/welcome.php @@ -10,8 +10,10 @@ * @copyright (c) 2010 Deon George * @license http://dev.leenooks.net/license.html */ -class Controller_User_Welcome extends Controller_TemplateDefault { - protected $auth_required = TRUE; +class Controller_User_Welcome extends Controller_TemplateDefault_User { + protected $secure_actions = array( + 'index'=>FALSE, + ); public function action_index() { $ao = ORM::factory('account',Auth::instance()->get_user()->id); diff --git a/application/classes/controller/welcome.php b/application/classes/controller/welcome.php index 64c32420..2a037616 100644 --- a/application/classes/controller/welcome.php +++ b/application/classes/controller/welcome.php @@ -37,5 +37,11 @@ class Controller_Welcome extends Controller_TemplateDefault { )); } } + + public function action_breadcrumb() { + $this->auto_render = FALSE; + + $this->response->body(Session::instance()->get_once('breadcrumb')); + } } ?> diff --git a/application/classes/country.php b/application/classes/country.php index 8c44c210..6bb86c6e 100644 --- a/application/classes/country.php +++ b/application/classes/country.php @@ -14,8 +14,8 @@ class Country { public static function icon($cid) { // @todo alt character should be country specific // @todo This doesnt correctly get the right 3 character country code - it should be obtained from a join with country/currency - return HTML::image(sprintf('media/img/country/%s.gif',StaticList_Module::record('country','two_code','id',$cid)),array('alt'=>'$','style'=>'border: 0px;')); - return sprintf('media/img/country/%s.gif',StaticList_Module::record('country','three_code','id',$cid)); + return HTML::image(sprintf('media/img/country/%s.png',strtolower(StaticList_Module::record('country','two_code','id',$cid))),array('alt'=>'$','style'=>'border: 0px;')); + return sprintf('media/img/country/%s.png',strtolower(StaticList_Module::record('country','three_code','id',$cid))); } } ?> diff --git a/application/classes/lnapp/breadcrumb.php b/application/classes/lnapp/breadcrumb.php index 04125f57..4379acc6 100644 --- a/application/classes/lnapp/breadcrumb.php +++ b/application/classes/lnapp/breadcrumb.php @@ -23,17 +23,32 @@ class lnApp_Breadcrumb extends HTMLRender { public static function set($path) { if (is_string($path)) static::$_data['path'] = explode('/',$path); - else + elseif (is_array($path)) static::$_data['path'] = $path; + else + throw new Kohana_Exception('Path is not a string, nor an array'); } /** * Enable a friendly name to be used for a path */ - public static function name($path,$name) { + public static function name($path,$name,$override=TRUE) { + if (isset(static::$_data['name'][$path]) AND ! $override) + return; + static::$_data['name'][$path] = $name; } + /** + * Enable specifying the URL for a path + */ + public static function URL($path,$url,$override=TRUE) { + if (isset(static::$_data['url'][$path]) AND ! $override) + return; + + static::$_data['url'][$path] = $url; + } + /** * Return an instance of this class * @@ -47,7 +62,9 @@ class lnApp_Breadcrumb extends HTMLRender { * Render this Breadcrumb */ protected function render() { - $output = HTML::anchor('/',_('Home')); + // @todo Make this into a view + $output = '
'; + $output .= HTML::anchor('/',_('Home')); $data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path']; @@ -55,9 +72,14 @@ class lnApp_Breadcrumb extends HTMLRender { $output .= static::$_spacer; $p = join('/',array_slice($data,0,$k+1)); - $output .= HTML::anchor($p,empty(static::$_data['name'][$p]) ? ucfirst($v) : static::$_data['name'][$p]); + $output .= HTML::anchor( + (empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]), + (empty(static::$_data['name'][$p]) ? ucfirst($v) : static::$_data['name'][$p]) + ); } + $output .= '
'; + return $output; } } diff --git a/application/classes/lnapp/config.php b/application/classes/lnapp/config.php index e91d7bff..bb026d13 100644 --- a/application/classes/lnapp/config.php +++ b/application/classes/lnapp/config.php @@ -62,6 +62,12 @@ abstract class lnApp_Config extends Kohana_Config { return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()]; } + public static function submode() { + $submode = Kohana::Config('config.debug.submode'); + + return (isset($submode[Request::$client_ip])) ? $submode[Request::$client_ip] : FALSE; + } + public static function sitename() { return Config::instance()->loadsite()->so->site_name; } diff --git a/application/views/lnapp/default.php b/application/views/lnapp/default.php index 44032b81..30509d16 100644 --- a/application/views/lnapp/default.php +++ b/application/views/lnapp/default.php @@ -32,11 +32,7 @@
- - - - -
+
diff --git a/modules/host_server/classes/controller/hostserver.php b/modules/host_server/classes/controller/hostserver.php index bb84adf0..c7989207 100644 --- a/modules/host_server/classes/controller/hostserver.php +++ b/modules/host_server/classes/controller/hostserver.php @@ -10,10 +10,6 @@ * @license http://dev.leenooks.net/license.html */ class Controller_HostServer extends Controller { -// protected $_control = array( -// array('Product Categories'=>'product_category'), -// ); - public function action_plesk_addclienttest($id) { $ao = ORM::factory('account',$id); diff --git a/modules/invoice/classes/controller/user/invoice.php b/modules/invoice/classes/controller/user/invoice.php index 6a6796fc..e2c4ed49 100644 --- a/modules/invoice/classes/controller/user/invoice.php +++ b/modules/invoice/classes/controller/user/invoice.php @@ -28,10 +28,11 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User { 25, array( 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), - 'date_orig'=>array('label'=>'Date'), - 'total_amt'=>array('label'=>'Total','class'=>'right'), + 'date_orig'=>array('label'=>'Date Issued'), + 'due_date'=>array('label'=>'Date Due'), + 'total(TRUE)'=>array('label'=>'Total','class'=>'right'), 'credit_amt'=>array('label'=>'Credits','class'=>'right'), - 'billed_amt'=>array('label'=>'Payments','class'=>'right'), + 'payments_total(TRUE)'=>array('label'=>'Payments','class'=>'right'), 'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'), ), array(