| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class contains all the function that are called using AJAX (dojo) |
| 20 | */ |
| 21 | class CRM_Member_Page_AJAX { |
| 22 | |
| 23 | /** |
| 24 | * SetDefaults according to membership type. |
| 25 | */ |
| 26 | public static function getMemberTypeDefaults() { |
| 27 | if (!$_POST['mtype']) { |
| 28 | $details['name'] = ''; |
| 29 | $details['auto_renew'] = ''; |
| 30 | $details['total_amount'] = ''; |
| 31 | |
| 32 | CRM_Utils_JSON::output($details); |
| 33 | } |
| 34 | $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer'); |
| 35 | |
| 36 | $query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew |
| 37 | FROM civicrm_membership_type |
| 38 | WHERE id = %1"; |
| 39 | |
| 40 | $dao = CRM_Core_DAO::executeQuery($query, [1 => [$memType, 'Positive']]); |
| 41 | $properties = ['financial_type_id', 'total_amount', 'name', 'auto_renew']; |
| 42 | while ($dao->fetch()) { |
| 43 | foreach ($properties as $property) { |
| 44 | $details[$property] = $dao->$property; |
| 45 | } |
| 46 | } |
| 47 | $details['total_amount_numeric'] = $details['total_amount']; |
| 48 | // fix the display of the monetary value, CRM-4038 |
| 49 | $details['total_amount'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($details['total_amount'] ?? 0); |
| 50 | $options = CRM_Core_SelectValues::memberAutoRenew(); |
| 51 | $details['auto_renew'] = $options[$details['auto_renew']] ?? NULL; |
| 52 | CRM_Utils_JSON::output($details); |
| 53 | } |
| 54 | |
| 55 | } |