patch as transmited by charles cook
authorXavier Dutoit <xavier@tttp.eu>
Thu, 13 Jun 2013 11:45:49 +0000 (13:45 +0200)
committerXavier Dutoit <xavier@tttp.eu>
Thu, 13 Jun 2013 11:45:49 +0000 (13:45 +0200)
CRM/Campaign/Form/Petition/Signature.php

index 7c77d301802e1c2aad3dda043b1d21a5fd721c46..2bfe2cd12a9120823db7a0bb68d175db160102b8 100644 (file)
@@ -283,6 +283,9 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
     }
 
     $this->setDefaults($this->_defaults);
+    
+    // add in all state country selectors for enabled countries
+    CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
   }
 
   public function buildQuickForm() {
@@ -584,6 +587,9 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
    */
   function buildCustom($id, $name, $viewOnly = FALSE) {
 
+    // create state country map array to hold selectors 
+    $stateCountryMap = array();
+
     if ($id) {
       $session = CRM_Core_Session::singleton();
       $this->assign("petition", $this->petition);
@@ -624,7 +630,15 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
             // ignore file upload fields
             continue;
           }
-
+          
+          // if state or country in the profile, create map 
+          list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
+          if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
+            if (!array_key_exists($index, $stateCountryMap)) {
+              $stateCountryMap[$index] = array();
+            }
+            $stateCountryMap[$index][$prefixName] = $key;
+          }  
 
           CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
           $this->_fields[$key] = $field;
@@ -633,6 +647,9 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
           }
         }
 
+        // initialize the state country map        
+        CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
+
         if ($addCaptcha &&
           !$viewOnly
         ) {