index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. if (cfr('SWITCHGROUPS')) {
  3. if ($ubillingConfig->getAlterParam('SWITCH_GROUPS_ENABLED')) {
  4. $switchGroups = new SwitchGroups();
  5. if (wf_CheckGet(array('ajax'))) {
  6. $swGroupsData = $switchGroups->getSwitchGroupsData('', true);
  7. $switchGroups->renderJSON($swGroupsData);
  8. }
  9. if (wf_CheckPost(array('swgroupcreate'))) {
  10. if (wf_CheckPost(array('swgroupname'))) {
  11. $newSwitchGroupName = $_POST['swgroupname'];
  12. $foundId = $switchGroups->checkSwitchGroupNameExists($newSwitchGroupName);
  13. if (empty($foundId)) {
  14. $switchGroups->addSwitchGroup($newSwitchGroupName, $_POST['swgroupdescr']);
  15. die();
  16. } else {
  17. $errormes = $switchGroups->getUbMsgHelperInstance()->getStyledMessage(__('Switch group with such name already exists with ID: ') . $foundId,
  18. 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  19. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['errfrmid'], '', true));
  20. }
  21. }
  22. die(wf_modalAutoForm(__('Add switch group'), $switchGroups->renderAddForm($_POST['modalWindowId']), $_POST['modalWindowId'], $_POST['modalWindowBodyId'], true));
  23. }
  24. if (wf_CheckPost(array('swgroupid'))) {
  25. $swGroupId = $_POST['swgroupid'];
  26. if (wf_CheckPost(array('swgroupedit'))) {
  27. if (wf_CheckPost(array('swgroupname'))) {
  28. $newSwitchGroupName = $_POST['swgroupname'];
  29. $foundId = $switchGroups->checkSwitchGroupNameExists($newSwitchGroupName, $swGroupId);
  30. if (empty($foundId)) {
  31. $switchGroups->editSwitchGroup($swGroupId, $newSwitchGroupName, $_POST['swgroupdescr']);
  32. die();
  33. } else {
  34. $errormes = $switchGroups->getUbMsgHelperInstance()->getStyledMessage(__('Switch group with such name already exists with ID: ') . $foundId,
  35. 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"');
  36. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['errfrmid'], '', true));
  37. }
  38. }
  39. die(wf_modalAutoForm(__('Edit switch group'), $switchGroups->renderEditForm($swGroupId, $_POST['modalWindowId']), $_POST['modalWindowId'], $_POST['modalWindowBodyId'], true));
  40. }
  41. if (wf_CheckPost(array('showswingroup'))) {
  42. die(wf_modalAutoForm('', $switchGroups->renderSwitchesInGroupTable($swGroupId), $_POST['modalWindowId'], $_POST['modalWindowBodyId'], true));
  43. }
  44. if (wf_CheckPost(array('delSWGroup'))) {
  45. if ( !$switchGroups->checkSwitchGroupProtected($swGroupId) ) {
  46. $switchGroups->deleteSwitchGroup($swGroupId);
  47. die();
  48. } else {
  49. $errormes = $switchGroups->getUbMsgHelperInstance()->getStyledMessage(__('Can not remove switch group which has existing relations on users or other DB entities'),
  50. 'error', 'style="margin: auto 0; padding: 10px 3px; width: 100%;"' );
  51. die(wf_modalAutoForm(__('Error'), $errormes, $_POST['errfrmid'], '', true));
  52. }
  53. }
  54. }
  55. $lnkId = wf_InputId();
  56. $addServiceJS = wf_tag('script', false, '', 'type="text/javascript"');
  57. $addServiceJS.= wf_JSAjaxModalOpener($switchGroups::URL_ME, array('swgroupcreate' => 'true'), $lnkId, false, 'POST');
  58. $addServiceJS.= wf_tag('script', true);
  59. show_window(__('Switch groups'), wf_Link('#', web_add_icon() . ' ' . __('Add switch group'), false, 'ubButton', 'id="' . $lnkId . '"') .
  60. wf_nbsp(2) . wf_BackLink('?module=switches') . wf_delimiter() . $addServiceJS . $switchGroups->renderJQDT());
  61. }
  62. } else {
  63. show_error(__('Access denied'));
  64. }
  65. ?>