Odyssey
lnappfunctions.i
1 <?php
2  /*
3  * File: lnappfunctions
4  * Purpose: The purpose of this file is to have the global functions for lnapp
5  * included in one place, but not take up extra room in the AppMain script
6  */
7 /*
8  * SET SOME GLOBAL VALUES
9  *
10  */
11  $MasterKey = 'ndcng/Mwln#TR-3APMkxf68MaFWeaXaD';
12 
13 function StartDMSTag($pStartTag, $pIdx=0, $pMenuVal='') {
14  global $LAYOUT_PAGE, $LAYOUT_GROUP, $LAYOUT_LINE, $CURRENT_LAYOUT, $Build_CSS_Menu, $PAGE_COUNT, $GROUP_COUNT;
15 
16  // * start a new Tag -- CLose any open tags based on the tag that is set to start
17 
18  // Okay, I want to start a new TAG
19  // ** First I want to make sure I close any open tags..
20  for ($idx = $CURRENT_LAYOUT; $idx >= $pStartTag; $idx--) {
21  // * closing each tag may be different for each
22  switch ($idx) {
23  case $LAYOUT_PAGE:
24  // * End div tag
25  print "</div>";
26  break;
27  case $LAYOUT_GROUP:
28  // * End div
29  print "</div><!--form-horizontal --></div><!-- well -->";
30  break;
31  case $LAYOUT_LINE:
32  // * Simple div tag
33  print "</div>";
34  break;
35  }
36  }
37 
38  if ($pIdx >= 0 ) {
39  // ** Start the new tag
40  switch ($pStartTag) {
41  case $LAYOUT_PAGE:
42  print "<div id='securepage$pIdx' class='noshow'>";
43  break;
44  case $LAYOUT_GROUP:
45  print "<div class='well well-sm col-xs-12 groupgo_{$GROUP_COUNT}'><div class='form-horizontal'>";
46  break;
47  case $LAYOUT_LINE:
48  print "<div class='newrow'>";
49  break;
50  }
51  }
52  $CURRENT_LAYOUT = $pStartTag;
53 
54 
55 
56  // ** Do something similar for the DMS Menu
57  for ($idxMenu = $CURRENT_LAYOUT; $idxMenu >= $pStartTag; $idxMenu--) {
58  switch ($idxMenu) {
59  case $LAYOUT_PAGE:
60 
61  if ($Build_CSS_Menu != '') {
62  $Build_CSS_Menu .= "</ul></li>";
63  }
64  break;
65  case $LAYOUT_GROUP:
66 
67  break;
68  }
69  if ($idxMenu >= 0 && $pMenuVal != '') {
70  switch ($pStartTag) {
71  case $LAYOUT_PAGE:
72  $Build_CSS_Menu .= "<li class='' data-rowid=''><a class='' href='#' target=''><div id='pghdr_{$PAGE_COUNT}' title='$pMenuVal'>$pMenuVal</div></a><ul class='nav nav-second-level collapse in'>";
73  break;
74  case $LAYOUT_GROUP:
75  $Build_CSS_Menu .= "<li id='group_{$GROUP_COUNT}'><a href='#groupgo_{$GROUP_COUNT}' id='page{$PAGE_COUNT}'><i class='fa fa-long-arrow-right local-menu-error' aria-hidden='true'></i>$pMenuVal</a></li>";
76  break;
77  }
78  }
79  }
80 
81  }
82 
83 //* Load_AnswerList -- Load the answer list into an array
84 function Load_AnswerList ($p_ansid) {
85  global $DB_TABLE_PREFIX, $App_AnswerDetail, $dbh;
86  // ** First determine if I already have some answers listed in the array.
87  // * my goal is to populate an array with the values because some forms may
88  // * utitlize the same options more than once. and then I would only query
89  // * the database once for each answer set
90 
91  $sql = "SELECT *
92  FROM {$DB_TABLE_PREFIX}anslookupdetail
93  WHERE ansid = " . intval($p_ansid) . "
94  ORDER BY ansdisplay ";
95 
96  $ans_rs = db_query($sql, $dbh);
97 
98  $ansid = 0;
99 
100  /*
101  *
102  * Add a blank option if one is NOT provided from the database
103  * The query MUST be ordered by text where the blank is expected first
104  *
105  */
106  $ansIdx = 0;
107  while ($ans_row = db_fetch_array($ans_rs, $ansid)) {
108  $ansIdx++;
109 
110  if ($ansIdx == 1 && trim($ans_row['ansvalue']) != '') {
111  // * FIRST ROW -- VALUE in DB
112  // * ADD BLANK ROW
113  $App_AnswerDetail[$p_ansid][''] = '';
114  }
115  $App_AnswerDetail[$p_ansid][$ans_row['ansvalue']] = $ans_row['ansdisplay'];
116  $ansid++;
117 
118  }
119  if ($ansid == 0){
120  // -- no rows were added so I need to record something here for that
121  $App_AnswerDetail[$p_ansid] = "NO ROWS";
122  }
123 
124 }
125 
126 function Display_AnswerList($p_ansid, $p_fieldname, $p_displaytype, $p_fieldlabel, $p_returndisplayof = "", $p_setdefaultval = "", $p_valueconditionalname='', $p_fieldclass='') {
127  global $App_AnswerDetail, $GROUP_COUNT;
128  // * this will display the answer list in either a SELECT or RADIO option
129 
130  // $p_returndisplayof -- If this is set, the function will ONLY return the
131  // display value of the particlur field instead of returning a <SELECT>or <INPUT> code
132 
133  if (!isset($App_AnswerDetail[$p_ansid])) {
134  // ** Send to load the answer
135  Load_AnswerList($p_ansid);
136  }
137  // ** If there were rows then insert the data -- OR test to see if it is an array...
138  $Answer_Field = "";
139 
140  // ** For first row, set the ID for a radio with the p_fieldname
141  $radio_id_value = " id='{$p_fieldname}' ";
142  if ($App_AnswerDetail[$p_ansid] != "NO ROWS") {
143  foreach ($App_AnswerDetail[$p_ansid] as $Ans_key => $Ans_value) {
144  if ($p_returndisplayof == '') {
145  $default_val = "";
146  switch($p_displaytype) {
147  case "S":
148  $default_val = ($p_setdefaultval != '' && $Ans_key == $p_setdefaultval ? " SELECTED " : "");
149  $Answer_Field .= "<option value='$Ans_key' $default_val>$Ans_value</option>";
150  break;
151  case "R":
152  // * *FOR RADIO OPTIONS, DO NOT INCLUDE if ans_key and ans_value are blank
153  if ($Ans_key != '' && $Ans_value != '') {
154  $default_val = ($p_setdefaultval != '' && $Ans_key == $p_setdefaultval ? " CHECKED " : "");
155 
156  $Answer_Field .= <<< APP_AR
157  <label class="radio-inline">
158  <input type='radio' group='group_{$GROUP_COUNT}' id='{$p_fieldname}' {$default_val} name='{$p_fieldname}' {$p_valueconditionalname} value='{$Ans_key}'/> {$Ans_value}
159  </label>
160 APP_AR;
161  $radio_id_value = ''; // SET id value to empty, so no others are set
162  }
163  break;
164 
165  }
166  } else {
167  // * Check to see if the value is the same
168  if ($Ans_key == $p_returndisplayof) {
169  $Answer_Field = $Ans_value;
170  break;
171  }
172  }
173  }
174  if ($p_displaytype == "S" && $p_returndisplayof == '') {
175  $Answer_Field = "<select class='$p_fieldclass' data-role='dropdownlist' id='$p_fieldname' name='$p_fieldname' class='t' style='width: 100%' title='$p_fieldlabel' {$p_valueconditionalname}>$Answer_Field</select>";
176 
177  }
178  }
179  return $Answer_Field;
180 }
181 
182 /**
183  * Encrypt a value using openssl_encrypt
184  *
185  * @param string $data - String to be encrypted
186  * @param string $key - Key used for encryption
187  * @param string $method - Default (AES-256-CBC) - One of the allowed php cipher methods
188  *
189  * @return string Base 64 encoded encrypted string
190  */
191 function encrypt($data, $key, $method='AES-256-ECB') {
192 
193  $ivSize = openssl_cipher_iv_length($method);
194  $iv = openssl_random_pseudo_bytes($ivSize);
195 
196  $encrypted = openssl_encrypt($data, $method, $key, OPENSSL_RAW_DATA, $iv);
197 
198  // For storage/transmission, we simply concatenate the IV and cipher text
199  $encrypted = base64_encode($iv . $encrypted);
200 
201  return $encrypted;
202 
203 }
204 
205 /**
206  * Decrypt a value using openssl_decrypt
207  *
208  * @param string $data - String to be decrypted
209  * @param string $key - Key used for encryption
210  * @param string $method - Default (AES-256-CBC) - One of the allowed php cipher methods
211  *
212  * @return string Base 64 encoded encrypted string
213  */
214 function decrypt($data, $key, $method='AES-256-ECB') {
215  $data = base64_decode($data);
216  $ivSize = openssl_cipher_iv_length($method);
217  $iv = substr($data, 0, $ivSize);
218  $data = openssl_decrypt(substr($data, $ivSize), $method, $key, OPENSSL_RAW_DATA, $iv);
219 
220  return $data;
221 }
222 
223 function Check_Credentials() {
224  global $DB_TABLE_PREFIX, $DMSAPP_USERID_CookieString, $MasterKey, $dbh, $DMSAPP_CURRENTCUCODE, $DMSAPP_SECRET_KEY;
225  $ret_user = "";
226  $ret_email = "";
227  $ret_status = false;
228  $l_cookieval_ary = array();
229 
230  //*** THIS FUNCTION ASSUMES FAIL UNTIL THE INFORMATION IS AUTHENTICATED -- ALL ELSE STATEMENTS ASSUME FALSE
231 
232  // ** This will check the credentials for the current user.. they will be sent
233  // * to the intro page if the cookie does not exist..
234 
235  if (isset($_COOKIE[$DMSAPP_USERID_CookieString])) {
236  // ** COOKIE IS SET --- EXPLODE OUT THE PIECES THAT ARE HERE..
237 
238  parse_str($_COOKIE[$DMSAPP_USERID_CookieString], $l_cookieval_ary);
239  $l_user = trim(decrypt($l_cookieval_ary['C1'], $MasterKey));
240 
241  if (intval($l_user) != $l_user) {
242  // ** Be sure l_user matches what was decrypted.. if not then fail
243  $l_user = -1;
244  } else {
245  $l_user = intval($l_user);
246  }
247  /*
248  print_r($l_cookieval_ary);
249  print "<BR>C1 - " . $l_cookieval_ary['C1'];
250  print "<br>" . encrypt($l_user, $MasterKey);
251  print "<br>::$l_user::";
252  print "<br/>Secret key :: $DMSAPP_SECRET_KEY";
253  print "<Br>" . sha1($DMSAPP_SECRET_KEY . $l_cookieval_ary['C1'] . $l_cookieval_ary['C2'] . $l_cookieval_ary['C3']);
254  $l_exptime = 999999999;
255  */
256 
257  // ** Now authenticate the information looks correct -- by taking pieces and recreating the hashed value, if they are the same, then we are good
258  // ** The decrypted user id MUST be an integer..
259  if ((sha1($DMSAPP_SECRET_KEY . $l_cookieval_ary['C1'] . $l_cookieval_ary['C2'] . $l_cookieval_ary['C3']) == $l_cookieval_ary['C4'])) {
260  // * DO I dare do a check here to see if the user is real...
261  // * Do I now check the contents of the DEVICE cookie.. to ensure
262  // it is correct??
263  $sql = "SELECT *
264  FROM {$DB_TABLE_PREFIX}user
265  WHERE userid = " . intval($l_user);
266  $user_rs = db_query($sql, $dbh);
267 
268  if ($user_row = db_fetch_array($user_rs)) {
269  // Fetch the information needed to rebuild the Device Cookie and
270  //
271  $ret_user = $l_user;
272  $l_email = trim($user_row['email']);
273  $l_banking_user_id = trim($user_row['banking_user_id']);
274  $l_pwd = trim($user_row['pwd']);
275  $l_confword = trim($user_row['confidenceword']);
276 
277  $l_device_cookie_name = ReturnDeviceCookieName($DMSAPP_CURRENTCUCODE, $l_cookieval_ary['C3'], $l_email, $ret_user);
278 
279  if (isset($_COOKIE[$l_device_cookie_name])) {
280  // ** Now rebuild the COOKIE VALUE AND MATCH WITH THE VALUE IN COOKIE
281  //$l_CookieVal = sha1($DMSAPP_SECRET_KEY . $l_pwd . $l_email . $l_confword . $l_username);
282  $l_CookieVal = sha1($DMSAPP_SECRET_KEY . $l_pwd . $l_email . $l_confword . $l_banking_user_id);
283 
284  if ($l_CookieVal == $_COOKIE[$l_device_cookie_name]) {
285  // The information IS Correct...
286  // Wonder if I should set email here as well..
287 
288  $ret_email = $l_email;
289 
290  // ** LASTLY CHECK THE TIME is still good
291  if (time() < $l_cookieval_ary['C2']) {
292  $ret_status = true;
293  } // !! ELSE FAIL {TIME EXPIRED}
294 
295  }
296  } // !! ELSE FAIL {DEVICE COOKIE NOT FOUND}
297  } // !! ELSE FAIL {USER NOT FOUND}
298  } // !! ELSE FAIL {TICKET CONTENTS CORRUPT}
299 
300  } // !! ELSE FAIL
301 
302 
303  return Array($ret_status, $ret_user, $ret_email, $l_cookieval_ary['C3']);
304 }
305 
306 function ReturnDeviceCookieName($p_cucode, $p_logintype, $p_email, $p_userid) {
307  global $DB_TABLE_PREFIX;
308  return sha1("{$DB_TABLE_PREFIX}{$p_cucode}Tu0geethSaith7ch{$p_logintype}{$p_email}{$p_userid}");
309 }
310 
311 function SetLnappDeviceCookie($p_hb_env, $p_cookiename, $p_cookieval, $pSessionCookie = false) {
312  global $DMSAPP_Device_Cookie_ExpireTime, $DMSAPP_Cookie_Domain;
313 
314  $cooked_exp = $pSessionCookie ? 0 : time() + $DMSAPP_Device_Cookie_ExpireTime; // Expire the time using the configurable option
315 
316  // ** Later can use the option for httponly -- this limits certain browsers
317  // * from allowing scripting languages access to the cookie
318 
319  HCU_setcookie_env($p_hb_env['SYSENV'], $p_cookiename, $p_cookieval, $cooked_exp);
320 }
321 // ** DMSAppSetCookie
322 // ** This function will be my standard function to set the cookie.. At this time
323  // * it is located in the usermaint but it may need to be put into the AppMain
324  // * file
325  // * Cookie will be valid for 30 minutes at this time
326 function DMSAppSetCookie($p_hb_env, $userid, $p_logintype, $p_ForceExpired = false) {
327 
328  global $MasterKey, $DMSAPP_Cookie_ExpireTime, $DMSAPP_USERID_CookieString, $DMSAPP_Cookie_Domain, $DMSAPP_SECRET_KEY;
329 
330 // $cooked_val = encrypt($userid, $MasterKey);
331 // $cooked_exp = time() + 60 * $DMSAPP_Cookie_ExpireTime; // Expire the time using the configurable option
332  $l_uid = encrypt($userid, $MasterKey);
333 
334  if (!$p_ForceExpired) {
335  $l_exptime = time() + (60 * $DMSAPP_Cookie_ExpireTime); // Expire the time using the configurable option
336  } else {
337  $l_exptime = time() - 60;
338  }
339 
340 
341  // * values being saved on the cookie are
342  // * C1 - The user ID
343  // * C2 - The Expiring time
344  // * C3 - User Login Type {H,L} HomeBanking/LoanApp
345  // * C4 - an sha1 hash of the values PLUS the DMS SECRET KEY
346  $cooked_val = "C1=" . urlencode($l_uid) . "&C2=$l_exptime&C3=$p_logintype&C4=" . sha1($DMSAPP_SECRET_KEY . $l_uid . $l_exptime . $p_logintype);
347 
348  // ** Later can use the option for httponly -- this limits certain browsers
349  // * from allowing scripting languages access to the cookie
350 // setcookie($DMSAPP_USERID_CookieString, $cooked_val, $cooked_exp, "/", $DMSAPP_Cookie_Domain, 1);
351 
352  // ** -- Purpose is to be similar to what is being done in home banking.. Create a cookie that
353  // * Contains the needed information in the cookie, however at the same time I want to create
354  // * the cookie to exist as long as the user does NOT close the browser. so if they time out
355  // * they immediately end up at the password screen again..
356 
357  HCU_setcookie_env($p_hb_env['SYSENV'], $DMSAPP_USERID_CookieString, $cooked_val);
358 }
359 
360 // If the cookie is still valid then reset the expiration time.
361 function DMSAppCookieResetTimer($p_hb_env) {
362  global $DMSAPP_Cookie_Domain, $DMSAPP_USERID_CookieString, $DMSAPP_Cookie_ExpireTime, $MasterKey, $DMSAPP_SECRET_KEY;
363 
364  // ** This will check the credentials for the current user.. they will be sent
365  // * to the intro page if the cookie does not exist..
366 
367  if (isset($_COOKIE[$DMSAPP_USERID_CookieString])) {
368  // ** COOKIE IS SET --- EXPLODE OUT THE PIECES THAT ARE HERE..
369 
370  $l_cookieval_ary = array();
371  parse_str($_COOKIE[$DMSAPP_USERID_CookieString], $l_cookieval_ary);
372  $l_user = trim(decrypt($l_cookieval_ary['C1'], $MasterKey));
373 
374  if (intval($l_user) == $l_user) {
375  $l_user = intval($l_user);
376  }
377 
378  // ** Now authenticate the information looks correct -- by taking pieces and recreating the hashed value, if they are the same, then we are good
379  // ** The decrypted user id MUST be an integer..
380  if ((sha1($DMSAPP_SECRET_KEY . $l_cookieval_ary['C1'] . $l_cookieval_ary['C2'] . $l_cookieval_ary['C3']) == $l_cookieval_ary['C4'])) {
381  // also
382  if (time() < $l_cookieval_ary['C2']) {
383  $l_exptime = time() + (60 * $DMSAPP_Cookie_ExpireTime); // Expire the time using the configurable option
384  $newC4 = sha1($DMSAPP_SECRET_KEY . $l_user . $l_exptime . $p_logintype);
385 
386  $reBakedVal = "C1={$l_cookieval_ary['C1']}&C2=$l_exptime&C3={$l_cookieval_ary['C3']}&C4=" . $newC4;
387 
388  setcookie($DMSAPP_USERID_CookieString, $reBakedVal, 0, "/", $DMSAPP_Cookie_Domain, 1);
389  }
390  }
391  }
392 
393  return;
394 }
395 
396 function Disclosure_Exists($p_LoanID = -1, $p_RespID = -1) {
397  global $dbh, $DMSAPP_CUHOME_PATH;
398  // ** Purpose - This function will determine if a Disclosure exists for a specific loan
399  // * it can look up a disclosure by either the LoanID or by the RespID from the
400  // * lnappuserresponse table.
401  // * It will lookup the disclosure name from the lnappschemaheader table and
402  // * and then verify the file exists on the File System.
403 
404  // ** Parameters - p_LoanID - The LoanID from the lnappschemaheader table
405  // p_RespID - The RespID from the lnappuserresponse table
406  // ** Returns: This function will return a {True/False} boolean
407 
408  $l_Return = False; // * I will assume False UNTIL FOUND
409 
410  if ($p_LoanID >= 0 || $p_RespID >= 0) {
411  // ** Determine the query to use to lookup
412  $sql = "";
413  if ($p_LoanID >= 0) {
414  $sql = "SELECT loandisclosure_fragment
415  FROM lnappschemamaster
416  WHERE loanid = " . intval($p_LoanID) . " ";
417  } elseif ($p_RespID >= 0) {
418  $sql = "SELECT loandisclosure_fragment
419  FROM lnappschemamaster
420  JOIN lnappuserresponse on lnappuserresponse.loanid = lnappschemamaster.loanid
421  WHERE respid = " . intval($p_RespID) . " ";
422  }
423  $disc_rs = db_query($sql, $dbh);
424  list($disc_filename) = db_fetch_array($disc_rs);
425 
426  if (trim($disc_filename) != '') {
427  // * *NOW LOOK UP THE FILE to see if it exists
428  if (file_exists($DMSAPP_CUHOME_PATH . $disc_filename)) {
429  // ** FILE EXISTS -- SO I WILL BE SHOWING
430  $l_Return = True;
431  }
432  }
433  } else {
434  // * NEITHER value is set... why??
435  $l_Return = False;
436  }
437 
438 
439  return $l_Return;
440 }
441 function SetAppMode($p_dbh, $p_cu, $p_dmsapp_online, $p_allowReadonly) {
442 
443  $retMode = Array("offline" => false, "offlineReadonly" => false, "offlineDesc" => "The loan application is currently offline. Please check back later.");
444  // ** Need to retrieve the Offline status from the core
445  $sql = "SELECT offlinestat, offlineblurb
446  FROM cuadmin
447  WHERE cu = '{$p_cu}'; ";
448 
449  if ($off_rs = db_query($sql, $p_dbh)) {
450  $off_row = db_fetch_assoc($off_rs, 0);
451  $curOfflineStat = $off_row['offlinestat'];
452  $retMode['offlineDesc'] = $off_row['offlineblurb'];
453 
454  // ** Allow ReadOnly should only be set for certain scripts
455  $setArray = array('Cu'=>$p_cu, 'offline'=>$curOfflineStat, 'live'=>$GLOBALS['DMSAPP_CULIVE'], 'allowReadonly'=>$p_allowReadonly);
456  $retMode['offline'] = hcu_checkOffline($p_dbh, $setArray);
457 
458  // ** offline Readonly is to help me to identify if the credit union is offline for readonly mode
459  // ** some scripts I will have different permissions. I will allow the script as a whole to be executed
460  // ** however, I will NOT let them do certain features for READONLY
461  $retMode['offlineReadonly'] = ($curOfflineStat == "R");
462  }
463 
464  // offline
465  // ** true -- Continue with the script, we are either "live/batch" and online OR
466  // batch -- readonly and this script allows readonly access
467  // ** false -- do NOT continue with "live" actions, such as application submits
468 
469  return $retMode;
470 }
471 
472 function RefreshCookie($p_hb_env) {
473  global $DMSAPP_CURRENTUSERID, $DMSAPP_CURRENTEMAIL, $DMSAPP_LOGINTYPE;
474 
475  // ** GUILTY!! unless proven INNOCENT
476  $Refresh_Return = "False";
477 
478  // ** GET THE COOKIE --
479  list($check_status, $check_user, $check_email, $check_logintype) = Check_Credentials();
480  if (intval($check_user) == $check_user) {
481  $DMSAPP_CURRENTUSERID = $check_user;
482  $DMSAPP_CURRENTEMAIL = strtolower($check_email);
483  $DMSAPP_LOGINTYPE = $check_logintype;
484 
485  if ($check_status) {
486  // ** THE CREDENTIALS ARE VALID -- EXTEND THE COOKIE
487  DMSAppSetCookie($p_hb_env, $DMSAPP_CURRENTUSERID, $DMSAPP_LOGINTYPE);
488  $Refresh_Return = "True";
489  }
490  }
491 
492  return $Refresh_Return;
493 } // end RefreshCookie
494 
495 /**
496  * Get all the loans associated with a specified user.
497  *
498  * @param array pHbEnv - The current environment array
499  * @param integer pUserId - Loan User Id associated to the search
500  *
501  * @return array
502  * [code] -- {000, 999}
503  * [error] -- * optional
504  * [data] -- array of array
505  * [LoanRespId] - Response Id for this User Loan
506  * [LoanType] - Loan Description
507  * [LoanName] - Loan Name
508  * [LoanStartOn] - Loan Started On
509  * [LoanSubmitOn] - Loan Submitted On
510  * [CuLoanStatus] - Loan Response Status
511  * [CuLoanResp] - Loan Response Status Desc
512  * [CuLoanId] - Loan Response Core Id
513  * [LoanDispStatus] - Loan Display Response
514  * [LoanAction] -- What actions can be taken against this loan
515  * [edit] - can the loan be viewed
516  * [delete] - can the loan be deleted
517  * [view] - can the loan be viewed/printed
518  */
519 function GetAllUserLoans($pHbEnv, $pUserId) {
520 
521 /*
522  * // ** This has not been submitted -- Allow Edit
523  if (($DMSAPP_CULIVE) || (!$DMSAPP_CULIVE && !($DMSAPP_MODE_ARY['offline'] && $DMSAPP_MODE_ARY['offlineReadonly'])) ) {
524  // ** DO NOT ALLOW EDITING if Batch and readonly, which is only way to get here.. I think..
525  $row_Action = "<a href='$self_full_url?f=entry&load=" . disp_text($resp_row['respid']) . "' title='Edit Application'><img src='{$http_script_path}images/appedit.png' class='icons' /></a>";
526 
527  $row_Action .= "&nbsp;<a href='$self_full_url?f=loandelete&remove=" . disp_text($resp_row['respid']) . "' title='Delete Application'><img src='{$http_script_path}images/apptrash.png' class='icons' /></a>";
528  }
529  $row_Action .= "&nbsp;<a href='$self_full_url?f=viewapplication&viewapp=" . disp_text($resp_row['respid']) . "' target='_blank' title='View Application'><img src='{$http_script_path}images/appinfo.png' class='icons' /></a>";
530 */
531 
532  global $DMSAPP_CULIVE, $DMSAPP_MODE_ARY;
533 
534 
535  $retVal = Array("code" => "000", "data" => Array());
536  try {
537  $dbh = HCU_array_key_value('dbh', $pHbEnv);
538 
539  if (db_connection_status($dbh) !== PGSQL_CONNECTION_OK) {
540  throw new Exception ("Database Error");
541  }
542  /* * GENERATE QUERY * */
543  $sql = "SELECT userresponse.*, schemamaster.loantitle,
544  to_char(userresponse.respstarton,'MM/DD/YYYY HH12:MI') as user_startedon,
545  to_char(userresponse.respsubmiton,'MM/DD/YYYY HH12:MI') as user_submiton,
546  trim(userresponse.resplname) || ', ' || trim(userresponse.respfname) || ' ' || userresponse.respmname as name,
547  case when resplastinquire + interval '5' minute < now() then 'T' else 'F' end as inquire
548  FROM {$pHbEnv['DB_TABLE_PREFIX']}userresponse as userresponse
549  JOIN {$pHbEnv['DB_TABLE_PREFIX']}schemamaster as schemamaster
550  ON schemamaster.loanid = userresponse.loanid
551  WHERE userid = " . intval($pUserId) . "
552  ORDER BY respstarton desc ";
553 
554 // echo $sql;
555  $resp_rs = db_query($sql, $dbh);
556 
557 
558  /*
559  * PROCESS EACH ROW
560  */
561  $resp_cnt = 0;
562 
563  while ($resp_row = db_fetch_array($resp_rs, $resp_cnt)) {
564  $resp_cnt++; // Increment for next row
565 
566  $dataRow = Array(); // * Reset row array
567  /*
568  if ($resp_cnt == 1) {
569  // ** FOR THE FIRST ROW start with the header table informaiton
570  print "
571  <h4 class='divTableCaption'>Current Loan Applications</h4>
572  <div class='divTableHeadRow'>
573  <div class='divTableCell'><h5 class='divTableColHdr'>Action&nbsp;</h5></div>
574  <div class='divTableCell2'><h5 class='divTableColHdr'>Loan For&nbsp;</h5></div>
575  <div class='divTableCell2'><h5 class='divTableColHdr'>Loan Type</h5></div>
576  <div class='divTableCell'><h5 class='divTableColHdr'>Started On</h5></div>
577  <div class='divTableCell'><h5 class='divTableColHdr'>Submitted On</h5></div>
578  <div class='divTableCell2'><h5 class='divTableColHdr'>Loan Status</h5></div>
579  <!-- <div class='divTableCell2'><h5 class='divTableColHdr'>Submit Response</h5></div>
580  </div>
581  <div class='divTableHeadRow'>
582  <div class='divTableCell'><h5 class='divTableColHdr'>CU Loan ID</h5></div>-->
583  </div> "; // ** END THE TABLE CREATION and header row
584  }
585  */
586  $dataRow['LoanRespId'] = intval($resp_row['respid']);
587  $dataRow['LoanId'] = intval($resp_row['loanid']);
588  $dataRow['LoanType'] = disp_text($resp_row['loantitle']);
589  $dataRow['LoanName'] = disp_text($resp_row['name']);
590  $tempName = disp_text($resp_row['resplname']) . ', ' . disp_text($resp_row['respfname']) . ' ' . disp_text($resp_row['respmname']);
591  $dataRow['LoanName'] = (strlen(trim($tempName)) > 1 ? $tempName : '');
592  $dataRow['LoanStartOn'] = disp_text($resp_row['user_startedon']);
593  $dataRow['LoanSubmitOn'] = disp_text($resp_row['user_submiton']);
594 
595  $dataRow['CuLoanStatus'] = disp_text($resp_row['respstatus']);
596  $dataRow['CuLoanResp'] = disp_text($resp_row['respstatusdesc']);
597 
598  $dataRow['CuLoanId'] = (disp_text($resp_row['respcoreloanappid']) == -1 ? "" : disp_text($resp_row['respcoreloanappid']));
599  $dataRow['LoanAction'] = Array("edit" => false,
600  "delete" => false,
601  "view" => false);
602 
603  // * Based on the submitted date, it will either allow editing OR print summary
604  $row_Action = "";
605  if (!isset($row_SubmitOn) || $row_SubmitOn == "") {
606  // ** This has not been submitted -- Allow Edit
607  if (($DMSAPP_CULIVE) || (!$DMSAPP_CULIVE && !($DMSAPP_MODE_ARY['offline'] && $DMSAPP_MODE_ARY['offlineReadonly'])) ) {
608 
609  $dataRow['action']['edit'] = true;
610  $dataRow['action']['delete'] = true;
611 
612  // ** DO NOT ALLOW EDITING if Batch and readonly, which is only way to get here.. I think..
613  // $row_Action = "<a href='$self_full_url?f=entry&load=" . $dataRow['LoanRespId'] . "' title='Edit Application'><img src='{$http_script_path}images/appedit.png' class='icons' /></a>";
614 
615  // $row_Action .= "&nbsp;<a href='$self_full_url?f=loandelete&remove=" . $dataRow['LoanRespId'] . "' title='Delete Application'><img src='{$http_script_path}images/apptrash.png' class='icons' /></a>";
616  }
617  $dataRow['action']['view'] = true;
618 
619  // $row_Action .= "&nbsp;<a href='$self_full_url?f=viewapplication&viewapp=" . $dataRow['LoanRespId'] . "' target='_blank' title='View Application'><img src='{$http_script_path}images/appinfo.png' class='icons' /></a>";
620  } else {
621  $dataRow['action']['view'] = true;
622  // ** This has been submitted -- ONLY ALLOW Print
623  // $row_Action = "<a href='$self_full_url?f=viewapplication&viewapp=" . $dataRow['LoanRespId'] . "' target='_blank' title='View Application'><img src='{$http_script_path}images/appinfo.png' class='icons' /></a>";
624 
625  // ** For certain loan statuses I want to requery the core for possible loan status update
626  // ** ONLY 026 -- Loan App Pending
627  // * First check to verify it has been about 5 minutes
628  // * values are T for it has been 5 minutes or F if it has not
629  if ($resp_row['inquire'] == 'T' && $DMSAPP_ONLINE && $DMSAPP_MODE_ARY['offline']) {
630 
631  if ((strpos(":" . $dataRow['CuLoanStatus'] . ":", ":026:") !== false) && ($dataRow['LoanId'] > 0)) {
632  list($inq_status, $inq_desc) = InquireApplication($dataRow['LoanRespId'], $dataRow['LoanId']);
633  // $inq_status = $resp_row['respstatus'];
634  // * if the descriptions do not match then do the next part
635  //
636  //** ALWAYS SET THE LAST INQUIRE -- SO WE DON't OVER DO SUBMITTING TO CORE
637  // ** REMOVE COMMENT
638  // ** 999 was found -- the application was ALREADY submitted once to get the 000 or 026
639  // * status .. but if we now have gotten here and the status returned is 999
640  // * then the throtlpkt did NOT update the record with the resplastinquire and
641  // * I will do that here
642  $sql = "UPDATE {$DB_TABLE_PREFIX}userresponse
643  SET resplastinquire = now()
644  WHERE respid = " . $dataRow['LoanRespId'] . "
645  AND userid = " . intval($pHbEnv['Uid']) . " ";
646 
647  $upd_rs = db_query($sql, $dbh);
648 
649  if (trim($inq_status) != trim($resp_row['respstatus'])) {
650  // ** If the descriptions changed, tehn use the one from the inquire app funciton
651  $dataRow['CuLoanStatus'] = $inq_status;
652  $dataRow['CuLoanResp'] = disp_text($inq_desc);
653 
654  }
655  }
656  }
657  if ($dataRow['CuLoanResp'] != '') {
658  // $row_CULoanResp_Img = "<a href='#' class='popup' title='$row_CULoanResp'><img src='{$http_script_path}images/appnote.png' class='icons'/></a>";
659  }
660 
661  switch ($dataRow['CuLoanStatus']) {
662  case "000":
663  $row_DisplayStatus = "Received";
664  break;
665  case "020":
666  // ** SUBMIT ERROR - Missing Field
667  case "021":
668  // ** SUBMIT ERROR - Invalid Member #
669  case "022":
670  // ** SUBMIT ERROR - Member # and SSN mismatch
671  $row_DisplayStatus = "Submit Error";
672  break;
673  // ** 025, 026, 027, 028, 029 -- are relevent to an INQAPP request
674  case "025":
675  // ** Invalid Application ID
676  // *nothing to do right now for this..
677  break;
678  case "027":
679  // ** Application Approved -_ NEED APPROVAL DATE
680  $row_DisplayStatus = "Approved";
681  case "028":
682  // ** Application Rejected -- NEED REJECTED DATE
683  $row_DisplayStatus = "Rejected";
684  case "026":
685  // ** Application Pending
686  $row_DisplayStatus = "Pending";
687  break;
688  case "029":
689  // ** Application Submitted -- Needs further review
690  case "030":
691  // ** Application Submitted -- Contact Credit Union for additional information
692  $row_DisplayStatus = "Submitted";
693  }
694  $dataRow['CuLoanResp'] = $row_DisplayStatus;
695  }
696  // ** Append new row
697  $retVal['data'][] = $dataRow;
698  }
699  } catch (Exception $e) {
700  $retVal['code'] = '999';
701 
702  }
703 
704  /* RETURN ARRAY */
705  return $retVal;
706 }
707 
708 
709 /**
710  * GetClassPropertyVal
711  *
712  * This will return a property of a class object, but only if it is set.
713  * Adding this to help when json is decoded into a class object.
714  *
715  * @param object $objVal - The object in question
716  * @param string $property - The object propert we want
717  *
718  * @return mixed
719  * false - the property does not exist
720  * else - the value of the property of the object
721  */
722 function GetClassPropertyVal($objVal, $property) {
723  $bolRet = false;
724 
725  if (is_object($objVal)) {
726  if (property_exists($objVal, $property)) {
727  $bolRet = $objVal->{$property};
728  }
729  }
730 
731  return $bolRet;
732 }
733 
734 /**
735  * This function will verify the specified user has LOAN account access for the
736  * specified account.
737  * It will use the Banking function Get_FeatureAccounts to retrieve the list
738  * and verify the account is one of the valid options
739  *
740  * @param object $pHbEnv - The Session Environment options
741  * @param integer $pUserId - The banking user id to verify
742  * @param string $pSelAcct - The selected account for the user
743  * @param string $pPlatform - Character: D(esktop), M(obiile), A(pp)
744  *
745  * @return boolean
746  * true - Valid Account
747  * false - Invalid Account
748  */
749 function VerifyUserAccountAccessForLoan($pHBEnv, $pUserId, $pSelAcct) {
750 
751  $pHBEnv['Uid'] = $pUserId;
752 
753  $pUsePlat = ($pHBEnv['platform'] == "MBL" ? "M" : "D");
754  $acctList = Get_FeatureAccounts( $pHBEnv, "LOAN", $pUsePlat );
755 
756  return (in_array($pSelAcct, $acctList) !== false);
757 
758 }
759