3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 class contains all the function that are called using AJAX
39 class CRM_Admin_Page_AJAX
{
42 * Function to build menu tree
44 static function getNavigationList() {
45 echo CRM_Core_BAO_Navigation
::buildNavigation(TRUE, FALSE);
46 CRM_Utils_System
::civiExit();
50 * Function to process drag/move action for menu tree
52 static function menuTree() {
53 echo CRM_Core_BAO_Navigation
::processNavigation($_GET);
54 CRM_Utils_System
::civiExit();
58 * Function to build status message while
59 * enabling/ disabling various objects
61 static function getStatusMsg() {
62 $recordID = CRM_Utils_Type
::escape($_POST['recordID'], 'Integer');
63 $recordBAO = CRM_Utils_Type
::escape($_POST['recordBAO'], 'String');
64 $op = CRM_Utils_Type
::escape($_POST['op'], 'String');
67 if ($op == 'disable-enable') {
68 $status = ts('Are you sure you want to enable this record?');
72 case 'CRM_Core_BAO_UFGroup':
73 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
74 $method = 'getUFJoinRecord';
75 $result = array($recordBAO, $method);
76 $ufJoin = call_user_func_array(($result), array($recordID, TRUE));
77 if (!empty($ufJoin)) {
78 $status = 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?');
81 $status = ts('Are you sure you want to disable this profile?');
85 case 'CRM_Price_BAO_PriceSet':
86 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
87 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($recordID);
88 $priceSet = CRM_Price_BAO_PriceSet
::getTitle($recordID);
90 if (!CRM_Utils_System
::isNull($usedBy)) {
91 $template = CRM_Core_Smarty
::singleton();
92 $template->assign('usedBy', $usedBy);
94 'Event' => 'civicrm_event',
95 'Contribution' => 'civicrm_contribution_page',
96 'EventTemplate' => 'civicrm_event_template'
99 foreach ($comps as $name => $table) {
100 if (array_key_exists($table, $usedBy)) {
104 $template->assign('contexts', $contexts);
107 $table = $template->fetch('CRM/Price/Page/table.tpl');
108 $status = ts('Unable to disable the \'%1\' price set - it is currently in use by one or more active events, contribution pages or contributions.', array(
109 1 => $priceSet)) . "<br/> $table";
112 $status = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet));
116 case 'CRM_Event_BAO_Event':
117 $status = ts('Are you sure you want to disable this Event?');
120 case 'CRM_Core_BAO_UFField':
121 $status = ts('Are you sure you want to disable this CiviCRM Profile field?');
124 case 'CRM_Contribute_BAO_ManagePremiums':
125 $status = 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.');
128 case 'CRM_Contact_BAO_RelationshipType':
129 $status = 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.');
132 case 'CRM_Financial_BAO_FinancialType':
133 $status = ts('Are you sure you want to disable this financial type?');
136 case 'CRM_Financial_BAO_FinancialAccount':
137 if (!CRM_Financial_BAO_FinancialAccount
::getARAccounts($recordID)) {
139 $status = 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).');
142 $status = ts('Are you sure you want to disable this financial account?');
146 case 'CRM_Financial_BAO_PaymentProcessor':
147 $status = 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.');
150 case 'CRM_Financial_BAO_PaymentProcessorType':
151 $status = ts('Are you sure you want to disable this payment processor type?');
154 case 'CRM_Core_BAO_LocationType':
155 $status = 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.');
158 case 'CRM_Event_BAO_ParticipantStatusType':
159 $status = 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.');
162 case 'CRM_Mailing_BAO_Component':
163 $status = ts('Are you sure you want to disable this component?');
166 case 'CRM_Core_BAO_CustomField':
167 $status = ts('Are you sure you want to disable this custom data field?');
170 case 'CRM_Core_BAO_CustomGroup':
171 $status = 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.');
174 case 'CRM_Core_BAO_MessageTemplate':
175 $status = ts('Are you sure you want to disable this message tempate?');
178 case 'CRM_ACL_BAO_ACL':
179 $status = ts('Are you sure you want to disable this ACL?');
182 case 'CRM_ACL_BAO_EntityRole':
183 $status = ts('Are you sure you want to disable this ACL Role Assignment?');
186 case 'CRM_Member_BAO_MembershipType':
187 $status = ts('Are you sure you want to disable this membership type?');
190 case 'CRM_Member_BAO_MembershipStatus':
191 $status = ts('Are you sure you want to disable this membership status rule?');
194 case 'CRM_Price_BAO_PriceField':
195 $status = ts('Are you sure you want to disable this price field?');
198 case 'CRM_Contact_BAO_Group':
199 $status = ts('Are you sure you want to disable this Group?');
202 case 'CRM_Core_BAO_OptionGroup':
203 $status = ts('Are you sure you want to disable this Option?');
206 case 'CRM_Contact_BAO_ContactType':
207 $status = ts('Are you sure you want to disable this Contact Type?');
210 case 'CRM_Core_BAO_OptionValue':
211 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
212 $label = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label');
213 $status = ts('Are you sure you want to disable the \'%1\' option ?', array(1 => $label));
214 $status .= '<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.');
217 case 'CRM_Contribute_BAO_ContributionRecur':
218 $recurDetails = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recordID);
219 $status = ts('Are you sure you want to mark this recurring contribution as cancelled?');
220 $status .= '<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>';
221 if ($recurDetails->membership_id
) {
222 $status .= '<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>';
226 case 'CRM_Batch_BAO_Batch':
227 if ($op == 'close') {
228 $status = ts('Are you sure you want to close this batch?');
230 elseif ($op == 'open') {
231 $status = ts('Are you sure you want to reopen this batch?');
233 elseif ($op == 'delete') {
234 $status = ts('Are you sure you want to delete this batch?');
236 elseif ($op == 'remove') {
237 $status = ts('Are you sure you want to remove this financial transaction?');
239 elseif ($op == 'export') {
240 $status = ts('Are you sure you want to close and export this batch?');
243 $status = ts('Are you sure you want to assign this financial transaction to the batch?');
248 $status = ts('Are you sure you want to disable this record?');
252 $statusMessage['status'] = $status;
253 $statusMessage['show'] = $show;
255 echo json_encode($statusMessage);
256 CRM_Utils_System
::civiExit();
259 static function getTagList() {
260 $name = CRM_Utils_Type
::escape($_GET['name'], 'String');
261 $parentId = CRM_Utils_Type
::escape($_GET['parentId'], 'Integer');
264 if (isset($_GET['search'])) {
265 $isSearch = CRM_Utils_Type
::escape($_GET['search'], 'Integer');
270 // always add current search term as possible tag
271 // here we append :::value to determine if existing / new tag should be created
275 'id' => $name . ":::value",
279 $query = "SELECT id, name FROM civicrm_tag WHERE parent_id = {$parentId} and name LIKE '%{$name}%'";
280 $dao = CRM_Core_DAO
::executeQuery($query);
282 while ($dao->fetch()) {
283 // make sure we return tag name entered by user only if it does not exists in db
284 if ($name == $dao->name
) {
287 // escape double quotes, which break results js
288 $tags[] = array('name' => addcslashes($dao->name
, '"'),
293 echo json_encode($tags);
294 CRM_Utils_System
::civiExit();
297 static function mergeTagList() {
298 $name = CRM_Utils_Type
::escape($_GET['s'], 'String');
299 $fromId = CRM_Utils_Type
::escape($_GET['fromId'], 'Integer');
300 $limit = CRM_Utils_Type
::escape($_GET['limit'], 'Integer');
302 // build used-for clause to be used in main query
303 $usedForTagA = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $fromId, 'used_for');
304 $usedForClause = array();
306 $usedForTagA = explode(",", $usedForTagA);
307 foreach ($usedForTagA as $key => $value) {
308 $usedForClause[] = "t1.used_for LIKE '%{$value}%'";
311 $usedForClause = !empty($usedForClause) ?
implode(' OR ', $usedForClause) : '1';
314 // query to list mergable tags
316 SELECT t1.name, t1.id, t1.used_for, t2.name as parent
318 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
319 WHERE t1.id <> {$fromId} AND
320 t1.name LIKE '%{$name}%' AND
323 $dao = CRM_Core_DAO
::executeQuery($query);
325 while ($dao->fetch()) {
327 if (!empty($dao->used_for
)) {
328 $usedForTagB = explode(',', $dao->used_for
);
330 $usedForDiff = array_diff($usedForTagA, $usedForTagB);
331 if (!empty($usedForDiff)) {
335 $tag = addcslashes($dao->name
, '"') . "|{$dao->id}|{$warning}\n";
336 echo $tag = $dao->parent ?
(addcslashes($dao->parent
, '"') . ' :: ' . $tag) : $tag;
338 CRM_Utils_System
::civiExit();
341 static function processTags() {
342 $skipTagCreate = $skipEntityAction = $entityId = NULL;
343 $action = CRM_Utils_Type
::escape($_POST['action'], 'String');
344 $parentId = CRM_Utils_Type
::escape($_POST['parentId'], 'Integer');
345 if ($_POST['entityId']) {
346 $entityId = CRM_Utils_Type
::escape($_POST['entityId'], 'Integer');
349 $entityTable = CRM_Utils_Type
::escape($_POST['entityTable'], 'String');
351 if ($_POST['skipTagCreate']) {
352 $skipTagCreate = CRM_Utils_Type
::escape($_POST['skipTagCreate'], 'Integer');
355 if ($_POST['skipEntityAction']) {
356 $skipEntityAction = CRM_Utils_Type
::escape($_POST['skipEntityAction'], 'Integer');
359 // check if user has selected existing tag or is creating new tag
360 // this is done to allow numeric tags etc.
361 $tagValue = explode(':::', $_POST['tagID']);
363 $createNewTag = FALSE;
364 $tagID = $tagValue[0];
365 if (isset($tagValue[1]) && $tagValue[1] == 'value') {
366 $createNewTag = TRUE;
370 // if action is select
371 if ($action == 'select') {
372 // check the value of tagID
373 // if numeric that means existing tag
374 // else create new tag
375 if (!$skipTagCreate && $createNewTag) {
378 'parent_id' => $parentId,
381 $tagObject = CRM_Core_BAO_Tag
::add($params, CRM_Core_DAO
::$_nullArray);
385 'id' => $tagObject->id
,
388 $tagID = $tagObject->id
;
391 if (!$skipEntityAction && $entityId) {
392 // save this tag to contact
394 'entity_table' => $entityTable,
395 'entity_id' => $entityId,
399 CRM_Core_BAO_EntityTag
::add($params);
401 // if action is delete
403 elseif ($action == 'delete') {
404 if (!is_numeric($tagID)) {
405 $tagID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name');
408 // delete this tag entry for the entity
410 'entity_table' => $entityTable,
411 'entity_id' => $entityId,
415 CRM_Core_BAO_EntityTag
::del($params);
423 echo json_encode($tagInfo);
424 CRM_Utils_System
::civiExit();
427 function mappingList() {
428 $params = array('mappingID');
429 foreach ($params as $param) {
430 $
$param = CRM_Utils_Array
::value($param, $_POST);
434 echo json_encode(array('error_msg' => 'required params missing.'));
435 CRM_Utils_System
::civiExit();
438 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection1($mappingID);
439 extract($selectionOptions);
442 foreach ($sel4 as $id => $name) {
449 echo json_encode($elements);
450 CRM_Utils_System
::civiExit();
453 function mappingList1() {
454 $params = array('mappingID');
455 foreach ($params as $param) {
456 $
$param = CRM_Utils_Array
::value($param, $_POST);
460 echo json_encode(array('error_msg' => 'required params missing.'));
461 CRM_Utils_System
::civiExit();
464 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection1($mappingID);
465 extract($selectionOptions);
468 foreach ($sel5 as $id => $name) {
469 $elements['sel5'][] = array(
474 $elements['recipientMapping'] = $recipientMapping;
476 echo json_encode($elements);
477 CRM_Utils_System
::civiExit();
480 static function mergeTags() {
481 $tagAId = CRM_Utils_Type
::escape($_POST['fromId'], 'Integer');
482 $tagBId = CRM_Utils_Type
::escape($_POST['toId'], 'Integer');
484 $result = CRM_Core_BAO_EntityTag
::mergeTags($tagAId, $tagBId);
486 if (!empty($result['tagB_used_for'])) {
487 $usedFor = CRM_Core_OptionGroup
::values('tag_used_for');
488 foreach ($result['tagB_used_for'] as & $val) {
489 $val = $usedFor[$val];
491 $result['tagB_used_for'] = implode(', ', $result['tagB_used_for']);
494 echo json_encode($result);
495 CRM_Utils_System
::civiExit();
498 function recipient() {
499 $params = array('recipient');
500 foreach ($params as $param) {
501 $
$param = CRM_Utils_Array
::value($param, $_POST);
505 echo json_encode(array('error_msg' => 'required params missing.'));
506 CRM_Utils_System
::civiExit();
509 switch ($recipient) {
510 case 'Participant Status':
511 $values = CRM_Event_PseudoConstant
::participantStatus();
514 case 'participant_role':
515 $values = CRM_Event_PseudoConstant
::participantRole();
523 foreach ($values as $id => $name) {
530 echo json_encode($elements);
531 CRM_Utils_System
::civiExit();