Work on Email and other major consistency work
This commit is contained in:
@@ -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 .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
|
||||
$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 .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
|
||||
$output .= View::factory($this->viewpath());
|
||||
$output .= View::factory($this->viewpath().'/translate');
|
||||
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
|
||||
$output .= Form::close();
|
||||
|
||||
Editor::add();
|
||||
Block::add(array(
|
||||
'title'=>sprintf(_('Edit Template '),$eto->name),
|
||||
'title'=>_('Available Email Templates'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
@@ -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 {
|
||||
}
|
||||
?>
|
@@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
38
modules/email/views/email/admin/add_edit_template.php
Normal file
38
modules/email/views/email/admin/add_edit_template.php
Normal 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 -->
|
30
modules/email/views/email/admin/ajaxtemplatetranslate.php
Normal file
30
modules/email/views/email/admin/ajaxtemplatetranslate.php
Normal 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(); ?>
|
@@ -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>
|
@@ -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>
|
@@ -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>
|
@@ -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>
|
@@ -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>
|
@@ -1 +0,0 @@
|
||||
</table>
|
@@ -1,6 +0,0 @@
|
||||
<!-- //@todo Translation required -->
|
||||
<table class="box-left">
|
||||
<tr class="head">
|
||||
<td>Template</td>
|
||||
<td>Active</td>
|
||||
</tr>
|
@@ -1,20 +1,32 @@
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td>To:</td><td class="data"><?php printf('%s (%s)',$elo->account->name(),$elo->display('email')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Date:</td><td class="data"><?php echo $elo->display('date_orig'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Subject:</td><td class="data"><?php echo $elo->translate_resolve('subject'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 100%;" colspan="2">
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td><?php echo $elo->translate_resolve('message_html'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="span11">
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><strong>To:</strong></td>
|
||||
<td><?php printf('%s (%s)',$elo->account->name(),$elo->display('email')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Date:</strong></td>
|
||||
<td><?php echo $elo->display('date_orig'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Subject:</strong></td>
|
||||
<td><?php echo $elo->resolve('subject'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><hr/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<table>
|
||||
<tr>
|
||||
<td><?php echo $elo->resolve('message_html'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div> <!-- /span -->
|
||||
</div> <!-- /row -->
|
||||
|
Reference in New Issue
Block a user