| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * Base class for offline membership / membership type / membership renewal and membership status forms |
| 38 | * |
| 39 | */ |
| 40 | class CRM_Member_Form extends CRM_Core_Form { |
| 41 | |
| 42 | /** |
| 43 | * The id of the object being edited / created |
| 44 | * |
| 45 | * @var int |
| 46 | */ |
| 47 | protected $_id; |
| 48 | |
| 49 | /** |
| 50 | * The name of the BAO object for this form |
| 51 | * |
| 52 | * @var string |
| 53 | */ |
| 54 | protected $_BAOName; |
| 55 | |
| 56 | function preProcess() { |
| 57 | $this->_id = $this->get('id'); |
| 58 | $this->_BAOName = $this->get('BAOName'); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This function sets the default values for the form. MobileProvider that in edit/view mode |
| 63 | * the default values are retrieved from the database |
| 64 | * |
| 65 | * @access public |
| 66 | * |
| 67 | * @return array defaults |
| 68 | */ |
| 69 | function setDefaultValues() { |
| 70 | $defaults = array(); |
| 71 | |
| 72 | if (isset($this->_id)) { |
| 73 | $params = array('id' => $this->_id); |
| 74 | $baoName = $this->_BAOName; |
| 75 | $baoName::retrieve($params, $defaults); |
| 76 | } |
| 77 | |
| 78 | if (isset($defaults['minimum_fee'])) { |
| 79 | $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a'); |
| 80 | } |
| 81 | |
| 82 | if (isset($defaults['status'])) { |
| 83 | $this->assign('membershipStatus', $defaults['status']); |
| 84 | } |
| 85 | |
| 86 | if ($this->_action & CRM_Core_Action::ADD) { |
| 87 | $defaults['is_active'] = 1; |
| 88 | } |
| 89 | |
| 90 | if (isset($defaults['member_of_contact_id']) && |
| 91 | $defaults['member_of_contact_id'] |
| 92 | ) { |
| 93 | $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', |
| 94 | $defaults['member_of_contact_id'], 'display_name' |
| 95 | ); |
| 96 | } |
| 97 | return $defaults; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Function to actually build the form |
| 102 | * |
| 103 | * @return void |
| 104 | * @access public |
| 105 | */ |
| 106 | public function buildQuickForm() { |
| 107 | if ($this->_action & CRM_Core_Action::RENEW) { |
| 108 | $this->addButtons(array( |
| 109 | array( |
| 110 | 'type' => 'upload', |
| 111 | 'name' => ts('Renew'), |
| 112 | 'isDefault' => TRUE |
| 113 | ), |
| 114 | array( |
| 115 | 'type' => 'cancel', |
| 116 | 'name' => ts('Cancel') |
| 117 | ) |
| 118 | ) |
| 119 | ); |
| 120 | } |
| 121 | elseif ($this->_action & CRM_Core_Action::DELETE) { |
| 122 | $this->addButtons(array( |
| 123 | array( |
| 124 | 'type' => 'next', |
| 125 | 'name' => ts('Delete'), |
| 126 | 'isDefault' => TRUE |
| 127 | ), |
| 128 | array( |
| 129 | 'type' => 'cancel', |
| 130 | 'name' => ts('Cancel') |
| 131 | ) |
| 132 | ) |
| 133 | ); |
| 134 | } |
| 135 | else { |
| 136 | $this->addButtons(array( |
| 137 | array( |
| 138 | 'type' => 'upload', |
| 139 | 'name' => ts('Save'), |
| 140 | 'isDefault' => TRUE |
| 141 | ), |
| 142 | array( |
| 143 | 'type' => 'upload', |
| 144 | 'name' => ts('Save and New'), |
| 145 | 'subName' => 'new' |
| 146 | ), |
| 147 | array( |
| 148 | 'type' => 'cancel', |
| 149 | 'name' => ts('Cancel') |
| 150 | ) |
| 151 | ) |
| 152 | ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Function to extract values from the contact create boxes on the form and assign appropriatley to |
| 158 | * |
| 159 | * - $this->_contributorEmail, |
| 160 | * - $this->_memberEmail & |
| 161 | * - $this->_contributonName |
| 162 | * - $this->_memberName |
| 163 | * - $this->_contactID (effectively memberContactId but changing might have spin-off effects) |
| 164 | * - $this->_contributorContactId - id of the contributor |
| 165 | * - $this->_receiptContactId |
| 166 | * |
| 167 | * If the member & contributor are the same then the values will be the same. But if different people paid |
| 168 | * then they weill differ |
| 169 | * |
| 170 | * @param $formValues array values from form. The important values we are looking for are |
| 171 | * - contact_id |
| 172 | * - soft_credit_contact_id |
| 173 | */ |
| 174 | /** |
| 175 | * @param $formValues |
| 176 | */ |
| 177 | function storeContactFields($formValues){ |
| 178 | // in a 'standalone form' (contact id not in the url) the contact will be in the form values |
| 179 | if (!empty($formValues['contact_id'])) { |
| 180 | $this->_contactID = $formValues['contact_id']; |
| 181 | } |
| 182 | |
| 183 | list($this->_memberDisplayName, |
| 184 | $this->_memberEmail |
| 185 | ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); |
| 186 | |
| 187 | //CRM-10375 Where the payer differs to the member the payer should get the email. |
| 188 | // here we store details in order to do that |
| 189 | if (!empty($formValues['soft_credit_contact_id'])) { |
| 190 | $this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id']; |
| 191 | list( $this->_contributorDisplayName, |
| 192 | $this->_contributorEmail ) = CRM_Contact_BAO_Contact_Location::getEmailDetails( $this->_contributorContactID ); |
| 193 | } |
| 194 | else { |
| 195 | $this->_receiptContactId = $this->_contributorContactID = $this->_contactID; |
| 196 | $this->_contributorDisplayName = $this->_memberDisplayName; |
| 197 | $this->_contributorEmail = $this->_memberEmail; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |