Open Source Billing
This commit is contained in:
154
modules/email/classes/Controller/Admin/Email.php
Normal file
154
modules/email/classes/Controller/Admin/Email.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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_TemplateDefault_Admin {
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
'templateadd'=>TRUE,
|
||||
'templateedit'=>TRUE,
|
||||
'templatelist'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* 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,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a template
|
||||
*/
|
||||
public function action_templateadd() {
|
||||
$eto = ORM::factory('Email_Template');
|
||||
$output = '';
|
||||
|
||||
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,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Template Definition
|
||||
* @todo Change this into an add_view function like payment()
|
||||
*/
|
||||
public function action_templateedit() {
|
||||
$id = $this->request->param('id');
|
||||
|
||||
$eto = ORM::factory('Email_Template',$id);
|
||||
|
||||
if (! $eto->loaded())
|
||||
HTTP::redirect(URL::link('admin','email/template/list'));
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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 .= Form::close();
|
||||
|
||||
Editor::add();
|
||||
Block::add(array(
|
||||
'title'=>sprintf(_('Edit Template '),$eto->name),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
14
modules/email/classes/Controller/Email.php
Normal file
14
modules/email/classes/Controller/Email.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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_Email extends Controller_TemplateDefault {
|
||||
}
|
||||
?>
|
14
modules/email/classes/Controller/Email/Template.php
Normal file
14
modules/email/classes/Controller/Email/Template.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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 {
|
||||
}
|
||||
?>
|
59
modules/email/classes/Controller/User/Email.php
Normal file
59
modules/email/classes/Controller/User/Email.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides User Email View functions
|
||||
*
|
||||
* @package Email
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_User_Email extends Controller_TemplateDefault_User {
|
||||
protected $secure_actions = array(
|
||||
'list'=>TRUE,
|
||||
'view'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* 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'),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
public function action_view() {
|
||||
list($id,$output) = Table::page(__METHOD__);
|
||||
|
||||
$elo = ORM::factory('Email_Log',$id);
|
||||
|
||||
if (! $elo->loaded() OR ! Auth::instance()->authorised($elo->account)) {
|
||||
$this->template->content = 'Unauthorised or doesnt exist?';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$output .= View::factory($this->viewpath())
|
||||
->set('elo',$elo);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Email'),$elo->translate_resolve('subject')),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user