Odyssey
aProfile.data
1 <?php
2 /**
3  * @package aProfileLst.prg
4  * Purpose: Handle the CRUD portion of the Profile/Profile Features, feature in Monitor. Return any requested data
5  * in a JSON format, for the client to display accordingly.
6  *
7  * Call this script with the following parameters
8  * @param string $action : requested database action
9  * @param int $pId : profile_id
10  * @param string $pCode : profile_code
11  * @param string $pDesc : profile description
12  * @param string $fList : feature list, list of profile feature codes to delete from profile_id
13  * @param string $fType : feature limit_type, determines what feature limits are set to NULL
14  * @param string $fCode : feature_code, name of profile feature limit
15  * @param float $fApt : feature limit, dollar amount per transaction
16  * @param float $fApd : feature limit, dollar amount per day
17  * @param float $fApm : feature limit, dollar amount per month
18  * @param float $fApa : feature limit, dollar amount per account per day
19  * @param int $fCpd : feature limit, quantity amount per day
20  * @param int $fCpm : feature limit, quantity amount per month
21  * @param int $fCpa : feature limit, quantity amount per account per day
22  * @param boolean $fCfm : feature limit, confirmation required
23  *
24  *
25  * @return JSON OBJECT.
26  */
27 header('Content-Type: application/json');
28 try {
29  require_once(dirname(__FILE__) . '/../../shared/library/dms_imp_val.i');
30 
31  $admVars = array();
32  $varOk = array(
33  "action" => array('filter' => FILTER_SANITIZE_STRING),
34  "pId" => array('filter' => FILTER_VALIDATE_INT),
35  "pCode" => array('filter' => FILTER_SANITIZE_STRING),
36  "pDesc" => array('filter' => FILTER_SANITIZE_STRING),
37  "fList" => array('filter' => FILTER_SANITIZE_STRING),
38  "fType" => array('filter' => FILTER_SANITIZE_STRING),
39  "fCode" => array('filter' => FILTER_SANITIZE_STRING),
40  "fApt" => array('filter' => FILTER_VALIDATE_FLOAT),
41  "fApa" => array('filter' => FILTER_VALIDATE_FLOAT),
42  "fApd" => array('filter' => FILTER_VALIDATE_FLOAT),
43  "fApm" => array('filter' => FILTER_VALIDATE_FLOAT),
44  "fCpa" => array('filter' => FILTER_VALIDATE_INT),
45  "fCpd" => array('filter' => FILTER_VALIDATE_INT),
46  "fCpm" => array('filter' => FILTER_VALIDATE_INT),
47  "fCfm" => array('filter' => FILTER_VALIDATE_BOOLEAN),
48  );
49 
50  HCU_ImportVars($admVars, "", $varOk);
51 
52  $action = isset($admVars['action']) ? $admVars['action'] : null;
53  $pId = isset($admVars['pId']) ? $admVars['pId'] : null;
54  $pCode = isset($admVars['pCode']) ? $admVars['pCode'] : null;
55  $pDesc = isset($admVars['pDesc']) ? $admVars['pDesc'] : null;
56  $fList = isset($admVars['fList']) ? $admVars['fList'] : null;
57  $fCode = isset($admVars['fCode']) ? $admVars['fCode'] : null;
58  $fType = isset($admVars['fType']) ? $admVars['fType'] : null;
59  $fApt = isset($admVars['fApt']) ? $admVars['fApt'] : null;
60  $fApd = isset($admVars['fApd']) ? $admVars['fApd'] : null;
61  $fApm = isset($admVars['fApm']) ? $admVars['fApm'] : null;
62  $fApa = isset($admVars['fApa']) ? $admVars['fApa'] : null;
63  $fCpd = isset($admVars['fCpd']) ? $admVars['fCpd'] : null;
64  $fCpm = isset($admVars['fCpm']) ? $admVars['fCpm'] : null;
65  $fCpa = isset($admVars['fCpa']) ? $admVars['fCpa'] : null;
66  $fCfm = isset($admVars['fCfm']) ? $admVars['fCfm'] : null;
67 
68  $aryResult = array();
69  $aryReply = array();
70 
71  switch ($action) {
72  case "data_read":
73 
74  $aryResult['data']['profiles'] = ReadProfiles($SYSENV, $dbh, $Cu);
75  $aryResult['data']['limits'] = ReadProfileFeatures($SYSENV, $dbh, $Cu);
76  $aryResult['data']['features'] = ReadAvailableFeatures($SYSENV, $dbh, $Cu);
77  break;
78 
79  case "profile_create":
80 
81  $aryResult = CreateProfile($SYSENV, $dbh, $pCode, $pDesc, $Cu);
82  break;
83 
84  case "profile_update":
85 
86  $aryResult = UpdateProfile($SYSENV, $dbh, $pId, $pCode, $pDesc, $Cu);
87  break;
88 
89  case "profile_delete":
90 
91  $aryResult = DeleteProfile($SYSENV, $dbh, $pId, $pCode, $Cu);
92  break;
93 
94  case "limit_create":
95 
96  $fAmount = array("apt" => $fApt, "apd" => $fApd, "apm" => $fApm, "apa" => $fApa);
97  $fCount = array("cpd" => $fCpd, "cpm" => $fCpm, "cpa" => $fCpa, "cfm" => $fCfm);
98  $fFeature = array("code" => $fCode, "type" => $fType);
99 
100  $aryResult = CreateLimit($SYSENV, $dbh, $pId, $fFeature, $fAmount, $fCount, $Cu);
101  break;
102 
103  case "limit_update":
104 
105  $fAmount = array("apt" => $fApt, "apd" => $fApd, "apm" => $fApm, "apa" => $fApa);
106  $fCount = array("cpd" => $fCpd, "cpm" => $fCpm, "cpa" => $fCpa, "cfm" => $fCfm);
107  $fFeature = array("code" => $fCode, "type" => $fType);
108 
109  $aryResult = UpdateLimit($SYSENV, $dbh, $pId, $fFeature, $fAmount, $fCount);
110  break;
111 
112  case "limit_delete":
113 
114  $aryResult = DeleteLimit($SYSENV, $dbh, $pId, $fList, $Cu);
115  break;
116  default:
117 
118  throw new Exception("Feature Action: ( $action ) unknown");
119  break;
120  }
121 
122 } catch (Exception $e) {
123  $aryReply['error'][] = $e->getMessage();
124  $aryResult['data'] = array();
125  $aryResult['info'] = array();
126 }
127 
128 $aryReply['action'] = $action;
129 if (isset($aryResult['data']) && count($aryResult['data'])) $aryReply['data'] = $aryResult['data'];
130 if (isset($aryResult['info']) && count($aryResult['info'])) $aryReply['info'] = $aryResult['info'];
131 if (isset($aryResult['error']) && count($aryResult['error'])) $aryReply['error'] = $aryResult['error'];
132 
133 print json_encode(array("Results" => $aryReply));
134 
135 /**
136  * LimitInUse: this function determines if an particular profile feature limit is being used by
137  * a group or user. If the feature is not in use it can be delete from the profile
138  *
139  * @param object $pEnv : system environment variable for debugging
140  * @param object $pDbh : system database variable for database manipulation
141  * @param int $pId : profile_id, check groups and users associated with this profile
142  * @param string $fCode : feature_code, feature associated with profile_id, check if in use
143  * @param string $pCu : credit union code associated with the profile_id
144  *
145  * @return booleam $sqlReturn : true if profile feature is in use by groups or users
146  */
147 function LimitInUse($pEnv, $pDbh, $pId, $fCode, $pCu) {
148 
149  $sqlReturn = false;
150  $sqlInUseGroup = "
151  SELECT COUNT(*) FROM {$pCu}grouprights gr
152  INNER JOIN {$pCu}group g
153  ON gr.group_id = g.group_id
154  WHERE g.profile_id = $pId
155  AND gr.feature_code = $fCode";
156 
157  $sqlInUseUser = "
158  SELECT COUNT(*) FROM {$pCu}userrights ur
159  INNER JOIN {$pCu}user u
160  ON ur.user_id = u.user_id
161  INNER JOIN {$pCu}group g
162  ON u.group_id = g.group_id
163  WHERE g.profile_id = $pId
164  AND ur.feature_code = $fCode";
165 
166  $sqlInUseGroupRs = db_query($sqlInUseGroup, $pDbh);
167  $sqlInUseUserRs = db_query($sqlInUseUser, $pDbh);
168  if (!$sqlInUseGroupRs || !$sqlInUseUserRs) {
169  $pEnv['logger']->error(db_last_error());
170  throw new Exception("Failed to read limit uses");
171  }
172 
173  $sqlDataGroup = db_fetch_all($sqlInUseGroupRs);
174  $sqlDataUser = db_fetch_all($sqlInUseUserRs);
175  $sqlDataGroupCount = $sqlDataGroup[0]['count'];
176  $sqlDataUserCount = $sqlDataUser[0]['count'];
177  if ($sqlDataGroupCount > 0 || $sqlDataUserCount > 0) {
178  $sqlReturn = true;
179  }
180 
181  return $sqlReturn;
182 }
183 
184 /**
185  * DeleteLimit: this function to be used to delete profile feature limits from a specified profile_id
186  *
187  * @param object $pEnv : system environment variable for debugging
188  * @param object $pDbh : system database variable for database manipulation
189  * @param int $pId : profile_id, check groups and users associated with this profile
190  * @param string $fList : list of profile feature_codes to delete, comma separated list
191  * @param string $pCu : credit union code associated with the profile_id
192  *
193  * @return array $sqlReturn : array containing deleted rows, and success information
194  */
195 function DeleteLimit($pEnv, $pDbh, $pId, $fList, $pCu) {
196 
197  $sqlReturn = array();
198 
199  $features = "";
200  $featuresAry = array();
201  $featuresLst = explode(",", $fList);
202  $featuresInUse = false;
203 
204  foreach ($featuresLst as $key => $value) {
205 
206  $feature = explode(":", $value);
207  $code = "'" . prep_save($feature[1], 10) . "'";
208  $desc = prep_save($feature[0], 255);
209 
210  $inUse = LimitInUse($pEnv, $pDbh, $pId, $code, $pCu);
211 
212  if ($inUse) {
213  $featuresInUse = true;
214  $sqlReturn['error'][] = "$desc ( Feature has custom access rights for one or more users. )";
215  } else {
216  array_push($featuresAry, $code);
217  $sqlReturn['info'][] = "$desc ( Deleted )";
218  }
219  }
220 
221  if ($featuresInUse) {
222  $sqlReturn['error'][] = "Contact HomeCU if you wish to delete these features from the profile.";
223  } else {
224  $features = implode(",", $featuresAry);
225 
226  $sqlColumnsLimit = "profile_id AS pid,
227  feature_code AS fcode,
228  amount_per_transaction AS fapt,
229  amount_per_day AS fapd,
230  amount_per_month AS fapm,
231  amount_per_account_per_day AS fapa,
232  count_per_day AS fcpd,
233  count_per_month AS fcpm,
234  count_per_account_per_day AS fcpa,
235  confirm_required AS fcfm";
236 
237  $sqlDeleteLimit = "DELETE FROM cu_profilerights
238  WHERE feature_code IN ($features)
239  AND profile_id = $pId
240  RETURNING $sqlColumnsLimit";
241 
242  $sqlDeleteRs = db_query($sqlDeleteLimit, $pDbh);
243  if (!$sqlDeleteRs) {
244  $pEnv['logger']->error(db_last_error());
245  throw new Exception("Failed to delete limits");
246  }
247 
248  $sqlReturn['data'] = db_fetch_all($sqlDeleteRs);
249  }
250 
251  return $sqlReturn;
252 }
253 
254 /**
255  * UpdateLimit: this function to be used to update an existing profile feature_code
256  * associated with an existing profile_id. Depending on feature limit_type, some values
257  * will be saved as NULL.
258  *
259  * @param object $pEnv : system environment variable for debugging
260  * @param object $pDbh : system database variable for database manipulation
261  * @param int $pId : profile_id, check groups and users associated with this profile
262  * @param array $fFeature : feature_code, limit_type; feature to be updated, NULL value determinant
263  * @param array $fAmount : feature limist: dolloar amount /transaction/day/month/account per day
264  * @param array $fCount : feature limits: quantity amount /day/month/account per day, confirmation required
265  *
266  * @return array $sqlReturn : array containing updated rows, and success information
267  */
268 function UpdateLimit($pEnv, $pDbh, $pId, $fFeature, $fAmount, $fCount) {
269 
270  $id = $pId;
271  $code = prep_save($fFeature['code'], 10);
272  $type = prep_save($fFeature['type'], 1);
273  $apt = ($type == "B" || $type == "D") ? $fAmount['apt'] : "NULL";
274  $apd = ($type == "B" || $type == "D") ? $fAmount['apd'] : "NULL";
275  $apm = ($type == "B" || $type == "D") ? $fAmount['apm'] : "NULL";
276  $apa = ($type == "B" || $type == "D") ? $fAmount['apa'] : "NULL";
277  $cpd = ($type == "B" || $type == "Q") ? $fCount['cpd'] : "NULL";
278  $cpm = ($type == "B" || $type == "Q") ? $fCount['cpm'] : "NULL";
279  $cpa = ($type == "B" || $type == "Q") ? $fCount['cpa'] : "NULL";
280  $cfm = $fCount['cfm'] == 1 ? "true" : "false";
281 
282  $sqlReturn = array();
283  $sqlColumnsLimit = "profile_id AS pid,
284  feature_code AS fcode,
285  amount_per_transaction AS fapt,
286  amount_per_day AS fapd,
287  amount_per_month AS fapm,
288  amount_per_account_per_day AS fapa,
289  count_per_day AS fcpd,
290  count_per_month AS fcpm,
291  count_per_account_per_day AS fcpa,
292  confirm_required AS fcfm";
293 
294  $sqlUpdateLimit = "UPDATE cu_profilerights
295  SET (amount_per_transaction, amount_per_day, amount_per_month, amount_per_account_per_day,
296  count_per_day, count_per_month, count_per_account_per_day, confirm_required)
297  = ($apt, $apd, $apm, $apa, $cpd, $cpm, $cpa, $cfm)
298  WHERE profile_id = $pId
299  AND feature_code = '$code'
300  RETURNING $sqlColumnsLimit";
301 
302  $sqlUpdateLimitRs = db_query($sqlUpdateLimit, $pDbh);
303  if (!$sqlUpdateLimitRs) {
304  $pEnv['logger']->error(db_last_error());
305  throw new Exception("Failed to update limit");
306  }
307 
308  $sqlReturn['data'] = db_fetch_all($sqlUpdateLimitRs);
309  $sqlReturn['info'][] = "Limit has been updated successfully";
310 
311  return $sqlReturn;
312 }
313 
314 /**
315  * CreateLimit: this function to be used to create a new profile feature_code
316  * associated with a profile_id. Depending on feature limit_type, some values
317  * will be saved as NULL.
318  *
319  * @param object $pEnv : system environment variable for debugging
320  * @param object $pDbh : system database variable for database manipulation
321  * @param int $pId : profile_id, check groups and users associated with this profile
322  * @param array $fFeature : feature_code, limit_type; feature to be added to profile_id, NULL value determinant
323  * @param array $fAmount : feature limist: dolloar amount /transaction/day/month/account per day
324  * @param array $fCount : feature limits: quantity amount /day/month/account per day, confirmation required
325  * @param string $pCu : credit union code associated with the profile_id
326  *
327  * @return array $sqlReturn : array containing updated rows, and success information
328  */
329 function CreateLimit($pEnv, $pDbh, $pId, $fFeature, $fAmount, $fCount, $pCu) {
330 
331  $id = $pId;
332  $code = prep_save($fFeature['code'], 10);
333  $type = prep_save($fFeature['type'], 1);
334  $apt = ($type == "B" || $type == "D") ? $fAmount['apt'] : "NULL";
335  $apd = ($type == "B" || $type == "D") ? $fAmount['apd'] : "NULL";
336  $apm = ($type == "B" || $type == "D") ? $fAmount['apm'] : "NULL";
337  $apa = ($type == "B" || $type == "D") ? $fAmount['apa'] : "NULL";
338  $cpd = ($type == "B" || $type == "Q") ? $fCount['cpd'] : "NULL";
339  $cpm = ($type == "B" || $type == "Q") ? $fCount['cpm'] : "NULL";
340  $cpa = ($type == "B" || $type == "Q") ? $fCount['cpa'] : "NULL";
341  $cfm = $fCount['cfm'] == 1 ? "true" : "false";
342 
343  $sql = "select 'FOUND' from cu_featuremenu fm inner join cu_feature f on fm.feature_code = f.feature_code and fm.cu = '" . prep_save($pCu, 10) . "' and f.enabled = true";
344  $sth = db_query($sql, $pDbh);
345  if (!$sth || db_num_rows($sth) == 0) {
346  throw new exception("Failed to create limit"); // Feature is not in Credit Union's list of features or feature is not enabled. Keep same exposed error message.
347  }
348 
349  $sqlReturn = array();
350  $sqlColumnsLimit = "profile_id AS pid,
351  feature_code AS fcode,
352  amount_per_transaction AS fapt,
353  amount_per_day AS fapd,
354  amount_per_month AS fapm,
355  amount_per_account_per_day AS fapa,
356  count_per_day AS fcpd,
357  count_per_month AS fcpm,
358  count_per_account_per_day AS fcpa,
359  confirm_required AS fcfm";
360 
361  $sqlInsertLimit = "INSERT INTO cu_profilerights
362  (profile_id, feature_code,
363  amount_per_transaction, amount_per_day, amount_per_month, amount_per_account_per_day,
364  count_per_day, count_per_month, count_per_account_per_day, confirm_required)
365  VALUES
366  ($id, '$code', $apt, $apd, $apm, $apa, $cpd, $cpm, $cpa, $cfm)
367  RETURNING $sqlColumnsLimit";
368 
369  $sqlInsertLimitRs = db_query($sqlInsertLimit, $pDbh);
370  if (!$sqlInsertLimitRs) {
371  $pEnv['logger']->error(db_last_error());
372  throw new Exception("Failed to create limit");
373  }
374 
375  $sqlReturn['data'] = db_fetch_all($sqlInsertLimitRs);
376  $sqlReturn['info'][] = "Limit has been created successfully";
377 
378  return $sqlReturn;
379 }
380 
381 /**
382  * ProfileInUse: function to be used in determining if a profile is in use, by checking
383  * if the profile_id has any limits associated with it or a group is a ssociated with the profile_id
384  *
385  * @param object $pEnv : system environment variable for debugging
386  * @param object $pDbh : system database variable for database manipulation
387  * @param int $pId : profile_id, check groups and users associated with this profile
388  * @param string $pCu : credit union code associated with the profile_id
389  *
390  * @return boolean $sqlReturn : true if profile is associated with any feature limits or groups
391  */
392 function ProfileInUse($pEnv, $pDbh, $pId, $pCu) {
393 
394  $sqlReturn = false;
395  $sqlSelectProfileGroup = "SELECT COUNT(*) FROM {$pCu}group
396  WHERE profile_id = $pId";
397 
398  $sqlSelectProfileRights = "SELECT COUNT(*) FROM cu_profilerights
399  WHERE profile_id = $pId";
400 
401  $sqlSelectProfileGroupRs = db_query($sqlSelectProfileGroup, $pDbh);
402  $sqlSelectProfileRightsRs = db_query($sqlSelectProfileRights, $pDbh);
403  if (!$sqlSelectProfileGroupRs || !$sqlSelectProfileRightsRs) {
404  $pEnv['logger']->error(db_last_error());
405  throw new Exception("Failed to read profile uses");
406  }
407 
408  $sqlDataProfileGroup = db_fetch_all($sqlSelectProfileGroupRs);
409  $sqlDataProfileRights = db_fetch_all($sqlSelectProfileRightsRs);
410  $sqlDataProfileGroupCount = $sqlDataProfileGroup[0]['count'];
411  $sqlDataProfileRightsCount = $sqlDataProfileRights[0]['count'];
412  if ($sqlDataProfileGroupCount > 0 || $sqlDataProfileRightsCount > 0) {
413  $sqlReturn = true;
414  }
415 
416  return $sqlReturn;
417 }
418 
419 /**
420  * DeleteProfile: this function be used for deleting existing profiles which are not associated
421  * with any feature limits or groups (determined by ProfileInUse).
422  *
423  * @param object $pEnv : system environment variable for debugging
424  * @param object $pDbh : system database variable for database manipulation
425  * @param int $pId : profile_id, check groups and users associated with this profile
426  * @param string $pCode : profile_code, 20 character code name associated with the profile_id
427  * @param string $pCu : credit union code associated with the profile_id
428  *
429  * @return array $sqlReturn : array containing updated rows, and success information
430  */
431 function DeleteProfile($pEnv, $pDbh, $pId, $pCode, $pCu) {
432 
433  $sqlReturn = array();
434  if (ProfileInUse($pEnv, $pDbh, $pId, $pCu)) {
435  throw new Exception("Failed to delete profile. It is currently in use");
436  }
437 
438  $sqlDeleteProfile = "DELETE FROM cu_profile
439  WHERE profile_id = $pId
440  AND profile_code = '$pCode'
441  AND cu = '$pCu'
442  RETURNING profile_id AS pid, profile_code AS pcode, description AS pdesc";
443 
444  $sqlDeleteProfileRs = db_query($sqlDeleteProfile, $pDbh);
445  if (!$sqlDeleteProfileRs) {
446  $pEnv['logger']->error(db_last_error());
447  throw new Exception("Failed to delete profile");
448  }
449 
450  $sqlReturn['data'] = db_fetch_all($sqlDeleteProfileRs);
451  $sqlReturn['info'][] = "Profile has been deleted successfully";
452 
453  return $sqlReturn;
454 }
455 
456 /**
457  * UpdateProfile: this function be used for updating existing profile descriptions associated
458  * with the profile_id.
459  *
460  * @param object $pEnv : system environment variable for debugging
461  * @param object $pDbh : system database variable for database manipulation
462  * @param int $pId : profile_id, check groups and users associated with this profile
463  * @param string $pCode : profile_code, 20 character code name associated with the profile_id
464  * @param string $pDesc : profile description, updated string for profile description
465  * @param string $pCu : credit union code associated with the profile_id
466  *
467  * @return array $sqlReturn : array containing updated rows, and success information
468  */
469 function UpdateProfile($pEnv, $pDbh, $pId, $pCode, $pDesc, $pCu) {
470 
471  $code = strtoupper($pCode);
472  $code = prep_save($code, 10);
473 
474  $desc = html_entity_decode($pDesc, ENT_QUOTES);
475  $desc = prep_save($desc, 255);
476 
477  $sqlReturn = array();
478  $sqlUpdateProfile = "UPDATE cu_profile
479  SET (profile_code, description) = ('$code', '$desc')
480  WHERE profile_id = $pId
481  AND cu = '$pCu'
482  RETURNING profile_id AS pid, profile_code AS pcode, description AS pdesc";
483 
484  $sqlUpdateRs = db_query($sqlUpdateProfile, $pDbh);
485  if (!$sqlUpdateRs) {
486  $pEnv['logger']->error(db_last_error());
487  throw new Exception("Failed to update profile");
488  }
489 
490  $sqlReturn['data'] = db_fetch_all($sqlUpdateRs);
491  $sqlReturn['info'][] = "Profile was successfully updated";
492 
493  return $sqlReturn;
494 }
495 
496 /**
497  * CreateProfile: this function be used for creating new profiles associated with a credit union code
498  *
499  * @param object $pEnv : system environment variable for debugging
500  * @param object $pDbh : system database variable for database manipulation
501  * @param string $pCode : profile_code, new 20 character code associated with profile_id
502  * @param string $pDesc : profile description: new 255 character description associated with profile_id
503  * @param string $pCu : credit union code associated with the profile_id
504  *
505  * @return array $sqlReturn : array containing updated rows, and success information
506  */
507 function CreateProfile($pEnv, $pDbh, $pCode, $pDesc, $pCu) {
508 
509  $code = strtoupper($pCode);
510  $code = prep_save($code, 20);
511 
512  $desc = html_entity_decode($pDesc, ENT_QUOTES);
513  $desc = prep_save($desc, 255);
514 
515  $cu = prep_save($pCu, 10);
516 
517  $sqlReturn = array();
518  $sqlInsertProfile = "INSERT INTO cu_profile
519  (profile_code, description, cu)
520  VALUES
521  ('$code', '$desc', '$cu')
522  RETURNING profile_id AS pid, profile_code AS pcode, description AS pdesc";
523 
524  $sqlInsertRs = db_query($sqlInsertProfile, $pDbh);
525  if (!$sqlInsertRs) {
526  $pEnv['logger']->error(db_last_error());
527  throw new Exception("Failed to create profile");
528  }
529 
530  $sqlReturn['data'] = db_fetch_all($sqlInsertRs);
531  $sqlReturn['info'][] = "Profile was successfully created";
532 
533  return $sqlReturn;
534 }
535 
536 /**
537  * ReadProfiles: generate a list of active profiles associated with the credit union
538  *
539  * @param object $pEnv : system environment variable for debugging
540  * @param object $pDbh : system database variable for database manipulation
541  * @param string $pCu : credit union code associated with a profile_id
542  *
543  * @return array $sqlReturn : array containing data rows, and success information
544  */
545 function ReadProfiles($pEnv, $pDbh, $pCu) {
546  $sqlReturn = array();
547  $sqlColumnsProfiles = "cup.profile_id AS pid,
548  cup.profile_code AS pcode,
549  cup.description AS pdesc";
550 
551  $sqlSelectProfiles = "SELECT $sqlColumnsProfiles
552  FROM cu_profile cup
553  WHERE cup.cu = '$pCu'
554  ORDER BY cup.description ASC";
555 
556  $sqlQueryProfiles = db_query($sqlSelectProfiles, $pDbh);
557  if (!$sqlQueryProfiles) {
558  $pEnv['logger']->error(db_last_error());
559  throw new Exception("Failed to read profiles list");
560  }
561 
562  $sqlReturn = db_fetch_all($sqlQueryProfiles);
563  return $sqlReturn;
564 }
565 
566 /**
567  * ReadProfileFeatures: generate a list of active profile feature limits associated with
568  * a credit union code.
569  *
570  * @param object $pEnv : system environment variable for debugging
571  * @param object $pDbh : system database variable for database manipulation
572  * @param string $pCu : credit union code associated with a profile_id
573  *
574  * @return array $sqlReturn : array containing data rows, and success information
575  */
576 function ReadProfileFeatures($pEnv, $pDbh, $pCu) {
577  $sqlReturn = array();
578 
579  $sqlColumnsRights = "cupr.profile_id AS pid,
580  cupr.feature_code AS fcode,
581  cupr.amount_per_transaction AS fapt,
582  cupr.amount_per_day AS fapd,
583  cupr.amount_per_month AS fapm,
584  cupr.amount_per_account_per_day AS fapa,
585  cupr.count_per_day AS fcpd,
586  cupr.count_per_month AS fcpm,
587  cupr.count_per_account_per_day AS fcpa,
588  cupr.confirm_required AS fcfm,
589  cuf.description AS fdesc,
590  cuf.limit_type AS ftype";
591 
592  $sqlSelectRights = "SELECT $sqlColumnsRights
593  FROM cu_profilerights cupr
594  INNER JOIN cu_feature cuf ON cupr.feature_code = cuf.feature_code
595  INNER JOIN cu_profile cup ON cupr.profile_id = cup.profile_id
596  WHERE cuf.enabled = TRUE
597  AND cup.cu = '$pCu'
598  ORDER BY cuf.description ASC";
599 
600  $sqlQueryRights = db_query($sqlSelectRights, $pDbh);
601  if (!$sqlQueryRights) {
602  $pEnv['logger']->error(db_last_error());
603  throw new Exception("Failed to read profile rights");
604  }
605 
606  $sqlReturn = db_fetch_all($sqlQueryRights);
607  return $sqlReturn;
608 }
609 
610 /**
611  * ReadAvailableFeatures: generate a list of globally enabled features
612  *
613  * @param object $pEnv : system environment variable for debugging
614  * @param object $pDbh : system database variable for database manipulation
615  * @param string $pCu : credit union code associated with a profile_id
616  *
617  * @return array $sqlReturn : array containing data rows, and success information
618  */
619 function ReadAvailableFeatures($pEnv, $pDbh, $pCu) {
620  $sqlReturn = array();
621 
622  $sqlColumnsFeatures = "cuf.feature_code AS fcode,
623  cuf.description AS fdesc,
624  cuf.limit_type AS ftype,
625  cuf.enabled AS fenabled";
626 
627  // WHERE EXISTS restricts feature list to the features that the credit union has.
628  $sqlSelectFeatures = "SELECT $sqlColumnsFeatures,
629  EXISTS (SELECT 'FOUND' FROM cu_featuremenu fm WHERE cuf.enabled = TRUE AND cuf.feature_code = fm.feature_code AND fm.cu = '" . prep_save($pCu, 10) . "') as cuexists
630  FROM cu_feature cuf
631  ORDER BY cuf.description ASC";
632 
633  $sqlQueryFeatures = db_query($sqlSelectFeatures, $pDbh);
634  if (!$sqlQueryFeatures) {
635  $pEnv['logger']->error(db_last_error());
636  throw new Exception("Failed to read feature list");
637  }
638 
639  $sqlReturn = db_fetch_all($sqlQueryFeatures);
640  return $sqlReturn;
641 }
642 ?>