edit_rules.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $msg_error = "";
  6. $sSQL = "SELECT * FROM User_list WHERE id=$id";
  7. $auth_info = get_record_sql($db_link, $sSQL);
  8. if (isset($_POST["s_remove"])) {
  9. $s_id = $_POST["s_id"];
  10. foreach ($s_id as $key => $val) {
  11. if (isset($val)) {
  12. LOG_INFO($db_link, "Remove rule id: $val");
  13. delete_record($db_link, "auth_rules", "id=" . $val);
  14. }
  15. }
  16. header("Location: " . $_SERVER["REQUEST_URI"]);
  17. exit;
  18. }
  19. if (isset($_POST['s_save'])) {
  20. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $save_id = intval($_POST['s_save'][$i]);
  23. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  24. for ($j = 0; $j < $len_all; $j ++) {
  25. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  26. $new['type'] = $_POST['s_type'][$j];
  27. $new['rule'] = trim($_POST['s_rule'][$j]);
  28. update_record($db_link, "auth_rules", "id='{$save_id}'", $new);
  29. }
  30. }
  31. header("Location: " . $_SERVER["REQUEST_URI"]);
  32. exit;
  33. }
  34. if (isset($_POST["s_create"])) {
  35. $new_rule = $_POST["s_new_rule"];
  36. if (isset($new_rule)) {
  37. $new['type'] = $_POST["s_new_type"];
  38. $new['rule'] = $new_rule;
  39. $new['user_id'] = $id;
  40. var_dump($new);
  41. LOG_INFO($db_link, "Create new rule $new_rule");
  42. insert_record($db_link, "auth_rules", $new);
  43. }
  44. header("Location: " . $_SERVER["REQUEST_URI"]);
  45. exit;
  46. }
  47. unset($_POST);
  48. fix_auth_rules($db_link);
  49. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  50. ?>
  51. <div id="cont">
  52. <br>
  53. <form name="def" action="edit_rules.php?id=<?php echo $id; ?>" method="post">
  54. <b>Правила автоназначения адресов в <?php print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  55. <br>
  56. Порядок применения: hotspot => subnet => mac => hostname => default user
  57. <br><br>
  58. <table class="data">
  59. <tr align="center">
  60. <td></td>
  61. <td width=30><b>id</b></td>
  62. <td><b>Тип</b></td>
  63. <td><b>Правило</b></td>
  64. <td><input type="submit" onclick="return confirm('Удалить?')" name="s_remove" value="Удалить"></td>
  65. </tr>
  66. <?php
  67. $t_auth_rules = get_records($db_link,'auth_rules',"user_id=$id ORDER BY id");
  68. foreach ( $t_auth_rules as $row ) {
  69. print "<tr align=center>\n";
  70. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  71. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  72. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  73. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  74. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  75. print "</tr>\n";
  76. }
  77. ?>
  78. <tr>
  79. <td colspan=6>Новое правило :<?php print_qa_rule_select("s_new_type","1"); print "<input type=\"text\" name='s_new_rule' value=''>"; ?></td>
  80. <td><input type="submit" name="s_create" value="Добавить"></td>
  81. </tr>
  82. </table>
  83. </form>
  84. <?php
  85. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  86. ?>