Added Tasks to KH
This commit is contained in:
@@ -102,6 +102,7 @@ Kohana::$config->attach(new Config_File);
|
||||
Kohana::modules(array(
|
||||
'auth' => SMDPATH.'auth', // Basic authentication
|
||||
'cache' => SMDPATH.'cache', // Caching with multiple backends
|
||||
'cron' => SMDPATH.'cron', // Kohana Cron Module
|
||||
// 'codebench' => SMDPATH.'codebench', // Benchmarking tool
|
||||
'database' => SMDPATH.'database', // Database access
|
||||
// 'image' => SMDPATH.'image', // Image manipulation
|
||||
|
4
application/classes/block/sub.php
Normal file
4
application/classes/block/sub.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Block_Sub extends lnApp_Block_Sub {}
|
||||
?>
|
70
application/classes/controller/admin/welcome.php
Normal file
70
application/classes/controller/admin/welcome.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* OSB Admin Main home page
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Page/Home
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Admin_Welcome extends Controller_TemplateDefault {
|
||||
protected $auth_required = TRUE;
|
||||
public $secure_actions = array(
|
||||
'index'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_index() {
|
||||
$ao = ORM::factory('account',Auth::instance()->get_user()->id);
|
||||
$t = time();
|
||||
|
||||
// Show outstanding invoices
|
||||
$o = ORM::factory('invoice');
|
||||
|
||||
Block_Sub::add(array(
|
||||
'title'=>'Invoices Overdue',
|
||||
'body'=>Table::limit(
|
||||
$o->list_overdue($t),
|
||||
30,
|
||||
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
|
||||
'due()'),
|
||||
'position'=>1,
|
||||
'order'=>1,
|
||||
));
|
||||
|
||||
Block_Sub::add(array(
|
||||
'title'=>'Invoices Due',
|
||||
'body'=>Table::limit(
|
||||
$o->list_due($t),
|
||||
30,
|
||||
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
|
||||
'due()'),
|
||||
'position'=>2,
|
||||
'order'=>1,
|
||||
));
|
||||
|
||||
// Show un-applied payments
|
||||
$o = ORM::factory('payment');
|
||||
|
||||
Block_Sub::add(array(
|
||||
'title'=>'Unapplied Payments',
|
||||
'body'=>Table::limit(
|
||||
$o->list_unapplied(),
|
||||
30,
|
||||
array('ID'=>'id','Account'=>'account->name()','Total'=>'display("total_amt")','Balance'=>'balance(TRUE)'),
|
||||
'balance(TRUE)'),
|
||||
'position'=>3,
|
||||
'order'=>1,
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
|
||||
'subtitle'=>_('Administrator Overview'),
|
||||
'body'=>(string)Block_Sub::factory(),
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
21
application/classes/controller/lnapp/task.php
Normal file
21
application/classes/controller/lnapp/task.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the default controller for tasks.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Task
|
||||
* @category Abstract/Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class Controller_lnApp_Task extends Controller {
|
||||
public function before() {
|
||||
if (! Kohana::$is_cli)
|
||||
throw new Kohana_Exception('Cant run :method, it must be run by the CLI',array(':method'=>$this->request->action()));
|
||||
|
||||
parent::before();
|
||||
}
|
||||
}
|
||||
?>
|
4
application/classes/controller/task.php
Normal file
4
application/classes/controller/task.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Controller_Task extends Controller_lnApp_Task {}
|
||||
?>
|
@@ -14,7 +14,7 @@ class Controller_User_Welcome extends Controller_TemplateDefault {
|
||||
protected $auth_required = TRUE;
|
||||
|
||||
public function action_index() {
|
||||
$ao = ORM::factory('account',Auth::instance()->get_user()->id);
|
||||
$ao = ORM::factory('account',Auth::instance()->get_user()->id);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
|
||||
|
@@ -28,3 +28,4 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
|
||||
Request::factory()->redirect('welcome');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
95
application/classes/lnapp/block/sub.php
Normal file
95
application/classes/lnapp/block/sub.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is for rendering HTML sub body blocks.
|
||||
*
|
||||
* It will provide a header, body and footer.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @uses Style
|
||||
*/
|
||||
class lnApp_Block_Sub extends HTMLRender {
|
||||
protected static $_data = array();
|
||||
protected static $_spacer = '<table><tr class="spacer"><td> </td></tr></table>';
|
||||
protected static $_required_keys = array('body','position');
|
||||
|
||||
/**
|
||||
* Add a block to be rendered
|
||||
*
|
||||
* @param array Block attributes
|
||||
*/
|
||||
public static function add($block,$prepend=FALSE) {
|
||||
parent::add($block);
|
||||
|
||||
// Detect any style sheets.
|
||||
if (! empty($block['style']) && is_array($block['style']))
|
||||
foreach ($block['style'] as $data=>$media)
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>$data,
|
||||
'media'=>$media,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
*
|
||||
* @return Block
|
||||
*/
|
||||
public static function factory() {
|
||||
return new Block_Sub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this block
|
||||
*
|
||||
* @see HTMLRender::render()
|
||||
*/
|
||||
protected function render() {
|
||||
$output = '';
|
||||
$o = array();
|
||||
|
||||
$i = 0;
|
||||
$x = $y = 0;
|
||||
Sort::MAsort(static::$_data,'order,position,title,subtitle');
|
||||
foreach (static::$_data as $value) {
|
||||
$i = (! isset($value['order'])) ? $i+1 : $value['order'];
|
||||
|
||||
// Work out our dimentions
|
||||
if ($value['position'] > $y)
|
||||
$y = $value['position'];
|
||||
if ($i > $x)
|
||||
$x = $i;
|
||||
|
||||
// @todo Alert if a sub block has already been defined.
|
||||
$o[$i][$value['position']] = '<table class="subblock" border="0">';
|
||||
|
||||
if (! empty($value['title']))
|
||||
$o[$i][$value['position']] .= sprintf('<tr class="title"><td>%s</td></tr>',$value['title']);
|
||||
|
||||
if (! empty($value['subtitle']))
|
||||
$o[$i][$value['position']] .= sprintf('<tr class="subtitle"><td>%s</td></tr>',$value['subtitle']);
|
||||
|
||||
$o[$i][$value['position']] .= sprintf('<tr class="body"><td>%s</td></tr>',$value['body']);
|
||||
|
||||
if (! empty($value['footer']))
|
||||
$o[$i][$value['position']] .= sprintf('<tr class="footer"><td>%s</td></tr>',$value['footer']);
|
||||
|
||||
$o[$i][$value['position']] .= '</table>';
|
||||
}
|
||||
|
||||
// Render our output.
|
||||
$output .= '<table class="subblockhead">';
|
||||
foreach ($o as $k => $v)
|
||||
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',round(100/$y,0),implode('</td><td>',$v));
|
||||
$output .= '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -84,6 +84,20 @@ abstract class lnApp_Config extends Kohana_Config {
|
||||
return date(Kohana::config('config.date_format'),$date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a date using a site configured format
|
||||
*/
|
||||
public static function time($date) {
|
||||
return date(Kohana::config('config.time_format'),$date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a date using a site configured format
|
||||
*/
|
||||
public static function datetime($date) {
|
||||
return date(Kohana::config('config.date_format').' '.Kohana::config('config.time_format'),$date);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if our emails for the template should be sent to configured admin(s)
|
||||
*
|
||||
|
@@ -77,9 +77,7 @@ abstract class lnApp_HTMLRender {
|
||||
|
||||
// Display the exception message
|
||||
catch (Exception $e) {
|
||||
Kohana::exception_handler($e);
|
||||
|
||||
return '';
|
||||
Kohana_Exception::handler($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
63
application/classes/lnapp/table.php
Normal file
63
application/classes/lnapp/table.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is for rendering a table of data.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Page
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @uses Style
|
||||
*/
|
||||
class lnApp_Table {
|
||||
public static function limit($data,$rows,array $cols,$other) {
|
||||
if (! (array)$data)
|
||||
return '';
|
||||
|
||||
$output = '';
|
||||
|
||||
$other = $i = 0;
|
||||
$output = '<table border="0">';
|
||||
$output .= '<tr><th>'.implode('</th><th>',array_keys($cols)).'</th></tr>';
|
||||
foreach ($data as $do) {
|
||||
if ($i++ < $rows) {
|
||||
$output .= '<tr>';
|
||||
|
||||
foreach (array_values($cols) as $col) {
|
||||
if (is_array($do) AND isset($do[$col]))
|
||||
$x = $do[$col];
|
||||
// If the col is a method, we need to eval it
|
||||
elseif (preg_match('/\(/',$col))
|
||||
eval("\$x = \$do->$col;");
|
||||
else
|
||||
$x = $do->{$col};
|
||||
|
||||
$output .= sprintf('<td>%s</td>',$x);
|
||||
}
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
} else {
|
||||
if (is_array($do) AND isset($do[$col]))
|
||||
$x = $do[$col];
|
||||
// If the col is a method, we need to eval it
|
||||
elseif (preg_match('/\(/',$col))
|
||||
eval("\$x = \$do->$col;");
|
||||
else
|
||||
$x = $do->{$col};
|
||||
|
||||
$other += $x;
|
||||
}
|
||||
}
|
||||
|
||||
if ($other)
|
||||
$output .= sprintf('<tr><td>Other</td><td colspan="%s">(%s) %s</td></tr>',count($cols)-1,$i-$rows,$other);
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
4
application/classes/table.php
Normal file
4
application/classes/table.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
class Table extends lnApp_Table {}
|
||||
?>
|
@@ -13,6 +13,7 @@ return array(
|
||||
'cache_type' => 'file',
|
||||
'currency_format' => '2',
|
||||
'date_format' => 'd-M-Y',
|
||||
'time_format' => 'H:i:s',
|
||||
'email_admin_only'=> array(
|
||||
'adsl_traffic_notice'=>array('deon@c5t61p.leenooks.vpn'=>'Deon George'),
|
||||
),
|
||||
|
@@ -197,6 +197,21 @@ table.page tr.pagemain td.pagebody table.content table.block {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.page tr.pagemain td.pagebody table.content table.block td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
table.page tr.pagemain td.pagebody table.content table.subblockhead {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.page tr.pagemain td.pagebody table.content table.subblock {
|
||||
width: 100%;
|
||||
border: 1px solid #AAAACC;
|
||||
margin-right: auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.page tr.pagemain td.pagebody table.content tr.title {
|
||||
text-align: left;
|
||||
margin: 0px;
|
||||
|
@@ -1 +0,0 @@
|
||||
<!-- This template is shown via CLI tasks -->
|
||||
|
Reference in New Issue
Block a user