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/" . HTML_LANG . ".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?id=<?php echo $id; ?>" method="post">
  53. <b><?php print WEB_ou_rules_for_autoassigning."&nbsp"; print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>
  54. <br>
  55. <?php echo WEB_ou_rules_order; ?>: 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><?php echo WEB_cell_type; ?></b></td>
  62. <td><b><?php echo WEB_ou_rule; ?></b></td>
  63. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="s_remove" value="<?php echo WEB_btn_delete; ?>"></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']}'>".WEB_btn_save."</button></td>\n";
  74. print "</tr>\n";
  75. }
  76. ?>
  77. </table>
  78. <div>
  79. <?php print WEB_ou_new_rule."&nbsp"; print_qa_rule_select("s_new_type","1");
  80. print "<input type=\"text\" name='s_new_rule' value=''>"; ?>
  81. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  82. </div>
  83. </form>
  84. <?php
  85. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  86. ?>