3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This is base class for all ajax calls
39 class CRM_Core_Page_AJAX
{
42 * function to call generic ajax forms
47 static function run() {
48 $className = CRM_Utils_Type
::escape($_REQUEST['class_name'], 'String');
50 if (!empty($_REQUEST['type'])) {
51 $type = CRM_Utils_Type
::escape($_REQUEST['type'], 'String');
55 CRM_Core_Error
::fatal(ts('Invalid className: %1', array(1 => $className)));
59 if (isset($_REQUEST['fn_name'])) {
60 $fnName = CRM_Utils_Type
::escape($_REQUEST['fn_name'], 'String');
63 if (!self
::checkAuthz($type, $className, $fnName)) {
64 CRM_Utils_System
::civiExit();
69 call_user_func(array($className, $fnName));
75 // FIXME: This is done to maintain current wire protocol, but it might be
76 // simpler to just require different 'types' for pages and forms
77 if (preg_match('/^CRM_[a-zA-Z0-9]+_Page_Inline_/', $className)) {
78 $page = new $className;
82 $wrapper = new CRM_Utils_Wrapper();
83 $wrapper->run($className);
87 CRM_Core_Error
::debug_log_message('Unsupported inline request type: ' . var_export($type, TRUE));
89 CRM_Utils_System
::civiExit();
93 * function to change is_quick_config priceSet to complex
98 static function setIsQuickConfig() {
99 $id = $context = NULL;
100 if (CRM_Utils_Array
::value('id', $_REQUEST)) {
101 $id = CRM_Utils_Type
::escape($_REQUEST['id'], 'Integer');
104 if (CRM_Utils_Array
::value('context', $_REQUEST)) {
105 $context = CRM_Utils_Type
::escape($_REQUEST['context'], 'String');
107 // return false if $id is null and
108 // $context is not civicrm_event or civicrm_contribution_page
109 if (!$id ||
!in_array($context, array('civicrm_event', 'civicrm_contribution_page'))) {
112 $priceSetId = CRM_Price_BAO_Set
::getFor($context, $id, NULL);
114 $result = CRM_Price_BAO_Set
::setIsQuickConfig($priceSetId, 0);
115 if ($context == 'civicrm_event') {
117 civicrm_price_set cps
118 INNER JOIN civicrm_discount cd ON cd.price_set_id = cps.id
119 SET cps.is_quick_config = 0
120 WHERE cd.entity_id = (%1) AND cd.entity_table = 'civicrm_event' ";
121 $params = array(1 => array($id, 'Integer'));
122 CRM_Core_DAO
::executeQuery($sql, $params);
123 CRM_Core_BAO_Discount
::del($id, $context);
129 echo json_encode($priceSetId);
131 CRM_Utils_System
::civiExit();
135 * Determine whether the request is for a valid class/method name.
137 * @param string $type 'method'|'class'|''
138 * @param string $className 'Class_Name'
139 * @param string $fnName method name
141 static function checkAuthz($type, $className, $fnName = null) {
144 if (!preg_match('/^CRM_[a-zA-Z0-9]+_Page_AJAX$/', $className)) {
147 if (!preg_match('/^[a-zA-Z0-9]+$/', $fnName)) {
151 // ensure that function exists
152 return method_exists($className, $fnName);
157 if (!preg_match('/^CRM_[a-zA-Z0-9]+_(Page|Form)_Inline_[a-zA-Z0-9]+$/', $className)) {
160 return class_exists($className);