instances.php 3.0 KB

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