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