Odyssey
hcuExternalAccts.data
1 <?php
2 /*
3  * File: hcuACH.data
4  * Purpose: Handle the CRUD portion of the ACH. This includes ACH Payments and Collections,
5  * single and batch, and also Payroll. When returning the requested data
6  * do it in a JSON format, for the client to display accordingly.
7  *
8  *
9  * Call this script with the following parameters
10  * action - what the client side is requesting.
11  *
12  * Returns JSON OBJECT.
13  */
14 try {
15  // ** SET HOMECU FLAGS
16  $serviceShowInfo = false;
17  $serviceLoadMenu = false;
18  $serviceShowMenu = false;
19 
20 
21  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
22  // hcuService will be returning a status object: e.g. ["homecuErrors":{[{"message":"message1"}...{"message":"messageN"}}]
23  require_once(dirname(__FILE__) . '/../library/hcuService.i');
24 
25  require_once(dirname(__FILE__) . '/../library/permissions.i');
26  require_once(dirname(__FILE__) . '/../library/hcuExternalAccts.i');
27 
28  // ** IMPORT FORM VALUES
29  $inputVars = array();
30  $varOk = array(
31  "action" => array('filter' => FILTER_SANITIZE_STRING),
32  "display_name" => array("filter" => FILTER_SANITIZE_STRING, 'options' => array('flags' => FILTER_FLAG_NO_ENCODE_QUOTES)),
33  "name_on_account" => array("filter" => FILTER_SANITIZE_STRING, 'options' => array('flags' => FILTER_FLAG_NO_ENCODE_QUOTES)),
34  "dfi_routing" => array('filter' => FILTER_SANITIZE_STRING),
35  "dfi_account" => array('filter' => FILTER_SANITIZE_STRING),
36  "dfi_account_type" => array('filter' => FILTER_SANITIZE_STRING),
37  "id" => array('filter' => FILTER_SANITIZE_NUMBER_INT),
38  "micro1" => array(' filter' => FILTER_SANITIZE_NUMBER_INT ),
39  "micro2" => array(' filter' => FILTER_SANITIZE_NUMBER_INT )
40  );
41 
42  HCU_ImportVars( $inputVars, "", $varOk );
43 
44  header('Content-Type: application/json');
45 
46  if (!$dbh) {
47  // The connection was not made to the database
48  // unresolved: return an error??
49  }
50 
51  $aryReply = array();
52  $aryResult = array();
53 
54  $aryInfo = array();
55 
56  /*
57  * Returned Errors Structure
58  *
59  * homecuInfo => An informational message to report to the user.
60  *
61  * The existence of Errors is proof of an error, if homecuErrors is NOT found or
62  * empty then success is assumed
63  *
64  * 'homecuErrors' element will contain an array of the following object
65  * 'id' => the element id of the error, this is useful so the client side can
66  * highlight the affected element
67  * 'message' => the error message to be displayed back to the member. For
68  * summary only information, leave the 'id' field blank and
69  * enter the message here
70  *
71  * 'homecuData' element will return information to display for the member.
72  */
73 
74  // ** First check the refer script -- This will be used to ensure proper usage later
75  $parseRefer = parse_url($_SERVER['HTTP_REFERER']);
76  $referScript = basename($parseRefer['path']);
77 
78  if (!in_array($referScript, array('hcuExternalAccts.prg', "hcuM2MAccts.prg", "hcuAppFeed.prg"))) {
79  // ** Wrong script calling this data routine
80  $aryErrors[] = $MC->msg('Feature Unavailable', HCU_DISPLAY_AS_RAW);
81  throw new Exception (HCU_JsonEncode($aryErrors));
82  }
83 
84  // ** Verify the user can access this feature.
85  $permissionInputs = array();
86  $permissionInputs["feature"] = $referScript == 'hcuExternalAccts.prg' ? FEATURE_EXTERNAL_TRANSFERS : FEATURE_M2M_TRANSFERS;
87 
88  // make sure the user can be here (don't redirect, so we can handle it)
89  $return = PermCheckFeatureScreen($dbh, $HB_ENV, $MC, $permissionInputs["feature"], "", false);
90  if ( !$return ) {
91  // * Rights NOT set up for user access
92  $aryErrors[] = $MC->msg('Rights not set', HCU_DISPLAY_AS_HTML);
93  throw new Exception (HCU_JsonEncode($aryErrors));
94  }
95 
96  $return = Perm_AccessRights( $dbh, $HB_ENV, $permissionInputs );
97  if ( !$return ) {
98  // * Rights NOT set up for user access
99  $aryErrors[] = $MC->msg('Rights not set', HCU_DISPLAY_AS_HTML);
100  throw new Exception (HCU_JsonEncode($aryErrors));
101  }
102 
103  // don't worry about checking if External Accounts Enabled because they wouldn't get the feature if it wasn't
104  $aryErrors = array();
105 
106  $return = ManageExternalAccount( $HB_ENV, $inputVars );
107 
108  if ( $return["info"] !== array() ) {
109  $aryInfo = $return["info"];
110  }
111 
112  if ( $return["status"]["code"] !== "000" ) {
113  throw new Exception (HCU_JsonEncode($return["status"]["errors"]));
114  }
115 
116  $action = $inputVars["action"];
117  $aryResult[$action] = $return["data"];
118 }
119 catch(Exception $ex)
120 {
121  //Return error message
122  $aryReply["homecuErrors"] = HCU_JsonDecode( $ex->getMessage() );
123 
124  // if returning error, not replying with data
125  $aryResult = array();
126 
127  // if returning error, not returning status
128  $aryInfo = array();
129 }
130 
131 if ( count( $aryInfo ) ) {
132  $aryReply["homecuInfo"] = $aryInfo;
133 }
134 
135 if ( count( $aryResult ) ) {
136  $aryReply["homecuData"] = $aryResult;
137 }
138 
139 print HCU_JsonEncode(Array("Results" => $aryReply));