Odyssey
hcuArchiveCheck.data
1 <?php
2 /*
3  * File: hcuArchiveCheck.data
4  * Purpose: Validate inputs and create a URL string to send to the third party.
5  *
6  * Call this script with the following parameters
7  * action - what the client side is requesting.
8  *
9  *
10  * Returns JSON OBJECT.
11  */
12 
13 try {
14  // ** SET HOMECU FLAGS
15  $serviceShowInfo = false;
16  $serviceLoadMenu = false;
17  $serviceShowMenu = false;
18  $serviceAllowReadonly = true;
19 
20 
21  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
22  // unresolved - hcuService will be returning a status object: e.g. ["homecuErrors":{[{"message":"message1"}...{"message":"messagen"}]}]
23  require_once(dirname(__FILE__) . '/../library/hcuService.i');
24 
25 
26  // ** IMPORT FORM VALUES
27  $varOk = array(
28  "action" => array("filter" => FILTER_SANITIZE_STRING),
29  "check_number" => array("filter" => FILTER_SANITIZE_STRING),
30  "date_cleared" => array("filter" => FILTER_SANITIZE_STRING),
31  "amount" => array("filter" => FILTER_SANITIZE_STRING),
32  "account" => array("filter" => FILTER_SANITIZE_STRING)
33  );
34  HCU_ImportVars( $HB_ENV, "HCUPOST", $varOk );
35 
36  $Cu = $HB_ENV["Cu"];
37  $Cn = $HB_ENV["Cn"];
38 
39  header('Content-Type: application/json');
40 
41 
42  //get the database connection
43  // $dbh is set up
44  // ** First check the refer script -- make sure coming from right place
45  $parseRefer = parse_url($_SERVER['HTTP_REFERER']);
46  $referScript = basename($parseRefer['path']);
47  if (!in_array($referScript, array('hcuArchiveCheck.prg'))) {
48  // ** Wrong script calling this data routine
49  $aryErrors[] = $MC->msg('Feature Unavailable', HCU_DISPLAY_AS_RAW);
50  throw new Exception (json_encode($aryErrors));
51  }
52 
53  /*
54  * ** CHECK USER FEATURE PERMISSIONS **
55  * NOTE: DO NOT AUTO-REDIR. Handle perm error here
56  */
57  if (!PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_BASIC, '', false)) {
58  throw new Exception (HCU_JsonEncode(Array($MC->msg('Rights not set', HCU_DISPLAY_AS_HTML))));
59  }
60 
61 
62  if (!$dbh) {
63  // The connection was not made to the database
64  // not calling the database as of 09/04/2014
65  }
66 
67  // initialize the error and result objects
68  $aryResult = array();
69  $aryErrors = array();
70  $aryInfo = array();
71  $aryReply = array();
72 
73 
74  // do the requested operation
75  switch ( $HB_ENV["HCUPOST"]["action"] ) {
76  case "create_url":
77  // Validate all information is correct and entered before creating the URL for the image
78  if (trim($HB_ENV["HCUPOST"]["check_number"]) == '' || !is_numeric($HB_ENV["HCUPOST"]["check_number"])) {
79  $aryErrors[] = $MC->msg('Check Number Must Be Numeric', HCU_DISPLAY_AS_RAW);
80  } else {
81  $check_number = trim($HB_ENV["HCUPOST"]["check_number"]);
82  }
83 
84  if (trim($HB_ENV["HCUPOST"]["amount"]) == '' || !is_numeric($HB_ENV["HCUPOST"]["amount"])) {
85  $aryErrors[] = $MC->msg('Invalid entry for check amount', HCU_DISPLAY_AS_RAW);
86  } else {
87  $check_amount = number_format($HB_ENV["HCUPOST"]["amount"], 2, '.', '');
88  }
89 
90  if (trim($HB_ENV["HCUPOST"]["account"]) == '' ) {
91  $aryErrors[] = $MC->msg('Please select an account', HCU_DISPLAY_AS_RAW);
92  }
93  list($ck_micr,$ck_acct,$ck_type) = explode("|",$HB_ENV["HCUPOST"]["account"]);
94 
95  list($mm,$dd,$yyyy) = preg_split("#[/-]#",$HB_ENV["HCUPOST"]["date_cleared"]);
96  $mm = intval($mm);
97  $dd = intval($dd);
98  $yyyy = intval($yyyy);
99 
100  $dateTest = strtotime( "$mm/$dd/$yyyy" );
101  if (!$dateTest) {
102  $aryErrors[] = $MC->msg('Invalid Date Format', HCU_DISPLAY_AS_RAW);
103  } else {
104  $check_date = date('m/d/Y', strtotime($HB_ENV["HCUPOST"]["date_cleared"]));
105  }
106 
107  if ( count( $aryErrors ) > 0 ) {
108  throw new Exception (json_encode($aryErrors));
109  } else {
110  $sql = "SELECT img, rt, flagset
111  FROM cuadmin
112  WHERE cu = '$Cu' ";
113 
114  $img_rs = db_query($sql, $dbh);
115 
116  list($img_vendor, $cu_rt, $flagset) = db_fetch_row($img_rs, 0);
117  $img_vendor = trim($img_vendor);
118  $cu_rt = trim($cu_rt);
119  db_free_result($img_rs);
120 
121  // Look for override micr settings applying to this check
122  $check_number = intval($check_number);
123  $use_rt = $cu_rt;
124  $use_micr = $ck_micr;
125 
126  $sql_om = "select trim(rt), trim(micraccount) from cuovermicr
127  where cu='$Cu' and accountnumber='$ck_acct'
128  and accounttype = '$ck_type'
129  and startcheck <= $check_number
130  order by startcheck desc
131  limit 1";
132  $om_rs = db_query($sql_om, $dbh);
133  if(db_num_rows($om_rs) == 1) {
134  list ($use_rt, $use_micr) = db_fetch_row($om_rs, 0);
135  }
136 
137 
138  //Create a CKHASH like $dmskey and CKITEM with all the stuff passed on url and add a CKARCHIVE flag (to both CKHASH and url.
139  //In ImageSOLO decode key based on CKARCHIVE and gather enough info to make the call.
140 
141 // $dmskey=sha1("{$Cu}{$img_vendor}{$check_number}{$check_amount}{$check_date}{$use_rt}{$use_micr}{$Cn}cierto");
142 // $img_url = "https://{$_SERVER['HTTP_HOST']}" .
143 // dirname($_SERVER['PHP_SELF']) . "/ImageSRC"
144 // . "?cu=$Cu&img=$img_vendor&check=$check_number&amount=$check_amount"
145 // . "&date=$check_date&rt={$use_rt}&micr={$use_micr}&dmskey=${dmskey}";
146 
147 # pass micr as $sk (sortkey)
148 # for MidAt clients using tracenumber, not micr, for image retrieval
149 /*
150  * changed 12/19/12 if FEDIMAGE, send check_number; if MAC send check_micr; else send ''
151  * so old legacy hacks for FEDIMAGE and MAC still work without breaking new alternate MICR for
152  * WASATCH / ISUCU
153  *
154  * Apparently lost these changes on the switch from ImageSRC to ImageSOLO (Mammoth upgrade)
155  * but really do need them...
156  */
157 
158  $sk='';
159  if ($img_vendor == 'FEDIMAGE') {
160  $sk = $check_number;
161  } elseif ($img_vendor == 'MAC') {
162  $sk = $use_micr;
163  } else {
164  $sk = '';
165  }
166 
167  $archiveFlag = "2"; // this needs to match in the check in ImageSOLO
168 
169  $infoParts = "$Cu|$img_vendor|$check_number|$check_amount|$check_date|$use_rt|$use_micr|$Cn|$sk";
170  $dmskey=sha1("{$Cu}{$img_vendor}{$check_number}{$check_amount}{$check_date}{$use_rt}{$use_micr}{$archiveFlag}{$Cn}cierto");
171  $ckitem=hcu_encrypturl( $infoParts, $chk_key );
172  $img_url = $HB_ENV['homebankingpath'] . "/ImageSOLO.prg?" . $HB_ENV['cuquery'] . "&CKITEM=$ckitem&CKARCHIVE=2&CKHASH=$dmskey";
173 
174  $aryResult["img_url"] = $img_url;
175  }
176  break;
177  default:
178  $aryErrors[] = array( "message" => "Unexpected action: {$HB_ENV["HCUPOST"]["action"]}" );
179  throw new Exception (json_encode($aryErrors));
180  break;
181  }
182 }
183 catch(Exception $ex)
184 {
185  //Return error message
186  $aryReply["homecuErrors"] = json_decode( $ex->getMessage() );
187 
188  // if an error, don't return data
189  $aryResult = array();
190 
191  // if an error, don't return info
192  $aryInfo = array();
193 }
194 
195  if ( count( $aryResult ) ) $aryReply["homecuData"] = $aryResult;
196 
197  if ( count( $aryInfo ) ) $aryReply["homecuInfo"] = $aryInfo;
198 
199  print json_encode($aryReply);