1
0

edit_rules.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. LOG_INFO($db_link, "Create new rule $new_rule");
  41. insert_record($db_link, "auth_rules", $new);
  42. }
  43. header("Location: " . $_SERVER["REQUEST_URI"]);
  44. exit;
  45. }
  46. unset($_POST);
  47. fix_auth_rules($db_link);
  48. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  49. ?>
  50. <div id="cont">
  51. <br>
  52. <form name="def" action="edit_rules.php" method="post">
  53. <b>Правила автоназначения адресов в <?php print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  54. <br>
  55. Порядок применения: hotspot => subnet => mac => hostname => default user
  56. <br><br>
  57. <table class="data">
  58. <tr align="center">
  59. <td></td>
  60. <td width=30><b>id</b></td>
  61. <td><b>Тип</b></td>
  62. <td><b>Правило</b></td>
  63. <td><input type="submit" onclick="return confirm('Удалить?')" name="s_remove" value="Удалить"></td>
  64. </tr>
  65. <?php
  66. $t_auth_rules = get_records($db_link,'auth_rules',"user_id=$id ORDER BY id");
  67. foreach ( $t_auth_rules as $row ) {
  68. print "<tr align=center>\n";
  69. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  70. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  71. print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
  72. print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
  73. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  74. print "</tr>\n";
  75. }
  76. ?>
  77. <tr>
  78. <td colspan=6>Новое правило :<?php print_qa_rule_select("s_new_type","1"); print "<input type=\"text\" name='s_new_rule' value=''>"; ?></td>
  79. <td><input type="submit" name="s_create" value="Добавить"></td>
  80. </tr>
  81. </table>
  82. </form>
  83. <?php
  84. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  85. ?>