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 * CRM-12337 Output navigation menu as executable javascript
43 * @see smarty_function_crmNavigationMenu
45 static function getNavigationMenu() {
46 $session = CRM_Core_Session
::singleton();
47 $contactID = $session->get('userID');
49 // Set headers to encourage browsers to cache for a long time
50 // If we want to refresh the menu we will send a different url
52 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() +
$year));
53 header('Content-Type: application/javascript');
54 header("Cache-Control: max-age=$year, public");
56 // Render template as a javascript file
57 $smarty = CRM_Core_Smarty
::singleton();
58 $navigation = CRM_Core_BAO_Navigation
::createNavigation($contactID);
59 $smarty->assign('timeGenerated', date('d M Y H:i:s'));
60 $smarty->assign('navigation', $navigation);
61 print $smarty->fetch('CRM/common/Navigation.tpl');
63 CRM_Utils_System
::civiExit();
67 * Return menu tree as json data for editing
69 static function getNavigationList() {
70 echo CRM_Core_BAO_Navigation
::buildNavigation(TRUE, FALSE);
71 CRM_Utils_System
::civiExit();
75 * Function to process drag/move action for menu tree
77 static function menuTree() {
78 CRM_Core_BAO_Navigation
::processNavigation($_GET);
82 * Function to build status message while
83 * enabling/ disabling various objects
85 static function getStatusMsg() {
86 $recordID = CRM_Utils_Type
::escape($_POST['recordID'], 'Integer');
87 $recordBAO = CRM_Utils_Type
::escape($_POST['recordBAO'], 'String');
88 $op = CRM_Utils_Type
::escape($_POST['op'], 'String');
91 if ($op == 'disable-enable') {
92 $status = ts('Are you sure you want to enable this record?');
96 case 'CRM_Core_BAO_UFGroup':
97 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
98 $method = 'getUFJoinRecord';
99 $result = array($recordBAO, $method);
100 $ufJoin = call_user_func_array(($result), array($recordID, TRUE));
101 if (!empty($ufJoin)) {
102 $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?');
105 $status = ts('Are you sure you want to disable this profile?');
109 case 'CRM_Price_BAO_PriceSet':
110 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
111 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($recordID);
112 $priceSet = CRM_Price_BAO_PriceSet
::getTitle($recordID);
114 if (!CRM_Utils_System
::isNull($usedBy)) {
115 $template = CRM_Core_Smarty
::singleton();
116 $template->assign('usedBy', $usedBy);
118 'Event' => 'civicrm_event',
119 'Contribution' => 'civicrm_contribution_page',
120 'EventTemplate' => 'civicrm_event_template'
123 foreach ($comps as $name => $table) {
124 if (array_key_exists($table, $usedBy)) {
128 $template->assign('contexts', $contexts);
131 $table = $template->fetch('CRM/Price/Page/table.tpl');
132 $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(
133 1 => $priceSet)) . "<br/> $table";
136 $status = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet));
140 case 'CRM_Event_BAO_Event':
141 $status = ts('Are you sure you want to disable this Event?');
144 case 'CRM_Core_BAO_UFField':
145 $status = ts('Are you sure you want to disable this CiviCRM Profile field?');
148 case 'CRM_Contribute_BAO_ManagePremiums':
149 $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.');
152 case 'CRM_Contact_BAO_RelationshipType':
153 $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.');
156 case 'CRM_Financial_BAO_FinancialType':
157 $status = ts('Are you sure you want to disable this financial type?');
160 case 'CRM_Financial_BAO_FinancialAccount':
161 if (!CRM_Financial_BAO_FinancialAccount
::getARAccounts($recordID)) {
163 $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).');
166 $status = ts('Are you sure you want to disable this financial account?');
170 case 'CRM_Financial_BAO_PaymentProcessor':
171 $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.');
174 case 'CRM_Financial_BAO_PaymentProcessorType':
175 $status = ts('Are you sure you want to disable this payment processor type?');
178 case 'CRM_Core_BAO_LocationType':
179 $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.');
182 case 'CRM_Event_BAO_ParticipantStatusType':
183 $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.');
186 case 'CRM_Mailing_BAO_Component':
187 $status = ts('Are you sure you want to disable this component?');
190 case 'CRM_Core_BAO_CustomField':
191 $status = ts('Are you sure you want to disable this custom data field?');
194 case 'CRM_Core_BAO_CustomGroup':
195 $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.');
198 case 'CRM_Core_BAO_MessageTemplate':
199 $status = ts('Are you sure you want to disable this message tempate?');
202 case 'CRM_ACL_BAO_ACL':
203 $status = ts('Are you sure you want to disable this ACL?');
206 case 'CRM_ACL_BAO_EntityRole':
207 $status = ts('Are you sure you want to disable this ACL Role Assignment?');
210 case 'CRM_Member_BAO_MembershipType':
211 $status = ts('Are you sure you want to disable this membership type?');
214 case 'CRM_Member_BAO_MembershipStatus':
215 $status = ts('Are you sure you want to disable this membership status rule?');
218 case 'CRM_Price_BAO_PriceField':
219 $status = ts('Are you sure you want to disable this price field?');
222 case 'CRM_Contact_BAO_Group':
223 $status = ts('Are you sure you want to disable this Group?');
226 case 'CRM_Core_BAO_OptionGroup':
227 $status = ts('Are you sure you want to disable this Option?');
230 case 'CRM_Contact_BAO_ContactType':
231 $status = ts('Are you sure you want to disable this Contact Type?');
234 case 'CRM_Core_BAO_OptionValue':
235 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $recordBAO) . '.php');
236 $label = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label');
237 $status = ts('Are you sure you want to disable the \'%1\' option ?', array(1 => $label));
238 $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.');
241 case 'CRM_Contribute_BAO_ContributionRecur':
242 $recurDetails = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recordID);
243 $status = ts('Are you sure you want to mark this recurring contribution as cancelled?');
244 $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>';
245 if ($recurDetails->membership_id
) {
246 $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>';
250 case 'CRM_Batch_BAO_Batch':
251 if ($op == 'close') {
252 $status = ts('Are you sure you want to close this batch?');
254 elseif ($op == 'open') {
255 $status = ts('Are you sure you want to reopen this batch?');
257 elseif ($op == 'delete') {
258 $status = ts('Are you sure you want to delete this batch?');
260 elseif ($op == 'remove') {
261 $status = ts('Are you sure you want to remove this financial transaction?');
263 elseif ($op == 'export') {
264 $status = ts('Are you sure you want to close and export this batch?');
267 $status = ts('Are you sure you want to assign this financial transaction to the batch?');
272 $status = ts('Are you sure you want to disable this record?');
276 $statusMessage['status'] = $status;
277 $statusMessage['show'] = $show;
279 echo json_encode($statusMessage);
280 CRM_Utils_System
::civiExit();
283 static function getTagList() {
284 $name = CRM_Utils_Type
::escape($_GET['name'], 'String');
285 $parentId = CRM_Utils_Type
::escape($_GET['parentId'], 'Integer');
288 if (isset($_GET['search'])) {
289 $isSearch = CRM_Utils_Type
::escape($_GET['search'], 'Integer');
294 // always add current search term as possible tag
295 // here we append :::value to determine if existing / new tag should be created
299 'id' => $name . ":::value",
303 $query = "SELECT id, name FROM civicrm_tag WHERE parent_id = {$parentId} and name LIKE '%{$name}%'";
304 $dao = CRM_Core_DAO
::executeQuery($query);
306 while ($dao->fetch()) {
307 // make sure we return tag name entered by user only if it does not exists in db
308 if ($name == $dao->name
) {
311 // escape double quotes, which break results js
312 $tags[] = array('name' => addcslashes($dao->name
, '"'),
317 echo json_encode($tags);
318 CRM_Utils_System
::civiExit();
321 static function mergeTagList() {
322 $name = CRM_Utils_Type
::escape($_GET['s'], 'String');
323 $fromId = CRM_Utils_Type
::escape($_GET['fromId'], 'Integer');
324 $limit = CRM_Utils_Type
::escape($_GET['limit'], 'Integer');
326 // build used-for clause to be used in main query
327 $usedForTagA = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $fromId, 'used_for');
328 $usedForClause = array();
330 $usedForTagA = explode(",", $usedForTagA);
331 foreach ($usedForTagA as $key => $value) {
332 $usedForClause[] = "t1.used_for LIKE '%{$value}%'";
335 $usedForClause = !empty($usedForClause) ?
implode(' OR ', $usedForClause) : '1';
338 // query to list mergable tags
340 SELECT t1.name, t1.id, t1.used_for, t2.name as parent
342 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
343 WHERE t1.id <> {$fromId} AND
344 t1.name LIKE '%{$name}%' AND
347 $dao = CRM_Core_DAO
::executeQuery($query);
349 while ($dao->fetch()) {
351 if (!empty($dao->used_for
)) {
352 $usedForTagB = explode(',', $dao->used_for
);
354 $usedForDiff = array_diff($usedForTagA, $usedForTagB);
355 if (!empty($usedForDiff)) {
359 $tag = addcslashes($dao->name
, '"') . "|{$dao->id}|{$warning}\n";
360 echo $tag = $dao->parent ?
(addcslashes($dao->parent
, '"') . ' :: ' . $tag) : $tag;
362 CRM_Utils_System
::civiExit();
365 static function processTags() {
366 $skipTagCreate = $skipEntityAction = $entityId = NULL;
367 $action = CRM_Utils_Type
::escape($_POST['action'], 'String');
368 $parentId = CRM_Utils_Type
::escape($_POST['parentId'], 'Integer');
369 if ($_POST['entityId']) {
370 $entityId = CRM_Utils_Type
::escape($_POST['entityId'], 'Integer');
373 $entityTable = CRM_Utils_Type
::escape($_POST['entityTable'], 'String');
375 if ($_POST['skipTagCreate']) {
376 $skipTagCreate = CRM_Utils_Type
::escape($_POST['skipTagCreate'], 'Integer');
379 if ($_POST['skipEntityAction']) {
380 $skipEntityAction = CRM_Utils_Type
::escape($_POST['skipEntityAction'], 'Integer');
383 // check if user has selected existing tag or is creating new tag
384 // this is done to allow numeric tags etc.
385 $tagValue = explode(':::', $_POST['tagID']);
387 $createNewTag = FALSE;
388 $tagID = $tagValue[0];
389 if (isset($tagValue[1]) && $tagValue[1] == 'value') {
390 $createNewTag = TRUE;
394 // if action is select
395 if ($action == 'select') {
396 // check the value of tagID
397 // if numeric that means existing tag
398 // else create new tag
399 if (!$skipTagCreate && $createNewTag) {
402 'parent_id' => $parentId,
405 $tagObject = CRM_Core_BAO_Tag
::add($params, CRM_Core_DAO
::$_nullArray);
409 'id' => $tagObject->id
,
412 $tagID = $tagObject->id
;
415 if (!$skipEntityAction && $entityId) {
416 // save this tag to contact
418 'entity_table' => $entityTable,
419 'entity_id' => $entityId,
423 CRM_Core_BAO_EntityTag
::add($params);
425 // if action is delete
427 elseif ($action == 'delete') {
428 if (!is_numeric($tagID)) {
429 $tagID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name');
432 // delete this tag entry for the entity
434 'entity_table' => $entityTable,
435 'entity_id' => $entityId,
439 CRM_Core_BAO_EntityTag
::del($params);
447 echo json_encode($tagInfo);
448 CRM_Utils_System
::civiExit();
451 function mappingList() {
452 $params = array('mappingID');
453 foreach ($params as $param) {
454 $
$param = CRM_Utils_Array
::value($param, $_POST);
458 echo json_encode(array('error_msg' => 'required params missing.'));
459 CRM_Utils_System
::civiExit();
462 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection1($mappingID);
463 extract($selectionOptions);
466 foreach ($sel4 as $id => $name) {
473 echo json_encode($elements);
474 CRM_Utils_System
::civiExit();
477 function mappingList1() {
478 $params = array('mappingID');
479 foreach ($params as $param) {
480 $
$param = CRM_Utils_Array
::value($param, $_POST);
484 echo json_encode(array('error_msg' => 'required params missing.'));
485 CRM_Utils_System
::civiExit();
488 $selectionOptions = CRM_Core_BAO_ActionSchedule
::getSelection1($mappingID);
489 extract($selectionOptions);
492 foreach ($sel5 as $id => $name) {
493 $elements['sel5'][] = array(
498 $elements['recipientMapping'] = $recipientMapping;
500 echo json_encode($elements);
501 CRM_Utils_System
::civiExit();
504 static function mergeTags() {
505 $tagAId = CRM_Utils_Type
::escape($_POST['fromId'], 'Integer');
506 $tagBId = CRM_Utils_Type
::escape($_POST['toId'], 'Integer');
508 $result = CRM_Core_BAO_EntityTag
::mergeTags($tagAId, $tagBId);
510 if (!empty($result['tagB_used_for'])) {
511 $usedFor = CRM_Core_OptionGroup
::values('tag_used_for');
512 foreach ($result['tagB_used_for'] as & $val) {
513 $val = $usedFor[$val];
515 $result['tagB_used_for'] = implode(', ', $result['tagB_used_for']);
518 echo json_encode($result);
519 CRM_Utils_System
::civiExit();
522 function recipient() {
523 $params = array('recipient');
524 foreach ($params as $param) {
525 $
$param = CRM_Utils_Array
::value($param, $_POST);
529 echo json_encode(array('error_msg' => 'required params missing.'));
530 CRM_Utils_System
::civiExit();
533 switch ($recipient) {
534 case 'Participant Status':
535 $values = CRM_Event_PseudoConstant
::participantStatus();
538 case 'participant_role':
539 $values = CRM_Event_PseudoConstant
::participantRole();
547 foreach ($values as $id => $name) {
554 echo json_encode($elements);
555 CRM_Utils_System
::civiExit();