*/
public $_invoiceTemplate;
+ /**
+ * selected output
+ */
+ public $_selectedOutput;
+
/**
* build all the data structures needed to build the form
*
);
CRM_Utils_System::appendBreadCrumb($breadCrumb);
- if (in_array("email", $this->urlPath)) {
+
+ $this->_selectedOutput = CRM_Utils_Request::retrieve('select', 'String', $this);
+ $this->assign('selectedOutput', $this->_selectedOutput);
+
+ if ($this->_selectedOutput == 'email') {
CRM_Utils_System::setTitle(ts('Email Invoice'));
}
else {
$fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]);
}
$fromEmail = CRM_Utils_Array::crmArrayMerge($emails, $fromEmailAddress);
-
- $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
- $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
$this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmail);
- $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule'));
+ if ($this->_selectedOutput != 'email') {
+ $this->addElement('radio', 'output', NULL, ts('Email Invoice'), 'email_invoice');
+ $this->addElement('radio', 'output', NULL, ts('PDF Invoice'), 'pdf_invoice');
+ $this->addRule('output', ts('Selection required'), 'required');
+ $this->addFormRule(array('CRM_Contribute_Form_Task_Invoice', 'formRule'));
+ }
+ else {
+ $this->addRule('from_email_address', ts('From Email Address is required'), 'required');
+ }
+
$this->addWysiwyg('email_comment', ts('If you would like to add personal message to email please add it here. (If sending to more then one receipient the same message will be sent to each contact.)'), array(
'rows' => 2,
'cols' => 40
*/
static function formRule($values) {
$errors = array();
- if (!$values['from_email_address']) {
- if (in_array("Email Invoice", $values)) {
- $errors['from_email_address'] = ts("From Email Address is required");
- }
- else {
- if (in_array("email_invoice", $values)) {
- $errors['from_email_address'] = ts("From Email Address is required");
- }
- else {
- $errors['output'] = ts("Selection required");
- }
- }
+
+ if ($values['output'] == 'email_invoice' && empty($values['from_email_address'])) {
+ $errors['from_email_address'] = ts("From Email Address is required");
}
+
return $errors;
}
$pdfElements['params'] = $params;
$pdfElements['createPdf'] = FALSE;
- if ($pdfElements['params']['output'] == "pdf_invoice" || $pdfElements['params']['output'] == "pdf_receipt") {
+ if (!empty($pdfElements['params']['output']) &&
+ ($pdfElements['params']['output'] == "pdf_invoice" || $pdfElements['params']['output'] == "pdf_receipt")) {
$pdfElements['createPdf'] = TRUE;
}
list($contactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, FALSE, FALSE);
$pdfElements['suppressedEmails'] = 0;
+ $suppressedEmails = 0;
foreach ($contactDetails as $id => $values) {
if (empty($values['email']) || !empty($values['do_not_email']) ||
CRM_Utils_Array::value('is_deceased', $values) || !empty($values['on_hold'])) {
*}
<div class="messages status no-popup">
<div class="icon inform-icon"></div>
- {include file="CRM/Contribute/Form/Task.tpl"}
+ {include file="CRM/Contribute/Form/Task.tpl"}
</div>
-{if $smarty.get.select != 'email' || $smarty.get.q != 'civicrm/contribute/invoice/email'}
- <div id="help">
- {ts}You may choose to email invoice to contributors OR download a PDF file containing one invoice per page to your local computer by clicking <strong>Process Invoice(s)</strong>. Your browser may display the file for you automatically, or you may need to open it for printing using any PDF reader (such as Adobe® Reader).{/ts}
- </div>
+{if $selectedOutput ne 'email'}
+ <div id="help">
+ {ts}You may choose to email invoice to contributors OR download a PDF file containing one invoice per page to your local computer by clicking
+ <strong>Process Invoice(s)</strong>
+ . Your browser may display the file for you automatically, or you may need to open it for printing using any PDF reader (such as Adobe® Reader).{/ts}
+ </div>
{/if}
-<table class="form-layout-compressed">
- {if $smarty.get.select == 'email' || $smarty.get.q == 'civicrm/contribute/invoice/email'}
- {literal}
- <script type="text/javascript">
- cj(document).ready(function() {
- cj('#emailId').show();
- cj('#comment').show();
- })
- </script>
- {/literal}
- {/if}
-
- {literal}
- <script type="text/javascript">
- cj(document).ready(function() {
- if(cj('input:radio[name=output]:checked').val() == 'email_invoice') {
- cj('#selectPdfFormat').hide();
- cj('#emailId').show();
- cj('#comment').show();
- }
- cj('#CIVICRM_QFID_email_invoice_2').click(function() {
- cj('#selectPdfFormat').hide();
- cj('#emailId').show();
- cj('#comment').show();
- });
- });
- </script>
- {/literal}
-
- {if $smarty.get.select != 'email' && $smarty.get.q != 'civicrm/contribute/invoice/email'}
+<table class="form-layout-compressed">
+ {if $selectedOutput ne 'email'}
<tr>
<td>{$form.output.email_invoice.html}</td>
</tr>
{/if}
- <tr id="emailId" style="display:none;">
+ <tr class="crm-email-element">
<td>{$form.from_email_address.label}{$form.from_email_address.html}{help id ="id-from_email" isAdmin=$isAdmin}</td>
</tr>
- <tr id="comment" style="display:none;">
+ <tr class="crm-email-element">
<td>{$form.email_comment.label}{$form.email_comment.html}</td>
</tr>
- {if $smarty.get.select != 'email' && $smarty.get.q != 'civicrm/contribute/invoice/email'}
+ {if $selectedOutput ne 'email'}
<tr>
<td>{$form.output.pdf_invoice.html}</td>
</tr>
{/if}
- <tr id="selectPdfFormat" style="display: none;">
+ <tr class="crm-pdf-element">
<td>{$form.pdf_format_id.html} {$form.pdf_format_id.label} </td>
</tr>
</table>
<div class="spacer"></div>
<div class="form-item">
- {$form.buttons.html}
+ {$form.buttons.html}
</div>
+
+
+<script type="text/javascript">
+ {literal}
+ CRM.$(function ($) {
+ var o = $('input[name="output"]');
+ if (o.length > 1) {
+ $('.crm-email-element').hide();
+ showhideEmailElements();
+ o.on('click', showhideEmailElements);
+ }
+ else {
+ $('.crm-email-element').show();
+ }
+
+ function showhideEmailElements() {
+ if ($('input[name="output"]:checked').val() == 'email_invoice') {
+ $('.crm-email-element').show();
+ $('.crm-pdf-element').hide();
+ }
+ else {
+ $('.crm-pdf-element').show();
+ $('.crm-email-element').hide();
+ }
+ }
+ });
+ {/literal}
+</script>
+