instances.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. // Сохранение изменений
  5. if (getPOST("save") !== null) {
  6. $f_ids = getPOST("f_id", null, []);
  7. $r_ids = getPOST("r_id", null, []);
  8. $f_names = getPOST("f_name", null, []);
  9. $f_descriptions = getPOST("f_description", null, []);
  10. if (is_array($f_ids) && is_array($r_ids)) {
  11. foreach ($f_ids as $save_id) {
  12. $save_id = (int)$save_id;
  13. if ($save_id <= 0) continue;
  14. $idx = array_search($save_id, $r_ids, true);
  15. if ($idx === false) continue;
  16. $new = [
  17. 'name' => trim($f_names[$idx] ?? ''),
  18. 'description' => trim($f_descriptions[$idx] ?? '')
  19. ];
  20. update_record($db_link, "filter_instances", "id = ?", $new, [$save_id]);
  21. }
  22. }
  23. header("Location: " . $_SERVER["REQUEST_URI"]);
  24. exit;
  25. }
  26. // Создание нового экземпляра
  27. if (getPOST("create") !== null) {
  28. $instance_name = trim(getPOST("new_instance", null, ''));
  29. if ($instance_name !== '') {
  30. insert_record($db_link, "filter_instances", ['name' => $instance_name]);
  31. }
  32. header("Location: " . $_SERVER["REQUEST_URI"]);
  33. exit;
  34. }
  35. // Удаление экземпляров
  36. if (getPOST("remove") !== null) {
  37. $r_ids = getPOST("r_id", null, []);
  38. if (is_array($r_ids)) {
  39. foreach ($r_ids as $id) {
  40. $id = (int)$id;
  41. if ($id <= 1) continue; // защищаем ID <= 1
  42. // Находим все группы, использующие этот instance_id
  43. $deleted_groups = get_records_sql($db_link,
  44. "SELECT id FROM group_list WHERE instance_id > 1 AND instance_id = ?",
  45. [$id]
  46. );
  47. if (!empty($deleted_groups)) {
  48. foreach ($deleted_groups as $d_group) {
  49. $group_id = (int)($d_group['id'] ?? 0);
  50. if ($group_id <= 0) continue;
  51. // Сбрасываем привязку в user_auth
  52. update_records($db_link, "user_auth",
  53. "deleted = 0 AND filter_group_id = ?",
  54. ['filter_group_id' => 0, 'changed' => 1],
  55. [$group_id]
  56. );
  57. // Удаление связей
  58. delete_records($db_link, "group_filters", "group_id = ?", [$group_id]);
  59. // Удаляем группу
  60. delete_record($db_link, "group_list", "id = ?", [$group_id]);
  61. }
  62. }
  63. // Удаляем сам экземпляр
  64. delete_record($db_link, "filter_instances", "id = ?", [$id]);
  65. }
  66. }
  67. header("Location: " . $_SERVER["REQUEST_URI"]);
  68. exit;
  69. }
  70. unset($_POST);
  71. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  72. print_filters_submenu($page_url);
  73. ?>
  74. <div id="cont">
  75. <form name="def" action="instances.php" method="post">
  76. <table class="data">
  77. <tr align="center">
  78. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  79. <td><b>Id</b></td>
  80. <td><b><?php echo WEB_group_instance_name; ?></b></td>
  81. <td><b><?php echo WEB_cell_description; ?></b></td>
  82. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
  83. <?php print "<td><input type=\"submit\" name=\"save\" value='".WEB_btn_save."'></td>"; ?>
  84. </tr>
  85. <?php
  86. $t_instance=get_records_sql($db_link, "SELECT * FROM filter_instances");
  87. foreach ($t_instance as $row) {
  88. print "<tr align=center>";
  89. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='".$row['id']."'></td>";
  90. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='".$row['id']."'>".$row['id']."</td>";
  91. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='".$row['name']."'></td>";
  92. print "<td class=\"data\"><input type=\"text\" name='f_description[]' value='".$row['description']."'></td>";
  93. print "<td colspan=2 class=\"data\"></td>";
  94. print "</tr>";
  95. }
  96. ?>
  97. </table>
  98. <div>
  99. <input type=text name=new_instance value="New_instance">
  100. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  101. </div>
  102. </form>
  103. <?php
  104. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  105. ?>