3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * This class contains all the function that are called using AJAX.
37 class CRM_Admin_Page_AJAX
{
40 * CRM-12337 Output navigation menu as executable javascript.
42 * @see smarty_function_crmNavigationMenu
44 public static function getNavigationMenu() {
45 $contactID = CRM_Core_Session
::singleton()->get('userID');
47 CRM_Core_Page_AJAX
::setJsHeaders();
48 print CRM_Core_Smarty
::singleton()->fetchWith('CRM/common/navigation.js.tpl', array(
49 'navigation' => CRM_Core_BAO_Navigation
::createNavigation($contactID),
52 CRM_Utils_System
::civiExit();
56 * Return menu tree as json data for editing.
58 public static function getNavigationList() {
59 echo CRM_Core_BAO_Navigation
::buildNavigation(TRUE, FALSE);
60 CRM_Utils_System
::civiExit();
64 * Process drag/move action for menu tree.
66 public static function menuTree() {
67 CRM_Core_BAO_Navigation
::processNavigation($_GET);
71 * Build status message while enabling/ disabling various objects.
73 public static function getStatusMsg() {
74 require_once 'api/v3/utils.php';
75 $recordID = CRM_Utils_Type
::escape($_GET['id'], 'Integer');
76 $entity = CRM_Utils_Type
::escape($_GET['entity'], 'String');
79 if ($recordID && $entity && $recordBAO = _civicrm_api3_get_BAO($entity)) {
81 case 'CRM_Core_BAO_UFGroup':
82 $method = 'getUFJoinRecord';
83 $result = array($recordBAO, $method);
84 $ufJoin = call_user_func_array(($result), array($recordID, TRUE));
85 if (!empty($ufJoin)) {
86 $ret['content'] = ts('This profile is currently used for %1.', array(1 => implode(', ', $ufJoin))) . ' <br/><br/>' . ts('If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?');
89 $ret['content'] = ts('Are you sure you want to disable this profile?');
93 case 'CRM_Price_BAO_PriceSet':
94 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($recordID);
95 $priceSet = CRM_Price_BAO_PriceSet
::getTitle($recordID);
97 if (!CRM_Utils_System
::isNull($usedBy)) {
98 $template = CRM_Core_Smarty
::singleton();
99 $template->assign('usedBy', $usedBy);
101 'Event' => 'civicrm_event',
102 'Contribution' => 'civicrm_contribution_page',
103 'EventTemplate' => 'civicrm_event_template',
106 foreach ($comps as $name => $table) {
107 if (array_key_exists($table, $usedBy)) {
111 $template->assign('contexts', $contexts);
113 $ret['illegal'] = TRUE;
114 $table = $template->fetch('CRM/Price/Page/table.tpl');
115 $ret['content'] = ts('Unable to disable the \'%1\' price set - it is currently in use by one or more active events, contribution pages or contributions.', array(
120 $ret['content'] = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet));
124 case 'CRM_Event_BAO_Event':
125 $ret['content'] = ts('Are you sure you want to disable this Event?');
128 case 'CRM_Core_BAO_UFField':
129 $ret['content'] = ts('Are you sure you want to disable this CiviCRM Profile field?');
132 case 'CRM_Contribute_BAO_ManagePremiums':
133 $ret['content'] = ts('Are you sure you want to disable this premium? This action will remove the premium from any contribution pages that currently offer it. However it will not delete the premium record - so you can re-enable it and add it back to your contribution page(s) at a later time.');
136 case 'CRM_Contact_BAO_Relationship':
137 $ret['content'] = ts('Are you sure you want to disable this relationship?');
140 case 'CRM_Contact_BAO_RelationshipType':
141 $ret['content'] = ts('Are you sure you want to disable this relationship type?') . '<br/><br/>' . ts('Users will no longer be able to select this value when adding or editing relationships between contacts.');
144 case 'CRM_Financial_BAO_FinancialType':
145 $ret['content'] = ts('Are you sure you want to disable this financial type?');
148 case 'CRM_Financial_BAO_FinancialAccount':
149 if (!CRM_Financial_BAO_FinancialAccount
::getARAccounts($recordID)) {
150 $ret['illegal'] = TRUE;
151 $ret['content'] = ts('The selected financial account cannot be disabled because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance).');
154 $ret['content'] = ts('Are you sure you want to disable this financial account?');
158 case 'CRM_Financial_BAO_PaymentProcessor':
159 $ret['content'] = ts('Are you sure you want to disable this payment processor?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing transaction pages.');
162 case 'CRM_Financial_BAO_PaymentProcessorType':
163 $ret['content'] = ts('Are you sure you want to disable this payment processor type?');
166 case 'CRM_Core_BAO_LocationType':
167 $ret['content'] = ts('Are you sure you want to disable this location type?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing contact locations.');
170 case 'CRM_Event_BAO_ParticipantStatusType':
171 $ret['content'] = ts('Are you sure you want to disable this Participant Status?') . '<br/><br/> ' . ts('Users will no longer be able to select this value when adding or editing Participant Status.');
174 case 'CRM_Mailing_BAO_Component':
175 $ret['content'] = ts('Are you sure you want to disable this component?');
178 case 'CRM_Core_BAO_CustomField':
179 $ret['content'] = ts('Are you sure you want to disable this custom data field?');
182 case 'CRM_Core_BAO_CustomGroup':
183 $ret['content'] = ts('Are you sure you want to disable this custom data group? Any profile fields that are linked to custom fields of this group will be disabled.');
186 case 'CRM_Core_BAO_MessageTemplate':
187 $ret['content'] = ts('Are you sure you want to disable this message tempate?');
190 case 'CRM_ACL_BAO_ACL':
191 $ret['content'] = ts('Are you sure you want to disable this ACL?');
194 case 'CRM_ACL_BAO_EntityRole':
195 $ret['content'] = ts('Are you sure you want to disable this ACL Role Assignment?');
198 case 'CRM_Member_BAO_MembershipType':
199 $ret['content'] = ts('Are you sure you want to disable this membership type?');
202 case 'CRM_Member_BAO_MembershipStatus':
203 $ret['content'] = ts('Are you sure you want to disable this membership status rule?');
206 case 'CRM_Price_BAO_PriceField':
207 $ret['content'] = ts('Are you sure you want to disable this price field?');
210 case 'CRM_Contact_BAO_Group':
211 $ret['content'] = ts('Are you sure you want to disable this Group?');
214 case 'CRM_Core_BAO_OptionGroup':
215 $ret['content'] = ts('Are you sure you want to disable this Option?');
218 case 'CRM_Contact_BAO_ContactType':
219 $ret['content'] = ts('Are you sure you want to disable this Contact Type?');
222 case 'CRM_Core_BAO_OptionValue':
223 $label = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label');
224 $ret['content'] = ts('Are you sure you want to disable the \'%1\' option ?', array(1 => $label));
225 $ret['content'] .= '<br /><br />' . ts('WARNING - Disabling an option which has been assigned to existing records will result in that option being cleared when the record is edited.');
228 case 'CRM_Contribute_BAO_ContributionRecur':
229 $recurDetails = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recordID);
230 $ret['content'] = ts('Are you sure you want to mark this recurring contribution as cancelled?');
231 $ret['content'] .= '<br /><br /><strong>' . ts('WARNING - This action sets the CiviCRM recurring contribution status to Cancelled, but does NOT send a cancellation request to the payment processor. You will need to ensure that this recurring payment (subscription) is cancelled by the payment processor.') . '</strong>';
232 if ($recurDetails->membership_id
) {
233 $ret['content'] .= '<br /><br /><strong>' . ts('This recurring contribution is linked to an auto-renew membership. If you cancel it, the associated membership will no longer renew automatically. However, the current membership status will not be affected.') . '</strong>';
238 $ret['content'] = ts('Are you sure you want to disable this record?');
243 $ret = array('status' => 'error', 'content' => 'Error: Unknown entity type.', 'illegal' => TRUE);
245 CRM_Core_Page_AJAX
::returnJsonResponse($ret);
248 public static function mergeTagList() {
249 $name = CRM_Utils_Type
::escape($_GET['term'], 'String');
250 $fromId = CRM_Utils_Type
::escape($_GET['fromId'], 'Integer');
251 $limit = Civi
::settings()->get('search_autocomplete_count');
253 // build used-for clause to be used in main query
254 $usedForTagA = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $fromId, 'used_for');
255 $usedForClause = array();
257 $usedForTagA = explode(",", $usedForTagA);
258 foreach ($usedForTagA as $key => $value) {
259 $usedForClause[] = "t1.used_for LIKE '%{$value}%'";
262 $usedForClause = !empty($usedForClause) ?
implode(' OR ', $usedForClause) : '1';
265 // query to list mergable tags
267 SELECT t1.name, t1.id, t1.used_for, t2.name as parent
269 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
270 WHERE t1.id <> {$fromId} AND
271 t1.name LIKE '%{$name}%' AND
274 $dao = CRM_Core_DAO
::executeQuery($query);
277 while ($dao->fetch()) {
280 'text' => ($dao->parent ?
"{$dao->parent} :: " : '') . $dao->name
,
282 // Add warning about used_for types
283 if (!empty($dao->used_for
)) {
284 $usedForTagB = explode(',', $dao->used_for
);
286 $usedForDiff = array_diff($usedForTagA, $usedForTagB);
287 if (!empty($usedForDiff)) {
288 $row['warning'] = TRUE;
293 CRM_Utils_JSON
::output($result);
297 * Get a list of mappings.
299 * This appears to be only used by scheduled reminders.
301 static public function mappingList() {
302 if (empty($_GET['mappingID'])) {
303 CRM_Utils_JSON
::output(array('status' => 'error', 'error_msg' => 'required params missing.'));
306 $mapping = CRM_Core_BAO_ActionSchedule
::getMapping($_GET['mappingID']);
307 $dateFieldLabels = $mapping ?
$mapping->getDateFields() : array();
309 // The UX here is quirky -- for "Activity" types, there's a simple drop "Recipients"
310 // dropdown which is always displayed. For other types, the "Recipients" drop down is
311 // conditional upon the weird isLimit ('Limit To / Also Include / Neither') dropdown.
312 $noThanksJustKidding = !$_GET['isLimit'];
313 if ($mapping instanceof CRM_Activity_ActionMapping ||
!$noThanksJustKidding) {
314 $entityRecipientLabels = $mapping ?
($mapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule
::getAdditionalRecipients()) : array();
317 $entityRecipientLabels = CRM_Core_BAO_ActionSchedule
::getAdditionalRecipients();
319 $recipientMapping = array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels));
322 'sel4' => CRM_Utils_Array
::toKeyValueRows($dateFieldLabels),
323 'sel5' => CRM_Utils_Array
::toKeyValueRows($entityRecipientLabels),
324 'recipientMapping' => $recipientMapping,
327 CRM_Utils_JSON
::output($output);
331 * (Scheduled Reminders) Get the list of possible recipient filters.
333 * Ex: GET /civicrm/ajax/recipientListing?mappingID=contribpage&recipientType=
335 public static function recipientListing() {
336 $mappingID = filter_input(INPUT_GET
, 'mappingID', FILTER_VALIDATE_REGEXP
, array(
338 'regexp' => '/^[a-zA-Z0-9_\-]+$/',
341 $recipientType = filter_input(INPUT_GET
, 'recipientType', FILTER_VALIDATE_REGEXP
, array(
343 'regexp' => '/^[a-zA-Z0-9_\-]+$/',
347 CRM_Utils_JSON
::output(array(
348 'recipients' => CRM_Utils_Array
::toKeyValueRows(CRM_Core_BAO_ActionSchedule
::getRecipientListing($mappingID, $recipientType)),
352 public static function mergeTags() {
353 $tagAId = CRM_Utils_Type
::escape($_POST['fromId'], 'Integer');
354 $tagBId = CRM_Utils_Type
::escape($_POST['toId'], 'Integer');
356 $result = CRM_Core_BAO_EntityTag
::mergeTags($tagAId, $tagBId);
358 if (!empty($result['tagB_used_for'])) {
359 $usedFor = CRM_Core_OptionGroup
::values('tag_used_for');
360 foreach ($result['tagB_used_for'] as & $val) {
361 $val = $usedFor[$val];
363 $result['tagB_used_for'] = implode(', ', $result['tagB_used_for']);
366 $result['message'] = ts('"%1" has been merged with "%2". All records previously tagged "%1" are now tagged "%2".',
367 array(1 => $result['tagA'], 2 => $result['tagB'])
370 CRM_Utils_JSON
::output($result);