10 $monLibrary= dirname(__FILE__) .
"/../library";
11 $monIncludes= dirname(__FILE__) .
"/../includes";
12 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
13 require_once(
"$monLibrary/cu_top.i");
14 require_once(
"$monLibrary/ck_hticket.i");
15 require_once(
"$monIncludes/cu_remote_top.prg");
16 require_once(
"$sharedLibrary/commonPhpFunctions.i");
18 if (!CheckPerm($link, $Hu,
'loanAppConfig', $_SERVER[
'REMOTE_ADDR'])) {
21 header(
"Location: /hcuadm/hcu_noperm.prg");
25 HCU_ImportVars($DATA_PARAMETERS,
"TOP_LEVEL", array(
'operation' =>
'string'));
26 $operation= $DATA_PARAMETERS[
"TOP_LEVEL"][
'operation'];
32 $returnArray= read($dbh);
35 $returnArray= createTop($dbh);
38 $returnArray= updateTop($dbh);
41 $returnArray= createBottom($dbh);
44 $returnArray= updateBottom($dbh);
47 $returnArray= deleteTop($dbh);
50 $returnArray= deleteBottom($dbh);
52 default: $returnArray= array(
"sql" => array(),
"error" => array(
"Operation not specified: '$operation'"),
"record" =>
"",
"operation" =>
"");
56 unset($returnArray[
"sql"]);
57 header(
'Content-type: application/json');
58 print HCU_JsonEncode($returnArray);
63 $sql=
"select h.ansid, h.anstitle, d.ansdetailid, d.ansvalue, d.ansdisplay from lnappanslookupheader h left join lnappanslookupdetail d on h.ansid= d.ansid 64 order by h.anstitle, d.ansdisplay, ansvalue";
66 $results= runSelectStatement($sql, $dbh, array(
"ansid" =>
"topId",
"anstitle" =>
"topTitle",
"ansdetailid" =>
"bottomId",
"ansvalue" =>
"bottomValue",
"ansdisplay" =>
"bottomText"));
67 $errors= $results[
"error"];
72 foreach($results[
"record"] as $record)
74 if ($currentTopId != $record[
"topId"])
76 $currentTopId= $record[
"topId"];
77 $gridData[]= array(
"topId" => $currentTopId,
"topTitle" => $record[
"topTitle"]);
78 $tempArray[$currentTopId]= array();
81 if ($record[
"bottomId"] !=
"")
83 $tempArray[$currentTopId][]= array(
"bottomId" => $record[
"bottomId"],
"bottomValue" => $record[
"bottomValue"],
"bottomText" => $record[
"bottomText"],
"topId" => $record[
"topId"]);
87 for($i=0, $count= count($gridData); $i != $count; $i++)
89 $topId= $gridData[$i][
"topId"];
90 if (isset($tempArray[$topId]))
91 $gridData[$i][
"details"]= $tempArray[$topId];
93 $gridData[$i][
"details"]= array();
96 return array(
"error" => $errors,
"sql" => array($sql),
"record" => $gridData,
"operation" =>
"read");
100 function createTop($dbh)
102 $parameters= array();
103 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"topTitle" =>
"string"));
105 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
106 array(
"topTitle" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50)));
107 $topTitle= $parameters[
"BOTTOM_LEVEL"][
"topTitle"];
109 $sql=
"insert into lnappanslookupheader (anstitle) values ('$topTitle'); select currval('lnappanslookupheader_ansid_seq'::regclass) as next; ";
110 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
111 $topId= intval($results[
"record"][0][
"next"]);
112 $errors= array_merge($errors, $results[
"error"]);
114 Remote_Field_Add(
"lnappanslookupheader",
"ansid", $topId);
115 Remote_Field_Add(
"lnappanslookupheader",
"anstitle", $topTitle);
117 $Remote_Results = Remote_Update_All(
"U",
"lnappanslookupheader");
119 return array(
"error" => $errors,
"sql" => array($sql),
"operation" =>
"create",
"record" => array(array(
"topTitle" => $topTitle,
"topId" => $topId,
"details" => array())));
123 function updateTop($dbh)
125 $parameters= array();
126 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"topTitle" =>
"string",
"topId" =>
"string"));
128 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
129 array(
"topTitle" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
130 "topId" => array(
"type" =>
"int",
"required" =>
true)));
131 $topTitle= $parameters[
"BOTTOM_LEVEL"][
"topTitle"];
132 $topId= $parameters[
"BOTTOM_LEVEL"][
"topId"];
134 $sql=
"update lnappanslookupheader set anstitle = '$topTitle' where ansid = $topId";
135 $results= runExecStatement($sql, $dbh);
136 $errors= array_merge($errors, $results[
"error"]);
138 Remote_Field_Add(
"lnappanslookupheader",
"ansid", $topId);
139 Remote_Field_Add(
"lnappanslookupheader",
"anstitle", $topTitle);
141 $Remote_Results = Remote_Update_All(
"U",
"lnappanslookupheader");
143 return array(
"error" => $errors,
"sql" => array($sql),
"operation" =>
"update",
"record" => array(array(
"topTitle" => $topTitle,
"topId" => $topId)));
147 function createBottom($dbh)
149 $parameters= array();
150 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"bottomValue" =>
"string",
"bottomText" =>
"string",
"topId" =>
"string"));
152 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
153 array(
"bottomValue" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
154 "bottomText" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
155 "topId" => array(
"type" =>
"int",
"required" =>
true)));
156 $bottomValue= $parameters[
"BOTTOM_LEVEL"][
"bottomValue"];
157 $bottomText= $parameters[
"BOTTOM_LEVEL"][
"bottomText"];
158 $topId= $parameters[
"BOTTOM_LEVEL"][
"topId"];
160 $sql=
"insert into lnappanslookupdetail (ansvalue, ansdisplay, ansid) values ('$bottomValue', '$bottomText', $topId); select currval('lnappanswerlookupdetail_ansdetailid_seq'::regclass) as next;";
161 $results= runSelectStatement($sql, $dbh, array(
"next" =>
"next"));
162 $bottomId= intval($results[
"record"][0][
"next"]);
163 $errors= array_merge($errors, $results[
"error"]);
165 $record= array(
"bottomId" => $bottomId,
"bottomValue" => $bottomValue,
"bottomText" => $bottomText,
"topId" => $topId);
167 Remote_Field_Add(
"lnappanslookupdetail",
"ansid", $topId);
168 Remote_Field_Add(
"lnappanslookupdetail",
"ansdetailid", $bottomId);
169 Remote_Field_Add(
"lnappanslookupdetail",
"ansvalue", $bottomValue);
170 Remote_Field_Add(
"lnappanslookupdetail",
"ansdisplay", $bottomText);
172 Remote_Update_All(
"U",
"lnappanslookupdetail");
174 return array(
"error" => $errors,
"sql" => array($sql),
"operation" =>
"create",
"record" => array($record));
178 function updateBottom($dbh)
180 $parameters= array();
181 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"bottomValue" =>
"string",
"bottomText" =>
"string",
"bottomId" =>
"string"));
183 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
184 array(
"bottomValue" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
185 "bottomText" => array(
"type" =>
"string",
"required" =>
true,
"maxlength" => 50),
186 "bottomId" => array(
"type" =>
"int",
"required" =>
true),
187 "topId" => array(
"type" =>
"int",
"required" =>
true)));
188 $bottomValue= $parameters[
"BOTTOM_LEVEL"][
"bottomValue"];
189 $bottomText= $parameters[
"BOTTOM_LEVEL"][
"bottomText"];
190 $bottomId= $parameters[
"BOTTOM_LEVEL"][
"bottomId"];
192 $sql=
"update lnappanslookupdetail set ansvalue = '$bottomValue', ansdisplay = '$bottomText' where ansdetailid = $bottomId";
193 $results= runExecStatement($sql, $dbh);
194 $errors= array_merge($errors, $results[
"error"]);
196 $record= array(
"bottomId" => $bottomId,
"bottomValue" => $bottomValue,
"bottomText" => $bottomText);
198 Remote_Field_Add(
"lnappanslookupdetail",
"ansdetailid", $bottomId);
199 Remote_Field_Add(
"lnappanslookupdetail",
"ansvalue", $bottomValue);
200 Remote_Field_Add(
"lnappanslookupdetail",
"ansdisplay", $bottomText);
202 Remote_Update_All(
"U",
"lnappanslookupdetail");
204 return array(
"error" => $errors,
"sql" => array($sql),
"operation" =>
"update",
"record" => array($record));
208 function deleteTop($dbh)
210 $parameters= array();
211 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"topId" =>
"string",
"deleteDetails" =>
"string"));
213 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
214 array(
"topId" => array(
"type" =>
"int",
"required" =>
true),
215 "deleteDetails" => array(
"type" =>
"boolean",
"required" =>
false)));
217 $topId= $parameters[
"BOTTOM_LEVEL"][
"topId"];
218 $deleteDetails= $parameters[
"BOTTOM_LEVEL"][
"deleteDetails"] ==
"Y";
223 $sql1=
"select ansdetailid from lnappanslookupdetail where ansid = $topId";
224 $results1= runSelectStatement($sql1, $dbh, array(
"ansdetailid" =>
"id"));
225 $sql2=
"delete from lnappanslookupdetail where ansid = $topId";
226 $results2= runExecStatement($sql2, $dbh);
227 $errors= array_merge($errors, $results1[
"error"], $results2[
"error"]);
228 array_push($sqls, $sql1, $sql2);
230 foreach($results1[
"record"] as $record)
232 Remote_Field_Add(
"lnappanslookupdetail",
"ansdetailid", $record[
"id"]);
233 Remote_Update_All(
"D",
"lnappanslookupdetail");
237 $sql=
"delete from lnappanslookupheader where ansid = $topId";
239 $results= runExecStatement($sql, $dbh);
240 $errors= array_merge($errors, $results[
"error"]);
242 Remote_Field_Add(
"lnappanslookupheader",
"ansid", $topId);
243 Remote_Update_All(
"D",
"lnappanslookupheader");
245 return array(
"error" => $errors,
"sql" => $sqls,
"operation" =>
"delete");
249 function deleteBottom($dbh)
251 $parameters= array();
252 HCU_ImportVars($parameters,
"BOTTOM_LEVEL", array(
"bottomId" =>
"string"));
254 $errors= cleanValuesForDatabase($parameters[
"BOTTOM_LEVEL"],
255 array(
"bottomId" => array(
"type" =>
"int",
"required" =>
true)));
257 $bottomId= $parameters[
"BOTTOM_LEVEL"][
"bottomId"];
259 $sql=
"delete from lnappanslookupdetail where ansdetailid = $bottomId";
260 $results= runExecStatement($sql, $dbh);
262 Remote_Field_Add(
"lnappanslookupdetail",
"ansdetailid", $bottomId);
263 Remote_Update_All(
"D",
"lnappanslookupdetail");
265 return array(
"error" => array_merge($errors, $results[
"error"]),
"sql" => array($sql),
"operation" =>
"delete");