Odyssey
servSettings.prg
1 <?php
2 /* File: cutrustdetail.v2 meant to replace cutrustvendor
3  * SPB, 10/6/2015-- Added version 2 with kendo
4 */
5 
6  $monLibrary= dirname(__FILE__) . "/../library";
7  $sharedLibrary= dirname(__FILE__) . "/../../shared/library";
8  require_once("$monLibrary/cu_top.i");
9  require_once("$monLibrary/ck_hticket.i");
10  require_once("$monLibrary/monitorView.i");
11  require_once("$sharedLibrary/commonJsFunctions.i");
12 
13  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
14  // ** Permissions failed
15  // ** redirect to new page
16  header("Location: /hcuadm/hcu_noperm.prg");
17  exit;
18  }
19 
20 // Globals
21 $dataFile= "cutrustdetail.data";
22 $dataPath= "/hcuadm/$dataFile";
23 $showSQL= false;
24 
25 dms_import_v2($DATA_PARAMETERS, "TOP_LEVEL", array("user_name" => "string"));
26 $cu= strtoupper($DATA_PARAMETERS["TOP_LEVEL"]["user_name"]);
27 printMonitorPageTop("Home CU Services", $homecuKendoVersion, $cloudfrontDomainName);
28 ?>
29 
30 <style>
31  .popupForm .grid_12 {
32  margin-bottom: 5px;
33  }
34 
35  .k-grid tbody .k-button {
36  min-width: 20px !important; /* override */
37  }
38 
39  #defaultValueGrid thead {
40  display: none;
41  }
42 
43  #defaultValueGrid tbody tr {
44  height: 50px;
45  }
46 
47  #defaultValueGrid .k-grid-customDelete {
48  position: relative;
49  left: -5px;
50  }
51 
52  .k-pager-numbers.k-reset {
53  font-family: Arial, Helvetica, sans-serif !important;
54  font-size: 10pt !important;
55  font-style: normal !important;
56  font-variant: normal !important;
57  font-weight: normal !important;
58  }
59 
60  .k-pager-wrap {
61  height: 24px;
62  line-height: 20px;
63  }
64 
65  .k-pager-nav {
66  margin-top: 4px !important;
67  height: 15px !important;
68  width: 15px !important;
69  }
70 
71  .k-link.k-pager-nav .k-icon {
72  top: -2px !important;
73  }
74 
75  .k-pager-nav .k-icon {
76  margin-top: auto;
77  margin-bottom: auto;
78  margin-left: auto;
79  margin-right: auto;
80  }
81 
82  .homecu-formStatus {
83  margin: 5px;
84  padding: 5px;
85  }
86 
87  #accordion {
88  border-color: rgb(204, 204, 204);
89  background-color: rgb(238, 238, 238);
90  border-radius: 6px;
91  color: rgb(51, 131, 187) !important;
92  display: block;
93  font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, sans-serif;
94  font-size: 11px;
95  font-weight: bold;
96  }
97 
98  #deleteDialogWindow .message {
99  text-align: center;
100  }
101 
102  #deleteDialogWindow .k-edit-buttons {
103  text-align: center;
104  }
105 </style>
106 
107 <script type="text/javascript">
108 
109 <?php
110 // Include common functions
111 getErrorsAreShownFunction();
112 getSetupDeleteConfirmDialogFunction();
113 getAddMinifiedActionStyleFunction();
114 getEscapeHTMLFunction();
115 getShowSQLFunction($showSQL);
116 getSetupValidatorInGridFunction();
117 getUseValidatorInGridFunction();
118 getShowWaitFunctions();
119 ?>
120 
121 <?php /* This initializes the grid. */ ?>
122 function initGrid()
123 {
124  var defaultsDDL= [];
125  var serverOptions= [];
126  var serviceUpdateOptions= [];
127  var initialized= false;
128  var initializeDDLs= "Y";
129 
130  var grid= $("#grid").kendoGrid({
131  dataSource: {
132  transport: {
133  read: {
134  url: "<?php echo $dataPath; ?>?operation=readServerSettings",
135  dataType: "json",
136  type: "POST"
137  },
138  create: {
139  url: "<?php echo $dataPath; ?>?operation=addServerSetting",
140  dataType: "json",
141  type: "POST"
142  },
143  update: {
144  url: "<?php echo $dataPath; ?>?operation=updateServerSetting",
145  dataType: "json",
146  type: "POST"
147  },
148  parameterMap: function(data, type) {
149  showWaitWindow();
150  if (type == "read")
151  return {initializeDDLs: initializeDDLs};
152  else if (type = "create")
153  return data;
154  }
155  },
156  schema: {
157  model: {
158  id: "property",
159  fields: {
160  property: {type: "string"},
161  value: {type: "string"},
162  text: {type: "string"},
163  message: {type: "string"}
164  }
165  },
166  parse: function (data) {
167  hideWaitWindow();
168  var append= false;
169  var gridData= [];
170  if (data.operation == "read")
171  {
172  if (initializeDDLs == "Y")
173  {
174  defaultsDDL= data.defaultsDDL;
175  serverOptions= data.serverOptions;
176  serviceUpdateOptions= data.serviceUpdateOptions;
177  initializeDDLs= "N";
178  }
179  else append= true;
180  gridData= data.record;
181  }
182  else
183  {
184  gridData= grid.dataSource.data();
185  }
186 
187  showSQL(data, append);
188 
189  if (errorsAreShown(data, "formValidateMainDiv"))
190  $("#invalidRequestServerSide").val(true);
191  else
192  {
193  $("#invalidRequestServerSide").val(false);
194  var limitedDefaultsDDL= [];
195  var lookup= {};
196  for (var i=0; i!= gridData.length; i++)
197  {
198  lookup[gridData[i].property]= true;
199  }
200  for (var i=0; i!= defaultsDDL.length; i++)
201  {
202  if (typeof(lookup[defaultsDDL[i].property]) == "undefined")
203  limitedDefaultsDDL.push(defaultsDDL[i]);
204  }
205 
206  if (limitedDefaultsDDL.length == 0)
207  $("#grid .k-grid-add").hide();
208  else
209  $("#grid .k-grid-add").show();
210  }
211  return data.record;
212  }
213  },
214  sort: {field: "property", dir: "asc"}
215  },
216  columns: [
217  {command: [{name: "edit", text: ""}, {name: "customDelete", text: "", iconClass: "k-icon k-i-delete"}], width: "100px"},
218  {field: "property", title: "Property"},
219  {field: "text", title: "Value"},
220  {field: "message", title: "Offline Message"}
221  ],
222  toolbar: [{name: "create", text: ""}, {name: "serviceUpdate", text: "Service Update"}],
223  editable: {
224  mode: "popup",
225  template: kendo.template($("#popupTemplate").html()),
226  window: {
227  draggable: false,
228  resizable: false,
229  title: "<span class='gridWindowTitle'>Add Service Property</span>",
230  actions: [],
231  width: 400
232  }
233  },
234  edit: function (e) {
235  setupValidatorInGrid(e, false);
236 
237  var valueDDL= $("#valueDDL").kendoDropDownList({
238  dataSource: {
239  data: serverOptions
240  },
241  dataTextField: "text",
242  dataValueField: "value",
243  change: function () {
244  e.model.value= this.value();
245  e.model.text= this.text();
246  e.model.dirty= true;
247  }
248  }).data("kendoDropDownList");
249 
250  if (e.model.isNew())
251  {
252  $(".gridWindowTitle").text("Add Service Property");
253  $("#propertyLabel").remove();
254 
255  e.model.value= valueDDL.value();
256  e.model.text= valueDDL.text();
257 
258  var limitedDefaultsDDL= [];
259  var lookup= {};
260  var data= grid.dataSource.data();
261  for (var i=0; i!= data.length; i++)
262  {
263  lookup[data[i].property]= true;
264  }
265  for (var i=0; i!= defaultsDDL.length; i++)
266  {
267  if (typeof(lookup[defaultsDDL[i].property]) == "undefined")
268  limitedDefaultsDDL.push(defaultsDDL[i]);
269  }
270  var propertyDDL= $("#propertyDDL").kendoDropDownList({
271  dataSource: {
272  data: limitedDefaultsDDL,
273  schema: {
274  model: {
275  id: "property",
276  fields: {
277  property: {type: "string"},
278  defaultValue: {type: "string"},
279  defaultMessage: {type: "string"}
280  }
281  }
282  }
283  },
284  filter: "startswith",
285  dataTextField: "property",
286  dataValueField: "property",
287  dataBound: function () {
288  var dataItem= this.dataItem();
289  if (typeof(dataItem) != "undefined")
290  {
291  valueDDL.value(dataItem.defaultValue);
292  $("[name='message']").text(dataItem.defaultMessage);
293  e.model.value= dataItem.defaultValue;
294  e.model.message= dataItem.defaultMessage;
295  e.model.text= valueDDL.text();
296  e.model.property= this.value();
297  }
298  },
299  change: function () {
300  var dataItem= this.dataItem();
301  if (typeof(dataItem) != "undefined")
302  {
303  valueDDL.value(dataItem.defaultValue);
304  $("[name='message']").text(dataItem.defaultMessage);
305  e.model.value= dataItem.defaultValue;
306  e.model.message= dataItem.defaultMessage;
307  e.model.text= valueDDL.text();
308  e.model.property= this.value();
309  }
310  },
311  }).data("kendoDropDownList");
312  }
313  else
314  {
315  $(".gridWindowTitle").text("Edit Service Property");
316  $("#propertyDDL").remove();
317 
318  valueDDL.value(e.model.value);
319  }
320  },
321  save: function (e) {
322  useValidatorInGrid(e, false);
323  },
324  dataBound: function (e) {
325 
326  if (!initialized)
327  {
328  addMinifiedActionStyle("#grid", true);
329  initialized= true;
330  }
331  setupDeleteConfirmDialog("<?php echo $dataPath; ?>?operation=removeServerSetting", "#grid", "property", "deleteDialogWindow", function () { $("#grid .k-grid-add").show(); });
332  }
333  }).data("kendoGrid");
334 
335  $("#grid .k-grid-serviceUpdate").click(function () {
336  openServiceUpdateModal(serviceUpdateOptions);
337  return false;
338  });
339 }
340 
341 <?php /* This opens the dialog to update all records. */ ?>
342 function openServiceUpdateModal(serviceUpdateOptions)
343 {
344  var serviceUpdateModal= $("#serviceUpdateModal").data("kendoWindow");
345  var ddl= $("#updateAllDDL").data("kendoDropDownList");
346  if (serviceUpdateModal == null)
347  {
348  serviceUpdateModal= $("<div id='serviceUpdateModal'></div>").kendoWindow({
349  content: {
350  template: kendo.template($("#serviceUpdateTemplate").html())
351  },
352  modal: true,
353  title: "Service Update",
354  visible: false,
355  actions: [],
356  draggable: false,
357  resizable: false,
358  width: 355
359  }).data("kendoWindow");
360 
361  ddl= $("#updateAllDDL").kendoDropDownList({
362  dataSource: {
363  data: serviceUpdateOptions
364  },
365  filter: "startswith",
366  dataTextField: "text",
367  dataValueField: "value"
368  }).data("kendoDropDownList");
369 
370  $("#serviceUpdateModal .updateBtn").click(function () {
371 
372  $.post("<?php echo $dataPath; ?>?operation=serviceUpdate", {isTurnOff: ddl.value()}, function (data) {
373  showSQL(data);
374 
375  if (!errorsAreShown(data, "formValidateMainDiv"))
376  $("#grid").data("kendoGrid").dataSource.read();
377  });
378 
379  serviceUpdateModal.close();
380  return false;
381  });
382 
383  $("#serviceUpdateModal .cancelBtn").click(function () {
384  serviceUpdateModal.close();
385  return false;
386  });
387  }
388 
389  serviceUpdateModal.open().center();
390 }
391 
392 <?php /* This initializes the accordion. */ ?>
393 function initAccordion()
394 {
395  var accordion= $("#accordion").kendoPanelBar({}).data("kendoPanelBar");
396  $(".insertList:eq(0)").html($("#list1Template").html());
397  $(".insertList:eq(1)").html($("#list2Template").html());
398 }
399 
400 
401 $(document).ready(function () {
402  initAccordion();
403  initGrid();
404 });
405 </script>
406 
407 <script id="deleteConfirmTemplate" type="text/x-kendo-template">
408  <div class="k-edit-form-container">
409  <div class="container_12">
410  <div class="grid_12 message">Are you sure that you want to delete?
411  </div>
412  <div class="k-edit-buttons k-state-default">
413  <a class="k-button k-button-icontext deleteConfirmContinueBtn" href="\#">
414  <span class="k-icon k-i-check"></span>
415  Continue
416  </a>
417  <a class="k-button k-button-icontext deleteConfirmCancelBtn" href="\#">
418  <span class="k-icon k-i-cancel"></span>
419  Cancel
420  </a>
421  </div>
422  </div>
423 </script>
424 <script id="serviceUpdateTemplate" type="text/x-kendo-template">
425  <div class="k-edit-form-container">
426  <div class="container_12">
427  <div class="grid_12">
428  <div class="grid_4 alpha">
429  <label>Update All:</label>
430  </div>
431  <div class="grid_7">
432  <div id="updateAllDDL"></div>
433  </div>
434  </div>
435  </div>
436  <div class="k-edit-buttons k-state-default" style="width:320px;">
437  <a class="k-button k-button-icontext updateBtn" href="\#">
438  <span class="k-icon k-i-check"></span>
439  Update
440  </a>
441  <a class="k-button k-button-icontext cancelBtn" href="\#">
442  <span class="k-icon k-i-cancel"></span>
443  Cancel
444  </a>
445  </div>
446  </div>
447 </script>
448 <script id="popupTemplate" type="text/x-kendo-template">
449  <div id="formValidatePopupDiv" class="homecu-formStatus k-block k-error-colored" style="display:none;"></div>
450  <form id="popupForm" class="popupForm" data-role="validator" novalidate>
451  <div class="container_12">
452  <div class="grid_12">
453  <div class="grid_4 alpha">
454  <label>Id:</label>
455  </div>
456  <div class="grid_7">
457  <div id="propertyLabel">#: property #</div>
458  <div id="propertyDDL"></div>
459  </div>
460  </div>
461  <div class="grid_12">
462  <div class="grid_4 alpha">
463  <label>Value:</label>
464  </div>
465  <div class="grid_7">
466  <div id="valueDDL"></div>
467  </div>
468  </div>
469  <div class="grid_12">
470  <div class="grid_4 alpha">
471  <label>Message:</label>
472  </div>
473  <div class="grid_7">
474  <textarea name="message"></textarea>
475  </div>
476  </div>
477  </div>
478  </form>
479 </script>
480 <script id="list1Template" type="text/x-kendo-template">
481  <ul>
482  <li>
483  <h4>No Change</h4>
484  <p>This will have no affect on the status of the services.</p>
485  </li>
486  <li>
487  <h4>Turn On</h4>
488  <p>This will set any service, NOT set to Offline (Stay Down), to Active.</p>
489  </li>
490  <li>
491  <h4>Turn Off</h4>
492  <p>This will set any service, set to Active, to Offline (Auto Up).</p>
493  </li>
494  </ul>
495 </script>
496 <script id="list2Template" type="text/x-kendo-template">
497  <ul>
498  <li>
499  <h3>Value</h3>
500  <ul>
501  <li>
502  <h4>Active</h4>
503  <p>This option marks the service as Active, and the hcu_checkService will return a true. Meaning the service should be on-line.</p>
504  </li>
505  <li>
506  <h4>Offline (Auto Up)</h4>
507  <p>This option marks the service as offline, and the hcu_checkService will return a false, and the service is considered offline.
508  However, if the HOMECUSERVICE update above is used and the status is set to On. Then this service will change to Active.</p>
509  </li>
510  <li>
511  <h4>Offline (Stay Down)</h4>
512  <p>This option marks the service as offline, and the hcu_checkService will return a false, and the service is considered offline.
513  However, changing the HOMECUSERVICE update above will have no affect on this servce.</p>
514  </li>
515  </ul>
516  </li>
517  <li>
518  <h3>Offline Message</h3>
519  <p>If you want a custom message for this service while it is offline, you can set the message here. This message is returned from the hcu_checkServiceMsg function when specifying the service.
520  Entering a value in this field creates a {SERVICE}_MSG entry in the cutrustdetail settings array with the string you enter.</p>
521  </li>
522  </ul>
523 </script>
524 
525 <?php printMonitorPageMiddle("Home CU Services"); ?>
526 
527  <div id='hideSubmitWait' style='position:relative; left:-2000px;top:-2000px;'>
528  <div id='homecuSubmitWait' class='k-block' >
529  <div class='k-loading-image'></div>
530  </div>
531  </div>
532  <input type="hidden" id="invalidRequestClientSide">
533  <input type="hidden" id="invalidRequestServerSide">
534  <div class="container_12">
535  <div class="grid_12">
536  <div class="grid_7 alpha omega">
537  <ul id='accordion'>
538  <li>What does this do
539  <ul>
540  <li>
541  <p>
542  This page will allow you to turn off all or a select service for the individual server.<br/>
543  Each server has their own service settings and need to be configured separately.<br/>
544  </p>
545  </li>
546  </ul>
547  </li>
548  <li>How to use
549  <ul>
550  <li>
551  <p>
552  <h2>How to turn on/off ALL services for this server.</h2></br>
553  On the HOMECUSERVICE row click on the 'edit' link.<br/>
554  A form with the following options appears<br/>
555  <span class="insertList"></span>
556 
557  <h2>How to turn on/off per server.</h2></br>
558  On the HOMECUSERVICE row click on the 'expand' link on the left.<br/>
559  A table will expand with all the services setup on the server.<br/>
560  When you find the row you are looking for, click on the 'edit' link. If you don't find the service click 'Add new record'<br/>
561  <span style='color: #770000;'>NOTE *** The list will not include any service ending in _MSG, these codes are reserved for storing the offline message</span>
562  <span class="insertList"></span>
563  </p>
564  </li>
565  </ul>
566  </li>
567  </ul>
568  </div></div>
569  <div class="grid_12">
570  &nbsp;
571  </div>
572  <div class="grid_12">
573  <div class="grid_7 alpha omega">
574  <div id="sqlOutput"></div>
575  </div>
576  </div>
577  <div class="grid_12">
578  <div class="grid_7 alpha omega">
579  <div id="formValidateMainDiv" class="k-block k-error-colored" style="display:none;"></div>
580  </div>
581  </div>
582  <div class="grid_12">
583  <div class="grid_7 alpha omega">
584  <div id="grid" style="width:100%"></div>
585  </div>
586  </div>
587  </div>
588 
589 <?php printMonitorPageBottom(); ?>