editgroup.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
  3. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
  4. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
  5. $group = get_record_sql($db_link, "SELECT * FROM group_list WHERE id=?", [ $id ]);
  6. // Редактирование группы
  7. if (getPOST("editgroup") !== null) {
  8. $new = [
  9. 'group_name' => trim(getPOST("f_group_name", null, $group['group_name'])),
  10. 'instance_id' => (int)getPOST("f_instance_id", null, 1),
  11. 'description' => trim(getPOST("f_group_description", null, ''))
  12. ];
  13. update_record($db_link, "group_list", "id = ?", $new, [$id]);
  14. header("Location: " . $_SERVER["REQUEST_URI"]);
  15. exit;
  16. }
  17. // Добавление фильтра в группу
  18. if (getPOST("addfilter") !== null) {
  19. $filter_id = (int)getPOST("newfilter", null, 0);
  20. if ($filter_id > 0) {
  21. $max_record = get_record_sql($db_link, "SELECT MAX(G.rule_order) as morder FROM group_filters AS G WHERE G.group_id = ?", [$id]);
  22. $forder = (!empty($max_record) && isset($max_record['morder']))
  23. ? ((int)$max_record['morder'] + 1)
  24. : 1;
  25. $new = [
  26. 'group_id' => $id,
  27. 'filter_id' => $filter_id,
  28. 'rule_order' => $forder,
  29. 'action' => 1
  30. ];
  31. insert_record($db_link, "group_filters", $new);
  32. }
  33. header("Location: " . $_SERVER["REQUEST_URI"]);
  34. exit;
  35. }
  36. // Удаление фильтров из группы
  37. if (getPOST("removefilter") !== null) {
  38. $f_group_filter = getPOST("f_group_filter", null, []);
  39. if (!empty($f_group_filter) && is_array($f_group_filter)) {
  40. foreach ($f_group_filter as $val) {
  41. $val = trim($val);
  42. if ($val !== '') {
  43. delete_record($db_link, "group_filters", "id = ?", [(int)$val]);
  44. }
  45. }
  46. }
  47. header("Location: " . $_SERVER["REQUEST_URI"]);
  48. exit;
  49. }
  50. // Обновление порядка и действий фильтров
  51. if (getPOST("updateFilters") !== null) {
  52. $f_group_filter = getPOST("f_group_filter", null, []);
  53. if (!empty($f_group_filter) && is_array($f_group_filter)) {
  54. $f_ord = getPOST("f_ord", null, []);
  55. $f_action = getPOST("f_action", null, []);
  56. LOG_DEBUG($db_link, "Update filters for group id: " . $id);
  57. foreach ($f_group_filter as $i => $group_filter_id) {
  58. $group_filter_id = (int)$group_filter_id;
  59. if ($group_filter_id <= 0) continue;
  60. $new = [
  61. 'rule_order' => isset($f_ord[$group_filter_id])
  62. ? (int)$f_ord[$group_filter_id]
  63. : $i,
  64. 'action' => isset($f_action[$group_filter_id])
  65. ? (int)$f_action[$group_filter_id]
  66. : 0
  67. ];
  68. update_record($db_link, "group_filters", "id = ?", $new, [$group_filter_id]);
  69. }
  70. }
  71. header("Location: " . $_SERVER["REQUEST_URI"]);
  72. exit;
  73. }
  74. unset($_POST);
  75. print_filters_submenu($page_url);
  76. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
  77. ?>
  78. <div id="cont">
  79. <br> <b><?php echo WEB_title_group; ?></b> <br>
  80. <form name="def" action="editgroup.php?id=<?php echo $id; ?>" method="post">
  81. <input type="hidden" name="id" value=<?php echo $id; ?>>
  82. <table class="data">
  83. <tr>
  84. <td><?php echo WEB_cell_name; ?></td>
  85. <td class='data'><input type="text" name="f_group_name" value="<?php echo $group['group_name']; ?>"></td>
  86. <td class='data' align=right><input type="submit" name="editgroup" value="<?php echo WEB_btn_save; ?>"></td>
  87. </tr>
  88. <tr>
  89. <td><?php echo WEB_cell_description; ?></td>
  90. <td class='data'><input type="text" name="f_group_description" value="<?php echo $group['description']; ?>"></td>
  91. <td class='data'></td>
  92. </tr>
  93. <tr>
  94. <td><?php echo WEB_submenu_filter_instance; ?></td>
  95. <td class='data'><?php print_instance_select($db_link,'f_instance_id',$group['instance_id']); ?></td>
  96. <td class='data'></td>
  97. </tr>
  98. </table>
  99. <br> <b><?php echo WEB_groups_filter_list; ?></b><br>
  100. <table class="data">
  101. <tr>
  102. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  103. <td><?php echo WEB_group_filter_order; ?></td>
  104. <td><?php echo WEB_group_filter_name; ?></td>
  105. <td><?php echo WEB_traffic_action; ?></td>
  106. <td class='up'><input type="submit" name="updateFilters" value="<?php echo WEB_btn_save_filters; ?>"></td>
  107. <td class='warn'><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete_filter; ?>?')" name="removefilter" value="<?php echo WEB_btn_delete; ?>"></td>
  108. </tr>
  109. <?php
  110. $sSQL = "SELECT G.id, G.filter_id, F.name, G.rule_order, G.action, F.description FROM group_filters G, filter_list F WHERE F.id=G.filter_id and group_id=? ORDER BY G.rule_order";
  111. $flist = get_records_sql($db_link, $sSQL, [ $id ]);
  112. foreach ($flist as $row) {
  113. print "<tr align=center>\n";
  114. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_group_filter[] value=" . $row['id'] . "></td>\n";
  115. print "<td class=\"data\" align=left><input type=text name=f_ord[" . $row['id'] . "] value=" . $row['rule_order'] . " size=4 ></td>\n";
  116. print "<td class=\"data\" align=left><a href=editfilter.php?id=" . $row['filter_id'] . ">" . $row['name'] . "</a></td>\n";
  117. $cl = "data";
  118. if ($row['action']) {
  119. $cl = "up";
  120. } else {
  121. $cl = "warn";
  122. }
  123. print "<td class=" . $cl . ">";
  124. print_action_select('f_action[' . $row['id'] . ']', $row['action']);
  125. print "</td>";
  126. print "<td colspan=2 class=\"data\" align=left>" . $row['description'] . "</a></td>\n";
  127. print "</tr>";
  128. }
  129. ?>
  130. </table>
  131. <div>
  132. <input type="submit" name="addfilter" value="<?php echo WEB_msg_add_filter; ?>"> <?php print_filter_select($db_link, 'newfilter', $id); ?>
  133. </div>
  134. </form>
  135. <?php
  136. require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
  137. ?>