Merge pull request #15825 from seamuslee001/dev_core_183_logging
[civicrm-core.git] / CRM / Member / Page / AJAX.php
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 * $Id$
17 *
18 */
19
20 /**
21 * This class contains all the function that are called using AJAX (dojo)
22 */
23 class CRM_Member_Page_AJAX {
24
25 /**
26 * SetDefaults according to membership type.
27 */
28 public static function getMemberTypeDefaults() {
29 if (!$_POST['mtype']) {
30 $details['name'] = '';
31 $details['auto_renew'] = '';
32 $details['total_amount'] = '';
33
34 CRM_Utils_JSON::output($details);
35 }
36 $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
37
38 $query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew
39 FROM civicrm_membership_type
40 WHERE id = %1";
41
42 $dao = CRM_Core_DAO::executeQuery($query, [1 => [$memType, 'Positive']]);
43 $properties = ['financial_type_id', 'total_amount', 'name', 'auto_renew'];
44 while ($dao->fetch()) {
45 foreach ($properties as $property) {
46 $details[$property] = $dao->$property;
47 }
48 }
49 $details['total_amount_numeric'] = $details['total_amount'];
50 // fix the display of the monetary value, CRM-4038
51 $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
52 $options = CRM_Core_SelectValues::memberAutoRenew();
53 $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
54 CRM_Utils_JSON::output($details);
55 }
56
57 }