2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
2011-10-13 21:41:01 +00:00
|
|
|
* This class provides Admin Email management
|
2010-11-29 22:41:08 +00:00
|
|
|
*
|
|
|
|
* @package lnApp
|
2011-10-13 21:41:01 +00:00
|
|
|
* @subpackage Page/Email
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Controllers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
2011-08-26 02:01:45 +00:00
|
|
|
class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
|
2011-08-26 01:16:48 +00:00
|
|
|
protected $secure_actions = array(
|
2011-08-27 06:33:46 +00:00
|
|
|
'list'=>TRUE,
|
2011-08-26 02:01:45 +00:00
|
|
|
'templateadd'=>TRUE,
|
|
|
|
'templateedit'=>TRUE,
|
|
|
|
'templatelist'=>TRUE,
|
2010-11-29 22:41:08 +00:00
|
|
|
);
|
|
|
|
|
2011-08-27 06:33:46 +00:00
|
|
|
/**
|
|
|
|
* Show a list of emails
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('System Emails Sent'),
|
|
|
|
'body'=>Table::display(
|
2012-11-09 23:13:57 +00:00
|
|
|
ORM::factory('Email_Log')->find_all(),
|
2011-08-27 06:33:46 +00:00
|
|
|
25,
|
|
|
|
array(
|
2013-02-12 11:14:59 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>URL::link('user','email/view/')),
|
2011-08-27 06:33:46 +00:00
|
|
|
'date_orig'=>array('label'=>'Date'),
|
2011-09-26 10:12:54 +00:00
|
|
|
'email'=>array('label'=>'To'),
|
2011-08-27 06:33:46 +00:00
|
|
|
'translate_resolve("subject")'=>array('label'=>'Subject'),
|
|
|
|
'account->accnum()'=>array('label'=>'Cust ID'),
|
|
|
|
'account->name()'=>array('label'=>'Customer'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2013-02-12 11:14:59 +00:00
|
|
|
'form'=>URL::link('user','email/view'),
|
2011-08-27 06:33:46 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* List our defined email templates
|
|
|
|
*/
|
2011-08-26 02:01:45 +00:00
|
|
|
public function action_templatelist() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$eto = ORM::factory('Email_Template');
|
2010-11-29 22:41:08 +00:00
|
|
|
$output = '';
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
// @todo Change this to use Table::
|
|
|
|
$output .= View::factory($this->viewpath().'/head');
|
2010-11-29 22:41:08 +00:00
|
|
|
foreach ($eto->find_all() as $et) {
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/body')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('template',$et);
|
|
|
|
}
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/foot');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Available Email Templates'),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a template
|
|
|
|
*/
|
2011-08-26 02:01:45 +00:00
|
|
|
public function action_templateadd() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$eto = ORM::factory('Email_Template');
|
2010-11-29 22:41:08 +00:00
|
|
|
$output = '';
|
|
|
|
|
|
|
|
if ($_POST AND $eto->values($_POST)->check()) {
|
|
|
|
// @todo To update the setup ID
|
|
|
|
$eto->email_setup_id=1;
|
|
|
|
|
|
|
|
// Entry updated
|
|
|
|
if ($eto->save()) {
|
2011-08-26 02:01:45 +00:00
|
|
|
$x = $eto->email_template_translate->values($_POST['translate']['new']);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$x->email_template_id = $eto->id;
|
|
|
|
if ($x->check())
|
|
|
|
$x->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= Form::open();
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath());
|
|
|
|
$output .= View::factory($this->viewpath().'/translate');
|
2011-08-31 06:54:44 +00:00
|
|
|
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Editor::add();
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Available Email Templates'),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit Template Definition
|
2011-12-21 01:39:21 +00:00
|
|
|
* @todo Change this into an add_view function like payment()
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2012-11-09 23:13:57 +00:00
|
|
|
public function action_templateedit() {
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
|
|
|
|
$eto = ORM::factory('Email_Template',$id);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
if (! $eto->loaded())
|
2013-02-12 11:14:59 +00:00
|
|
|
HTTP::redirect(URL::link('admin','email/template/list'));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
if ($_POST AND $eto->values($_POST)->check()) {
|
|
|
|
// Entry updated
|
|
|
|
if ($eto->save()) {
|
|
|
|
foreach ($_POST['translate'] as $id => $details) {
|
2011-08-26 02:01:45 +00:00
|
|
|
$x = $eto->email_template_translate->where('id','=',$id)->find();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
if ($x->values($details)->check())
|
|
|
|
$x->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= Form::open();
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath())
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('template',$eto);
|
|
|
|
|
2011-08-26 02:01:45 +00:00
|
|
|
foreach ($eto->email_template_translate->find_all() as $to) {
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath().'/translate')
|
2010-11-29 22:41:08 +00:00
|
|
|
->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')))),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-08-31 06:54:44 +00:00
|
|
|
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Editor::add();
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf(_('Edit Template '),$eto->name),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|