diff --git a/CRM/Admin/Page/Options.php b/CRM/Admin/Page/Options.php index 7eb50a7e0001..dbfe1b9005a9 100644 --- a/CRM/Admin/Page/Options.php +++ b/CRM/Admin/Page/Options.php @@ -151,6 +151,7 @@ public function preProcess() { $this->assign('showCounted', TRUE); } $this->assign('isLocked', self::$_isLocked); + $this->assign('allowLoggedIn', Civi::settings()->get('allow_mail_from_logged_in_contact')); $config = CRM_Core_Config::singleton(); if (self::$_gName == 'activity_type') { $this->assign('showComponent', TRUE); diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index cf81b45fa0a2..c8795f440780 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -1393,7 +1393,7 @@ public function addGroupBys() { foreach ($this->_columns as $tableName => $table) { if (array_key_exists('group_bys', $table)) { foreach ($table['group_bys'] as $fieldName => $field) { - if (!empty($field)) { + if (!empty($field) && empty($field['no_display'])) { $options[$field['title']] = $fieldName; if (!empty($field['frequency'])) { $freqElements[$field['title']] = $fieldName; @@ -5291,45 +5291,45 @@ protected function buildColumns($specs, $tableName, $daoName = NULL, $tableAlias */ protected function storeGroupByArray() { - if (CRM_Utils_Array::value('group_bys', $this->_params) && - is_array($this->_params['group_bys']) && - !empty($this->_params['group_bys']) - ) { - foreach ($this->_columns as $tableName => $table) { - $table = $this->_columns[$tableName]; - if (array_key_exists('group_bys', $table)) { - foreach ($table['group_bys'] as $fieldName => $fieldData) { - $field = $this->_columns[$tableName]['metadata'][$fieldName]; - if (!empty($this->_params['group_bys'][$fieldName])) { - if (!empty($field['chart'])) { - $this->assign('chartSupported', TRUE); - } + if (!CRM_Utils_Array::value('group_bys', $this->_params) + || !is_array($this->_params['group_bys'])) { + $this->_params['group_bys'] = []; + } - if (!empty($table['group_bys'][$fieldName]['frequency']) && - !empty($this->_params['group_bys_freq'][$fieldName]) - ) { + foreach ($this->_columns as $tableName => $table) { + $table = $this->_columns[$tableName]; + if (array_key_exists('group_bys', $table)) { + foreach ($table['group_bys'] as $fieldName => $fieldData) { + $field = $this->_columns[$tableName]['metadata'][$fieldName]; + if (!empty($this->_params['group_bys'][$fieldName]) || !empty($fieldData['required'])) { + if (!empty($field['chart'])) { + $this->assign('chartSupported', TRUE); + } - switch ($this->_params['group_bys_freq'][$fieldName]) { - case 'FISCALYEAR': - $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = self::fiscalYearOffset($field['dbAlias']); + if (!empty($table['group_bys'][$fieldName]['frequency']) && + !empty($this->_params['group_bys_freq'][$fieldName]) + ) { - case 'YEAR': - $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = " {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})"; + switch ($this->_params['group_bys_freq'][$fieldName]) { + case 'FISCALYEAR': + $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = self::fiscalYearOffset($field['dbAlias']); - default: - $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = "EXTRACT(YEAR_{$this->_params['group_bys_freq'][$fieldName]} FROM {$field['dbAlias']})"; + case 'YEAR': + $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = " {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})"; + + default: + $this->_groupByArray[$tableName . '_' . $fieldName . '_start'] = "EXTRACT(YEAR_{$this->_params['group_bys_freq'][$fieldName]} FROM {$field['dbAlias']})"; - } } - else { - if (!in_array($field['dbAlias'], $this->_groupByArray)) { - $this->_groupByArray[$tableName . '_' . $fieldName] = $field['dbAlias']; - } + } + else { + if (!in_array($field['dbAlias'], $this->_groupByArray)) { + $this->_groupByArray[$tableName . '_' . $fieldName] = $field['dbAlias']; } } } - } + } } } diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 7068fb7468a7..b64e45f58a53 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -36,6 +36,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { protected $_softFrom = NULL; + protected $noDisplayContributionOrSoftColumn = FALSE; + protected $_customGroupExtends = array( 'Contact', 'Individual', @@ -338,10 +340,6 @@ public function select() { $this->_columnHeaders = array(); parent::select(); - //total_amount was affected by sum as it is considered as one of the stat field - //so it is been replaced with correct alias, CRM-13833 - $this->_select = str_replace("sum({$this->_aliases['civicrm_contribution']}.total_amount)", "{$this->_aliases['civicrm_contribution']}.total_amount", $this->_select); - $this->_selectClauses = str_replace("sum({$this->_aliases['civicrm_contribution']}.total_amount)", "{$this->_aliases['civicrm_contribution']}.total_amount", $this->_selectClauses); } public function orderBy() { @@ -723,7 +721,7 @@ public function alterDisplay(&$rows) { } // Contribution amount links to viewing contribution - if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && + if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount', $row)) && CRM_Core_Permission::check('access CiviContribute') ) { $url = CRM_Utils_System::url("civicrm/contact/view/contribution", @@ -732,8 +730,8 @@ public function alterDisplay(&$rows) { "&action=view&context=contribution&selectedChild=contribute", $this->_absoluteUrl ); - $rows[$rowNum]['civicrm_contribution_total_amount_sum_link'] = $url; - $rows[$rowNum]['civicrm_contribution_total_amount_sum_hover'] = ts("View Details of this Contribution."); + $rows[$rowNum]['civicrm_contribution_total_amount_link'] = $url; + $rows[$rowNum]['civicrm_contribution_total_amount_hover'] = ts("View Details of this Contribution."); $entryFound = TRUE; } @@ -752,7 +750,7 @@ public function alterDisplay(&$rows) { array_key_exists('civicrm_contribution_contribution_id', $row) ) { $query = " -SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency +SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount, civicrm_contribution_currency FROM civireport_contribution_detail_temp2 WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}"; $this->addToDeveloperTab($query); @@ -764,7 +762,7 @@ public function alterDisplay(&$rows) { $dao->civicrm_contact_id); $string = $string . ($string ? $separator : '') . "{$dao->civicrm_contact_sort_name} " . - CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency); + CRM_Utils_Money::format($dao->civicrm_contribution_total_amount, $dao->civicrm_contribution_currency); } $rows[$rowNum]['civicrm_contribution_soft_credits'] = $string; } @@ -845,10 +843,10 @@ public function sectionTotals() { $addtotals = ''; - if (array_search("civicrm_contribution_total_amount_sum", $this->_selectAliases) !== + if (array_search("civicrm_contribution_total_amount", $this->_selectAliases) !== FALSE ) { - $addtotals = ", sum(civicrm_contribution_total_amount_sum) as sumcontribs"; + $addtotals = ", sum(civicrm_contribution_total_amount) as sumcontribs"; $showsumcontribs = TRUE; } diff --git a/CRM/Report/Form/Contribute/TopDonor.php b/CRM/Report/Form/Contribute/TopDonor.php index c7ebf9d90bdf..36a97fe44800 100644 --- a/CRM/Report/Form/Contribute/TopDonor.php +++ b/CRM/Report/Form/Contribute/TopDonor.php @@ -104,12 +104,13 @@ public function __construct() { ), ), 'filters' => $this->getBasicContactFilters(), + 'group_bys' => ['contact_contact_id' => ['name' => 'id', 'required' => 1, 'no_display' => 1]], ), 'civicrm_line_item' => array( 'dao' => 'CRM_Price_DAO_LineItem', ), ); - $this->_columns += $this->getAddressColumns(); + $this->_columns += $this->getAddressColumns(['group_by' => FALSE]); $this->_columns += array( 'civicrm_contribution' => array( 'dao' => 'CRM_Contribute_DAO_Contribution', @@ -159,6 +160,7 @@ public function __construct() { 'default' => array(1), ), ), + 'group_bys' => ['contribution_currency' => ['name' => 'currency', 'required' => 1, 'no_display' => 1]], ), 'civicrm_financial_trxn' => array( 'dao' => 'CRM_Financial_DAO_FinancialTrxn', @@ -208,19 +210,6 @@ public function __construct() { parent::__construct(); } - public function preProcess() { - parent::preProcess(); - } - - /** - * Select only contact ID when adding to group. - * - * @todo consider moving that to parent to support AddToGroup in general. - */ - public function select() { - parent::select(); - } - /** * @param $fields * @param $files @@ -316,10 +305,6 @@ public function where() { } } - public function groupBy() { - $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, array("{$this->_aliases['civicrm_contact']}.id", "{$this->_aliases['civicrm_contribution']}.currency")); - } - /** * Build output rows. * diff --git a/templates/CRM/Admin/Page/Options.tpl b/templates/CRM/Admin/Page/Options.tpl index 00a9185af24c..d1e7af21c83a 100644 --- a/templates/CRM/Admin/Page/Options.tpl +++ b/templates/CRM/Admin/Page/Options.tpl @@ -59,7 +59,11 @@ {elseif $gName eq 'participant_status'} {ts}Define statuses for event participants here (e.g. Registered, Attended, Cancelled...). You can then assign statuses and search for participants by status.{/ts} {ts}"Counted?" controls whether a person with that status is counted as participant for the purpose of controlling the Maximum Number of Participants.{/ts} {elseif $gName eq 'from_email_address'} - {ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, you can use this page to define one or more general Email Addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts} + {if $allowLoggedIn} + {ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, you can use this page to define one or more general Email Addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts} + {else} + {ts}You can use this page to define one or more general Email Addresses that can be selected as the From Address. EXAMPLE: "Client Services" <clientservices@example.org>{/ts} + {/if} {elseif $isLocked} {ts}This option group is reserved for system use. You cannot add or delete options in this list.{/ts} {else} diff --git a/templates/CRM/Contact/Form/Task/Email.hlp b/templates/CRM/Contact/Form/Task/Email.hlp index 4931100cd525..37a5ddecfae9 100644 --- a/templates/CRM/Contact/Form/Task/Email.hlp +++ b/templates/CRM/Contact/Form/Task/Email.hlp @@ -27,10 +27,18 @@ {ts}From Address{/ts} {/htxt} {htxt id="id-from_email"} -
{ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, users with Administer CiviCRM permission can configure one or more general email addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts}
+{if $params.logged_in_email_setting == "1"} +{ts}By default, CiviCRM uses the primary email address of the logged in user as the FROM address when sending emails to contacts. However, users with Administer CiviCRM permission can configure one or more general email addresses that can be selected as an alternative. EXAMPLE: "Client Services" <clientservices@example.org>{/ts}
+{else} +{ts}CiviCRM is currently configured to only use the defined From Email addresses. If you wish to be able to use the email address of the logged in user as the From Address you will need to set the setting "Allow mail from loged in contact" setting. Users with Administer CiviCRM can set this setting in the SMTP settings.{/ts}
+ {if $params.isAdmin} + {capture assign="smtpUrl"}{crmURL p="civicrm/admin/setting/smtp" q="reset=1"}{/capture} +
{ts 1=$smtpUrl}Go to Settings - Outbound Mail to enable the usage of the logged in contact's email address as the from email{/ts}
+ {/if} +{/if} {if $params.isAdmin} - {capture assign="fromConfig"}{crmURL p="civicrm/admin/options/from_email_address" q="reset=1"}{/capture} -{ts 1=$fromConfig}Go to Administer CiviCRM » Communications » FROM Email Addresses to add or edit general email addresses. Make sure these email addresses are valid email accounts with your email service provider.{/ts}
+ {capture assign="fromConfig"}{crmURL p="civicrm/admin/options/from_email_address" q="reset=1"}{/capture} +{ts 1=$fromConfig}Go to Administer CiviCRM » Communications » FROM Email Addresses to add or edit general email addresses. Make sure these email addresses are valid email accounts with your email service provider.{/ts}
{/if} {/htxt} diff --git a/templates/CRM/Contact/Form/Task/Email.tpl b/templates/CRM/Contact/Form/Task/Email.tpl index 96622dbd8767..107d23f7dc4e 100644 --- a/templates/CRM/Contact/Form/Task/Email.tpl +++ b/templates/CRM/Contact/Form/Task/Email.tpl @@ -30,10 +30,11 @@{ts count=$suppressedEmails plural='Email will NOT be sent to %count contacts - (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).'}Email will NOT be sent to %count contact - (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).{/ts}
{/if} +{crmSetting var="logged_in_email_setting" name="allow_mail_from_logged_in_contact"}{$form.from_email_address.label} | -{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin} | +{$form.from_email_address.html} {help id="id-from_email" file="CRM/Contact/Form/Task/Email.hlp" isAdmin=$isAdmin logged_in_email_setting=$logged_in_email_setting} |
{if $single eq false}{ts}Recipient(s){/ts}{else}{$form.to.label}{/if} | diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index d37c6095fa34..8cc5b6f6d822 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -188,7 +188,6 @@ public function testReportTemplateGetStatisticsAllReports($reportID) { public static function getReportTemplates() { $reportsToSkip = array( 'activity' => 'does not respect function signature on from clause', - 'contribute/topDonor' => 'construction of query in postProcess makes inaccessible ', 'event/income' => 'I do no understand why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120', 'logging/contact/summary' => '(likely to be test related) probably logging off Undefined index: Form/Contact/LoggingSummary.php(231): PHP', 'logging/contribute/summary' => '(likely to be test related) probably logging off DB Error: no such table',