Odyssey
TrustedReport.data
1 <?php
2 /*
3  * File: TrustedReport.data
4  * Purpose: Handle the CRUD portion of the Trusted Vendor Master / Detail report.
5  * When returning the requested data do it in a JSON format, for the client to
6  * display accordingly.
7  *
8  * Call this script with the following parameters
9  * action - what the client side is requesting.
10  * optionally, trustid for data related to a particular cutrustedmaster
11  * optionally, cu for a particular cutrusteddetail entry
12  *
13  * Returns JSON OBJECT.
14  */
15 try {
16  // ** Include required SCRIPTS
17  $monLibrary= dirname(__FILE__) . "/../library";
18  $monIncludes= dirname(__FILE__) . "/../includes";
19  $sharedLibrary= dirname(__FILE__) . "/../../shared/library";
20  require_once("$monLibrary/cu_top.i");
21  require_once("$monLibrary/ck_hticket.i");
22  require_once("$monIncludes/cu_remote_top.prg");
23  require_once("$sharedLibrary/cutrusted.i");
24  require_once("$sharedLibrary/hcuErrorReport.i");
25 
26  $dms_ok = array('action'=>'string', 'trustid'=>'string', 'cu'=>'string');
27  dms_import($dms_ok);
28 
29  //Open database connection
30  $dbh = $link;
31 
32  header('Content-Type: application/json');
33 
34 
35  //get the database connection
36  //$dbh is set up
37 
38  //require_once('cu_fun.i');
39 
40  $aryResult = array();
41  $aryErrors = array();
42  $aryReply = array();
43  $aryInfo = array();
44  // do the requested operation
45  switch ($action) {
46  case "create":
47  case "update": // update has an id
48  case "destroy":
49  // no add / update / delete at this time
50 
51  break;
52 
53  case "read_master":
54  /*
55  * list info from cutrustedmaster table
56  */
57  $parms = array();
58  $return = cutm_list($dbh, $parms);
59 
60  //$aryResult = $return['data'];
61  $aryResult = array();
62  if (is_array($return['data'])) {
63  foreach ($return['data'] as $key => $val) {
64  $thisprop = array();
65  if (is_array($val['fields'])) {
66  foreach ($val['fields'] as $vk => $vv) {
67  if (is_array($vv)) {
68  $thisprop[] = array('vname' => $vk, 'vtype' => $vv['Type'], 'vdefault' => $vv['Default']);
69  }
70  }
71  }
72  $thisun = array(
73  'trustedid' => $val['trustedid'],
74  'trustedvendor' => $val['trustedvendor'],
75  'trustedtype' => $val['trustedtype'],
76  'trustedprops' => array_values($thisprop));
77  //"hcuinterface":"[]",
78  $return['data'][$key] = $thisun;
79  }
80  }
81  $aryResult=(is_array($return['data']) ? array_values($return['data']) : '[]');
82  if ($fp) {
83  fwrite($fp, print_r($aryResult, true));
84  }
85 
86 
87  //for ( $i = 0; $i < count( $aryResult ); $i++ ) {
88  //$aryResult[$i]["notifymsg"] = html_entity_decode( $aryResult[$i]["notifymsg"], ENT_COMPAT | ENT_HTML401, "UTF-8" );
89  //}
90 
91  break;
92 
93  case "read_masterprop":
94  /*
95  * list properties from a single cutrustedmaster entry
96  */
97  $parms = array('trustedid' => $trustid);
98  $return = cutm_readdflt($dbh, $parms);
99 
100  $aryResult = $return["master"];
101 
102  break;
103 
104  case "read_clients":
105  /*
106  * list clients with a detail record for a selected cutrustedmaster entry
107  */
108  $parms = array('trustedid' => $trustid);
109  $return = cutd_list($dbh, $parms);
110 
111  $aryResult = array();
112  //foreach ($return['data'] as $key => $val) {
113  //$aryResult[] = $val;
114  //}
115  if (is_array($return['data'])) {
116  foreach ($return['data'] as $key => $val) {
117  $thisprop = array();
118  if (is_array($val['fields'])) {
119  foreach ($val['fields'] as $vk =>$vv) {
120  $thisprop[]=array('propname'=>$vk,'propval'=>$vv);
121  }
122  }
123  $thisun = array(
124  'cu' => $val['cu'],
125  'trustedid' => $val['trustedid'],
126  'trustedprops'=> array_values($thisprop));
127  $return['data'][$key]=$thisun;
128  }
129  }
130  $aryResult=(is_array($return['data']) ? array_values($return['data']) : '[]');
131  if ($fp) {
132  fwrite($fp, print_r($aryResult, true));
133  }
134 
135  break;
136 
137  case "read_clientprop":
138  /*
139  * list properties from a single cutrusteddetail entry
140  */
141  $parms = array('Cu' => $cu, 'trustedid' => $trustid);
142  $return = cutd_read($dbh, $parms);
143 
144  $aryResult = array();
145  foreach ($return['data'] as $key => $val) {
146  $aryResult[] = $val;
147  }
148  break;
149  default:
150  $aryErrors[] = "Unexpected action: {$action}";
151  throw new Exception(json_encode($aryErrors));
152  }
153 }
154 catch(Exception $ex)
155 {
156  //Return error message
157  $aryReply["homecuErrors"] = json_decode( $ex->getMessage() );
158 
159  // if returning error, not replying with data
160  $aryResult = array();
161 
162  // if returning error, not returning status
163  $aryInfo = array();
164 }
165 
166  if ( count( $aryInfo ) ) {
167  $aryReply["homecuInfo"] = $aryInfo;
168  }
169 
170  if ($aryResult == '[]') {
171  $aryReply["homecuData"]=null;
172  $aryReply["homecuCount"] = 0;
173  } else {
174  $aryReply["homecuData"] = $aryResult;
175  $aryReply["homecuCount"] = count($aryResult);
176  }
177 
178  print json_encode($aryReply);
179 
180 ?>