13 require_once(
"$admLibrary/aGroupSupport.i");
18 "operation" => array(
"filter" => FILTER_SANITIZE_STRING),
19 "payload" => array(
"filter" => FILTER_SANITIZE_STRING)
21 HCU_ImportVars($admVars,
"GROUP_DELETE", $admOk);
23 $dOperation = isset($admVars[
"GROUP_DELETE"][
"operation"]) ? $admVars[
"GROUP_DELETE"][
"operation"] :
null;
24 $dPayload = isset($admVars[
"GROUP_DELETE"][
"payload"]) ? $admVars[
"GROUP_DELETE"][
"payload"] :
null;
30 GroupDecrypt($SYSENV, $Cu, $dPayload) :
34 $dContext = $dPayload ?
35 GroupContext($SYSENV, $Cu, $dGroup[
'group']) :
36 GroupContext($SYSENV, $Cu);
41 switch ($dOperation) {
46 header(
'Content-type: application/json');
48 $gDelete = GroupDelete($SYSENV, $dbh, $dContext);
49 $aryResult[
'data'][
'group'] = $gDelete[
'group'];
50 $aryResult[
'info'] = $gDelete[
'message'];
51 GroupReply($aryResult, $aryReply, $dOperation);
54 throw new Exception(
"Unknown server request: " . $dOperation);
58 }
catch (Exception $e) {
59 $aryReply[
'errors'][] = $e->getMessage();
60 $aryResult[
'data'] = array();
61 $aryResult[
'info'] = array();
63 GroupReply($aryResult, $aryReply, $dOperation);
66 function GroupDelete($pEnv, $pDbh, $pContext) {
67 $gId = $pContext[
'g_id'];
68 $pId = $pContext[
'p_id'];
69 $cuTable = $pContext[
'cu_table'];
70 $cuCode = $pContext[
'cu_code'];
74 DELETE FROM {$cuTable}group 80 group_name AS g_name";
82 $sqlDeleteRs = db_query($sqlDelete, $pDbh);
84 $pEnv[
'logger']->error(db_last_error());
85 throw new Exception(
"Failed to delete group.");
88 $sqlReturn[
'group'] = db_fetch_all($sqlDeleteRs)[0];
89 $sqlReturn[
'message'] =
"The following group has been deleted successfully:";
94 <?php
function PrintGroupDelete() { ?>
96 <div
class=
"hcu-template">
97 <div
class=
"hcu-edit-buttons k-state-default">
98 <span
class=
"hcu-icon-delete">
99 <!--<a href=
"##" id=
"lnkDelete">
100 <i
class=
"fa fa-trash fa-lg"></i>
103 <a href=
"##" id=
"lnkCancel">Cancel</a>
105 <a href=
"##" id=
"btnUpdate" class=
"k-button k-primary">
106 <i
class=
"fa fa-trash fa-lg"></i>
113 <div
id=
"gdInfo"></div>
115 <script type=
"text/x-kendo-template" id=
"gdOrphaned">
116 <div
class=
"col-sm-12">
117 <p>You are about to
remove this group from the system.</p>
118 <p>Do you wish to
continue?</p>
122 <script type=
"text/x-kendo-template" id=
"gdFull">
123 <div
class=
"col-sm-12">
124 <p>There are existing users in
this group.</p>
125 <p>Groups cannot be deleted
if there are users.
126 Use the Group Users card to view which users
127 are still
using this group.</p>
131 <script type=
"text/javascript">
132 var GroupDelete =
function() {
133 var gdCardContainer =
null;
134 var gdCardWindows =
null;
138 var gdPayload =
null;
141 var gdDataSource =
null;
145 var EventOpenWindow =
function(e) {
146 var windowElement = this.element[0];
147 var windowId = windowElement.id;
153 gdCardWindows.push(
this);
156 var EventCloseWindow =
function(e) {
157 var windowElement = this.element[0];
158 var windowId = windowElement.id;
161 case "deleteConfirm":
162 EventPopWindow(windowId);
164 operation:
"groupDelete",
168 gdDataSource.transport.options.read.type =
"POST";
169 gdDataSource.read(groupRequest);
172 EventPopWindow(windowId);
179 var EventPopWindow =
function(windowId) {
181 for (var i = 0; i < gdCardWindows.length; i++) {
182 var openWindow = gdCardWindows[i].element[0];
183 var openId = openWindow.id;
185 if (openId == windowId) {
192 gdCardWindows.splice(popIndex, 1);
196 var InitDataSources =
function() {
197 gdDataSource =
new kendo.data.DataSource({
202 contentType:
"application/x-www-form-urlencoded",
211 parse:
function(response) {
213 var resultData =
null;
214 var resultOperation =
null;
217 if (response.hasOwnProperty(
"Results")) {
218 results = response.Results;
219 resultData = results.data;
221 gdInfo.content(
"Error Parsing Server");
227 if (results.hasOwnProperty(
"errors")) {
228 gdInfo.content(results.errors);
235 content +=
"<p>" + results.info +
"</p>";
236 content +=
"<p></p>";
237 content +=
"<p><strong>" + gdGroup.g_name +
"</strong></p>";
239 gdInfo.content(content);
242 gdCall(
"removeGroupInfo");
243 gdCall(
"updateGroupResults", []);
251 var InitDataViews =
function() {
252 gdDelete = $(
"#gdDelete").kendoWindow({
253 title:
"Delete Group",
259 activate: EventOpenWindow,
260 close: EventCloseWindow
261 }).data(
"kendoWindow");
263 gdInfo = $(
"#gdInfo").kendoDialog({
264 title:
"Delete Group",
270 show: EventOpenWindow,
271 close: EventCloseWindow,
273 { text:
"Ok", primary:
true }
275 }).data(
"kendoDialog");
278 var InitDataActions =
function() {
279 $(
"#btnUpdate").off();
280 $(
"#btnUpdate").on(
"click",
function(e) {
282 if (gdGroup.g_count == 0) {
283 gdAction =
"deleteConfirm";
288 $(
"#lnkCancel").off();
289 $(
"#lnkCancel").on(
"click",
function(e) {
291 gdAction =
"deleteDeny";
296 this.Open =
function(windowStack) {
297 gdCardWindows = windowStack;
299 if (gdGroup.g_count == 0) {
300 $(
"#gdDelete").prepend(
301 $(
"#gdOrphaned").html()
304 $(
"#gdDelete").prepend(
309 var
template= kendo.template($(
"#titleTemplate").html());
310 gdGroup.cardTitle=
"Delete Group";
311 gdDelete.title(
template(gdGroup));
316 this.Close =
function() {
320 this.Data =
function(payload, group) {
325 this.Init =
function(hubCall, carContainer) {
327 gdCardContainer = carContainer;
333 gdCall(
"GroupDelete",
this);