Odyssey
hcuSetLang.prg
1 <?php
2  /*
3  * Filename: hcuSetLang
4  *
5  * Purpose: This script is used to set the Flang cookie for the homeCU domain.
6  * This script can be executed without the user being logged in, it will
7  * set the cookie from the First Login screen.
8  *
9  * The script does NOT return anything in HTML, it simply set the Flang
10  * cookie, it will be up to the calling script to refresh the page.
11  *
12  * Parameters:
13  * homecuLang - This is the language selection. If the user tries to be clever
14  * and load a false language setting into this field, the hcuService
15  * will ignore the value and simply show English
16  *
17  */
18 
19 $retStatus_ary = Array(
20  'homecuInfo' => '',
21  'homecuErrors' => Array(),
22  'homecuData' => ''
23  );
24 
25 $aryErrors = array();
26 $aryReply = array();
27 $aryInfo = array();
28 
29 try {
30 
31  $serviceShowInfo = false;
32  $serviceLoadMenu = false;
33  $serviceShowMenu = false;
34  $serviceAllowReadonly = true;
35 
36  /**
37  * This can be called prior to login, we want to load the proper HB_ENV, but don't need the Banking Cookie
38  */
39  $serviceSkipCredentials = true;
40  $serviceSkipSecurity = true;
41 
42  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
43  // hcuService will be returning a status object: e.g. ["homecuErrors":{[{"message":"message1"}...{"message":"messageN"}}]
44  require_once(dirname(__FILE__) . '/../library/hcuService.i');
45 
46 
47  $dms_ok = array('homecuLang' => 'string');
48  dms_import_v2($HB_ENV, 'LANGPOST', $dms_ok);
49 
50 
51  if (HCU_array_key_exists('language', $cuSettings)) {
52  $changeLangTo = $HB_ENV['LANGPOST']['homecuLang'];
53 
54  // ** The language element exists in cuSettings
55  if (in_array($changeLangTo, array_keys(HCU_array_key_value('language', $cuSettings)))) {
56  //** Change the language
57  $useCu = $HB_ENV['cu'];
58  // ** CookieName
59  $cookieName = $useCu . '_lang';
60  // ** Cookie Value - This is the language code the user is choosing to use
61  $cookieValue = $_POST['homecuLang'];
62  // ** Cookie Expire - Session Only
63  $cookieExpire = 0;
64 
65  HCU_setcookie_env($HB_ENV['SYSENV'], $cookieName, $cookieValue, $cookieExpire);
66 
67  // ** Everything looks good
68  $retStatus_ary['homecuInfo'] = 'OK';
69 
70  } else {
71  throw new Exception ("Language Code Not Allowed");
72  }
73  } else {
74  throw new Exception ("No Assigned Languages");
75  }
76 
77 
78 } catch(Exception $ex) {
79  //Return error message
80  $retStatus_ary['homecuErrors'] = "FAIL";
81 }
82 
83 header('Content-type: application/json');
84 print json_encode($retStatus_ary);