From e6f9ffeac5e782c85a742d7f3ef16056c81ad102 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Mon, 4 Feb 2013 20:37:16 +0100 Subject: [PATCH] Allow to customize Subject and Text for Email Reports --- lang/en.php | 4 ++ plugins/PDFReports/PDFReports.php | 26 ++++++++++++- .../templates/report_parameters.tpl | 39 ++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/lang/en.php b/lang/en.php index a0644bbec97..0f08885fd5c 100644 --- a/lang/en.php +++ b/lang/en.php @@ -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', diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php index 91f32fdaae5..1571d0dda69 100644 --- a/plugins/PDFReports/PDFReports.php +++ b/plugins/PDFReports/PDFReports.php @@ -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; @@ -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, ); @@ -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])) { @@ -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'] @@ -385,7 +410,6 @@ function sendReport( $notification ) } // Get user emails and languages - $reportParameters = $report['parameters']; $emails = array(); if(isset($reportParameters[self::ADDITIONAL_EMAILS_PARAMETER])) diff --git a/plugins/PDFReports/templates/report_parameters.tpl b/plugins/PDFReports/templates/report_parameters.tpl index 053a686bedf..d0bb7b5497b 100644 --- a/plugins/PDFReports/templates/report_parameters.tpl +++ b/plugins/PDFReports/templates/report_parameters.tpl @@ -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}'] = @@ -25,7 +32,6 @@ updateReportParametersFunctions['{$reportType}'] = function (reportParameters) {ldelim} - if(reportParameters == null) return; $('#display_format option[value='+reportParameters.displayFormat+']').prop('selected', 'selected'); @@ -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 @@ -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(); @@ -64,6 +82,7 @@ {rdelim}; $('#display_format').change(updateEvolutionGraphParameterVisibility); + $('#report_custom_texts').change(updateCustomTextsParameterVisibility); {rdelim}); @@ -79,6 +98,24 @@ + + + {'PDFReports_CustomizeEmail'|translate} + + + + +
+

+ {'PDFReports_CustomSubjectText'|translate}
+ +

+ {'PDFReports_CustomContentText'|translate}
+ + +
+ + {*PDFReports_AggregateReportsFormat should be named PDFReports_DisplayFormat*}