Merge pull request #4812 from colemanw/CRM-15495
[civicrm-core.git] / CRM / Contribute / Form / Contribution / OnBehalfOf.php
index 8d118d6a8bc6a5cfe153ecbe27c4307028499ba5..d4de8f8508458ccd4ff8599bbae1e175f98d7713 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Contribute_Form_Contribution_OnBehalfOf {
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
    *
-   * @param $form
+   * @param CRM_Core_Form $form
    *
    * @return void
-   * @access public
    */
-  static function preProcess(&$form) {
+  public static function preProcess(&$form) {
     $session = CRM_Core_Session::singleton();
     $contactID = $form->_contactID;
 
@@ -95,6 +94,13 @@ 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'])) {
+          if (!empty($form->_submitValues['onbehalfof_id'])) {
+            $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
+          }
+          $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
+        }
       }
 
       if ($form->_values['is_for_organization'] != 2) {
@@ -116,16 +122,13 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
   }
 
   /**
-   * Function to build form for related contacts / on behalf of organization.
-   *
-   * @param $form              object  invoking Object
+   * Build form for related contacts / on behalf of organization.
    *
-   * @internal param string $contactType contact type
-   * @internal param string $title fieldset title
+   * @param CRM_Core_Form $form
    *
    * @static
    */
-  static function buildQuickForm(&$form) {
+  public static function buildQuickForm(&$form) {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
 
@@ -161,28 +164,10 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
       $fieldTypes = array_merge($fieldTypes, array('Contribution'));
     }
 
-    $stateCountryMap = array();
     foreach ($profileFields as $name => $field) {
       if (in_array($field['field_type'], $fieldTypes)) {
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
-        if (in_array($prefixName, array(
-          'state_province', 'country', 'county'))) {
-          if (!array_key_exists($index, $stateCountryMap)) {
-            $stateCountryMap[$index] = array();
-          }
-
-          $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
-
-          if (count($form->_submitValues)) {
-            $locationTypeId = $field['location_type_id'];
-            if (!empty($form->_submitValues['onbehalf']["country-{$locationTypeId}"]) &&
-              $prefixName == "state_province") {
-              $field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($form, "country-{$locationTypeId}", TRUE);
-            }
-          }
-        }
-        elseif (in_array($prefixName, array(
-          'organization_name', 'email')) && empty($field['is_required'])) {
+        if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
           $field['is_required'] = 1;
         }
 
@@ -190,15 +175,7 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
       }
     }
 
-    if (!empty($stateCountryMap)) {
-      CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
-      // now fix all state country selectors
-      CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray);
-    }
-
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
   }
 }
-