26 extract($POSTED[
"HCUPOST"]);
28 $returnMsgData = Array();
29 switch ($POSTED[
'HCUPOST'][
'action']) {
31 if (!isset($Cu) || !isset($trustid)) {
32 throw new Exception(
'Missing Expected Parameters');
35 $where= array(
"providermode='$trustid'");
37 # should only be one record, but just in case, limit 1 40 $where[]=
"accountnumber='$member'";
44 $where[]=
"user_id=" . intval($userid);
46 $sql =
"select user_id as userid, id as keyid, trim(accountnumber) as accountnumber, parms from {$Cu}extkey 47 where " . implode(
" and ", $where) . ($doLimit ?
" limit 1" :
"");
49 $sqlRs = db_query($sql, $dbh);
51 throw new Exception(
"SQL failed ($sql).");
54 while ($dRecord = db_fetch_assoc($sqlRs, $sIdx)) {
61 $payload = $iClass->parms_parse($dRecord[
'parms']); #array(
'card4' => $card4,
'cardsig' => $cardsig,
'cardtype' => $cardtype);
62 $returnMsgData[] = $dRecord + $payload;
66 $retStatus_ary[
'homecuData'] = $returnMsgData;
76 if (!isset($Cu) || !isset($trustid) || !isset($accountnumber)) {
78 throw new Exception(
'Missing Expected Parameters');
85 $sql =
"SELECT count(*) as count_rec 86 FROM ${Cu}user where primary_account = '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"'";
87 $cntRs = db_query($sql, $dbh);
88 list($recordCount) = db_fetch_array($cntRs);
89 if ($recordCount == 0) {
90 throw new Exception(
'Unable to save entry, Invalid Member Number.');
94 $sql =
"SELECT count(*) as count_rec 96 WHERE accountnumber = '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"' 97 AND providermode = '" . prep_save($POSTED[
'HCUPOST'][
'trustid'], 20) .
"'";
98 $cntRs = db_query($sql, $dbh);
99 list($recordCount) = db_fetch_array($cntRs);
100 if ($recordCount > 0) {
101 throw new Exception(
'Unable to save entry, Only one entry per Member allowed.');
104 $payload = $iClass->parms_validate($POSTED[
'HCUPOST']);
105 if (is_array($payload[errors])) {
106 throw new exception(
"Multiple errors", 1);
109 $sql =
"INSERT INTO {$Cu}extkey (accountnumber, user_id, providermode, parms) 111 '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"', 112 '" . prep_save($POSTED[
'HCUPOST'][
'userid']) .
"', 113 '" . prep_save($POSTED[
'HCUPOST'][
'trustid'], 20) .
"', 114 '" . prep_save($payload[
'data']) .
"'); 115 select currval('${Cu}extkey_id_seq')";
116 $updRs = db_query($sql, $dbh);
120 throw new Exception(
'A problem occurred, unable to save entry.');
122 list($keyid) = db_fetch_array($updRs,0);
124 $retStatus_ary[
'homecuInfo'][] =
"Entry successfully saved.";
125 $retStatus_ary[
'homecuData'] = $iClass->parms_parse($payload[
'data']);
126 $retStatus_ary[
'homecuData'][
'keyid'] = $keyid;
127 $retStatus_ary[
'homecuData'][
'accountnumber'] = $POSTED[
'HCUPOST'][
'accountnumber'];
138 if (!isset($Cu) || !isset($trustid) || !isset($accountnumber)) {
140 throw new Exception(
'Missing Expected Parameters');
146 $sql =
"SELECT count(*) as count_rec 147 FROM ${Cu}user where primary_account = '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"'";
148 $cntRs = db_query($sql, $dbh);
149 list($recordCount) = db_fetch_array($cntRs);
150 if ($recordCount == 0) {
151 throw new Exception(
'Update failed, Invalid Member Number.');
155 $sql =
"SELECT count(*) as count_rec 157 WHERE accountnumber = '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"' 158 AND providermode = '" . prep_save($POSTED[
'HCUPOST'][
'trustid'], 20) .
"' 159 AND id <> {$POSTED['HCUPOST']['keyid']}";
160 $cntRs = db_query($sql, $dbh);
161 list($recordCount) = db_fetch_array($cntRs);
162 if ($recordCount > 0) {
163 throw new Exception(
'Update failed, Only one entry per Member allowed.');
166 $payload = $iClass->parms_validate($POSTED[
'HCUPOST']);
167 if (is_array($payload[errors])) {
168 throw new Exception(implode(
"<br>\n",$payload[errors]));
171 $sql =
"UPDATE {$Cu}extkey SET accountnumber = '" . prep_save($POSTED[
'HCUPOST'][
'accountnumber'], 12) .
"', 172 providermode = '" . prep_save($POSTED[
'HCUPOST'][
'trustid'], 20) .
"', 173 parms='" . prep_save($payload[
'data']) .
"' 174 WHERE id = {$POSTED['HCUPOST']['keyid']}";
175 $updRs = db_query($sql, $dbh);
178 throw new Exception(
'A problem occurred, update failed.');
179 } elseif (db_affected_rows($updRs) != 1) {
180 throw new Exception(
'Record not found.');
183 $retStatus_ary[
'homecuInfo'][] =
"Entry successfully updated.";
188 $sql =
"DELETE FROM {$Cu}extkey 189 WHERE id = {$POSTED['HCUPOST']['keyid']}";
191 $updRs = db_query($sql, $dbh);
194 throw new Exception(
'A problem occurred, delete failed.');
195 } elseif (db_affected_rows($updRs) != 1) {
196 throw new Exception(
'Record not found, delete failed.');
199 $retStatus_ary[
'homecuInfo'][] =
"Entry successfully deleted.";
205 throw new Exception(
"Unexpected action: {$action}. Action cancelled.");
209 }
catch (Exception $ex) {
210 if ($ex->getCode() == 1)
211 $retStatus_ary[
'homecuErrors']= $payload[errors];
213 $retStatus_ary[
'homecuErrors'][] = $ex->getMessage();
216 header(
'Content-type: application/json');
218 print json_encode(Array(
"Results" => Array($retStatus_ary)));