Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to customize Subject and Text for Email Reports #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,10 @@
'PDFReports_Pagination' => 'Page %s of %s',
'PDFReports_ReportIncludeNWebsites' => 'The report will include main metrics for all websites that have at least one visit (from the %s websites currently available).',
'PDFReports_TopLinkTooltip' => 'Create Email Reports to get Piwik stats delivered to your email or your customers\' address automatically!',
'PDFReports_CustomizeEmail' => 'Customize Email',
'PDFReports_Customize EmailTexts' => 'Customize Email Subject and Content',
'PDFReports_CustomSubjectText' => 'Enter custom Subject',
'PDFReports_CustomContentText' => 'Enter custom Content',
'ImageGraph_PluginDescription' => 'Generate beautiful static PNG Graph images for any Piwik report.',
'ImageGraph_ColumnOrdinateMissing' => 'The column \'%s\' was not found in this report. Try any of %s',
'RowEvolution_MetricsFor' => 'Metrics for %s',
Expand Down
26 changes: 25 additions & 1 deletion plugins/PDFReports/PDFReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Piwik_PDFReports extends Piwik_Plugin
const EVOLUTION_GRAPH_PARAMETER = 'evolutionGraph';
const ADDITIONAL_EMAILS_PARAMETER = 'additionalEmails';
const DISPLAY_FORMAT_PARAMETER = 'displayFormat';
const CUSTOM_EMAIL_TEXT_PARAMETER = 'customEmailText';
const EMAIL_SUBJECT_PARAMETER = 'emailSubject';
const EMAIL_CONTENT_PARAMETER = 'emailContent';
const CUSTOM_EMAIL_TEXT_PARAMETER_DEFAULT_VALUE = false;
const EMAIL_ME_PARAMETER_DEFAULT_VALUE = true;
const EVOLUTION_GRAPH_PARAMETER_DEFAULT_VALUE = false;

Expand All @@ -42,6 +46,9 @@ class Piwik_PDFReports extends Piwik_Plugin
self::EMAIL_ME_PARAMETER => false,
self::EVOLUTION_GRAPH_PARAMETER => false,
self::ADDITIONAL_EMAILS_PARAMETER => false,
self::CUSTOM_EMAIL_TEXT_PARAMETER => false,
self::EMAIL_SUBJECT_PARAMETER => false,
self::EMAIL_CONTENT_PARAMETER => false,
self::DISPLAY_FORMAT_PARAMETER => true,
);

Expand Down Expand Up @@ -145,6 +152,16 @@ function validateReportParameters( $notification )
$parameters[self::EMAIL_ME_PARAMETER] = self::valueIsTrue($parameters[self::EMAIL_ME_PARAMETER]);
}

// customText is an optional parameter
if(!isset($parameters[self::CUSTOM_EMAIL_TEXT_PARAMETER]))
{
$parameters[self::CUSTOM_EMAIL_TEXT_PARAMETER] = self::CUSTOM_EMAIL_TEXT_PARAMETER_DEFAULT_VALUE;
}
else
{
$parameters[self::CUSTOM_EMAIL_TEXT_PARAMETER] = self::valueIsTrue($parameters[self::CUSTOM_EMAIL_TEXT_PARAMETER]);
}

// evolutionGraph is an optional parameter
if(!isset($parameters[self::EVOLUTION_GRAPH_PARAMETER]))
{
Expand Down Expand Up @@ -331,11 +348,19 @@ function sendReport( $notification )
$contents = $notificationInfo[Piwik_PDFReports_API::REPORT_CONTENT_KEY];
$filename = $notificationInfo[Piwik_PDFReports_API::FILENAME_KEY];
$additionalFiles = $notificationInfo[Piwik_PDFReports_API::ADDITIONAL_FILES_KEY];
$reportParameters = $report['parameters'];

$periods = self::getPeriodToFrequency();
$message = Piwik_Translate('PDFReports_EmailHello');
$subject = Piwik_Translate('General_Report') . ' '. $websiteName . " - ".$prettyDate;

//Review if customText is specified for report
if($reportParameters[self::CUSTOM_EMAIL_TEXT_PARAMETER])
{
$message = $reportParameters[self::EMAIL_CONTENT_PARAMETER];
$subject = $reportParameters[self::EMAIL_SUBJECT_PARAMETER];
}

$mail = new Piwik_Mail();
$mail->setSubject($subject);
$fromEmailName = Piwik_Config::getInstance()->branding['use_custom_logo']
Expand Down Expand Up @@ -385,7 +410,6 @@ function sendReport( $notification )
}

// Get user emails and languages
$reportParameters = $report['parameters'];
$emails = array();

if(isset($reportParameters[self::ADDITIONAL_EMAILS_PARAMETER]))
Expand Down
39 changes: 38 additions & 1 deletion plugins/PDFReports/templates/report_parameters.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
evolutionGraphParameterInput.hide() : evolutionGraphParameterInput.show();
{rdelim}

function updateCustomTextsParameterVisibility ()
{ldelim}
var customTextsDivs = $('#report_especify_custom_texts');
$('#report_custom_texts').is(':checked') ?
customTextsDivs.show() : customTextsDivs.hide();
{rdelim}

$(function() {ldelim}

resetReportParametersFunctions ['{$reportType}'] =
Expand All @@ -25,7 +32,6 @@

updateReportParametersFunctions['{$reportType}'] =
function (reportParameters) {ldelim}

if(reportParameters == null) return;

$('#display_format option[value='+reportParameters.displayFormat+']').prop('selected', 'selected');
Expand All @@ -36,6 +42,15 @@
else
$('#report_email_me').removeProp('checked');

if(reportParameters.customEmailText === true) {ldelim}
$('#report_custom_texts').prop('checked', 'checked');
$('#report_custom_subject_text').text(reportParameters.emailSubject);
$('#report_custom_content_text').text(reportParameters.emailContent);
{rdelim} else
$('#report_custom_texts').removeProp('checked');

updateCustomTextsParameterVisibility();

if(reportParameters.evolutionGraph === true)
$('#report_evolution_graph').prop('checked', 'checked');
else
Expand All @@ -54,6 +69,9 @@

parameters.displayFormat = $('#display_format option:selected').val();
parameters.emailMe = $('#report_email_me').prop('checked');
parameters.customEmailText = $('#report_custom_texts').prop('checked');
parameters.emailSubject=$('#report_custom_subject_text').val();
parameters.emailContent=$('#report_custom_content_text').val();
parameters.evolutionGraph = $('#report_evolution_graph').prop('checked');

additionalEmails = $('#report_additional_emails').val();
Expand All @@ -64,6 +82,7 @@
{rdelim};

$('#display_format').change(updateEvolutionGraphParameterVisibility);
$('#report_custom_texts').change(updateCustomTextsParameterVisibility);

{rdelim});
</script>
Expand All @@ -79,6 +98,24 @@
<textarea cols="30" rows="3" id="report_additional_emails" class="inp"></textarea>
</td>
</tr>

<tr class='{$reportType}'>
<td style='width:240px;' class="first">{'PDFReports_CustomizeEmail'|translate}
</td>
<td>
<input type="checkbox" id="report_custom_texts"/>
<label for="report_custom_texts">{'PDFReports_Customize EmailTexts'|translate} </label>
<div id="report_especify_custom_texts">
<br/><br/>
{'PDFReports_CustomSubjectText'|translate}<br/>
<textarea cols="30" rows="3" id="report_custom_subject_text" class="inp"></textarea>
<br/><br/>
{'PDFReports_CustomContentText'|translate}<br/>
<textarea cols="30" rows="3" id="report_custom_content_text" class="inp"></textarea>

</div>
</td>
</tr>
<tr class='{$reportType}'>
<td class="first">
{*PDFReports_AggregateReportsFormat should be named PDFReports_DisplayFormat*}
Expand Down