Odyssey
CuVendorListApi.prg
1 <?php
2 /* This is an api to cutd_list(), allowing us to make use of the single trustid or array of
3  * trustedids to batch get associated CU's. It is intended for use only in monitor, if used
4  * otherwise remove $e->getMessage(). Params from POST.
5  * @cookie string HCUTicket
6  * @param string cu optional
7  * @param string trustedid optional
8  * @param array trustedids optional
9  * @return string JSON
10  */
11  // Resolve obscurity. These are set by variable variables in dms_import().
12 $Cu = null;
13 $params = array();
14 $trustedid = null;
15 $trustedids = null;
16 
17 $monLibrary = __DIR__ . "/../library";
18 $sharedLibrary = __DIR__ . "/../../shared/library";
19 require_once("$monLibrary/cu_top.i");
20 require_once("$monLibrary/ck_hticket.i");
21 require_once("$sharedLibrary/hcuCommon.i");
22 require_once("$sharedLibrary/cutrusted.i");
23 
24 if (!CheckPerm($dbh, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
25  // ** Permissions failed
26  // ** redirect to new page
27  header("Location: /hcuadm/hcu_noperm.prg");
28  exit;
29 }
30 
31 header('Content-Type: application/json');
32 
33 try {
34  $dms_ok = array('trustedid'=>'string', 'trustedids' => 'string', 'Cu'=>'string');
35  dms_import($dms_ok);
36 
37  if ($trustedid && ! empty($trustedid)) {
38  $params['trustedid'] = $trustedid;
39  }
40  if ($trustedids && ! empty($trustedids)) {
41  $params['trustedids'] = HCU_JsonDecode($trustedids, true, true);
42  }
43  if ($Cu && ! empty($Cu)) {
44  $params['Cu'] = $Cu;
45  }
46 
47  echo HCU_JsonEncode(cutd_list($dbh, $params));
48 
49 } catch (Exception $e) {
50 
51  echo HCU_JsonEncode(array(
52  'status' => array(
53  'Response' => 'false',
54  'Message' => 'Failed',
55  'Errors' => array("Exception reading CU/Trusted ID list: {$e->getMessage()}")
56  )
57  )
58  );
59 }