Skip to content

Commit

Permalink
IP-348 - Improve email templates to support EmailToSMS services
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskoola committed Oct 27, 2015
1 parent a5d6469 commit 1f2146d
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 16 deletions.
13 changes: 11 additions & 2 deletions application/helpers/mailer_helper.php
Expand Up @@ -36,7 +36,9 @@ function email_invoice(
$body,
$cc = null,
$bcc = null,
$attachments = null
$attachments = null,
$send_pdf,
$send_attachments
) {
$CI = &get_instance();

Expand All @@ -45,10 +47,17 @@ function email_invoice(
$CI->load->helper('invoice');
$CI->load->helper('pdf');

$invoice = generate_invoice_pdf($invoice_id, false, $invoice_template);
$invoice = null;
if($send_pdf) {
$invoice = generate_invoice_pdf($invoice_id, false, $invoice_template);
}
if (!$send_attachments) {
$attachments = null;
}

$db_invoice = $CI->mdl_invoices->where('ip_invoices.invoice_id', $invoice_id)->get()->row();

$to = parse_template($db_invoice, $to);
$message = parse_template($db_invoice, $body);
$subject = parse_template($db_invoice, $subject);
$cc = parse_template($db_invoice, $cc);
Expand Down
3 changes: 3 additions & 0 deletions application/language/english/ip_lang.php
Expand Up @@ -56,6 +56,7 @@
'client' => 'Client',
'client_access' => 'Client Access',
'client_already_exists' => 'Client already exists!',
'client_email' => 'Client Email',
'client_form' => 'Client Form',
'client_name' => 'Client Name',
'clients' => 'Clients',
Expand Down Expand Up @@ -396,7 +397,9 @@
'select_family' => 'Select family',
'select_payment_method' => 'Select the Payment Method',
'send' => 'Send',
'send_attachments' => 'Send Attachments',
'send_email' => 'Send Email',
'send_pdf' => 'Send Invoice/Quote PDF',
'sent' => 'Sent',
'set_new_password' => 'Set a new password',
'settings' => 'Settings',
Expand Down
12 changes: 12 additions & 0 deletions application/modules/email_templates/models/mdl_email_templates.php
Expand Up @@ -44,6 +44,10 @@ public function validation_rules()
'field' => 'email_template_pdf_quote_template',
'label' => lang('type')
),
'email_template_to_email' => array(
'field' => 'email_template_to_email',
'label' => lang('to_email')
),
'email_template_subject' => array(
'field' => 'email_template_subject',
'label' => lang('subject')
Expand All @@ -68,6 +72,14 @@ public function validation_rules()
'field' => 'email_template_pdf_template',
'label' => lang('default_pdf_template')
),
'email_template_send_pdf' => array(
'field' => 'email_template_send_pdf',
'label' => lang('send_pdf')
),
'email_template_send_attachments' => array(
'field' => 'email_template_send_attachments',
'label' => lang('send_attachments')
),
'email_template_body' => array(
'field' => 'email_template_body',
'label' => lang('body')
Expand Down
52 changes: 52 additions & 0 deletions application/modules/email_templates/views/form.php
Expand Up @@ -46,6 +46,17 @@ class="form-control">

<hr>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_to_email" class="control-label"><?php echo lang('to_email'); ?>: </label>
</div>
<div class="col-xs-12 col-sm-6">
<input type="text" name="email_template_to_email" id="email_template_to_email"
class="form-control taggable"
value="<?php echo $this->mdl_email_templates->form_value('email_template_to_email'); ?>">
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_from_name" class="control-label"><?php echo lang('from_name'); ?>: </label>
Expand Down Expand Up @@ -120,6 +131,46 @@ class="form-control taggable"
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_send_pdf" class="control-label">
<?php echo lang('send_pdf'); ?>:
</label>
</div>
<div class="col-xs-12 col-sm-6">
<select name="email_template_send_pdf" class="input-sm form-control">
<option value="1"
<?php if ($this->mdl_email_templates->form_value('email_template_send_pdf')) { ?>selected="selected"<?php } ?>>
<?php echo lang('yes'); ?>
</option>
<option value="0"
<?php if (!$this->mdl_email_templates->form_value('email_template_send_pdf')) { ?>selected="selected"<?php } ?>>
<?php echo lang('no'); ?>
</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_send_attachments" class="control-label">
<?php echo lang('send_attachments'); ?>:
</label>
</div>
<div class="col-xs-12 col-sm-6">
<select name="email_template_send_attachments" class="input-sm form-control">
<option value="1"
<?php if ($this->mdl_email_templates->form_value('email_template_send_attachments')) { ?>selected="selected"<?php } ?>>
<?php echo lang('yes'); ?>
</option>
<option value="0"
<?php if (!$this->mdl_email_templates->form_value('email_template_send_attachments')) { ?>selected="selected"<?php } ?>>
<?php echo lang('no'); ?>
</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_body">
Expand Down Expand Up @@ -184,6 +235,7 @@ class="email-template-body form-control taggable"><?php echo $this->mdl_email_te
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2">
<strong><?php echo lang('client'); ?></strong><br>
<a href="#" class="text-tag" data-tag="{{{client_name}}}"><?php echo lang('client_name'); ?></a><br>
<a href="#" class="text-tag" data-tag="{{{client_email}}}"><?php echo lang('client_email'); ?></a><br>
<a href="#" class="text-tag"
data-tag="{{{client_address_1}}}"><?php echo lang('client'); ?> <?php echo lang('address'); ?>
1</a><br>
Expand Down
6 changes: 4 additions & 2 deletions application/modules/mailer/controllers/mailer.php
Expand Up @@ -125,8 +125,10 @@ public function send_invoice($invoice_id)
$cc = $this->input->post('cc');
$bcc = $this->input->post('bcc');
$attachment_files = $this->mdl_uploads->get_invoice_uploads($invoice_id);

if (email_invoice($invoice_id, $pdf_template, $from, $to, $subject, $body, $cc, $bcc, $attachment_files)) {
$send_pdf = $this->input->post('send_pdf');
$send_attachments = $this->input->post('send_attachments');

if (email_invoice($invoice_id, $pdf_template, $from, $to, $subject, $body, $cc, $bcc, $attachment_files, $send_pdf, $send_attachments)) {
$this->mdl_invoices->mark_sent($invoice_id);

$this->session->set_flashdata('alert_success', lang('email_successfully_sent'));
Expand Down
60 changes: 48 additions & 12 deletions application/modules/mailer/views/invoice.php
@@ -1,6 +1,6 @@
<script type="text/javascript">
$(function () {
var template_fields = ["body", "subject", "from_name", "from_email", "cc", "bcc", "pdf_template"];
var template_fields = ["to_email", "body", "subject", "from_name", "from_email", "cc", "bcc", "pdf_template", "send_pdf", "send_attachments"];

$('#email_template').change(function () {
var email_template_id = $(this).val();
Expand Down Expand Up @@ -43,28 +43,28 @@

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="to_email" class="control-label"><?php echo lang('to_email'); ?>: </label>
<label for="email_template" class="control-label"><?php echo lang('email_template'); ?>: </label>
</div>
<div class="col-xs-12 col-sm-6">
<input type="text" name="to_email" id="to_email" class="form-control"
value="<?php echo $invoice->client_email; ?>">
<select name="email_template" id="email_template" class="form-control">
<option value=""></option>
<?php foreach ($email_templates as $email_template): ?>
<option value="<?php echo $email_template->email_template_id; ?>"
<?php if ($selected_email_template == $email_template->email_template_id) { ?>selected="selected"<?php } ?>><?php echo $email_template->email_template_title; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>

<hr>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template" class="control-label"><?php echo lang('email_template'); ?>: </label>
<label for="to_email" class="control-label"><?php echo lang('to_email'); ?>: </label>
</div>
<div class="col-xs-12 col-sm-6">
<select name="email_template" id="email_template" class="form-control">
<option value=""></option>
<?php foreach ($email_templates as $email_template): ?>
<option value="<?php echo $email_template->email_template_id; ?>"
<?php if ($selected_email_template == $email_template->email_template_id) { ?>selected="selected"<?php } ?>><?php echo $email_template->email_template_title; ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="to_email" id="to_email" class="form-control"
value="<?php echo $invoice->client_email; ?>">
</div>
</div>

Expand Down Expand Up @@ -136,6 +136,42 @@
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="send_pdf" class="control-label">
<?php echo lang('send_pdf'); ?>:
</label>
</div>
<div class="col-xs-12 col-sm-6">
<select name="send_pdf" id="send_pdf" class="form-control">
<option value="1" selected="selected">
<?php echo lang('yes'); ?>
</option>
<option value="0">
<?php echo lang('no'); ?>
</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="send_attachments" class="control-label">
<?php echo lang('send_attachments'); ?>:
</label>
</div>
<div class="col-xs-12 col-sm-6">
<select name="send_attachments" id="send_attachments" class="form-control">
<option value="1" selected="selected">
<?php echo lang('yes'); ?>
</option>
<option value="0">
<?php echo lang('no'); ?>
</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-xs-12 col-sm-2 text-right text-left-xs">
<label for="email_template_body">
Expand Down

0 comments on commit 1f2146d

Please sign in to comment.