devmodels.php 4.6 KB

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