This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/email/classes/Controller/Admin/Email.php

138 lines
3.4 KiB
PHP
Raw Permalink Normal View History

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
*/
class Controller_Admin_Email extends Controller_Email {
2013-10-10 02:44:53 +00:00
protected $secure_actions = array(
'ajaxtemplatetranslate'=>TRUE,
2013-10-10 02:44:53 +00:00
'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;
}
2013-10-10 02:44:53 +00:00
/**
* Add a template
2013-10-10 02:44:53 +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
}
/**
* List our defined email templates
2013-10-10 02:44:53 +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',
'status'=>'Active',
'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() {
list($id,$output) = Table::page(__METHOD__);
2013-10-10 02:44:53 +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
private function add_edit_template($id=NULL,$output='') {
$eto = ORM::factory('Email_Template',$id);
2013-10-10 02:44:53 +00:00
if ($_POST) {
// @todo To update the setup ID
$eto->email_setup_id = '1';
2013-10-10 02:44:53 +00:00
if (! $this->save($eto))
$eto->reload();
2013-10-10 02:44:53 +00:00
}
// @todo With tinymce, if the user reselects a different language, we loose the editor?
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]").empty().append(data);
}
});
});
});
');
2013-10-10 02:44:53 +00:00
return View::factory('email/admin/add_edit_template')
->set('o',$eto);
2013-10-10 02:44:53 +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(
'title'=>_('Available Email Templates'),
2013-10-10 02:44:53 +00:00
'body'=>$output,
));
}
}
?>