index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
  4. if (isset($_POST["remove"])) {
  5. $fid = $_POST["f_id"];
  6. foreach ($fid as $key => $val) {
  7. if (isset($val) and $val > 0) {
  8. $new['ou_id'] = 0;
  9. update_record($db_link, "User_list", "ou_id=" . $val, $new);
  10. delete_record($db_link, "OU", "id=" . $val);
  11. }
  12. }
  13. header("Location: " . $_SERVER["REQUEST_URI"]);
  14. }
  15. if (isset($_POST['save'])) {
  16. $saved = array();
  17. //button save
  18. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  19. for ($i = 0; $i < $len; $i ++) {
  20. $save_id = intval($_POST['save'][$i]);
  21. if ($save_id == 0) { continue; }
  22. array_push($saved,$save_id);
  23. }
  24. //select box
  25. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  26. if ($len>1) {
  27. for ($i = 0; $i < $len; $i ++) {
  28. $save_id = intval($_POST['f_id'][$i]);
  29. if ($save_id == 0) { continue; }
  30. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  31. }
  32. }
  33. //save changes
  34. $len = is_array($saved) ? count($saved) : 0;
  35. for ($i = 0; $i < $len; $i ++) {
  36. $save_id = intval($saved[$i]);
  37. if ($save_id == 0) { continue; }
  38. $len_all = is_array($_POST['id']) ? count($_POST['id']) : 0;
  39. for ($j = 0; $j < $len_all; $j ++) {
  40. if (intval($_POST['id'][$j]) != $save_id) { continue; }
  41. $new['ou_name'] = $_POST['f_group_name'][$j];
  42. $new['nagios_dir'] = $_POST['f_nagios'][$j];
  43. $new['nagios_host_use'] = $_POST['f_nagios_host'][$j];
  44. $new['nagios_ping'] = $_POST['f_nagios_ping'][$j];
  45. $new['nagios_default_service'] = $_POST['f_nagios_service'][$j];
  46. update_record($db_link, "OU", "id='{$save_id}'", $new);
  47. }
  48. }
  49. header("Location: " . $_SERVER["REQUEST_URI"]);
  50. }
  51. if (isset($_POST["create"])) {
  52. $ou_name = $_POST["new_ou"];
  53. if (isset($ou_name)) {
  54. $new['ou_name'] = $ou_name;
  55. insert_record($db_link, "OU", $new);
  56. }
  57. header("Location: " . $_SERVER["REQUEST_URI"]);
  58. }
  59. unset($_POST);
  60. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  61. ?>
  62. <div id="cont">
  63. <table>
  64. <tr>
  65. <td><b>Список групп</b><br>
  66. <form name="def" action="index.php" method="post">
  67. <table class="data">
  68. <tr align="center">
  69. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  70. <td><b>Id</b></td>
  71. <td><b>Название</b></td>
  72. <td><b>Nagios directory</b></td>
  73. <td><b>Host template</b></td>
  74. <td><b>Ping</b></td>
  75. <td><b>Host service</b></td>
  76. <td><input type="submit" name="remove" value="Удалить"></td>
  77. </tr>
  78. <?
  79. $t_ou = get_records($db_link,'OU','TRUE ORDER BY ou_name');
  80. foreach ($t_ou as $row) {
  81. print "<tr align=center>\n";
  82. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  83. print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  84. print "<td class=\"data\"><input type=\"text\" name='f_group_name[]' value='{$row['ou_name']}'></td>\n";
  85. print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_dir']}'></td>\n";
  86. print "<td class=\"data\"><input type=\"text\" name='f_nagios_host[]' value='{$row['nagios_host_use']}'></td>\n";
  87. print "<td class=\"data\">"; print_qa_select("f_nagios_ping[]",$row['nagios_ping']); print "</td>\n";
  88. print "<td class=\"data\"><input type=\"text\" name='f_nagios_service[]' value='{$row['nagios_default_service']}'></td>\n";
  89. print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>Сохранить</button></td>\n";
  90. print "</tr>\n";
  91. }
  92. ?>
  93. </table>
  94. <table>
  95. <tr>
  96. <td><input type=text name=new_ou value="Unknown"></td>
  97. <td><input type="submit" name="create" value="Добавить"></td>
  98. <td align="right"></td>
  99. </tr>
  100. </table>
  101. </form>
  102. <?php
  103. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  104. ?>