Odyssey
aMemberSupport.i
1 <?php
2 /**
3  * Reply:
4  * @uses return data to client view print to json
5  * @param assoc $pResult: array contining results of search
6  * @param assoc $pReply: empty array to return to client
7  * @param assoc $pOperation: requested search operation
8  */
9 function MemberReply($pResult, $pReply, $pOperation) {
10  $pReply['operation'] = $pOperation;
11  if (isset($pResult['data']) && count($pResult['data'])) $pReply['data'] = $pResult['data'];
12  if (isset($pResult['info']) && count($pResult['info'])) $pReply['info'] = $pResult['info'];
13 
14  print json_encode(array("Results" => $pReply));
15 }
16 
17 /**
18  * MemberContext:
19  * @uses create a context array holding any needed data for a member hub
20  * card function.
21  *
22  * @param $pEnv array: $pEnv array: evironment object for debugging
23  * @param $pCu string: cu code used for accessing variables and database tables
24  * @param $member string | array: possible needed member values for member hub
25  * functions.
26  *
27  * @return $vContext array: array of member hub function data
28  */
29 function MemberContext($pEnv, $pCu, $pMember = null) {
30  $mCu = prep_save($pCu, 20);
31 
32  $mContext = array(
33  "cu_table" => strtolower($mCu),
34  "cu_code" => strtoupper($mCu),
35  "m_account" => $pMember ? ( isset($pMember['m_account']) ? prep_save($pMember['m_account'], 12) : null ) : null
36  );
37 
38  return $mContext;
39 }
40 
41 /**
42  * MemberValidate:
43  * @uses validate the json string of parameters submitted by the user.
44  * this function will prepare the data for submission to the database (if needed).
45  *
46  * @param $pEnv array: evironment object for debugging
47  * @param $pParameters string: json string of field/value pairs from user submitted
48  * form.
49  *
50  * @return $vParameters array: array of data valid for use in the database
51  */
52 function MemberValidate($pEnv, $pParameters, $pJson = false) {
53  $mParameters = $pParameters;
54  $mValidate = array();
55  // if parameters are in json string form
56  // decode into array
57  if ($pJson) {
58  $mParameters = html_entity_decode($pParameters, ENT_QUOTES);
59  $mParameters = HCU_JsonDecode($mParameters);
60  }
61 
62  // validate member parameter if available
63  if (isset($mParameters['m_account'])) {
64 
65  $mAccount = $mParameters['m_account'];
66  $mAccount = strtolower($mAccount);
67  $mAccount = prep_save($mAccount, 12);
68  $mAccount = preg_replace('/[^0-9]/', "", $mAccount);
69  $mAccount = trim($mAccount);
70 
71  $mValidate['m_account'] = $mAccount;
72  }
73 
74  return $mValidate;
75 }
76 
77 /**
78  * MemberSelect:
79  * @uses select a member by specific parameters, for now select only by
80  * member accountnumber stored in the context variable.
81  *
82  * @param $pEnv array: evironment object for debugging
83  * @param $pDbh object: database access variable
84  * @param $pContext array: array of data needed for multiple member hub functions:
85  * in this case the member accountnumber.
86  *
87  * @return $sqlReturn array: single data row, the selected member
88  */
89 function MemberSelect($pEnv, $pDbh, $pContext) {
90  $cuTable = $pContext['cu_table'];
91  $cuCode = $pContext['cu_code'];
92  $cuMember = $pContext['m_account'];
93 
94  $sqlReturn = array();
95 
96  // select number of users with this account
97  $sqlCount = "
98  SELECT COUNT(DISTINCT ua.user_id) m_count,
99  CASE WHEN BOOL_OR(COALESCE(TRIM(u.employee), 'N') = 'Y')
100  THEN 'Y'
101  ELSE 'N' END m_employee
102  FROM {$cuTable}useraccounts ua
103  LEFT JOIN ${cuTable}user u ON ua.user_id = u.user_id
104  WHERE ua.accountnumber = '$cuMember'";
105 
106  $sqlSelect = "
107  SELECT TRIM(img) AS image
108  FROM cuadmin
109  WHERE cu = '$cuCode'";
110  $sqlSelectRs = db_query($sqlSelect, $pDbh);
111  if (!$sqlSelectRs) {
112  if (isset($pEnv))
113  $pEnv['logger']->error(db_last_error());
114  throw new Exception("Failed to read credit union image vendor.");
115  };
116  $sqlData = db_fetch_array($sqlSelectRs, 0);
117  $sqlSub = $sqlData['image'];
118  if ($sqlSub == "NO" || $GLOBALS['CU_SHOWIMAGES'] == 0) {
119  $sqlSub = "NO";
120  }
121 
122  $sqlColumns = "
123  u.accountnumber AS m_account,
124  u.estmnt_flag AS m_stmnt,
125  u.billpayid AS m_payid,
126  u.rdcsetting AS m_rdc,
127  u.restrictions AS m_restr,
128  '$sqlSub' AS m_image,
129  t.m_count,
130  t.m_employee";
131  $sqlSelect = "
132  SELECT $sqlColumns
133  FROM {$cuTable}memberacct u
134  CROSS JOIN ($sqlCount) t
135  WHERE u.accountnumber = '$cuMember'";
136 
137  $sqlSelectRs = db_query($sqlSelect, $pDbh);
138  if (!$sqlSelectRs) {
139  if (isset($pEnv))
140  $pEnv['logger']->error(db_last_error());
141  throw new Exception("Failed to select member.");
142  }
143 
144  $sqlReturn['member'] = db_fetch_all($sqlSelectRs)[0];
145  return $sqlReturn;
146 }
147 
148 /**
149  * MemberEncrypt:
150  * @uses encode member data from anywhere given at least the member accountnumber. This function
151  * will also encode the string for url purposes.
152  *
153  * @param $pEnv array: $pEnv array: evironment object for debugging
154  * @param $pCu string: cu code used for accessing variables and database tables
155  * @param $pMember array: member data to encode
156  * @param $pJson boolean: allows user to pass array or json string to be encoded (optional)
157  *
158  * @return $sMemberEncrypt string: encoded data string
159  */
160 function MemberEncrypt($pEnv, $pCu, $pMember, $pJson = false) {
161  $sMemberEncode = $pMember;
162 
163  if ($pJson) {
164  $sMemberEncode = html_entity_decode($sMemberEncode, ENT_QUOTES);
165  $sMemberEncode = HCU_JsonDecode($sMemberEncode);
166  }
167 
168  $sMemberEncrypt = HCU_PayloadEncode($pCu, $sMemberEncode);
169  return $sMemberEncrypt;
170 }
171 
172 /**
173  * MemberDecrypt:
174  * @uses decrypt member data from anywhere given the encrypted string, this function will
175  * decode any url characters if neccessary.
176  *
177  * @param $pEnv array: $pEnv array: evironment object for debugging
178  * @param $pCu string: cu code used for accessing variables and database tables
179  * @param $pEncode string: encrypted data string
180  * @param $pJson boolean: allows user to return an array or json string (optional)
181  *
182  * @return $sMemberDecode string | array: decrypted member data as string or array
183  */
184 function MemberDecrypt($pEnv, $pCu, $pEncrypt, $rJson = false) {
185  $sMemberDecrypt = HCU_PayloadDecode($pCu, $pEncrypt, $rJson);
186  return $sMemberDecrypt;
187 }
188 
189 ?>