9 $string = array(
"filter" => HCUFILTER_INPUT_STRING);
10 $parameters = array(
"a" => array(
"operation" =>
"",
"payload" =>
""));
11 HCU_ImportVars($parameters,
"a", array(
"operation" => $string,
"payload" => $string));
12 extract($parameters[
"a"]);
14 $operation = !isset($operation) ?
"" : trim($operation);
15 $payload = !isset($payload) ?
"" : trim($payload);
18 try { $userId = HCU_PayloadDecode($Cu, $payload); }
catch(exception $e) {}
19 $userId = isset($userId) ? $userId[
"user_id"] :
null;
20 $showSQL = $SYSENV[
"devmode"];
22 if ($operation !=
"") {
26 $returnArray = deleteUser($dbh, $Cu, $userId, $Cn);
29 $returnArray = array(
"error" => array(
"Operation not specified: '$operation'"),
"record" => array(),
"sql" => array());
32 $returnArray = array(
"error" =>
"No User Found",
"record" => array(),
"sql" => array());
35 header(
'Content-type: application/json');
37 unset($returnArray[
"sql"]);
39 print HCU_JsonEncode($returnArray);
42 $isPrimary = getIsPrimary($dbh, $Cu, $userId);
43 $isPrimary = $isPrimary[
"code"] == 0 ? $isPrimary[
"isPrimary"] :
false;
44 printPage(
"$menu_link?ft=$ft", $userId, $isPrimary,
"$menu_link?ft=22", $payload);
46 <div
class=
'noUserFound'><div>No
User Found</div></div>
60 function getIsPrimary($dbh, $Cu, $userId) {
63 $sql =
"select is_group_primary from ${Cu}user where user_id = $userId";
65 $sth = db_query($sql, $dbh);
67 throw new exception(
"Select query failed.", 1);
69 if (db_num_rows($sth) == 0) {
70 throw new exception(
"User not found.", 2);
72 $isPrimary = trim(db_fetch_row($sth, 0)[0]) ==
"t";
73 }
catch(exception $e) {
74 return array(
"error" => array($e->getMessage()),
"code" => $e->getCode());
76 return array(
"error" => array(),
"code" => 0,
"isPrimary" => $isPrimary);
95 function createHighLevelDeleteAuditRecord($dbh, $Cu, $Cn, $userId, $shortCode, $longDescription, &$sqls, &$email, $before) {
96 if (!isset($email) || trim($email) ==
"") {
97 $sql =
"select email from cuadminusers where user_name = '$Cn' and cu = '$Cu'";
99 $sth = db_query($sql, $dbh);
101 throw new exception(
"email query failed.", 105);
103 $email = trim(db_fetch_row($sth)[0]);
107 $script =
"userSupportDelete.prg";
108 $addr = trim($_SERVER[
"REMOTE_ADDR"]);
109 $vars = array(
"cu" => $Cu);
111 $auditRecord = SetAuditRecord($dbh, array(
"cu" => $Cu),
null, $userId, $shortCode,
"admin",
"userSupportDelete.prg",
"A", $longDescription, $Cn, $email,
112 trim($_SERVER[
"REMOTE_ADDR"]), $before,
null);
113 if ($auditRecord[
"code"] !=
"000") {
114 throw new exception(
"Audit record creation failed.", 104);
131 function deleteUser($dbh, $Cu, $userId, $Cn) {
134 if (!isset($userId) || !is_numeric($userId) || $userId <= 0) {
135 throw new exception(
"UserId must be set to a valid number.", 3);
138 $sql =
"select u.group_id, u.is_group_primary, u.user_name, g.group_name from ${Cu}user u 139 inner join ${Cu}group g on u.group_id = g.group_id where u.user_id = $userId";
141 $sth = db_query($sql, $dbh);
143 throw new exception(
"select query failed.", 4);
145 $row = db_fetch_assoc($sth, 0);
146 $groupId = isset($row[
"group_id"]) ? intval($row[
"group_id"]) : 0;
147 $isPrimary = !isset($row[
"is_group_primary"]) ? false : trim($row[
"is_group_primary"]) ==
"t";
148 $username = trim($row[
"user_name"]);
149 $groupname = trim($row[
"group_name"]);
151 $nonPrimaryUsers = array();
154 $sql =
"select user_id, user_name from ${Cu}user where group_id = $groupId and user_id <> $userId";
156 $sth = db_query($sql, $dbh);
158 throw new exception(
"non primary query failed.", 5);
160 for($i = 0; $row = db_fetch_row($sth, $i); $i++) {
161 $nonPrimaryUsers[] = $row;
164 $sql =
"select distinct accountnumber from ${Cu}useraccounts where user_id = $userId";
166 $sth = db_query($sql, $dbh);
168 throw new exception(
"distinct accountnumber query failed.", 6);
170 for($i = 0; $row = db_fetch_row($sth, $i); $i++) {
171 $accounts[] = trim($row[0]);
177 $sth = db_query($sql, $dbh);
179 throw new exception(
"Begin work failed.", 134);
183 foreach($nonPrimaryUsers as $nonPrimaryUserRow) {
184 $nonPrimaryUser = trim($nonPrimaryUserRow[0]);
185 userDeletion($dbh, $Cu, $nonPrimaryUser, $sqls);
186 $before = HCU_JsonEncode(array(
"deldata" => array(
"user_name" => $nonPrimaryUserRow[1])));
187 createHighLevelDeleteAuditRecord($dbh, $Cu, $Cn, $nonPrimaryUser,
"U_DEL_U",
"User Login Deleted", $sqls, $email, $before);
191 userDeletion($dbh, $Cu, $userId, $sqls);
192 $before = HCU_JsonEncode(array(
"deldata" => array(
"user_name" => $username)));
193 createHighLevelDeleteAuditRecord($dbh, $Cu, $Cn, $userId,
"U_DEL_U",
"User Login Deleted", $sqls, $email, $before);
196 groupDeletion($dbh, $Cu, $groupId, $sqls);
197 $before = HCU_JsonEncode(array(
"deldata" => array(
"group_name" => $groupname,
"user_name" => $username)));
198 createHighLevelDeleteAuditRecord($dbh, $Cu, $Cn, $userId,
"U_DEL_G",
"Group Deleted", $sqls, $email, $before);
200 foreach ($accounts as $accountnumber) {
201 if (checkAccountUsage($dbh, $Cu, $userId, $accountnumber, $sqls)) {
202 accountDeletion($dbh, $Cu, $accountnumber, $sqls);
203 $before = HCU_JsonEncode(array(
"deldata" => array(
"accountnumber" => $accountnumber,
"user_name" => $username)));
204 createHighLevelDeleteAuditRecord($dbh, $Cu, $Cn, $userId,
"U_DEL_A",
"Account Deleted", $sqls, $email, $before);
209 $sql =
"commit work";
211 $sth = db_query($sql, $dbh);
213 throw new exception(
"commit work failed.", 135);
215 }
catch (exception $e) {
216 if ($e->getCode() >= 100) {
217 $sql =
"rollback work";
219 db_query($sql, $dbh);
220 return array(
"error" => array(
"Deletion was not successful."),
"code" => 101,
"sql" => $sqls);
222 return array(
"error" => array($e->getMessage()),
"code" => $e->getCode(),
"sql" => $sqls);
224 return array(
"error" => array(),
"code" => 0,
"sql" => $sqls);
237 function printPage($self, $userId, $primaryUser, $userReset, $payload) { ?>
238 <script type=
"text/javascript">
248 $.homecuValidator.setup({formValidate:
"deleteDiv", formStatusField:
"formValidateDiv"});
249 $(
"#externalTabWindow").data(
"preferredHeight",
"auto");
250 $(
".deleteDiv").on(
"click",
".cancelBtn",
function() {
255 $(
".deleteDiv").on(
"click",
".deleteBtn",
function() {
270 function openFailDialog(errors, title) {
271 var failDialog = $(
"#failDialog").data(
"kendoDialog");
272 if (failDialog ==
null) {
273 failDialog = $(
"<div id='failDialog'></div>").appendTo(
"body").kendoDialog({
278 if (window.activeWindows !=
null) {
279 window.activeWindows.push(
this);
283 if (window.activeWindows !=
null) {
284 window.activeWindows.pop();
290 }).data(
"kendoDialog");
293 var content = errors ==
null ?
"" : (typeof(errors) ==
"string" ? errors.trim() : (errors.length <=1 ? errors.join(
"").trim() :
"<ul><li>" + errors.join(
"</li><li>") +
"</li></ul>"));
294 failDialog.title(title).content(content).open();
303 function openConfirm() {
304 var confirmDialog = $(
"#confirmDeleteDialog").data(
"kendoDialog");
306 if (confirmDialog ==
null) {
307 <?php
if ($primaryUser) { ?>
310 content +=
"<p>This user is a group primary user.</p>";
311 content +=
"<p>Deleting this user will result in the following:</p>";
312 content +=
"<ul style=\"margin-left: 15px;\"><li>Delete primary user</li><li>Delete group</li><li>Delete all other users in the group</li>" 313 content +=
"<li>Delete the primary user's account(s) if no other users reference the account(s)</li></ul>";
314 content +=
"<p>Do you wish to continue?</p>";
318 var content =
"<p>You are about to delete this user.</p><p>Do you wish to continue?</p>";
322 confirmDialog = $(
"<div id='confirmDeleteDialog'></div>").appendTo(
"body").kendoDialog({
324 actions: [{text:
"No"}, {text:
"Yes", primary:
true, action:
function() {
325 confirmDialog.close();
327 $.post(
"<?php echo $self; ?>&operation=deleteUser", {payload:
"<?php echo $payload; ?>"},
function(data) {
329 if (data.error.length > 0) {
330 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
332 window.location.href=
"<?php echo $userReset; ?>";
339 if (window.activeWindows !=
null) {
340 window.activeWindows.push(
this);
344 if (window.activeWindows !=
null) {
345 window.activeWindows.pop();
348 title:
"Confirm User Removal",
352 }).data(
"kendoDialog");
354 confirmDialog.open();
363 function postPostPostPost() {
364 $(
"#externalTabWindow").data(
"isClosing",
true);
365 $(
"#externalTabWindow").data(
"kendoWindow").close();
366 $(
"#externalTabWindow").data(
"isClosing",
false);
372 <div
class=
"container hcu-all-100 deleteDiv vsgPrimary hcu-template" id=
"deleteDiv">
373 <div
class=
"row notificationRow hcuSpacer"></div>
375 <div
id=
"formValidateDiv" class=
"k-block k-error-colored formValidateDiv" style=
"display:none"></div>
378 <?php echo $primaryUser ?
"Delete this primary user, all users in the group, the group, and the account if no more users reference the account." 379 :
"Delete this non-primary user."; ?>
381 <div
class=
"hcu-edit-buttons k-state-default row">
382 <a
class=
"cancelBtn" href=
"#">Cancel</a> <a
class=
"deleteBtn k-button k-primary" href=
"#"><i
class=
"fa fa-trash"></i>Delete</a>