2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides Admin Email management
|
|
|
|
*
|
|
|
|
* @package Email
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-10-11 02:08:50 +00:00
|
|
|
class Controller_Admin_Email extends Controller_Email {
|
2013-10-10 02:44:53 +00:00
|
|
|
protected $secure_actions = array(
|
2013-11-22 04:36:50 +00:00
|
|
|
'ajaxtemplatetranslate'=>TRUE,
|
2013-10-10 02:44:53 +00:00
|
|
|
'templateadd'=>TRUE,
|
|
|
|
'templateedit'=>TRUE,
|
|
|
|
'templatelist'=>TRUE,
|
|
|
|
);
|
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
public function action_ajaxtemplatetranslate() {
|
|
|
|
$eto = ORM::factory('Email_Template',$this->request->param('id'));
|
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if (! $eto->loaded() OR ! $this->request->query('key')) {
|
2013-11-22 04:36:50 +00:00
|
|
|
$output = _('Unable to find translate data');
|
|
|
|
|
|
|
|
} else {
|
2016-08-03 06:20:25 +00:00
|
|
|
$eto = $eto->translate->where('language_id','=',$this->request->query('key'))->find();
|
2013-11-22 04:36:50 +00:00
|
|
|
|
|
|
|
$output = View::factory('email/admin/ajaxtemplatetranslate')
|
|
|
|
->set('o',$eto);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->template->content = $output;
|
|
|
|
}
|
|
|
|
|
2013-10-10 02:44:53 +00:00
|
|
|
/**
|
2013-11-22 04:36:50 +00:00
|
|
|
* Add a template
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-22 04:36:50 +00:00
|
|
|
public function action_templateadd() {
|
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title('Add Email Template')
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body($this->add_edit_template());
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-22 04:36:50 +00:00
|
|
|
* List our defined email templates
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-22 04:36:50 +00:00
|
|
|
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',
|
2016-08-31 05:03:09 +00:00
|
|
|
'active'=>'Active',
|
2013-11-22 04:36:50 +00:00
|
|
|
'description'=>'Descrption',
|
|
|
|
))
|
|
|
|
->prepend(array(
|
|
|
|
'id'=>array('url'=>URL::link('admin','email/templateedit/')),
|
|
|
|
))
|
|
|
|
);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit Template Definition
|
|
|
|
* @todo Change this into an add_view function like payment()
|
|
|
|
*/
|
|
|
|
public function action_templateedit() {
|
2013-11-22 04:36:50 +00:00
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
Block::factory()
|
|
|
|
->type('form-horizontal')
|
|
|
|
->title('Update Email Template')
|
|
|
|
->title_icon('icon-wrench')
|
|
|
|
->body($this->add_edit_template($id,$output));
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
private function add_edit_template($id=NULL,$output='') {
|
|
|
|
$eto = ORM::factory('Email_Template',$id);
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2016-08-03 06:20:25 +00:00
|
|
|
if ($this->request->post()) {
|
2013-11-22 04:36:50 +00:00
|
|
|
// @todo To update the setup ID
|
|
|
|
$eto->email_setup_id = '1';
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
if (! $this->save($eto))
|
|
|
|
$eto->reload();
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 00:22:20 +00:00
|
|
|
// @todo With tinymce, if the user reselects a different language, we loose the editor?
|
2013-11-22 04:36:50 +00:00
|
|
|
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) {
|
2013-11-27 00:22:20 +00:00
|
|
|
$("div[id=translate]").empty().append(data);
|
2013-11-22 04:36:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
');
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
return View::factory('email/admin/add_edit_template')
|
|
|
|
->set('o',$eto);
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
$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>';
|
2013-10-10 02:44:53 +00:00
|
|
|
$output .= Form::close();
|
|
|
|
|
|
|
|
Block::add(array(
|
2013-11-22 04:36:50 +00:00
|
|
|
'title'=>_('Available Email Templates'),
|
2013-10-10 02:44:53 +00:00
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|