5 $monLibrary= dirname(__FILE__) .
"/../library";
6 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
7 require_once(
"$monLibrary/cu_top.i");
8 require_once(
"$monLibrary/ck_hticket.i");
9 require_once(
"$sharedLibrary/commonPhpFunctions.i");
11 HCU_ImportVars($DATA_PARAMETERS,
"TOP_LEVEL", array(
'operation' =>
'string',
"action" =>
"string"));
13 if (HCU_array_key_exists(
"operation", $DATA_PARAMETERS[
'TOP_LEVEL'])) {
14 $operation = $DATA_PARAMETERS[
'TOP_LEVEL'][
'operation'];
16 $operation = $DATA_PARAMETERS[
'TOP_LEVEL'][
'action'];
21 if (!CheckPerm($link, $Hu,
'loanAppConfig', $_SERVER[
'REMOTE_ADDR'])) {
24 header(
"Location: /hcuadm/hcu_noperm.prg");
31 $returnArray= readOrModifyOptions($dbh,
"read");
34 $returnArray= readOrModifyOptions($dbh,
"add");
37 $returnArray= readOrModifyOptions($dbh,
"update");
40 $returnArray= readOrModifyOptions($dbh,
"delete");
42 case "readLoanApplications":
43 $returnArray= readLoanApplications($dbh);
45 case "createLoanApplication":
46 $returnArray= createOrUpdateLoanApplication($dbh,
true);
48 case "updateLoanApplication":
49 $returnArray= createOrUpdateLoanApplication($dbh,
false);
51 case "deleteLoanApplication":
52 $returnArray= deleteLoanApplication($dbh);
55 $returnArray= editSave($dbh);
57 default: $returnArray= array(
"sql" => array(),
"error" => array(
"Operation not specified: '$operation'"),
"record" =>
"",
"operation" =>
"");
61 unset($returnArray[
"sql"]);
62 header(
'Content-type: application/json');
63 print HCU_JsonEncode($returnArray);
65 function getConfigOptions($isLive)
67 return array(
"configHomeLogin" => array(
"text" =>
"Allow Home Banking Login",
"type" =>
"boolean"),
68 "configDisableEmail" => array(
"text" =>
"Disable Email Login",
"type" =>
"boolean"),
69 "configSSOOnly" => array(
"text" =>
"SSO Only",
"type" =>
"boolean"),
70 "configLoanSubmit" => array(
"text" =>
"Post Loan Applications to Core",
"type" =>
"boolean",
"disabled" => !$isLive,
"defaultValue" =>
true),
71 "configLoanSubmitMember" => array(
"text" =>
"Post Primary Member With Loan App",
"type" =>
"boolean"),
72 "configLoanFormat" => array(
"text" =>
"Post Loan Applications Format",
"type" =>
"list"),
73 "configLoanMIR" => array(
"text" =>
"Allow Member Info to Populate From Core",
"type" =>
"boolean"),
74 "configLoanCSS" => array(
"text" =>
"Loan App Stylesheet",
"type" =>
"url"),
75 "configLoanIntroMbr" => array(
"text" =>
"Loan Login Message for Members",
"type" =>
"string"),
76 "configLoanIntroNonHBMbr" => array(
"text" =>
"Loan Login Message for Non-Home Banking Members",
"type" =>
"string"),
77 "configLoanIntroNon" => array(
"text" =>
"Loan Login Message for non-Members",
"type" =>
"string"),
78 "configLoanDataOnly" => array(
"text" =>
"Submit Fields With Data Only",
"type" =>
"boolean"),
79 "configPassword" => array(
"text" =>
"Password Requirements",
"type" =>
"string")
83 function getConfigLists()
85 return array(
"configLoanFormat" => array(
"XML",
"JSON",
"SERIAL"));
88 function readOrModifyOptions($dbh, $mode)
91 $allowed= array(
"cu" =>
"string");
94 $allowed[
"configId"]=
"string";
95 $allowed[
"value"]=
"string";
97 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", $allowed);
100 if ($mode !=
"read") {
101 $configId= $parameters[
"BOTTOM_LEVEL"][
"configId"];
103 if ($mode !=
"read" && $mode !=
"delete") {
104 $value= $parameters[
"BOTTOM_LEVEL"][
"value"];
107 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
108 array(
"cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
109 "configId" => array(
"type" =>
"string",
"required" =>
true),
110 "value" => array(
"type" =>
"string",
"required" =>
false)));
112 $cu= strtoupper($parameters[
"BOTTOM_LEVEL"][
"cu"]);
114 $findAppConfigSQL=
"select appconfig, cu from lnappconfig where upper(cu) = '$cu'";
115 $findLiveBatchSQL=
"select livebatch from cuadmin where upper(user_name) = '$cu'";
116 $sqls= array($findAppConfigSQL, $findLiveBatchSQL);
118 $appResults= runSelectStatement($findAppConfigSQL, $dbh, array(
"appconfig" =>
"appconfig",
"cu" =>
"cu"));
119 $liveBatchResults= runSelectStatement($findLiveBatchSQL, $dbh, array(
"livebatch" =>
"livebatch"));
120 $errors= array_merge($errors, $appResults[
"error"], $liveBatchResults[
"error"]);
124 $hasAppConfigRecord =
false;
125 if (HCU_array_key_exists(0, $appResults[
"record"])) {
126 $appConfig= strval($appResults[
"record"][0][
"appconfig"]);
127 $isLive= trim($liveBatchResults[
"record"][0][
"livebatch"]) ==
"L";
128 $hasAppConfigRecord= strval($appResults[
"record"][0][
"cu"]) !=
"";
131 $configOptions= getConfigOptions($isLive);
133 $options= $appConfig ==
"" ? array() : HCU_JsonDecode($appConfig, true);
135 if (is_array($options))
142 unset($options[$configId]);
146 $options[$configId]= $value;
149 $errors[]=
"$mode is not a valid mode.";
151 $appConfig= prepSave(HCU_JsonEncode($options));
152 $updateSQL= $hasAppConfigRecord ?
"update lnappconfig set appconfig='$appConfig' where upper(cu) = '$cu'" 153 :
"insert into lnappconfig (cu, appconfig) values ('$cu', '$appConfig')";
155 if (count($errors) == 0)
157 $results= runExecStatement($updateSQL, $dbh);
158 $errors= array_merge($errors, $results[
"error"]);
164 foreach($options as $key => $value)
166 $config= $configOptions[$key];
167 $configText= isset($config[
"text"]) ? $config[
"text"] : $key;
168 $type= isset($config[
"type"]) ? $config[
"type"] :
"string";
169 $disabled= isset($config[
"disabled"]) ? $config[
"disabled"] :
false;
170 $gridData[]= array(
"configId" => $key,
"configText" => $configText,
"value" => $value,
"type" => $type,
"disabled" => $disabled);
173 else if ($mode !=
"delete")
175 $config= $configOptions[$configId];
176 $configText= isset($config[
"text"]) ? $config[
"text"] : $configId;
177 $type= isset($config[
"type"]) ? $config[
"type"] :
"string";
178 $disabled= isset($config[
"disabled"]) ? $config[
"disabled"] :
false;
179 $gridData[]= array(
"configId" => $configId,
"configText" => $configText,
"value" => $value,
"type" => $type,
"disabled" => $disabled);
183 $errors[]=
"Options not coded correctly for $cu.";
185 $returnArray= array(
"error" => $errors,
"sql" => $sqls,
"operation" => $mode);
187 if ($mode !=
"delete")
188 $returnArray[
"record"]= $gridData;
193 $configLists= getConfigLists();
194 foreach($configOptions as $key => $record)
196 $record[
"value"]= $key;
197 $configDDL[]= $record;
199 $returnArray[
"configDDL"]= $configDDL;
200 $returnArray[
"configLists"]= $configLists;
206 function readLoanApplications($dbh)
208 $parameters= array();
209 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"cu" =>
"string"));
211 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
212 array(
"cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12)));
214 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
217 $sql=
"select asm.loanid, asm.cu, asm.loantitle, asm.loandisclosure_fragment, asm.lastmodified from lnappschemamaster asm order by case when cu = 'DMSTEMPL' then 0 else 1 end, cu, loanid";
221 $templateDDL= array(array(
"value" => 0,
"text" =>
"(None)"));
222 if (count($errors) == 0)
224 $results= runSelectStatement($sql, $dbh, array(
"loanid" =>
"loanId",
"cu" =>
"cu",
"loantitle" =>
"title",
"loandisclosure_fragment" =>
"fragment",
"lastmodified" =>
"lastModified"));
225 $errors= array_merge($errors, $results[
"error"]);
227 foreach($results[
"record"] as $record)
229 $templateDDL[]= array(
"value" => $record[
"loanId"],
"text" => $record[
'cu'] .
" - " . $record[
"title"]);
230 if (((strtoupper($cu) ==
'DMSTEMPL') && $record[
'cu'] ==
'DMSTEMPL') || $record[
"cu"] == strtoupper($cu))
232 unset($record[
"cu"]);
237 $templateDDL[]= array(
"value" =>
"",
"text" =>
"Blank");
240 return array(
"sql" => $sqls,
"error" => $errors,
"record" => $records,
"operation" =>
"read",
"templateDDL" => $templateDDL);
243 function createOrUpdateLoanApplication($dbh, $isCreate)
245 $parameters= array();
246 $allowed= array(
"title" =>
"string",
"fragment" =>
"string");
249 $allowed[
"cu"]=
"string";
250 $allowed[
"templateId"]=
"string";
254 $allowed[
"loanId"]=
"string";
256 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", $allowed);
259 $title= $parameters[
"BOTTOM_LEVEL"][
"title"];
260 $fragment= $parameters[
"BOTTOM_LEVEL"][
"fragment"];
263 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
264 array(
"cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12),
265 "title" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
266 "fragment" => array(
"type" =>
"string",
"required" =>
false,
"maxlength" => 50),
267 "templateId" => array(
"type" =>
"int",
"required" =>
false),
268 "loanId" => array(
"type" =>
"int",
"required" =>
true)));
270 $titleClean= $parameters[
"BOTTOM_LEVEL"][
"title"];
271 $fragmentClean= $parameters[
"BOTTOM_LEVEL"][
"fragment"];
273 if (count($errors) == 0)
277 $cu= $parameters[
"BOTTOM_LEVEL"][
"cu"];
278 $cuClean= $parameters[
"BOTTOM_LEVEL"][
"cu"];
279 $templateId= intval($parameters[
"BOTTOM_LEVEL"][
"templateId"]);
281 $sql=
"insert into lnappschemamaster (cu, loantitle, loandisclosure_fragment, lastmodified) values ('$cuClean', '$titleClean', '$fragmentClean', now()); 282 select currval('lnappschemamaster_loanid_seq'::regclass) as next";
284 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
285 $errors= array_merge($errors, $results[
"error"]);
286 $loanId= intval($results[
"record"][0][
"next"]);
288 if (count($errors) == 0 && $templateId != 0)
290 $sql=
"insert into lnappschemadetail(loanid, pageid, groupid, lineid, fieldtype, fieldvalue, fieldattr) select $loanId, pageid, groupid, lineid, fieldtype, fieldvalue, fieldattr 291 from lnappschemadetail where loanid = $templateId";
293 $results= runExecStatement($sql, $dbh);
294 $errors= array_merge($errors, $results[
"error"]);
299 $loanId= $parameters[
"BOTTOM_LEVEL"][
"loanId"];
301 $sql=
"update lnappschemamaster set loantitle= '$titleClean', loandisclosure_fragment= '$fragmentClean', lastmodified= now() where loanid= $loanId";
303 $results= runExecStatement($sql, $dbh);
304 $errors= array_merge($errors, $results[
"error"]);
307 return array(
"error" => $errors,
"sql" => $sqls,
"operation" => $isCreate ?
"create" :
"update",
"record" => array(array(
"loanId" => $loanId,
"title" => $title,
"fragment" => $fragment)));
310 function deleteLoanApplication($dbh)
312 $parameters= array();
313 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"loanId" =>
"string",
"cu" =>
"string"));
316 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
317 array(
"loanId" => array(
"type" =>
"int",
"required" =>
true),
318 "cu" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 12)));
320 $loanId= $parameters[
"BOTTOM_LEVEL"][
"loanId"];
321 $cu= strtolower($parameters[
"BOTTOM_LEVEL"][
"cu"]);
323 $sql=
"delete from lnappschemadetail where loanid = $loanId and exists (select 'FOUND' from lnappschemamaster where loanid = $loanId and lower(cu) = '$cu'); 324 delete from lnappschemamaster where loanid = $loanId and lower(cu) = '$cu'";
326 if (count($errors) == 0)
328 $results= runExecStatement($sql, $dbh);
329 $errors= array_merge($errors, $results[
"error"]);
332 return array(
"sql" => $sqls,
"error" => $errors,
"operation" =>
"delete");
335 function editSave($dbh)
337 $parameters= array();
338 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"loanid" =>
"string"));
339 $loanid= $parameters[
"BOTTOM_LEVEL"][
"loanid"];
350 $sql =
"DELETE FROM lnappschemadetail 351 WHERE loanid = " . intval($loanid) .
"; ";
353 foreach ($_POST[
'lnapp-item'] as $item_value) {
357 if ($item_value < 0) {
359 $sql .=
"INSERT INTO lnappschemadetail (loanid, pageid, groupid, lineid, fieldtype, fieldvalue, fieldattr) 361 ( " . intval($loanid) .
", 362 " . intval($_POST[
'lnapp-item-page-' . $item_value]) .
", 363 " . intval($_POST[
'lnapp-item-group-' . $item_value]) .
", 364 " . intval($_POST[
'lnapp-item-line-' . $item_value]) .
", 365 '" . prep_save($_POST[
'lnapp-item-fieldtype-' . $item_value], 10) .
"', 366 '" . prep_save($_POST[
'lnapp-item-fieldvalue-' . $item_value], 2000) .
"', 367 '" . prep_save($_POST[
'lnapp-item-fieldattr-' . $item_value], 3000) .
"' 371 $sql .=
"INSERT INTO lnappschemadetail (detailid, loanid, pageid, groupid, lineid, fieldtype, fieldvalue, fieldattr) 373 ( " . intval($item_value) .
", 374 " . intval($loanid) .
", 375 " . intval($_POST[
'lnapp-item-page-' . $item_value]) .
", 376 " . intval($_POST[
'lnapp-item-group-' . $item_value]) .
", 377 " . intval($_POST[
'lnapp-item-line-' . $item_value]) .
", 378 '" . prep_save($_POST[
'lnapp-item-fieldtype-' . $item_value], 10) .
"', 379 '" . prep_save($_POST[
'lnapp-item-fieldvalue-' . $item_value], 2000) .
"', 380 '" . prep_save($_POST[
'lnapp-item-fieldattr-' . $item_value], 3000) .
"' 386 $sql .=
"UPDATE lnappschemamaster 387 SET lastmodified = current_timestamp 388 WHERE loanid = " . intval($loanid) .
" ";
390 $results= runExecStatement($sql, $dbh);
391 if (count($results[
"error"]) > 0)
392 return array(
"Result" =>
"ERROR",
"sql" => array($sql),
"Message" => $results[
"error"][0]);
394 return array(
"Result" =>
"OK",
"sql" => array($sql));