Merge pull request #1641 from PalanteJon/CRM-13396
[civicrm-core.git] / CRM / Contribute / Form / ContributionBase.php
index 2118a03de561bcc858af5f3f33a414f03347928d..d2d853e532a938c65684c799046e2720e1ebaa2b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -226,13 +226,18 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
           $this->_defaultMemTypeId = $membership->membership_type_id;
           if ($membership->contact_id != $this->_contactID) {
             $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID);
-            if (array_key_exists($membership->contact_id, $employers)) {
-              $this->_membershipContactID = $membership->contact_id;
-              $this->assign('membershipContactID', $this->_membershipContactID);
-              $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']);
+            if (!empty($employers)) {
+              if (array_key_exists($membership->contact_id, $employers)) {
+                $this->_membershipContactID = $membership->contact_id;
+                $this->assign('membershipContactID', $this->_membershipContactID);
+                $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']);
+              }
+              else {
+                CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
+              }
             }
             else {
-              CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
+              $this->_membershipContactID = $membership->contact_id;
             }
           }
         }
@@ -553,8 +558,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
             $this->_params[$v] = $frequencyUnits[$this->_params[$v]];
           }
         }
-        if ($v == "amount") {
-          $this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], ' ');
+        if ($v == "amount" && $this->_params[$v] === 0) {
+          $this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], NULL, NULL, TRUE);
         }
         $this->assign($v, $this->_params[$v]);
       }