Merge pull request #17178 from mattwire/simplifyrecurtemplates
[civicrm-core.git] / CRM / Report / Utils / Report.php
index 329bf0f83575839696effa228a7d25970cfdb0f8..e2ca8de2139b9c21c1185296d90ee6884e401184 100644 (file)
@@ -13,8 +13,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
  */
 class CRM_Report_Utils_Report {
 
@@ -31,8 +29,7 @@ class CRM_Report_Utils_Report {
       );
     }
     else {
-      $config = CRM_Core_Config::singleton();
-      $args = explode('/', $_GET[$config->userFrameworkURLVar]);
+      $args = explode('/', CRM_Utils_System::currentPath());
 
       // remove 'civicrm/report' from args
       array_shift($args);
@@ -188,9 +185,9 @@ WHERE  inst.report_id = %1";
     $params['from'] = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
     //$domainEmailName;
     $params['toName'] = "";
-    $params['toEmail'] = CRM_Utils_Array::value('email_to', $instanceInfo);
-    $params['cc'] = CRM_Utils_Array::value('email_cc', $instanceInfo);
-    $params['subject'] = CRM_Utils_Array::value('email_subject', $instanceInfo);
+    $params['toEmail'] = $instanceInfo['email_to'] ?? NULL;
+    $params['cc'] = $instanceInfo['email_cc'] ?? NULL;
+    $params['subject'] = $instanceInfo['email_subject'] ?? NULL;
     if (empty($instanceInfo['attachments'])) {
       $instanceInfo['attachments'] = [];
     }
@@ -251,10 +248,10 @@ WHERE  inst.report_id = %1";
     $value = NULL;
     foreach ($rows as $row) {
       foreach ($columnHeaders as $k => $v) {
-        $value = CRM_Utils_Array::value($v, $row);
+        $value = $row[$v] ?? NULL;
         if (isset($value)) {
           // Remove HTML, unencode entities, and escape quotation marks.
-          $value = str_replace('"', '""', html_entity_decode(strip_tags($value)));
+          $value = str_replace('"', '""', html_entity_decode(strip_tags($value), ENT_QUOTES | ENT_HTML401));
 
           if (CRM_Utils_Array::value('type', $form->_columnHeaders[$v]) & 4) {
             if (CRM_Utils_Array::value('group_by', $form->_columnHeaders[$v]) == 'MONTH' ||
@@ -298,15 +295,10 @@ WHERE  inst.report_id = %1";
    */
   public static function getInstanceID() {
 
-    $config = CRM_Core_Config::singleton();
-    $arg = explode('/', $_GET[$config->userFrameworkURLVar]);
+    $arg = explode('/', CRM_Utils_System::currentPath());
 
-    if ($arg[1] == 'report' &&
-      CRM_Utils_Array::value(2, $arg) == 'instance'
-    ) {
-      if (CRM_Utils_Rule::positiveInteger($arg[3])) {
-        return $arg[3];
-      }
+    if (isset($arg[3]) && $arg[1] == 'report' && $arg[2] == 'instance' && CRM_Utils_Rule::positiveInteger($arg[3])) {
+      return $arg[3];
     }
   }
 
@@ -314,15 +306,11 @@ WHERE  inst.report_id = %1";
    * @return string
    */
   public static function getInstancePath() {
-    $config = CRM_Core_Config::singleton();
-    $arg = explode('/', $_GET[$config->userFrameworkURLVar]);
+    $arg = explode('/', CRM_Utils_System::currentPath());
 
-    if ($arg[1] == 'report' &&
-      CRM_Utils_Array::value(2, $arg) == 'instance'
-    ) {
+    if (isset($arg[3]) && $arg[1] == 'report' && $arg[2] == 'instance') {
       unset($arg[0], $arg[1], $arg[2]);
-      $path = trim(CRM_Utils_Type::escape(implode('/', $arg), 'String'), '/');
-      return $path;
+      return trim(CRM_Utils_Type::escape(implode('/', $arg), 'String'), '/');
     }
   }
 
@@ -395,7 +383,7 @@ WHERE  inst.report_id = %1";
    * @return array
    */
   public static function processReport($params) {
-    $instanceId = CRM_Utils_Array::value('instanceId', $params);
+    $instanceId = $params['instanceId'] ?? NULL;
 
     // hack for now, CRM-8358
     $_REQUEST['instanceId'] = $instanceId;
@@ -502,7 +490,7 @@ WHERE  inst.report_id = %1";
             // (e.g., values for 'nll' and 'nnll' ops are blank),
             // so store them temporarily and examine below.
             $string_values[$basename] = $field_value;
-            $op_values[$basename] = CRM_Utils_Array::value("{$basename}_op", $params);
+            $op_values[$basename] = $params["{$basename}_op"] ?? NULL;
           }
           elseif ($suffix == '_op') {
             // These filters can have an effect even without a value