devmodels.php 4.8 KB

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