devmodels.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/vendorfilter.php");
  5. if (isset($_POST["remove"])) {
  6. $fid = $_POST["f_id"];
  7. foreach ($fid as $key => $val) {
  8. if (isset($val) and $val > 0) {
  9. $new['ou_id'] = 0;
  10. update_record($db_link, "User_auth", "device_model_id=" . $val, $new);
  11. update_record($db_link, "devices", "device_model_id=" . $val, $new);
  12. delete_record($db_link, "device_models", "id=" . $val);
  13. }
  14. }
  15. header("Location: " . $_SERVER["REQUEST_URI"]);
  16. }
  17. if (isset($_POST['save'])) {
  18. $saved = array();
  19. //button save
  20. $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
  21. for ($i = 0; $i < $len; $i ++) {
  22. $save_id = intval($_POST['save'][$i]);
  23. if ($save_id == 0) { continue; }
  24. array_push($saved,$save_id);
  25. }
  26. //select box
  27. $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
  28. if ($len>0) {
  29. for ($i = 0; $i < $len; $i ++) {
  30. $save_id = intval($_POST['f_id'][$i]);
  31. if ($save_id == 0) { continue; }
  32. if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
  33. }
  34. }
  35. //save changes
  36. $len = is_array($saved) ? count($saved) : 0;
  37. for ($i = 0; $i < $len; $i ++) {
  38. $save_id = intval($saved[$i]);
  39. if ($save_id == 0) { continue; }
  40. $len_all = is_array($_POST['id']) ? count($_POST['id']) : 0;
  41. for ($j = 0; $j < $len_all; $j ++) {
  42. if (intval($_POST['id'][$j]) != $save_id) { continue; }
  43. $new['vendor_id'] = $_POST['f_vendor'][$j];
  44. $new['model_name'] = $_POST['f_name'][$j];
  45. $new['nagios_template'] = $_POST['f_nagios'][$j];
  46. update_record($db_link, "device_models", "id='{$save_id}'", $new);
  47. }
  48. }
  49. header("Location: " . $_SERVER["REQUEST_URI"]);
  50. }
  51. if (isset($_POST["create"])) {
  52. $model_name = $_POST["new_model"];
  53. if (isset($model_name)) {
  54. $new['vendor_id']=1;
  55. if (isset($f_vendor_select) and $f_vendor_select>1) { $new['vendor_id']=$f_vendor_select; }
  56. $new['model_name'] = $model_name;
  57. insert_record($db_link, "device_models", $new);
  58. }
  59. header("Location: " . $_SERVER["REQUEST_URI"]);
  60. }
  61. unset($_POST);
  62. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  63. print_device_submenu($page_url);
  64. ?>
  65. <div id="cont">
  66. <form name="def" action="devmodels.php" method="post">
  67. <table class="data">
  68. <tr>
  69. <td colspan=3><b>Список моделей</b></td>
  70. <td colspan=2><?php print_vendor_select($db_link,'vendor_select',$f_vendor_select); ?></td>
  71. <td><input type="submit" name="OK" value="Показать"></td>
  72. </tr>
  73. <tr align="center">
  74. <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
  75. <td><b>Id</b></td>
  76. <td><b>Производитель</b></td>
  77. <td><b>Название</b></td>
  78. <td><b>Шаблон Nagios</b></td>
  79. <td><input type="submit" name='save' value="Сохранить"></td>
  80. <td><input type="submit" name="remove" value="Удалить"></td>
  81. </tr>
  82. <?
  83. $v_filter='';
  84. if (!empty($f_vendor_select)) { $v_filter = "WHERE vendor_id=".$f_vendor_select; }
  85. $t_ou = get_records_sql($db_link,'SELECT * FROM device_models '.$v_filter.' ORDER BY vendor_id, model_name');
  86. foreach ($t_ou as $row) {
  87. print "<tr align=center>\n";
  88. print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
  89. print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  90. print "<td class=\"data\" width=150>"; print_vendor_set($db_link,'f_vendor[]',$row['vendor_id']); print "</td>\n";
  91. print "<td class=\"data\"><input type=\"text\" name='f_name[]' value='{$row['model_name']}'></td>\n";
  92. print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_template']}'></td>\n";
  93. print "<td class=\"data\"></td>\n";
  94. print "<td class=\"data\"></td>\n";
  95. print "</tr>\n";
  96. }
  97. ?>
  98. </table>
  99. <table>
  100. <tr>
  101. <td><input type=text name=new_model value="Unknown"></td>
  102. <td><input type="submit" name="create" value="Добавить"></td>
  103. <td align="right"></td>
  104. </tr>
  105. </table>
  106. </form>
  107. <?php
  108. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  109. ?>