From c18d5a388177b3fd0ea978715d976f599d75419e Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 22 Nov 2013 15:36:50 +1100 Subject: [PATCH] Work on Email and other major consistency work --- .../Controller/Admin/Module/Method.php | 11 +- .../classes/Controller/Admin/Setup.php | 12 +- .../classes/Controller/Admin/Welcome.php | 22 ++ .../classes/Controller/TemplateDefault.php | 23 +- .../classes/Controller/User/Account.php | 32 +-- application/classes/Model/Account.php | 2 + application/classes/Model/Setup.php | 12 +- application/classes/ORM.php | 15 ++ application/classes/ORM/OSB.php | 6 +- application/views/theme/baseadmin/page.php | 12 +- application/views/welcome/user/shortcuts.php | 1 + .../adsl/classes/Controller/Admin/Adsl.php | 22 +- .../Controller/Reseller/Service/Adsl.php | 2 +- .../classes/Model/Service/Plugin/Adsl.php | 6 +- .../adsl/classes/Task/Adsl/Trafficalert.php | 2 + .../classes/Controller/Reseller/Charge.php | 10 +- .../email/classes/Controller/Admin/Email.php | 214 +++++++++--------- .../classes/Controller/Email/Template.php | 14 -- .../email/classes/Controller/User/Email.php | 52 ++--- modules/email/classes/Email/Template.php | 114 ++++++---- modules/email/classes/Model/Email/Log.php | 12 +- .../email/classes/Model/Email/Template.php | 23 +- .../Model/Email/Template/Translate.php | 26 ++- .../views/email/admin/add_edit_template.php | 38 ++++ .../email/admin/ajaxtemplatetranslate.php | 30 +++ .../email/views/email/admin/templateadd.php | 14 -- .../email/admin/templateadd/translate.php | 18 -- .../email/views/email/admin/templateedit.php | 14 -- .../email/admin/templateedit/translate.php | 18 -- .../views/email/admin/templatelist/body.php | 4 - .../views/email/admin/templatelist/foot.php | 1 - .../views/email/admin/templatelist/head.php | 6 - modules/email/views/email/user/view.php | 52 +++-- .../classes/Controller/Admin/Export.php | 22 +- modules/highchart | 2 +- .../classes/Controller/User/Invoice.php | 3 + modules/invoice/classes/Model/Invoice.php | 8 +- .../invoice/classes/Model/Invoice/Item.php | 8 +- modules/lnApp | 2 +- .../classes/Controller/Admin/Payment.php | 7 +- modules/payment/classes/Model/Payment.php | 2 +- .../classes/Controller/Admin/Product.php | 8 +- modules/product/classes/Model/Product.php | 33 ++- .../classes/Model/Product/Category.php | 31 ++- .../Model/Product/Category/Translate.php | 2 + .../classes/Model/Product/Translate.php | 2 + .../views/product/admin/ajaxtranslate.php | 10 +- .../product/category/admin/ajaxtranslate.php | 7 +- .../classes/Controller/Admin/Service.php | 48 +--- modules/service/classes/Model/Service.php | 6 + modules/service/views/service/user/view.php | 21 ++ .../ssl/classes/Controller/Reseller/Ssl.php | 35 +-- modules/ssl/classes/Controller/User/Ssl.php | 18 +- .../views/service/admin/plugin/ssl/edit.php | 6 +- modules/ssl/views/ssl/reseller/add_edit.php | 4 +- 55 files changed, 550 insertions(+), 575 deletions(-) create mode 100644 application/classes/Controller/Admin/Welcome.php delete mode 100644 modules/email/classes/Controller/Email/Template.php create mode 100644 modules/email/views/email/admin/add_edit_template.php create mode 100644 modules/email/views/email/admin/ajaxtemplatetranslate.php delete mode 100644 modules/email/views/email/admin/templateadd.php delete mode 100644 modules/email/views/email/admin/templateadd/translate.php delete mode 100644 modules/email/views/email/admin/templateedit.php delete mode 100644 modules/email/views/email/admin/templateedit/translate.php delete mode 100644 modules/email/views/email/admin/templatelist/body.php delete mode 100644 modules/email/views/email/admin/templatelist/foot.php delete mode 100644 modules/email/views/email/admin/templatelist/head.php diff --git a/application/classes/Controller/Admin/Module/Method.php b/application/classes/Controller/Admin/Module/Method.php index 51c046d7..b018b4d2 100644 --- a/application/classes/Controller/Admin/Module/Method.php +++ b/application/classes/Controller/Admin/Module/Method.php @@ -29,14 +29,9 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module { $mmo->module_id = $mo->id; $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))); - SystemMessage::factory() - ->title('Record added') - ->type('success') - ->body(_('Method record has been added.')); - HTTP::redirect(URL::link('admin','module/edit/'.$mo->id)); } @@ -69,7 +64,7 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module { if ($_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))); 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, )); - if (! $gmo->check() OR ! $gmo->save()) + if (! $this->save($gmo)) SystemMessage::factory() ->title(_('Unable to SAVE Group Method')) ->type('error') diff --git a/application/classes/Controller/Admin/Setup.php b/application/classes/Controller/Admin/Setup.php index 8b45a2f5..581803d5 100644 --- a/application/classes/Controller/Admin/Setup.php +++ b/application/classes/Controller/Admin/Setup.php @@ -20,16 +20,8 @@ class Controller_Admin_Setup extends Controller_TemplateDefault { public function action_edit() { $o = Company::instance()->so(); - // Store our new values - $o->values($_POST); - - // 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.')); + if ($_POST AND $o->values($_POST)->changed() AND (! $this->save($o))) + $o->reload(); Block::factory() ->title('Update Site Configuration') diff --git a/application/classes/Controller/Admin/Welcome.php b/application/classes/Controller/Admin/Welcome.php new file mode 100644 index 00000000..b21b4f2e --- /dev/null +++ b/application/classes/Controller/Admin/Welcome.php @@ -0,0 +1,22 @@ +TRUE, + ); + + public function action_index() { + HTTP::redirect(URL::link('reseller','welcome')); + } +} +?> diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php index 2103ad3a..5a06bd5c 100644 --- a/application/classes/Controller/TemplateDefault.php +++ b/application/classes/Controller/TemplateDefault.php @@ -50,17 +50,29 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau 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('
',array_values($e->errors('models')))); + + return FALSE; + } + } + protected function setup(array $config_items=array()) { $mo = ORM::factory('Module',array('name'=>Request::current()->controller())); if (! $mo->loaded()) throw HTTP_Exception::factory(501,'Unknown module :module',array(':module'=>Request::current()->controller())); if ($_POST AND isset($_POST['module_config'][$mo->id])) - if (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.')); + Config::instance()->module_config($mo->name,$_POST['module_config'][$mo->id])->save(); if ($config_items) { Block::factory() @@ -68,7 +80,6 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau ->title_icon('icon-wrench') ->type('form-horizontal') ->body(View::factory('setup/admin/module')->set('o',Company::instance()->so())->set('mid',$mo->id)); - } } } diff --git a/application/classes/Controller/User/Account.php b/application/classes/Controller/User/Account.php index eec23589..f274c520 100644 --- a/application/classes/Controller/User/Account.php +++ b/application/classes/Controller/User/Account.php @@ -19,34 +19,8 @@ class Controller_User_Account extends Controller_Account { * Enable User to Edit their Account Details */ public function action_edit() { - // Store our new values - $this->ao->values($_POST); - - // 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('
  • %s %s
  • ',$field,$error); - - if ($output) - $output = sprintf('',$output); - - SystemMessage::factory() - ->title(_('Record NOT updated')) - ->type('error') - ->body(_('Your updates didnt pass validation.').'
    '.$output); - } + if ($_POST AND $this->ao->values($_POST)->changed() AND (! $this->save($this->ao))) + $this->ao->reload(); Block::factory() ->title(sprintf('Account: %s',$this->ao->accnum())) @@ -70,7 +44,7 @@ class Controller_User_Account extends Controller_Account { ->title(_('Record NOT updated')) ->type('error') ->body(_('Your password didnt pass validation.')); - + // Run validation and save elseif ($this->ao->changed()) if ($this->ao->save()) { diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index 69979717..fd381619 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -40,6 +40,8 @@ class Model_Account extends Model_Auth_UserDefault { ), ); + protected $_save_message = TRUE; + /** * Our account number format */ diff --git a/application/classes/Model/Setup.php b/application/classes/Model/Setup.php index a6c829f2..78602968 100644 --- a/application/classes/Model/Setup.php +++ b/application/classes/Model/Setup.php @@ -22,8 +22,18 @@ class Model_Setup extends ORM_OSB { 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), ); + protected $_save_message = TRUE; + + // Validation 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. unset($r['site_id']); diff --git a/application/classes/ORM.php b/application/classes/ORM.php index e38e3696..3d0ff2bb 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -22,6 +22,9 @@ abstract class ORM extends Kohana_ORM { // Tables that do not have a site_id column 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 * @see parent::__build() @@ -215,6 +218,18 @@ abstract class ORM extends Kohana_ORM { 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() { return $this->_where_active(); } diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php index fe3f218b..0cecfd1c 100644 --- a/application/classes/ORM/OSB.php +++ b/application/classes/ORM/OSB.php @@ -202,7 +202,7 @@ abstract class ORM_OSB extends ORM { 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. if ($this->_changed) 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)) { $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); diff --git a/application/views/theme/baseadmin/page.php b/application/views/theme/baseadmin/page.php index 1cbd5daf..0a296405 100644 --- a/application/views/theme/baseadmin/page.php +++ b/application/views/theme/baseadmin/page.php @@ -18,14 +18,10 @@ 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/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 { 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/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'); @@ -73,7 +69,7 @@ get_user()) AND $ao->isAdmin()) : ?>
  • - Admin + Admin
  • isReseller()) : ?>
  • @@ -109,16 +105,10 @@ 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/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'); } else { 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'); - // @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'); } diff --git a/application/views/welcome/user/shortcuts.php b/application/views/welcome/user/shortcuts.php index 98762d2a..184c5279 100644 --- a/application/views/welcome/user/shortcuts.php +++ b/application/views/welcome/user/shortcuts.php @@ -1,4 +1,5 @@ diff --git a/modules/adsl/classes/Controller/Admin/Adsl.php b/modules/adsl/classes/Controller/Admin/Adsl.php index 5f4c32e1..fe60bf61 100644 --- a/modules/adsl/classes/Controller/Admin/Adsl.php +++ b/modules/adsl/classes/Controller/Admin/Adsl.php @@ -68,26 +68,8 @@ class Controller_Admin_Adsl extends Controller_Adsl { HTTP::redirect(URL::link('admin','adsl/list')); if ($_POST) { - // Entry updated - if ($apo->values($_POST)->check() AND $apo->changed()) { - 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('
    ',array_values($errors))); - - $sco->reload(); - } - } + if ($apo->values($_POST)->changed() AND (! $this->save($apo))) + $apo->reload(); if (isset($_POST['test'])) { $charge = isset($_POST['test']['charge']) ? $_POST['test']['charge'] : FALSE; diff --git a/modules/adsl/classes/Controller/Reseller/Service/Adsl.php b/modules/adsl/classes/Controller/Reseller/Service/Adsl.php index 350671d4..c4b83c52 100644 --- a/modules/adsl/classes/Controller/Reseller/Service/Adsl.php +++ b/modules/adsl/classes/Controller/Reseller/Service/Adsl.php @@ -43,7 +43,7 @@ class Controller_Reseller_Service_Adsl extends Controller_Service { public function action_list() { $highchart = HighChart::factory('Combo'); $highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday')))); - $highchart->xmetric('MB'); + $highchart->ymetric('MB'); $c = 0; foreach ($this->consoltraffic(time()) as $k => $details) { diff --git a/modules/adsl/classes/Model/Service/Plugin/Adsl.php b/modules/adsl/classes/Model/Service/Plugin/Adsl.php index 1bcfe73a..2cf6bd68 100644 --- a/modules/adsl/classes/Model/Service/Plugin/Adsl.php +++ b/modules/adsl/classes/Model/Service/Plugin/Adsl.php @@ -352,9 +352,9 @@ $(document).ready(function() { $highchart = HighChart::factory('Combo'); switch ($this->plan()->metric) { - case '1000' : $highchart->xmetric('GB'); break; - case '1' : $highchart->xmetric('MB'); break; - default: $highchart->xmetric('?'); + case '1000' : $highchart->ymetric('GB'); break; + case '1' : $highchart->ymetric('MB'); break; + default: $highchart->ymetric('?'); } $c=0; diff --git a/modules/adsl/classes/Task/Adsl/Trafficalert.php b/modules/adsl/classes/Task/Adsl/Trafficalert.php index 3b0662d6..32ba9a24 100644 --- a/modules/adsl/classes/Task/Adsl/Trafficalert.php +++ b/modules/adsl/classes/Task/Adsl/Trafficalert.php @@ -31,6 +31,8 @@ class Task_Adsl_Trafficalert extends Minion_Task { // Get our variable data $et->to = array('account'=>array($so->account_id)); $et->variables = $so->plugin()->template_variables($et->variables(),$data); + $et->module = $so->mid(); + $et->module_data = $so->id; $et->send(); diff --git a/modules/charge/classes/Controller/Reseller/Charge.php b/modules/charge/classes/Controller/Reseller/Charge.php index 3c5a0f41..68bb0f28 100644 --- a/modules/charge/classes/Controller/Reseller/Charge.php +++ b/modules/charge/classes/Controller/Reseller/Charge.php @@ -54,14 +54,8 @@ class Controller_Reseller_Charge extends Controller_Charge { private function add_edit($id=NULL,$output='') { $co = ORM::factory('Charge',$id); - if ($_POST) { - // Entry updated - if ($co->values($_POST)->check() AND $co->save()) - SystemMessage::factory() - ->title('Record updated') - ->type('success') - ->body(_('Your Charge record has been recorded/updated.')); - } + if ($_POST AND $co->values($_POST)->changed() AND (! $this->save($co))) + $co->reload(); Script::factory() ->type('file') diff --git a/modules/email/classes/Controller/Admin/Email.php b/modules/email/classes/Controller/Admin/Email.php index 453c575f..570364ca 100644 --- a/modules/email/classes/Controller/Admin/Email.php +++ b/modules/email/classes/Controller/Admin/Email.php @@ -11,90 +11,87 @@ */ class Controller_Admin_Email extends Controller_Email { protected $secure_actions = array( + 'ajaxtemplatetranslate'=>TRUE, 'list'=>TRUE, 'templateadd'=>TRUE, 'templateedit'=>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 */ public function action_list() { - Block::add(array( - 'title'=>_('System Emails Sent'), - 'body'=>Table::display( - ORM::factory('Email_Log')->find_all(), - 25, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('user','email/view/')), - 'date_orig'=>array('label'=>'Date'), - 'email'=>array('label'=>'To'), - 'translate_resolve("subject")'=>array('label'=>'Subject'), - 'account->accnum()'=>array('label'=>'Cust ID'), - 'account->name()'=>array('label'=>'Customer'), - ), - array( - 'page'=>TRUE, - 'type'=>'select', - 'form'=>URL::link('user','email/view'), - )), - )); - } - - /** - * 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, - )); + Block::factory() + ->title(_('System Emails Sent')) + ->title_icon('icon-th') + ->body(Table::factory() + ->page_items(25) + ->data(ORM::factory('Email_Log')->find_all()) + ->columns(array( + 'id'=>'ID', + 'date_orig'=>'Date', + 'email'=>'To', + 'resolve("subject")'=>'Subject', + 'account->accnum()'=>'Cust ID', + 'account->name()'=>'Customer', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','email/view/')), + )) + ->postproc(array( + 'resolve("subject")'=>array('trim'=>60), + )) + ); } /** * Add a template */ public function action_templateadd() { - $eto = ORM::factory('Email_Template'); - $output = ''; + Block::factory() + ->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 - $eto->email_setup_id=1; - - // Entry updated - if ($eto->save()) { - $x = $eto->email_template_translate->values($_POST['translate']['new']); - - $x->email_template_id = $eto->id; - if ($x->check()) - $x->save(); - } - } - - $output .= Form::open(); - $output .= View::factory($this->viewpath()); - $output .= View::factory($this->viewpath().'/translate'); - $output .= '
    '.Form::submit('submit',_('Add'),array('class'=>'form_button')).'
    '; - $output .= Form::close(); - - Editor::add(); - Block::add(array( - 'title'=>_('Available Email Templates'), - 'body'=>$output, - )); + /** + * List our defined email templates + */ + public function action_templatelist() { + Block::factory() + ->title(_('System Emails Templates Available')) + ->title_icon('icon-th') + ->body(Table::factory() + ->page_items(25) + ->data(ORM::factory('Email_Template')->find_all()) + ->columns(array( + 'id'=>'ID', + 'name'=>'Name', + 'status'=>'Active', + 'description'=>'Descrption', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('admin','email/templateedit/')), + )) + ); } /** @@ -102,51 +99,64 @@ class Controller_Admin_Email extends Controller_Email { * @todo Change this into an add_view function like payment() */ 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); - if (! $eto->loaded()) - HTTP::redirect(URL::link('admin','email/template/list')); + if ($_POST) { + // @todo To update the setup ID + $eto->email_setup_id = '1'; - $output = ''; - - 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(); - } - } + if (! $this->save($eto)) + $eto->reload(); } + 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 .= View::factory($this->viewpath()) - ->set('template',$eto); - - 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 .= '
    '.Form::submit('submit',_('Update'),array('class'=>'form_button')).'
    '; + $output .= View::factory($this->viewpath()); + $output .= View::factory($this->viewpath().'/translate'); + $output .= '
    '.Form::submit('submit',_('Add'),array('class'=>'form_button')).'
    '; $output .= Form::close(); - Editor::add(); Block::add(array( - 'title'=>sprintf(_('Edit Template '),$eto->name), + 'title'=>_('Available Email Templates'), 'body'=>$output, )); } diff --git a/modules/email/classes/Controller/Email/Template.php b/modules/email/classes/Controller/Email/Template.php deleted file mode 100644 index d2c602a1..00000000 --- a/modules/email/classes/Controller/Email/Template.php +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/modules/email/classes/Controller/User/Email.php b/modules/email/classes/Controller/User/Email.php index beccbbc5..29384712 100644 --- a/modules/email/classes/Controller/User/Email.php +++ b/modules/email/classes/Controller/User/Email.php @@ -9,7 +9,7 @@ * @copyright (c) 2009-2013 Open Source Billing * @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( 'list'=>TRUE, 'view'=>TRUE, @@ -19,22 +19,24 @@ class Controller_User_Email extends Controller_TemplateDefault_User { * Show a list of emails */ public function action_list() { - Block::add(array( - 'title'=>sprintf('%s: %s - %s',_('Email For'),$this->ao->accnum(),$this->ao->name(TRUE)), - 'body'=>Table::display( - $this->ao->email_log->find_all(), - 25, - array( - 'id'=>array('label'=>'ID','url'=>URL::link('user','email/view/')), - 'date_orig'=>array('label'=>'Date'), - 'translate_resolve("subject")'=>array('label'=>'Subject'), - ), - array( - 'page'=>TRUE, - 'type'=>'select', - 'form'=>URL::link('user','email/view'), - )), - )); + Block::factory() + ->title(sprintf(_('System Emails Sent for %s: %s'),$this->ao->accnum(),$this->ao->name(TRUE))) + ->title_icon('icon-th') + ->body(Table::factory() + ->page_items(25) + ->data($this->ao->email_log->find_all()) + ->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'=>60), + )) + ); } public function action_view() { @@ -42,18 +44,16 @@ class Controller_User_Email extends Controller_TemplateDefault_User { $elo = ORM::factory('Email_Log',$id); - if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account)) { - $this->template->content = 'Unauthorised or doesnt exist?'; - return FALSE; - } + if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account)) + throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); - $output .= View::factory($this->viewpath()) + $output .= View::factory('email/user/view') ->set('elo',$elo); - Block::add(array( - 'title'=>sprintf('%s: %s',_('Email'),$elo->translate_resolve('subject')), - 'body'=>$output, - )); + Block::factory() + ->title(sprintf('%s: %s',$elo->id,$elo->resolve('subject'))) + ->title_icon('icon-list-alt') + ->body($output); } } ?> diff --git a/modules/email/classes/Email/Template.php b/modules/email/classes/Email/Template.php index 282a8cd8..d7592e1a 100644 --- a/modules/email/classes/Email/Template.php +++ b/modules/email/classes/Email/Template.php @@ -10,31 +10,32 @@ * @license http://dev.osbill.net/license.html */ class Email_Template { - // We'll store the template here - private $template; - private $etto; - private $email_data = array(); - // @todo Default lang should be the site setup - private $default_lang = 1; - private $components = array('subject','message_text','message_html'); + // Our components that need resolving + private $_components = array('subject','message_text','message_html'); + // Our Email Data + private $_data = array(); + // Our Email Template Object + private $_etto; 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)); 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(); - if (! $this->etto->loaded()) - $this->etto = $this->template->email_template_translate->where('language_id','=',$this->default_lang)->find(); + $this->_etto = $eto->translate + ->where_open() + ->where('language_id','=',$language_id) + ->or_where('language_id','=',Config::language()) + ->where_close() + ->find(); - // @todo Change this to log/email the admin - return; - #throw new Kohana_Exception('No template (:template) found for user language (:language_id) or default language (:default_lang)', - # array(':template'=>$this->template->name,':language_id'=>$language_id,':default_lang'=>$this->default_lang)); + if (! $this->_etto->loaded()) + 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())); } 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))) 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; case 'variables': @@ -52,7 +61,7 @@ class Email_Template { if (! is_array($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; default: @@ -64,16 +73,16 @@ class Email_Template { switch ($key) { case 'bcc': case 'to': - if (empty($this->email_data[$key])) + if (empty($this->_data[$key])) return array(); - elseif (isset($this->email_data[$key]['email'])) - return $this->email_data[$key]['email']; + elseif (isset($this->_data[$key]['email'])) + return $this->_data[$key]['email']; - elseif (isset($this->email_data[$key]['account'])) { + elseif (isset($this->_data[$key]['account'])) { $list = array(); - foreach ($this->email_data[$key]['account'] as $id) { + foreach ($this->_data[$key]['account'] as $id) { $ao = ORM::factory('Account',$id); if ($ao->loaded()) $list[$ao->email] = $ao->name(); @@ -85,7 +94,7 @@ class Email_Template { break; case 'variables': - return $this->email_data[$key]; + return $this->_data[$key]; default: 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); } - 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()) { $e = Email::connect(); $sm = Swift_Message::newInstance() ->setFrom(Kohana::$config->load('config')->email_from); - foreach ($this->components as $component) { - if ($this->etto->loaded()) { - $s = $this->etto->rresolve($this->email_data['variables'],$component); + foreach ($this->_components as $component) { + if ($this->_etto->loaded()) { + $s = $this->_etto->complete($this->_data['variables'],$component); switch ($component) { case 'message_html': @@ -132,14 +130,14 @@ class Email_Template { } } else { $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); - if ($admin OR ($admin = Config::testmail($this->template->name))) { + if ($admin OR ($admin = Config::testmail($this->_etto->template->name))) { $sm->setTo($admin); $sa = array(1); @@ -153,18 +151,22 @@ class Email_Template { // Store our email log. $elo = ORM::factory('Email_Log'); - if ($result) { - + if ($result) foreach ($sa as $id) { $elo->clear(); $elo->account_id = $id; $elo->email = implode(',',array_keys($this->to)); - $elo->email_template_translate_id = $this->etto->id; - $elo->data = $this->email_data['variables']; + $elo->email_template_translate_id = $this->_etto->id; + $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(); } - } return ($result AND $elo->saved()) ? $elo->id : $result; } @@ -173,10 +175,24 @@ class Email_Template { // @todo Set the default account in a configuration file. $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 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; } } ?> diff --git a/modules/email/classes/Model/Email/Log.php b/modules/email/classes/Model/Email/Log.php index b07b27ad..dab53317 100644 --- a/modules/email/classes/Model/Email/Log.php +++ b/modules/email/classes/Model/Email/Log.php @@ -15,7 +15,7 @@ class Model_Email_Log extends ORM_OSB { protected $_belongs_to = array( '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( @@ -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))) - return $this->email_template_translate->display($column); - else - return $this->email_template_translate->rresolve($this->data,$column); + /** + * Resolve a data variable into + */ + public function resolve($column) { + return (! $this->data OR ! $this->translate->variables($column)) ? $this->translate->display($column) : $this->translate->complete($this->data,$column); } } ?> diff --git a/modules/email/classes/Model/Email/Template.php b/modules/email/classes/Model/Email/Template.php index 9e1d8cc4..18cd1a33 100644 --- a/modules/email/classes/Model/Email/Template.php +++ b/modules/email/classes/Model/Email/Template.php @@ -10,7 +10,7 @@ */ class Model_Email_Template extends ORM_OSB { 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 @@ -27,8 +27,29 @@ class Model_Email_Template extends ORM_OSB { ), ); + protected $_save_message = TRUE; + public function 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; + } } ?> diff --git a/modules/email/classes/Model/Email/Template/Translate.php b/modules/email/classes/Model/Email/Template/Translate.php index e49f136a..38050d7d 100644 --- a/modules/email/classes/Model/Email/Template/Translate.php +++ b/modules/email/classes/Model/Email/Template/Translate.php @@ -13,11 +13,26 @@ class Model_Email_Template_Translate extends ORM_OSB { protected $_created_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) { $results = 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) $results[$v[1]] = $v[0]; @@ -27,14 +42,5 @@ class Model_Email_Template_Translate extends ORM_OSB { 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; - } } ?> diff --git a/modules/email/views/email/admin/add_edit_template.php b/modules/email/views/email/admin/add_edit_template.php new file mode 100644 index 00000000..6acb7e09 --- /dev/null +++ b/modules/email/views/email/admin/add_edit_template.php @@ -0,0 +1,38 @@ +
    +
    +
    +
    + name,array('label'=>'Name','class'=>'span3')); ?> +
    +
    + +
    +
    + status,FALSE,array('label'=>'Email Template Active','class'=>'span1')); ?> +
    +
    + +
    +
    + notes,array('label'=>'Notes','class'=>'span8')); ?> +
    +
    + +
    +
    + list_select(TRUE),'',array('label'=>'Language','required')); ?> +
    +
    + +
    +
    +
    + +
    +
    + + +
    +
    +
    +
    diff --git a/modules/email/views/email/admin/ajaxtemplatetranslate.php b/modules/email/views/email/admin/ajaxtemplatetranslate.php new file mode 100644 index 00000000..3094b462 --- /dev/null +++ b/modules/email/views/email/admin/ajaxtemplatetranslate.php @@ -0,0 +1,30 @@ +
    +
    + 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')))))); ?> +
    +
    + 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')))))); ?> +
    +
    + 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')))))); ?>' +
    +
    + +render_all(); ?> +render_all(); ?> diff --git a/modules/email/views/email/admin/templateadd.php b/modules/email/views/email/admin/templateadd.php deleted file mode 100644 index 2bf0fc33..00000000 --- a/modules/email/views/email/admin/templateadd.php +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - -
    Name:30)); ?>
    Active:
    Notes:80)); ?>
    diff --git a/modules/email/views/email/admin/templateadd/translate.php b/modules/email/views/email/admin/templateadd/translate.php deleted file mode 100644 index 80c32905..00000000 --- a/modules/email/views/email/admin/templateadd/translate.php +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - -
    Language:5)); ?>
    Subject:80)); ?>
    Text:120,'rows'=>10)); ?>
    HTML:120,'rows'=>10,'class'=>'mceEditor')); ?>
    diff --git a/modules/email/views/email/admin/templateedit.php b/modules/email/views/email/admin/templateedit.php deleted file mode 100644 index 16faada0..00000000 --- a/modules/email/views/email/admin/templateedit.php +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - -
    Name:name,array('size'=>30)); ?>
    Active:status); ?>
    Notes:notes,array('size'=>80)); ?>
    diff --git a/modules/email/views/email/admin/templateedit/translate.php b/modules/email/views/email/admin/templateedit/translate.php deleted file mode 100644 index 01b44829..00000000 --- a/modules/email/views/email/admin/templateedit/translate.php +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - -
    Language:id),$translate->language_id,array('size'=>5)); ?>
    Subject:id),$translate->subject,array('size'=>80)); ?>
    Text:id),$translate->message_text,array('cols'=>120,'rows'=>10)); ?>
    HTML:id),$translate->message_html,array('cols'=>120,'rows'=>20,'class'=>'mceEditor')); ?>
    diff --git a/modules/email/views/email/admin/templatelist/body.php b/modules/email/views/email/admin/templatelist/body.php deleted file mode 100644 index f9570eeb..00000000 --- a/modules/email/views/email/admin/templatelist/body.php +++ /dev/null @@ -1,4 +0,0 @@ - - name; ?> - display('status'); ?> - diff --git a/modules/email/views/email/admin/templatelist/foot.php b/modules/email/views/email/admin/templatelist/foot.php deleted file mode 100644 index 000ca4b0..00000000 --- a/modules/email/views/email/admin/templatelist/foot.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/modules/email/views/email/admin/templatelist/head.php b/modules/email/views/email/admin/templatelist/head.php deleted file mode 100644 index 6a428ae1..00000000 --- a/modules/email/views/email/admin/templatelist/head.php +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/modules/email/views/email/user/view.php b/modules/email/views/email/user/view.php index 40fcabd4..db7168e9 100644 --- a/modules/email/views/email/user/view.php +++ b/modules/email/views/email/user/view.php @@ -1,20 +1,32 @@ -
    TemplateActive
    - - - - - - - - - - - - -
    To:account->name(),$elo->display('email')); ?>
    Date:display('date_orig'); ?>
    Subject:translate_resolve('subject'); ?>
    - - - - -
    translate_resolve('message_html'); ?>
    -
    +
    +
    + + + + + + + + + + + + + + + + + + + + +
    To:account->name(),$elo->display('email')); ?>
    Date:display('date_orig'); ?>
    Subject:resolve('subject'); ?>

    + + + + +
    resolve('message_html'); ?>
    +
    + +
    +
    diff --git a/modules/export/classes/Controller/Admin/Export.php b/modules/export/classes/Controller/Admin/Export.php index 05a9cb1e..08a50772 100644 --- a/modules/export/classes/Controller/Admin/Export.php +++ b/modules/export/classes/Controller/Admin/Export.php @@ -25,16 +25,10 @@ class Controller_Admin_Export extends Controller_Export { $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; - if (! $edo->save()) - 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.')); + $this->save($edo); } Block::factory() @@ -87,16 +81,8 @@ class Controller_Admin_Export extends Controller_Export { if ($_POST AND isset($_POST['export_module_id'])) { $emo = ORM::factory('Export_Module',$_POST['export_module_id']); - if ($emo->loaded()) { - $emo->values($_POST); - $emo->save(); - - if ($emo->saved()) - SystemMessage::factory() - ->title('Record updated') - ->type('success') - ->body(_('Export Module record has been updated.')); - } + if ($emo->loaded() AND $emo->values($_POST)->changed() AND ! $this->save($emo)) + $emo->reload(); } if ($x = $this->request->param('id')) { diff --git a/modules/highchart b/modules/highchart index 9ed797b1..4bd8d1ff 160000 --- a/modules/highchart +++ b/modules/highchart @@ -1 +1 @@ -Subproject commit 9ed797b1d2e9a2b3b8227bbb42be01ea620916d4 +Subproject commit 4bd8d1ffae3d89ee85de63e1a80a3d7aeb7b0fa5 diff --git a/modules/invoice/classes/Controller/User/Invoice.php b/modules/invoice/classes/Controller/User/Invoice.php index 340c2896..e6c75969 100644 --- a/modules/invoice/classes/Controller/User/Invoice.php +++ b/modules/invoice/classes/Controller/User/Invoice.php @@ -22,6 +22,9 @@ class Controller_User_Invoice extends Controller_Invoice { public function action_download() { $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 $imo = $io->invoice_memo; $imo->invoice_id = $io->id; diff --git a/modules/invoice/classes/Model/Invoice.php b/modules/invoice/classes/Model/Invoice.php index 532289ef..c2ac392c 100644 --- a/modules/invoice/classes/Model/Invoice.php +++ b/modules/invoice/classes/Model/Invoice.php @@ -215,7 +215,6 @@ class Model_Invoice extends ORM_OSB implements Cartable { return $format ? Currency::display($result) : $result; } -//ZZ /** * 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()) 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(); if (! $iio->saved()) { @@ -548,7 +542,7 @@ class Model_Invoice extends ORM_OSB implements Cartable { } else throw new Kohana_Exception('Couldnt save invoice for some reason?'); - return TRUE; + return $this; } public function set_remind($key,$value,$add=FALSE) { diff --git a/modules/invoice/classes/Model/Invoice/Item.php b/modules/invoice/classes/Model/Invoice/Item.php index c485b8f0..8cd1c51e 100644 --- a/modules/invoice/classes/Model/Invoice/Item.php +++ b/modules/invoice/classes/Model/Invoice/Item.php @@ -188,9 +188,6 @@ class Model_Invoice_Item extends ORM_OSB { } public function save(Validation $validation = NULL) { - if (! $this->changed()) - return; - // Save the invoice item parent::save($validation); @@ -214,9 +211,6 @@ class Model_Invoice_Item extends ORM_OSB { // @todo Rounding here should come from a global config $iito->amount = round($tax['amount'],2); - if (! $iito->check()) - throw new Kohana_Exception('Couldnt save tax for some reason - failed check()?'); - $iito->save(); if (! $iito->saved()) @@ -224,6 +218,8 @@ class Model_Invoice_Item extends ORM_OSB { } } else throw new Kohana_Exception('Couldnt save invoice_item for some reason?'); + + return $this; } } ?> diff --git a/modules/lnApp b/modules/lnApp index 610c223c..1ec370f0 160000 --- a/modules/lnApp +++ b/modules/lnApp @@ -1 +1 @@ -Subproject commit 610c223cb823f2b16df3e1f49912e8ef42dc6bd7 +Subproject commit 1ec370f07af319e5deda43dce6585ad9e0240c18 diff --git a/modules/payment/classes/Controller/Admin/Payment.php b/modules/payment/classes/Controller/Admin/Payment.php index a49378c2..b5a5f976 100644 --- a/modules/payment/classes/Controller/Admin/Payment.php +++ b/modules/payment/classes/Controller/Admin/Payment.php @@ -96,12 +96,7 @@ class Controller_Admin_Payment extends Controller_Payment { $pio->alloc_amt = is_numeric($v) ? $v : 0; } - // Entry updated - if ($po->values($_POST)->check() AND $po->save()) - SystemMessage::factory() - ->title('Record updated') - ->type('success') - ->body(_('Your Payment record has been recorded/updated.')); + $this->save($po); } Script::factory() diff --git a/modules/payment/classes/Model/Payment.php b/modules/payment/classes/Model/Payment.php index ca601698..746a345c 100644 --- a/modules/payment/classes/Model/Payment.php +++ b/modules/payment/classes/Model/Payment.php @@ -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)); } - return TRUE; + return $this; } /** diff --git a/modules/product/classes/Controller/Admin/Product.php b/modules/product/classes/Controller/Admin/Product.php index 4317000b..be1bd2b9 100644 --- a/modules/product/classes/Controller/Admin/Product.php +++ b/modules/product/classes/Controller/Admin/Product.php @@ -65,8 +65,8 @@ class Controller_Admin_Product extends Controller_Product { if (! $pco->loaded()) HTTP::redirect(URL::link('admin','product/list')); - if ($_POST) - $pco->values($_POST)->save(); + if ($_POST AND $pco->values($_POST)->changed() AND (! $this->save($pco))) + $pco->reload(); Script::factory() ->type('stdin') @@ -113,8 +113,8 @@ $(document).ready(function() { if (! $po->loaded()) HTTP::redirect('welcome/index'); - if ($_POST) - $po->values($_POST)->save(); + if ($_POST AND $po->values($_POST)->changed() AND (! $this->save($po))) + $po->reload(); Script::factory() ->type('stdin') diff --git a/modules/product/classes/Model/Product.php b/modules/product/classes/Model/Product.php index d5e0d73c..67e5ca5b 100644 --- a/modules/product/classes/Model/Product.php +++ b/modules/product/classes/Model/Product.php @@ -14,9 +14,9 @@ */ class Model_Product extends ORM_OSB { protected $_has_many = array( - 'product_translate'=>array('far_key'=>'id'), - 'service'=>array('far_key'=>'id'), 'invoice'=>array('through'=>'invoice_item'), + 'service'=>array('far_key'=>'id'), + 'translate'=>array('model'=>'Product_Translate','far_key'=>'id'), ); protected $_sorting = array( @@ -44,6 +44,8 @@ class Model_Product extends ORM_OSB { 'price_group', ); + protected $_save_message = TRUE; + /** * Which categories is this product available in */ @@ -106,29 +108,22 @@ class Model_Product extends ORM_OSB { } public function save(Validation $validation=NULL) { - if ($this->changed()) - if (parent::save($validation)) - SystemMessage::factory() - ->title('Record Updated') - ->type('success') - ->body(sprintf('Record %s Updated',$this->id)); + parent::save($validation); // 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'])) { - $pto = $this->product_translate->where('language_id','=',$_POST['language_id'])->find(); + 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 (! $pto->loaded()) { - $pto->product_id = $this->id; - $pto->language_id = $_POST['language_id']; + if (! $to->loaded()) { + $to->product_id = $this->id; + $to->language_id = $_POST['language_id']; } - if ($pto->values($x['product_translate'])->save()) - SystemMessage::factory() - ->title('Record Updated') - ->type('success') - ->body(sprintf('Translation for Record %s Updated',$this->id)); + $to->values($x['translate'])->save(); } + + return $this; } /** @@ -143,7 +138,7 @@ class Model_Product extends ORM_OSB { } private function translate() { - return $this->product_translate->where('language_id','=',Config::language())->find(); + return $this->translate->where('language_id','=',Config::language())->find(); } /** diff --git a/modules/product/classes/Model/Product/Category.php b/modules/product/classes/Model/Product/Category.php index cda202c2..154cce6c 100644 --- a/modules/product/classes/Model/Product/Category.php +++ b/modules/product/classes/Model/Product/Category.php @@ -20,14 +20,16 @@ class Model_Product_Category extends ORM_OSB { ); 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'), + 'translate'=>array('model'=>'Product_Category_Translate','foreign_key'=>'product_cat_id','far_key'=>'id'), ); protected $_sorting = array( 'position'=>'ASC', ); + protected $_save_message = TRUE; + /** * Return the translated description for a category. */ @@ -51,29 +53,22 @@ class Model_Product_Category extends ORM_OSB { } public function save(Validation $validation=NULL) { - if ($this->changed()) - if (parent::save($validation)) - SystemMessage::factory() - ->title('Record Updated') - ->type('success') - ->body(sprintf('Record %s Updated',$this->id)); + parent::save($validation); // 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'])) { - $pcto = $this->product_category_translate->where('language_id','=',$_POST['language_id'])->find(); + 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_cat_id - if (! $pcto->loaded()) { - $pcto->product_cat_id = $this->id; - $pcto->language_id = $_POST['language_id']; + if (! $to->loaded()) { + $to->product_cat_id = $this->id; + $to->language_id = $_POST['language_id']; } - if ($pcto->values($x['product_category_translate'])->save()) - SystemMessage::factory() - ->title('Record Updated') - ->type('success') - ->body(sprintf('Translation for Record %s Updated',$this->id)); + $to->values($x['translate'])->save(); } + + return $this; } /** @@ -111,7 +106,7 @@ class Model_Product_Category extends ORM_OSB { private function translate() { - return $this->product_category_translate->where('language_id','=',Config::language())->find(); + return $this->translate->where('language_id','=',Config::language())->find(); } } ?> diff --git a/modules/product/classes/Model/Product/Category/Translate.php b/modules/product/classes/Model/Product/Category/Translate.php index 24ec4c22..fe3c8781 100644 --- a/modules/product/classes/Model/Product/Category/Translate.php +++ b/modules/product/classes/Model/Product/Category/Translate.php @@ -17,5 +17,7 @@ class Model_Product_Category_Translate extends ORM_OSB { protected $_belongs_to = array( 'product_category'=>array(), ); + + protected $_save_message = TRUE; } ?> diff --git a/modules/product/classes/Model/Product/Translate.php b/modules/product/classes/Model/Product/Translate.php index 27193d5a..35f55cc8 100644 --- a/modules/product/classes/Model/Product/Translate.php +++ b/modules/product/classes/Model/Product/Translate.php @@ -16,5 +16,7 @@ class Model_Product_Translate extends ORM_OSB { protected $_belongs_to = array( 'product'=>array(), ); + + protected $_save_message = TRUE; } ?> diff --git a/modules/product/views/product/admin/ajaxtranslate.php b/modules/product/views/product/admin/ajaxtranslate.php index 1bbb03fb..952e96d6 100644 --- a/modules/product/views/product/admin/ajaxtranslate.php +++ b/modules/product/views/product/admin/ajaxtranslate.php @@ -1,6 +1,6 @@
    - name,array( + name,array( 'label'=>'Category Title', 'placeholder'=>'Descriptive Title', 'class'=>'span3', @@ -8,20 +8,24 @@ 'help-block'=>'The title is shown when uses search products by category')); ?>
    - description_short,array( + description_short,array( 'label'=>'Short Product Description', 'placeholder'=>'Short Description', 'class'=>'span6', 'required', + 'editor'=>'wysihtml5', 'help-block'=>'Complete description of this category')); ?>
    - description_full,array( + description_full,array( 'label'=>'Full Product Description', 'placeholder'=>'Full Description', 'class'=>'span6', 'required', + 'editor'=>'wysihtml5', 'help-block'=>'Complete description of this category')); ?>
    + +render_all(); ?> render_all(); ?> diff --git a/modules/product/views/product/category/admin/ajaxtranslate.php b/modules/product/views/product/category/admin/ajaxtranslate.php index fa621ea1..b0ae3d22 100644 --- a/modules/product/views/product/category/admin/ajaxtranslate.php +++ b/modules/product/views/product/category/admin/ajaxtranslate.php @@ -1,6 +1,6 @@
    - name,array( + name,array( 'label'=>'Category Title', 'placeholder'=>'Descriptive Title', 'class'=>'span3', @@ -8,12 +8,15 @@ 'help-block'=>'The title is shown when uses search products by category')); ?>
    - description,array( + description,array( 'label'=>'Category Description', 'placeholder'=>'Description', 'class'=>'span6', 'required', + 'editor'=>'wysihtml5', 'help-block'=>'Complete description of this category')); ?>
    + +render_all(); ?> render_all(); ?> diff --git a/modules/service/classes/Controller/Admin/Service.php b/modules/service/classes/Controller/Admin/Service.php index 6c7fe3cf..30a53e7f 100644 --- a/modules/service/classes/Controller/Admin/Service.php +++ b/modules/service/classes/Controller/Admin/Service.php @@ -127,46 +127,12 @@ class Controller_Admin_Service extends Controller_Service { if (isset($_POST['plugin']) AND $_POST['plugin']) { $p = $so->plugin(); - if ($p->values($_POST['plugin'])->changed() AND $p->check()) { - try { - $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('
    ',array_values($errors))); - - $so->reload(); - } - } + if ($p->values($_POST['plugin'])->changed() AND ! $this->save($p)) + $p->reload(); } - if ($so->values($_POST)->changed() AND $so->check()) { - try { - $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('
    ',array_values($errors))); - - $so->reload(); - } - } + if ($so->values($_POST)->changed() AND ! $this->save($so)) + $so->reload(); } Script::factory() @@ -211,10 +177,8 @@ $(document).ready(function() { $so = ORM::factory('Service',$id); - if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) { - $this->template->content = 'Unauthorised or doesnt exist?'; - return FALSE; - } + if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) + throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); $doutput = $loutput = ''; diff --git a/modules/service/classes/Model/Service.php b/modules/service/classes/Model/Service.php index 82b7ad97..9a3468f1 100644 --- a/modules/service/classes/Model/Service.php +++ b/modules/service/classes/Model/Service.php @@ -91,6 +91,12 @@ class Model_Service extends ORM_OSB { 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 */ diff --git a/modules/service/views/service/user/view.php b/modules/service/views/service/user/view.php index 2cec255b..5518596d 100644 --- a/modules/service/views/service/user/view.php +++ b/modules/service/views/service/user/view.php @@ -109,3 +109,24 @@ + +email()->find_all(); if ($x->count()) : ?> +
    +
    + Emails about this service + 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), + )); ?> +
    +
    + diff --git a/modules/ssl/classes/Controller/Reseller/Ssl.php b/modules/ssl/classes/Controller/Reseller/Ssl.php index c6fed9b4..fea423d1 100644 --- a/modules/ssl/classes/Controller/Reseller/Ssl.php +++ b/modules/ssl/classes/Controller/Reseller/Ssl.php @@ -116,44 +116,19 @@ class Controller_Reseller_SSL extends Controller_SSL { public function action_renew() { $so = ORM::factory('Service',Request::current()->param('id')); - if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) { - SystemMessage::factory() - ->title('SSL Certificate not updated') - ->type('error') - ->body('Either the Service doesnt exist, or you are not authorised to see it'); - - HTTP::redirect('welcome'); - } + if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) + throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it'); $so->plugin()->renew(); + HTTP::redirect(URL::link('user','service/view/'.$so->id)); } private function add_edit($id=NULL,$output='') { $sco = ORM::factory('SSL_CA',$id); - if ($_POST) { - // Entry updated - 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('
    ',array_values($errors))); - - $sco->reload(); - } - } - } + if ($_POST AND $sco->values($_POST)->changed() AND ! ($this->save($sco))) + $sco->reload(); return View::factory('ssl/reseller/add_edit') ->set('o',$sco); diff --git a/modules/ssl/classes/Controller/User/Ssl.php b/modules/ssl/classes/Controller/User/Ssl.php index e852d031..9bd4d2b6 100644 --- a/modules/ssl/classes/Controller/User/Ssl.php +++ b/modules/ssl/classes/Controller/User/Ssl.php @@ -15,13 +15,13 @@ class Controller_User_SSL extends Controller_SSL { ); public function action_download() { - $id = $_POST['sid']; - $so = ORM::factory('Service',$id); + $so = ORM::factory('Service',$this->request->post('sid')); - if (! $so->loaded()) - HTTP::redirect('welcome/index'); + if (! $so->loaded() OR ! Auth::instance()->authorised($so->account)) + 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) { SystemMessage::add(array( 'title'=>_('Validation failed'), @@ -32,11 +32,6 @@ class Controller_User_SSL extends Controller_SSL { 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 $smo = $so->service_memo; $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())); $x = file_get_contents($file); unlink($file); + + $this->auto_render = FALSE; $this->response->headers('Content-Type','application/pks12'); $this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"'); $this->response->body($x); - $this->auto_render = FALSE; } } ?> diff --git a/modules/ssl/views/service/admin/plugin/ssl/edit.php b/modules/ssl/views/service/admin/plugin/ssl/edit.php index e203a691..5ac6e73e 100644 --- a/modules/ssl/views/service/admin/plugin/ssl/edit.php +++ b/modules/ssl/views/service/admin/plugin/ssl/edit.php @@ -1,17 +1,17 @@
    - service->plugin()->csr,array('class'=>'span6','label'=>'CSR','placeholder'=>'CSR','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr))); ?> + service->plugin()->csr,array('class'=>'span6','label'=>'CSR','placeholder'=>'CSR','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->csr))); ?>
    - 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))); ?> + service->plugin()->pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->pk))); ?>
    - 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))); ?> + service->plugin()->cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->service->plugin()->cert))); ?>
    diff --git a/modules/ssl/views/ssl/reseller/add_edit.php b/modules/ssl/views/ssl/reseller/add_edit.php index 1168423d..9592818c 100644 --- a/modules/ssl/views/ssl/reseller/add_edit.php +++ b/modules/ssl/views/ssl/reseller/add_edit.php @@ -50,8 +50,8 @@
    - sign_pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_pk))); ?> - sign_cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','nowysihtml'=>TRUE,'style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_cert))); ?> + sign_pk,array('class'=>'span6','label'=>'Private Key','placeholder'=>'Private Key','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_pk))); ?> + sign_cert,array('class'=>'span6','label'=>'Public Certificate','placeholder'=>'Public Certificate','style'=>'font-family: monospace;','rows'=>Form::textarea_rows($o->sign_cert))); ?> 'btn btn-primary')); ?>