Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-07-15-48-59
authorkurund <kurund@civicrm.org>
Mon, 7 Jul 2014 10:24:13 +0000 (15:54 +0530)
committerkurund <kurund@civicrm.org>
Mon, 7 Jul 2014 10:24:13 +0000 (15:54 +0530)
Conflicts:
CRM/Dedupe/Merger.php
sql/civicrm_generated.mysql
xml/version.xml

CRM/Contact/Import/Form/MapField.php
CRM/Contact/Import/Parser/Contact.php
CRM/Contribute/Form/Contribution/OnBehalfOf.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/Page/AJAX/Location.php
CRM/Dedupe/Merger.php
CRM/Upgrade/Incremental/sql/4.4.7.mysql.tpl [new file with mode: 0644]
CRM/Utils/DeprecatedUtils.php
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

index e6f03f3f203c22758f255a305a01dc56318d4eb2..a97805064b2036c193000e10ddfe1f4d720c3919 100644 (file)
@@ -57,6 +57,8 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
 
   protected $_dedupeFields;
 
+  protected static $customFields;
+
   /**
    * Attempt to match header labels with our mapper fields
    * FIXME: This is essentially the same function as parent::defaultFromHeader
@@ -151,9 +153,16 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
         }
       }
     }
-
+    // retrieve and highlight required custom fields
+    $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
+    self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
+    foreach(self::$customFields as $key => $attr) {
+      if (!empty($attr['is_required'])) {
+        $highlightedFields[] = "custom_$key";
+      }
+    }
     $this->assign('highlightedFields', $highlightedFields);
-    $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $this->formatCustomFieldName($this->_mapperFields));
+    $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
 
     $columnNames = array();
     //get original col headers from csv if present.
index 22df0346ab437f4ec7c92ed4000a43b5ad468cc4..7175f9865b1378319692aa6e6389a62a3e57dbf3 100644 (file)
@@ -1152,6 +1152,11 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
         if (!array_key_exists($customFieldID, $customFields)) {
           self::addToErrorMsg(ts('field ID'), $errorMessage);
         }
+        // validate null values for required custom fields of type boolean
+        if (!empty($customFields[$customFieldID]['is_required']) && (empty($params['custom_'.$customFieldID]) && !is_numeric($params['custom_'.$customFieldID])) && $customFields[$customFieldID]['data_type'] == 'Boolean') {
+          self::addToErrorMsg($customFields[$customFieldID]['label'].'::'.$customFields[$customFieldID]['groupTitle'], $errorMessage);
+        }
+
         //For address custom fields, we do get actual custom field value as an inner array of
         //values so need to modify
         if (array_key_exists($customFieldID, $addressCustomFields)) {
@@ -1173,7 +1178,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
           }
           elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
             if (CRM_Utils_String::strtoboolstr($value) === FALSE) {
-              self::addToErrorMsg($customFields[$customFieldID]['label'], $errorMessage);
+              self::addToErrorMsg($customFields[$customFieldID]['label'].'::'.$customFields[$customFieldID]['groupTitle'], $errorMessage);
             }
           }
           // need not check for label filed import
@@ -1799,7 +1804,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
                   }
                 }
                 else {
-                  if ($getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) {
+                  if ((!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id'])) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) {
                     unset($params[$locKeys][$key]);
                   }
                 }
@@ -1882,7 +1887,12 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
           self::formatCustomDate($params, $formatted, $dateType, $key);
         }
         elseif ($customFields[$customFieldID]['data_type'] == 'Boolean') {
-          $params[$key] = CRM_Utils_String::strtoboolstr($val);
+          if (empty($val) && !is_numeric($val) && $this->_onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
+            //retain earlier value when Import mode is `Fill`
+            unset($params[$key]);
+          }
+          else {
+            $params[$key] = CRM_Utils_String::strtoboolstr($val);
           }
         }
 
@@ -1900,14 +1910,10 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
         $params[$key] = $this->checkGender($val);
       }
     }
+   }
 
     //now format custom data.
     foreach ($params as $key => $field) {
-      if (!isset($field) || empty($field)){
-        unset($params[$key]);
-        continue;
-      }
-
       if (is_array($field)) {
         $isAddressCustomField = FALSE;
         foreach ($field as $value) {
@@ -2017,6 +2023,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
     // to check if not update mode and unset the fields with empty value.
     if (!$this->_updateWithId && array_key_exists('custom', $formatted)) {
       foreach ($formatted['custom'] as $customKey => $customvalue) {
+        if (empty($formatted['custom'][$customKey][- 1]['is_required'])) {
+          $formatted['custom'][$customKey][-1]['is_required'] = $customFields[$customKey]['is_required'];
+        }
         $emptyValue = CRM_Utils_Array::value('value', $customvalue[ - 1]);
         if (!isset($emptyValue)) {
           unset($formatted['custom'][$customKey]);
index 8d118d6a8bc6a5cfe153ecbe27c4307028499ba5..11662677cb19200a8c387fc0296a66b03dd18791 100644 (file)
@@ -95,6 +95,11 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
         }
         $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
         $form->assign('locDataURL', $locDataURL);
+
+        if (!empty($form->_submitValues['onbehalf'])) {
+          $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
+          $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
+        }
       }
 
       if ($form->_values['is_for_organization'] != 2) {
@@ -201,4 +206,3 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
   }
 }
-
index 5411668fb71fc8a2ec88a4ef86207cdef853ea16..854831b33f9ae7499a8962786f88d8005622be04 100644 (file)
@@ -498,6 +498,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
                             $cfTable.default_value,
                             $cfTable.options_per_line, $cfTable.text_length,
                             $cfTable.custom_group_id,
+                            $cfTable.is_required,
                             $cgTable.extends, $cfTable.is_search_range,
                             $cgTable.extends_entity_column_value,
                             $cgTable.extends_entity_column_id,
@@ -572,6 +573,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           $fields[$dao->id]['option_group_id'] = $dao->option_group_id;
           $fields[$dao->id]['date_format'] = $dao->date_format;
           $fields[$dao->id]['time_format'] = $dao->time_format;
+          $fields[$dao->id]['is_required'] = $dao->is_required;
         }
 
         CRM_Core_BAO_Cache::setItem($fields,
index 7978c8aeccdc72c7e8b80176a579e2df16901032..ccc7225be6685714a2431fd42d2030285891e192 100644 (file)
@@ -1250,7 +1250,9 @@ ORDER BY civicrm_custom_group.weight,
         }
 
         $fieldId = $field['id'];
-        $elementName = $field['element_name'];
+        if (!empty($field['element_name'])) {
+          $elementName = $field['element_name'];
+        }
         switch ($field['html_type']) {
           case 'Multi-Select':
           case 'AdvMulti-Select':
index 93f7fb9657a1a5cbfdd728c27ef3f2942d869715..3782674a2a9baa141cf8f094e1fdfb13d94e7391 100644 (file)
@@ -51,7 +51,8 @@ class CRM_Core_Page_AJAX_Location {
 
     // Verify user id
     $user = CRM_Utils_Request::retrieve('uid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, CRM_Core_Session::singleton()->get('userID'));
-    if (!$user || !CRM_Contact_BAO_Contact_Permission::validateChecksumContact($user, CRM_Core_DAO::$_nullObject, FALSE)) {
+    if (empty($user) || (CRM_Utils_Request::retrieve('cs', 'String', $form, FALSE) && !CRM_Contact_BAO_Contact_Permission::validateChecksumContact($user, CRM_Core_DAO::$_nullObject, FALSE))
+    ) {
       CRM_Utils_System::civiExit();
     }
 
@@ -301,4 +302,3 @@ class CRM_Core_Page_AJAX_Location {
     CRM_Utils_System::civiExit();
   }
 }
-
index 4bd23f7115efb985b754ea6655dbe709b1404e47..688cc8885b6a1f1caf5a73403f327727465587cb 100644 (file)
@@ -1588,4 +1588,3 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     }
   }
 }
-
diff --git a/CRM/Upgrade/Incremental/sql/4.4.7.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.4.7.mysql.tpl
new file mode 100644 (file)
index 0000000..8d49b44
--- /dev/null
@@ -0,0 +1 @@
+{* file to handle db changes in 4.4.7 during upgrade *}
index 591cac52a7041009829dfb03cf4df46db53a8912..9ec53a73ad9a08fc77ba6051b7b346a40cc2e8fe 100644 (file)
@@ -1188,7 +1188,7 @@ function _civicrm_api3_deprecated_validate_formatted_contact(&$params) {
           $valid = CRM_Core_BAO_CustomValue::typecheck(CRM_Utils_Array::value('type', $value),
             CRM_Utils_Array::value('value', $value)
           );
-          if (!$valid) {
+          if (!$valid && $value['is_required']) {
             return civicrm_api3_create_error('Invalid value for custom field \'' .
               CRM_Utils_Array::value('name', $custom) . '\''
             );
index bebba33d181fce3ce2a695dd3d754a460c135e9b..9088aa348c6726e3be01895266b1dff3ccce9e18 100644 (file)
@@ -198,7 +198,17 @@ function setOrgName( ) {
 }
 
 
-function setLocationDetails(contactID) {
+function setLocationDetails(contactID , reset) {
+  var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
+  var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
+  submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
+  if (submittedCID == contactID) {
+    cj.each(submittedOnBehalfInfo, function(key, value) {
+      cj('#onbehalf_' + key ).val(value);
+    });
+    return;
+  }
+
   resetValues();
   var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
   cj.ajax({