Work on Email and other major consistency work

This commit is contained in:
Deon George 2013-11-22 15:36:50 +11:00
parent 89deb9c97b
commit c18d5a3881
55 changed files with 550 additions and 575 deletions

View File

@ -29,14 +29,9 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
$mmo->module_id = $mo->id; $mmo->module_id = $mo->id;
$mmo->values($_POST); $mmo->values($_POST);
if (! $mmo->check() OR ! $mmo->save()) if (! $this->save($mmo))
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST))); throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
SystemMessage::factory()
->title('Record added')
->type('success')
->body(_('Method record has been added.'));
HTTP::redirect(URL::link('admin','module/edit/'.$mo->id)); HTTP::redirect(URL::link('admin','module/edit/'.$mo->id));
} }
@ -69,7 +64,7 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
if ($_POST) { if ($_POST) {
$mmo->values($_POST); $mmo->values($_POST);
if (! $mmo->check() OR ! $mmo->save()) if (! $this->save($mmo))
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST))); throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
foreach (ORM::factory('Group')->find_all() as $go) { foreach (ORM::factory('Group')->find_all() as $go) {
@ -91,7 +86,7 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
'group_id'=>$go->id, 'group_id'=>$go->id,
)); ));
if (! $gmo->check() OR ! $gmo->save()) if (! $this->save($gmo))
SystemMessage::factory() SystemMessage::factory()
->title(_('Unable to SAVE Group Method')) ->title(_('Unable to SAVE Group Method'))
->type('error') ->type('error')

View File

@ -20,16 +20,8 @@ class Controller_Admin_Setup extends Controller_TemplateDefault {
public function action_edit() { public function action_edit() {
$o = Company::instance()->so(); $o = Company::instance()->so();
// Store our new values if ($_POST AND $o->values($_POST)->changed() AND (! $this->save($o)))
$o->values($_POST); $o->reload();
// Run validation and save
if ($o->changed())
if ($o->check() AND $o->save())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your setup record has been updated.'));
Block::factory() Block::factory()
->title('Update Site Configuration') ->title('Update Site Configuration')

View File

@ -0,0 +1,22 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Admin Main home page
*
* @package OSB
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Welcome extends Controller_Welcome {
protected $auth_required = TRUE;
public $secure_actions = array(
'index'=>TRUE,
);
public function action_index() {
HTTP::redirect(URL::link('reseller','welcome'));
}
}
?>

View File

@ -50,17 +50,29 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau
parent::after(); parent::after();
} }
protected function save(Model $o) {
try {
$o->save();
return $o->saved();
} catch (ORM_Validation_Exception $e) {
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->body(join('<br/>',array_values($e->errors('models'))));
return FALSE;
}
}
protected function setup(array $config_items=array()) { protected function setup(array $config_items=array()) {
$mo = ORM::factory('Module',array('name'=>Request::current()->controller())); $mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
if (! $mo->loaded()) if (! $mo->loaded())
throw HTTP_Exception::factory(501,'Unknown module :module',array(':module'=>Request::current()->controller())); throw HTTP_Exception::factory(501,'Unknown module :module',array(':module'=>Request::current()->controller()));
if ($_POST AND isset($_POST['module_config'][$mo->id])) if ($_POST AND isset($_POST['module_config'][$mo->id]))
if (Config::instance()->module_config($mo->name,$_POST['module_config'][$mo->id])->save()) Config::instance()->module_config($mo->name,$_POST['module_config'][$mo->id])->save();
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your setup record has been updated.'));
if ($config_items) { if ($config_items) {
Block::factory() Block::factory()
@ -68,7 +80,6 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau
->title_icon('icon-wrench') ->title_icon('icon-wrench')
->type('form-horizontal') ->type('form-horizontal')
->body(View::factory('setup/admin/module')->set('o',Company::instance()->so())->set('mid',$mo->id)); ->body(View::factory('setup/admin/module')->set('o',Company::instance()->so())->set('mid',$mo->id));
} }
} }
} }

View File

@ -19,34 +19,8 @@ class Controller_User_Account extends Controller_Account {
* Enable User to Edit their Account Details * Enable User to Edit their Account Details
*/ */
public function action_edit() { public function action_edit() {
// Store our new values if ($_POST AND $this->ao->values($_POST)->changed() AND (! $this->save($this->ao)))
$this->ao->values($_POST); $this->ao->reload();
// Run validation and save
if ($this->ao->changed())
if ($this->ao->check()) {
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your account record has been updated.'));
$this->ao->save();
} else {
$output = '';
// @todo Need to check that this still works with the new bootstrap theming
foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
if ($output)
$output = sprintf('<ul>%s</ul>',$output);
SystemMessage::factory()
->title(_('Record NOT updated'))
->type('error')
->body(_('Your updates didnt pass validation.').'<br/>'.$output);
}
Block::factory() Block::factory()
->title(sprintf('Account: %s',$this->ao->accnum())) ->title(sprintf('Account: %s',$this->ao->accnum()))

View File

@ -40,6 +40,8 @@ class Model_Account extends Model_Auth_UserDefault {
), ),
); );
protected $_save_message = TRUE;
/** /**
* Our account number format * Our account number format
*/ */

View File

@ -22,8 +22,18 @@ class Model_Setup extends ORM_OSB {
'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'),
); );
protected $_save_message = TRUE;
// Validation rules
public function rules() { public function rules() {
$r = parent::rules(); $r = Arr::merge(parent::rules(), array(
'url' => array(
array('not_empty'),
array('min_length', array(':value', 8)),
array('max_length', array(':value', 127)),
array('url'),
),
));
// This module doesnt use site_id. // This module doesnt use site_id.
unset($r['site_id']); unset($r['site_id']);

View File

@ -22,6 +22,9 @@ abstract class ORM extends Kohana_ORM {
// Tables that do not have a site_id column // Tables that do not have a site_id column
public static $no_site_id_tables = array('setup','country','currency','language','tax'); public static $no_site_id_tables = array('setup','country','currency','language','tax');
// Whether to show a SystemMessage when a record is saved.
protected $_save_message = FALSE;
/** /**
* Add our OSB site_id to each SELECT query * Add our OSB site_id to each SELECT query
* @see parent::__build() * @see parent::__build()
@ -215,6 +218,18 @@ abstract class ORM extends Kohana_ORM {
return $x; return $x;
} }
public function save(Validation $validation=NULL) {
parent::save();
if ($this->saved() AND $this->_save_message)
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Record %s:%s Updated',$this->_table_name,$this->id));
return $this;
}
public function where_active() { public function where_active() {
return $this->_where_active(); return $this->_where_active();
} }

View File

@ -202,7 +202,7 @@ abstract class ORM_OSB extends ORM {
return ORM::factory('Module',array('name'=>$this->_table_name)); return ORM::factory('Module',array('name'=>$this->_table_name));
} }
public function save(Validation $validation = NULL) { public function save(Validation $validation=NULL) {
// Find any fields that have changed, and process them. // Find any fields that have changed, and process them.
if ($this->_changed) if ($this->_changed)
foreach ($this->_changed as $c) { foreach ($this->_changed as $c) {
@ -218,6 +218,10 @@ abstract class ORM_OSB extends ORM {
} elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) { } elseif (is_array($this->_object[$c]) AND in_array($c,$this->_serialize_column)) {
$this->_object[$c] = serialize($this->_object[$c]); $this->_object[$c] = serialize($this->_object[$c]);
} }
// Test if the value has still changed
if ($this->_original_values AND $this->_object[$c] == $this->_original_values[$c])
unset($this->_changed[$c]);
} }
return parent::save($validation); return parent::save($validation);

View File

@ -18,14 +18,10 @@
echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css'); echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css');
echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css'); echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css');
echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css'); echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css');
// @todo Work out how to delay this loading until required
echo HTML::style('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.css');
} else { } else {
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css'); echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap.min.css');
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css'); echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css');
echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css'); echo HTML::style($meta->secure().'netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css');
// @todo Work out how to delay this loading until required
echo HTML::style($meta->secure().'cdn.jsdelivr.net/bootstrap.wysihtml5/0.0.2/bootstrap-wysihtml5-0.0.2.css');
} }
echo HTML::style($meta->secure().'fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800'); echo HTML::style($meta->secure().'fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800');
@ -73,7 +69,7 @@
</li> </li>
<?php if (($ao = Auth::instance()->get_user()) AND $ao->isAdmin()) : ?> <?php if (($ao = Auth::instance()->get_user()) AND $ao->isAdmin()) : ?>
<li class=""> <li class="">
<a href="<?php echo URL::link('reseller','welcome',TRUE); ?>"><i class="icon-tasks"></i> <span>Admin</span></a> <a href="<?php echo URL::link('admin','welcome',TRUE); ?>"><i class="icon-tasks"></i> <span>Admin</span></a>
</li> </li>
<?php elseif ($ao->isReseller()) : ?> <?php elseif ($ao->isReseller()) : ?>
<li class=""> <li class="">
@ -109,16 +105,10 @@
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) { if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) {
echo HTML::script('media/js/jquery/jquery-1.9.1.min.js'); echo HTML::script('media/js/jquery/jquery-1.9.1.min.js');
echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js'); echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js');
// @todo Work out how to delay this loading until required
echo HTML::script('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/libs/js/wysihtml5-0.3.0_rc2.min.js');
echo HTML::script('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.min.js');
echo HTML::script('media/js/lodash/lodash-1.2.1.min.js'); echo HTML::script('media/js/lodash/lodash-1.2.1.min.js');
} else { } else {
echo HTML::script($meta->secure().'code.jquery.com/jquery-1.9.1.min.js'); echo HTML::script($meta->secure().'code.jquery.com/jquery-1.9.1.min.js');
echo HTML::script($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js'); echo HTML::script($meta->secure().'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js');
// @todo Work out how to delay this loading until required
echo HTML::script($meta->secure().'cdn.jsdelivr.net/wysihtml5/0.3.0/wysihtml5-0.3.0.min.js');
echo HTML::script($meta->secure().'cdn.jsdelivr.net/bootstrap.wysihtml5/0.0.2/bootstrap-wysihtml5-0.0.2.min.js');
echo HTML::script($meta->secure().'cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js'); echo HTML::script($meta->secure().'cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js');
} }

View File

@ -1,4 +1,5 @@
<div class="shortcuts"> <div class="shortcuts">
<a href="<?php echo URL::link('user','email/list',TRUE); ?>" class="shortcut"><i class="shortcut-icon icon-list-alt"></i><span class="shortcut-label">Emails</span></a>
<a href="<?php echo URL::link('user','invoice/list',TRUE); ?>" class="shortcut"><i class="shortcut-icon icon-list-alt"></i><span class="shortcut-label">Invoices</span></a> <a href="<?php echo URL::link('user','invoice/list',TRUE); ?>" class="shortcut"><i class="shortcut-icon icon-list-alt"></i><span class="shortcut-label">Invoices</span></a>
<a href="<?php echo URL::link('user','service/list',TRUE); ?>" class="shortcut"><i class="shortcut-icon icon-list-alt"></i><span class="shortcut-label">Services</span></a> <a href="<?php echo URL::link('user','service/list',TRUE); ?>" class="shortcut"><i class="shortcut-icon icon-list-alt"></i><span class="shortcut-label">Services</span></a>
</div> </div>

View File

@ -68,26 +68,8 @@ class Controller_Admin_Adsl extends Controller_Adsl {
HTTP::redirect(URL::link('admin','adsl/list')); HTTP::redirect(URL::link('admin','adsl/list'));
if ($_POST) { if ($_POST) {
// Entry updated if ($apo->values($_POST)->changed() AND (! $this->save($apo)))
if ($apo->values($_POST)->check() AND $apo->changed()) { $apo->reload();
try {
if ($apo->save())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$sco->reload();
}
}
if (isset($_POST['test'])) { if (isset($_POST['test'])) {
$charge = isset($_POST['test']['charge']) ? $_POST['test']['charge'] : FALSE; $charge = isset($_POST['test']['charge']) ? $_POST['test']['charge'] : FALSE;

View File

@ -43,7 +43,7 @@ class Controller_Reseller_Service_Adsl extends Controller_Service {
public function action_list() { public function action_list() {
$highchart = HighChart::factory('Combo'); $highchart = HighChart::factory('Combo');
$highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday')))); $highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday'))));
$highchart->xmetric('MB'); $highchart->ymetric('MB');
$c = 0; $c = 0;
foreach ($this->consoltraffic(time()) as $k => $details) { foreach ($this->consoltraffic(time()) as $k => $details) {

View File

@ -352,9 +352,9 @@ $(document).ready(function() {
$highchart = HighChart::factory('Combo'); $highchart = HighChart::factory('Combo');
switch ($this->plan()->metric) { switch ($this->plan()->metric) {
case '1000' : $highchart->xmetric('GB'); break; case '1000' : $highchart->ymetric('GB'); break;
case '1' : $highchart->xmetric('MB'); break; case '1' : $highchart->ymetric('MB'); break;
default: $highchart->xmetric('?'); default: $highchart->ymetric('?');
} }
$c=0; $c=0;

View File

@ -31,6 +31,8 @@ class Task_Adsl_Trafficalert extends Minion_Task {
// Get our variable data // Get our variable data
$et->to = array('account'=>array($so->account_id)); $et->to = array('account'=>array($so->account_id));
$et->variables = $so->plugin()->template_variables($et->variables(),$data); $et->variables = $so->plugin()->template_variables($et->variables(),$data);
$et->module = $so->mid();
$et->module_data = $so->id;
$et->send(); $et->send();

View File

@ -54,14 +54,8 @@ class Controller_Reseller_Charge extends Controller_Charge {
private function add_edit($id=NULL,$output='') { private function add_edit($id=NULL,$output='') {
$co = ORM::factory('Charge',$id); $co = ORM::factory('Charge',$id);
if ($_POST) { if ($_POST AND $co->values($_POST)->changed() AND (! $this->save($co)))
// Entry updated $co->reload();
if ($co->values($_POST)->check() AND $co->save())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
}
Script::factory() Script::factory()
->type('file') ->type('file')

View File

@ -11,90 +11,87 @@
*/ */
class Controller_Admin_Email extends Controller_Email { class Controller_Admin_Email extends Controller_Email {
protected $secure_actions = array( protected $secure_actions = array(
'ajaxtemplatetranslate'=>TRUE,
'list'=>TRUE, 'list'=>TRUE,
'templateadd'=>TRUE, 'templateadd'=>TRUE,
'templateedit'=>TRUE, 'templateedit'=>TRUE,
'templatelist'=>TRUE, 'templatelist'=>TRUE,
); );
public function action_ajaxtemplatetranslate() {
$eto = ORM::factory('Email_Template',$this->request->param('id'));
if (! $eto->loaded() OR ! isset($_REQUEST['key'])) {
$output = _('Unable to find translate data');
} else {
$eto = $eto->translate->where('language_id','=',$_REQUEST['key'])->find();
$output = View::factory('email/admin/ajaxtemplatetranslate')
->set('o',$eto);
}
$this->template->content = $output;
}
/** /**
* Show a list of emails * Show a list of emails
*/ */
public function action_list() { public function action_list() {
Block::add(array( Block::factory()
'title'=>_('System Emails Sent'), ->title(_('System Emails Sent'))
'body'=>Table::display( ->title_icon('icon-th')
ORM::factory('Email_Log')->find_all(), ->body(Table::factory()
25, ->page_items(25)
array( ->data(ORM::factory('Email_Log')->find_all())
'id'=>array('label'=>'ID','url'=>URL::link('user','email/view/')), ->columns(array(
'date_orig'=>array('label'=>'Date'), 'id'=>'ID',
'email'=>array('label'=>'To'), 'date_orig'=>'Date',
'translate_resolve("subject")'=>array('label'=>'Subject'), 'email'=>'To',
'account->accnum()'=>array('label'=>'Cust ID'), 'resolve("subject")'=>'Subject',
'account->name()'=>array('label'=>'Customer'), 'account->accnum()'=>'Cust ID',
), 'account->name()'=>'Customer',
array( ))
'page'=>TRUE, ->prepend(array(
'type'=>'select', 'id'=>array('url'=>URL::link('user','email/view/')),
'form'=>URL::link('user','email/view'), ))
)), ->postproc(array(
)); 'resolve("subject")'=>array('trim'=>60),
} ))
);
/**
* List our defined email templates
*/
public function action_templatelist() {
$eto = ORM::factory('Email_Template');
$output = '';
// @todo Change this to use Table::
$output .= View::factory($this->viewpath().'/head');
foreach ($eto->find_all() as $et) {
$output .= View::factory($this->viewpath().'/body')
->set('template',$et);
}
$output .= View::factory($this->viewpath().'/foot');
Block::add(array(
'title'=>_('Available Email Templates'),
'body'=>$output,
));
} }
/** /**
* Add a template * Add a template
*/ */
public function action_templateadd() { public function action_templateadd() {
$eto = ORM::factory('Email_Template'); Block::factory()
$output = ''; ->type('form-horizontal')
->title('Add Email Template')
->title_icon('icon-wrench')
->body($this->add_edit_template());
}
if ($_POST AND $eto->values($_POST)->check()) { /**
// @todo To update the setup ID * List our defined email templates
$eto->email_setup_id=1; */
public function action_templatelist() {
// Entry updated Block::factory()
if ($eto->save()) { ->title(_('System Emails Templates Available'))
$x = $eto->email_template_translate->values($_POST['translate']['new']); ->title_icon('icon-th')
->body(Table::factory()
$x->email_template_id = $eto->id; ->page_items(25)
if ($x->check()) ->data(ORM::factory('Email_Template')->find_all())
$x->save(); ->columns(array(
} 'id'=>'ID',
} 'name'=>'Name',
'status'=>'Active',
$output .= Form::open(); 'description'=>'Descrption',
$output .= View::factory($this->viewpath()); ))
$output .= View::factory($this->viewpath().'/translate'); ->prepend(array(
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>'; 'id'=>array('url'=>URL::link('admin','email/templateedit/')),
$output .= Form::close(); ))
);
Editor::add();
Block::add(array(
'title'=>_('Available Email Templates'),
'body'=>$output,
));
} }
/** /**
@ -102,51 +99,64 @@ class Controller_Admin_Email extends Controller_Email {
* @todo Change this into an add_view function like payment() * @todo Change this into an add_view function like payment()
*/ */
public function action_templateedit() { public function action_templateedit() {
$id = $this->request->param('id'); list($id,$output) = Table::page(__METHOD__);
Block::factory()
->type('form-horizontal')
->title('Update Email Template')
->title_icon('icon-wrench')
->body($this->add_edit_template($id,$output));
}
private function add_edit_template($id=NULL,$output='') {
$eto = ORM::factory('Email_Template',$id); $eto = ORM::factory('Email_Template',$id);
if (! $eto->loaded()) if ($_POST) {
HTTP::redirect(URL::link('admin','email/template/list')); // @todo To update the setup ID
$eto->email_setup_id = '1';
$output = ''; if (! $this->save($eto))
$eto->reload();
if ($_POST AND $eto->values($_POST)->check()) {
// Entry updated
if ($eto->save()) {
foreach ($_POST['translate'] as $id => $details) {
$x = $eto->email_template_translate->where('id','=',$id)->find();
if ($x->values($details)->check())
$x->save();
}
}
} }
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("select[name=language_id]").change(function() {
// If we select a blank, then dont continue
if (this.value == 0)
return false;
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::link('admin','email/ajaxtemplatetranslate/'.$eto->id,TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=translate]").replaceWith(data);
}
});
});
});
');
return View::factory('email/admin/add_edit_template')
->set('o',$eto);
$output .= Form::open(); $output .= Form::open();
$output .= View::factory($this->viewpath());
$output .= View::factory($this->viewpath()) $output .= View::factory($this->viewpath().'/translate');
->set('template',$eto); $output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
foreach ($eto->email_template_translate->find_all() as $to) {
$output .= View::factory($this->viewpath().'/translate')
->set('translate',$to);
SystemMessage::add(array(
'title'=>_('Available Variables'),
'type'=>'info',
'body'=>sprintf('This template uses the following TEXT variables (%s) and HTML variables (%s)',
implode('|',array_values($to->variables('message_text'))),
implode('|',array_values($to->variables('message_html')))),
));
}
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
$output .= Form::close(); $output .= Form::close();
Editor::add();
Block::add(array( Block::add(array(
'title'=>sprintf(_('Edit Template '),$eto->name), 'title'=>_('Available Email Templates'),
'body'=>$output, 'body'=>$output,
)); ));
} }

View File

@ -1,14 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides email management
*
* @package Email
* @category Controllers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_EmailTemplate extends Controller_TemplateDefault {
}
?>

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_User_Email extends Controller_TemplateDefault_User { class Controller_User_Email extends Controller_Email {
protected $secure_actions = array( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'view'=>TRUE, 'view'=>TRUE,
@ -19,22 +19,24 @@ class Controller_User_Email extends Controller_TemplateDefault_User {
* Show a list of emails * Show a list of emails
*/ */
public function action_list() { public function action_list() {
Block::add(array( Block::factory()
'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)), ->title(sprintf(_('System Emails Sent for %s: %s'),$this->ao->accnum(),$this->ao->name(TRUE)))
'body'=>Table::display( ->title_icon('icon-th')
$this->ao->email_log->find_all(), ->body(Table::factory()
25, ->page_items(25)
array( ->data($this->ao->email_log->find_all())
'id'=>array('label'=>'ID','url'=>URL::link('user','email/view/')), ->columns(array(
'date_orig'=>array('label'=>'Date'), 'id'=>'ID',
'translate_resolve("subject")'=>array('label'=>'Subject'), 'date_orig'=>'Date',
), 'resolve("subject")'=>'Subject',
array( ))
'page'=>TRUE, ->prepend(array(
'type'=>'select', 'id'=>array('url'=>URL::link('user','email/view/')),
'form'=>URL::link('user','email/view'), ))
)), ->postproc(array(
)); 'resolve("subject")'=>array('trim'=>60),
))
);
} }
public function action_view() { public function action_view() {
@ -42,18 +44,16 @@ class Controller_User_Email extends Controller_TemplateDefault_User {
$elo = ORM::factory('Email_Log',$id); $elo = ORM::factory('Email_Log',$id);
if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account)) { if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account))
$this->template->content = 'Unauthorised or doesnt exist?'; throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
return FALSE;
}
$output .= View::factory($this->viewpath()) $output .= View::factory('email/user/view')
->set('elo',$elo); ->set('elo',$elo);
Block::add(array( Block::factory()
'title'=>sprintf('%s: %s',_('Email'),$elo->translate_resolve('subject')), ->title(sprintf('%s: %s',$elo->id,$elo->resolve('subject')))
'body'=>$output, ->title_icon('icon-list-alt')
)); ->body($output);
} }
} }
?> ?>

View File

@ -10,31 +10,32 @@
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Email_Template { class Email_Template {
// We'll store the template here // Our components that need resolving
private $template; private $_components = array('subject','message_text','message_html');
private $etto; // Our Email Data
private $email_data = array(); private $_data = array();
// @todo Default lang should be the site setup // Our Email Template Object
private $default_lang = 1; private $_etto;
private $components = array('subject','message_text','message_html');
public function __construct($template,$language_id=NULL) { public function __construct($template,$language_id=NULL) {
$this->template = ORM::factory('Email_Template',array('name'=>$template)); $eto = ORM::factory('Email_Template',array('name'=>$template));
if (! $this->template->loaded()) if (! $eto->loaded())
throw new Kohana_Exception('Email template :template not defined in DB',array(':template'=>$template)); throw new Kohana_Exception('Email template :template not defined in DB',array(':template'=>$template));
if (is_null($language_id)) if (is_null($language_id))
$language_id = $this->default_lang; $language_id = Config::language();
$this->etto = $this->template->email_template_translate->where('language_id','=',$language_id)->find(); $this->_etto = $eto->translate
if (! $this->etto->loaded()) ->where_open()
$this->etto = $this->template->email_template_translate->where('language_id','=',$this->default_lang)->find(); ->where('language_id','=',$language_id)
->or_where('language_id','=',Config::language())
->where_close()
->find();
// @todo Change this to log/email the admin if (! $this->_etto->loaded())
return; throw new Kohana_Exception('No template (:template) found for user language (:language_id) or default language (:default_lang)',
#throw new Kohana_Exception('No template (:template) found for user language (:language_id) or default language (:default_lang)', array(':template'=>$eto->name,':language_id'=>$language_id,':default_lang'=>Config::language()));
# array(':template'=>$this->template->name,':language_id'=>$language_id,':default_lang'=>$this->default_lang));
} }
public function __set($key,$value) { public function __set($key,$value) {
@ -44,7 +45,15 @@ class Email_Template {
if (! is_array($value) OR ! array_intersect(array('email','account'),array_keys($value))) if (! is_array($value) OR ! array_intersect(array('email','account'),array_keys($value)))
throw new Kohana_Exception('Values for to should be an array of either "mail" or "account", however :value was given',array(':value'=>serialize($value))); throw new Kohana_Exception('Values for to should be an array of either "mail" or "account", however :value was given',array(':value'=>serialize($value)));
$this->email_data[$key] = $value; $this->_data[$key] = $value;
break;
case 'module':
$this->_data[$key] = $value;
break;
case 'module_data':
$this->_data[$key] = $value;
break; break;
case 'variables': case 'variables':
@ -52,7 +61,7 @@ class Email_Template {
if (! is_array($value)) if (! is_array($value))
throw new Kohana_Exception('Values for variables should be an array, however :value was given',array(':value'=>$value)); throw new Kohana_Exception('Values for variables should be an array, however :value was given',array(':value'=>$value));
$this->email_data[$key] = $value; $this->_data[$key] = $value;
break; break;
default: default:
@ -64,16 +73,16 @@ class Email_Template {
switch ($key) { switch ($key) {
case 'bcc': case 'bcc':
case 'to': case 'to':
if (empty($this->email_data[$key])) if (empty($this->_data[$key]))
return array(); return array();
elseif (isset($this->email_data[$key]['email'])) elseif (isset($this->_data[$key]['email']))
return $this->email_data[$key]['email']; return $this->_data[$key]['email'];
elseif (isset($this->email_data[$key]['account'])) { elseif (isset($this->_data[$key]['account'])) {
$list = array(); $list = array();
foreach ($this->email_data[$key]['account'] as $id) { foreach ($this->_data[$key]['account'] as $id) {
$ao = ORM::factory('Account',$id); $ao = ORM::factory('Account',$id);
if ($ao->loaded()) if ($ao->loaded())
$list[$ao->email] = $ao->name(); $list[$ao->email] = $ao->name();
@ -85,7 +94,7 @@ class Email_Template {
break; break;
case 'variables': case 'variables':
return $this->email_data[$key]; return $this->_data[$key];
default: default:
throw new Kohana_Exception('Unknown variable :key (:value)',array(':key'=>$key,':value'=>is_string($value) ? $value : serialize($value))); throw new Kohana_Exception('Unknown variable :key (:value)',array(':key'=>$key,':value'=>is_string($value) ? $value : serialize($value)));
@ -96,25 +105,14 @@ class Email_Template {
return new Email_Template($template); return new Email_Template($template);
} }
public function variables() {
$result = array();
foreach ($this->components as $v)
foreach ($this->etto->variables($v) as $x => $y)
if (! in_array($y,$result))
array_push($result,$y);
return $result;
}
public function send(array $admin=array()) { public function send(array $admin=array()) {
$e = Email::connect(); $e = Email::connect();
$sm = Swift_Message::newInstance() $sm = Swift_Message::newInstance()
->setFrom(Kohana::$config->load('config')->email_from); ->setFrom(Kohana::$config->load('config')->email_from);
foreach ($this->components as $component) { foreach ($this->_components as $component) {
if ($this->etto->loaded()) { if ($this->_etto->loaded()) {
$s = $this->etto->rresolve($this->email_data['variables'],$component); $s = $this->_etto->complete($this->_data['variables'],$component);
switch ($component) { switch ($component) {
case 'message_html': case 'message_html':
@ -132,14 +130,14 @@ class Email_Template {
} }
} else { } else {
$sm->setSubject(_('Email from').' '.Company::instance()->name()); $sm->setSubject(_('Email from').' '.Company::instance()->name());
$sm->setBody(print_r($this->email_data['variables'],TRUE),'text/plain'); $sm->setBody(print_r($this->_data['variables'],TRUE),'text/plain');
} }
} }
if (isset($this->email_data['bcc'])) if (isset($this->_data['bcc']))
$sm->setBcc($this->bcc); $sm->setBcc($this->bcc);
if ($admin OR ($admin = Config::testmail($this->template->name))) { if ($admin OR ($admin = Config::testmail($this->_etto->template->name))) {
$sm->setTo($admin); $sm->setTo($admin);
$sa = array(1); $sa = array(1);
@ -153,18 +151,22 @@ class Email_Template {
// Store our email log. // Store our email log.
$elo = ORM::factory('Email_Log'); $elo = ORM::factory('Email_Log');
if ($result) { if ($result)
foreach ($sa as $id) { foreach ($sa as $id) {
$elo->clear(); $elo->clear();
$elo->account_id = $id; $elo->account_id = $id;
$elo->email = implode(',',array_keys($this->to)); $elo->email = implode(',',array_keys($this->to));
$elo->email_template_translate_id = $this->etto->id; $elo->email_template_translate_id = $this->_etto->id;
$elo->data = $this->email_data['variables']; $elo->data = $this->_data['variables'];
if (isset($this->_data['module']) AND isset($this->_data['module_data'])) {
$elo->module_id = $this->_data['module'];
$elo->module_data = $this->_data['module_data'];
}
$elo->save(); $elo->save();
} }
}
return ($result AND $elo->saved()) ? $elo->id : $result; return ($result AND $elo->saved()) ? $elo->id : $result;
} }
@ -173,10 +175,24 @@ class Email_Template {
// @todo Set the default account in a configuration file. // @todo Set the default account in a configuration file.
$default = array(1); $default = array(1);
if (! isset($this->email_data['to']) OR ! is_array($this->email_data['to']) OR ! array_intersect(array('email','account'),array_keys($this->email_data['to']))) if (! isset($this->_data['to']) OR ! is_array($this->_data['to']) OR ! array_intersect(array('email','account'),array_keys($this->_data['to'])))
return $default; return $default;
return isset($this->email_data['to']['account']) ? $this->email_data['to']['account'] : $default; return isset($this->_data['to']['account']) ? $this->_data['to']['account'] : $default;
}
/**
* Work out all the required variables for this message
*/
public function variables() {
$result = array();
foreach ($this->_components as $v)
foreach ($this->_etto->variables($v) as $x => $y)
if (! in_array($y,$result))
array_push($result,$y);
return $result;
} }
} }
?> ?>

View File

@ -15,7 +15,7 @@ class Model_Email_Log extends ORM_OSB {
protected $_belongs_to = array( protected $_belongs_to = array(
'account'=>array('far_key'=>'id'), 'account'=>array('far_key'=>'id'),
'email_template_translate'=>array('far_key'=>'id'), 'translate'=>array('model'=>'Email_Template_Translate','foreign_key'=>'email_template_translate_id'),
); );
protected $_sorting = array( protected $_sorting = array(
@ -28,11 +28,11 @@ class Model_Email_Log extends ORM_OSB {
), ),
); );
public function translate_resolve($column) { /**
if (! $this->data OR ! ($this->email_template_translate->variables($column))) * Resolve a data variable into
return $this->email_template_translate->display($column); */
else public function resolve($column) {
return $this->email_template_translate->rresolve($this->data,$column); return (! $this->data OR ! $this->translate->variables($column)) ? $this->translate->display($column) : $this->translate->complete($this->data,$column);
} }
} }
?> ?>

View File

@ -10,7 +10,7 @@
*/ */
class Model_Email_Template extends ORM_OSB { class Model_Email_Template extends ORM_OSB {
protected $_has_many = array( protected $_has_many = array(
'email_template_translate'=>array('foreign_key'=>'email_template_id','far_key'=>'id'), 'translate'=>array('model'=>'Email_Template_Translate','foreign_key'=>'email_template_id','far_key'=>'id'),
); );
// This module doesnt keep track of column updates automatically // This module doesnt keep track of column updates automatically
@ -27,8 +27,29 @@ class Model_Email_Template extends ORM_OSB {
), ),
); );
protected $_save_message = TRUE;
public function name() { public function name() {
return ! is_null($this->description) ? $this->description : $this->name; return ! is_null($this->description) ? $this->description : $this->name;
} }
public function save(Validation $validation=NULL) {
parent::save();
// Save our Translated Message
if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['translate']) AND is_array($_POST['translate'])) {
$to = $this->translate->where('language_id','=',$_POST['language_id'])->find();
// For a new entry, we need to set the product_id
if (! $to->loaded()) {
$to->product_id = $this->id;
$to->language_id = $_POST['language_id'];
}
$to->values($x['translate'])->save();
}
return $this;
}
} }
?> ?>

View File

@ -13,11 +13,26 @@ class Model_Email_Template_Translate extends ORM_OSB {
protected $_created_column = FALSE; protected $_created_column = FALSE;
protected $_updated_column = FALSE; protected $_updated_column = FALSE;
protected $_belongs_to = array(
'template'=>array('model'=>'Email_Template','foreign_key'=>'email_template_id'),
);
protected $_save_message = TRUE;
public function complete($data,$column) {
$output = $this->display($column);
foreach ($this->variables($column) as $k => $v)
$output = str_replace('$'.$v.'$',$data[$v],$output);
return $output;
}
public function variables($field) { public function variables($field) {
$results = array(); $results = array();
$matches = array(); $matches = array();
preg_match_all('/%([A-Z0-9_]+)%/U',$this->$field,$matches,PREG_OFFSET_CAPTURE); preg_match_all('/\$([A-Z0-9_]+)\$/U',$this->$field,$matches,PREG_OFFSET_CAPTURE);
foreach ($matches[1] as $k => $v) foreach ($matches[1] as $k => $v)
$results[$v[1]] = $v[0]; $results[$v[1]] = $v[0];
@ -27,14 +42,5 @@ class Model_Email_Template_Translate extends ORM_OSB {
return $results; return $results;
} }
public function rresolve($data,$column) {
$output = $this->display($column);
foreach ($this->variables($column) as $k => $v)
$output = str_replace('%'.$v.'%',$data[$v],$output);
return $output;
}
} }
?> ?>

View File

@ -0,0 +1,38 @@
<div class="row">
<div class="span9 offset1">
<div class="row">
<div class="span3">
<?php echo Form::input('name',$o->name,array('label'=>'Name','class'=>'span3')); ?>
</div>
</div> <!-- /row -->
<div class="row">
<div class="span3">
<?php echo StaticList_YesNo::form('status',$o->status,FALSE,array('label'=>'Email Template Active','class'=>'span1')); ?>
</div>
</div>
<div class="row">
<div class="span8">
<?php echo Form::textarea('notes',$o->notes,array('label'=>'Notes','class'=>'span8')); ?>
</div>
</div> <!-- /row -->
<div class="row">
<div class="span5">
<?php echo Form::select('language_id',ORM::factory('Language')->list_select(TRUE),'',array('label'=>'Language','required')); ?>
</div>
</div> <!-- /row -->
<div class="row">
<div id="translate"></div>
</div> <!-- /row -->
<div class="row">
<div class="offset2">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn">Cancel</button>
</div>
</div>
</div>
</div> <!-- /row -->

View File

@ -0,0 +1,30 @@
<div id="translate">
<div class="span9">
<?php echo Form::input('translate[subject]',$o->subject,array(
'label'=>'Email Subject',
'placeholder'=>'Email Subject',
'class'=>'span8',
'required',
'help-block'=>sprintf('This is the subject line on the email. Uses variables: %s',implode(', ',array_values($o->variables('subject')))))); ?>
</div>
<div class="span9">
<?php echo Form::textarea('translate[message_text]',$o->message_text,array(
'label'=>'Message Text',
'placeholder'=>'Message Text',
'class'=>'span8',
'required',
'help-block'=>sprintf('The message in plain text that is used in the email for email clients that cannot render HTML. Uses variables: %s',implode(', ',array_values($o->variables('message_text')))))); ?>
</div>
<div class="span9">
<?php echo Form::textarea('translate[message_html]',$o->message_html,array(
'label'=>'Message HTML',
'placeholder'=>'Message HTML',
'class'=>'span8',
'required',
'editor'=>'tinymce',
'help-block'=>sprintf('The message in HTML that is used in the email. Uses variables: %s',implode(', ',array_values($o->variables('message_html')))))); ?>'
</div>
</div>
<?php echo Style::factory()->render_all(); ?>
<?php echo Script::factory()->render_all(); ?>

View File

@ -1,14 +0,0 @@
<table class="box-left">
<tr>
<td class="head">Name:</td>
<td><?php echo Form::input('name','',array('size'=>30)); ?></td>
</tr>
<tr>
<td class="head">Active:</td>
<td><?php echo StaticList_YesNo::form('status',TRUE); ?></td>
</tr>
<tr>
<td class="head">Notes:</td>
<td><?php echo Form::input('notes','',array('size'=>80)); ?></td>
</tr>
</table>

View File

@ -1,18 +0,0 @@
<table class="box-left">
<tr>
<td class="head">Language:</td>
<td><?php echo Form::input(sprintf('translate[%s][language_id]','new'),'',array('size'=>5)); ?></td>
</tr>
<tr>
<td class="head">Subject:</td>
<td><?php echo Form::input(sprintf('translate[%s][subject]','new'),'',array('size'=>80)); ?></td>
</tr>
<tr>
<td class="head">Text:</td>
<td><?php echo Form::textarea(sprintf('translate[%s][message_text]','new'),'',array('cols'=>120,'rows'=>10)); ?></td>
</tr>
<tr>
<td class="head">HTML:</td>
<td><?php echo Form::textarea(sprintf('translate[%s][message_html]','new'),'',array('cols'=>120,'rows'=>10,'class'=>'mceEditor')); ?></td>
</tr>
</table>

View File

@ -1,14 +0,0 @@
<table class="box-left">
<tr>
<td class="head">Name:</td>
<td><?php echo Form::input('name',$template->name,array('size'=>30)); ?></td>
</tr>
<tr>
<td class="head">Active:</td>
<td><?php echo StaticList_YesNo::form('status',$template->status); ?></td>
</tr>
<tr>
<td class="head">Notes:</td>
<td><?php echo Form::input('notes',$template->notes,array('size'=>80)); ?></td>
</tr>
</table>

View File

@ -1,18 +0,0 @@
<table class="box-left">
<tr>
<td class="head">Language:</td>
<td><?php echo Form::input(sprintf('translate[%s][language_id]',$translate->id),$translate->language_id,array('size'=>5)); ?></td>
</tr>
<tr>
<td class="head">Subject:</td>
<td><?php echo Form::input(sprintf('translate[%s][subject]',$translate->id),$translate->subject,array('size'=>80)); ?></td>
</tr>
<tr>
<td class="head">Text:</td>
<td><?php echo Form::textarea(sprintf('translate[%s][message_text]',$translate->id),$translate->message_text,array('cols'=>120,'rows'=>10)); ?></td>
</tr>
<tr>
<td class="head">HTML:</td>
<td><?php echo Form::textarea(sprintf('translate[%s][message_html]',$translate->id),$translate->message_html,array('cols'=>120,'rows'=>20,'class'=>'mceEditor')); ?></td>
</tr>
</table>

View File

@ -1,4 +0,0 @@
<tr>
<td><a href="<?php echo URL::link('admin','email/templateedit/'.$template->id,TRUE); ?>" alt=""><?php echo $template->name; ?></a></td>
<td><?php echo $template->display('status'); ?></td>
</tr>

View File

@ -1 +0,0 @@
</table>

View File

@ -1,6 +0,0 @@
<!-- //@todo Translation required -->
<table class="box-left">
<tr class="head">
<td>Template</td>
<td>Active</td>
</tr>

View File

@ -1,20 +1,32 @@
<table width="100%"> <div class="row">
<tr> <div class="span11">
<td>To:</td><td class="data"><?php printf('%s (%s)',$elo->account->name(),$elo->display('email')); ?></td>
</tr> <table>
<tr> <tr>
<td>Date:</td><td class="data"><?php echo $elo->display('date_orig'); ?></td> <td><strong>To:</strong></td>
</tr> <td><?php printf('%s (%s)',$elo->account->name(),$elo->display('email')); ?></td>
<tr> </tr>
<td>Subject:</td><td class="data"><?php echo $elo->translate_resolve('subject'); ?></td> <tr>
</tr> <td><strong>Date:</strong></td>
<tr> <td><?php echo $elo->display('date_orig'); ?></td>
<td style="width: 100%;" colspan="2"> </tr>
<table class="box-full"> <tr>
<tr> <td><strong>Subject:</strong></td>
<td><?php echo $elo->translate_resolve('message_html'); ?></td> <td><?php echo $elo->resolve('subject'); ?></td>
</tr> </tr>
</table> <tr>
</td> <td colspan="2"><hr/></td>
</tr> </tr>
</table> <tr>
<td colspan="2">
<table>
<tr>
<td><?php echo $elo->resolve('message_html'); ?></td>
</tr>
</table>
</td>
</tr>
</table>
</div> <!-- /span -->
</div> <!-- /row -->

View File

@ -25,16 +25,10 @@ class Controller_Admin_Export extends Controller_Export {
$edo = ORM::factory('Export_DataMap'); $edo = ORM::factory('Export_DataMap');
if ($_POST AND isset($_POST['item_id']) AND $edo->values($_POST)->check()) { if ($_POST AND isset($_POST['item_id']) AND $edo->values($_POST)->changed()) {
$edo->status = 1; $edo->status = 1;
if (! $edo->save()) $this->save($edo);
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
SystemMessage::factory()
->title('Record added')
->type('success')
->body(_('Export DataMap record has been added.'));
} }
Block::factory() Block::factory()
@ -87,16 +81,8 @@ class Controller_Admin_Export extends Controller_Export {
if ($_POST AND isset($_POST['export_module_id'])) { if ($_POST AND isset($_POST['export_module_id'])) {
$emo = ORM::factory('Export_Module',$_POST['export_module_id']); $emo = ORM::factory('Export_Module',$_POST['export_module_id']);
if ($emo->loaded()) { if ($emo->loaded() AND $emo->values($_POST)->changed() AND ! $this->save($emo))
$emo->values($_POST); $emo->reload();
$emo->save();
if ($emo->saved())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Export Module record has been updated.'));
}
} }
if ($x = $this->request->param('id')) { if ($x = $this->request->param('id')) {

@ -1 +1 @@
Subproject commit 9ed797b1d2e9a2b3b8227bbb42be01ea620916d4 Subproject commit 4bd8d1ffae3d89ee85de63e1a80a3d7aeb7b0fa5

View File

@ -22,6 +22,9 @@ class Controller_User_Invoice extends Controller_Invoice {
public function action_download() { public function action_download() {
$io = ORM::factory('Invoice',$this->request->param('id')); $io = ORM::factory('Invoice',$this->request->param('id'));
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account))
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
// Log the download // Log the download
$imo = $io->invoice_memo; $imo = $io->invoice_memo;
$imo->invoice_id = $io->id; $imo->invoice_id = $io->id;

View File

@ -215,7 +215,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $format ? Currency::display($result) : $result; return $format ? Currency::display($result) : $result;
} }
//ZZ
/** /**
* Return a list of valid checkout options for this invoice * Return a list of valid checkout options for this invoice
*/ */
@ -508,11 +507,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
if (! $iio->changed()) if (! $iio->changed())
continue; continue;
if (! $iio->check()) {
// @todo Mark invoice as cancelled and write a memo, then...
throw new Kohana_Exception('Problem saving invoice_item for invoice :invoice - Failed check()',array(':invoice'=>$this->id));
}
$iio->save(); $iio->save();
if (! $iio->saved()) { if (! $iio->saved()) {
@ -548,7 +542,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
} else } else
throw new Kohana_Exception('Couldnt save invoice for some reason?'); throw new Kohana_Exception('Couldnt save invoice for some reason?');
return TRUE; return $this;
} }
public function set_remind($key,$value,$add=FALSE) { public function set_remind($key,$value,$add=FALSE) {

View File

@ -188,9 +188,6 @@ class Model_Invoice_Item extends ORM_OSB {
} }
public function save(Validation $validation = NULL) { public function save(Validation $validation = NULL) {
if (! $this->changed())
return;
// Save the invoice item // Save the invoice item
parent::save($validation); parent::save($validation);
@ -214,9 +211,6 @@ class Model_Invoice_Item extends ORM_OSB {
// @todo Rounding here should come from a global config // @todo Rounding here should come from a global config
$iito->amount = round($tax['amount'],2); $iito->amount = round($tax['amount'],2);
if (! $iito->check())
throw new Kohana_Exception('Couldnt save tax for some reason - failed check()?');
$iito->save(); $iito->save();
if (! $iito->saved()) if (! $iito->saved())
@ -224,6 +218,8 @@ class Model_Invoice_Item extends ORM_OSB {
} }
} else } else
throw new Kohana_Exception('Couldnt save invoice_item for some reason?'); throw new Kohana_Exception('Couldnt save invoice_item for some reason?');
return $this;
} }
} }
?> ?>

@ -1 +1 @@
Subproject commit 610c223cb823f2b16df3e1f49912e8ef42dc6bd7 Subproject commit 1ec370f07af319e5deda43dce6585ad9e0240c18

View File

@ -96,12 +96,7 @@ class Controller_Admin_Payment extends Controller_Payment {
$pio->alloc_amt = is_numeric($v) ? $v : 0; $pio->alloc_amt = is_numeric($v) ? $v : 0;
} }
// Entry updated $this->save($po);
if ($po->values($_POST)->check() AND $po->save())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Payment record has been recorded/updated.'));
} }
Script::factory() Script::factory()

View File

@ -200,7 +200,7 @@ class Model_Payment extends ORM_OSB {
throw HTTP_Exception::factory(501,'Problem saving payment :id - Failed save()',array(':id'=>$this->id)); throw HTTP_Exception::factory(501,'Problem saving payment :id - Failed save()',array(':id'=>$this->id));
} }
return TRUE; return $this;
} }
/** /**

View File

@ -65,8 +65,8 @@ class Controller_Admin_Product extends Controller_Product {
if (! $pco->loaded()) if (! $pco->loaded())
HTTP::redirect(URL::link('admin','product/list')); HTTP::redirect(URL::link('admin','product/list'));
if ($_POST) if ($_POST AND $pco->values($_POST)->changed() AND (! $this->save($pco)))
$pco->values($_POST)->save(); $pco->reload();
Script::factory() Script::factory()
->type('stdin') ->type('stdin')
@ -113,8 +113,8 @@ $(document).ready(function() {
if (! $po->loaded()) if (! $po->loaded())
HTTP::redirect('welcome/index'); HTTP::redirect('welcome/index');
if ($_POST) if ($_POST AND $po->values($_POST)->changed() AND (! $this->save($po)))
$po->values($_POST)->save(); $po->reload();
Script::factory() Script::factory()
->type('stdin') ->type('stdin')

View File

@ -14,9 +14,9 @@
*/ */
class Model_Product extends ORM_OSB { class Model_Product extends ORM_OSB {
protected $_has_many = array( protected $_has_many = array(
'product_translate'=>array('far_key'=>'id'),
'service'=>array('far_key'=>'id'),
'invoice'=>array('through'=>'invoice_item'), 'invoice'=>array('through'=>'invoice_item'),
'service'=>array('far_key'=>'id'),
'translate'=>array('model'=>'Product_Translate','far_key'=>'id'),
); );
protected $_sorting = array( protected $_sorting = array(
@ -44,6 +44,8 @@ class Model_Product extends ORM_OSB {
'price_group', 'price_group',
); );
protected $_save_message = TRUE;
/** /**
* Which categories is this product available in * Which categories is this product available in
*/ */
@ -106,29 +108,22 @@ class Model_Product extends ORM_OSB {
} }
public function save(Validation $validation=NULL) { public function save(Validation $validation=NULL) {
if ($this->changed()) parent::save($validation);
if (parent::save($validation))
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Record %s Updated',$this->id));
// Save our Translated Message // Save our Translated Message
if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['product_translate']) AND is_array($_POST['product_translate'])) { if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['translate']) AND is_array($_POST['translate'])) {
$pto = $this->product_translate->where('language_id','=',$_POST['language_id'])->find(); $to = $this->translate->where('language_id','=',$_POST['language_id'])->find();
// For a new entry, we need to set the product_id // For a new entry, we need to set the product_id
if (! $pto->loaded()) { if (! $to->loaded()) {
$pto->product_id = $this->id; $to->product_id = $this->id;
$pto->language_id = $_POST['language_id']; $to->language_id = $_POST['language_id'];
} }
if ($pto->values($x['product_translate'])->save()) $to->values($x['translate'])->save();
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Translation for Record %s Updated',$this->id));
} }
return $this;
} }
/** /**
@ -143,7 +138,7 @@ class Model_Product extends ORM_OSB {
} }
private function translate() { private function translate() {
return $this->product_translate->where('language_id','=',Config::language())->find(); return $this->translate->where('language_id','=',Config::language())->find();
} }
/** /**

View File

@ -20,14 +20,16 @@ class Model_Product_Category extends ORM_OSB {
); );
protected $_has_many = array( protected $_has_many = array(
'product_category_translate'=>array('foreign_key'=>'product_cat_id','far_key'=>'id'),
'subcategories'=>array('model'=>'product_category','foreign_key'=>'parent_id','far_key'=>'id'), 'subcategories'=>array('model'=>'product_category','foreign_key'=>'parent_id','far_key'=>'id'),
'translate'=>array('model'=>'Product_Category_Translate','foreign_key'=>'product_cat_id','far_key'=>'id'),
); );
protected $_sorting = array( protected $_sorting = array(
'position'=>'ASC', 'position'=>'ASC',
); );
protected $_save_message = TRUE;
/** /**
* Return the translated description for a category. * Return the translated description for a category.
*/ */
@ -51,29 +53,22 @@ class Model_Product_Category extends ORM_OSB {
} }
public function save(Validation $validation=NULL) { public function save(Validation $validation=NULL) {
if ($this->changed()) parent::save($validation);
if (parent::save($validation))
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Record %s Updated',$this->id));
// Save our Translated Message // Save our Translated Message
if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['product_category_translate']) AND is_array($_POST['product_category_translate'])) { if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['translate']) AND is_array($_POST['translate'])) {
$pcto = $this->product_category_translate->where('language_id','=',$_POST['language_id'])->find(); $to = $this->translate->where('language_id','=',$_POST['language_id'])->find();
// For a new entry, we need to set the product_cat_id // For a new entry, we need to set the product_cat_id
if (! $pcto->loaded()) { if (! $to->loaded()) {
$pcto->product_cat_id = $this->id; $to->product_cat_id = $this->id;
$pcto->language_id = $_POST['language_id']; $to->language_id = $_POST['language_id'];
} }
if ($pcto->values($x['product_category_translate'])->save()) $to->values($x['translate'])->save();
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Translation for Record %s Updated',$this->id));
} }
return $this;
} }
/** /**
@ -111,7 +106,7 @@ class Model_Product_Category extends ORM_OSB {
private function translate() { private function translate() {
return $this->product_category_translate->where('language_id','=',Config::language())->find(); return $this->translate->where('language_id','=',Config::language())->find();
} }
} }
?> ?>

View File

@ -17,5 +17,7 @@ class Model_Product_Category_Translate extends ORM_OSB {
protected $_belongs_to = array( protected $_belongs_to = array(
'product_category'=>array(), 'product_category'=>array(),
); );
protected $_save_message = TRUE;
} }
?> ?>

View File

@ -16,5 +16,7 @@ class Model_Product_Translate extends ORM_OSB {
protected $_belongs_to = array( protected $_belongs_to = array(
'product'=>array(), 'product'=>array(),
); );
protected $_save_message = TRUE;
} }
?> ?>

View File

@ -1,6 +1,6 @@
<div id="translate"> <div id="translate">
<div class="span6"> <div class="span6">
<?php echo Form::input('product_translate[name]',$o->name,array( <?php echo Form::input('translate[name]',$o->name,array(
'label'=>'Category Title', 'label'=>'Category Title',
'placeholder'=>'Descriptive Title', 'placeholder'=>'Descriptive Title',
'class'=>'span3', 'class'=>'span3',
@ -8,20 +8,24 @@
'help-block'=>'The title is shown when uses search products by category')); ?> 'help-block'=>'The title is shown when uses search products by category')); ?>
</div> </div>
<div class="span9"> <div class="span9">
<?php echo Form::textarea('product_translate[description_short]',$o->description_short,array( <?php echo Form::textarea('translate[description_short]',$o->description_short,array(
'label'=>'Short Product Description', 'label'=>'Short Product Description',
'placeholder'=>'Short Description', 'placeholder'=>'Short Description',
'class'=>'span6', 'class'=>'span6',
'required', 'required',
'editor'=>'wysihtml5',
'help-block'=>'Complete description of this category')); ?> 'help-block'=>'Complete description of this category')); ?>
</div> </div>
<div class="span9"> <div class="span9">
<?php echo Form::textarea('product_translate[description_full]',$o->description_full,array( <?php echo Form::textarea('translate[description_full]',$o->description_full,array(
'label'=>'Full Product Description', 'label'=>'Full Product Description',
'placeholder'=>'Full Description', 'placeholder'=>'Full Description',
'class'=>'span6', 'class'=>'span6',
'required', 'required',
'editor'=>'wysihtml5',
'help-block'=>'Complete description of this category')); ?> 'help-block'=>'Complete description of this category')); ?>
</div> </div>
</div> </div>
<?php echo Style::factory()->render_all(); ?>
<?php echo Script::factory()->render_all(); ?> <?php echo Script::factory()->render_all(); ?>

View File

@ -1,6 +1,6 @@
<div id="translate"> <div id="translate">
<div class="span6"> <div class="span6">
<?php echo Form::input('product_category_translate[name]',$o->name,array( <?php echo Form::input('translate[name]',$o->name,array(
'label'=>'Category Title', 'label'=>'Category Title',
'placeholder'=>'Descriptive Title', 'placeholder'=>'Descriptive Title',
'class'=>'span3', 'class'=>'span3',
@ -8,12 +8,15 @@
'help-block'=>'The title is shown when uses search products by category')); ?> 'help-block'=>'The title is shown when uses search products by category')); ?>
</div> </div>
<div class="span9"> <div class="span9">
<?php echo Form::textarea('product_category_translate[description]',$o->description,array( <?php echo Form::textarea('translate[description]',$o->description,array(
'label'=>'Category Description', 'label'=>'Category Description',
'placeholder'=>'Description', 'placeholder'=>'Description',
'class'=>'span6', 'class'=>'span6',
'required', 'required',
'editor'=>'wysihtml5',
'help-block'=>'Complete description of this category')); ?> 'help-block'=>'Complete description of this category')); ?>
</div> </div>
</div> </div>
<?php echo Style::factory()->render_all(); ?>
<?php echo Script::factory()->render_all(); ?> <?php echo Script::factory()->render_all(); ?>

View File

@ -127,46 +127,12 @@ class Controller_Admin_Service extends Controller_Service {
if (isset($_POST['plugin']) AND $_POST['plugin']) { if (isset($_POST['plugin']) AND $_POST['plugin']) {
$p = $so->plugin(); $p = $so->plugin();
if ($p->values($_POST['plugin'])->changed() AND $p->check()) { if ($p->values($_POST['plugin'])->changed() AND ! $this->save($p))
try { $p->reload();
$p->values($_POST['plugin'])->save();
SystemMessage::factory()
->title('Record PLUGIN updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record PLUGIN NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$so->reload();
}
}
} }
if ($so->values($_POST)->changed() AND $so->check()) { if ($so->values($_POST)->changed() AND ! $this->save($so))
try { $so->reload();
$so->values($_POST)->save();
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$so->reload();
}
}
} }
Script::factory() Script::factory()
@ -211,10 +177,8 @@ $(document).ready(function() {
$so = ORM::factory('Service',$id); $so = ORM::factory('Service',$id);
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) { if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
$this->template->content = 'Unauthorised or doesnt exist?'; throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
return FALSE;
}
$doutput = $loutput = ''; $doutput = $loutput = '';

View File

@ -91,6 +91,12 @@ class Model_Service extends ORM_OSB {
return $format ? Currency::display($total) : $total; return $format ? Currency::display($total) : $total;
} }
public function email() {
return ORM::factory('Email_Log')
->where('module_id','=',$this->mid())
->where('module_data','=',$this);
}
/** /**
* When does this service expire * When does this service expire
*/ */

View File

@ -109,3 +109,24 @@
</fieldset> </fieldset>
</div> <!-- /row --> </div> <!-- /row -->
<?php endif ?> <?php endif ?>
<?php $x=$o->email()->find_all(); if ($x->count()) : ?>
<div class="row">
<fieldset class="span5">
<legend>Emails about this service</legend>
<?php echo Table::factory()
->data($x)
->columns(array(
'id'=>'ID',
'date_orig'=>'Date',
'resolve("subject")'=>'Subject',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','email/view/')),
))
->postproc(array(
'resolve("subject")'=>array('trim'=>45),
)); ?>
</fieldset>
</div> <!-- /row -->
<?php endif ?>

View File

@ -116,44 +116,19 @@ class Controller_Reseller_SSL extends Controller_SSL {
public function action_renew() { public function action_renew() {
$so = ORM::factory('Service',Request::current()->param('id')); $so = ORM::factory('Service',Request::current()->param('id'));
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) { if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
SystemMessage::factory() throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
->title('SSL Certificate not updated')
->type('error')
->body('Either the Service doesnt exist, or you are not authorised to see it');
HTTP::redirect('welcome');
}
$so->plugin()->renew(); $so->plugin()->renew();
HTTP::redirect(URL::link('user','service/view/'.$so->id)); HTTP::redirect(URL::link('user','service/view/'.$so->id));
} }
private function add_edit($id=NULL,$output='') { private function add_edit($id=NULL,$output='') {
$sco = ORM::factory('SSL_CA',$id); $sco = ORM::factory('SSL_CA',$id);
if ($_POST) { if ($_POST AND $sco->values($_POST)->changed() AND ! ($this->save($sco)))
// Entry updated $sco->reload();
if ($sco->values($_POST)->check()) {
try {
$sco->save();
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your Charge record has been recorded/updated.'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->body(join('<br/>',array_values($errors)));
$sco->reload();
}
}
}
return View::factory('ssl/reseller/add_edit') return View::factory('ssl/reseller/add_edit')
->set('o',$sco); ->set('o',$sco);

View File

@ -15,13 +15,13 @@ class Controller_User_SSL extends Controller_SSL {
); );
public function action_download() { public function action_download() {
$id = $_POST['sid']; $so = ORM::factory('Service',$this->request->post('sid'));
$so = ORM::factory('Service',$id);
if (! $so->loaded()) if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
HTTP::redirect('welcome/index'); throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
$passwd = $this->request->post('passwd');
$passwd = $_POST['passwd'];
if (strlen($passwd) < Kohana::$config->load('ssl')->minpass_length) { if (strlen($passwd) < Kohana::$config->load('ssl')->minpass_length) {
SystemMessage::add(array( SystemMessage::add(array(
'title'=>_('Validation failed'), 'title'=>_('Validation failed'),
@ -32,11 +32,6 @@ class Controller_User_SSL extends Controller_SSL {
HTTP::redirect(URL::link('user','service/view/'.$so->id)); HTTP::redirect(URL::link('user','service/view/'.$so->id));
} }
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) {
$this->template->content = 'Unauthorised or doesnt exist?';
return FALSE;
}
// Log the download // Log the download
$smo = $so->service_memo; $smo = $so->service_memo;
$smo->service_id = $so->id; $smo->service_id = $so->id;
@ -49,10 +44,11 @@ class Controller_User_SSL extends Controller_SSL {
openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts())); openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts()));
$x = file_get_contents($file); $x = file_get_contents($file);
unlink($file); unlink($file);
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/pks12'); $this->response->headers('Content-Type','application/pks12');
$this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"'); $this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"');
$this->response->body($x); $this->response->body($x);
$this->auto_render = FALSE;
} }
} }
?> ?>

View File

@ -1,17 +1,17 @@
<div class="row"> <div class="row">
<div class="span6"> <div class="span6">
<?php echo Form::textarea('plugin[csr]',$o->service->plugin()->csr,array('class'=>'span6','label'=>'CSR','placeholder'=>'CSR','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr))); ?> <?php echo Form::textarea('plugin[csr]',$o->service->plugin()->csr,array('class'=>'span6','label'=>'CSR','placeholder'=>'CSR','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr))); ?>
</div> </div>
</div> <!-- /row --> </div> <!-- /row -->
<div class="row"> <div class="row">
<div class="span6"> <div class="span6">
<?php echo Form::textarea('plugin[pk]',$o->service->plugin()->pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->pk))); ?> <?php echo Form::textarea('plugin[pk]',$o->service->plugin()->pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->pk))); ?>
</div> </div>
</div> <!-- /row --> </div> <!-- /row -->
<div class="row"> <div class="row">
<div class="span6"> <div class="span6">
<?php echo Form::textarea('plugin[cert]',$o->service->plugin()->cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->cert))); ?> <?php echo Form::textarea('plugin[cert]',$o->service->plugin()->cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->cert))); ?>
</div> </div>
</div> <!-- /row --> </div> <!-- /row -->

View File

@ -50,8 +50,8 @@
</div> <!-- /dl-horizontal --> </div> <!-- /dl-horizontal -->
<br/> <br/>
<?php echo Form::textarea('sign_pk',$o->sign_pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_pk))); ?> <?php echo Form::textarea('sign_pk',$o->sign_pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_pk))); ?>
<?php echo Form::textarea('sign_cert',$o->sign_cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_cert))); ?> <?php echo Form::textarea('sign_cert',$o->sign_cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_cert))); ?>
<?php echo Form::button('submit','Submit',array('class'=>'btn btn-primary')); ?> <?php echo Form::button('submit','Submit',array('class'=>'btn btn-primary')); ?>
</div> <!-- /span --> </div> <!-- /span -->