instances.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. if (isset($_POST['save'])) {
  5. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  6. for ($i = 0; $i < $len; $i ++) {
  7. $save_id = intval($_POST['f_id'][$i]);
  8. $len_all = is_array($_POST['r_id']) ? count($_POST['r_id']) : 0;
  9. for ($j = 0; $j < $len_all; $j ++) {
  10. if (intval($_POST['r_id'][$j]) != $save_id) { continue; }
  11. $id = intval($_POST['r_id'][$j]);
  12. $new['name'] = trim($_POST['f_name'][$j]);
  13. $new['comment'] = trim($_POST['f_comment'][$j]);
  14. update_record($db_link, "filter_instances", "id='$id'", $new);
  15. }
  16. }
  17. header("Location: " . $_SERVER["REQUEST_URI"]);
  18. exit;
  19. }
  20. if (isset($_POST["create"])) {
  21. $instance_name = trim($_POST["new_instance"]);
  22. if (!empty($instance_name)) {
  23. $instance['name'] = $instance_name;
  24. insert_record($db_link, "filter_instances", $instance);
  25. }
  26. header("Location: " . $_SERVER["REQUEST_URI"]);
  27. exit;
  28. }
  29. if (isset($_POST["remove"])) {
  30. $len = is_array($_POST['r_id']) ? count($_POST['r_id']) : 0;
  31. for ($i = 0; $i < $len; $i ++) {
  32. $id = intval($_POST['r_id'][$i]);
  33. if (!empty($id) and $id>1) {
  34. $deleted_groups = get_records_sql($db_link,"SELECT * FROM Group_list WHERE `instance_id`>1 AND `instance_id`=".$id);
  35. foreach ($deleted_groups as $d_group) {
  36. run_sql($db_link, "UPDATE User_auth SET filter_group_id=0, changed = 1 WHERE deleted=0 AND filter_group_id=" . $d_group['id']);
  37. delete_record($db_link, "Group_list", "id=" . $d_group['id']);
  38. }
  39. delete_record($db_link, "filter_instances", "id=" . $id * 1);
  40. }
  41. }
  42. header("Location: " . $_SERVER["REQUEST_URI"]);
  43. exit;
  44. }
  45. unset($_POST);
  46. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  47. print_filters_submenu($page_url);
  48. ?>
  49. <div id="cont">
  50. <form name="def" action="instances.php" method="post">
  51. <table class="data">
  52. <tr align="center">
  53. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  54. <td><b>Id</b></td>
  55. <td><b><?php echo WEB_group_instance_name; ?></b></td>
  56. <td><b><?php echo WEB_cell_comment; ?></b></td>
  57. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
  58. <?php print "<td><input type=\"submit\" name=\"save\" value='".WEB_btn_save."'></td>"; ?>
  59. </tr>
  60. <?php
  61. $t_instance=get_records_sql($db_link, "SELECT * FROM filter_instances");
  62. foreach ($t_instance as $row) {
  63. print "<tr align=center>";
  64. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='".$row['id']."'></td>";
  65. print "<td class=\"data\"><input type=\"hidden\" name='r_id[]' value='".$row['id']."'>".$row['id']."</td>";
  66. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='".$row['name']."'></td>";
  67. print "<td class=\"data\"><input type=\"text\" name='f_comment[]' value='".$row['comment']."'></td>";
  68. print "<td colspan=2 class=\"data\"></td>";
  69. print "</tr>";
  70. }
  71. ?>
  72. </table>
  73. <div>
  74. <input type=text name=new_instance value="New_instance">
  75. <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
  76. </div>
  77. </form>
  78. <?php
  79. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  80. ?>