Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
15 | * @copyright TTTP | |
6a488035 TO |
16 | * |
17 | */ | |
18 | ||
19 | /** | |
3ab5efa9 EM |
20 | * @param $params |
21 | * @param $smarty | |
22 | * @return string|void | |
6a488035 TO |
23 | */ |
24 | function smarty_function_crmAPI($params, &$smarty) { | |
6a488035 TO |
25 | if (!array_key_exists('entity', $params)) { |
26 | $smarty->trigger_error("assign: missing 'entity' parameter"); | |
27 | return "crmAPI: missing 'entity' parameter"; | |
28 | } | |
be2fb01f | 29 | $errorScope = CRM_Core_TemporaryErrorScope::create(['CRM_Utils_REST', 'fatal']); |
6a488035 | 30 | $entity = $params['entity']; |
bb6f7117 CW |
31 | $action = CRM_Utils_Array::value('action', $params, 'get'); |
32 | $params['sequential'] = CRM_Utils_Array::value('sequential', $params, 1); | |
9c1bc317 | 33 | $var = $params['var'] ?? NULL; |
bb6f7117 | 34 | CRM_Utils_Array::remove($params, 'entity', 'action', 'var'); |
6a488035 TO |
35 | $params['version'] = 3; |
36 | require_once 'api/api.php'; | |
37 | $result = civicrm_api($entity, $action, $params); | |
ca32aecc | 38 | unset($errorScope); |
6a488035 | 39 | if ($result === FALSE) { |
b44e3f84 | 40 | $smarty->trigger_error("Unknown error"); |
6a488035 TO |
41 | } |
42 | ||
9df35622 | 43 | if (!empty($result['is_error'])) { |
92fcb95f | 44 | $smarty->trigger_error("{crmAPI} " . $result["error_message"]); |
79004baa XD |
45 | } |
46 | ||
bb6f7117 | 47 | if (!$var) { |
6a488035 TO |
48 | return json_encode($result); |
49 | } | |
50 | if (!empty($params['json'])) { | |
bb6f7117 | 51 | $smarty->assign($var, json_encode($result)); |
6a488035 TO |
52 | } |
53 | else { | |
bb6f7117 | 54 | $smarty->assign($var, $result); |
6a488035 TO |
55 | } |
56 | } |