From 86545d90d61266e6571b9d087fc82cbb4aabc478 Mon Sep 17 00:00:00 2001
From: Kevin Cristiano <kcristiano@tadpole.cc>
Date: Fri, 26 Oct 2018 14:22:17 -0400
Subject: [PATCH] civicrm 5.6.1

Signed-off-by: Kevin Cristiano <kcristiano@tadpole.cc>
---
 assets/templates/civicrm.shortcode.php        |   2 +-
 civicrm.php                                   |   7 +-
 civicrm/CRM/Contact/BAO/SavedSearch.php       |  34 +--
 civicrm/CRM/Contact/Page/View/Summary.php     | 201 ++++++++----------
 civicrm/CRM/Core/BAO/CustomField.php          |  12 +-
 civicrm/CRM/Core/BAO/MessageTemplate.php      |  27 +++
 civicrm/CRM/Core/Component.php                |   6 +-
 civicrm/CRM/Core/Permission.php               |   4 +-
 civicrm/CRM/Grant/Info.php                    |   2 +-
 civicrm/CRM/Mailing/BAO/Mailing.php           |   2 +
 civicrm/CRM/Report/Form.php                   |   3 +-
 civicrm/CRM/Report/Form/Activity.php          |   4 +-
 .../Upgrade/Incremental/sql/5.6.1.mysql.tpl   |   1 +
 civicrm/CRM/Utils/System/WordPress.php        |  10 +-
 .../bower_components/jquery-ui/.bower.json    |   2 +-
 civicrm/civicrm-version.php                   |   2 +-
 civicrm/css/joomla.css                        |   1 +
 civicrm/release-notes/5.6.1.md                |  44 ++++
 civicrm/sql/civicrm_data.mysql                |   2 +-
 civicrm/sql/civicrm_generated.mysql           |   2 +-
 civicrm/vendor/autoload.php                   |   2 +-
 civicrm/vendor/composer/autoload_real.php     |  14 +-
 civicrm/vendor/composer/autoload_static.php   |  10 +-
 civicrm/xml/version.xml                       |   2 +-
 includes/civicrm.basepage.php                 |   2 +-
 includes/civicrm.shortcodes.modal.php         |   2 +-
 includes/civicrm.shortcodes.php               |   2 +-
 includes/civicrm.users.php                    |   2 +-
 languages/civicrm.pot                         |   2 +-
 uninstall.php                                 |   2 +-
 wp-cli/civicrm.php                            |   2 +-
 31 files changed, 237 insertions(+), 173 deletions(-)
 create mode 100644 civicrm/CRM/Upgrade/Incremental/sql/5.6.1.mysql.tpl
 create mode 100644 civicrm/release-notes/5.6.1.md

diff --git a/assets/templates/civicrm.shortcode.php b/assets/templates/civicrm.shortcode.php
index 02f45e08df..c590390b01 100644
--- a/assets/templates/civicrm.shortcode.php
+++ b/assets/templates/civicrm.shortcode.php
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/civicrm.php b/civicrm.php
index 1830f1e12c..19aa9993e3 100644
--- a/civicrm.php
+++ b/civicrm.php
@@ -2,11 +2,10 @@
 /*
 Plugin Name: CiviCRM
 Description: CiviCRM - Growing and Sustaining Relationships
-Version: 5.6.0
+Version: 5.6.1
 Author: CiviCRM LLC
 Author URI: https://civicrm.org/
 Plugin URI: https://wiki.civicrm.org/confluence/display/CRMDOC/Installing+CiviCRM+for+WordPress
-GitHub Plugin URI: https://github.com/tadpolecc/civicrm.git
 License: AGPL3
 Text Domain: civicrm
 Domain Path: /languages
@@ -15,7 +14,7 @@ Domain Path: /languages
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
@@ -71,7 +70,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
 
 
 // set version here: when it changes, will force JS to reload
-define( 'CIVICRM_PLUGIN_VERSION', '5' );
+define( 'CIVICRM_PLUGIN_VERSION', '4.7' );
 
 // store reference to this file
 if (!defined('CIVICRM_PLUGIN_FILE')) {
diff --git a/civicrm/CRM/Contact/BAO/SavedSearch.php b/civicrm/CRM/Contact/BAO/SavedSearch.php
index da2b6fd946..b33fa859de 100644
--- a/civicrm/CRM/Contact/BAO/SavedSearch.php
+++ b/civicrm/CRM/Contact/BAO/SavedSearch.php
@@ -124,20 +124,30 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch {
             continue;
           }
         }
+        // Check for a date range field, which might be a standard date
+        // range or a relative date.
         if (strpos($id, '_date_low') !== FALSE || strpos($id, '_date_high') !== FALSE) {
           $entityName = strstr($id, '_date', TRUE);
-          if (!empty($result['relative_dates']) && array_key_exists($entityName, $result['relative_dates'])) {
-            $result[$id] = NULL;
-            $result["{$entityName}_date_relative"] = $result['relative_dates'][$entityName];
-          }
-          elseif (!empty($specialDateFields[$id])) {
-            $entityName = strstr($specialDateFields[$id], '_date', TRUE);
-            $result[$id] = NULL;
-            $result["{$entityName}_relative"] = $result['relative_dates'][$entityName];
-          }
-          else {
-            $result[$id] = $value;
-            $result["{$entityName}_date_relative"] = 0;
+
+          // This is the default, for non relative dates. We will overwrite
+          // it if we determine this is a relative date.
+          $result[$id] = $value;
+          $result["{$entityName}_date_relative"] = 0;
+
+          if (!empty($result['relative_dates'])) {
+            if (array_key_exists($entityName, $result['relative_dates'])) {
+              // We have a match from a regular field.
+              $result[$id] = NULL;
+              $result["{$entityName}_date_relative"] = $result['relative_dates'][$entityName];
+            }
+            elseif (!empty($specialDateFields[$id])) {
+              // We may have a match on a special date field.
+              $entityName = strstr($specialDateFields[$id], '_date', TRUE);
+              if (array_key_exists($entityName, $result['relative_dates'])) {
+                $result[$id] = NULL;
+                $result["{$entityName}_relative"] = $result['relative_dates'][$entityName];
+              }
+            }
           }
         }
         else {
diff --git a/civicrm/CRM/Contact/Page/View/Summary.php b/civicrm/CRM/Contact/Page/View/Summary.php
index e8cad663a1..d41da69d8f 100644
--- a/civicrm/CRM/Contact/Page/View/Summary.php
+++ b/civicrm/CRM/Contact/Page/View/Summary.php
@@ -264,105 +264,23 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
     $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact');
     $this->assign_by_ref('lastModified', $lastModified);
 
+    $allTabs = array();
+    $weight = 10;
+
     $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(
       CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
       'contact_view_options',
       TRUE
     );
 
+    // show the tabs only if user has generic access to CiviCRM
+    $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
+
     $changeLog = $this->_viewOptions['log'];
     $this->assign_by_ref('changeLog', $changeLog);
+    $components = CRM_Core_Component::getEnabledComponents();
 
-    $this->assign('allTabs', $this->getTabs());
-
-    // hook for contact summary
-    // ignored but needed to prevent warnings
-    $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
-    CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
-    if ($content) {
-      $this->assign_by_ref('hookContent', $content);
-      $this->assign('hookContentPlacement', $contentPlacement);
-    }
-  }
-
-  /**
-   * @return string
-   */
-  public function getTemplateFileName() {
-    if ($this->_contactId) {
-      $contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array();
-
-      // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
-      foreach ($contactSubtypes as $csType) {
-        if ($csType) {
-          $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
-          $template = CRM_Core_Page::getTemplate();
-          if ($template->template_exists($templateFile)) {
-            return $templateFile;
-          }
-        }
-      }
-    }
-    return parent::getTemplateFileName();
-  }
-
-  /**
-   * @return array
-   */
-  public static function basicTabs() {
-    return [
-      [
-        'id' => 'summary',
-        'url' => '#contact-summary',
-        'title' => ts('Summary'),
-        'weight' => 0,
-      ],
-      [
-        'id' => 'activity',
-        'title' => ts('Activities'),
-        'class' => 'livePage',
-        'weight' => 70,
-      ],
-      [
-        'id' => 'rel',
-        'title' => ts('Relationships'),
-        'class' => 'livePage',
-        'weight' => 80,
-      ],
-      [
-        'id' => 'group',
-        'title' => ts('Groups'),
-        'class' => 'ajaxForm',
-        'weight' => 90,
-      ],
-      [
-        'id' => 'note',
-        'title' => ts('Notes'),
-        'class' => 'livePage',
-        'weight' => 100,
-      ],
-      [
-        'id' => 'tag',
-        'title' => ts('Tags'),
-        'weight' => 110,
-      ],
-      [
-        'id' => 'log',
-        'title' => ts('Change Log'),
-        'weight' => 120,
-      ],
-    ];
-  }
-
-  /**
-   * @return array
-   * @throws \CRM_Core_Exception
-   */
-  public function getTabs() {
-    $allTabs = [];
-    $weight = 10;
-
-    foreach (CRM_Core_Component::getEnabledComponents() as $name => $component) {
+    foreach ($components as $name => $component) {
       if (!empty($this->_viewOptions[$name]) &&
         CRM_Core_Permission::access($component->name)
       ) {
@@ -384,32 +302,59 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
         if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) {
           $q .= "&isTest=1";
         }
-        $allTabs[] = [
+        $allTabs[] = array(
           'id' => $i,
           'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q),
           'title' => $elem['title'],
           'weight' => $elem['weight'],
           'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId),
           'class' => 'livePage',
-        ];
+        );
+        // make sure to get maximum weight, rest of tabs go after
+        // FIXME: not very elegant again
+        if ($weight < $elem['weight']) {
+          $weight = $elem['weight'];
+        }
       }
     }
 
-    // show the tabs only if user has generic access to CiviCRM
-    $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM');
-    foreach (self::basicTabs() as $tab) {
-      if ($tab['id'] == 'summary') {
-        $allTabs[] = $tab;
-      }
-      elseif ($accessCiviCRM && !empty($this->_viewOptions[$tab['id']])) {
-        $allTabs[] = $tab + [
+    $rest = array(
+      'activity' => array(
+        'title' => ts('Activities'),
+        'class' => 'livePage',
+      ),
+      'rel' => array(
+        'title' => ts('Relationships'),
+        'class' => 'livePage',
+      ),
+      'group' => array(
+        'title' => ts('Groups'),
+        'class' => 'ajaxForm',
+      ),
+      'note' => array(
+        'title' => ts('Notes'),
+        'class' => 'livePage',
+      ),
+      'tag' => array(
+        'title' => ts('Tags'),
+      ),
+      'log' => array(
+        'title' => ts('Change Log'),
+      ),
+    );
+
+    foreach ($rest as $k => $v) {
+      if ($accessCiviCRM && !empty($this->_viewOptions[$k])) {
+        $allTabs[] = $v + array(
+          'id' => $k,
           'url' => CRM_Utils_System::url(
-            "civicrm/contact/view/{$tab['id']}",
+            "civicrm/contact/view/$k",
             "reset=1&cid={$this->_contactId}"
           ),
-          'count' => CRM_Contact_BAO_Contact::getCountComponent($tab['id'], $this->_contactId),
-        ];
-        $weight = $tab['weight'] + 10;
+          'weight' => $weight,
+          'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId),
+        );
+        $weight += 10;
       }
     }
 
@@ -423,7 +368,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
 
     foreach ($activeGroups as $group) {
       $id = "custom_{$group['id']}";
-      $allTabs[] = [
+      $allTabs[] = array(
         'id' => $id,
         'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"),
         'title' => $group['title'],
@@ -431,18 +376,56 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
         'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']),
         'hideCount' => !$group['is_multiple'],
         'class' => 'livePage',
-      ];
+      );
       $weight += 10;
     }
 
-    $context = ['contact_id' => $this->_contactId];
+    $context = array('contact_id' => $this->_contactId);
     // see if any other modules want to add any tabs
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
 
+    $allTabs[] = array(
+      'id' => 'summary',
+      'url' => '#contact-summary',
+      'title' => ts('Summary'),
+      'weight' => 0,
+    );
+
     // now sort the tabs based on weight
-    usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']);
-    return $allTabs;
+    usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
+
+    $this->assign('allTabs', $allTabs);
+
+    // hook for contact summary
+    // ignored but needed to prevent warnings
+    $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW;
+    CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement);
+    if ($content) {
+      $this->assign_by_ref('hookContent', $content);
+      $this->assign('hookContentPlacement', $contentPlacement);
+    }
+  }
+
+  /**
+   * @return string
+   */
+  public function getTemplateFileName() {
+    if ($this->_contactId) {
+      $contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array();
+
+      // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
+      foreach ($contactSubtypes as $csType) {
+        if ($csType) {
+          $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
+          $template = CRM_Core_Page::getTemplate();
+          if ($template->template_exists($templateFile)) {
+            return $templateFile;
+          }
+        }
+      }
+    }
+    return parent::getTemplateFileName();
   }
 
 }
diff --git a/civicrm/CRM/Core/BAO/CustomField.php b/civicrm/CRM/Core/BAO/CustomField.php
index 6176ba1030..6fc3fe7d49 100644
--- a/civicrm/CRM/Core/BAO/CustomField.php
+++ b/civicrm/CRM/Core/BAO/CustomField.php
@@ -1662,7 +1662,7 @@ SELECT id
       $value = 0;
     }
 
-    $fileID = NULL;
+    $fileId = NULL;
 
     if ($customFields[$customFieldId]['data_type'] == 'File') {
       if (empty($value)) {
@@ -1701,20 +1701,20 @@ SELECT $columnName
   FROM $tableName
  WHERE id = %1";
         $params = array(1 => array($customValueId, 'Integer'));
-        $fileID = CRM_Core_DAO::singleValueQuery($query, $params);
+        $fileId = CRM_Core_DAO::singleValueQuery($query, $params);
       }
 
       $fileDAO = new CRM_Core_DAO_File();
 
-      if ($fileID) {
-        $fileDAO->id = $fileID;
+      if ($fileId) {
+        $fileDAO->id = $fileId;
       }
 
       $fileDAO->uri = $filename;
       $fileDAO->mime_type = $mimeType;
       $fileDAO->upload_date = date('YmdHis');
       $fileDAO->save();
-      $fileID = $fileDAO->id;
+      $fileId = $fileDAO->id;
       $value = $filename;
     }
 
@@ -1742,7 +1742,7 @@ SELECT $columnName
       'custom_group_id' => $groupID,
       'table_name' => $tableName,
       'column_name' => $columnName,
-      'file_id' => $fileID,
+      'file_id' => $fileId,
       'is_multiple' => $customFields[$customFieldId]['is_multiple'],
     );
 
diff --git a/civicrm/CRM/Core/BAO/MessageTemplate.php b/civicrm/CRM/Core/BAO/MessageTemplate.php
index 9d2b002aac..0fd69789cc 100644
--- a/civicrm/CRM/Core/BAO/MessageTemplate.php
+++ b/civicrm/CRM/Core/BAO/MessageTemplate.php
@@ -83,6 +83,33 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate {
    * @return object
    */
   public static function add(&$params) {
+    // System Workflow Templates have a specific wodkflow_id in them but normal user end message templates don't
+    // If we have an id check to see if we are update, and need to check if original is a system workflow or not.
+    $systemWorkflowPermissionDeniedMessage = 'Editing or creating system workflow messages requires edit system workflow message templates permission or the edit message templates permission';
+    $userWorkflowPermissionDeniedMessage = 'Editing or creating user driven workflow messages requires edit user-driven message templates or the edit message templates permission';
+    if (!empty($params['check_permissions'])) {
+      if (!CRM_Core_Permission::check('edit message templates')) {
+        if (!empty($params['id'])) {
+          $details = civicrm_api3('MessageTemplate', 'getSingle', ['id' => $params['id']]);
+          if (!empty($details['workflow_id'])) {
+            if (!CRM_Core_Permission::check('edit system workflow message templates')) {
+              throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
+            }
+          }
+          elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
+            throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $userWorkflowPermissionDeniedMessage]));
+          }
+        }
+        else {
+          if (!empty($params['workflow_id']) && !CRM_Core_Permission::check('edit system workflow message templates')) {
+            throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
+          }
+          elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
+            throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $userWorkflowPermissionDeniedMessage]));
+          }
+        }
+      }
+    }
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'MessageTemplate', CRM_Utils_Array::value('id', $params), $params);
 
diff --git a/civicrm/CRM/Core/Component.php b/civicrm/CRM/Core/Component.php
index 4a379eaf9f..8316aafd86 100644
--- a/civicrm/CRM/Core/Component.php
+++ b/civicrm/CRM/Core/Component.php
@@ -47,7 +47,7 @@ class CRM_Core_Component {
   /**
    * @param bool $force
    *
-   * @return CRM_Core_Component_Info[]
+   * @return array|null
    */
   private static function &_info($force = FALSE) {
     if (!isset(Civi::$statics[__CLASS__]['info'])|| $force) {
@@ -84,7 +84,7 @@ class CRM_Core_Component {
   /**
    * @param bool $force
    *
-   * @return CRM_Core_Component_Info[]
+   * @return array
    * @throws Exception
    */
   public static function &getComponents($force = FALSE) {
@@ -132,7 +132,7 @@ class CRM_Core_Component {
   /**
    * @param bool $force
    *
-   * @return CRM_Core_Component_Info[]
+   * @return array|null
    */
   static public function &getEnabledComponents($force = FALSE) {
     return self::_info($force);
diff --git a/civicrm/CRM/Core/Permission.php b/civicrm/CRM/Core/Permission.php
index 49d003dd62..3448f7f0df 100644
--- a/civicrm/CRM/Core/Permission.php
+++ b/civicrm/CRM/Core/Permission.php
@@ -1486,8 +1486,8 @@ class CRM_Core_Permission {
 
     $permissions['message_template'] = array(
       'get' => array('access CiviCRM'),
-      'create' => array('edit message templates', 'edit user-driven message templates', 'edit system workflow message templates'),
-      'update' => array('edit message templates', 'edit user-driven message templates', 'edit system workflow message templates'),
+      'create' => array(array('edit message templates', 'edit user-driven message templates', 'edit system workflow message templates')),
+      'update' => array(array('edit message templates', 'edit user-driven message templates', 'edit system workflow message templates')),
     );
 
     $permissions['report_template']['update'] = 'save Report Criteria';
diff --git a/civicrm/CRM/Grant/Info.php b/civicrm/CRM/Grant/Info.php
index 1bf6045ff2..acd3e20f09 100644
--- a/civicrm/CRM/Grant/Info.php
+++ b/civicrm/CRM/Grant/Info.php
@@ -117,7 +117,7 @@ class CRM_Grant_Info extends CRM_Core_Component_Info {
     return array(
       'title' => ts('Grants'),
       'url' => 'grant',
-      'weight' => 60,
+      'weight' => 50,
     );
   }
 
diff --git a/civicrm/CRM/Mailing/BAO/Mailing.php b/civicrm/CRM/Mailing/BAO/Mailing.php
index dd4ef5bc01..b5e4561582 100644
--- a/civicrm/CRM/Mailing/BAO/Mailing.php
+++ b/civicrm/CRM/Mailing/BAO/Mailing.php
@@ -296,9 +296,11 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->select("$contact.id as contact_id, $entityTable.id as $entityColumn")
         ->join($entityTable, " INNER JOIN $entityTable ON $entityTable.contact_id = $contact.id ")
         ->join('gc', " INNER JOIN civicrm_group_contact_cache gc ON $contact.id = gc.contact_id ")
+        ->join('gcr', " LEFT JOIN civicrm_group_contact gcr ON gc.group_id = gcr.group_id AND gc.contact_id = gcr.contact_id")
         ->join('mg', " INNER JOIN civicrm_mailing_group mg  ON  gc.group_id = mg.entity_id AND mg.search_id IS NULL ")
         ->join('temp', " LEFT JOIN $excludeTempTablename temp ON $contact.id = temp.contact_id ")
         ->where('gc.group_id IN (#groups)')
+        ->where('gcr.status IS NULL OR gcr.status != "Removed"')
         ->merge($criteria)
         ->replaceInto($includedTempTablename, array('contact_id', $entityColumn))
         ->param('#groups', $includeSmartGroupIDs)
diff --git a/civicrm/CRM/Report/Form.php b/civicrm/CRM/Report/Form.php
index 7686111204..29d228b9de 100644
--- a/civicrm/CRM/Report/Form.php
+++ b/civicrm/CRM/Report/Form.php
@@ -2449,8 +2449,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
    * @return mixed
    */
   protected function alterLocationTypeID($value, &$row, $selectedfield, $criteriaFieldName) {
-    $values = $this->getLocationTypeOptions();
-    return CRM_Utils_Array::value($value, $values);
+    return CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Address', 'location_type_id', $value);
   }
 
   /**
diff --git a/civicrm/CRM/Report/Form/Activity.php b/civicrm/CRM/Report/Form/Activity.php
index 9b55f415fa..a2c95fe8a5 100644
--- a/civicrm/CRM/Report/Form/Activity.php
+++ b/civicrm/CRM/Report/Form/Activity.php
@@ -693,7 +693,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
     $new_having = ' addtogroup_contact_id';
     $having = str_ireplace(' civicrm_contact_contact_target_id', $new_having, $this->_having);
     $query = "$select
-FROM {$this->temporaryTables['activity_temp_table']} tar
+FROM {$this->temporaryTables['activity_temp_table']['name']} tar
 GROUP BY civicrm_activity_id $having {$this->_orderBy}";
     $select = 'AS addtogroup_contact_id';
     $query = str_ireplace('AS civicrm_contact_contact_target_id', $select, $query);
@@ -1080,7 +1080,7 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
       $this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($ifnulls, $sectionAliases);
 
       $query = $this->_select .
-        ", count(DISTINCT civicrm_activity_id) as ct from {$this->temporaryTables['activity_temp_table']} group by " .
+        ", count(DISTINCT civicrm_activity_id) as ct from {$this->temporaryTables['activity_temp_table']['name']} group by " .
         implode(", ", $sectionAliases);
 
       // initialize array of total counts
diff --git a/civicrm/CRM/Upgrade/Incremental/sql/5.6.1.mysql.tpl b/civicrm/CRM/Upgrade/Incremental/sql/5.6.1.mysql.tpl
new file mode 100644
index 0000000000..b4c965826f
--- /dev/null
+++ b/civicrm/CRM/Upgrade/Incremental/sql/5.6.1.mysql.tpl
@@ -0,0 +1 @@
+{* file to handle db changes in 5.6.1 during upgrade *}
diff --git a/civicrm/CRM/Utils/System/WordPress.php b/civicrm/CRM/Utils/System/WordPress.php
index 7bdb1e9ea1..f2df6c8476 100644
--- a/civicrm/CRM/Utils/System/WordPress.php
+++ b/civicrm/CRM/Utils/System/WordPress.php
@@ -767,13 +767,11 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     $contactCreated = 0;
     $contactMatching = 0;
 
-    // previously used $wpdb - which means WordPress *must* be bootstrapped
-    $wpUsers = get_users(array(
-      'blog_id' => get_current_blog_id(),
-      'number' => -1,
-    ));
+    global $wpdb;
+    $wpUserIds = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users");
 
-    foreach ($wpUsers as $wpUserData) {
+    foreach ($wpUserIds as $wpUserId) {
+      $wpUserData = get_userdata($wpUserId);
       $contactCount++;
       if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($wpUserData,
         $wpUserData->$id,
diff --git a/civicrm/bower_components/jquery-ui/.bower.json b/civicrm/bower_components/jquery-ui/.bower.json
index d28097dd88..a37977e293 100644
--- a/civicrm/bower_components/jquery-ui/.bower.json
+++ b/civicrm/bower_components/jquery-ui/.bower.json
@@ -17,6 +17,6 @@
     "commit": "44ecf3794cc56b65954cc19737234a3119d036cc"
   },
   "_source": "https://github.com/components/jqueryui.git",
-  "_target": "~1.12",
+  "_target": ">=1.9",
   "_originalSource": "jquery-ui"
 }
\ No newline at end of file
diff --git a/civicrm/civicrm-version.php b/civicrm/civicrm-version.php
index ba95fa041c..3e8214f329 100644
--- a/civicrm/civicrm-version.php
+++ b/civicrm/civicrm-version.php
@@ -1,7 +1,7 @@
 <?php
 /** @deprecated */
 function civicrmVersion( ) {
-  return array( 'version'  => '5.6.0',
+  return array( 'version'  => '5.6.1',
                 'cms'      => 'Wordpress',
                 'revision' => '' );
 }
diff --git a/civicrm/css/joomla.css b/civicrm/css/joomla.css
index 195f38bec4..57eb00d002 100644
--- a/civicrm/css/joomla.css
+++ b/civicrm/css/joomla.css
@@ -296,6 +296,7 @@ br.clear {
 
 ul#civicrm-menu {
   position:relative;
+  z-index:1;
 }
 
 div#toolbar-box div.m {
diff --git a/civicrm/release-notes/5.6.1.md b/civicrm/release-notes/5.6.1.md
new file mode 100644
index 0000000000..74df77ea70
--- /dev/null
+++ b/civicrm/release-notes/5.6.1.md
@@ -0,0 +1,44 @@
+# CiviCRM 5.6.1
+
+Released 23 Oct 2018
+
+- **[Synopsis](#synopsis)**
+- **[Bugs resolved](#bugs)**
+- **[Credits](#credits)**
+- **[Feedback](#feedback)**
+
+## <a name="synopsis"></a>Synopsis
+
+| *Does this version...?*                                         |         |
+|:--------------------------------------------------------------- |:-------:|
+| Fix security vulnerabilities?                                   |   no    |
+| Change the database schema?                                     |   no    |
+| Alter the API?                                                  |   no    |
+| Require attention to configuration options?                     |   no    |
+| Fix problems installing or upgrading to a previous version?     |   no    |
+| Introduce features?                                             |   no    |
+| **Fix bugs?**                                                   | **yes** |
+
+## <a name="bugs"></a>Bugs resolved
+
+- **Fix regressions in activity-detail and contact-summary reports (Backport: [12963](https://github.com/civicrm/civicrm-core/pull/12963),
+  [12915](https://github.com/civicrm/civicrm-core/pull/12915), [12967](https://github.com/civicrm/civicrm-core/pull/12967))**
+- **Fix for Joomla menu alignment (Backport: [12952](https://github.com/civicrm/civicrm-core/pull/12952))**
+- **Fix for manual date ranges in smart-groups (Backport: [12909](https://github.com/civicrm/civicrm-core/pull/12909))**
+- **(dev/core#421) Fix for overzealous message-template permissioning (Backport: [12896](https://github.com/civicrm/civicrm-core/pull/12896))**
+- **(dev/core#448) Fix for handling smart-group removals (Backport: [12962](https://github.com/civicrm/civicrm-core/pull/12962))**
+
+## <a name="credits"></a>Credits
+
+This release was developed by the following authors and reviewers:
+
+Wikimedia Foundation - Eileen McNaughton; Thomas Mannell; Progressive
+Technology Project - Jamie McClelland; Pradeep Nayak; Nicol Wistreich;
+Joinery - Allen Shaw; JMA Consulting - Monish Deb; Circle Interactive -
+Martin Castle; Australian Greens - Seamus Lee; Agileware - Justin Freeman
+
+## <a name="feedback"></a>Feedback
+
+These release notes are edited by Tim Otten and Andrew Hunt.  If you'd like to
+provide feedback on them, please login to https://chat.civicrm.org/civicrm and
+contact `@agh1`.
diff --git a/civicrm/sql/civicrm_data.mysql b/civicrm/sql/civicrm_data.mysql
index 6469929e49..9b262dbcc6 100644
--- a/civicrm/sql/civicrm_data.mysql
+++ b/civicrm/sql/civicrm_data.mysql
@@ -23979,4 +23979,4 @@ INSERT INTO `civicrm_report_instance`
     ( `domain_id`, `title`, `report_id`, `description`, `permission`, `form_values`)
 VALUES
     (  @domainID, 'Survey Details', 'survey/detail', 'Detailed report for canvassing, phone-banking, walk lists or other surveys.', 'access CiviReport', 'a:39:{s:6:"fields";a:2:{s:9:"sort_name";s:1:"1";s:6:"result";s:1:"1";}s:22:"assignee_contact_id_op";s:2:"eq";s:25:"assignee_contact_id_value";s:0:"";s:12:"sort_name_op";s:3:"has";s:15:"sort_name_value";s:0:"";s:17:"street_number_min";s:0:"";s:17:"street_number_max";s:0:"";s:16:"street_number_op";s:3:"lte";s:19:"street_number_value";s:0:"";s:14:"street_name_op";s:3:"has";s:17:"street_name_value";s:0:"";s:15:"postal_code_min";s:0:"";s:15:"postal_code_max";s:0:"";s:14:"postal_code_op";s:3:"lte";s:17:"postal_code_value";s:0:"";s:7:"city_op";s:3:"has";s:10:"city_value";s:0:"";s:20:"state_province_id_op";s:2:"in";s:23:"state_province_id_value";a:0:{}s:13:"country_id_op";s:2:"in";s:16:"country_id_value";a:0:{}s:12:"survey_id_op";s:2:"in";s:15:"survey_id_value";a:0:{}s:12:"status_id_op";s:2:"eq";s:15:"status_id_value";s:1:"1";s:11:"custom_1_op";s:2:"in";s:14:"custom_1_value";a:0:{}s:11:"custom_2_op";s:2:"in";s:14:"custom_2_value";a:0:{}s:17:"custom_3_relative";s:1:"0";s:13:"custom_3_from";s:0:"";s:11:"custom_3_to";s:0:"";s:11:"description";s:75:"Detailed report for canvassing, phone-banking, walk lists or other surveys.";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:17:"access CiviReport";s:6:"groups";s:0:"";s:9:"domain_id";i:1;}');
-UPDATE civicrm_domain SET version = '5.6.0';
+UPDATE civicrm_domain SET version = '5.6.1';
diff --git a/civicrm/sql/civicrm_generated.mysql b/civicrm/sql/civicrm_generated.mysql
index 8f13232e55..f2876110c6 100644
--- a/civicrm/sql/civicrm_generated.mysql
+++ b/civicrm/sql/civicrm_generated.mysql
@@ -399,7 +399,7 @@ UNLOCK TABLES;
 
 LOCK TABLES `civicrm_domain` WRITE;
 /*!40000 ALTER TABLE `civicrm_domain` DISABLE KEYS */;
-INSERT INTO `civicrm_domain` (`id`, `name`, `description`, `config_backend`, `version`, `contact_id`, `locales`, `locale_custom_strings`) VALUES (1,'Default Domain Name',NULL,NULL,'5.6.0',1,NULL,'a:1:{s:5:\"en_US\";a:0:{}}');
+INSERT INTO `civicrm_domain` (`id`, `name`, `description`, `config_backend`, `version`, `contact_id`, `locales`, `locale_custom_strings`) VALUES (1,'Default Domain Name',NULL,NULL,'5.6.1',1,NULL,'a:1:{s:5:\"en_US\";a:0:{}}');
 /*!40000 ALTER TABLE `civicrm_domain` ENABLE KEYS */;
 UNLOCK TABLES;
 
diff --git a/civicrm/vendor/autoload.php b/civicrm/vendor/autoload.php
index bcb4f7e149..1a08351cbc 100644
--- a/civicrm/vendor/autoload.php
+++ b/civicrm/vendor/autoload.php
@@ -4,4 +4,4 @@
 
 require_once __DIR__ . '/composer/autoload_real.php';
 
-return ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c::getLoader();
+return ComposerAutoloaderInit6380814b9cfdf6d165564b66c3e668d5::getLoader();
diff --git a/civicrm/vendor/composer/autoload_real.php b/civicrm/vendor/composer/autoload_real.php
index 333e8fce71..0e80ba571e 100644
--- a/civicrm/vendor/composer/autoload_real.php
+++ b/civicrm/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
 
 // autoload_real.php @generated by Composer
 
-class ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c
+class ComposerAutoloaderInit6380814b9cfdf6d165564b66c3e668d5
 {
     private static $loader;
 
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c
             return self::$loader;
         }
 
-        spl_autoload_register(array('ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c', 'loadClassLoader'), true, true);
+        spl_autoload_register(array('ComposerAutoloaderInit6380814b9cfdf6d165564b66c3e668d5', 'loadClassLoader'), true, true);
         self::$loader = $loader = new \Composer\Autoload\ClassLoader();
-        spl_autoload_unregister(array('ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c', 'loadClassLoader'));
+        spl_autoload_unregister(array('ComposerAutoloaderInit6380814b9cfdf6d165564b66c3e668d5', 'loadClassLoader'));
 
         $includePaths = require __DIR__ . '/include_paths.php';
         $includePaths[] = get_include_path();
@@ -31,7 +31,7 @@ class ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c
         if ($useStaticLoader) {
             require_once __DIR__ . '/autoload_static.php';
 
-            call_user_func(\Composer\Autoload\ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::getInitializer($loader));
+            call_user_func(\Composer\Autoload\ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::getInitializer($loader));
         } else {
             $map = require __DIR__ . '/autoload_namespaces.php';
             foreach ($map as $namespace => $path) {
@@ -52,19 +52,19 @@ class ComposerAutoloaderInit51610d91ebd47e0f48d98a5f52f3068c
         $loader->register(true);
 
         if ($useStaticLoader) {
-            $includeFiles = Composer\Autoload\ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::$files;
+            $includeFiles = Composer\Autoload\ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::$files;
         } else {
             $includeFiles = require __DIR__ . '/autoload_files.php';
         }
         foreach ($includeFiles as $fileIdentifier => $file) {
-            composerRequire51610d91ebd47e0f48d98a5f52f3068c($fileIdentifier, $file);
+            composerRequire6380814b9cfdf6d165564b66c3e668d5($fileIdentifier, $file);
         }
 
         return $loader;
     }
 }
 
-function composerRequire51610d91ebd47e0f48d98a5f52f3068c($fileIdentifier, $file)
+function composerRequire6380814b9cfdf6d165564b66c3e668d5($fileIdentifier, $file)
 {
     if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
         require $file;
diff --git a/civicrm/vendor/composer/autoload_static.php b/civicrm/vendor/composer/autoload_static.php
index 895b6feb3c..0cbc833b0e 100644
--- a/civicrm/vendor/composer/autoload_static.php
+++ b/civicrm/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
 
 namespace Composer\Autoload;
 
-class ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c
+class ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5
 {
     public static $files = array (
         '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@@ -397,10 +397,10 @@ class ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c
     public static function getInitializer(ClassLoader $loader)
     {
         return \Closure::bind(function () use ($loader) {
-            $loader->prefixLengthsPsr4 = ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::$prefixLengthsPsr4;
-            $loader->prefixDirsPsr4 = ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::$prefixDirsPsr4;
-            $loader->prefixesPsr0 = ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::$prefixesPsr0;
-            $loader->classMap = ComposerStaticInit51610d91ebd47e0f48d98a5f52f3068c::$classMap;
+            $loader->prefixLengthsPsr4 = ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::$prefixLengthsPsr4;
+            $loader->prefixDirsPsr4 = ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::$prefixDirsPsr4;
+            $loader->prefixesPsr0 = ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::$prefixesPsr0;
+            $loader->classMap = ComposerStaticInit6380814b9cfdf6d165564b66c3e668d5::$classMap;
 
         }, null, ClassLoader::class);
     }
diff --git a/civicrm/xml/version.xml b/civicrm/xml/version.xml
index 855316b180..fe642b610e 100644
--- a/civicrm/xml/version.xml
+++ b/civicrm/xml/version.xml
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="iso-8859-1" ?>
 <version>
-  <version_no>5.6.0</version_no>
+  <version_no>5.6.1</version_no>
 </version>
diff --git a/includes/civicrm.basepage.php b/includes/civicrm.basepage.php
index a9d0b525de..78762ba068 100644
--- a/includes/civicrm.basepage.php
+++ b/includes/civicrm.basepage.php
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/includes/civicrm.shortcodes.modal.php b/includes/civicrm.shortcodes.modal.php
index 6f249e1e30..d606a8a0b4 100644
--- a/includes/civicrm.shortcodes.modal.php
+++ b/includes/civicrm.shortcodes.modal.php
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/includes/civicrm.shortcodes.php b/includes/civicrm.shortcodes.php
index 26e1b163cb..833a6dec48 100644
--- a/includes/civicrm.shortcodes.php
+++ b/includes/civicrm.shortcodes.php
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/includes/civicrm.users.php b/includes/civicrm.users.php
index 800b8888eb..6c387d7818 100644
--- a/includes/civicrm.users.php
+++ b/includes/civicrm.users.php
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/languages/civicrm.pot b/languages/civicrm.pot
index 4e28eef654..22349420e7 100644
--- a/languages/civicrm.pot
+++ b/languages/civicrm.pot
@@ -2,7 +2,7 @@
 # This file is distributed under the same license as the CiviCRM package.
 msgid ""
 msgstr ""
-"Project-Id-Version: CiviCRM 5\n"
+"Project-Id-Version: CiviCRM 4.6\n"
 "Report-Msgid-Bugs-To: http://wordpress.org/tag/civicrm\n"
 "POT-Creation-Date: 2014-11-11 09:48:56+00:00\n"
 "MIME-Version: 1.0\n"
diff --git a/uninstall.php b/uninstall.php
index c73696a982..7579c21f70 100644
--- a/uninstall.php
+++ b/uninstall.php
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
diff --git a/wp-cli/civicrm.php b/wp-cli/civicrm.php
index 3163678470..a3c35c5521 100644
--- a/wp-cli/civicrm.php
+++ b/wp-cli/civicrm.php
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
-- 
GitLab