Merge pull request #8491 from seamuslee001/CRM-18752
authorEileen McNaughton <eileen@mcnaughty.com>
Sun, 5 Jun 2016 17:53:50 +0000 (11:53 -0600)
committerEileen McNaughton <eileen@mcnaughty.com>
Sun, 5 Jun 2016 17:53:50 +0000 (11:53 -0600)
CRM-18752 Fix Custom multi value importer

CRM/Contact/Form/Search/Custom/ActivitySearch.php
CRM/Contribute/Form/CancelSubscription.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/Payment/AuthorizeNet.php
CRM/Mailing/Event/BAO/TrackableURLOpen.php
CRM/Report/Form/Contribute/Recur.php
js/Common.js
js/crm.searchForm.js
settings/Localization.setting.php
templates/CRM/common/navigation.js.tpl

index d7b8ba87fc93c591e32fdcdb083a0caf8d96dcbd..649679f24faea586f2be7f9f559e51be63a9e06a 100644 (file)
@@ -70,12 +70,10 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
     );
 
     //Add custom fields to columns array for inclusion in export
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $form, NULL,
-      NULL, '', NULL
-    );
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
 
     //use simplified formatted groupTree
-    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
+    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree);
 
     //cycle through custom fields and assign to _columns array
     foreach ($groupTree as $key) {
@@ -84,7 +82,6 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
         $this->_columns[$fieldlabel] = $field['column_name'];
       }
     }
-    //end custom fields
   }
 
   /**
@@ -204,7 +201,7 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
     }
 
     // add custom group fields to SELECT and FROM clause
-    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $form, NULL, NULL, '', NULL);
+    $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
 
     foreach ($groupTree as $key) {
       if (!empty($key['extends']) && $key['extends'] == 'Activity') {
index db83d20ffc8a311c7b9cde4ee53272a9d67309a8..817fc58af87924b8e20431c4491c7c5b39dacd87 100644 (file)
@@ -71,12 +71,13 @@ class CRM_Contribute_Form_CancelSubscription extends CRM_Core_Form {
     }
 
     if ($this->_mid) {
-      if (CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_mid)) {
-        CRM_Core_Error::fatal(ts('The auto renewal option for this membership looks to have been cancelled already.'));
-      }
       $this->_mode = 'auto_renew';
-      $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj');
-      $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership');
+      // CRM-18468: crid is more accurate than mid for getting
+      // subscriptionDetails, so don't get them again.
+      if (!$this->_crid) {
+        $this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_mid, 'membership', 'obj');
+        $this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_mid, 'membership');
+      }
 
       $membershipTypes = CRM_Member_PseudoConstant::membershipType();
       $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_mid, 'membership_type_id');
index ec67256b03d887a9dd669e8725798e1c8d5e7c29..abebd93404451228a96cf7f1674d0e2534321e88 100644 (file)
@@ -864,6 +864,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           $qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
         }
         else {
+          if ($field->text_length) {
+            $field->attributes .= ' maxlength=' . $field->text_length;
+            if ($field->text_length < 20) {
+              $field->attributes .= ' size=' . $field->text_length;
+            }
+          }
           $element = $qf->add('text', $elementName, $label,
             $field->attributes,
             $useRequired && !$search
@@ -908,7 +914,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           //CRM-18487 - max date should be the last date of the year.
           'maxDate' => isset($maxYear) ? $maxYear . '-12-31' : NULL,
           'time' => $field->time_format ? $field->time_format * 12 : FALSE,
-          'yearRange' => "{$minYear}:{$maxYear}",
         );
         if ($field->is_search_range && $search) {
           $qf->add('datepicker', $elementName . '_from', $label, $attr + array('placeholder' => ts('From')), FALSE, $params);
index 0a9b3e78bc6d607891b7738cf398dd56aa12967a..1c21f8f8936f991efba5459a76a4cd43c9a509de 100644 (file)
@@ -1821,7 +1821,7 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1,
    *
    * @return array
    */
-  public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form) {
+  public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NULL) {
     $formattedGroupTree = array();
     $uploadNames = array();
 
index fc8ab4eab8386b53c4bb67f256a2124460b63f90..19b4bcec9c7f1a3f5535a7042de71f0f45f4858f 100644 (file)
@@ -23,6 +23,7 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment {
   const AUTH_APPROVED = 1;
   const AUTH_DECLINED = 2;
   const AUTH_ERROR = 3;
+  const AUTH_REVIEW = 4;
   const TIMEZONE = 'America/Denver';
 
   protected $_mode = NULL;
@@ -166,7 +167,6 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment {
     curl_close($submit);
 
     $response_fields = $this->explode_csv($response);
-
     // check gateway MD5 response
     if (!$this->checkMD5($response_fields[37], $response_fields[6], $response_fields[9])) {
       return self::error(9003, 'MD5 Verification failed');
@@ -175,30 +175,42 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment {
     // check for application errors
     // TODO:
     // AVS, CVV2, CAVV, and other verification results
-    if ($response_fields[0] != self::AUTH_APPROVED) {
-      $errormsg = $response_fields[2] . ' ' . $response_fields[3];
-      return self::error($response_fields[1], $errormsg);
-    }
-
-    // Success
-
-    // test mode always returns trxn_id = 0
-    // also live mode in CiviCRM with test mode set in
-    // Authorize.Net return $response_fields[6] = 0
-    // hence treat that also as test mode transaction
-    // fix for CRM-2566
-    if (($this->_mode == 'test') || $response_fields[6] == 0) {
-      $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
-      $p = array();
-      $trxn_id = strval(CRM_Core_DAO::singleValueQuery($query, $p));
-      $trxn_id = str_replace('test', '', $trxn_id);
-      $trxn_id = intval($trxn_id) + 1;
-      $params['trxn_id'] = sprintf('test%08d', $trxn_id);
-    }
-    else {
-      $params['trxn_id'] = $response_fields[6];
+    $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
+    switch ($response_fields[0]) {
+      case self::AUTH_REVIEW :
+        $params['payment_status_id'] = array_search('Pending', $contributionStatus);
+        break;
+
+      case self::AUTH_ERROR :
+        $params['payment_status_id'] = array_search('Failed', $contributionStatus);
+        break;
+
+      case self::AUTH_DECLINED :
+        $errormsg = $response_fields[2] . ' ' . $response_fields[3];
+        return self::error($response_fields[1], $errormsg);
+
+      default:
+        // Success
+
+        // test mode always returns trxn_id = 0
+        // also live mode in CiviCRM with test mode set in
+        // Authorize.Net return $response_fields[6] = 0
+        // hence treat that also as test mode transaction
+        // fix for CRM-2566
+        if (($this->_mode == 'test') || $response_fields[6] == 0) {
+          $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id RLIKE 'test[0-9]+'";
+          $p = array();
+          $trxn_id = strval(CRM_Core_DAO::singleValueQuery($query, $p));
+          $trxn_id = str_replace('test', '', $trxn_id);
+          $trxn_id = intval($trxn_id) + 1;
+          $params['trxn_id'] = sprintf('test%08d', $trxn_id);
+        }
+        else {
+          $params['trxn_id'] = $response_fields[6];
+        }
+        $params['gross_amount'] = $response_fields[9];
+        break;
     }
-    $params['gross_amount'] = $response_fields[9];
     // TODO: include authorization code?
 
     return $params;
index 18e3284bbdb67b05f0752cffcdfe7629f125c6e3..039c0dc092e42bd730d9860c2ac68387380aba25 100644 (file)
@@ -79,9 +79,16 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track
     );
 
     if (!$search->fetch()) {
-      // Whoops, error, don't track it.  Return the base url.
+      // Can't find either the URL or the queue. If we can find the URL then
+      // return the URL without tracking.  Otherwise return the base URL.
 
-      return CRM_Utils_System::baseURL();
+      $search->query("SELECT $turl.url as url from $turl
+                    WHERE $turl.id = " . CRM_Utils_Type::escape($url_id, 'Integer')
+      );
+      if (!$search->fetch()) {
+        return CRM_Utils_System::baseURL();
+      }
+      return $search->url;
     }
 
     $open = new CRM_Mailing_Event_BAO_TrackableURLOpen();
index 2e55034366272c02775075fc44b179078c58f48a..7675191d99c5674f441136d751bdca8fa31281f7 100644 (file)
@@ -174,7 +174,7 @@ class CRM_Report_Form_Contribute_Recur extends CRM_Report_Form {
             'title' => ts('Frequency Unit'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_OptionGroup::values('recur_frequency_units'),
-            'type' => CRM_Utils_Type::T_INT,
+            'type' => CRM_Utils_Type::T_STRING,
           ),
           'frequency_interval' => array(
             'title' => ts('Frequency Interval'),
index d9ec1d7a1d12caded37f8b959d3e323857dab5ac..f3aae295005b78780b1fbd03472c18dec6cbbce2 100644 (file)
@@ -655,12 +655,15 @@ if (!CRM.vars) CRM.vars = {};
         $dateField = $('<input type="' + type + '">').insertAfter($dataField);
         copyAttributes($dataField, $dateField, ['placeholder', 'style', 'class', 'disabled']);
         $dateField.addClass('crm-form-' + type);
-        settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null;
-        settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null;
         if (hasDatepicker) {
+          settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null;
+          settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null;
           settings.dateFormat = typeof settings.date === 'string' ? settings.date : CRM.config.dateInputFormat;
           settings.changeMonth = _.includes(settings.dateFormat, 'm');
           settings.changeYear = _.includes(settings.dateFormat, 'y');
+          if (!settings.yearRange && settings.minDate !== null && settings.maxDate !== null) {
+            settings.yearRange = '' + CRM.utils.formatDate(settings.minDate, 'yy') + ':' + CRM.utils.formatDate(settings.maxDate, 'yy');
+          }
           $dateField.addClass('crm-form-date').datepicker(settings);
         } else {
           $dateField.attr('min', settings.minDate ? CRM.utils.formatDate(settings.minDate, 'yy') : '1000');
index 3de76afb892c801518dac1747aa08c3a92bab25a..c1105213301532c0c3b47a0f74f3ba1af8c5bdcd 100644 (file)
 
   $(function() {
     initForm();
+
+    // Focus first search field
+    $('.crm-form-text:input:visible:first', 'form.crm-search-form').focus();
+
     // Handle user interactions with search results
     $('#crm-container')
       // When toggling between "all records" and "selected records only"
index 454b00e5dec65a22ca2d1db0331873d421cae2ab..e375d92f3a9a3f72e377a65ce3394eec0c67fdf7 100644 (file)
@@ -188,11 +188,12 @@ return array(
     'group' => 'localization',
     'name' => 'countryLimit',
     'type' => 'Array',
-    'quick_form_type' => 'Select',
-    'html_type' => 'Select',
+    'quick_form_type' => 'Element',
+    'html_type' => 'advmultiselect',
     'html_attributes' => array(
-      'multiple' => 1,
-      'class' => 'crm-select2',
+      'size' => 5,
+      'style' => 'width:150px',
+      'class' => 'advmultiselect',
     ),
     'default' => array(),
     'add' => '4.3',
@@ -210,15 +211,16 @@ return array(
     'group' => 'localization',
     'name' => 'provinceLimit',
     'type' => 'Array',
-    'quick_form_type' => 'Select',
-    'html_type' => 'Select',
+    'quick_form_type' => 'Element',
+    'html_type' => 'advmultiselect',
     'html_attributes' => array(
-      'multiple' => 1,
-      'class' => 'crm-select2',
+      'size' => 5,
+      'style' => 'width:150px',
+      'class' => 'advmultiselect',
     ),
     'default' => array(),
     'add' => '4.3',
-    'title' => 'Available States and Provinces',
+    'title' => 'Available States and Provinces (by Country)',
     'is_domain' => 1,
     'is_contact' => 0,
     'description' => '',
index fdce48e01b2dde0085a1239039802a17a3065e1e..f04700e5c6539646f2a73d72321028b312d69404 100644 (file)
@@ -127,6 +127,7 @@ $('#civicrm-menu').ready(function() {
       $.Menu.closeAll();
     })
     .on('focus', function() {
+      setQuickSearchValue();
       if ($(this).attr('style').indexOf('14em') < 0) {
         $(this).animate({width: '14em'});
       }
@@ -153,15 +154,29 @@ $('#civicrm-menu').ready(function() {
     }
     e.preventDefault();
   });
-  $('.crm-quickSearchField').click(function() {
-    var label = $(this).text();
-    var value = $('input', this).val();
+  function setQuickSearchValue() {
+    var $selection = $('.crm-quickSearchField input:checked'),
+      label = $selection.parent().text(),
+      value = $selection.val();
     // These fields are not supported by advanced search
     if (value === 'first_name' || value === 'last_name') {
       value = 'sort_name';
     }
-    $('#sort_name_navigation').attr({name: value, placeholder: label}).focus();
+    $('#sort_name_navigation').attr({name: value, placeholder: label});
+  }
+  $('.crm-quickSearchField').click(function() {
+    setQuickSearchValue();
+    $('#sort_name_navigation').focus();
   });
+  // Set & retrieve default value
+  if (window.localStorage) {
+    $('.crm-quickSearchField').click(function() {
+      localStorage.quickSearchField = $('input', this).val();
+    });
+    if (localStorage.quickSearchField) {
+      $('.crm-quickSearchField input[value=' + localStorage.quickSearchField + ']').prop('checked', true);
+    }
+  }
   // redirect to view page if there is only one contact
   $('#id_search_block').on('submit', function() {
     var $menu = $('#sort_name_navigation').autocomplete('widget');