CRM-12743 - goodbye eval
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Registration.php
index 7703f7a4bbbbcf09c73b9c155bdbffb7de044a33..1935bc78920b5eb86d41d305d1b0ea45ba3126c8 100644 (file)
@@ -350,7 +350,8 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
     $form->add('select', 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $mainProfiles);
 
     $form->add('select', 'additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $addtProfiles);
-    $form->add('select', 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $addtProfiles);
+    // Allow user to NOT provide a bottom profile for Additional Participant registration 
+    $form->add('select', 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), array('none' => ts('- no profile -')) + $addtProfiles);
   }
 
   function buildMultipleProfileBottom(&$form, $count, $prefix = '', $name = 'Include Profile') {
@@ -362,7 +363,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
 
     if ($prefix == 'additional_') {
       $mainProfiles = array(
-        '' => ts('- same as for main contact -')) + $profiles;
+        '' => ts('- same as for main contact -'), 'none' => ts('- no profile -')) + $profiles;
     }
     else {
       $mainProfiles = array(
@@ -529,37 +530,41 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
         else {
           $isPreError = FALSE;
         }
-        //check for additional custom post profile
-        $additionalCustomPostId = CRM_Utils_Array::value('additional_custom_post_id', $values);
-        if (!empty($additionalCustomPostId)) {
-          if (!($additionalCustomPostId == 'none')) {
-            $customPostId = $additionalCustomPostId;
+        
+        // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
+        if ($isPreError) {
+          $additionalCustomPostId = CRM_Utils_Array::value('additional_custom_post_id', $values);
+          if (!empty($additionalCustomPostId)) {
+            if (!($additionalCustomPostId == 'none')) {
+              $customPostId = $additionalCustomPostId;
+            }
+            else {
+              $isPostError = FALSE;
+            }
           }
           else {
-            $isPostError = FALSE;
+            $customPostId = CRM_Utils_Array::value('custom_post_id', $values) ? $values['custom_post_id'] : NULL;
           }
-        }
-        else {
-          $customPostId = CRM_Utils_Array::value('custom_post_id', $values) ? $values['custom_post_id'] : NULL;
-        }
-        //check whether the additional custom post profile is of type 'Individual' and its subtypes
-        if (!empty($customPostId)) {
-          $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPostId);
-          foreach ($types as $individualTypes) {
-            if (in_array($individualTypes, $profileTypes)) {
-              $isPostError = FALSE;
-              break;
+          //check whether the additional custom post profile is of type 'Individual' and its subtypes
+          if (!empty($customPostId)) {
+            $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPostId);
+            foreach ($types as $individualTypes) {
+              if (in_array($individualTypes, $profileTypes)) {
+                $isPostError = FALSE;
+                break;
+              }
             }
           }
-        }
-        else {
-          $isPostError = FALSE;
-        }
-        if ($isPreError || (empty($customPreId) && empty($customPostId))) {
-          $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
-        }
-        if ($isPostError) {
-          $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
+          else {
+            $isPostError = FALSE;
+          }
+
+          if (empty($customPreId) && empty($customPostId)) {
+            $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
+          }
+          if ($isPostError) {
+            $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
+          }
         }
       }
       if (!$isProfileComplete) {