Odyssey
hcuAppDirector.prg
1 <?php
2 
3 # Retrieve appconfig.xml file for cu specificed by ORG
4 # Insert <ANNOUNCE> tag content if applicable
5 #
6 # APPID : Identifies partner. Use OFXRQ for iPhone, OFXAA for Android
7 # ORG : Client Code
8 # APPVERSION : specify app code version
9 # DATAVERSION : specify version of returned data
10 #
11 
12 
13 /*
14  * TODO
15  * This file should recognize and return the offline status and offlineblurb
16  * when a cu is offline. Replace the appconfig.xml <cudown> tag
17  */
18  require_once(dirname(__FILE__) . '/../../shared/library/hcuCommon.i');
19  require_once(dirname(__FILE__) . '/../../shared/library/dms_imp_val.i');
20  require_once(dirname(__FILE__) . '/../../shared/library/hcuAppCommon.i');
21 
22  $inPost = array();
23  $varOk = array(
24  "APPID" => array('filter' => FILTER_SANITIZE_STRING),
25  "ORG" => array('filter' => FILTER_SANITIZE_STRING)
26  );
27 
28 HCU_ImportVars( $inPost, "", $varOk );
29 
30 try {
31 # must be POST method
32 if ($_SERVER['REQUEST_METHOD'] != 'POST')
33  throw new Exception('Unauthorized Method',2010);# post method required
34 
35 $inPost["APPID"] = trim( $inPost["APPID"] );
36 switch ($inPost['APPID']) {
37  case "OFXRQ":
38  # iPhone APP
39  $client_source_override = 'APP';
40  $appminver = 1;
41  $appdataver = 1;
42  break;
43 
44  case "OFXAA":
45  # Android APP
46  $client_source_override = 'ADA';
47  $appminver = 1;
48  $appdataver = 1;
49  break;
50 
51  default:
52  $HB_ENV['SYSENV']['logger']->info('request: ' . HCU_JsonEncode($_REQUEST));
53  $HB_ENV['SYSENV']['logger']->info('inPost: ' . HCU_JsonEncode($inPost));
54  throw new Exception("Unauthorized ID",2020); # invalid app id
55 }
56 
57 if (empty($inPost['ORG'])) {
58  throw new Exception("Invalid Credentials",2030); # Missing values
59 }
60  $CU = $inPost['ORG'];
61 
62 // ** SET HOMECU FLAGS
63  $serviceMinimal = true;
64  $serviceShowInfo = false;
65  $serviceLoadMenu = false;
66  $serviceShowMenu = false;
67  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
68  // hcuService will be returning a status object: e.g. ["homecuErrors":{[{"message":"message1"}...{"message":"messageN"}}]
69  require_once(dirname(__FILE__) . '/../library/hcuService.i');
70 
71 // $HB_ENV["SYSENV"]["logger"]->info( "CU is $CU \n\n" . print_r(array_diff_key($HB_ENV,array('MC' => 'drop')),true) . "\n\n" );
72 // $appfile = "/home/" . strtolower($CU) . "/public_html/appconfig.xml";
73 // $appconfig = file_get_contents($appfile);
74 
75  $appconfig = GetAppConfig($CU,'appconfig.xml');
76 
77  /*
78  * Include front page links.
79  * This is a temporary, hackish method until
80  * we can actually serve up 'app config' from database
81  */
82 
83  $links_arr = array();
84 
85  // ** Determine if we will be showing the 'FORGOT MY PASSWORD' link
86  if ($HB_ENV['flagset'] & GetFlagsetValue('CU_MEMRESET')) {
87  $links_arr[]['hculink'] = array(
88  'url' => htmlentities("{$HB_ENV['loginpath']}/hcuResetPwd.prg?cu=" . trim(strtoupper($CU)), ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE),
89  'label' => htmlentities($HB_ENV['MC']->msg('Forgot your password'), ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE),
90  'iconclass' => '',
91  'location' => 'FRONT');
92  }
93 
94  // ** Determine if we will be showing the 'MEMBER ENROLL' link
95  if ($HB_ENV['flagset3'] & GetFlagsetValue('CU3_SHOW_ENROLL')) {
96  $links_arr[]['hculink'] = array(
97  'url' => htmlentities("{$HB_ENV['loginpath']}/hcuActivate.prg?cu=" . trim(strtoupper($CU)), ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE),
98  'label' => htmlentities($HB_ENV['MC']->msg('New To Home Banking'), ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE),
99  'iconclass' => '',
100  'location' => 'FRONT');
101  }
102 
103 $frontLinks = assocArrayToXML($links_arr,'frontlinks');
104 # add the front links results to the appconfig results
105 
106 $appconfig = preg_replace('/<appfeed>/',"<appfeed>{$frontLinks}",$appconfig);
107 
108 // header("Content-Type: application/x-ofx");
109  header("Content-length: " . strlen($appconfig));
110  print $appconfig;
111 
112  exit;
113 
114 } catch (Exception $e) {
115  $code = $e->getCode();
116  $message = $e->getMessage();
117 
118  $xml_arr = array('STATUS' => array('CODE' => $code, 'SEVERITY' => 'ERROR'),
119  'MESSAGE'=> array('ERR' => htmlspecialchars($message, ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE), 'ERRNO' => 999, 'ERRSTAT' =>'FAIL'));
120 
121  send_response($xml_arr,'XML');
122 }
123 /**
124  *
125  * @param string $data XML string to be formatted
126  * @return string XML 'pretty' with indents
127  */
128  function Format_AppFeed($data) {
129  /*
130  * decided not to use this -- adds unneccessary white space
131  * and we want to explore moving to json instead
132  */
133 
134  $dom = new DOMDocument();
135 
136  $dom->preserveWhiteSpace = false;
137  $dom->formatOutput = true;
138 
139  $dom->loadXML($data);
140  $out = $dom->saveXML();
141 
142  $out = str_replace('<?xml version="1.0"?>','',$out);
143 
144  return ($out);
145 }
146 
147 function send_response($reply_arr, $sendas='XML') {
148  switch ($sendas) {
149  case 'JSON':
150  $xmlResp = HCU_JsonEncode($reply_arr);
151  header("Content-Type: application/json");
152 // header("Content-disposition: inline; filename=\"{$HB_ENV['Cu']}_txns.json\"");
153  break;
154  case 'XML':
155  default:
156 // $xmlResp = Format_AppFeed(assocArrayToXML($reply_arr,'APPFEED'));
157  $xmlResp = assocArrayToXML($reply_arr,'APPFEED');
158  header("Content-Type: application/x-ofx");
159 // header("Content-disposition: inline; filename=\"{$HB_ENV['Cu']}_txns.ofx\"");
160  break;
161  }
162 
163  header("Content-length: " . strlen($xmlResp));
164  print $xmlResp;
165 
166  exit;
167 }
168 
169 /**
170  *
171  * @param array $ar associative array of items to be transformed to XML
172  * @param string $base root xml tag to use
173  *
174  * @return string XML result string
175  */
176 function assocArrayToXML($ar, $base='APPFEED')
177 {
178  $xml = new SimpleXMLElement("<$base></$base>");
179 // $GLOBALS["HB_ENV"]["SYSENV"]["logger"]->info(print_r($ar,true));
180 
181  $f = create_function('$f,$c,$a','
182  foreach($a as $k=>$v) {
183  if(is_array($v)) {
184  if (is_numeric($k)) {
185  $f($f,$c,$v);
186  } else {
187  $ch=$c->addChild($k);
188  $f($f,$ch,$v);
189  }
190  } else {
191  $c->addChild($k,$v);
192  }
193  }');
194  $f($f,$xml,$ar);
195 
196  $return = $xml->asXML();
197 
198  $return = str_replace('<?xml version="1.0"?>','',$return);
199 
200  return $return;
201 }