Skip to content
Snippets Groups Projects
Commit 34c17b95 authored by Aegir user's avatar Aegir user
Browse files

* Make the 'Export to Excel' button submit the form, as a task would

* Detect whether CiviCRM core was patched, so that we can support both legacy and new method.
parent b02668b6
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,6 @@ easier to use).
This extension uses the PHPExcel library. See the "License" section below
for more information (LGPL v2).
For discussion, see: http://forum.civicrm.org/index.php/topic,32954.0.html
See also the "Todo" section for a general roadmap.
To download the latest version of this module:
https://lab.civicrm.org/extensions/civiexportexcel/
......@@ -38,9 +35,13 @@ Install as any other regular CiviCRM extension:
You may need to create it if it does not already exist, and configure
the correct path in CiviCRM -> Administer -> System -> Directories.
2- Enable the extension from CiviCRM -> Administer -> System -> Extensions.
2- Run `composer install`
3- Apply this CiviCRM core patch civiexportexcel-core.patch (optional but recommended).
4- Enable the extension from CiviCRM -> Administer -> System -> Extensions.
3- If you wish to send emails with the report as an Excel attachment,
5- If you wish to send emails with the report as an Excel attachment,
you must apply the patch in civiexportexcel-core-mail.patch.
Report mails
......@@ -88,8 +89,7 @@ License
Distributed under the terms of the GNU Affero General public license (AGPL).
See LICENSE.txt for details.
This extension uses PHPExcel:
This extension relies on phpSpreadsheet by PHPOffice:
https://github.com/PHPOffice/PhpSpreadsheet
Version 1.8.0, 2014-03-02
Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
See composer.json for more information about dependencies.
diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php
index 055e0d9..358e6ee 100644
index f3dbf456e8..45a07ea1cc 100644
--- a/CRM/Report/Form.php
+++ b/CRM/Report/Form.php
@@ -185,6 +185,7 @@ class CRM_Report_Form extends CRM_Core_Form {
protected $_printButtonName = NULL;
protected $_pdfButtonName = NULL;
protected $_csvButtonName = NULL;
+ protected $_excelButtonName = NULL;
protected $_groupButtonName = NULL;
protected $_chartButtonName = NULL;
protected $_csvSupported = TRUE;
@@ -446,6 +447,7 @@ class CRM_Report_Form extends CRM_Core_Form {
$this->_printButtonName = $this->getButtonName('submit', 'print');
$this->_pdfButtonName = $this->getButtonName('submit', 'pdf');
$this->_csvButtonName = $this->getButtonName('submit', 'csv');
+ $this->_excelButtonName = $this->getButtonName('submit', 'excel');
$this->_groupButtonName = $this->getButtonName('submit', 'group');
$this->_chartButtonName = $this->getButtonName('submit', 'chart');
}
@@ -1075,6 +1077,9 @@ class CRM_Report_Form extends CRM_Core_Form {
$this->addElement('submit', $this->_csvButtonName, $label);
}
@@ -152,6 +152,9 @@ class CRM_Report_Form extends CRM_Core_Form {
*/
protected $_groupFilter = FALSE;
+ $label = $this->_id ? ts('Excel (test)') : ts('Preview Excel');
+ $this->addElement('submit', $this->_excelButtonName, $label);
+ // [ML] Required for civiexportexcel
+ public $supportsExportExcel = TRUE;
+
if (CRM_Core_Permission::check('administer Reports') && $this->_add2groupSupported) {
$this->addElement('select', 'groups', ts('Group'),
array('' => ts('- select group -')) + CRM_Core_PseudoConstant::staticGroup()
@@ -2094,6 +2099,13 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
$this->_outputMode = 'csv';
$this->_absoluteUrl = TRUE;
}
+ elseif ($this->_excelButtonName == $buttonName || $output == 'excel2007') {
+ $this->assign('printOnly', TRUE);
+ $printOnly = TRUE;
+ $this->assign('outputMode', 'excel2007');
+ $this->_outputMode = 'excel2007';
+ $this->_absoluteUrl = TRUE;
+ }
elseif ($this->_groupButtonName == $buttonName || $output == 'group') {
$this->assign('outputMode', 'group');
$this->_outputMode = 'group';
@@ -2610,6 +2622,9 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
/**
* Has the report been optimised for group filtering.
*
@@ -3429,6 +3432,9 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
elseif ($this->_outputMode == 'csv') {
CRM_Report_Utils_Report::export2csv($this, $rows);
}
......@@ -52,23 +22,4 @@ index 055e0d9..358e6ee 100644
elseif ($this->_outputMode == 'group') {
$group = $this->_params['groups'];
$this->add2group($group);
diff --git a/templates/CRM/Report/Form/Actions.tpl b/templates/CRM/Report/Form/Actions.tpl
index d4aa43f..32344ba 100644
--- a/templates/CRM/Report/Form/Actions.tpl
+++ b/templates/CRM/Report/Form/Actions.tpl
@@ -31,6 +31,7 @@
{assign var=print value="_qf_"|cat:$form.formName|cat:"_submit_print"}
{assign var=pdf value="_qf_"|cat:$form.formName|cat:"_submit_pdf"}
{assign var=csv value="_qf_"|cat:$form.formName|cat:"_submit_csv"}
+ {assign var=excel value="_qf_"|cat:$form.formName|cat:"_submit_excel"}
{assign var=group value="_qf_"|cat:$form.formName|cat:"_submit_group"}
{assign var=chart value="_qf_"|cat:$form.formName|cat:"_submit_chart"}
<table style="border:0;">
@@ -41,6 +42,7 @@
<td>{$form.$print.html}&nbsp;&nbsp;</td>
<td>{$form.$pdf.html}&nbsp;&nbsp;</td>
<td>{$form.$csv.html}&nbsp;&nbsp;</td>
+ <td>{$form.$excel.html}&nbsp;&nbsp;</td>
{if $instanceUrl}
<td>&nbsp;&nbsp;&raquo;&nbsp;<a href="{$instanceUrl}">{ts}Existing report(s) from this template{/ts}</a></td>
{/if}
......@@ -136,46 +136,52 @@ function civiexportexcel_civicrm_buildForm($formName, &$form) {
'template' => 'CRM/Report/Form/Actions-civiexportexcel.tpl',
));
// This hook also gets called when we click on a submit button,
// so we can handle that part here too.
$buttonName = $form->controller->getButtonName();
$output = CRM_Utils_Request::retrieve('output', 'String', CRM_Core_DAO::$_nullObject);
// This is to preserve legacy behaviour, i.e. if core is not patched
if (empty($form->supportsExportExcel) && CRM_Utils_Request::retrieveValue('task', 'String') == 'report_instance.excel2007') {
civiexportexcel_legacyBuildFormExport($form);
}
}
}
if ($form->_excelButtonName == $buttonName || $output == 'excel2007') {
$form->assign('printOnly', TRUE);
$printOnly = TRUE;
$form->assign('outputMode', 'excel2007');
/**
* Legacy code for exporting report data, without a patch on CiviCRM core.
*
* @see civiexportexcel_civicrm_buildForm()
* @deprecated
*/
function civiexportexcel_legacyBuildFormExport($form) {
$output = CRM_Utils_Request::retrieve('output', 'String', CRM_Core_DAO::$_nullObject);
$form->assign('printOnly', TRUE);
$printOnly = TRUE;
$form->assign('outputMode', 'excel2007');
// FIXME: this duplicates part of CRM_Report_Form::postProcess()
// since we do not have a place to hook into, we hi-jack the form process
// before it gets into postProcess.
// FIXME: this duplicates part of CRM_Report_Form::postProcess()
// since we do not have a place to hook into, we hi-jack the form process
// before it gets into postProcess.
// get ready with post process params
$form->beginPostProcess();
// get ready with post process params
$form->beginPostProcess();
// build query
$sql = $form->buildQuery(FALSE);
// build query
$sql = $form->buildQuery(FALSE);
// build array of result based on column headers. This method also allows
// modifying column headers before using it to build result set i.e $rows.
$rows = array();
$form->buildRows($sql, $rows);
// build array of result based on column headers. This method also allows
// modifying column headers before using it to build result set i.e $rows.
$rows = array();
$form->buildRows($sql, $rows);
// format result set.
// This seems to cause more problems than it fixes.
// $form->formatDisplay($rows);
// format result set.
// This seems to cause more problems than it fixes.
// $form->formatDisplay($rows);
// Show stats on a second Excel page.
$stats = $form->statistics($rows);
// Show stats on a second Excel page.
$stats = $form->statistics($rows);
// assign variables to templates
$form->doTemplateAssignment($rows);
// FIXME: END.
// assign variables to templates
$form->doTemplateAssignment($rows);
// FIXME: END.
CRM_CiviExportExcel_Utils_Report::export2excel2007($form, $rows, $stats);
}
}
CRM_CiviExportExcel_Utils_Report::export2excel2007($form, $rows, $stats);
}
/**
......
{* We need this reference for the js injection below *}
{assign var=csv value="_qf_"|cat:$form.formName|cat:"_submit_csv"}
{*
* Preserved for legacy behavior, when users expect
* the 'Export to Excel' button.
*
* Remove at some point?
*}
{* The nbps; are a mimic of what other buttons do in templates/CRM/Report/Form/Actions.tpl *}
{assign var=excel value="_qf_"|cat:$form.formName|cat:"_submit_excel"}
......@@ -10,27 +14,19 @@
CRM.$(function($) {
var form_id = '{/literal}{$form.$excel.id}{literal}';
{/literal}
{* CiviCRM 4.6 *}
{if $form.$csv.id}
{literal}
var $dest = $('input#{/literal}{$form.$csv.id}{literal}').parent();
$('input#' + form_id).appendTo($dest);
{/literal}
{else}
{* CiviCRM 4.7+ *}
{literal}
if ($('.crm-report-field-form-block .crm-submit-buttons').size() > 0) {
$('input#' + form_id).appendTo('.crm-report-field-form-block .crm-submit-buttons');
}
else {
// Do not show the button when running in a dashlet
// FIXME: we should probably just not add the HTML in the first place.
$('input#' + form_id).hide();
}
{/literal}
{/if}
{literal}
if ($('.crm-report-field-form-block .crm-submit-buttons').size() > 0) {
$('input#' + form_id).appendTo('.crm-report-field-form-block .crm-submit-buttons');
$('input#' + form_id).on('click', function(e) {
e.preventDefault();
$('select#task').val('report_instance.excel2007').trigger('change');
});
}
else {
// Do not show the button when running in a dashlet
// FIXME: we should probably just not add the HTML in the first place.
$('input#' + form_id).hide();
}
});
</script>
{/literal}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment